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..8c9f704cf5e 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; @@ -72,28 +74,40 @@ public Response updateAccount(@PathParam("id") String accountID, JWS jws) throws engine.validateJWS(jws, header.getAlg(), account.getJWK()); String payload = new String(jws.getPayloadAsBytes(), "UTF-8"); - logger.info("Payload: " + payload); - - ACMEAccount update = ACMEAccount.fromJSON(payload); - String newStatus = update.getStatus(); - if (newStatus != null) { - logger.info("New status: " + newStatus); - account.setStatus(newStatus); + if (payload.isEmpty()) { + logger.info("Empty payload; treating as POST-as-GET"); } - String[] newContact = update.getContact(); - if (newContact != null) { - logger.info("New contact:"); - for (String c : newContact) { - logger.info("- " + c); + else { + logger.info("Payload: " + payload); + + ACMEAccount update; + try { + update = ACMEAccount.fromJSON(payload); + } catch (JsonProcessingException e) { + throw engine.createMalformedException(e.toString()); } - account.setContact(newContact); - } - engine.updateAccount(account); + String newStatus = update.getStatus(); + if (newStatus != null) { + logger.info("New status: " + newStatus); + account.setStatus(newStatus); + } + + String[] newContact = update.getContact(); + if (newContact != null) { + logger.info("New contact:"); + for (String c : newContact) { + logger.info("- " + c); + } + account.setContact(newContact); + } - // TODO: if account is deactivated, cancel all account's pending operations + engine.updateAccount(account); + + // TODO: if account is deactivated, cancel all account's pending operations + } // RFC 8555 Section 7.1.2.1 Orders List // 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); }