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

Make attestationApplicationId field not optional #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -153,13 +153,8 @@ private static void printAuthorizationList(AuthorizationList authorizationList,
});
print(authorizationList.osVersion(), indent + "OS Version");
print(authorizationList.osPatchLevel(), indent + "OS Patch Level");
authorizationList
.attestationApplicationId()
.ifPresent(
attestationApplicationId -> {
System.out.println(indent + "Attestation Application ID:");
print(attestationApplicationId, indent + "\t");
});
System.out.println(indent + "Attestation Application ID:");
print(authorizationList.attestationApplicationId(), indent + "\t");
print(authorizationList.attestationIdBrand(), indent + "Attestation ID Brand");
print(authorizationList.attestationIdDevice(), indent + "Attestation ID Device");
print(authorizationList.attestationIdProduct(), indent + "Attestation ID Product");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.errorprone.annotations.Immutable;
import com.google.protobuf.ByteString;
import java.io.IOException;
import java.util.Optional;
import java.util.Set;
import org.bouncycastle.asn1.ASN1Encodable;
import org.bouncycastle.asn1.ASN1Integer;
Expand Down Expand Up @@ -112,7 +113,10 @@ static AttestationApplicationId createAttestationApplicationId(byte[] attestatio
return builder.build();
}

byte[] getEncoded() {
Optional<byte[]> getEncoded() {
if (packageInfos().isEmpty() && signatureDigests().isEmpty()) {
return Optional.empty();
}
ASN1Encodable[] applicationIdAsn1Array = new ASN1Encodable[2];
applicationIdAsn1Array[ATTESTATION_APPLICATION_ID_PACKAGE_INFOS_INDEX] =
new DERSet(
Expand All @@ -127,7 +131,7 @@ byte[] getEncoded() {
.toArray(DEROctetString[]::new));

try {
return new DERSequence(applicationIdAsn1Array).getEncoded();
return Optional.of(new DERSequence(applicationIdAsn1Array).getEncoded());
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ public enum OperationPurpose {

public abstract Optional<YearMonth> osPatchLevel();

public abstract Optional<AttestationApplicationId> attestationApplicationId();
public abstract AttestationApplicationId attestationApplicationId();

public abstract Optional<ByteString> attestationIdBrand();

Expand Down Expand Up @@ -433,7 +433,8 @@ public static Builder builder() {
.setAllApplications(false)
.setRollbackResistant(false)
.setIndividualAttestation(false)
.setIdentityCredentialKey(false);
.setIdentityCredentialKey(false)
.setAttestationApplicationId(AttestationApplicationId.builder().build());
}

/**
Expand Down Expand Up @@ -905,7 +906,7 @@ public ASN1Sequence toAsn1Sequence() {
this.osPatchLevel().map(AuthorizationList::toString).map(Integer::valueOf),
vector);
this.attestationApplicationId()
.map(AttestationApplicationId::getEncoded)
.getEncoded()
.map(DEROctetString::new)
.map(obj -> new DERTaggedObject(KM_TAG_ATTESTATION_APPLICATION_ID, obj))
.ifPresent(vector::add);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package com.google.android.attestation;

import static com.google.android.attestation.AuthorizationList.toLocalDate;
import static com.google.android.attestation.AuthorizationList.DigestMode.SHA_2_256;
import static com.google.android.attestation.AuthorizationList.OperationPurpose.SIGN;
import static com.google.android.attestation.AuthorizationList.OperationPurpose.VERIFY;
Expand All @@ -25,6 +24,7 @@
import static com.google.android.attestation.AuthorizationList.UserAuthType.PASSWORD;
import static com.google.android.attestation.AuthorizationList.UserAuthType.USER_AUTH_TYPE_ANY;
import static com.google.android.attestation.AuthorizationList.UserAuthType.USER_AUTH_TYPE_NONE;
import static com.google.android.attestation.AuthorizationList.toLocalDate;
import static com.google.android.attestation.AuthorizationList.userAuthTypeToEnum;
import static com.google.android.attestation.Constants.UINT32_MAX;
import static com.google.common.truth.Truth.assertThat;
Expand Down Expand Up @@ -116,7 +116,7 @@ public void testCanParseAuthorizationListFromSwEnforced() throws IOException {
assertThat(authorizationList.creationDateTime()).hasValue(EXPECTED_SW_CREATION_DATETIME);
assertThat(authorizationList.rootOfTrust()).isEmpty();
assertThat(authorizationList.attestationApplicationId())
.hasValue(EXPECTED_SW_ATTESTATION_APPLICATION_ID);
.isEqualTo(EXPECTED_SW_ATTESTATION_APPLICATION_ID);
assertThat(authorizationList.individualAttestation()).isFalse();
assertThat(authorizationList.identityCredentialKey()).isFalse();
}
Expand Down
Loading