risdenk commented on a change in pull request #195: KNOX-2126. Add an API to
retrieve the public key used for Knox JWT verification.
URL: https://github.com/apache/knox/pull/195#discussion_r346860463
##########
File path:
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java
##########
@@ -278,6 +284,39 @@ public Response revoke(String token) {
return resp;
}
+ @GET
+ @Path(PUBLIC_KEY_PATH)
+ @Produces ({APPLICATION_JSON})
+ public Response publicKey() {
+ GatewayServices services = (GatewayServices) request.getServletContext()
+ .getAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE);
+
+ KeystoreService ks = services.getService(ServiceType.KEYSTORE_SERVICE);
+
+ try {
+ PublicKey publicKey =
ks.getSigningKeystore().getCertificate(getSigningKeyAlias()).getPublicKey();
+ publicKey.getAlgorithm();
+ byte[] pubKeyBytes = publicKey.getEncoded();
+ String base64Key = Base64.encodeBase64String(pubKeyBytes);
+ Map<String, String> map = new HashMap<>();
+ map.put(PUBLIC_KEY, base64Key);
+ map.put(ALGORITHM, publicKey.getAlgorithm());
+
+ String jsonResponse = JsonUtils.renderAsJsonString(map);
+ return Response.ok().entity(jsonResponse).build();
+ } catch (KeyStoreException | KeystoreServiceException e) {
+ return Response.serverError().build();
+ // TODO: Look at serverError(). ... (Ref: ServiceDefinitionResource for
more info)
+ }
+ }
+
+ private String getSigningKeyAlias() {
Review comment:
I think the code already accounts for the `alias == null` case?
https://github.com/apache/knox/blame/master/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java#L749
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services