-
-
Save jcfrank/003cc2d75d0ffb28ae739ae2bf3283e3 to your computer and use it in GitHub Desktop.
Revisions
-
jcfrank revised this gist
Aug 26, 2020 . 1 changed file with 19 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ #!/usr/bin/env python3 import os import sys @@ -22,11 +22,22 @@ _cert_string = fp.read() _cert_x509 = x509.load_pem_x509_certificate(_cert_string, default_backend()) cert_fp_hash = b64encode(_cert_x509.fingerprint(hashes.SHA1())).decode() cert_base64 = _cert_string.decode().replace('\n', '') cert_base64 = cert_base64.replace('-----BEGIN CERTIFICATE-----', '') cert_base64 = cert_base64.replace('-----END CERTIFICATE-----', '') key_id = uuid4() print(f'Custom Key Identifier (SHA1 hash of certificate fingerprint): {cert_fp_hash}') print(f'Key ID: {key_id}') print(f'Base64 encoded certificate:\n{cert_base64}\n') print(f'''Azure App credentials format: {{ "customKeyIdentifier": "{cert_fp_hash}", "keyId": "{key_id}", "type": "AsymmetricX509Cert", "usage": "Verify", "value": "{cert_base64}" }} ''') -
vinodc revised this gist
Aug 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -27,6 +27,6 @@ cert_base64 = cert_base64.replace(b'-----BEGIN CERTIFICATE-----', b'') cert_base64 = cert_base64.replace(b'-----END CERTIFICATE-----', b'') print('Custom Key Identifier (SHA1 hash of certificate fingerprint): %s' % cert_fp_hash.decode()) print('Key ID: %s' % uuid4()) print('Base64 encoded certificate:\n%s\n' % cert_base64.decode()) -
vinodc revised this gist
Jul 7, 2020 . 1 changed file with 7 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -20,13 +20,13 @@ with open(sys.argv[1], 'rb') as fp: _cert_string = fp.read() _cert_x509 = x509.load_pem_x509_certificate(_cert_string, default_backend()) cert_fp_hash = b64encode(_cert_x509.fingerprint(hashes.SHA1())) cert_base64 = _cert_string.replace(b'\n', b'') cert_base64 = cert_base64.replace(b'-----BEGIN CERTIFICATE-----', b'') cert_base64 = cert_base64.replace(b'-----END CERTIFICATE-----', b'') print('SHA1 hash of certificate fingerprint: %s' % cert_fp_hash.decode()) print('Key ID: %s' % uuid4()) print('Base64 encoded certificate:\n%s\n' % cert_base64.decode()) -
vinodc created this gist
Aug 23, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #!/usr/bin/env python import os import sys from base64 import b64encode from uuid import uuid4 try: from cryptography import x509 from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes except ImportError: print("Please install cryptography: `pip install cryptography`") sys.exit(1) if len(sys.argv) < 2 or not os.path.exists(sys.argv[1]): print("Specify the path to the certificate as the first argument:\n" "\tpython %s /path/to/cert" % sys.argv[0].rsplit('/')[-1]) sys.exit(1) with open(sys.argv[1], 'rb') as fp: _cert_string = fp.read() _cert_x509 = x509.load_pem_x509_certificate( str.encode(_cert_string), default_backend()) cert_fp_hash = b64encode(_cert_x509.fingerprint(hashes.SHA1())) cert_base64 = _cert_string.replace('\n', '') cert_base64 = cert_base64.replace('-----BEGIN CERTIFICATE-----', '') cert_base64 = cert_base64.replace('-----END CERTIFICATE-----', '') print('SHA1 hash of certificate fingerprint: %s' % cert_fp_hash) print('Key ID: %s' % uuid4()) print('Base64 encoded certificate:\n%s\n' % cert_base64)