diff --git a/components/mission_key_management/convert_config.py b/components/mission_key_management/convert_config.py index 2acffbe..70b1b40 100644 --- a/components/mission_key_management/convert_config.py +++ b/components/mission_key_management/convert_config.py @@ -1,6 +1,7 @@ ''' Convert an MKM policy configuration from text to binary format. The text -format is TOML with sections like this: +format is INI (as handled by Python's `configparser` module) with sections like +this: [00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff] key0 = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa @@ -11,8 +12,8 @@ `bbbb...`. ''' import argparse +import configparser import struct -import tomllib MEASURE_SIZE = 32 KEY_ID_SIZE = 1 @@ -23,8 +24,8 @@ def parse_args(): ap = argparse.ArgumentParser() - ap.add_argument('toml_path', - help='path to the input file in text/TOML format') + ap.add_argument('ini_path', + help='path to the input file in text/INI format') ap.add_argument('bin_path', help='path to the output file in binary format') return ap.parse_args() @@ -38,10 +39,16 @@ def parse_hex(s): def main(): args = parse_args() - t = tomllib.load(open(args.toml_path, 'rb')) + + cfg = configparser.ConfigParser() + cfg.read(args.ini_path) + f = open(args.bin_path, 'wb') - for measure_str, keys in t.items(): + for measure_str, keys in cfg.items(): + if measure_str == 'DEFAULT' and len(keys) == 0: + continue + measure = parse_hex(measure_str) assert len(measure) == MEASURE_SIZE, \ 'expected measure to be %d bytes, but got %r (%d bytes)' \ diff --git a/components/mission_key_management/test_config.toml b/components/mission_key_management/test_config.ini similarity index 62% rename from components/mission_key_management/test_config.toml rename to components/mission_key_management/test_config.ini index e35edd1..71d3347 100644 --- a/components/mission_key_management/test_config.toml +++ b/components/mission_key_management/test_config.ini @@ -1,16 +1,16 @@ # "measurement of valid client code" [6d6561737572656d656e74206f662076616c696420636c69656e7420636f6465] # "key for encrypting secret things" -key0 = "6b657920666f7220656e6372797074696e6720736563726574207468696e6773" +key0 = 6b657920666f7220656e6372797074696e6720736563726574207468696e6773 # "another secret cryptographic key" -key1 = "616e6f74686572207365637265742063727970746f67726170686963206b6579" +key1 = 616e6f74686572207365637265742063727970746f67726170686963206b6579 # Measurement of `test_attest_helper.py` [d2813a46b2a071670fca308762ec34a76a61d67a321b43cb7d252fe4cc1d92a7] # "extra key for test_attest to use" -key0 = "6578747261206b657920666f7220746573745f61747465737420746f20757365" +key0 = 6578747261206b657920666f7220746573745f61747465737420746f20757365 # Measurement of `mkm_client`'s `run_client.sh` script [5bfaa5e5eddcc36e155bde859ac55e5277936791761a34b2c6bcb5da81b4746b] # "mkm_client uses this key to test" -key0 = "6d6b6d5f636c69656e7420757365732074686973206b657920746f2074657374" +key0 = 6d6b6d5f636c69656e7420757365732074686973206b657920746f2074657374