]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.7] crypto/x509: speed up and deflake non-cgo Darwin root cert...
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 15 Dec 2016 05:53:01 +0000 (05:53 +0000)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 25 Jan 2017 17:21:33 +0000 (17:21 +0000)
commit5c2b5ee3c8271c3d19d8f0c38804983950c752bf
tree336838b33e521ba8262cd071738633d9fcce8b9f
parentefdb1813a0f65b04fdfe9982b68f4f6d31eda277
[release-branch.go1.7] crypto/x509: speed up and deflake non-cgo Darwin root cert discovery

Backporting Go 1.8's fix to #18203
Fixes #18688

---

Piping into security verify-cert only worked on macOS Sierra, and was
flaky for unknown reasons. Users reported that the number of trusted
root certs stopped randomly jumping around once they switched to using
verify-cert against files on disk instead of /dev/stdin.

But even using "security verify-cert" on 150-200 certs took too
long. It took 3.5 seconds on my machine. More than 4 goroutines
hitting verify-cert didn't help much, and soon started to hurt
instead.

New strategy, from comments in the code:

// 1. Run "security trust-settings-export" and "security
//    trust-settings-export -d" to discover the set of certs with some
//    user-tweaked trusy policy. We're too lazy to parse the XML (at
//    least at this stage of Go 1.8) to understand what the trust
//    policy actually is. We just learn that there is _some_ policy.
//
// 2. Run "security find-certificate" to dump the list of system root
//    CAs in PEM format.
//
// 3. For each dumped cert, conditionally verify it with "security
//    verify-cert" if that cert was in the set discovered in Step 1.
//    Without the Step 1 optimization, running "security verify-cert"
//    150-200 times takes 3.5 seconds. With the optimization, the
//    whole process takes about 180 milliseconds with 1 untrusted root
//    CA. (Compared to 110ms in the cgo path)

Change-Id: I79737d9f2cb9b020ba297a326d4d31d68c7e9fee
Reviewed-on: https://go-review.googlesource.com/35634
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
src/crypto/x509/root_darwin.go
src/crypto/x509/root_darwin_test.go