truststore_nss: support multiple NSS databases

This adds support for Snap's Chromium, and and CentOS 7.

Fixes #116
Fixes #120
Closes #121
This commit is contained in:
Filippo Valsorda
2019-06-01 16:01:09 +01:00
parent 74ab68812e
commit 8d9e434520

View File

@@ -17,17 +17,26 @@ var (
hasNSS bool hasNSS bool
hasCertutil bool hasCertutil bool
certutilPath string certutilPath string
nssDB = filepath.Join(os.Getenv("HOME"), ".pki/nssdb") nssDBs = []string{
) filepath.Join(os.Getenv("HOME"), ".pki/nssdb"),
filepath.Join(os.Getenv("HOME"), "snap/chromium/current/.pki/nssdb"), // Snapcraft
func init() { "/etc/pki/nssdb", // CentOS 7
for _, path := range []string{ }
"/usr/bin/firefox", nssDB, "/Applications/Firefox.app", firefoxPaths = []string{
"/usr/bin/firefox", "/Applications/Firefox.app",
"/Applications/Firefox Developer Edition.app", "/Applications/Firefox Developer Edition.app",
"/Applications/Firefox Nightly.app", "/Applications/Firefox Nightly.app",
"C:\\Program Files\\Mozilla Firefox", "C:\\Program Files\\Mozilla Firefox",
} { }
hasNSS = hasNSS || pathExists(path) )
func init() {
allPaths := append(append([]string{}, nssDBs...), firefoxPaths...)
for _, path := range allPaths {
if pathExists(path) {
hasNSS = true
break
}
} }
switch runtime.GOOS { switch runtime.GOOS {
@@ -96,12 +105,7 @@ func (m *mkcert) uninstallNSS() {
func (m *mkcert) forEachNSSProfile(f func(profile string)) (found int) { func (m *mkcert) forEachNSSProfile(f func(profile string)) (found int) {
profiles, _ := filepath.Glob(FirefoxProfile) profiles, _ := filepath.Glob(FirefoxProfile)
if pathExists(nssDB) { profiles = append(profiles, nssDBs...)
profiles = append(profiles, nssDB)
}
if len(profiles) == 0 {
return
}
for _, profile := range profiles { for _, profile := range profiles {
if stat, err := os.Stat(profile); err != nil || !stat.IsDir() { if stat, err := os.Stat(profile); err != nil || !stat.IsDir() {
continue continue