登录
首页 >  Golang >  Go问答

在 TLS 握手之前执行 OCSP 检查

来源:stackoverflow

时间:2024-02-29 18:15:23 455浏览 收藏

目前golang学习网上已经有很多关于Golang的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《在 TLS 握手之前执行 OCSP 检查》,也希望能帮助到大家,如果阅读完后真的对你学习Golang有帮助,欢迎动动手指,评论留言并分享~

问题内容

我需要使用 Go 作为客户端在完成 TLS 握手之前对服务器证书进行 OCSP 吊销检查,即 [启动握手 -> 获取服务器证书 -> 检查吊销状态 -> 如果吊销中止],而不是[发起握手->完成握手->检查撤销状态]

使用 Go 的标准 TLS 库,这似乎不可能,因为 tls.Dial 似乎没有进行任何 OCSP 检查。另一种可能的解决方法是获取服务器证书而不执行握手,然后检查吊销状态,如果状态正常,则使用 tls.Dial 重做握手,但我找不到在 Go 中执行此操作的方法。 p>

关于如何解决这个特定问题有什么建议吗?


解决方案


您可以在 tls.config 对象中设置 verifypeercertificate,并在吊销检查失败且您希望中止握手时让指向的函数返回非零错误。

来自docs

// VerifyPeerCertificate, if not nil, is called after normal
// certificate verification by either a TLS client or server. It
// receives the raw ASN.1 certificates provided by the peer and also
// any verified chains that normal processing found. If it returns a
// non-nil error, the handshake is aborted and that error results.
//
// If normal verification fails then the handshake will abort before
// considering this callback. If normal verification is disabled by
// setting InsecureSkipVerify, or (for a server) when ClientAuth is
// RequestClientCert or RequireAnyClientCert, then this callback will
// be considered but the verifiedChains argument will always be nil.
VerifyPeerCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error // Go 1.8

本篇关于《在 TLS 握手之前执行 OCSP 检查》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>