Merge "Adding test to check that ASN.1 lengths are properly encoded"

am: c6b086785d

Change-Id: Ia3ae894786c281feced2161142a69775838b9ad5
This commit is contained in:
Max Bires
2019-10-24 15:34:49 -07:00
committed by android-build-merger

View File

@@ -4412,6 +4412,35 @@ TEST_F(AttestationTest, EcAttestationRequiresAttestationAppId) {
&cert_chain));
}
/*
* AttestationTest.AttestationApplicationIDLengthProperlyEncoded
*
* Verifies that the Attestation Application ID software enforced tag has a proper length encoding.
* Some implementations break strict encoding rules by encoding a length between 127 and 256 in one
* byte. Proper DER encoding specifies that for lengths greather than 127, one byte should be used
* to specify how many following bytes will be used to encode the length.
*/
TEST_F(AttestationTest, AttestationApplicationIDLengthProperlyEncoded) {
auto creation_time = std::chrono::system_clock::now();
ASSERT_EQ(ErrorCode::OK, GenerateKey(AuthorizationSetBuilder()
.Authorization(TAG_NO_AUTH_REQUIRED)
.EcdsaSigningKey(EcCurve::P_256)
.Digest(Digest::SHA_2_256)));
hidl_vec<hidl_vec<uint8_t>> cert_chain;
const string app_id(143, 'a');
ASSERT_EQ(ErrorCode::OK,
AttestKey(AuthorizationSetBuilder()
.Authorization(TAG_ATTESTATION_CHALLENGE, HidlBuf("challenge"))
.Authorization(TAG_ATTESTATION_APPLICATION_ID, HidlBuf(app_id)),
&cert_chain));
EXPECT_GE(cert_chain.size(), 2U);
EXPECT_TRUE(verify_attestation_record("challenge", app_id, //
key_characteristics_.softwareEnforced, //
key_characteristics_.hardwareEnforced, //
SecLevel(), cert_chain[0], creation_time));
}
/*
* AttestationTest.AesAttestation
*