From 2d9249b6d9b57dea57b70357432bda945504c4b5 Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Tue, 29 Aug 2023 16:19:40 -0400 Subject: [PATCH] Replace deprecated `elliptic.Marshal` (#26800) In PR #26786, the Go version for golangci-lint is bumped to 1.21. This causes the following error: ``` models/migrations/v1_16/v210.go:132:23: SA1019: elliptic.Marshal has been deprecated since Go 1.21: for ECDH, use the crypto/ecdh package. This function returns an encoding equivalent to that of PublicKey.Bytes in crypto/ecdh. (staticcheck) PublicKey: elliptic.Marshal(elliptic.P256(), parsed.PubKey.X, parsed.PubKey.Y), ``` The change now uses [func (*PublicKey) ECDH](https://pkg.go.dev/crypto/ecdsa#PublicKey.ECDH), which is added in Go 1.20. --- models/migrations/v1_16/v210.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/models/migrations/v1_16/v210.go b/models/migrations/v1_16/v210.go index 4e55afccc1..533bb4bf80 100644 --- a/models/migrations/v1_16/v210.go +++ b/models/migrations/v1_16/v210.go @@ -4,7 +4,6 @@ package v1_16 //nolint import ( - "crypto/elliptic" "encoding/base32" "fmt" "strings" @@ -123,13 +122,17 @@ func RemigrateU2FCredentials(x *xorm.Engine) error { if err != nil { continue } + pubKey, err := parsed.PubKey.ECDH() + if err != nil { + continue + } remigrated := &webauthnCredential{ ID: reg.ID, Name: reg.Name, LowerName: strings.ToLower(reg.Name), UserID: reg.UserID, CredentialID: base32.HexEncoding.EncodeToString(parsed.KeyHandle), - PublicKey: elliptic.Marshal(elliptic.P256(), parsed.PubKey.X, parsed.PubKey.Y), + PublicKey: pubKey.Bytes(), AttestationType: "fido-u2f", AAGUID: []byte{}, SignCount: reg.Counter,