Commit d1d466f6 authored by Adam Langley's avatar Adam Langley

crypto/x509: prevent chain cycles in Verify

It's possible to include a self-signed root certificate as an
intermediate and push Verify into a loop.

I already had a test for this so I thought that it was ok, but it
turns out that the test was void because the Verisign root certificate
doesn't contain the "IsCA" flag and so it wasn't an acceptable
intermediate certificate for that reason.

R=bradfitz
CC=golang-dev
https://golang.org/cl/4657080
parent 141f676b
...@@ -171,8 +171,14 @@ func (c *Certificate) buildChains(cache map[int][][]*Certificate, currentChain [ ...@@ -171,8 +171,14 @@ func (c *Certificate) buildChains(cache map[int][][]*Certificate, currentChain [
chains = append(chains, appendToFreshChain(currentChain, root)) chains = append(chains, appendToFreshChain(currentChain, root))
} }
nextIntermediate:
for _, intermediateNum := range opts.Intermediates.findVerifiedParents(c) { for _, intermediateNum := range opts.Intermediates.findVerifiedParents(c) {
intermediate := opts.Intermediates.certs[intermediateNum] intermediate := opts.Intermediates.certs[intermediateNum]
for _, cert := range currentChain {
if cert == intermediate {
continue nextIntermediate
}
}
err = intermediate.isValid(intermediateCertificate, opts) err = intermediate.isValid(intermediateCertificate, opts)
if err != nil { if err != nil {
continue continue
......
...@@ -72,23 +72,24 @@ var verifyTests = []verifyTest{ ...@@ -72,23 +72,24 @@ var verifyTests = []verifyTest{
}, },
}, },
{ {
leaf: googleLeaf, leaf: dnssecExpLeaf,
intermediates: []string{verisignRoot, thawteIntermediate}, intermediates: []string{startComIntermediate},
roots: []string{verisignRoot}, roots: []string{startComRoot},
currentTime: 1302726541, currentTime: 1302726541,
expectedChains: [][]string{ expectedChains: [][]string{
[]string{"Google", "Thawte", "VeriSign"}, []string{"dnssec-exp", "StartCom Class 1", "StartCom Certification Authority"},
}, },
}, },
{ {
leaf: dnssecExpLeaf, leaf: dnssecExpLeaf,
intermediates: []string{startComIntermediate}, intermediates: []string{startComIntermediate, startComRoot},
roots: []string{startComRoot}, roots: []string{startComRoot},
currentTime: 1302726541, currentTime: 1302726541,
expectedChains: [][]string{ expectedChains: [][]string{
[]string{"dnssec-exp", "StartCom Class 1", "StartCom Certification Authority"}, []string{"dnssec-exp", "StartCom Class 1", "StartCom Certification Authority"},
[]string{"dnssec-exp", "StartCom Class 1", "StartCom Certification Authority", "StartCom Certification Authority"},
}, },
}, },
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment