From 8ff73503d21f55e3dfa099035d74a8989db4977f Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Fri, 16 Aug 2019 18:13:31 -0400 Subject: [PATCH] truststore_darwin: check the default Homebrew path for certutil "mkcert localhost" went from 2.125s to 0.552s, a 4x speedup. Fixes #135 --- truststore_nss.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/truststore_nss.go b/truststore_nss.go index 8772e0e..1cb1eaa 100644 --- a/truststore_nss.go +++ b/truststore_nss.go @@ -41,9 +41,15 @@ func init() { switch runtime.GOOS { case "darwin": - if hasCertutil = binaryExists("certutil"); hasCertutil { + switch { + case binaryExists("certutil"): certutilPath, _ = exec.LookPath("certutil") - } else { + hasCertutil = true + case binaryExists("/usr/local/opt/nss/bin/certutil"): + // Check the default Homebrew path, to save executing Ruby. #135 + certutilPath = "/usr/local/opt/nss/bin/certutil" + hasCertutil = true + default: out, err := exec.Command("brew", "--prefix", "nss").Output() if err == nil { certutilPath = filepath.Join(strings.TrimSpace(string(out)), "bin", "certutil")