Using only JWKS configuration with custom URL protocol handlers...

22 views
Skip to first unread message

Scott Stark

unread,
Apr 18, 2018, 10:04:12 PM4/18/18
to Eclipse MicroProfile
In our last call there was some concern about the burden the use of JWKS configuration as a URL would impose on deployments. Previously there was also concern about having to support PEM keys bundled in applications. One way to potentially address both concerns would be include support for custom URL protocol handlers as part of the configuration changes. I have added tests in the sandbox that illustrate how this would work:

/**
* Validate that the jwks: protocol handler works
* @throws Exception on failure
*/
@Test
public void testJwksURL() throws Exception {
// Load the /signer-keyset.jwk JWKS resource from the classpath as a JWKS
URL signerJwk = new URL("jwks:/signer-keyset.jwk");
String signerJwksContent = signerJwk.getContent().toString();
System.out.println(signerJwksContent);
JsonObject jwks = Json.createReader(new StringReader(signerJwksContent)).readObject();
JsonArray keys = jwks.getJsonArray("keys");
JsonObject key = keys.getJsonObject(0);
Assert.assertEquals(key.getJsonString("kty").getString(), "RSA");
Assert.assertEquals(key.getJsonString("use").getString(), "sig");
Assert.assertEquals(key.getJsonString("kid").getString(), "jwk-test");
Assert.assertEquals(key.getJsonString("alg").getString(), "RS256");
Assert.assertEquals(key.getJsonString("e").getString(), "AQAB");
Assert.assertTrue(key.getJsonString("n").getString().startsWith("uGU_nmjYC7cKRR89NCAo"));
}
/**
* Validate that the pemjwks: protocol handler works
* @throws Exception on failure
*/
@Test
public void testPemJwksURL() throws Exception {
// Load the /publicKey.pem PEM encoded public key resource from the classpath as a JWKS
URL signerJwk = new URL("pemjwks:/publicKey.pem?kid=pem-test");
String signerJwksContent = signerJwk.getContent().toString();
System.out.println(signerJwksContent);
JsonObject jwks = Json.createReader(new StringReader(signerJwksContent)).readObject();
JsonArray keys = jwks.getJsonArray("keys");
JsonObject key = keys.getJsonObject(0);
Assert.assertEquals(key.getJsonString("kty").getString(), "RSA");
Assert.assertEquals(key.getJsonString("use").getString(), "sig");
Assert.assertEquals(key.getJsonString("kid").getString(), "pem-test");
Assert.assertEquals(key.getJsonString("alg").getString(), "RS256");
Assert.assertEquals(key.getJsonString("e").getString(), "AQAB");
Assert.assertTrue(key.getJsonString("n").getString().startsWith("livFI8qB4D0y2jy0Cf"));
}


What do you think of this as a way of supporting both embedded and remote public keys?

Rudy De Busscher

unread,
Apr 19, 2018, 4:16:55 PM4/19/18
to Eclipse MicroProfile
I like the idea of how you can add the kid value for a PEM.

Although you could in theory just try to load the resource as each format (and ignore the errors), being explicit on the type through the protocol is very clear in what you expect to load.

Rudy
Reply all
Reply to author
Forward
0 new messages