Skip to content

Commit

Permalink
[release-branch.go1.20] crypto/x509: tolerate multiple matching chain…
Browse files Browse the repository at this point in the history
…s in testVerify

Due to the semantics of roots, a root store may contain two valid roots
that have the same subject (but different SPKIs) at the asme time. As
such in testVerify it is possible that when we verify a certificate we
may get two chains that has the same stringified representation.

Rather than doing something fancy to include keys (which is just overly
complicated), tolerate multiple matches.

Updates #60925
Fixes #60947

Change-Id: I5f51f7635801762865a536bcb20ec75f217a36ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/505035
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Roland Shoemaker <roland@golang.org>
Auto-Submit: Roland Shoemaker <roland@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
(cherry picked from commit 2031366)
Reviewed-on: https://go-review.googlesource.com/c/go/+/505275
Run-TryBot: Heschi Kreinick <heschi@google.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Auto-Submit: Heschi Kreinick <heschi@google.com>
  • Loading branch information
rolandshoemaker authored and gopherbot committed Jun 22, 2023
1 parent b8e67d1 commit bca8175
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/crypto/x509/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,22 +500,21 @@ func testVerify(t *testing.T, test verifyTest, useSystemRoots bool) {
return true
}

// Every expected chain should match 1 returned chain
// Every expected chain should match one (or more) returned chain. We tolerate multiple
// matches, as due to root store semantics it is plausible that (at least on the system
// verifiers) multiple identical (looking) chains may be returned when two roots with the
// same subject are present.
for _, expectedChain := range test.expectedChains {
nChainMatched := 0
var match bool
for _, chain := range chains {
if doesMatch(expectedChain, chain) {
nChainMatched++
match = true
break
}
}

if nChainMatched != 1 {
t.Errorf("Got %v matches instead of %v for expected chain %v", nChainMatched, 1, expectedChain)
for _, chain := range chains {
if doesMatch(expectedChain, chain) {
t.Errorf("\t matched %v", chainToDebugString(chain))
}
}
if !match {
t.Errorf("No match found for %v", expectedChain)
}
}

Expand Down

0 comments on commit bca8175

Please sign in to comment.