Skip to content

Commit

Permalink
Merge pull request #103 from Venafi/ecdsa-curve-default-value
Browse files Browse the repository at this point in the history
fix #102
  • Loading branch information
mr-tron authored Apr 21, 2020
2 parents b5e2214 + 114e6d8 commit dd32326
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cmd/vcert/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,9 @@ func generateCsrForCommandGenCsr(cf *commandFlags, privateKeyPass []byte) (priva
certReq.KeyType = *cf.keyType
}
certReq.KeyLength = cf.keySize
certReq.KeyCurve = cf.keyCurve
if cf.keyCurve != certificate.EllipticCurveNotSet {
certReq.KeyCurve = cf.keyCurve
}
err = certReq.GeneratePrivateKey()
if err != nil {
return
Expand Down
8 changes: 6 additions & 2 deletions cmd/vcert/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func fillCertificateRequest(req *certificate.Request, cf *commandFlags) *certifi
} else if req.KeyLength == 0 {
req.KeyLength = 2048
}
req.KeyCurve = cf.keyCurve
if cf.keyCurve != certificate.EllipticCurveNotSet {
req.KeyCurve = cf.keyCurve
}
req.CsrOrigin = certificate.ServiceGeneratedCSR

default: // "local" == cf.csrOption:
Expand All @@ -141,7 +143,9 @@ func fillCertificateRequest(req *certificate.Request, cf *commandFlags) *certifi
} else if req.KeyLength == 0 {
req.KeyLength = 2048
}
req.KeyCurve = cf.keyCurve
if cf.keyCurve != certificate.EllipticCurveNotSet {
req.KeyCurve = cf.keyCurve
}
req.CsrOrigin = certificate.LocalGeneratedCSR
}
return req
Expand Down
2 changes: 1 addition & 1 deletion cmd/vcert/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func validateCommonFlags(commandName string) error {
return fmt.Errorf("unknown key type: %s", flags.keyTypeString)
}

switch flags.keyCurveString {
switch strings.ToLower(flags.keyCurveString) {
case "p256":
flags.keyCurve = certificate.EllipticCurveP256
case "p384":
Expand Down
7 changes: 5 additions & 2 deletions pkg/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ func (ec *EllipticCurve) Set(value string) error {
}

const (
EllipticCurveNotSet EllipticCurve = iota
// EllipticCurveP521 represents the P521 curve
EllipticCurveP521 EllipticCurve = iota
EllipticCurveP521
// EllipticCurveP256 represents the P256 curve
EllipticCurveP256
// EllipticCurveP384 represents the P384 curve
Expand Down Expand Up @@ -451,7 +452,9 @@ func GenerateECDSAPrivateKey(curve EllipticCurve) (*ecdsa.PrivateKey, error) {
var priv *ecdsa.PrivateKey
var c elliptic.Curve
var err error

if curve == EllipticCurveNotSet {
curve = EllipticCurveDefault
}
switch curve {
case EllipticCurveP521:
c = elliptic.P521()
Expand Down
4 changes: 2 additions & 2 deletions pkg/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,9 @@ func (z *ZoneConfiguration) UpdateCertificateRequest(request *certificate.Reques
foundMatch = true
switch request.KeyType {
case certificate.KeyTypeECDSA:
if len(keyConf.KeyCurves) != 0 {
if len(keyConf.KeyCurves) != 0 && request.KeyCurve == certificate.EllipticCurveNotSet {
request.KeyCurve = keyConf.KeyCurves[0]
} else {
} else if request.KeyCurve == certificate.EllipticCurveNotSet {
request.KeyCurve = certificate.EllipticCurveDefault
}
case certificate.KeyTypeRSA:
Expand Down

0 comments on commit dd32326

Please sign in to comment.