3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 04:32:37 +01:00

tools/ios_convert: add raw XML option

This option allows the script to be called with a raw XML file. This
is mostly useful for testing, but since its already implemented we
might as well include it.
This commit is contained in:
James Prestwood 2019-08-26 16:34:19 -07:00 committed by Denis Kenzior
parent ab0c8cae3c
commit 96ce39c1c2

View File

@ -366,8 +366,9 @@ supported. Inner methods supported are PAP, CHAP, MSCHAP, MSCHAPv2.
'''
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-i', '--input', nargs='?', required=True,
metavar='mobileconfig', help='iOS mobileconfig file')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-i', '--input', nargs='?', metavar='mobileconfig',
help='iOS mobileconfig file')
parser.add_argument('-o', '--iwd-out', nargs='?', metavar='dir',
help='IWD configuration directory (default /var/lib/iwd)')
parser.add_argument('-u', '--user', action='store_true',
@ -376,27 +377,34 @@ parser.add_argument('-p', '--passwd', action='store_true',
help='Store password (plaintext) in provisioning file')
parser.add_argument('-v', '--verbose', action='store_true',
help='Enable verbose output')
group.add_argument('-x', '--xml', nargs='?',
help='Directly pass XML')
args = parser.parse_args()
if args.iwd_out:
iwd_dir = args.iwd_out
with open(os.devnull, 'w') as devnull:
proc = subprocess.Popen(['openssl', 'cms', '-in', args.input, '-inform',
'der', '-verify', '-noverify'],
stdout=subprocess.PIPE, stderr=devnull)
if args.input:
with open(os.devnull, 'w') as devnull:
proc = subprocess.Popen(['openssl', 'cms', '-in', args.input, '-inform',
'der', '-verify', '-noverify'],
stdout=subprocess.PIPE, stderr=devnull)
xml, err = proc.communicate()
xml, err = proc.communicate()
xml = xml.decode('utf-8')
else:
with open(args.xml) as f:
xml = f.read()
if args.verbose:
print(xml.decode("utf-8"))
print(xml)
subprocess.call(['openssl', 'cms', '-in', args.input, '-inform', 'der',
'-outform', 'pem', '-noout', '-cmsout', '-certsout',
'/tmp/certchain.crt'])
xml = xml.decode('utf-8')
if args.input:
subprocess.call(['openssl', 'cms', '-in', args.input, '-inform', 'der',
'-outform', 'pem', '-noout', '-cmsout', '-certsout',
'/tmp/certchain.crt'])
root = ElementTree.fromstring(xml)
@ -410,7 +418,10 @@ for i in range(len(root)):
payload = root[i][j + 1]
nets = process_payload(payload)
root_ca_path = find_root_ca('/tmp/certchain.crt')
if args.input:
root_ca_path = find_root_ca('/tmp/certchain.crt')
else:
root_ca_path = None
for n in nets:
write_network(n, root_ca_path)