What version of Go are you using (go version)?
$ go version 1.19
What did you do?
In go 1.19 crypto/elliptic will now panic when operating on invalid curve points. This is great as it avoids undefined behavior, but crypto/x509 will now panic in marshalPublicKey in the case *ecdsa.PublicKey: where it previosly would return errors.New("x509: unsupported elliptic curve") as it calls elliptic.Marshal(pub.Curve, pub.X, pub.Y) before it checks oidFromNamedCurve(pub.Curve).
So simply switching those two calls around should fix the issue.
Meanwhile clients have to manually check if their key satisfies IsOnCurve before calling something like x509.MarshalPKIXPublicKey where in previous versions of go you could rely on an error being returned instead of a panic.
What version of Go are you using (
go version)?What did you do?
In go 1.19
crypto/ellipticwill now panic when operating on invalid curve points. This is great as it avoids undefined behavior, butcrypto/x509will now panic inmarshalPublicKeyin thecase *ecdsa.PublicKey:where it previosly would returnerrors.New("x509: unsupported elliptic curve")as it callselliptic.Marshal(pub.Curve, pub.X, pub.Y)before it checksoidFromNamedCurve(pub.Curve).So simply switching those two calls around should fix the issue.
Meanwhile clients have to manually check if their key satisfies
IsOnCurvebefore calling something likex509.MarshalPKIXPublicKeywhere in previous versions of go you could rely on an error being returned instead of a panic.