Skip to content

Commit 5ca75d1

Browse files
committed
switch to JSON for new verify API response
1 parent e29ec1d commit 5ca75d1

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ Standard attestation message in the same format as the Auditor app QR code.
124124

125125
* Response body:
126126

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

130129
## Logging
131130

src/main/java/app/attestation/server/AttestationServer.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,8 @@ public void handlePost(final HttpExchange exchange) throws IOException {
16061606
private static class VerifyHandler extends AppPostHandler {
16071607
@Override
16081608
public void handlePost(final HttpExchange exchange) throws IOException, SQLiteException {
1609+
final boolean legacy = exchange.getRequestURI().toString().equals("/verify");
1610+
16091611
String authorization = null;
16101612
try {
16111613
authorization = getRequestHeaderValue(exchange, "Authorization");
@@ -1669,11 +1671,22 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx
16691671
return;
16701672
}
16711673

1672-
final byte[] result = (BaseEncoding.base64().encode(currentSubscribeKey) + " " +
1673-
verifyInterval).getBytes();
1674-
exchange.sendResponseHeaders(200, result.length);
1675-
try (final OutputStream output = exchange.getResponseBody()) {
1676-
output.write(result);
1674+
if (legacy) {
1675+
final byte[] result = (BaseEncoding.base64().encode(currentSubscribeKey) + " " +
1676+
verifyInterval).getBytes();
1677+
exchange.sendResponseHeaders(200, result.length);
1678+
try (final OutputStream output = exchange.getResponseBody()) {
1679+
output.write(result);
1680+
}
1681+
} else {
1682+
final JsonObjectBuilder result = Json.createObjectBuilder();
1683+
result.add("verifyInterval", verifyInterval);
1684+
exchange.getResponseHeaders().set("Content-Type", "application/json");
1685+
exchange.sendResponseHeaders(200, 0);
1686+
try (final OutputStream output = exchange.getResponseBody();
1687+
final JsonWriter writer = Json.createWriter(output)) {
1688+
writer.write(result.build());
1689+
}
16771690
}
16781691
}
16791692
}

0 commit comments

Comments
 (0)