Skip to content

Commit

Permalink
acme: return proper error on malformed account payload
Browse files Browse the repository at this point in the history
ACMEAccountService currently throws an uncaught exception if decode
the account object payload fails.  This results in the server
responding 500 Internal Server Error.  Respond with status 400 and
a proper problem document instead.
  • Loading branch information
frasertweedale authored and fmarco76 committed Nov 30, 2023
1 parent 93c666e commit daffa76
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions base/acme/src/main/java/org/dogtagpki/acme/server/ACMEEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit daffa76

Please sign in to comment.