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