|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +import argparse |
| 4 | + |
| 5 | +if __name__ == '__main__': |
| 6 | + parser = argparse.ArgumentParser("get_install_parameters", |
| 7 | + description="Return parameters for installing FIDO2Applet with custom settings") |
| 8 | + parser.add_argument('--enable-attestation', action='store_true', default=None, |
| 9 | + help="Allows loading an attestation certificate after installing the applet") |
| 10 | + parser.add_argument('--high-security', action='store_true', default=None, |
| 11 | + help="Does not comply with the FIDO standards, but protects credentials against bugs or " |
| 12 | + "faulty authenticator hardware. Implies high-security RKs.") |
| 13 | + parser.add_argument('--force-always-uv', action='store_true', default=None, |
| 14 | + help="Requires the PIN for all operations, always") |
| 15 | + parser.add_argument('--high-security-rks', action='store_true', default=None, |
| 16 | + help="Protects discoverable credentials against bugs and faulty authenticator hardware," |
| 17 | + "at the cost of standards compliance") |
| 18 | + parser.add_argument('--protect-against-reset', action='store_true', default=None, |
| 19 | + help="Require sending a reset command twice, across two power cycles, to truly reset " |
| 20 | + "the authenticator") |
| 21 | + parser.add_argument('--kdf-iterations', type=int, default=5, |
| 22 | + help="Number of iterations of the Key Derivation Function used. Protects against " |
| 23 | + "brute-force attacks against the PIN (when authenticator hardware is faulty), " |
| 24 | + "at the cost of performance") |
| 25 | + parser.add_argument('--max-cred-blob-len', type=int, default=32, |
| 26 | + help="Maximum length of the blob stored with every discoverable credential. Must be >=32") |
| 27 | + parser.add_argument('--large-blob-store-size', type=int, default=1024, |
| 28 | + help="Length of the large blob array in flash memory. Must be >=1024") |
| 29 | + parser.add_argument('--max-rk-rp-length', type=int, default=32, |
| 30 | + help="Number of bytes of the relying party identifier stored with each RK. Must be >=32") |
| 31 | + parser.add_argument('--max-ram-scratch', type=int, default=254, |
| 32 | + help="Number of bytes of RAM to use for working memory. Reduces flash wear. Must be <=254") |
| 33 | + parser.add_argument('--buffer-mem', type=int, default=1024, |
| 34 | + help="Number of bytes of RAM to use for request processing. Reduces flash wear. Must be >=1024") |
| 35 | + parser.add_argument('--flash-scratch', type=int, default=1024, |
| 36 | + help="Number of bytes of flash to use when RAM is exhausted. For low-memory situations") |
| 37 | + |
| 38 | + args = parser.parse_args() |
| 39 | + |
| 40 | + num_options_set = 0 |
| 41 | + install_param_bytes = [] |
| 42 | + for option_number, option_string in enumerate([ |
| 43 | + 'enable_attestation', |
| 44 | + 'high_security', |
| 45 | + 'force_always_uv', |
| 46 | + 'high_security_rks', |
| 47 | + 'protect_against_reset', |
| 48 | + 'kdf_iterations', |
| 49 | + 'max_cred_blob_len', |
| 50 | + 'large_blob_store_size', |
| 51 | + 'max_rk_rp_length', |
| 52 | + 'max_ram_scratch', |
| 53 | + 'buffer_mem', |
| 54 | + 'flash_scratch' |
| 55 | + ]): |
| 56 | + val = getattr(args, option_string) |
| 57 | + if val is None: |
| 58 | + continue |
| 59 | + num_options_set += 1 |
| 60 | + |
| 61 | + bytes_for_option = [] |
| 62 | + if val is True: |
| 63 | + bytes_for_option = [0xF5] |
| 64 | + elif val is False: |
| 65 | + bytes_for_option = [0xF4] |
| 66 | + else: |
| 67 | + if val <= 23: |
| 68 | + bytes_for_option = [val] |
| 69 | + elif val <= 255: |
| 70 | + bytes_for_option = [0x18, val] |
| 71 | + else: |
| 72 | + bytes_for_option = [0x19, (val & 0xFF00) >> 8, val & 0x00FF] |
| 73 | + |
| 74 | + install_param_bytes += [option_number] + bytes_for_option |
| 75 | + |
| 76 | + install_param_bytes = [0xA0 + num_options_set] + install_param_bytes |
| 77 | + print(bytes(install_param_bytes).hex()) |
0 commit comments