Browse Source

added optional arg --keygrip-hex-output-path

Fabian Peter Hammerle 5 years ago
parent
commit
aeac59ceed
1 changed files with 11 additions and 1 deletions
  1. 11 1
      create-gpg-shadow-key-from-x509-cert-req.py

+ 11 - 1
create-gpg-shadow-key-from-x509-cert-req.py

@@ -56,7 +56,7 @@ def load_public_key(input_path):
         return req.public_key()
 
 
-def create_gpg_key(input_path, gpg_key_output_path_pattern, smartcard_app_id_hex):
+def create_gpg_key(input_path, gpg_key_output_path_pattern, smartcard_app_id_hex, keygrip_hex_output_path):
     pubnums = load_public_key(input_path).public_numbers()
     key_data = ['shadowed-private-key', [
         'rsa',
@@ -67,6 +67,9 @@ def create_gpg_key(input_path, gpg_key_output_path_pattern, smartcard_app_id_hex
     key_sexp_data = convert_to_sexp(key_data)
     keygrip = keygrip_from_key_sexp(key_sexp_data)
     keygrip_hex = binascii.hexlify(keygrip).upper().decode()
+    if keygrip_hex_output_path:
+        with open(keygrip_hex_output_path, 'w') as f:
+            f.write(keygrip_hex + '\n')
     with open(gpg_key_output_path_pattern.format(keygrip_hex=keygrip_hex), 'wb') as f:
         f.write(key_sexp_data)
 
@@ -97,6 +100,13 @@ def _init_argparser():
         default=DEFAULT_SMARTCARD_APP_ID_HEX,
         help='default: %(default)s',
     )
+    argparser.add_argument(
+        '--keygrip-hex-output-path',
+        metavar='path',
+        default=None,
+        help='path where to save keygrip in hex format'
+            + ' (default: no output)',
+    )
     return argparser