diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/origin-trials/gen-keys.py | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/origin-trials/gen-keys.py')
-rw-r--r-- | dom/origin-trials/gen-keys.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/dom/origin-trials/gen-keys.py b/dom/origin-trials/gen-keys.py new file mode 100644 index 0000000000..6d00d695cf --- /dev/null +++ b/dom/origin-trials/gen-keys.py @@ -0,0 +1,42 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import sys + +from pyasn1.codec.der import decoder +from pyasn1.type import univ +from pyasn1_modules import pem + + +def public_key_to_string(file, name): + out = "static const unsigned char " + name + "[65] = { " + with open(file) as f: + substrate = pem.readPemFromFile( + f, "-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----" + ) + key = decoder.decode(substrate) + ident = key[0][0] + assert ident[0] == univ.ObjectIdentifier( + "1.2.840.10045.2.1" + ), "should be an ECPublicKey" + assert ident[1] == univ.ObjectIdentifier( + "1.2.840.10045.3.1.7" + ), "should be a EcdsaP256 key" + bits = key[0][1] + assert isinstance(bits, univ.BitString), "Should be a bit string" + assert len(bits) == 520, "Should be 520 bits (65 bytes)" + for byte in bits.asOctets(): + out += hex(byte) + ", " + out += "};" + return out + + +def generate(output, test_key, prod_key): + output.write(public_key_to_string(test_key, "kTestKey")) + output.write("\n\n") + output.write(public_key_to_string(prod_key, "kProdKey")) + + +if __name__ == "__main__": + generate(sys.stdout, *sys.argv[1:]) |