haskell - How to get a SHA-1 digest of a X509 certificate with HsOpenSSL? -
i'm writing web server accepts ssl connections , calculate sha-1 hash of client certificates:
import openssl (withopenssl) import openssl.session ssl import openssl.x509 x509 import openssl.evp.digest evp sslstuff :: ssl.ssl -> io string sslstuff ssl = withopenssl $ x509 <- liftm fromjust $ ssl.getpeercertificate ssl issuer <- x509.getissuername x509 false subj <- x509.getsubjectname x509 false putstrln $ "\tsubject: " ++show subj putstrln $ "\tissuer: " ++show issuer dg <- liftm fromjust $ evp.getdigestbyname "sha1" cert <- x509.printx509 x509 putstrln cert let s = evp.digest dg cert putstrln $ "after digest: "++s return s
i certificate, digest 15 bytes long instead of 20. i'm not sure correctly convert cert string before passing evp.digest. please give me example of how right way?
i not know haskell. following code might you.
x509 * x509; char sha1dig[sha1_digest_length]; /*get x509 certificate in x509*/ //call x509_check_purpose set sha1 hash. x509_check_purpose (x509, -1, 0); //get sha1 hash buffer. use x509->sha1_hash memcpy(sha1dig, x509->sha1_hash, sha1_digest_length);
i believe comments convert program convert haskell.
Comments
Post a Comment