在golang中获取远程ssl证书 [英] Get remote ssl certificate in golang

查看:1748
本文介绍了在golang中获取远程ssl证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆