-
Notifications
You must be signed in to change notification settings - Fork 22
Implement io.jwt.verify_eddsa builtin (closes #145) #153
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
Merged
sspaink
merged 4 commits into
open-policy-agent:main
from
ume3445:implement-jwt-verify-eddsa
Aug 11, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
5391236
Implement io.jwt.verify_eddsa builtin (closes #145)
ume3445 4fb00ae
Address review: support Ed25519 (OKP) JWKs in extractPublicKey
ume3445 cf4a574
Merge branch 'main' into implement-jwt-verify-eddsa
sspaink 6d55983
Fixup into 4fb00ae: import Curve/OctetKeyPair, drop ratchet entry
sspaink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...t/java/io/github/open_policy_agent/opa/ast/builtin/impls/TokenBuiltinsEd25519JwkTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package io.github.open_policy_agent.opa.ast.builtin.impls; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
|
|
||
| import io.github.open_policy_agent.opa.ast.types.RegoBoolean; | ||
| import io.github.open_policy_agent.opa.ast.types.RegoString; | ||
| import io.github.open_policy_agent.opa.ast.types.RegoValue; | ||
| import io.github.open_policy_agent.opa.rego.EvaluationContext; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Covers the JWK (OKP / Ed25519) path for {@code io.jwt.verify_eddsa}, which is not exercised by | ||
| * compliance fixtures (those only use PEM public keys for verify_eddsa). | ||
| */ | ||
| public class TokenBuiltinsEd25519JwkTest { | ||
|
|
||
| // From jwtencodesign/test-jwtencodesign-eddsa.json | ||
| private static final String PRIVATE_JWK = | ||
| "{\"kty\":\"OKP\",\"alg\":\"EdDSA\",\"crv\":\"Ed25519\"," | ||
| + "\"x\":\"wEZFfoAj1rFKTLOOmjJjVZlCHwksuvMb2I5y_hg70E8\"," | ||
| + "\"d\":\"9XI34uQzYUJfWhDZf_0nYsLMBRVu8a6dFsy60P8uugk\"}"; | ||
|
|
||
| private static final String PUBLIC_JWK = | ||
| "{\"kty\":\"OKP\",\"crv\":\"Ed25519\"," | ||
| + "\"x\":\"wEZFfoAj1rFKTLOOmjJjVZlCHwksuvMb2I5y_hg70E8\"}"; | ||
|
|
||
| // Different Ed25519 public key (same length, wrong material) | ||
| private static final String WRONG_PUBLIC_JWK = | ||
| "{\"kty\":\"OKP\",\"crv\":\"Ed25519\"," | ||
| + "\"x\":\"11qYAYKxCrfVS_7TyWQHOg7hcvPapiMlrwIaaPcHURo\"}"; | ||
|
|
||
| private static final String HEADERS = "{\"alg\":\"EdDSA\",\"typ\":\"JWT\"}"; | ||
| private static final String PAYLOAD = | ||
| "{\"iss\":\"joe\",\"exp\":1300819380,\"http://example.com/is_root\":true}"; | ||
|
|
||
| private final TokenBuiltins builtins = new TokenBuiltins(); | ||
| private final EvaluationContext ctx = new EvaluationContext.Builder().build(); | ||
|
|
||
| @Test | ||
| public void verifyEddsaWithMatchingPublicJwkReturnsTrue() { | ||
| RegoString jwt = | ||
| builtins.encodeSignRaw( | ||
| ctx, | ||
| new RegoValue[] { | ||
| new RegoString(HEADERS), new RegoString(PAYLOAD), new RegoString(PRIVATE_JWK) | ||
| }); | ||
|
|
||
| RegoBoolean result = | ||
| builtins.verifyEdDSA( | ||
| ctx, new RegoValue[] {jwt, new RegoString(PUBLIC_JWK)}); | ||
|
|
||
| assertEquals(RegoBoolean.TRUE, result); | ||
| } | ||
|
|
||
| @Test | ||
| public void verifyEddsaWithMismatchedPublicJwkReturnsFalse() { | ||
| RegoString jwt = | ||
| builtins.encodeSignRaw( | ||
| ctx, | ||
| new RegoValue[] { | ||
| new RegoString(HEADERS), new RegoString(PAYLOAD), new RegoString(PRIVATE_JWK) | ||
| }); | ||
|
|
||
| RegoBoolean result = | ||
| builtins.verifyEdDSA( | ||
| ctx, new RegoValue[] {jwt, new RegoString(WRONG_PUBLIC_JWK)}); | ||
|
|
||
| assertInstanceOf(RegoBoolean.class, result); | ||
| assertEquals(RegoBoolean.FALSE, result); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,8 +54,6 @@ http.send | |
|
|
||
| internal.template_string | ||
|
|
||
| io.jwt.verify_eddsa | ||
|
|
||
| rego.parse_module | ||
|
|
||
| strings.render_template | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_verifyEdDSAreachesgetPublicKey→extractPublicKey, which only handlesRSAKeyandECKey. An Ed25519 JWK parses to anOctetKeyPair(kty: OKP), so it falls into theelsebranch and throws"Unsupported JWK key type"— meaning this returnsfalse(or errors in strict mode) for a valid Ed25519 JWK, even though the arg doc here advertises "the JWK key (set)".This diverges from OPA: its
getKeysFromCertOrJWK(v1/topdown/tokens.go) parses JWKs via jwx'sjwk.Export, which supports OKP keys, so OPA accepts an Ed25519 JWK forio.jwt.verify_eddsa. For parity, consider adding an OKP branch toextractPublicKey(convertOctetKeyPair→ Ed25519PublicKey) rather than only supporting the PEM path. The added test only covers the PEM cert fixture, so the JWK path is untested for EdDSA.