1
我想使用golang crypto/tls庫爲服務器返回的鏈中的所有證書提取SubjectKeyIdentifiers。提取與golang的主題密鑰標識符
package main
import (
"crypto/tls"
"fmt"
)
func main() {
conn, err := tls.Dial("tcp", "mail.google.com:443", &tls.Config{
InsecureSkipVerify: true,
})
if err != nil {
panic("failed to connect: " + err.Error())
}
state := conn.ConnectionState()
if err != nil {
panic("failed to get ConnState: " + err.Error())
}
for _, cert := range state.PeerCertificates {
fmt.Printf("%s\n", cert.Subject.CommonName)
fmt.Printf("%X\n", cert.SubjectKeyId)
}
conn.Close()
}
根據文檔SubjectKeyId應該已經填充了ASN1分析數據。 的問題是,我得到 4E16C14EFCD46B0A09F8090F1C00278C6F992C65
而真正的一個是
30:A1:48:01:DB:2B:C3:EE:D3:84:54:4B:66:AF: 0C:4C:66:F7:69:47
我在這裏做錯了什麼?
你如何知道30:A1:48:01:DB:2B:C3:EE:D3:84:54:4B:66:AF:0C:4C :66:F7:69:47是正確的嗎? – reticentroot
運行你的代碼,我得到'4ADD06161BBCF668B576F581B6BB621ABA5A812F',其匹配,看着谷歌谷歌的證書鉻工具,我得到 '4A DD 06 16 1B BC F6 68 B5 76 F5 81 B6 BB 62 1A BA 5A 81 2F' 他們比賽。 – reticentroot
另請參閱 https://security.stackexchange.com/questions/41578/why-does-google-ssl-cert-change-so-times- – reticentroot