#!/bin/bash
httpserver="http://10.226.200.96/"
vpnprofilename="vpn.mobileconfig"
if [ ! -d "/tmp/vpn" ]; then
mkdir /tmp/vpn
fi
cp ../tms_rest/$vpnprofilename /tmp/vpn
cp ../tms_rest/get_pwd_plist.py /tmp/vpn
cd /tmp/vpn
if [ ! -f $vpnprofilename ]; then
wget $httpserver$vpnprofilename -o log
fi
#openssl smime -verify -noverify -nochain -inform DER -in $vpnprofilename | grep verification
python get_pwd_plist.py $vpnprofilename
sed -i 's/^[ \t]*//g' user.p12
base64 -d user.p12 > user.p126
openssl pkcs12 -in user.p126 -out user.cert -passin file:passin -nodes
#openssl pkcs12 -in user.p12 -out user.cert -passin file:passin -nodes
openssl x509 -in pem -in user.cert -noout -text | tr -d ' ' | grep "Username:" | sed 's/;/\n/g'
cat pacfile
echo ''
cat removeoption
echo ''
#cat vpnexception
--------------------------------------------------------------------------------------
get_pwd_plist.py
import plistlib
import sys
from xml.etree import ElementTree
def save_file(filename, content):
if filename and content:
fd = open(filename, 'w')
fd.write(content)
fd.close()
class ParsePayloadFile(object):
def __init__(self):
#self.payloadfile_name = 'vpn.mobileconfig'
self.payloadfile_name = sys.argv[1]
self.pacfile_name = 'pacfile'
self.passinfile_name = 'passin'
self.p12file_name ='user.p12'
self.removeoption_name = 'removeoption'
self.vpnexception_name = 'vpnexception'
def __del__(self):
pass
def get_child_node(self, node, child_node_name):
node_childs = node.getchildren()
for child in node_childs:
if child.text == child_node_name:
return child
return None
def get_next_node(self, node, child_node_name):
node_childs = node.getchildren()
next_node = False
for child in node_childs:
if next_node:
return child
elif child.text == child_node_name:
next_node = True
return None
def parse_payloadfile_xml(self):
result=ElementTree.parse(self.payloadfile_name)
node_root=result.getroot()
node_dict=node_root.getchildren()[0]
#print node_dict
node_payloads_val = self.get_next_node(node_dict, 'PayloadContent')
self.node_vpn = node_payloads_val.getchildren()[0]
node_pro_val = self.get_next_node(self.node_vpn, 'Proxies')
node_pro_url_val = self.get_next_node(node_pro_val, 'ProxyAutoConfigURLString')
save_file(self.pacfile_name,node_pro_url_val.text)
#print node_pro_url_val.text
'''node_ipsec_val = self.get_next_node(self.node_vpn, 'IPSec')
node_ipsec_ondemandrules_val = self.get_next_node(node_ipsec_val, 'OnDemandRules')
ondemandrules_dict = node_ipsec_ondemandrules_val.getchildren()[3]
node_ActionParameters_val = self.get_next_node(ondemandrules_dict, 'ActionParameters')
vpn_exception_list = '-' * 40 + '\n'
vpn_exception_list += 'OnDemandRules:\n'
dict_Domains = node_ActionParameters_val.getchildren()[0]
node_domains_val = self.get_next_node(dict_Domains, 'Domains')
for item in node_domains_val:
vpn_exception_list += item.text + '\n'
node_domainsaction_val = self.get_next_node(dict_Domains, 'DomainAction')
DomainAction = "DomainAction : %s" % node_domainsaction_val.text
vpn_exception_list += DomainAction + '\n'
node_ipsec_exception_val = self.get_next_node(node_ipsec_val, 'OnDemandMatchDomainsNever')
vpn_exception_list += '-' * 20 + '\n'
vpn_exception_list += 'OnDemandMatchDomainsNever:\n'
for item in node_ipsec_exception_val:
vpn_exception_list += item.text + '\n'
save_file(self.vpnexception_name, vpn_exception_list)'''
node_py4 = node_payloads_val.getchildren()[4]
node_py4_pw = self.get_next_node(node_py4, 'Password')
save_file(self.passinfile_name, node_py4_pw.text)
#print node_py4_pw.text
node_py4_pc = self.get_next_node(node_py4, 'PayloadContent')
#print node_py4_pc.text
save_file(self.p12file_name, node_py4_pc.text)
node_vpntag = self.get_next_node(node_dict,'PayloadRemovalDisallowed')
remove_vpn_profile="PayloadRemovalDisallowed:%s" % node_vpntag.tag
save_file(self.removeoption_name, remove_vpn_profile)
def parse_payloadfile(self):
fd = open(self.payloadfile_name, 'r')
#fd = open(sys.argv[1], "r")
text = fd.readlines()
fd.close()
content = ''
for item in text:
if item.find('<?xml') >= 0:
start_pos = item.find('<?xml')
end_pos = item.find('?>') + 3
content = item[start_pos:end_pos]
continue
if item.find('</plist>') == -1:
content = content + item
else:
content = content + item
break
# save_file('content.txt', content)
# print content
if content:
pl = plistlib.readPlistFromString(content)
if pl:
#print pl
#print pl['PayloadRemovalDisallowed']
remove_vpn_profile = "PayloadRemovalDisallowed:%s" % pl['PayloadRemovalDisallowed']
save_file(self.removeoption_name, remove_vpn_profile)
pl_content = pl['PayloadContent']
for item in pl_content:
#print item
if item.has_key('Proxies'):
save_file(self.pacfile_name, item['Proxies']['ProxyAutoConfigURLString'])
if item.has_key('Password'):
save_file(self.passinfile_name, item['Password'])
#save_file('user.b64', item['PayloadContent'].data)
save_file(self.p12file_name, item['PayloadContent'].data)
if __name__ == '__main__':
pp = ParsePayloadFile()
pp.parse_payloadfile_xml() |