Thanks for your blog post, very inspiring. One thing I noticed while trying to implement this on a gRPC client is your example calls NewServerTLSFromCert instead of NewClientTLSFromCert. I personally use client configs for Dial options (I might be off here).
conn, err := grpc.Dial(*serverAddr, grpc.NewServerTLSFromCert(tlsCert))
if err != nil {
...
}
defer conn.Close()
So, in my case I had to create a certPool with the PeerCertificates that I can pass to NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string).
certPool := x509.NewCertPool()
for _, cert := range tconn.ConnectionState().PeerCertificates {
certPool.AddCert(cert)
}
The good news is that it works!, I could connect to the devices (server) without manually providing the .pem certificate file. On the other hand, I'm still wrapping my head around this as NewClientTLSFromCert pass this cert as RootCAs.
func NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string) TransportCredentials {
return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp})
}
Thanks for your blog post, very inspiring. One thing I noticed while trying to implement this on a gRPC client is your example calls
NewServerTLSFromCertinstead ofNewClientTLSFromCert. I personally use client configs for Dial options (I might be off here).So, in my case I had to create a
certPoolwith thePeerCertificatesthat I can pass toNewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string).The good news is that it works!, I could connect to the devices (server) without manually providing the
.pemcertificate file. On the other hand, I'm still wrapping my head around this asNewClientTLSFromCertpass this cert asRootCAs.