mirror of
https://github.com/FiloSottile/mkcert.git
synced 2025-10-14 00:41:40 +08:00
@@ -117,6 +117,8 @@ mkcert supports the following root stores:
|
|||||||
* Chrome and Chromium
|
* Chrome and Chromium
|
||||||
* Java (when `JAVA_HOME` is set)
|
* Java (when `JAVA_HOME` is set)
|
||||||
|
|
||||||
|
To only install the local root CA into a subset of them, you can set the `TRUST_STORES` environment variable to a comma-separated list. Options are: "system", "java" and "nss" (includes Firefox).
|
||||||
|
|
||||||
## Advanced topics
|
## Advanced topics
|
||||||
|
|
||||||
### Advanced options
|
### Advanced options
|
||||||
|
39
main.go
39
main.go
@@ -16,6 +16,7 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/idna"
|
"golang.org/x/net/idna"
|
||||||
)
|
)
|
||||||
@@ -61,6 +62,11 @@ const advancedUsage = `Advanced options:
|
|||||||
Set the CA certificate and key storage location. (This allows
|
Set the CA certificate and key storage location. (This allows
|
||||||
maintaining multiple local CAs in parallel.)
|
maintaining multiple local CAs in parallel.)
|
||||||
|
|
||||||
|
$TRUST_STORES (environment variable)
|
||||||
|
A comma-separated list of trust stores to install the local
|
||||||
|
root CA into. Options are: "system", "java" and "nss" (includes
|
||||||
|
Firefox). Autodetected by default.
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -140,15 +146,15 @@ func (m *mkcert) Run(args []string) {
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
var warning bool
|
var warning bool
|
||||||
if !m.checkPlatform() {
|
if storeEnabled("system") && !m.checkPlatform() {
|
||||||
warning = true
|
warning = true
|
||||||
log.Println("Warning: the local CA is not installed in the system trust store! ⚠️")
|
log.Println("Warning: the local CA is not installed in the system trust store! ⚠️")
|
||||||
}
|
}
|
||||||
if hasNSS && CertutilInstallHelp != "" && !m.checkNSS() {
|
if storeEnabled("nss") && hasNSS && CertutilInstallHelp != "" && !m.checkNSS() {
|
||||||
warning = true
|
warning = true
|
||||||
log.Printf("Warning: the local CA is not installed in the %s trust store! ⚠️", NSSBrowsers)
|
log.Printf("Warning: the local CA is not installed in the %s trust store! ⚠️", NSSBrowsers)
|
||||||
}
|
}
|
||||||
if hasJava && !m.checkJava() {
|
if storeEnabled("java") && hasJava && !m.checkJava() {
|
||||||
warning = true
|
warning = true
|
||||||
log.Println("Warning: the local CA is not installed in the Java trust store! ⚠️")
|
log.Println("Warning: the local CA is not installed in the Java trust store! ⚠️")
|
||||||
}
|
}
|
||||||
@@ -209,14 +215,14 @@ func getCAROOT() string {
|
|||||||
|
|
||||||
func (m *mkcert) install() {
|
func (m *mkcert) install() {
|
||||||
var printed bool
|
var printed bool
|
||||||
if !m.checkPlatform() {
|
if storeEnabled("system") && !m.checkPlatform() {
|
||||||
if m.installPlatform() {
|
if m.installPlatform() {
|
||||||
log.Print("The local CA is now installed in the system trust store! ⚡️")
|
log.Print("The local CA is now installed in the system trust store! ⚡️")
|
||||||
}
|
}
|
||||||
m.ignoreCheckFailure = true // TODO: replace with a check for a successful install
|
m.ignoreCheckFailure = true // TODO: replace with a check for a successful install
|
||||||
printed = true
|
printed = true
|
||||||
}
|
}
|
||||||
if hasNSS && !m.checkNSS() {
|
if storeEnabled("nss") && hasNSS && !m.checkNSS() {
|
||||||
if hasCertutil && m.installNSS() {
|
if hasCertutil && m.installNSS() {
|
||||||
log.Printf("The local CA is now installed in the %s trust store (requires browser restart)! 🦊", NSSBrowsers)
|
log.Printf("The local CA is now installed in the %s trust store (requires browser restart)! 🦊", NSSBrowsers)
|
||||||
} else if CertutilInstallHelp == "" {
|
} else if CertutilInstallHelp == "" {
|
||||||
@@ -227,7 +233,7 @@ func (m *mkcert) install() {
|
|||||||
}
|
}
|
||||||
printed = true
|
printed = true
|
||||||
}
|
}
|
||||||
if hasJava && !m.checkJava() {
|
if storeEnabled("java") && hasJava && !m.checkJava() {
|
||||||
if hasKeytool {
|
if hasKeytool {
|
||||||
m.installJava()
|
m.installJava()
|
||||||
log.Println("The local CA is now installed in Java's trust store! ☕️")
|
log.Println("The local CA is now installed in Java's trust store! ☕️")
|
||||||
@@ -242,7 +248,7 @@ func (m *mkcert) install() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mkcert) uninstall() {
|
func (m *mkcert) uninstall() {
|
||||||
if hasNSS {
|
if storeEnabled("nss") && hasNSS {
|
||||||
if hasCertutil {
|
if hasCertutil {
|
||||||
m.uninstallNSS()
|
m.uninstallNSS()
|
||||||
} else if CertutilInstallHelp != "" {
|
} else if CertutilInstallHelp != "" {
|
||||||
@@ -252,7 +258,7 @@ func (m *mkcert) uninstall() {
|
|||||||
log.Print("")
|
log.Print("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hasJava {
|
if storeEnabled("java") && hasJava {
|
||||||
if hasKeytool {
|
if hasKeytool {
|
||||||
m.uninstallJava()
|
m.uninstallJava()
|
||||||
} else {
|
} else {
|
||||||
@@ -261,10 +267,10 @@ func (m *mkcert) uninstall() {
|
|||||||
log.Print("")
|
log.Print("")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if m.uninstallPlatform() {
|
if storeEnabled("system") && m.uninstallPlatform() {
|
||||||
log.Print("The local CA is now uninstalled from the system trust store(s)! 👋")
|
log.Print("The local CA is now uninstalled from the system trust store(s)! 👋")
|
||||||
log.Print("")
|
log.Print("")
|
||||||
} else if hasCertutil {
|
} else if storeEnabled("nss") && hasCertutil {
|
||||||
log.Printf("The local CA is now uninstalled from the %s trust store(s)! 👋", NSSBrowsers)
|
log.Printf("The local CA is now uninstalled from the %s trust store(s)! 👋", NSSBrowsers)
|
||||||
log.Print("")
|
log.Print("")
|
||||||
}
|
}
|
||||||
@@ -279,6 +285,19 @@ func (m *mkcert) checkPlatform() bool {
|
|||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func storeEnabled(name string) bool {
|
||||||
|
stores := os.Getenv("TRUST_STORES")
|
||||||
|
if stores == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
for _, store := range strings.Split(stores, ",") {
|
||||||
|
if store == name {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func fatalIfErr(err error, msg string) {
|
func fatalIfErr(err error, msg string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("ERROR: %s: %s", msg, err)
|
log.Fatalf("ERROR: %s: %s", msg, err)
|
||||||
|
Reference in New Issue
Block a user