Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff02baac authored by Max Bires's avatar Max Bires
Browse files

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
parent f581c60f
Loading
Loading
Loading
Loading
+23 −19
Original line number Diff line number Diff line
@@ -4421,6 +4421,8 @@ TEST_F(AttestationTest, EcAttestationRequiresAttestationAppId) {
 * to specify how many following bytes will be used to encode the length.
 */
TEST_F(AttestationTest, AttestationApplicationIDLengthProperlyEncoded) {
    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)
@@ -4428,7 +4430,7 @@ TEST_F(AttestationTest, AttestationApplicationIDLengthProperlyEncoded) {
                                                     .Digest(Digest::SHA_2_256)));

        hidl_vec<hidl_vec<uint8_t>> cert_chain;
    const string app_id(143, 'a');
        const string app_id(length, 'a');
        ASSERT_EQ(ErrorCode::OK,
                  AttestKey(AuthorizationSetBuilder()
                                    .Authorization(TAG_ATTESTATION_CHALLENGE, HidlBuf("challenge"))
@@ -4440,6 +4442,8 @@ TEST_F(AttestationTest, AttestationApplicationIDLengthProperlyEncoded) {
                                              key_characteristics_.softwareEnforced,  //
                                              key_characteristics_.hardwareEnforced,  //
                                              SecLevel(), cert_chain[0], creation_time));
        CheckedDeleteKey();
    }
}
/*
 * AttestationTest.AesAttestation