def test_import_public_der(self): key_file = load_file("ecc_p521_public.der") key = ECC._import_subjectPublicKeyInfo(key_file) self.assertEqual(self.ref_public, key) key = ECC._import_der(key_file, None) self.assertEqual(self.ref_public, key) key = ECC.import_key(key_file) self.assertEqual(self.ref_public, key)
def test_import_public_der(self): key_file = load_file("ecc_p521_public.der") key = ECC._import_subjectPublicKeyInfo(key_file) self.assertEqual(self.ref_public, key) key = ECC._import_der(key_file, None) self.assertEqual(self.ref_public, key) key = ECC.import_key(key_file) self.assertEqual(self.ref_public, key)
parser = argparse.ArgumentParser() parser.add_argument('--rawfile', type=pathlib.Path, required=True) parser.add_argument('--outfile', type=pathlib.Path, default=None) parser.add_argument('--hdrfile', type=pathlib.Path, default=None) parser.add_argument('--outdir', type=pathlib.Path, default='extract') args = parser.parse_args() ec_privkey = match_key(args.hdrfile) with args.rawfile.open('rb') as fd_in: print(f"[+] loading {args.rawfile}") point = fd_in.read(0x200) try: ec_pub = ECC._import_subjectPublicKeyInfo(point.rstrip(b'\x00')) dump_ec_key(ec_pub, 'pub') except Exception as e: print("[x] failed to load public key from envelope header") print(e) sys.exit() try: print(f"[+] using private key:\n{ec_privkey}\n") ec_priv = ECC.import_key(ec_privkey) dump_ec_key(ec_priv, 'priv') except ValueError as e: print("[x] failed to load private key") print(e) sys.exit()