23 Commits

Author SHA1 Message Date
Stefan Wrobel
2d05f3b4d8 Add link to Chocolatey in README (#181) 2019-07-25 21:59:21 +02:00
y-yagi
a5bb69b629 Fix markdown formatting (#179)
It seems correctly show in GitHub, but this may not be shown correctly
in other markdown readers.
2019-07-21 07:18:11 -04:00
Filippo Valsorda
df15e0c1ef Backdate notBefore to support macOS Catalina
Updates #174
2019-07-06 19:12:45 -03:00
Filippo Valsorda
1f0796c926 Add staticcheck to CI (#171) 2019-07-05 01:41:23 -03:00
Filippo Valsorda
4d2ab596e7 .travis.yml: disable cgo for all release binaries
Fixes #169
2019-07-05 01:28:46 -03:00
Robert Panzer
c2b30c48f1 Add support for URL SANs (#166) 2019-07-05 01:16:19 -03:00
Filippo Valsorda
0a679a8bcd README: revert to $(go env GOPATH)
See discussion at #168
2019-06-21 20:11:30 -04:00
Robert Panzer
574ea52743 Add serverAuth EKU to client certs for Service Mesh mTLS setups 2019-06-17 11:02:53 -04:00
Daniel Martí
ff17118210 README: use $GOBIN instead of $GOPATH/bin (#168)
$GOPATH/bin works in the simple cases, but will break if the user
specifies their own $GOBIN, or if their $GOPATH has multiple elements.

This form is also simpler. Even if the user doesn't specify their custom
$GOBIN, 'go env GOBIN' will return the correct default.
2019-06-12 13:24:10 -04:00
Filippo Valsorda
72ec55f07f Import howett.net/plist by its correct name
Also bumping the version to one with a go.mod.
2019-06-02 12:57:09 +01:00
Filippo Valsorda
e9f8fbcdf4 cert: use os.Hostname for the OU, and add the long form user name
The output of the hostname command on Windows is probably UTF-16, but
instead of figuring out its edge cases, switch to the syscall on every
platform.

Fixes #96
Closes #142
2019-06-02 12:15:03 +01:00
Filippo Valsorda
8d9e434520 truststore_nss: support multiple NSS databases
This adds support for Snap's Chromium, and and CentOS 7.

Fixes #116
Fixes #120
Closes #121
2019-06-01 16:27:42 +01:00
Filippo Valsorda
74ab68812e Fix and add missing license headers 2019-06-01 14:58:20 +01:00
Filippo Valsorda
245b2732c8 Cleanup path logics with pathExists and binaryExists 2019-06-01 14:55:58 +01:00
Filippo Valsorda
b1564cfb0d truststore_linux: autodetect CertutilInstallHelp 2019-06-01 14:41:10 +01:00
Ricardo Branco
b90c9c60cb Support SLES & OpenSUSE (#162)
* Add support for SLES & OpenSUSE

* Update README.md with support for SLES & OpenSUSE

* Fix CertutilInstallHelp
2019-06-01 14:05:08 +01:00
Filippo Valsorda
bf08925790 README: mention "example.test" as an example 2019-05-19 14:11:53 -04:00
Filippo Valsorda
ad5c6ddbef README: document S/MIME certificates 2019-04-27 14:24:17 -04:00
Ben Toews
0d4cf75db8 Allow email SANs for S/MIME certificates (#152) 2019-04-11 22:59:44 -04:00
Filippo Valsorda
c7c85b20ae README: update example names 2019-03-29 12:34:59 -04:00
David Crawshaw
c03e3ceaca Swap exec.Command("hostname") for os.Hostname() (#137) 2019-02-15 21:11:46 +01:00
Filippo Valsorda
9e9563535e Add a -client suffix to filenames when generating client certificates 2019-02-05 14:19:51 -05:00
Filippo Valsorda
fcdbc54cc3 Fix a minor typo in the README 2019-02-02 19:03:13 -05:00
38 changed files with 171 additions and 91 deletions

View File

@@ -1,14 +1,15 @@
language: go language: go
sudo: false sudo: false
go: stable go: stable
install: "# skip" install: (cd && go get honnef.co/go/tools/cmd/staticcheck)
script: script:
- go vet - go vet
- GOOS=linux GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-linux-amd64" - staticcheck ./...
- GOOS=linux GOARCH=arm GOARM=6 go build -o "mkcert-$(git describe --tags)-linux-arm" - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-linux-amd64"
- GOOS=darwin GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-darwin-amd64" - CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o "mkcert-$(git describe --tags)-linux-arm"
- GOOS=windows GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-windows-amd64.exe" - CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-darwin-amd64"
- CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-windows-amd64.exe"
deploy: deploy:
provider: releases provider: releases

View File

@@ -6,15 +6,15 @@ mkcert is a simple tool for making locally-trusted development certificates. It
$ mkcert -install $ mkcert -install
Created a new local CA at "/Users/filippo/Library/Application Support/mkcert" 💥 Created a new local CA at "/Users/filippo/Library/Application Support/mkcert" 💥
The local CA is now installed in the system trust store! ⚡️ The local CA is now installed in the system trust store! ⚡️
The local CA is now installed in the Firefox trust store (requires restart)! 🦊 The local CA is now installed in the Firefox trust store (requires browser restart)! 🦊
$ mkcert example.com "*.example.org" myapp.dev localhost 127.0.0.1 ::1 $ mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1
Using the local CA at "/Users/filippo/Library/Application Support/mkcert" ✨ Using the local CA at "/Users/filippo/Library/Application Support/mkcert" ✨
Created a new certificate valid for the following names 📜 Created a new certificate valid for the following names 📜
- "example.com" - "example.com"
- "*.example.org" - "*.example.com"
- "myapp.dev" - "example.test"
- "localhost" - "localhost"
- "127.0.0.1" - "127.0.0.1"
- "::1" - "::1"
@@ -24,7 +24,7 @@ The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.
<p align="center"><img width="498" alt="Chrome and Firefox screenshot" src="https://user-images.githubusercontent.com/1225294/51066373-96d4aa80-15be-11e9-91e2-f4e44a3a4458.png"></p> <p align="center"><img width="498" alt="Chrome and Firefox screenshot" src="https://user-images.githubusercontent.com/1225294/51066373-96d4aa80-15be-11e9-91e2-f4e44a3a4458.png"></p>
Using certificates from real certificate authorities (CAs) for development can be dangerous or impossible (for hosts like `localhost` or `127.0.0.1`), but self-signed certificates cause trust errors. Managing your own CA is the best solution, but usually involves arcane commands, specialized knowledge and manual steps. Using certificates from real certificate authorities (CAs) for development can be dangerous or impossible (for hosts like `example.test`, `localhost` or `127.0.0.1`), but self-signed certificates cause trust errors. Managing your own CA is the best solution, but usually involves arcane commands, specialized knowledge and manual steps.
mkcert automatically creates and installs a local CA in the system root store, and generates locally-trusted certificates. mkcert does not automatically configure servers to use the certificates, though, that's up to you. mkcert automatically creates and installs a local CA in the system root store, and generates locally-trusted certificates. mkcert does not automatically configure servers to use the certificates, though, that's up to you.
@@ -59,13 +59,15 @@ sudo apt install libnss3-tools
sudo yum install nss-tools sudo yum install nss-tools
-or- -or-
sudo pacman -S nss sudo pacman -S nss
-or-
sudo zypper install mozilla-nss-tools
``` ```
Then you can install using [Linuxbrew](http://linuxbrew.sh/) Then you can install using [Linuxbrew](http://linuxbrew.sh/)
``` ```
brew install mkcert brew install mkcert
```` ```
or build from source (requires Go 1.10+) or build from source (requires Go 1.10+)
@@ -86,7 +88,7 @@ makepkg -si
### Windows ### Windows
On Windows, use Chocolatey On Windows, use [Chocolatey](https://chocolatey.org)
``` ```
choco install mkcert choco install mkcert
@@ -111,7 +113,7 @@ mkcert supports the following root stores:
* Windows system store * Windows system store
* Linux variants that provide either * Linux variants that provide either
* `update-ca-trust` (Fedora, RHEL, CentOS) or * `update-ca-trust` (Fedora, RHEL, CentOS) or
* `update-ca-certificates` (Ubuntu, Debian) or * `update-ca-certificates` (Ubuntu, Debian, OpenSUSE, SLES) or
* `trust` (Arch) * `trust` (Arch)
* Firefox (macOS and Linux only) * Firefox (macOS and Linux only)
* Chrome and Chromium * Chrome and Chromium
@@ -142,6 +144,14 @@ To only install the local root CA into a subset of them, you can set the `TRUST_
all other flags and arguments except -install and -cert-file. all other flags and arguments except -install and -cert-file.
``` ```
### S/MIME
mkcert automatically generates an S/MIME certificate if one of the supplied names is an email address.
```
mkcert filippo@example.com
```
### Mobile devices ### Mobile devices
For the certificates to be trusted on mobile devices, you will have to install the root CA. It's the `rootCA.pem` file in the folder printed by `mkcert -CAROOT`. For the certificates to be trusted on mobile devices, you will have to install the root CA. It's the `rootCA.pem` file in the folder printed by `mkcert -CAROOT`.

46
cert.go
View File

@@ -1,4 +1,4 @@
// Copyright 2018 The Go Authors. All rights reserved. // Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@@ -19,8 +19,9 @@ import (
"log" "log"
"math/big" "math/big"
"net" "net"
"net/mail"
"net/url"
"os" "os"
"os/exec"
"os/user" "os/user"
"path/filepath" "path/filepath"
"regexp" "regexp"
@@ -34,12 +35,16 @@ import (
var userAndHostname string var userAndHostname string
func init() { func init() {
u, _ := user.Current() u, err := user.Current()
if u != nil { if err == nil {
userAndHostname = u.Username + "@" userAndHostname = u.Username + "@"
} }
out, _ := exec.Command("hostname").Output() if h, err := os.Hostname(); err == nil {
userAndHostname += strings.TrimSpace(string(out)) userAndHostname += h
}
if err == nil && u.Name != "" && u.Name != u.Username {
userAndHostname += " (" + u.Name + ")"
}
} }
func (m *mkcert) makeCert(hosts []string) { func (m *mkcert) makeCert(hosts []string) {
@@ -59,21 +64,37 @@ func (m *mkcert) makeCert(hosts []string) {
}, },
NotAfter: time.Now().AddDate(10, 0, 0), NotAfter: time.Now().AddDate(10, 0, 0),
NotBefore: time.Now(),
// Fix the notBefore to temporarily bypass macOS Catalina's limit on
// certificate lifespan. Once mkcert provides an ACME server, automation
// will be the recommended way to guarantee uninterrupted functionality,
// and the lifespan will be shortened to 825 days. See issue 174 and
// https://support.apple.com/en-us/HT210176.
NotBefore: time.Date(2019, time.June, 1, 0, 0, 0, 0, time.UTC),
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true, BasicConstraintsValid: true,
} }
for _, h := range hosts { for _, h := range hosts {
if ip := net.ParseIP(h); ip != nil { if ip := net.ParseIP(h); ip != nil {
tpl.IPAddresses = append(tpl.IPAddresses, ip) tpl.IPAddresses = append(tpl.IPAddresses, ip)
} else if email, err := mail.ParseAddress(h); err == nil && email.Address == h {
tpl.EmailAddresses = append(tpl.EmailAddresses, h)
} else if uriName, err := url.Parse(h); err == nil && uriName.Scheme != "" && uriName.Host != "" {
tpl.URIs = append(tpl.URIs, uriName)
} else { } else {
tpl.DNSNames = append(tpl.DNSNames, h) tpl.DNSNames = append(tpl.DNSNames, h)
} }
} }
if m.client { if m.client {
tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth} tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}
} else if len(tpl.IPAddresses) > 0 || len(tpl.DNSNames) > 0 {
tpl.ExtKeyUsage = []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}
}
if len(tpl.EmailAddresses) > 0 {
tpl.ExtKeyUsage = append(tpl.ExtKeyUsage, x509.ExtKeyUsageCodeSigning, x509.ExtKeyUsageEmailProtection)
} }
// IIS (the main target of PKCS #12 files), only shows the deprecated // IIS (the main target of PKCS #12 files), only shows the deprecated
@@ -149,6 +170,9 @@ func (m *mkcert) fileNames(hosts []string) (certFile, keyFile, p12File string) {
if len(hosts) > 1 { if len(hosts) > 1 {
defaultName += "+" + strconv.Itoa(len(hosts)-1) defaultName += "+" + strconv.Itoa(len(hosts)-1)
} }
if m.client {
defaultName += "-client"
}
certFile = "./" + defaultName + ".pem" certFile = "./" + defaultName + ".pem"
if m.certFile != "" { if m.certFile != "" {
@@ -234,7 +258,7 @@ func (m *mkcert) makeCertFromCSR() {
// loadCA will load or create the CA at CAROOT. // loadCA will load or create the CA at CAROOT.
func (m *mkcert) loadCA() { func (m *mkcert) loadCA() {
if _, err := os.Stat(filepath.Join(m.CAROOT, rootName)); os.IsNotExist(err) { if !pathExists(filepath.Join(m.CAROOT, rootName)) {
m.newCA() m.newCA()
} else { } else {
log.Printf("Using the local CA at \"%s\" ✨\n", m.CAROOT) log.Printf("Using the local CA at \"%s\" ✨\n", m.CAROOT)
@@ -249,7 +273,7 @@ func (m *mkcert) loadCA() {
m.caCert, err = x509.ParseCertificate(certDERBlock.Bytes) m.caCert, err = x509.ParseCertificate(certDERBlock.Bytes)
fatalIfErr(err, "failed to parse the CA certificate") fatalIfErr(err, "failed to parse the CA certificate")
if _, err := os.Stat(filepath.Join(m.CAROOT, rootKeyName)); os.IsNotExist(err) { if !pathExists(filepath.Join(m.CAROOT, rootKeyName)) {
return // keyless mode, where only -install works return // keyless mode, where only -install works
} }

2
go.mod
View File

@@ -1,8 +1,8 @@
module github.com/FiloSottile/mkcert module github.com/FiloSottile/mkcert
require ( require (
github.com/DHowett/go-plist v0.0.0-20180609054337-500bd5b9081b
golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b
golang.org/x/text v0.3.0 // indirect golang.org/x/text v0.3.0 // indirect
howett.net/plist v0.0.0-20181124034731-591f970eefbb
software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237 software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237
) )

11
go.sum
View File

@@ -1,8 +1,15 @@
github.com/DHowett/go-plist v0.0.0-20180609054337-500bd5b9081b h1:WFNhl1+1ofCWWdNFEhut77cmuMXjJYYvkEVloDdaUCI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/DHowett/go-plist v0.0.0-20180609054337-500bd5b9081b/go.mod h1:5paT5ZDrOm8eAJPem2Bd+q3FTi3Gxm/U4tb2tH8YIUQ= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b h1:oXs/nlnyk1ue6g+mFGEHIuIaQIT28IgumdSIRMq2aJY= golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b h1:oXs/nlnyk1ue6g+mFGEHIuIaQIT28IgumdSIRMq2aJY=
golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
howett.net/plist v0.0.0-20181124034731-591f970eefbb h1:jhnBjNi9UFpfpl8YZhA9CrOqpnJdvzuiHsl/dnxl11M=
howett.net/plist v0.0.0-20181124034731-591f970eefbb/go.mod h1:vMygbs4qMhSZSc4lCUl2OEE+rDiIIJAIdR4m7MiMcm0=
software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237 h1:iAEkCBPbRaflBgZ7o9gjVUuWuvWeV4sytFWg9o+Pj2k= software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237 h1:iAEkCBPbRaflBgZ7o9gjVUuWuvWeV4sytFWg9o+Pj2k=
software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237/go.mod h1:/xvNRWUqm0+/ZMiF4EX00vrSCMsE4/NHb+Pt3freEeQ= software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237/go.mod h1:/xvNRWUqm0+/ZMiF4EX00vrSCMsE4/NHb+Pt3freEeQ=

View File

@@ -1,3 +1,7 @@
// Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//+build !go1.10 //+build !go1.10
package main package main

31
main.go
View File

@@ -1,4 +1,4 @@
// Copyright 2018 The Go Authors. All rights reserved. // Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@@ -12,7 +12,10 @@ import (
"fmt" "fmt"
"log" "log"
"net" "net"
"net/mail"
"net/url"
"os" "os"
"os/exec"
"path/filepath" "path/filepath"
"regexp" "regexp"
"runtime" "runtime"
@@ -89,13 +92,13 @@ func main() {
p12FileFlag = flag.String("p12-file", "", "") p12FileFlag = flag.String("p12-file", "", "")
) )
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), shortUsage) fmt.Fprint(flag.CommandLine.Output(), shortUsage)
fmt.Fprintln(flag.CommandLine.Output(), `For more options, run "mkcert -help".`) fmt.Fprintln(flag.CommandLine.Output(), `For more options, run "mkcert -help".`)
} }
flag.Parse() flag.Parse()
if *helpFlag { if *helpFlag {
fmt.Fprintf(flag.CommandLine.Output(), shortUsage) fmt.Fprint(flag.CommandLine.Output(), shortUsage)
fmt.Fprintf(flag.CommandLine.Output(), advancedUsage) fmt.Fprint(flag.CommandLine.Output(), advancedUsage)
return return
} }
if *carootFlag { if *carootFlag {
@@ -190,13 +193,19 @@ func (m *mkcert) Run(args []string) {
if ip := net.ParseIP(name); ip != nil { if ip := net.ParseIP(name); ip != nil {
continue continue
} }
if email, err := mail.ParseAddress(name); err == nil && email.Address == name {
continue
}
if uriName, err := url.Parse(name); err == nil && uriName.Scheme != "" && uriName.Host != "" {
continue
}
punycode, err := idna.ToASCII(name) punycode, err := idna.ToASCII(name)
if err != nil { if err != nil {
log.Fatalf("ERROR: %q is not a valid hostname or IP: %s", name, err) log.Fatalf("ERROR: %q is not a valid hostname, IP, URL or email: %s", name, err)
} }
args[i] = punycode args[i] = punycode
if !hostnameRegexp.MatchString(punycode) { if !hostnameRegexp.MatchString(punycode) {
log.Fatalf("ERROR: %q is not a valid hostname or IP", name) log.Fatalf("ERROR: %q is not a valid hostname, IP, URL or email", name)
} }
} }
@@ -326,3 +335,13 @@ func fatalIfCmdErr(err error, cmd string, out []byte) {
log.Fatalf("ERROR: failed to execute \"%s\": %s\n\n%s\n", cmd, err, out) log.Fatalf("ERROR: failed to execute \"%s\": %s\n\n%s\n", cmd, err, out)
} }
} }
func pathExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func binaryExists(name string) bool {
_, err := exec.LookPath(name)
return err == nil
}

View File

@@ -1,4 +1,4 @@
// Copyright 2018 The Go Authors. All rights reserved. // Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@@ -13,7 +13,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"github.com/DHowett/go-plist" "howett.net/plist"
) )
var ( var (

View File

@@ -1,4 +1,4 @@
// Copyright 2018 The Go Authors. All rights reserved. // Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@@ -39,19 +39,16 @@ func init() {
hasJava = true hasJava = true
javaHome = v javaHome = v
_, err := os.Stat(filepath.Join(v, keytoolPath)) if pathExists(filepath.Join(v, keytoolPath)) {
if err == nil {
hasKeytool = true hasKeytool = true
keytoolPath = filepath.Join(v, keytoolPath) keytoolPath = filepath.Join(v, keytoolPath)
} }
_, err = os.Stat(filepath.Join(v, "lib", "security", "cacerts")) if pathExists(filepath.Join(v, "lib", "security", "cacerts")) {
if err == nil {
cacertsPath = filepath.Join(v, "lib", "security", "cacerts") cacertsPath = filepath.Join(v, "lib", "security", "cacerts")
} }
_, err = os.Stat(filepath.Join(v, "jre", "lib", "security", "cacerts")) if pathExists(filepath.Join(v, "jre", "lib", "security", "cacerts")) {
if err == nil {
cacertsPath = filepath.Join(v, "jre", "lib", "security", "cacerts") cacertsPath = filepath.Join(v, "jre", "lib", "security", "cacerts")
} }
} }

View File

@@ -1,4 +1,4 @@
// Copyright 2018 The Go Authors. All rights reserved. // Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
@@ -17,14 +17,22 @@ import (
var ( var (
FirefoxProfile = os.Getenv("HOME") + "/.mozilla/firefox/*" FirefoxProfile = os.Getenv("HOME") + "/.mozilla/firefox/*"
CertutilInstallHelp = `apt install libnss3-tools" or "yum install nss-tools`
NSSBrowsers = "Firefox and/or Chrome/Chromium" NSSBrowsers = "Firefox and/or Chrome/Chromium"
SystemTrustFilename string SystemTrustFilename string
SystemTrustCommand []string SystemTrustCommand []string
CertutilInstallHelp string
) )
func init() { func init() {
switch {
case binaryExists("apt"):
CertutilInstallHelp = "apt install libnss3-tools"
case binaryExists("yum"):
CertutilInstallHelp = "yum install nss-tools"
case binaryExists("zypper"):
CertutilInstallHelp = "zypper install mozilla-nss-tools"
}
if pathExists("/etc/pki/ca-trust/source/anchors/") { if pathExists("/etc/pki/ca-trust/source/anchors/") {
SystemTrustFilename = "/etc/pki/ca-trust/source/anchors/%s.pem" SystemTrustFilename = "/etc/pki/ca-trust/source/anchors/%s.pem"
SystemTrustCommand = []string{"update-ca-trust", "extract"} SystemTrustCommand = []string{"update-ca-trust", "extract"}
@@ -34,19 +42,14 @@ func init() {
} else if pathExists("/etc/ca-certificates/trust-source/anchors/") { } else if pathExists("/etc/ca-certificates/trust-source/anchors/") {
SystemTrustFilename = "/etc/ca-certificates/trust-source/anchors/%s.crt" SystemTrustFilename = "/etc/ca-certificates/trust-source/anchors/%s.crt"
SystemTrustCommand = []string{"trust", "extract-compat"} SystemTrustCommand = []string{"trust", "extract-compat"}
} else if pathExists("/usr/share/pki/trust/anchors") {
SystemTrustFilename = "/usr/share/pki/trust/anchors/%s.pem"
SystemTrustCommand = []string{"update-ca-certificates"}
} }
if SystemTrustCommand != nil { if SystemTrustCommand != nil && !binaryExists(SystemTrustCommand[0]) {
_, err := exec.LookPath(SystemTrustCommand[0])
if err != nil {
SystemTrustCommand = nil SystemTrustCommand = nil
} }
} }
}
func pathExists(path string) bool {
_, err := os.Stat(path)
return err == nil
}
func (m *mkcert) systemTrustFilename() string { func (m *mkcert) systemTrustFilename() string {
return fmt.Sprintf(SystemTrustFilename, strings.Replace(m.caUniqueName(), " ", "_", -1)) return fmt.Sprintf(SystemTrustFilename, strings.Replace(m.caUniqueName(), " ", "_", -1))
@@ -99,7 +102,7 @@ func (m *mkcert) uninstallPlatform() bool {
} }
func CommandWithSudo(cmd ...string) *exec.Cmd { func CommandWithSudo(cmd ...string) *exec.Cmd {
if _, err := exec.LookPath("sudo"); err != nil { if !binaryExists("sudo") {
return exec.Command(cmd[0], cmd[1:]...) return exec.Command(cmd[0], cmd[1:]...)
} }
return exec.Command("sudo", append([]string{"--"}, cmd...)...) return exec.Command("sudo", append([]string{"--"}, cmd...)...)

View File

@@ -1,3 +1,7 @@
// Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main package main
import ( import (
@@ -13,39 +17,44 @@ 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",
} { }
_, err := os.Stat(path) )
hasNSS = hasNSS || err == nil
func init() {
allPaths := append(append([]string{}, nssDBs...), firefoxPaths...)
for _, path := range allPaths {
if pathExists(path) {
hasNSS = true
break
}
} }
switch runtime.GOOS { switch runtime.GOOS {
case "darwin": case "darwin":
var err error if hasCertutil = binaryExists("certutil"); hasCertutil {
certutilPath, err = exec.LookPath("certutil") certutilPath, _ = exec.LookPath("certutil")
if err != nil { } else {
var out []byte out, err := exec.Command("brew", "--prefix", "nss").Output()
out, err = exec.Command("brew", "--prefix", "nss").Output() if err == nil {
if err != nil {
return
}
certutilPath = filepath.Join(strings.TrimSpace(string(out)), "bin", "certutil") certutilPath = filepath.Join(strings.TrimSpace(string(out)), "bin", "certutil")
_, err = os.Stat(certutilPath) hasCertutil = pathExists(certutilPath)
}
} }
hasCertutil = err == nil
case "linux": case "linux":
var err error if hasCertutil = binaryExists("certutil"); hasCertutil {
certutilPath, err = exec.LookPath("certutil") certutilPath, _ = exec.LookPath("certutil")
hasCertutil = err == nil }
} }
} }
@@ -96,22 +105,15 @@ 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 _, err := os.Stat(nssDB); err == nil { 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
} }
if _, err := os.Stat(filepath.Join(profile, "cert9.db")); err == nil { if pathExists(filepath.Join(profile, "cert9.db")) {
f("sql:" + profile) f("sql:" + profile)
found++ found++
continue } else if pathExists(filepath.Join(profile, "cert8.db")) {
}
if _, err := os.Stat(filepath.Join(profile, "cert8.db")); err == nil {
f("dbm:" + profile) f("dbm:" + profile)
found++ found++
} }

View File

@@ -1,3 +1,7 @@
// Copyright 2018 The mkcert Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main package main
import ( import (

9
vendor/howett.net/plist/go.mod generated vendored Normal file
View File

@@ -0,0 +1,9 @@
module howett.net/plist
require (
// for cmd/ply
github.com/jessevdk/go-flags v1.4.0
github.com/kr/pretty v0.1.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
gopkg.in/yaml.v2 v2.2.1
)

4
vendor/modules.txt vendored
View File

@@ -1,5 +1,3 @@
# github.com/DHowett/go-plist v0.0.0-20180609054337-500bd5b9081b
github.com/DHowett/go-plist
# golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b # golang.org/x/net v0.0.0-20180627171509-e514e69ffb8b
golang.org/x/net/idna golang.org/x/net/idna
# golang.org/x/text v0.3.0 # golang.org/x/text v0.3.0
@@ -7,6 +5,8 @@ golang.org/x/text/secure/bidirule
golang.org/x/text/unicode/bidi golang.org/x/text/unicode/bidi
golang.org/x/text/unicode/norm golang.org/x/text/unicode/norm
golang.org/x/text/transform golang.org/x/text/transform
# howett.net/plist v0.0.0-20181124034731-591f970eefbb
howett.net/plist
# software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237 # software.sslmate.com/src/go-pkcs12 v0.0.0-20180114231543-2291e8f0f237
software.sslmate.com/src/go-pkcs12 software.sslmate.com/src/go-pkcs12
software.sslmate.com/src/go-pkcs12/internal/rc2 software.sslmate.com/src/go-pkcs12/internal/rc2