Skip to content

Commit

Permalink
util: support intermediate certs when use TLS (#39016)
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored Nov 9, 2022
1 parent 4aa89a6 commit 5426727
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion util/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,21 @@ func NewTLSConfig(opts ...TLSConfigOption) (*tls.Config, error) {
return err
}

intermediates := x509.NewCertPool()
for _, certBytes := range rawCerts[1:] {
c, err2 := x509.ParseCertificate(certBytes)
if err2 != nil {
return err2
}
intermediates.AddCert(c)
}

certPoolMu.RLock()
defer certPoolMu.RUnlock()
if _, err = cert.Verify(x509.VerifyOptions{Roots: certPool}); err != nil {
if _, err = cert.Verify(x509.VerifyOptions{
Roots: certPool,
Intermediates: intermediates,
}); err != nil {
return errors.Wrap(err, "can't verify certificate, maybe different CA is used")
}
return nil
Expand Down

0 comments on commit 5426727

Please sign in to comment.