Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | #------------------------------------------------------------------------------- |
| 3 | # Copyright (c) 2019-2022, Arm Limited. All rights reserved. |
| 4 | # |
| 5 | # SPDX-License-Identifier: BSD-3-Clause |
| 6 | # |
| 7 | #------------------------------------------------------------------------------- |
| 8 | |
| 9 | import argparse |
| 10 | import sys |
| 11 | |
| 12 | import yaml |
| 13 | from iatverifier.util import convert_token_to_map |
| 14 | from iatverifier.psa_iot_profile1_token_verifier import PSAIoTProfile1TokenVerifier |
| 15 | |
| 16 | |
| 17 | if __name__ == '__main__': |
Mate Toth-Pal | 6978f7c | 2022-03-30 14:38:55 +0200 | [diff] [blame^] | 18 | |
| 19 | token_verifiers = { |
| 20 | "PSA-IoT-Profile1-token": PSAIoTProfile1TokenVerifier, |
| 21 | } |
| 22 | |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 23 | parser = argparse.ArgumentParser() |
| 24 | parser.add_argument('source', help='A compiled COSE IAT token.') |
| 25 | parser.add_argument('-o', '--outfile', |
| 26 | help='''Output file for the depompiled claims. If this is not |
| 27 | specified, the claims will be written to standard output.''') |
Mate Toth-Pal | 6978f7c | 2022-03-30 14:38:55 +0200 | [diff] [blame^] | 28 | parser.add_argument('-t', '--token-type', |
| 29 | help='''The type of the Token.''', |
| 30 | choices=token_verifiers.keys(), |
| 31 | required=True) |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 32 | args = parser.parse_args() |
| 33 | |
Mate Toth-Pal | 6978f7c | 2022-03-30 14:38:55 +0200 | [diff] [blame^] | 34 | verifier = token_verifiers[args.token_type].get_verifier() |
Mate Toth-Pal | 51b6198 | 2022-03-17 14:19:30 +0100 | [diff] [blame] | 35 | with open(args.source, 'rb') as fh: |
| 36 | token_map = convert_token_to_map(fh.read(), verifier) |
| 37 | |
| 38 | if args.outfile: |
| 39 | with open(args.outfile, 'w') as wfh: |
| 40 | yaml.dump(token_map, wfh) |
| 41 | else: |
| 42 | yaml.dump(token_map, sys.stdout) |
| 43 | |
| 44 | |