diff options
author | Max Bires <jbires@google.com> | 2019-11-05 16:44:37 -0800 |
---|---|---|
committer | Max Bires <jbires@google.com> | 2019-11-12 09:35:18 -0800 |
commit | ff02baaca913759a64469c8324ad481ece4f41bc (patch) | |
tree | 73b7c4beba16ffb3885ee24c217a48d2b7adbf0d | |
parent | f581c60f088350ee5fd65af24e8422f24b830aeb (diff) | |
download | platform_hardware_interfaces-ff02baaca913759a64469c8324ad481ece4f41bc.tar.gz platform_hardware_interfaces-ff02baaca913759a64469c8324ad481ece4f41bc.tar.bz2 platform_hardware_interfaces-ff02baaca913759a64469c8324ad481ece4f41bc.zip |
Adding test to check another ASN.1 Encoding Case
This test will check that the length of the attestation application id
field will be properly encoded in valid DER ASN.1 in cases where the
length is long enough to require extra bytes to encode. In those cases,
the encoding of that field should include:
-A byte to specify how many bytes are required to enumerate the length
-The bytes required to enumerate the length
-The actual data that follows
Bug: 142674020
Test: atest keymaster_hidl_hal_test
Change-Id: I6d162efa4c8c6e0922989e234d0377caf3c1758e
-rw-r--r-- | keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp index c5acf8cc53..769b29abb7 100644 --- a/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp +++ b/keymaster/4.0/vts/functional/keymaster_hidl_hal_test.cpp @@ -4421,25 +4421,29 @@ TEST_F(AttestationTest, EcAttestationRequiresAttestationAppId) { * 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)); + std::vector<uint32_t> app_id_lengths{143, 258}; + for (uint32_t length : app_id_lengths) { + 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(length, '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)); + CheckedDeleteKey(); + } } /* * AttestationTest.AesAttestation |