Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom parameters: ca-xx and cert-xxx #616

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 36 additions & 7 deletions cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,28 @@ func (m *mkcert) makeCert(hosts []string) {
// Certificates last for 2 years and 3 months, which is always less than
// 825 days, the limit that macOS/iOS apply to all certificates,
// including custom roots. See https://support.apple.com/en-us/HT210176.
expiration := time.Now().AddDate(2, 3, 0)
expiration := time.Now().AddDate(0, 0, m.certDays)

certOrg := "mkcert development certificate"
certOrgUnit := userAndHostname
certCommonName := hosts[0]

if m.certOrg != "" {
certOrg = m.certOrg
}
if m.certOrgUnit != "" {
certOrgUnit = m.certOrgUnit
}
if m.certCommonName != "" {
certCommonName = m.certCommonName
}

tpl := &x509.Certificate{
SerialNumber: randomSerialNumber(),
Subject: pkix.Name{
Organization: []string{"mkcert development certificate"},
OrganizationalUnit: []string{userAndHostname},
Organization: []string{certOrg},
OrganizationalUnit: []string{certOrgUnit},
CommonName: certCommonName,
},

NotBefore: time.Now(), NotAfter: expiration,
Expand Down Expand Up @@ -324,20 +339,34 @@ func (m *mkcert) newCA() {

skid := sha1.Sum(spki.SubjectPublicKey.Bytes)

caOrg := "mkcert development CA"
caOrgUnit := userAndHostname
caCommonName := "mkcert " + userAndHostname

if m.caOrg != "" {
caOrg = m.caOrg
}
if m.caOrgUnit != "" {
caOrgUnit = m.caOrgUnit
}
if m.caCommonName != "" {
caCommonName = m.caCommonName
}

tpl := &x509.Certificate{
SerialNumber: randomSerialNumber(),
Subject: pkix.Name{
Organization: []string{"mkcert development CA"},
OrganizationalUnit: []string{userAndHostname},
Organization: []string{caOrg},
OrganizationalUnit: []string{caOrgUnit},

// The CommonName is required by iOS to show the certificate in the
// "Certificate Trust Settings" menu.
// https://github.com/FiloSottile/mkcert/issues/47
CommonName: "mkcert " + userAndHostname,
CommonName: caCommonName,
},
SubjectKeyId: skid[:],

NotAfter: time.Now().AddDate(10, 0, 0),
NotAfter: time.Now().AddDate(m.caYears, 0, 0),
NotBefore: time.Now(),

KeyUsage: x509.KeyUsageCertSign,
Expand Down
17 changes: 17 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ func main() {
certFileFlag = flag.String("cert-file", "", "")
keyFileFlag = flag.String("key-file", "", "")
p12FileFlag = flag.String("p12-file", "", "")
// certInfo
certOrgFlag = flag.String("cert-org", "", "")
certOrgUnitFlag = flag.String("cert-orgUnit", "", "")
certCommonNameFlag = flag.String("cert-commonName", "", "")
certDaysFlag = flag.Int("ca-days", 825, "")
// caInfo
caOrgFlag = flag.String("ca-org", "", "")
caOrgUnitFlag = flag.String("ca-orgUnit", "", "")
caCommonNameFlag = flag.String("ca-commonName", "", "")
caYearsFlag = flag.Int("ca-years", 10, "")

versionFlag = flag.Bool("version", false, "")
)
flag.Usage = func() {
Expand Down Expand Up @@ -146,6 +157,8 @@ func main() {
installMode: *installFlag, uninstallMode: *uninstallFlag, csrPath: *csrFlag,
pkcs12: *pkcs12Flag, ecdsa: *ecdsaFlag, client: *clientFlag,
certFile: *certFileFlag, keyFile: *keyFileFlag, p12File: *p12FileFlag,
certOrg: *certOrgFlag, certOrgUnit: *certOrgUnitFlag, certCommonName: *certCommonNameFlag, certDays: *certDaysFlag,
caOrg: *caOrgFlag, caOrgUnit: *caOrgUnitFlag, caCommonName: *caCommonNameFlag, caYears: *caYearsFlag,
}).Run(flag.Args())
}

Expand All @@ -156,6 +169,10 @@ type mkcert struct {
installMode, uninstallMode bool
pkcs12, ecdsa, client bool
keyFile, certFile, p12File string
certOrg, certOrgUnit, certCommonName string
certDays int
caOrg, caOrgUnit, caCommonName string
caYears int
csrPath string

CAROOT string
Expand Down