Skip to content

Commit

Permalink
switch to JSON for new verify API response
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 1, 2024
1 parent c902001 commit f632cd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ Standard attestation message in the same format as the Auditor app QR code.

* Response body:

Returns space-separated values in plain text: `<subscribeKey> <verifyInterval>`. Additional fields
may be added in the future.
Returns JSON with a verifyInterval field.

## Logging

Expand Down
23 changes: 18 additions & 5 deletions src/main/java/app/attestation/server/AttestationServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,8 @@ public void handlePost(final HttpExchange exchange) throws IOException {
private static class VerifyHandler extends AppPostHandler {
@Override
public void handlePost(final HttpExchange exchange) throws IOException, SQLiteException {
final boolean legacy = exchange.getRequestURI().toString().equals("/verify");

String authorization = null;
try {
authorization = getRequestHeaderValue(exchange, "Authorization");
Expand Down Expand Up @@ -1669,11 +1671,22 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
return;
}

final byte[] result = (BaseEncoding.base64().encode(currentSubscribeKey) + " " +
verifyInterval).getBytes();
exchange.sendResponseHeaders(200, result.length);
try (final OutputStream output = exchange.getResponseBody()) {
output.write(result);
if (legacy) {
final byte[] result = (BaseEncoding.base64().encode(currentSubscribeKey) + " " +
verifyInterval).getBytes();
exchange.sendResponseHeaders(200, result.length);
try (final OutputStream output = exchange.getResponseBody()) {
output.write(result);
}
} else {
final JsonObjectBuilder result = Json.createObjectBuilder();
result.add("verifyInterval", verifyInterval);
exchange.getResponseHeaders().set("Content-Type", "application/json");
exchange.sendResponseHeaders(200, 0);
try (final OutputStream output = exchange.getResponseBody();
final JsonWriter writer = Json.createWriter(output)) {
writer.write(result.build());
}
}
}
}
Expand Down

0 comments on commit f632cd3

Please sign in to comment.