Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ACMEAccountService fixes/enhancements #4625

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
//
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
Loading