Skip to content

Commit 34ae31d

Browse files
honourfishjgough
andauthored
Ensure we use the correct curve for public key (#101)
re: AB#10116 Co-authored-by: jgough <[email protected]>
1 parent 0426bbf commit 34ae31d

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

azkeys/coseSigner.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ func base64BEtoBigInt(in string) (*big.Int, error) {
105105
}
106106

107107
// PublicKey returns the public key for this instance of CoseSignerKeyVault
108+
//
109+
// NOTE: Only valid for ECDSA
108110
func (kv *KeyVaultCoseSigner) PublicKey() (*ecdsa.PublicKey, error) {
109111
if kv.key.Key.X == nil || kv.key.Key.Y == nil {
110112
return nil, fmt.Errorf("public key is nil")
@@ -120,12 +122,23 @@ func (kv *KeyVaultCoseSigner) PublicKey() (*ecdsa.PublicKey, error) {
120122
return nil, fmt.Errorf("unable to convert Y %s: %w", *kv.key.Key.Y, err)
121123
}
122124

125+
var curve elliptic.Curve
126+
127+
switch kv.key.Key.Crv {
128+
case keyvault.P256:
129+
curve = elliptic.P256()
130+
case keyvault.P384:
131+
curve = elliptic.P384()
132+
case keyvault.P521:
133+
curve = elliptic.P521()
134+
default:
135+
return nil, fmt.Errorf("failed to find ecdsa curve for public key")
136+
}
137+
123138
return &ecdsa.PublicKey{
124-
Curve: &elliptic.CurveParams{
125-
Name: "P-384",
126-
},
127-
X: X,
128-
Y: Y,
139+
Curve: curve,
140+
X: X,
141+
Y: Y,
129142
}, nil
130143
}
131144

0 commit comments

Comments
 (0)