Skip to content

Commit

Permalink
convert attestation parsing error to GeneralSecurityException
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 1, 2024
1 parent 1376ac2 commit 9d565b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/main/java/app/attestation/server/AttestationProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ private static X509Certificate generateCertificate(final InputStream in)

private static Verified verifyStateless(final Certificate[] certificates,
final Cache<ByteBuffer, Boolean> pendingChallenges, final boolean hasPersistentKey,
final byte[][] validRoots) throws GeneralSecurityException, IOException {
final byte[][] validRoots) throws GeneralSecurityException {

verifyCertificateSignatures(certificates, hasPersistentKey);

Expand All @@ -496,7 +496,7 @@ private static Verified verifyStateless(final Certificate[] certificates,
try {
attestation = ParsedAttestationRecord.createParsedAttestationRecord(
List.of((X509Certificate) certificates[0]));
} catch (final ParsedAttestationRecord.KeyDescriptionMissingException e) {
} catch (final IOException | ParsedAttestationRecord.KeyDescriptionMissingException e) {
throw new GeneralSecurityException(e);
}

Expand Down Expand Up @@ -730,6 +730,8 @@ private static Verified verifyStateless(final Certificate[] certificates,
}

attestKey = true;
} catch (final IOException e) {
throw new GeneralSecurityException(e);
} catch (final ParsedAttestationRecord.KeyDescriptionMissingException ignored) {}

// enforce attest key for new pairings with devices supporting it
Expand All @@ -740,7 +742,9 @@ private static Verified verifyStateless(final Certificate[] certificates,
for (int i = 2; i < certificates.length; i++) {
try {
ParsedAttestationRecord.createParsedAttestationRecord(List.of((X509Certificate) certificates[i]));
} catch (final ParsedAttestationRecord.KeyDescriptionMissingException e) {
} catch (final IOException e) {
throw new GeneralSecurityException(e);
} catch (final ParsedAttestationRecord.KeyDescriptionMissingException e) {
continue;
}
throw new GeneralSecurityException("only initial key and attest key should have attestation extension");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/app/attestation/server/AttestationServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1536,7 +1536,8 @@ public void handlePost(final HttpExchange exchange) throws IOException, SQLiteEx

try {
AttestationProtocol.verifySerialized(attestationResult, pendingChallenges, userId, subscribeKey == null);
} catch (final BufferUnderflowException | NegativeArraySizeException | DataFormatException | GeneralSecurityException | IOException e) {
} catch (final BufferUnderflowException | NegativeArraySizeException |
DataFormatException | GeneralSecurityException e) {
logger.log(Level.WARNING, "invalid request", e);
final byte[] response = "Error\n".getBytes();
exchange.sendResponseHeaders(400, response.length);
Expand Down

0 comments on commit 9d565b0

Please sign in to comment.