Skip to content

Commit

Permalink
Add endpoints for new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
starksm64 committed May 3, 2018
1 parent da822e3 commit 9a3c71b
Showing 1 changed file with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public JsonObject verifyKeyLocationAsPEMUrl() {
}

/**
* Verify that the injected key is a JWKS public key
* Verify that the injected key is a JWK public key
* @return json object for test result
*/
@GET
Expand Down Expand Up @@ -241,6 +241,42 @@ public JsonObject verifyKeyAsJWK(@QueryParam("kid") String kid) {
.build();
return result;
}

/**
* Verify that the injected key is a base64 encoded JWK public key
* @return json object for test result
*/
@GET
@Path("/verifyKeyAsBase64JWK")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("Tester")
public JsonObject verifyKeyAsBase64JWK(@QueryParam("kid") String kid) {
boolean pass = false;
String msg;

// Check that the key exists and is a valid base64 JWK public key
try {
String base64Jwk = key.get();
log.info("verifyKeyAsBase64JWK, base64Jwk="+base64Jwk);
byte[] data = Base64.getDecoder().decode(base64Jwk);
String jsonJwk = new String(data);
log.info("verifyKeyAsBase64JWK, jsonJwk="+jsonJwk);
StringBuilder msgBuilder = new StringBuilder();
JsonObject jwk = Json.createReader(new StringReader(jsonJwk)).readObject();
pass = verifyJWK(jwk, kid, msgBuilder);
msg = msgBuilder.toString();
}
catch (Exception e) {
msg = String.format("Failed to read key with exception: %s", e.getMessage());
}

JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}

/**
* Verify that the injected key is a JWKS public key
* @return json object for test result
Expand Down Expand Up @@ -271,6 +307,47 @@ public JsonObject verifyKeyAsJWKS(@QueryParam("kid") String kid) {
return result;
}

@GET
@Path("/verifyKeyLocationAsJWKResource")
@Produces(MediaType.APPLICATION_JSON)
@RolesAllowed("Tester")
public JsonObject verifyKeyLocationAsJWKResource(@QueryParam("kid") String kid) {
boolean pass = false;
String msg;
// Check the location exists and is a valid PEM public key
if(location.isPresent()) {
String locationValue = location.get();
log.info(String.format("verifyKeyLocationAsJWKResource, location=%s", locationValue));
try {
String jwkValue = SimpleTokenUtils.readResource(locationValue);
log.info(String.format("verifyKeyLocationAsJWKResource, locationValue=%s", jwkValue));
StringBuilder msgBuilder = new StringBuilder();
JsonObject jwk = Json.createReader(new StringReader(jwkValue)).readObject();
if(verifyJWK(jwk, kid, msgBuilder)) {
PublicKey publicKey = SimpleTokenUtils.decodeJWKSPublicKey(jwkValue);
log.info(String.format("verifyKeyLocationAsJWKResource, publicKey=%s", publicKey));
msg = "key location as resource to JWK PASS";
pass = true;
}
else {
msg = msgBuilder.toString();
}
}
catch (Exception e) {
msg = String.format("Failed to read key with exception: %s", e.getMessage());
}
}
else {
msg = "no location property injected";
}

JsonObject result = Json.createObjectBuilder()
.add("pass", pass)
.add("msg", msg)
.build();
return result;
}

@GET
@Path("/verifyKeyLocationAsJWKSResource")
@Produces(MediaType.APPLICATION_JSON)
Expand Down

0 comments on commit 9a3c71b

Please sign in to comment.