So I've been finally integrating trustme into aiohttp's test today.
Turns out that certificate fingerprint calculation isn't well-documented on the Internet for Python stdlib's ssl module. All examples use pyOpenSSL instead.
So after fighting it for a while, I've figured out that one should turn certificate into DER format as opposed to PEM (ssl.PEM_cert_to_DER_cert()), because it's what SSLSocket.getpeercert() returns and what client uses to calculate hash: aio-libs/aiohttp@c180800#diff-484462fced51d1a06b1d93b4a44dd535R69
Ref: https://github.com/aio-libs/aiohttp/blob/c9dabcb/aiohttp/client_reqrep.py#L105-L136
So I think it'd be nice to wrap it into a method bound to LeafCert (and maybe Blob?).
The suggested API is:
# fingerprint calc function wrapped with `lru_cache`
LeafCert.make_fingerprint(hash_function='sha256')
# @properties:
LeafCert.sha256_fingerprint
LeafCert.sha1_fingerprint
LeafCert.md5_fingerprint
Maybe fingerprint would need to be represented by its own Fingerprint class, not just some bytes.
So I've been finally integrating
trustmeintoaiohttp's test today.Turns out that certificate fingerprint calculation isn't well-documented on the Internet for Python stdlib's
sslmodule. All examples usepyOpenSSLinstead.So after fighting it for a while, I've figured out that one should turn certificate into DER format as opposed to PEM (
ssl.PEM_cert_to_DER_cert()), because it's whatSSLSocket.getpeercert()returns and what client uses to calculate hash: aio-libs/aiohttp@c180800#diff-484462fced51d1a06b1d93b4a44dd535R69Ref: https://github.com/aio-libs/aiohttp/blob/c9dabcb/aiohttp/client_reqrep.py#L105-L136
So I think it'd be nice to wrap it into a method bound to
LeafCert(and maybeBlob?).The suggested API is:
Maybe fingerprint would need to be represented by its own
Fingerprintclass, not just some bytes.