Skip to content
This repository was archived by the owner on Sep 21, 2023. It is now read-only.
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
4 changes: 3 additions & 1 deletion cmd/sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ func NewSignCommand() cli.Command {
Flags: []cli.Flag{
cli.StringFlag{"passphrase", "", "Passphrase to decrypt private-key PEM block of CA", ""},
cli.IntFlag{"years", 10, "How long until the certificate expires", ""},
cli.BoolTFlag{"server", "Allow server authentication", ""},
cli.BoolTFlag{"client", "Allow client authentication", ""},
},
Action: newSignAction,
}
Expand Down Expand Up @@ -72,7 +74,7 @@ func newSignAction(c *cli.Context) {
os.Exit(1)
}

crtHost, err := pkix.CreateCertificateHost(crt, info, key, csr, c.Int("years"))
crtHost, err := pkix.CreateCertificateHost(crt, info, key, csr, c.Int("years"), c.Bool("server"), c.Bool("client"))
if err != nil {
fmt.Fprintln(os.Stderr, "Create certificate error:", err)
os.Exit(1)
Expand Down
10 changes: 9 additions & 1 deletion pkix/cert_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var (

// CreateCertificateHost creates certificate for host.
// The arguments include CA certificate, CA certificate info, CA key, certificate request.
func CreateCertificateHost(crtAuth *Certificate, info *CertificateAuthorityInfo, keyAuth *Key, csr *CertificateSigningRequest, years int) (*Certificate, error) {
func CreateCertificateHost(crtAuth *Certificate, info *CertificateAuthorityInfo, keyAuth *Key, csr *CertificateSigningRequest, years int, serverAuth, clientAuth bool) (*Certificate, error) {
hostTemplate.SerialNumber.Set(info.SerialNumber)
info.IncSerialNumber()

Expand All @@ -73,6 +73,14 @@ func CreateCertificateHost(crtAuth *Certificate, info *CertificateAuthorityInfo,

hostTemplate.NotAfter = time.Now().AddDate(years, 0, 0).UTC()

hostTemplate.ExtKeyUsage = []x509.ExtKeyUsage{}
if serverAuth {
hostTemplate.ExtKeyUsage = append(hostTemplate.ExtKeyUsage, x509.ExtKeyUsageServerAuth)
}
if clientAuth {
hostTemplate.ExtKeyUsage = append(hostTemplate.ExtKeyUsage, x509.ExtKeyUsageClientAuth)
}

hostTemplate.SubjectKeyId, err = GenerateSubjectKeyId(rawCsr.PublicKey)
if err != nil {
return nil, err
Expand Down