3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-22 06:29:23 +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 = argparse.ArgumentParser(description=description)
parser.add_argument('-i', '--input', nargs='?', required=True, group = parser.add_mutually_exclusive_group(required=True)
metavar='mobileconfig', help='iOS mobileconfig file') group.add_argument('-i', '--input', nargs='?', metavar='mobileconfig',
help='iOS mobileconfig file')
parser.add_argument('-o', '--iwd-out', nargs='?', metavar='dir', parser.add_argument('-o', '--iwd-out', nargs='?', metavar='dir',
help='IWD configuration directory (default /var/lib/iwd)') help='IWD configuration directory (default /var/lib/iwd)')
parser.add_argument('-u', '--user', action='store_true', 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') help='Store password (plaintext) in provisioning file')
parser.add_argument('-v', '--verbose', action='store_true', parser.add_argument('-v', '--verbose', action='store_true',
help='Enable verbose output') help='Enable verbose output')
group.add_argument('-x', '--xml', nargs='?',
help='Directly pass XML')
args = parser.parse_args() args = parser.parse_args()
if args.iwd_out: if args.iwd_out:
iwd_dir = args.iwd_out iwd_dir = args.iwd_out
with open(os.devnull, 'w') as devnull: if args.input:
proc = subprocess.Popen(['openssl', 'cms', '-in', args.input, '-inform', with open(os.devnull, 'w') as devnull:
'der', '-verify', '-noverify'], proc = subprocess.Popen(['openssl', 'cms', '-in', args.input, '-inform',
stdout=subprocess.PIPE, stderr=devnull) '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: if args.verbose:
print(xml.decode("utf-8")) print(xml)
subprocess.call(['openssl', 'cms', '-in', args.input, '-inform', 'der', if args.input:
'-outform', 'pem', '-noout', '-cmsout', '-certsout', subprocess.call(['openssl', 'cms', '-in', args.input, '-inform', 'der',
'/tmp/certchain.crt']) '-outform', 'pem', '-noout', '-cmsout', '-certsout',
'/tmp/certchain.crt'])
xml = xml.decode('utf-8')
root = ElementTree.fromstring(xml) root = ElementTree.fromstring(xml)
@ -410,7 +418,10 @@ for i in range(len(root)):
payload = root[i][j + 1] payload = root[i][j + 1]
nets = process_payload(payload) 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: for n in nets:
write_network(n, root_ca_path) write_network(n, root_ca_path)