Add PKCS#12 generation with default password changeit

Merges #34
Fixes #20
This commit is contained in:
linux_china
2018-07-04 13:35:53 -07:00
committed by Filippo Valsorda
parent 53f1769ab5
commit 6be76ae477
3 changed files with 22 additions and 2 deletions

11
Gopkg.lock generated
View File

@@ -34,9 +34,18 @@
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
version = "v0.3.0" version = "v0.3.0"
[[projects]]
branch = "master"
name = "software.sslmate.com/src/go-pkcs12"
packages = [
".",
"internal/rc2"
]
revision = "2291e8f0f237e77e89ce233be7653ecca8cf391a"
[solve-meta] [solve-meta]
analyzer-name = "dep" analyzer-name = "dep"
analyzer-version = 1 analyzer-version = 1
inputs-digest = "eb8c5336b6da0643bb04cf921e8e61c2966555c879bc20533b060724d71667c6" inputs-digest = "af41b15413cbd854c23022d16f6da65af1235c9510e4193a17efef737de71c70"
solver-name = "gps-cdcl" solver-name = "gps-cdcl"
solver-version = 1 solver-version = 1

View File

@@ -36,3 +36,7 @@
[[constraint]] [[constraint]]
branch = "master" branch = "master"
name = "golang.org/x/net" name = "golang.org/x/net"
[[constraint]]
name = "software.sslmate.com/src/go-pkcs12"
branch = "master"

View File

@@ -21,6 +21,7 @@ import (
"os/user" "os/user"
"path/filepath" "path/filepath"
"regexp" "regexp"
"software.sslmate.com/src/go-pkcs12"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -91,6 +92,12 @@ func (m *mkcert) makeCert(hosts []string) {
&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 key")
// generate PKCS#12
domainCert, _ := x509.ParseCertificate(cert)
pfxData, _ := pkcs12.Encode(rand.Reader, priv, domainCert, []*x509.Certificate{m.caCert}, "changeit")
err = ioutil.WriteFile(filename+".p12", pfxData, 0644)
fatalIfErr(err, "failed to save PKCS#12")
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 {
@@ -99,7 +106,7 @@ func (m *mkcert) makeCert(hosts []string) {
log.Printf(" Warning: many browsers don't support second-level wildcards like %q ⚠️", h) log.Printf(" Warning: many browsers don't support second-level wildcards like %q ⚠️", h)
} }
} }
log.Printf("\nThe certificate is at \"./%s.pem\" and the key at \"./%s-key.pem\" ✅\n\n", filename, filename) log.Printf("\nThe certificate is at \"./%s.pem\", and the key at \"./%s-key.pem\", and the PKCS#12 at \"./%s.p12\" ✅\n\n", filename, filename, filename)
} }
// loadCA will load or create the CA at CAROOT. // loadCA will load or create the CA at CAROOT.