fix: correct Ed25519 JWK thumbprint kty from "OTP" to "OKP"

Signed-off-by: Joonas Bergius <joonas@defenseunicorns.com>
This commit is contained in:
Joonas Bergius
2026-03-01 12:27:45 -06:00
parent ab67ffa0bd
commit 830758b5b2
2 changed files with 28 additions and 1 deletions

View File

@@ -90,7 +90,7 @@ func getJWKThumbprint(publickey crypto.PublicKey, skipED25519 bool) string {
}
x := base64.RawURLEncoding.EncodeToString(pubkey)
return hashAndEncode(fmt.Sprintf(`{"crv":"Ed25519","kty":"OTP","x":"%s"}`, x))
return hashAndEncode(fmt.Sprintf(`{"crv":"Ed25519","kty":"OKP","x":"%s"}`, x))
default:
return ""
}

View File

@@ -0,0 +1,27 @@
package token
import (
"crypto/ed25519"
"encoding/base64"
"testing"
)
func TestEd25519JWKThumbprint(t *testing.T) {
// Test vector from RFC 8037 Appendix A.2:
// https://datatracker.ietf.org/doc/html/rfc8037#appendix-A.2
examplePubKeyBase64 := "11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo"
// Canonical thumbprint from RFC 8037 Appendix A.3:
// https://datatracker.ietf.org/doc/html/rfc8037#appendix-A.3
expected := "kPrK_qmxVWaYVA9wwBF6Iuo3vVzz7TxHCTwXBygrS4k"
pubBytes, err := base64.RawURLEncoding.DecodeString(examplePubKeyBase64)
if err != nil {
t.Fatal(err)
}
publicKey := ed25519.PublicKey(pubBytes)
got := GetJWKThumbprint(publicKey)
if got != expected {
t.Errorf("GetJWKThumbprint(ed25519) = %q, expected %q", got, expected)
}
}