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

Commit 3950b45a authored by Tommy Chiu's avatar Tommy Chiu
Browse files

vts: Correct the parameters on strongbox

If GenerateKey() with user-provide key_blob, it needs to be specified in
the following begin() operations as well. Update the test case just to
take key_blob from private member instead of creating a local one.

Note:
- Remove redudent TAG_NO_AUTH_REQUIRED in DeviceUniqueAttestationTest

Change-Id: I81860294e1e7e01a57e66e08e75507a8292ec0c3
parent 8b25958b
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -70,7 +70,6 @@ TEST_P(DeviceUniqueAttestationTest, RsaNonStrongBoxUnimplemented) {
                                      .Digest(Digest::SHA_2_256)
                                      .Padding(PaddingMode::RSA_PKCS1_1_5_SIGN)
                                      .Authorization(TAG_INCLUDE_UNIQUE_ID)
                                      .Authorization(TAG_NO_AUTH_REQUIRED)
                                      .AttestationChallenge("challenge")
                                      .AttestationApplicationId("foo")
                                      .Authorization(TAG_DEVICE_UNIQUE_ATTESTATION),
@@ -124,7 +123,6 @@ TEST_P(DeviceUniqueAttestationTest, RsaDeviceUniqueAttestation) {
                                      .Digest(Digest::SHA_2_256)
                                      .Padding(PaddingMode::RSA_PKCS1_1_5_SIGN)
                                      .Authorization(TAG_INCLUDE_UNIQUE_ID)
                                      .Authorization(TAG_NO_AUTH_REQUIRED)
                                      .AttestationChallenge("challenge")
                                      .AttestationApplicationId("foo")
                                      .Authorization(TAG_DEVICE_UNIQUE_ATTESTATION),
+13 −9
Original line number Diff line number Diff line
@@ -443,9 +443,8 @@ TEST_P(NewKeyGenerationTest, AesInvalidPadding) {
            for (auto padding_mode : InvalidPaddingModes(Algorithm::AES, block_mode)) {
                SCOPED_TRACE(testing::Message()
                             << "AES-" << key_size << "-" << block_mode << "-" << padding_mode);
                vector<uint8_t> key_blob;
                vector<KeyCharacteristics> key_characteristics;
                auto builder = AuthorizationSetBuilder()
                                       .Authorization(TAG_NO_AUTH_REQUIRED)
                                       .AesEncryptionKey(key_size)
                                       .BlockMode(block_mode)
                                       .Padding(padding_mode)
@@ -454,11 +453,14 @@ TEST_P(NewKeyGenerationTest, AesInvalidPadding) {
                    builder.Authorization(TAG_MIN_MAC_LENGTH, 128);
                }

                auto result = GenerateKey(builder, &key_blob, &key_characteristics);
                auto result = GenerateKey(builder);
                if (result == ErrorCode::OK) {
                    // Key creation was OK but has generated a key that cannot be used.
                    auto params =
                            AuthorizationSetBuilder().BlockMode(block_mode).Padding(padding_mode);
                    if (block_mode == BlockMode::GCM) {
                        params.Authorization(TAG_MAC_LENGTH, 128);
                    }
                    auto result = Begin(KeyPurpose::ENCRYPT, params);
                    EXPECT_TRUE(result == ErrorCode::INCOMPATIBLE_PADDING_MODE ||
                                result == ErrorCode::INVALID_KEY_BLOB);
@@ -2884,13 +2886,14 @@ TEST_P(ImportKeyTest, AesFailure) {
    string key = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    uint32_t bitlen = key.size() * 8;
    for (uint32_t key_size : {bitlen - 1, bitlen + 1, bitlen - 8, bitlen + 8}) {
        ASSERT_EQ(ErrorCode::UNSUPPORTED_KEY_SIZE,
                  ImportKey(AuthorizationSetBuilder()
        auto result = ImportKey(AuthorizationSetBuilder()
                                    .Authorization(TAG_NO_AUTH_REQUIRED)
                                    .AesEncryptionKey(key_size)
                                    .EcbMode()
                                    .Padding(PaddingMode::PKCS7),
                            KeyFormat::RAW, key));
                                KeyFormat::RAW, key);
        ASSERT_TRUE(result == ErrorCode::IMPORT_PARAMETER_MISMATCH ||
                    result == ErrorCode::UNSUPPORTED_KEY_SIZE);
    }
}

@@ -2930,13 +2933,14 @@ TEST_P(ImportKeyTest, TripleDesFailure) {
    string key = hex2str("a49d7564199e97cb529d2c9d97bf2f98d35edf57ba1f7358");
    uint32_t bitlen = key.size() * 8;
    for (uint32_t key_size : {bitlen - 1, bitlen + 1, bitlen - 8, bitlen + 8}) {
        ASSERT_EQ(ErrorCode::UNSUPPORTED_KEY_SIZE,
                  ImportKey(AuthorizationSetBuilder()
        auto result = ImportKey(AuthorizationSetBuilder()
                                    .Authorization(TAG_NO_AUTH_REQUIRED)
                                    .TripleDesEncryptionKey(key_size)
                                    .EcbMode()
                                    .Padding(PaddingMode::PKCS7),
                            KeyFormat::RAW, key));
                                KeyFormat::RAW, key);
        ASSERT_TRUE(result == ErrorCode::IMPORT_PARAMETER_MISMATCH ||
                    result == ErrorCode::UNSUPPORTED_KEY_SIZE);
    }
}