![](/img/trans.png)
[英]Why is tls.Client failing with message:first record does not look like a TLS handshake
[英]Golang TLS handshake error - "first record does not look like a TLS handshake"?
客戶端代碼
tlsconf := &tls.Config{InsecureSkipVerify: true}
creds := credentials.NewTLS(tlsconf)
opts = append(opts, grpc.WithTransportCredentials(creds))
conn, err := grpc.Dial(endpoint, opts...)
// handle error and other cases
服務器正確注冊服務。 下面給出了代碼。
if err := s.registerServices(); err != nil {
err = errors.Wrap(err, "unable to register services")
return err
}
這里s
是我s *Server
(指向我的struct
的指針)。
type Server struct {
s *grpc.Server
conf *config
listener net.Listener
}
但是當我嘗試使用s.Serve()
服務於請求時,它給了我這個 tls 握手錯誤:
transport: authentication handshake failed: tls: first record does not look like a TLS handshake
你的信用似乎很奇怪。 當我嘗試在不安全的連接上發送安全數據時,我看到了這個錯誤。
查看文檔 - 您濫用了配置:
// InsecureSkipVerify controls whether a client verifies the server's
// certificate chain and host name. If InsecureSkipVerify is true, crypto/tls
// accepts any certificate presented by the server and any host name in that
// certificate. In this mode, TLS is susceptible to machine-in-the-middle
// attacks unless custom verification is used. This should be used only for
// testing or in combination with VerifyConnection or VerifyPeerCertificate.
嘗試改用此 DialOption:
grpc.WithInsecure()
所以准確地說:
address := ...
conn, err := grpc.Dial(address, grpc.WithInsecure())
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.