我正在编写一个接受 SSL 连接并计算客户端证书的 SHA-1 哈希的 Web 服务器:
import OpenSSL (withOpenSSL)
import OpenSSL.Session as SSL
import OpenSSL.X509 as X509
import OpenSSL.EVP.Digest as EVP
sslStuff :: SSL.SSL -> IO String
sslStuff ssl = withOpenSSL $ do
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
我成功获得了证书,但摘要只有 15 个字节而不是 20 个字节。我不确定在将证书传递给 EVP.digest 之前是否正确将其转换为字符串。谁能给我一个如何以正确方式做的例子?