Skip to content
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

Support AES GCM KW algorithms for encrypting tokens #583

Merged
merged 1 commit into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public enum KeyEncryptionAlgorithm {
A128KW("A128KW"),
A192KW("A192KW"),
A256KW("A256KW"),
A128GCMKW("A128GCMKW"),
A192GCMKW("A192GCMKW"),
A256GCMKW("A256GCMKW"),
PBES2_HS256_A128KW("PBES2-HS256+A128KW"),
PBES2_HS384_A192KW("PBES2-HS384+A192KW"),
PBES2_HS512_A256KW("PBES2-HS512+A256KW");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,23 @@ public void testEncryptWithSecretKey() throws Exception {
checkJwtClaims(claims);
}

@Test
public void testEncryptWithSecretKeyAndGsmKeyWrap() throws Exception {
String jweCompact = Jwt.claims()
.claim("customClaim", "custom-value")
.jwe()
.keyId("key-enc-key-id")
.keyAlgorithm(KeyEncryptionAlgorithm.A256GCMKW)
.encrypt(createSecretKey());

checkJweHeaders(jweCompact, "A256GCMKW", 5);

JsonWebEncryption jwe = getJsonWebEncryption(jweCompact, createSecretKey());

JwtClaims claims = JwtClaims.parse(jwe.getPlaintextString());
checkJwtClaims(claims);
}

@Test
public void testEncryptWithSecret() throws Exception {
String secret = "AyM1SysPpbyDfgZld3umj1qzKObwVMko";
Expand Down Expand Up @@ -408,6 +425,10 @@ private static void checkJweHeaders(String jweCompact, String keyEncKeyAlg, Stri
if ("ECDH-ES+A256KW".equals(keyEncKeyAlg)) {
Assert.assertNotNull(jweHeaders.get("epk"));
}
if ("A256GCMKW".equals(keyEncKeyAlg)) {
Assert.assertNotNull(jweHeaders.get("iv"));
Assert.assertNotNull(jweHeaders.get("tag"));
}
}

private static void checkRsaEncJweHeaders(String jweCompact) throws Exception {
Expand Down