Background:
I am writing a client utility which is capable of connecting to a remote server using SSL/TLS. The client uses OpenSSL to perform the SSL/TLS transactions and I would like to allow users to specify authorized CA Certs (in the case of self signed certs or private CA setups) used to sign the server’s certificate. I plan on using the cert’s fingerprint, common name, and validity dates to allow the user to quickly view the certs the client uses to validate servers.
Question:
How do you calculate the SHA1 hash/fingerprint of an X509 cert stored within a PEM file using C/C++/Objective-C?
After days of search and experimenting I found a solution and will post it as an answer, however I welcome better or more correct solutions.
I found below to yield identical output to above:
which is a bit shorter in objective C. It needs the below extensions to NSData/NSString though to get the formatting close to Netscape, OSX or Windows.