• 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
..
archive Loading commit data...
bufio Loading commit data...
builtin Loading commit data...
bytes Loading commit data...
cmd Loading commit data...
compress Loading commit data...
container Loading commit data...
context Loading commit data...
crypto Loading commit data...
database/sql Loading commit data...
debug Loading commit data...
encoding Loading commit data...
errors Loading commit data...
expvar Loading commit data...
flag Loading commit data...
fmt Loading commit data...
go Loading commit data...
hash Loading commit data...
html Loading commit data...
image Loading commit data...
index/suffixarray Loading commit data...
internal Loading commit data...
io Loading commit data...
log Loading commit data...
math Loading commit data...
mime Loading commit data...
net Loading commit data...
os Loading commit data...
path Loading commit data...
reflect Loading commit data...
regexp Loading commit data...
runtime Loading commit data...
sort Loading commit data...
strconv Loading commit data...
strings Loading commit data...
sync Loading commit data...
syscall Loading commit data...
testing Loading commit data...
text Loading commit data...
time Loading commit data...
unicode Loading commit data...
unsafe Loading commit data...
vendor/golang_org/x/net Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
androidtest.bash Loading commit data...
bootstrap.bash Loading commit data...
buildall.bash Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
cmp.bash Loading commit data...
iostest.bash Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
naclmake.bash Loading commit data...
nacltest.bash Loading commit data...
race.bash Loading commit data...
race.bat Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...