在golang中获取远程ssl证书 [英] Get remote ssl certificate in golang
问题描述
我想通过TLS接收TCP连接。我想验证客户端证书并使用它来向我的应用程序验证客户端。
Go有标准的 crypto / tls
包。它可以验证客户端/服务器证书。但我无法找到获取远程(客户端)证书详细信息的方法,例如通用名称。
I want to receive a TCP connection over TLS. I want to validate client certificate and use it to authenticate the client to my application.
Go has the standard crypto/tls
package. It can validate client/server certificates. But I can't find way to get details of the remote (client) certificate, like the common name.
推荐答案
必须请致电 crypto / tls / Conn.Handshake 。
然后你可以读对等证书:
tlsconn.ConnectionState()。PeerCertificates [0] .Subject.CommonName
Have to call crypto/tls/Conn.Handshake. Then you can read peer certificate: tlsconn.ConnectionState().PeerCertificates[0].Subject.CommonName
这篇关于在golang中获取远程ssl证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!