第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

了解 Mutual TLS,使用服務(wù)器名的客戶端配置

了解 Mutual TLS,使用服務(wù)器名的客戶端配置

Go
有只小跳蛙 2023-05-08 15:56:00
我試圖了解雙向 TLS 的工作原理,我有以下示例:我有一個客戶端想要連接到服務(wù)器“svc1.example.com”但服務(wù)器有一個服務(wù)器證書的通用名稱為“svc1.example.cloud”,SAN 為“svc.example.test.cloud”?,F(xiàn)在,當(dāng)我發(fā)出 GET 請求時,我得到以下信息:x509:證書對 svc.example.test.cloud 有效,對 svc1.example.com 無效。所以,我的問題是我應(yīng)該對 TLS clientConfig 進(jìn)行更改以包含服務(wù)器名嗎?或者我應(yīng)該在 TLS 客戶端配置中添加自定義 verifyPeerCertificate 函數(shù),如下所示?請讓我知道 Servername 應(yīng)該是什么以及我應(yīng)該在 verifyPeerCertificate 函數(shù)中檢查什么。func customverify(customCName func(*x509.Certificate) bool) func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error {    if customCName == nil {        return nil    }    return func(_ [][]byte, verifiedChains [][]*x509.Certificate) error {        for _, certs := range verifiedChains {            leaf := certs[0]            if customCName(leaf) {                return nil            }        }        return fmt.Errorf("client identity verification failed")    }}func configureClient(certFile, keyFile string) (*http.Client, error) {    certpool, err := addRootCA()    if err != nil {        return nil, err    }cert, err := tls.LoadX509KeyPair(certFile, keyFile)if err != nil {    return nil, err}transport := ytls.NewClientTransport()transport.TLSClientConfig.Certificates = []tls.Certificate{cert}transport.TLSClientConfig.RootCAs = certpool//transport.TLSClientConfig.ServerName = expectedCNametransport.TLSClientConfig.VerifyPeerCertificate = customverify(func(cert *x509.Certificate) bool {    return cert.Subject.CommonName == "svc1.example.cloud"})httpClient := &http.Client{Transport: transport}return httpClient, nil}
查看完整描述

1 回答

?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個贊

由于x509: certificate 對 svc.example.test.cloud 有效,所以transport.TLSClientConfig.ServerName = "svc.example.test.cloud"


VerifyPeerCertificate(如果不是 nil)在 TLS 客戶端或服務(wù)器進(jìn)行正常證書驗(yàn)證后調(diào)用。它
接收對等方提供的原始 ASN.1 證書以及
正常處理發(fā)現(xiàn)的任何經(jīng)過驗(yàn)證的鏈。如果它返回一個
非零錯誤,則握手將中止并導(dǎo)致該錯誤。

如果正常驗(yàn)證失敗,則握手將在
考慮此回調(diào)之前中止。如果通過設(shè)置 InsecureSkipVerify 禁用正常驗(yàn)證
,或者(對于服務(wù)器)當(dāng) ClientAuth 是RequestClientCert 或 RequireAnyClientCert 時,將?考慮
此回調(diào),但 verifiedChains 參數(shù)將始終為 nil。

VerifyPeerCertificate func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) 錯誤

因此,如果正常驗(yàn)證失敗,則VerifyPeerCertificate不會被調(diào)用。另外,如果正常驗(yàn)證通過,我認(rèn)為你不需要這個額外的檢查VerifyPeerCertificate。



查看完整回答
反對 回復(fù) 2023-05-08
  • 1 回答
  • 0 關(guān)注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號