Skip to content

Commit 3fd4d32

Browse files
committed
certcheck: check self-signature on roots
1 parent 8de9966 commit 3fd4d32

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

x509util/certcheck/certcheck.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var (
4646
checkRevoked = flag.Bool("check_revocation", false, "Check revocation status of certificate")
4747
)
4848

49-
func addCerts(filename string, pool *x509.CertPool) {
49+
func addCerts(filename string, pool *x509.CertPool, validateSelfSigned bool) {
5050
if filename != "" {
5151
dataList, err := x509util.ReadPossiblePEMFile(filename, "CERTIFICATE")
5252
if err != nil {
@@ -58,6 +58,12 @@ func addCerts(filename string, pool *x509.CertPool) {
5858
glog.Exitf("Failed to parse certificate from %s: %v", filename, err)
5959
}
6060
for _, cert := range certs {
61+
if validateSelfSigned {
62+
err := cert.CheckSignature(cert.SignatureAlgorithm, cert.RawTBSCertificate, cert.Signature)
63+
if err != nil {
64+
glog.Exitf("Failed to verify self-signature on root cert from %s: %v", filename, err)
65+
}
66+
}
6167
pool.AddCert(cert)
6268
}
6369
}
@@ -223,8 +229,8 @@ func validateChain(chain []*x509.Certificate, opts x509.VerifyOptions, rootsFile
223229
opts.KeyUsages = []x509.ExtKeyUsage{x509.ExtKeyUsageAny}
224230
opts.Roots = roots
225231
opts.Intermediates = x509.NewCertPool()
226-
addCerts(rootsFile, opts.Roots)
227-
addCerts(intermediatesFile, opts.Intermediates)
232+
addCerts(rootsFile, opts.Roots /* validate_self_signed= */, true)
233+
addCerts(intermediatesFile, opts.Intermediates /* validate_self_signed= */, false)
228234

229235
if !useSystemRoots && len(rootsFile) == 0 {
230236
// No root CA certs provided, so assume the chain is self-contained.

0 commit comments

Comments
 (0)