-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
136 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"time" | ||
|
||
"github.com/dvob/pcert" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func registerCertFlags(cmd *cobra.Command, certOpts *pcert.CertificateOptions) { | ||
bindCertFlags(cmd.Flags(), certOpts) | ||
|
||
_ = cmd.RegisterFlagCompletionFunc("sign-alg", signAlgorithmCompletionFunc) | ||
|
||
_ = cmd.RegisterFlagCompletionFunc("key-usage", keyUsageCompletionFunc) | ||
_ = cmd.RegisterFlagCompletionFunc("ext-key-usage", extKeyUsageCompletionFunc) | ||
} | ||
|
||
func bindCertFlags(fs *pflag.FlagSet, co *pcert.CertificateOptions) { | ||
// SAN | ||
fs.StringSliceVar(&co.DNSNames, "dns", []string{}, "DNS subject alternative name.") | ||
fs.StringSliceVar(&co.EmailAddresses, "email", []string{}, "Email subject alternative name.") | ||
fs.IPSliceVar(&co.IPAddresses, "ip", []net.IP{}, "IP subject alternative name.") | ||
fs.Var(newURISliceValue(&co.URIs), "uri", "URI subject alternative name.") | ||
|
||
// signature algorithm | ||
fs.Var(newSignAlgValue(&co.SignatureAlgorithm), "sign-alg", "Signature Algorithm. See 'pcert list' for available algorithms.") | ||
|
||
// validity duration | ||
fs.Var(newTimeValue(&co.NotBefore), "not-before", fmt.Sprintf("Not valid before time in RFC3339 format (e.g. '%s').", time.Now().UTC().Format(time.RFC3339))) | ||
fs.Var(newTimeValue(&co.NotAfter), "not-after", fmt.Sprintf("Not valid after time in RFC3339 format (e.g. '%s').", time.Now().Add(time.Hour*24*60).UTC().Format(time.RFC3339))) | ||
fs.Var(newDurationValue(&co.Expiry), "expiry", "Validity period of the certificate. If --not-after is set this option has no effect.") | ||
|
||
// subject | ||
fs.Var(newSubjectValue(&co.Subject), "subject", "Subject in the form '/C=CH/O=My Org/OU=My Team'.") | ||
bindSubjectFlags(fs, &co.Subject) | ||
|
||
// basic constraints | ||
fs.BoolVar(&co.BasicConstraintsValid, "basic-constraints", co.BasicConstraintsValid, "Add basic constraints extension.") | ||
fs.BoolVar(&co.IsCA, "is-ca", co.IsCA, "Mark certificate as CA in the basic constraints. Only takes effect if --basic-constraints is true.") | ||
fs.Var(newMaxPathLengthValue(co.MaxPathLen), "max-path-length", "Sets the max path length in the basic constraints.") | ||
|
||
// key usage | ||
fs.Var(newKeyUsageValue(&co.KeyUsage), "key-usage", "Set the key usage. See 'pcert list' for available key usages.") | ||
fs.Var(newExtKeyUsageValue(&co.ExtKeyUsage), "ext-key-usage", "Set the extended key usage. See 'pcert list' for available extended key usages.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/dvob/pcert" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func registerKeyFlags(cmd *cobra.Command, keyOpts *pcert.KeyOptions) { | ||
bindKeyFlags(cmd.Flags(), keyOpts) | ||
|
||
_ = cmd.RegisterFlagCompletionFunc("key-alg", keyAlgorithmCompletionFunc) | ||
} | ||
|
||
func bindKeyFlags(fs *pflag.FlagSet, keyOptions *pcert.KeyOptions) { | ||
fs.Var(newKeyAlgorithmValue(&keyOptions.Algorithm), "key-alg", "Public key algorithm. See 'pcert list' for available algorithms.") | ||
fs.IntVar(&keyOptions.Size, "key-size", keyOptions.Size, "Key Size. This defaults to 256 for ECDSA and to 2048 for RSA.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"strconv" | ||
) | ||
|
||
type maxPathLengthValue struct { | ||
cert *x509.Certificate | ||
maxPathLen *int | ||
} | ||
|
||
func newMaxPathLengthValue(c *x509.Certificate) *maxPathLengthValue { | ||
func newMaxPathLengthValue(maxPathLen *int) *maxPathLengthValue { | ||
return &maxPathLengthValue{ | ||
cert: c, | ||
maxPathLen: maxPathLen, | ||
} | ||
} | ||
|
||
func (m *maxPathLengthValue) Type() string { | ||
return "int|none" | ||
return "int|-" | ||
} | ||
|
||
func (m *maxPathLengthValue) String() string { | ||
if m.cert.MaxPathLen < 0 { | ||
return "none" | ||
if m.maxPathLen == nil { | ||
return "-" | ||
} | ||
if m.cert.MaxPathLen == 0 && !m.cert.MaxPathLenZero { | ||
return "none" | ||
} | ||
return strconv.Itoa(m.cert.MaxPathLen) | ||
return strconv.Itoa(*m.maxPathLen) | ||
} | ||
|
||
func (m *maxPathLengthValue) Set(length string) error { | ||
var err error | ||
if length == "none" { | ||
m.cert.MaxPathLen = -1 | ||
return nil | ||
if length == "-" { | ||
m.maxPathLen = nil | ||
} | ||
|
||
m.cert.MaxPathLen, err = strconv.Atoi(length) | ||
return err | ||
value, err := strconv.Atoi(length) | ||
if err != nil { | ||
return err | ||
} | ||
m.maxPathLen = &value | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/x509" | ||
"net" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
func registerRequestFlags(cmd *cobra.Command, csr *x509.CertificateRequest) { | ||
bindRequestFlags(cmd.Flags(), csr) | ||
|
||
_ = cmd.RegisterFlagCompletionFunc("sign-alg", signAlgorithmCompletionFunc) | ||
} | ||
|
||
func bindRequestFlags(fs *pflag.FlagSet, csr *x509.CertificateRequest) { | ||
fs.StringSliceVar(&csr.DNSNames, "dns", []string{}, "DNS subject alternative name.") | ||
fs.StringSliceVar(&csr.EmailAddresses, "email", []string{}, "Email subject alternative name.") | ||
fs.IPSliceVar(&csr.IPAddresses, "ip", []net.IP{}, "IP subject alternative name.") | ||
fs.Var(newURISliceValue(&csr.URIs), "uri", "URI subject alternative name.") | ||
fs.Var(newSignAlgValue(&csr.SignatureAlgorithm), "sign-alg", "Signature Algorithm. See 'pcert list' for available algorithms.") | ||
fs.Var(newSubjectValue(&csr.Subject), "subject", "Subject in the form '/C=CH/O=My Org/OU=My Team'.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters