我正在嘗試使用自簽名服務器證書建立TLS連接。Golang - 帶有自簽名證書的TLS
我產生這個示例代碼證書:http://golang.org/src/pkg/crypto/tls/generate_cert.go
我的相關客戶端的代碼看起來像這樣:
// server cert is self signed -> server_cert == ca_cert
CA_Pool := x509.NewCertPool()
severCert, err := ioutil.ReadFile("./cert.pem")
if err != nil {
log.Fatal("Could not load server certificate!")
}
CA_Pool.AppendCertsFromPEM(severCert)
config := tls.Config{RootCAs: CA_Pool}
conn, err := tls.Dial("tcp", "127.0.0.1:8000", &config)
if err != nil {
log.Fatalf("client: dial: %s", err)
}
及相關服務器代碼那樣:
cert, err := tls.LoadX509KeyPair("./cert.pem", "./key.pem")
config := tls.Config{Certificates: []tls.Certificate{cert}}
listener, err := tls.Listen("tcp", "127.0.0.1:8000", &config)
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("server: accept: %s", err)
break
}
log.Printf("server: accepted from %s", conn.RemoteAddr())
go handleConnection(conn)
}
由於服務器證書是自簽名的,因此對服務器和客戶端CA_P使用相同的證書但是,這似乎並沒有工作,因爲我總是得到這個錯誤:
client: dial: x509: certificate signed by unknown authority
(possibly because of "x509: invalid signature: parent certificate
cannot sign this kind of certificate" while trying to verify
candidate authority certificate "serial:0")
我的錯誤是什麼?
OK,我用EasyCert但現在我得到一個:「客戶:撥打:X509:無法爲127.0.0.1,因爲驗證證書它不包含任何IP SAN「什麼是ISAN – Zap
我要在這裏肢解並說你可能會在Go中遇到一個錯誤:https://code.google.com/p/go/issues/detail?id = 4658也許嘗試升級您的Go版本,如果可能的話。 –