File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -290,3 +290,11 @@ def certificate_fingerprint(der, hash="sha256"):
290290 raise UnsupportedAlgorithm (hash )
291291
292292 return ':' .join ([fp [i :i + 2 ] for i in range (0 , len (fp ), 2 )]).upper ()
293+
294+
295+ def pem_hash (pem_file ):
296+ with open (pem_file , "r" ) as fp :
297+ pem = fp .read ()
298+
299+ der = ssl .PEM_cert_to_DER_cert (pem )
300+ return hashlib .sha1 (as_bytes (der )).hexdigest ()
Original file line number Diff line number Diff line change 1616from cryptojwt .exception import UnsupportedAlgorithm
1717from cryptojwt .exception import WrongUsage
1818from cryptojwt .jwk import JWK
19+ from cryptojwt .jwk import pem_hash
20+ from cryptojwt .jwk import pems_to_x5c
1921from cryptojwt .jwk .ec import NIST2SEC
2022from cryptojwt .jwk .ec import ECKey
2123from cryptojwt .jwk .hmac import SYMKey
@@ -639,3 +641,17 @@ def test_key_ops_and_use():
639641 key_ops = ["sign" , "verify" ],
640642 use = "sig"
641643 )
644+
645+
646+ def test_pem_to_x5c ():
647+ with open (full_path ("cert.pem" )) as fp :
648+ cert_chain = fp .read ()
649+
650+ x5c = pems_to_x5c ([cert_chain ])
651+ assert len (x5c ) == 1
652+ assert x5c [0 ] == 'MIIB2jCCAUOgAwIBAgIBATANBgkqhkiG9w0BAQUFADA0MRgwFgYDVQQDEw9UaGUgY29kZSB0ZXN0ZXIxGDAWBgNVBAoTD1VtZWEgVW5pdmVyc2l0eTAeFw0xMjEwMDQwMDIzMDNaFw0xMzEwMDQwMDIzMDNaMDIxCzAJBgNVBAYTAlNFMSMwIQYDVQQDExpPcGVuSUQgQ29ubmVjdCBUZXN0IFNlcnZlcjCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAwf+wiusGhA+gleZYQAOPQlNUIucPiqXdPVyieDqQbXXOPBe3nuggtVzeq7pVFH1dZz4dY2Q2LA5DaegvP8kRvoSB/87ds3dy3Rfym/GUSc5B0l1TgEobcyaep8jguRoHto6GWHfCfKqoUYZq4N8vh4LLMQwLR6zi6Jtu82nB5k8CAwEAATANBgkqhkiG9w0BAQUFAAOBgQCsTntG4dfW5kO/Qle6uBhIhZU+3IreIPmbwzpXoCbcgjRa01z6WiBLwDC1RLAL7ucaF/EVlUq4e0cNXKt4ESGNc1xHISOMLetwvS1SN5tKWA9HNua/SaqRtiShxLUjPjmrtpUgotLNDRvUYnTdTT1vhZar7TSPr1yObirjvz/qLw=='
653+
654+
655+ def test_pem_hash ():
656+ _hash = pem_hash (full_path ("cert.pem" ))
657+ assert _hash
You can’t perform that action at this time.
0 commit comments