Skip to content

Commit

Permalink
convert VerificationResult and AttestationResult to record classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thestinger committed Oct 1, 2024
1 parent a6f79cd commit 64cb3ae
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,15 @@ private void handleAttestation(final byte[] serialized) {
try {
final AttestationProtocol.VerificationResult result = AttestationProtocol.verifySerialized(this, serialized, auditorChallenge);
runOnUiThread(() -> {
setBackgroundResource(result.strong ? R.color.green : R.color.orange);
binding.content.textview.setText(result.strong ? R.string.verify_strong : R.string.verify_basic);
setBackgroundResource(result.strong() ? R.color.green : R.color.orange);
binding.content.textview.setText(result.strong() ? R.string.verify_strong : R.string.verify_basic);
binding.content.textview.append(getText(R.string.hardware_enforced));
binding.content.textview.append(result.teeEnforced);
binding.content.textview.append(result.teeEnforced());
binding.content.textview.append(getText(R.string.os_enforced));
binding.content.textview.append(result.osEnforced);
if (!result.history.isEmpty()) {
binding.content.textview.append(result.osEnforced());
if (!result.history().isEmpty()) {
binding.content.textview.append(getText(R.string.history));
binding.content.textview.append(result.history);
binding.content.textview.append(result.history());
}
});
} catch (final DataFormatException | GeneralSecurityException | IOException |
Expand All @@ -380,8 +380,8 @@ private void generateAttestation(final byte[] challenge) {
final AttestationProtocol.AttestationResult result =
AttestationProtocol.generateSerialized(this, challenge, null, "");
runOnUiThread(() -> {
auditeePairing = result.pairing;
auditeeShowAttestation(result.serialized);
auditeePairing = result.pairing();
auditeeShowAttestation(result.serialized());
});
} catch (final GeneralSecurityException | IOException e) {
Log.e(TAG, "attestation generation error", e);
Expand Down
25 changes: 2 additions & 23 deletions app/src/main/java/app/attestation/auditor/AttestationProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -932,20 +932,7 @@ private static void verifySignature(final PublicKey key, final ByteBuffer messag
}
}

static class VerificationResult {
final boolean strong;
final String teeEnforced;
final String osEnforced;
final String history;

VerificationResult(final boolean strong, final String teeEnforced,
final String osEnforced, final String history) {
this.strong = strong;
this.teeEnforced = teeEnforced;
this.osEnforced = osEnforced;
this.history = history;
}
}
record VerificationResult(boolean strong, String teeEnforced, String osEnforced, String history) {}

private static String toYesNoString(final Context context, final boolean value) {
return value ? context.getString(R.string.yes) : context.getString(R.string.no);
Expand Down Expand Up @@ -1249,15 +1236,7 @@ static VerificationResult verifySerialized(final Context context, final byte[] a
adbEnabled, addUsersWhenLocked, enrolledBiometrics, oemUnlockAllowed, systemUser);
}

static class AttestationResult {
final boolean pairing;
final byte[] serialized;

AttestationResult(final boolean pairing, final byte[] serialized) {
this.pairing = pairing;
this.serialized = serialized;
}
}
record AttestationResult(boolean pairing, byte[] serialized) {}

static KeyGenParameterSpec.Builder getKeyBuilder(final String alias, final int purposes,
final boolean useStrongBox, final byte[] challenge, final boolean temporary) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public boolean onStartJob(final JobParameters params) {
connection.setConnectTimeout(CONNECT_TIMEOUT);
connection.setReadTimeout(READ_TIMEOUT);
connection.setDoOutput(true);
final String extra = result.pairing ? " " + subscribeKey : "";
final String extra = result.pairing() ? " " + subscribeKey : "";
connection.setRequestProperty("Authorization", "Auditor " + userId + extra);

final OutputStream output = connection.getOutputStream();
output.write(result.serialized);
output.write(result.serialized());
output.close();

final int responseCode = connection.getResponseCode();
Expand All @@ -188,7 +188,7 @@ public boolean onStartJob(final JobParameters params) {
schedule(context, interval);
}
} else {
if (result.pairing) {
if (result.pairing()) {
AttestationProtocol.clearAuditee(STATE_PREFIX, Long.toString(userId));
}
throw new IOException("response code: " + responseCode);
Expand Down

0 comments on commit 64cb3ae

Please sign in to comment.