Skip to content

Commit

Permalink
x/ref/lib/security/keys/sshkeys: elliptic.Unmarshal deprecation (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
cosnicolaou authored Oct 9, 2024
1 parent ca2c6ae commit 61dac54
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions x/ref/lib/security/keys/sshkeys/agent_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,29 @@ func parseECDSAKey(key ssh.PublicKey) (*ecdsa.PublicKey, error) {
if err := ssh.Unmarshal(key.Marshal(), &sshWire); err != nil {
return nil, fmt.Errorf("failed to unmarshal key type: %v: %v", key.Type(), err)
}
pk := new(ecdsa.PublicKey)
switch sshWire.ID {
case "nistp256":
pk.Curve = elliptic.P256()
return &ecdsa.PublicKey{
Curve: elliptic.P256(),
X: big.NewInt(0).SetBytes(sshWire.Key[1:33]),
Y: big.NewInt(0).SetBytes(sshWire.Key[33:]),
}, nil
case "nistp384":
pk.Curve = elliptic.P384()
return &ecdsa.PublicKey{
Curve: elliptic.P384(),
X: big.NewInt(0).SetBytes(sshWire.Key[1:49]),
Y: big.NewInt(0).SetBytes(sshWire.Key[49:]),
}, nil
case "nistp521":
pk.Curve = elliptic.P521()
return &ecdsa.PublicKey{
Curve: elliptic.P521(),
X: big.NewInt(0).SetBytes(sshWire.Key[1:67]),
Y: big.NewInt(0).SetBytes(sshWire.Key[67:]),
}, nil
default:
return nil, fmt.Errorf("uncrecognised ecdsa curve: %v", sshWire.ID)
}
pk.X, pk.Y = elliptic.Unmarshal(pk.Curve, sshWire.Key) //nolint:staticcheck // deprecation of elliptic.Unmarshal
if pk.X == nil || pk.Y == nil {
return nil, fmt.Errorf("invalid curve point")
}
return pk, nil

}

// parseED25519Key creates an ed25519.PublicKey from an ssh ED25519 key.
Expand Down

0 comments on commit 61dac54

Please sign in to comment.