Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dial_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ func WithCustomCerts(certPath string, insecureSkipVerify bool) grpc.DialOption {
}))
}

// WithCustomCertBytes is a dial option for requiring TLS from a []byte.
//
// This function panics if custom certificate pool cannot be instantiated.
func WithCustomCertBytes(cert []byte, insecureSkipVerify bool) grpc.DialOption {
certPool := x509.NewCertPool()
ok := certPool.AppendCertsFromPEM(cert)
if !ok {
panic("No x509 Certificates parsed")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this actually returns the same error as this:

return nil, errors.New("failed to append certs from CA PEM")

I think there are going to be too many scenarios where users might specify the wrong file and this function should actually fail rather than panic.

}

return grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
RootCAs: certPool,
InsecureSkipVerify: insecureSkipVerify,
}))
}

type secureMetadataCreds map[string]string

func (c secureMetadataCreds) RequireTransportSecurity() bool { return true }
Expand Down