• Brad Fitzpatrick's avatar
    [release-branch.go1.7] crypto/x509: speed up and deflake non-cgo Darwin root cert discovery · 5c2b5ee3
    Brad Fitzpatrick authored
    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/35634Reviewed-by: 's avatarJoe Tsai <thebrokentoaster@gmail.com>
    5c2b5ee3
Name
Last commit
Last update
..
aes Loading commit data...
cipher Loading commit data...
des Loading commit data...
dsa Loading commit data...
ecdsa Loading commit data...
elliptic Loading commit data...
hmac Loading commit data...
md5 Loading commit data...
rand Loading commit data...
rc4 Loading commit data...
rsa Loading commit data...
sha1 Loading commit data...
sha256 Loading commit data...
sha512 Loading commit data...
subtle Loading commit data...
tls Loading commit data...
x509 Loading commit data...
crypto.go Loading commit data...