alecmuffett / certificate-transparency

Automatically exported from code.google.com/p/certificate-transparency
0 stars 0 forks source link

API to get cert fingerprint? #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I recently had to compare some certs output from OpenSSL to compare against ct.

I hacked a small patch (for reference only)

Thoughts on an API like this?  It could

* return raw DER copy
* return rash binary sha1
* return string in  OpenSSL format of 12:34:…AB:CD:EF

(more inför: 
http://stackoverflow.com/questions/4803799/how-to-calculate-x-509-certificates-s
ha-1-fingerprint
)

thanks,

nickg

+import hashlib
+
 from ct.crypto import error
 from ct.crypto import name
 from ct.crypto import pem
@@ -81,6 +83,13 @@ class Certificate(object):
         self.__cached_extensions = defaultdict(list)
         self.__cache_extensions()

+    def fingerprint(self):
+        """ Computes a fingerprint that matches OpenSSL
+        """
+        h = hashlib.new('sha1')
+        h.update(self.__cached_der)
+        return h.digest()

Original issue reported on code.google.com by nickgsup...@gmail.com on 23 Oct 2013 at 3:29

GoogleCodeExporter commented 9 years ago
CL in
https://codereview.appspot.com/20800043/

Original comment by ekasper@google.com on 1 Nov 2013 at 3:24

GoogleCodeExporter commented 9 years ago
Committed in
https://code.google.com/p/certificate-transparency/source/detail?r=156a72e3d07cc
bfcaabb51df3f45ddf24d373d41

Original comment by ekasper@google.com on 5 Nov 2013 at 9:48