mirror of
https://github.com/FiloSottile/mkcert.git
synced 2025-10-14 17:01:41 +08:00
Compare commits
43 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
2d05f3b4d8 | ||
![]() |
a5bb69b629 | ||
![]() |
df15e0c1ef | ||
![]() |
1f0796c926 | ||
![]() |
4d2ab596e7 | ||
![]() |
c2b30c48f1 | ||
![]() |
0a679a8bcd | ||
![]() |
574ea52743 | ||
![]() |
ff17118210 | ||
![]() |
72ec55f07f | ||
![]() |
e9f8fbcdf4 | ||
![]() |
8d9e434520 | ||
![]() |
74ab68812e | ||
![]() |
245b2732c8 | ||
![]() |
b1564cfb0d | ||
![]() |
b90c9c60cb | ||
![]() |
bf08925790 | ||
![]() |
ad5c6ddbef | ||
![]() |
0d4cf75db8 | ||
![]() |
c7c85b20ae | ||
![]() |
c03e3ceaca | ||
![]() |
9e9563535e | ||
![]() |
fcdbc54cc3 | ||
![]() |
99e15e29f9 | ||
![]() |
592400aab0 | ||
![]() |
66af5a51f6 | ||
![]() |
5bb0c47df7 | ||
![]() |
821679b01f | ||
![]() |
50b8c9f09f | ||
![]() |
3bcdd3721c | ||
![]() |
a177c7e2ad | ||
![]() |
8dca36bc48 | ||
![]() |
610df05c5c | ||
![]() |
da4da8a4bc | ||
![]() |
5ea72c377d | ||
![]() |
0d0636e824 | ||
![]() |
6f4ab38307 | ||
![]() |
7fbb1febce | ||
![]() |
6060e206a4 | ||
![]() |
ea716f38b3 | ||
![]() |
438ae98b1c | ||
![]() |
afbc420fa0 | ||
![]() |
48e7d200ae |
10
.travis.yml
10
.travis.yml
@@ -1,13 +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=darwin GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-darwin-amd64"
|
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-linux-amd64"
|
||||||
- GOOS=windows GOARCH=amd64 go build -o "mkcert-$(git describe --tags)-windows-amd64.exe"
|
- CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=6 go build -o "mkcert-$(git describe --tags)-linux-arm"
|
||||||
|
- 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
|
||||||
|
72
README.md
72
README.md
@@ -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"
|
||||||
@@ -22,11 +22,11 @@ Created a new certificate valid for the following names 📜
|
|||||||
The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.pem" ✅
|
The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.pem" ✅
|
||||||
```
|
```
|
||||||
|
|
||||||
<p align="center"><img width="444" alt="Chrome screenshot" src="https://user-images.githubusercontent.com/1225294/41887838-7acd55ca-78d0-11e8-8a81-139a54faaf87.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 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.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@@ -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+)
|
||||||
|
|
||||||
@@ -76,15 +78,17 @@ $(go env GOPATH)/bin/mkcert
|
|||||||
|
|
||||||
or use [the pre-built binaries](https://github.com/FiloSottile/mkcert/releases).
|
or use [the pre-built binaries](https://github.com/FiloSottile/mkcert/releases).
|
||||||
|
|
||||||
On Arch Linux you can use your [AUR helper](https://wiki.archlinux.org/index.php/AUR_helpers) to install mkcert from the [PKGBUILD](https://aur.archlinux.org/packages/mkcert/).
|
For Arch Linux users, mkcert is available from AUR as [`mkcert`](https://aur.archlinux.org/packages/mkcert/) or [`mkcert-git`](https://aur.archlinux.org/packages/mkcert-git/).
|
||||||
|
|
||||||
```
|
```bash
|
||||||
yaourt -S mkcert
|
git clone https://aur.archlinux.org/mkcert.git
|
||||||
|
cd mkcert
|
||||||
|
makepkg -si
|
||||||
```
|
```
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
On Windows, use Chocolatey
|
On Windows, use [Chocolatey](https://chocolatey.org)
|
||||||
|
|
||||||
```
|
```
|
||||||
choco install mkcert
|
choco install mkcert
|
||||||
@@ -93,11 +97,14 @@ choco install mkcert
|
|||||||
or use Scoop
|
or use Scoop
|
||||||
|
|
||||||
```
|
```
|
||||||
|
scoop bucket add extras
|
||||||
scoop install mkcert
|
scoop install mkcert
|
||||||
```
|
```
|
||||||
|
|
||||||
or build from source (requires Go 1.10+), or use [the pre-built binaries](https://github.com/FiloSottile/mkcert/releases).
|
or build from source (requires Go 1.10+), or use [the pre-built binaries](https://github.com/FiloSottile/mkcert/releases).
|
||||||
|
|
||||||
|
If you're running into permission problems try running `mkcert` as an Administrator.
|
||||||
|
|
||||||
## Supported root stores
|
## Supported root stores
|
||||||
|
|
||||||
mkcert supports the following root stores:
|
mkcert supports the following root stores:
|
||||||
@@ -106,14 +113,45 @@ 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
|
||||||
* 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
|
||||||
|
|
||||||
|
```
|
||||||
|
-cert-file FILE, -key-file FILE, -p12-file FILE
|
||||||
|
Customize the output paths.
|
||||||
|
|
||||||
|
-client
|
||||||
|
Generate a certificate for client authentication.
|
||||||
|
|
||||||
|
-ecdsa
|
||||||
|
Generate a certificate with an ECDSA key.
|
||||||
|
|
||||||
|
-pkcs12
|
||||||
|
Generate a ".p12" PKCS #12 file, also know as a ".pfx" file,
|
||||||
|
containing certificate and key for legacy applications.
|
||||||
|
|
||||||
|
-csr CSR
|
||||||
|
Generate a certificate based on the supplied CSR. Conflicts with
|
||||||
|
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`.
|
||||||
@@ -122,6 +160,14 @@ On iOS, you can either use AirDrop, email the CA to yourself, or serve it from a
|
|||||||
|
|
||||||
For Android, you will have to install the CA and then enable user roots in the development build of your app. See [this StackOverflow answer](https://stackoverflow.com/a/22040887/749014).
|
For Android, you will have to install the CA and then enable user roots in the development build of your app. See [this StackOverflow answer](https://stackoverflow.com/a/22040887/749014).
|
||||||
|
|
||||||
|
### Using the root with Node.js
|
||||||
|
|
||||||
|
Node does not use the system root store, so it won't accept mkcert certificates automatically. Instead, you will have to set the [`NODE_EXTRA_CA_CERTS`](https://nodejs.org/api/cli.html#cli_node_extra_ca_certs_file) environment variable.
|
||||||
|
|
||||||
|
```
|
||||||
|
export NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
|
||||||
|
```
|
||||||
|
|
||||||
### Changing the location of the CA files
|
### Changing the location of the CA files
|
||||||
|
|
||||||
The CA certificate and its key are stored in an application data folder in the user home. You usually don't have to worry about it, as installation is automated, but the location is printed by `mkcert -CAROOT`.
|
The CA certificate and its key are stored in an application data folder in the user home. You usually don't have to worry about it, as installation is automated, but the location is printed by `mkcert -CAROOT`.
|
||||||
|
221
cert.go
221
cert.go
@@ -1,10 +1,13 @@
|
|||||||
// 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.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto"
|
||||||
|
"crypto/ecdsa"
|
||||||
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
@@ -16,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"
|
||||||
@@ -25,18 +29,22 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"software.sslmate.com/src/go-pkcs12"
|
pkcs12 "software.sslmate.com/src/go-pkcs12"
|
||||||
)
|
)
|
||||||
|
|
||||||
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) {
|
||||||
@@ -44,63 +52,91 @@ func (m *mkcert) makeCert(hosts []string) {
|
|||||||
log.Fatalln("ERROR: can't create new certificates because the CA key (rootCA-key.pem) is missing")
|
log.Fatalln("ERROR: can't create new certificates because the CA key (rootCA-key.pem) is missing")
|
||||||
}
|
}
|
||||||
|
|
||||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
priv, err := m.generateKey(false)
|
||||||
fatalIfErr(err, "failed to generate certificate key")
|
fatalIfErr(err, "failed to generate certificate key")
|
||||||
|
pub := priv.(crypto.Signer).Public()
|
||||||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
|
||||||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
|
||||||
fatalIfErr(err, "failed to generate serial number")
|
|
||||||
|
|
||||||
tpl := &x509.Certificate{
|
tpl := &x509.Certificate{
|
||||||
SerialNumber: serialNumber,
|
SerialNumber: randomSerialNumber(),
|
||||||
Subject: pkix.Name{
|
Subject: pkix.Name{
|
||||||
Organization: []string{"mkcert development certificate"},
|
Organization: []string{"mkcert development certificate"},
|
||||||
OrganizationalUnit: []string{userAndHostname},
|
OrganizationalUnit: []string{userAndHostname},
|
||||||
},
|
},
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub := priv.PublicKey
|
if m.client {
|
||||||
cert, err := x509.CreateCertificate(rand.Reader, tpl, m.caCert, &pub, m.caKey)
|
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
|
||||||
|
// Common Name in the UI. See issue #115.
|
||||||
|
if m.pkcs12 {
|
||||||
|
tpl.Subject.CommonName = hosts[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
cert, err := x509.CreateCertificate(rand.Reader, tpl, m.caCert, pub, m.caKey)
|
||||||
fatalIfErr(err, "failed to generate certificate")
|
fatalIfErr(err, "failed to generate certificate")
|
||||||
|
|
||||||
filename := strings.Replace(hosts[0], ":", "_", -1)
|
certFile, keyFile, p12File := m.fileNames(hosts)
|
||||||
filename = strings.Replace(filename, "*", "_wildcard", -1)
|
|
||||||
if len(hosts) > 1 {
|
|
||||||
filename += "+" + strconv.Itoa(len(hosts)-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !m.pkcs12 {
|
if !m.pkcs12 {
|
||||||
privDER, err := x509.MarshalPKCS8PrivateKey(priv)
|
privDER, err := x509.MarshalPKCS8PrivateKey(priv)
|
||||||
fatalIfErr(err, "failed to encode certificate key")
|
fatalIfErr(err, "failed to encode certificate key")
|
||||||
err = ioutil.WriteFile(filename+"-key.pem", pem.EncodeToMemory(
|
err = ioutil.WriteFile(keyFile, pem.EncodeToMemory(
|
||||||
&pem.Block{Type: "PRIVATE KEY", Bytes: privDER}), 0600)
|
&pem.Block{Type: "PRIVATE KEY", Bytes: privDER}), 0600)
|
||||||
fatalIfErr(err, "failed to save certificate key")
|
fatalIfErr(err, "failed to save certificate key")
|
||||||
|
|
||||||
err = ioutil.WriteFile(filename+".pem", pem.EncodeToMemory(
|
err = ioutil.WriteFile(certFile, pem.EncodeToMemory(
|
||||||
&pem.Block{Type: "CERTIFICATE", Bytes: cert}), 0644)
|
&pem.Block{Type: "CERTIFICATE", Bytes: cert}), 0644)
|
||||||
fatalIfErr(err, "failed to save certificate key")
|
fatalIfErr(err, "failed to save certificate")
|
||||||
} else {
|
} else {
|
||||||
domainCert, _ := x509.ParseCertificate(cert)
|
domainCert, _ := x509.ParseCertificate(cert)
|
||||||
pfxData, err := pkcs12.Encode(rand.Reader, priv, domainCert, []*x509.Certificate{m.caCert}, "changeit")
|
pfxData, err := pkcs12.Encode(rand.Reader, priv, domainCert, []*x509.Certificate{m.caCert}, "changeit")
|
||||||
fatalIfErr(err, "failed to generate PKCS#12")
|
fatalIfErr(err, "failed to generate PKCS#12")
|
||||||
err = ioutil.WriteFile(filename+".p12", pfxData, 0644)
|
err = ioutil.WriteFile(p12File, pfxData, 0644)
|
||||||
fatalIfErr(err, "failed to save PKCS#12")
|
fatalIfErr(err, "failed to save PKCS#12")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.printHosts(hosts)
|
||||||
|
|
||||||
|
if !m.pkcs12 {
|
||||||
|
log.Printf("\nThe certificate is at \"%s\" and the key at \"%s\" ✅\n\n", certFile, keyFile)
|
||||||
|
} else {
|
||||||
|
log.Printf("\nThe PKCS#12 bundle is at \"%s\" ✅\n", p12File)
|
||||||
|
log.Printf("\nThe legacy PKCS#12 encryption password is the often hardcoded default \"changeit\" ℹ️\n\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mkcert) printHosts(hosts []string) {
|
||||||
secondLvlWildcardRegexp := regexp.MustCompile(`(?i)^\*\.[0-9a-z_-]+$`)
|
secondLvlWildcardRegexp := regexp.MustCompile(`(?i)^\*\.[0-9a-z_-]+$`)
|
||||||
log.Printf("\nCreated a new certificate valid for the following names 📜")
|
log.Printf("\nCreated a new certificate valid for the following names 📜")
|
||||||
for _, h := range hosts {
|
for _, h := range hosts {
|
||||||
@@ -110,16 +146,119 @@ func (m *mkcert) makeCert(hosts []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !m.pkcs12 {
|
for _, h := range hosts {
|
||||||
log.Printf("\nThe certificate is at \"./%s.pem\" and the key at \"./%s-key.pem\" ✅\n\n", filename, filename)
|
if strings.HasPrefix(h, "*.") {
|
||||||
} else {
|
log.Printf("\nReminder: X.509 wildcards only go one level deep, so this won't match a.b.%s ℹ️", h[2:])
|
||||||
log.Printf("\nThe PKCS#12 bundle is at \"./%s.p12\" ✅\n\n", filename)
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mkcert) generateKey(rootCA bool) (crypto.PrivateKey, error) {
|
||||||
|
if m.ecdsa {
|
||||||
|
return ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
|
||||||
|
}
|
||||||
|
if rootCA {
|
||||||
|
return rsa.GenerateKey(rand.Reader, 3072)
|
||||||
|
}
|
||||||
|
return rsa.GenerateKey(rand.Reader, 2048)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mkcert) fileNames(hosts []string) (certFile, keyFile, p12File string) {
|
||||||
|
defaultName := strings.Replace(hosts[0], ":", "_", -1)
|
||||||
|
defaultName = strings.Replace(defaultName, "*", "_wildcard", -1)
|
||||||
|
if len(hosts) > 1 {
|
||||||
|
defaultName += "+" + strconv.Itoa(len(hosts)-1)
|
||||||
|
}
|
||||||
|
if m.client {
|
||||||
|
defaultName += "-client"
|
||||||
|
}
|
||||||
|
|
||||||
|
certFile = "./" + defaultName + ".pem"
|
||||||
|
if m.certFile != "" {
|
||||||
|
certFile = m.certFile
|
||||||
|
}
|
||||||
|
keyFile = "./" + defaultName + "-key.pem"
|
||||||
|
if m.keyFile != "" {
|
||||||
|
keyFile = m.keyFile
|
||||||
|
}
|
||||||
|
p12File = "./" + defaultName + ".p12"
|
||||||
|
if m.p12File != "" {
|
||||||
|
p12File = m.p12File
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func randomSerialNumber() *big.Int {
|
||||||
|
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
||||||
|
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
||||||
|
fatalIfErr(err, "failed to generate serial number")
|
||||||
|
return serialNumber
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mkcert) makeCertFromCSR() {
|
||||||
|
if m.caKey == nil {
|
||||||
|
log.Fatalln("ERROR: can't create new certificates because the CA key (rootCA-key.pem) is missing")
|
||||||
|
}
|
||||||
|
|
||||||
|
csrPEMBytes, err := ioutil.ReadFile(m.csrPath)
|
||||||
|
fatalIfErr(err, "failed to read the CSR")
|
||||||
|
csrPEM, _ := pem.Decode(csrPEMBytes)
|
||||||
|
if csrPEM == nil {
|
||||||
|
log.Fatalln("ERROR: failed to read the CSR: unexpected content")
|
||||||
|
}
|
||||||
|
if csrPEM.Type != "CERTIFICATE REQUEST" {
|
||||||
|
log.Fatalln("ERROR: failed to read the CSR: expected CERTIFICATE REQUEST, got " + csrPEM.Type)
|
||||||
|
}
|
||||||
|
csr, err := x509.ParseCertificateRequest(csrPEM.Bytes)
|
||||||
|
fatalIfErr(err, "failed to parse the CSR")
|
||||||
|
fatalIfErr(csr.CheckSignature(), "invalid CSR signature")
|
||||||
|
|
||||||
|
tpl := &x509.Certificate{
|
||||||
|
SerialNumber: randomSerialNumber(),
|
||||||
|
Subject: csr.Subject,
|
||||||
|
ExtraExtensions: csr.Extensions, // includes requested SANs
|
||||||
|
|
||||||
|
NotAfter: time.Now().AddDate(10, 0, 0),
|
||||||
|
NotBefore: time.Now(),
|
||||||
|
|
||||||
|
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
|
||||||
|
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
|
||||||
|
BasicConstraintsValid: true,
|
||||||
|
|
||||||
|
// If the CSR does not request a SAN extension, fix it up for them as
|
||||||
|
// the Common Name field does not work in modern browsers. Otherwise,
|
||||||
|
// this will get overridden.
|
||||||
|
DNSNames: []string{csr.Subject.CommonName},
|
||||||
|
}
|
||||||
|
|
||||||
|
cert, err := x509.CreateCertificate(rand.Reader, tpl, m.caCert, csr.PublicKey, m.caKey)
|
||||||
|
fatalIfErr(err, "failed to generate certificate")
|
||||||
|
|
||||||
|
var hosts []string
|
||||||
|
hosts = append(hosts, csr.DNSNames...)
|
||||||
|
hosts = append(hosts, csr.EmailAddresses...)
|
||||||
|
for _, ip := range csr.IPAddresses {
|
||||||
|
hosts = append(hosts, ip.String())
|
||||||
|
}
|
||||||
|
if len(hosts) == 0 {
|
||||||
|
hosts = []string{csr.Subject.CommonName}
|
||||||
|
}
|
||||||
|
certFile, _, _ := m.fileNames(hosts)
|
||||||
|
|
||||||
|
err = ioutil.WriteFile(certFile, pem.EncodeToMemory(
|
||||||
|
&pem.Block{Type: "CERTIFICATE", Bytes: cert}), 0644)
|
||||||
|
fatalIfErr(err, "failed to save certificate")
|
||||||
|
|
||||||
|
m.printHosts(hosts)
|
||||||
|
|
||||||
|
log.Printf("\nThe certificate is at \"%s\" ✅\n\n", certFile)
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
@@ -134,11 +273,11 @@ 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, keyName)); os.IsNotExist(err) {
|
if !pathExists(filepath.Join(m.CAROOT, rootKeyName)) {
|
||||||
return // keyless mode, where only -install works
|
return // keyless mode, where only -install works
|
||||||
}
|
}
|
||||||
|
|
||||||
keyPEMBlock, err := ioutil.ReadFile(filepath.Join(m.CAROOT, keyName))
|
keyPEMBlock, err := ioutil.ReadFile(filepath.Join(m.CAROOT, rootKeyName))
|
||||||
fatalIfErr(err, "failed to read the CA key")
|
fatalIfErr(err, "failed to read the CA key")
|
||||||
keyDERBlock, _ := pem.Decode(keyPEMBlock)
|
keyDERBlock, _ := pem.Decode(keyPEMBlock)
|
||||||
if keyDERBlock == nil || keyDERBlock.Type != "PRIVATE KEY" {
|
if keyDERBlock == nil || keyDERBlock.Type != "PRIVATE KEY" {
|
||||||
@@ -149,15 +288,11 @@ func (m *mkcert) loadCA() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mkcert) newCA() {
|
func (m *mkcert) newCA() {
|
||||||
priv, err := rsa.GenerateKey(rand.Reader, 3072)
|
priv, err := m.generateKey(true)
|
||||||
fatalIfErr(err, "failed to generate the CA key")
|
fatalIfErr(err, "failed to generate the CA key")
|
||||||
pub := priv.PublicKey
|
pub := priv.(crypto.Signer).Public()
|
||||||
|
|
||||||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
spkiASN1, err := x509.MarshalPKIXPublicKey(pub)
|
||||||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
|
||||||
fatalIfErr(err, "failed to generate serial number")
|
|
||||||
|
|
||||||
spkiASN1, err := x509.MarshalPKIXPublicKey(&pub)
|
|
||||||
fatalIfErr(err, "failed to encode public key")
|
fatalIfErr(err, "failed to encode public key")
|
||||||
|
|
||||||
var spki struct {
|
var spki struct {
|
||||||
@@ -170,7 +305,7 @@ func (m *mkcert) newCA() {
|
|||||||
skid := sha1.Sum(spki.SubjectPublicKey.Bytes)
|
skid := sha1.Sum(spki.SubjectPublicKey.Bytes)
|
||||||
|
|
||||||
tpl := &x509.Certificate{
|
tpl := &x509.Certificate{
|
||||||
SerialNumber: serialNumber,
|
SerialNumber: randomSerialNumber(),
|
||||||
Subject: pkix.Name{
|
Subject: pkix.Name{
|
||||||
Organization: []string{"mkcert development CA"},
|
Organization: []string{"mkcert development CA"},
|
||||||
OrganizationalUnit: []string{userAndHostname},
|
OrganizationalUnit: []string{userAndHostname},
|
||||||
@@ -192,12 +327,12 @@ func (m *mkcert) newCA() {
|
|||||||
MaxPathLenZero: true,
|
MaxPathLenZero: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
cert, err := x509.CreateCertificate(rand.Reader, tpl, tpl, &pub, priv)
|
cert, err := x509.CreateCertificate(rand.Reader, tpl, tpl, pub, priv)
|
||||||
fatalIfErr(err, "failed to generate CA certificate")
|
fatalIfErr(err, "failed to generate CA certificate")
|
||||||
|
|
||||||
privDER, err := x509.MarshalPKCS8PrivateKey(priv)
|
privDER, err := x509.MarshalPKCS8PrivateKey(priv)
|
||||||
fatalIfErr(err, "failed to encode CA key")
|
fatalIfErr(err, "failed to encode CA key")
|
||||||
err = ioutil.WriteFile(filepath.Join(m.CAROOT, keyName), pem.EncodeToMemory(
|
err = ioutil.WriteFile(filepath.Join(m.CAROOT, rootKeyName), pem.EncodeToMemory(
|
||||||
&pem.Block{Type: "PRIVATE KEY", Bytes: privDER}), 0400)
|
&pem.Block{Type: "PRIVATE KEY", Bytes: privDER}), 0400)
|
||||||
fatalIfErr(err, "failed to save CA key")
|
fatalIfErr(err, "failed to save CA key")
|
||||||
|
|
||||||
|
2
go.mod
2
go.mod
@@ -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
11
go.sum
@@ -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=
|
||||||
|
@@ -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
|
||||||
|
153
main.go
153
main.go
@@ -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,15 +12,19 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"net/mail"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"golang.org/x/net/idna"
|
"golang.org/x/net/idna"
|
||||||
)
|
)
|
||||||
|
|
||||||
const usage = `Usage of mkcert:
|
const shortUsage = `Usage of mkcert:
|
||||||
|
|
||||||
$ mkcert -install
|
$ mkcert -install
|
||||||
Install the local CA in the system trust store.
|
Install the local CA in the system trust store.
|
||||||
@@ -31,27 +35,72 @@ const usage = `Usage of mkcert:
|
|||||||
$ mkcert example.com myapp.dev localhost 127.0.0.1 ::1
|
$ mkcert example.com myapp.dev localhost 127.0.0.1 ::1
|
||||||
Generate "example.com+4.pem" and "example.com+4-key.pem".
|
Generate "example.com+4.pem" and "example.com+4-key.pem".
|
||||||
|
|
||||||
$ mkcert '*.example.com'
|
$ mkcert "*.example.it"
|
||||||
Generate "_wildcard.example.com.pem" and "_wildcard.example.com-key.pem".
|
Generate "_wildcard.example.it.pem" and "_wildcard.example.it-key.pem".
|
||||||
|
|
||||||
$ mkcert -pkcs12 example.com
|
|
||||||
Generate "example.com.p12" instead of a PEM file.
|
|
||||||
|
|
||||||
$ mkcert -uninstall
|
$ mkcert -uninstall
|
||||||
Uninstall the local CA (but do not delete it).
|
Uninstall the local CA (but do not delete it).
|
||||||
|
|
||||||
Change the CA certificate and key storage location by setting $CAROOT,
|
`
|
||||||
print it with "mkcert -CAROOT".
|
|
||||||
|
const advancedUsage = `Advanced options:
|
||||||
|
|
||||||
|
-cert-file FILE, -key-file FILE, -p12-file FILE
|
||||||
|
Customize the output paths.
|
||||||
|
|
||||||
|
-client
|
||||||
|
Generate a certificate for client authentication.
|
||||||
|
|
||||||
|
-ecdsa
|
||||||
|
Generate a certificate with an ECDSA key.
|
||||||
|
|
||||||
|
-pkcs12
|
||||||
|
Generate a ".p12" PKCS #12 file, also know as a ".pfx" file,
|
||||||
|
containing certificate and key for legacy applications.
|
||||||
|
|
||||||
|
-csr CSR
|
||||||
|
Generate a certificate based on the supplied CSR. Conflicts with
|
||||||
|
all other flags and arguments except -install and -cert-file.
|
||||||
|
|
||||||
|
-CAROOT
|
||||||
|
Print the CA certificate and key storage location.
|
||||||
|
|
||||||
|
$CAROOT (environment variable)
|
||||||
|
Set the CA certificate and key storage location. (This allows
|
||||||
|
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() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
var installFlag = flag.Bool("install", false, "install the local root CA in the system trust store")
|
var (
|
||||||
var uninstallFlag = flag.Bool("uninstall", false, "uninstall the local root CA from the system trust store")
|
installFlag = flag.Bool("install", false, "")
|
||||||
var pkcs12Flag = flag.Bool("pkcs12", false, "generate PKCS#12 instead of PEM")
|
uninstallFlag = flag.Bool("uninstall", false, "")
|
||||||
var carootFlag = flag.Bool("CAROOT", false, "print the CAROOT path")
|
pkcs12Flag = flag.Bool("pkcs12", false, "")
|
||||||
flag.Usage = func() { fmt.Fprintf(flag.CommandLine.Output(), usage) }
|
ecdsaFlag = flag.Bool("ecdsa", false, "")
|
||||||
|
clientFlag = flag.Bool("client", false, "")
|
||||||
|
helpFlag = flag.Bool("help", false, "")
|
||||||
|
carootFlag = flag.Bool("CAROOT", false, "")
|
||||||
|
csrFlag = flag.String("csr", "", "")
|
||||||
|
certFileFlag = flag.String("cert-file", "", "")
|
||||||
|
keyFileFlag = flag.String("key-file", "", "")
|
||||||
|
p12FileFlag = flag.String("p12-file", "", "")
|
||||||
|
)
|
||||||
|
flag.Usage = func() {
|
||||||
|
fmt.Fprint(flag.CommandLine.Output(), shortUsage)
|
||||||
|
fmt.Fprintln(flag.CommandLine.Output(), `For more options, run "mkcert -help".`)
|
||||||
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
if *helpFlag {
|
||||||
|
fmt.Fprint(flag.CommandLine.Output(), shortUsage)
|
||||||
|
fmt.Fprint(flag.CommandLine.Output(), advancedUsage)
|
||||||
|
return
|
||||||
|
}
|
||||||
if *carootFlag {
|
if *carootFlag {
|
||||||
if *installFlag || *uninstallFlag {
|
if *installFlag || *uninstallFlag {
|
||||||
log.Fatalln("ERROR: you can't set -[un]install and -CAROOT at the same time")
|
log.Fatalln("ERROR: you can't set -[un]install and -CAROOT at the same time")
|
||||||
@@ -62,17 +111,27 @@ func main() {
|
|||||||
if *installFlag && *uninstallFlag {
|
if *installFlag && *uninstallFlag {
|
||||||
log.Fatalln("ERROR: you can't set -install and -uninstall at the same time")
|
log.Fatalln("ERROR: you can't set -install and -uninstall at the same time")
|
||||||
}
|
}
|
||||||
|
if *csrFlag != "" && (*pkcs12Flag || *ecdsaFlag || *clientFlag) {
|
||||||
|
log.Fatalln("ERROR: can only combine -csr with -install and -cert-file")
|
||||||
|
}
|
||||||
|
if *csrFlag != "" && flag.NArg() != 0 {
|
||||||
|
log.Fatalln("ERROR: can't specify extra arguments when using -csr")
|
||||||
|
}
|
||||||
(&mkcert{
|
(&mkcert{
|
||||||
installMode: *installFlag, uninstallMode: *uninstallFlag, pkcs12: *pkcs12Flag,
|
installMode: *installFlag, uninstallMode: *uninstallFlag, csrPath: *csrFlag,
|
||||||
|
pkcs12: *pkcs12Flag, ecdsa: *ecdsaFlag, client: *clientFlag,
|
||||||
|
certFile: *certFileFlag, keyFile: *keyFileFlag, p12File: *p12FileFlag,
|
||||||
}).Run(flag.Args())
|
}).Run(flag.Args())
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootName = "rootCA.pem"
|
const rootName = "rootCA.pem"
|
||||||
const keyName = "rootCA-key.pem"
|
const rootKeyName = "rootCA-key.pem"
|
||||||
|
|
||||||
type mkcert struct {
|
type mkcert struct {
|
||||||
installMode, uninstallMode bool
|
installMode, uninstallMode bool
|
||||||
pkcs12 bool
|
pkcs12, ecdsa, client bool
|
||||||
|
keyFile, certFile, p12File string
|
||||||
|
csrPath string
|
||||||
|
|
||||||
CAROOT string
|
CAROOT string
|
||||||
caCert *x509.Certificate
|
caCert *x509.Certificate
|
||||||
@@ -102,15 +161,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! ⚠️")
|
||||||
}
|
}
|
||||||
@@ -119,8 +178,13 @@ func (m *mkcert) Run(args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.csrPath != "" {
|
||||||
|
m.makeCertFromCSR()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
log.Printf("\n%s", usage)
|
flag.Usage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,14 +241,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 == "" {
|
||||||
@@ -189,7 +259,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! ☕️")
|
||||||
@@ -204,7 +274,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 != "" {
|
||||||
@@ -214,7 +284,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 {
|
||||||
@@ -223,10 +293,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("")
|
||||||
}
|
}
|
||||||
@@ -241,6 +311,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)
|
||||||
@@ -252,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
|
||||||
|
}
|
||||||
|
@@ -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 (
|
||||||
|
@@ -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,25 +39,26 @@ 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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mkcert) checkJava() bool {
|
func (m *mkcert) checkJava() bool {
|
||||||
|
if !hasKeytool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// exists returns true if the given x509.Certificate's fingerprint
|
// exists returns true if the given x509.Certificate's fingerprint
|
||||||
// is in the keytool -list output
|
// is in the keytool -list output
|
||||||
exists := func(c *x509.Certificate, h hash.Hash, keytoolOutput []byte) bool {
|
exists := func(c *x509.Certificate, h hash.Hash, keytoolOutput []byte) bool {
|
||||||
@@ -108,7 +109,7 @@ func (m *mkcert) uninstallJava() {
|
|||||||
// the command wrapped in 'sudo' to work around file permissions.
|
// the command wrapped in 'sudo' to work around file permissions.
|
||||||
func (m *mkcert) execKeytool(cmd *exec.Cmd) ([]byte, error) {
|
func (m *mkcert) execKeytool(cmd *exec.Cmd) ([]byte, error) {
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil && bytes.Contains(out, []byte("java.io.FileNotFoundException")) {
|
if err != nil && bytes.Contains(out, []byte("java.io.FileNotFoundException")) && runtime.GOOS != "windows" {
|
||||||
origArgs := cmd.Args[1:]
|
origArgs := cmd.Args[1:]
|
||||||
cmd = exec.Command("sudo", keytoolPath)
|
cmd = exec.Command("sudo", keytoolPath)
|
||||||
cmd.Args = append(cmd.Args, origArgs...)
|
cmd.Args = append(cmd.Args, origArgs...)
|
||||||
|
@@ -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...)...)
|
||||||
|
@@ -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,38 +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
|
||||||
|
"/etc/pki/nssdb", // CentOS 7
|
||||||
|
}
|
||||||
|
firefoxPaths = []string{
|
||||||
|
"/usr/bin/firefox", "/Applications/Firefox.app",
|
||||||
|
"/Applications/Firefox Developer Edition.app",
|
||||||
|
"/Applications/Firefox Nightly.app",
|
||||||
|
"C:\\Program Files\\Mozilla Firefox",
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for _, path := range []string{
|
allPaths := append(append([]string{}, nssDBs...), firefoxPaths...)
|
||||||
"/usr/bin/firefox", nssDB, "/Applications/Firefox.app",
|
for _, path := range allPaths {
|
||||||
"/Applications/Firefox Developer Edition.app",
|
if pathExists(path) {
|
||||||
"C:\\Program Files\\Mozilla Firefox",
|
hasNSS = true
|
||||||
} {
|
break
|
||||||
_, err := os.Stat(path)
|
}
|
||||||
hasNSS = hasNSS || err == nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,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++
|
||||||
}
|
}
|
||||||
|
@@ -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 (
|
||||||
|
0
vendor/github.com/DHowett/go-plist/LICENSE → vendor/howett.net/plist/LICENSE
generated
vendored
0
vendor/github.com/DHowett/go-plist/LICENSE → vendor/howett.net/plist/LICENSE
generated
vendored
0
vendor/github.com/DHowett/go-plist/README.md → vendor/howett.net/plist/README.md
generated
vendored
0
vendor/github.com/DHowett/go-plist/README.md → vendor/howett.net/plist/README.md
generated
vendored
0
vendor/github.com/DHowett/go-plist/bplist.go → vendor/howett.net/plist/bplist.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/bplist.go → vendor/howett.net/plist/bplist.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/decode.go → vendor/howett.net/plist/decode.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/decode.go → vendor/howett.net/plist/decode.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/doc.go → vendor/howett.net/plist/doc.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/doc.go → vendor/howett.net/plist/doc.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/encode.go → vendor/howett.net/plist/encode.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/encode.go → vendor/howett.net/plist/encode.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/fuzz.go → vendor/howett.net/plist/fuzz.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/fuzz.go → vendor/howett.net/plist/fuzz.go
generated
vendored
9
vendor/howett.net/plist/go.mod
generated
vendored
Normal file
9
vendor/howett.net/plist/go.mod
generated
vendored
Normal 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
|
||||||
|
)
|
0
vendor/github.com/DHowett/go-plist/marshal.go → vendor/howett.net/plist/marshal.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/marshal.go → vendor/howett.net/plist/marshal.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/must.go → vendor/howett.net/plist/must.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/must.go → vendor/howett.net/plist/must.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/plist.go → vendor/howett.net/plist/plist.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/plist.go → vendor/howett.net/plist/plist.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/typeinfo.go → vendor/howett.net/plist/typeinfo.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/typeinfo.go → vendor/howett.net/plist/typeinfo.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/util.go → vendor/howett.net/plist/util.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/util.go → vendor/howett.net/plist/util.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/zerocopy.go → vendor/howett.net/plist/zerocopy.go
generated
vendored
0
vendor/github.com/DHowett/go-plist/zerocopy.go → vendor/howett.net/plist/zerocopy.go
generated
vendored
4
vendor/modules.txt
vendored
4
vendor/modules.txt
vendored
@@ -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
|
||||||
|
Reference in New Issue
Block a user