Skip to content

Commit

Permalink
tls: Stop using elliptic.Marshal
Browse files Browse the repository at this point in the history
It's been deprecated in go 1.21:
https://pkg.go.dev/crypto/elliptic#Marshal
> Deprecated: for ECDH, use the crypto/ecdh package. This function
> returns an encoding equivalent to that of PublicKey.Bytes in
> crypto/ecdh.

This fixes a `make lint` failure.
  • Loading branch information
cfergeau authored and praveenkumar committed May 23, 2024
1 parent 0a73631 commit 95bf3f4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pkg/crc/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tls
import (
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
Expand Down Expand Up @@ -133,7 +132,7 @@ func SignedCertificate(
return x509.ParseCertificate(certBytes)
}

// generateSubjectKeyID generates a SHA-1 hash of the subject public key.
// generateSubjectKeyID generates a SHA-256 hash of the subject public key.
func generateSubjectKeyID(pub crypto.PublicKey) ([]byte, error) {
var publicKeyBytes []byte
var err error
Expand All @@ -145,7 +144,11 @@ func generateSubjectKeyID(pub crypto.PublicKey) ([]byte, error) {
return nil, errors.Wrap(err, "failed to Marshal ans1 public key")
}
case *ecdsa.PublicKey:
publicKeyBytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y)
ecdhPubKey, err := pub.ECDH()
if err != nil {
return nil, errors.Wrap(err, "failed to get ECDH public key")
}
publicKeyBytes = ecdhPubKey.Bytes()
default:
return nil, errors.New("only RSA and ECDSA public keys supported")
}
Expand Down

0 comments on commit 95bf3f4

Please sign in to comment.