![](/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.