Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/ref/lib/security/keys/sshkeys: elliptic.Unmarshal deprecation #426

Merged
merged 1 commit into from
Oct 9, 2024
Merged
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
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
Loading