diff --git a/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEAccountService.java b/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEAccountService.java index b4d43fcf567..38db0b2c3dc 100644 --- a/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEAccountService.java +++ b/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEAccountService.java @@ -17,6 +17,8 @@ import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.UriInfo; +import com.fasterxml.jackson.core.JsonProcessingException; + import org.dogtagpki.acme.ACMEAccount; import org.dogtagpki.acme.ACMEHeader; import org.dogtagpki.acme.ACMENonce; @@ -74,7 +76,12 @@ public Response updateAccount(@PathParam("id") String accountID, JWS jws) throws String payload = new String(jws.getPayloadAsBytes(), "UTF-8"); logger.info("Payload: " + payload); - ACMEAccount update = ACMEAccount.fromJSON(payload); + ACMEAccount update; + try { + update = ACMEAccount.fromJSON(payload); + } catch (JsonProcessingException e) { + throw engine.createMalformedException(e.toString()); + } String newStatus = update.getStatus(); if (newStatus != null) { diff --git a/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEEngine.java b/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEEngine.java index 938c9b76f47..92a8baa99a5 100644 --- a/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEEngine.java +++ b/base/acme/src/main/java/org/dogtagpki/acme/server/ACMEEngine.java @@ -728,6 +728,18 @@ public Exception createAccountDoesNotExistException(String accountID) { return new WebApplicationException(builder.build()); } + public Exception createMalformedException(String desc) { + ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST); + builder.type("application/problem+json"); + + ACMEError error = new ACMEError(); + error.setType("urn:ietf:params:acme:error:malformed"); + error.setDetail("Malformed request: " + desc); + builder.entity(error); + + return new WebApplicationException(builder.build()); + } + public void updateAccount(ACMEAccount account) throws Exception { database.updateAccount(account); }