Skip to content

Commit edfd563

Browse files
Copilotshueybubbles
andcommitted
Fix intermediate certificate handling in setupTLSCommonName
Co-authored-by: shueybubbles <[email protected]>
1 parent afa3e49 commit edfd563

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

msdsn/conn_str_go115.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,20 @@ func setupTLSCommonName(config *tls.Config, pem []byte) error {
4141
return fmt.Errorf("invalid certificate name %q, expected %q", commonName, config.ServerName)
4242
}
4343

44+
// Build intermediates pool from the peer certificates (excluding the first one which is the server cert)
45+
intermediates := x509.NewCertPool()
46+
for i := 1; i < len(rawCerts); i++ {
47+
intermediateCert, err := x509.ParseCertificate(rawCerts[i])
48+
if err != nil {
49+
return fmt.Errorf("failed to parse intermediate certificate: %w", err)
50+
}
51+
intermediates.AddCert(intermediateCert)
52+
}
53+
4454
// Verify the certificate chain against the provided root CA
4555
opts := x509.VerifyOptions{
4656
Roots: roots,
47-
Intermediates: x509.NewCertPool(),
57+
Intermediates: intermediates,
4858
}
4959
_, err = cert.Verify(opts)
5060
return err

0 commit comments

Comments
 (0)