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

Commit 73bf3ea0 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 4434599 from c1512b45 to pi-release

Change-Id: If144ee9bb3d468d7d5a486ee8bbdf4287e68a39a
parents 6b6a2d0d c1512b45
Loading
Loading
Loading
Loading
+105 −12
Original line number Diff line number Diff line
@@ -89,6 +89,10 @@ static const uint8_t kInvalidUUID[16] = {
    0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80,
    0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80};

static const uint32_t k256SubSampleByteCount = 256;
static const uint32_t k512SubSampleClearBytes = 512;
static const uint32_t k512SubSampleEncryptedBytes = 512;

class DrmHalClearkeyFactoryTest : public ::testing::VtsHalHidlTargetTestBase {
   public:
    virtual void SetUp() override {
@@ -965,6 +969,8 @@ class DrmHalClearkeyDecryptTest : public DrmHalClearkeyPluginTest {
            const hidl_vec<SubSample>& subSamples, const vector<uint8_t>& key);
    void aes_cbc_decrypt(uint8_t* dest, uint8_t* src, uint8_t* iv,
            const hidl_vec<SubSample>& subSamples, const vector<uint8_t>& key);
    void decryptWithInvalidKeys(hidl_vec<uint8_t>& invalidResponse,
            vector<uint8_t>& iv, const Pattern& noPattern, const vector<SubSample>& subSamples);
};

void DrmHalClearkeyDecryptTest::fillRandom(const sp<IMemory>& memory) {
@@ -1119,16 +1125,14 @@ TEST_F(DrmHalClearkeyDecryptTest, TestQueryKeyStatus) {
    closeSession(sessionId);
}


/**
 * Positive decrypt test.  "Decrypt" a single clear segment
 */
TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
    vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
    const Pattern noPattern = {0, 0};
    const uint32_t kByteCount = 256;
    const vector<SubSample> subSamples = {
        {.numBytesOfClearData = kByteCount,
        {.numBytesOfClearData = k256SubSampleByteCount,
         .numBytesOfEncryptedData = 0}};
    auto sessionId = openSession();
    loadKeys(sessionId);
@@ -1138,7 +1142,7 @@ TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {

    uint32_t byteCount = decrypt(Mode::UNENCRYPTED, &iv[0], subSamples,
            noPattern, Status::OK);
    EXPECT_EQ(kByteCount, byteCount);
    EXPECT_EQ(k256SubSampleByteCount, byteCount);

    closeSession(sessionId);
}
@@ -1150,12 +1154,9 @@ TEST_F(DrmHalClearkeyDecryptTest, ClearSegmentTest) {
TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {
    vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
    const Pattern noPattern = {0, 0};
    const uint32_t kClearBytes = 512;
    const uint32_t kEncryptedBytes = 512;
    const vector<SubSample> subSamples = {
        {.numBytesOfClearData = kClearBytes,
         .numBytesOfEncryptedData = kEncryptedBytes
        }};
        {.numBytesOfClearData = k512SubSampleClearBytes,
         .numBytesOfEncryptedData = k512SubSampleEncryptedBytes}};
    auto sessionId = openSession();
    loadKeys(sessionId);

@@ -1164,10 +1165,11 @@ TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTest) {

    uint32_t byteCount = decrypt(Mode::AES_CTR, &iv[0], subSamples,
            noPattern, Status::OK);
    EXPECT_EQ(kClearBytes + kEncryptedBytes, byteCount);
    EXPECT_EQ(k512SubSampleClearBytes + k512SubSampleEncryptedBytes, byteCount);

    closeSession(sessionId);
}

/**
 * Negative decrypt test. Decrypt without loading keys.
 */
@@ -1175,8 +1177,8 @@ TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) {
    vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
    const Pattern noPattern = {0, 0};
    const vector<SubSample> subSamples = {
        {.numBytesOfClearData = 256,
         .numBytesOfEncryptedData = 256}};
        {.numBytesOfClearData = k256SubSampleByteCount,
         .numBytesOfEncryptedData = k256SubSampleByteCount}};
    auto sessionId = openSession();

    Status status = cryptoPlugin->setMediaDrmSession(sessionId);
@@ -1188,3 +1190,94 @@ TEST_F(DrmHalClearkeyDecryptTest, EncryptedAesCtrSegmentTestNoKeys) {

    closeSession(sessionId);
}

/**
 * Helper method to test decryption with invalid keys is returned
 */
void DrmHalClearkeyDecryptTest::decryptWithInvalidKeys(
        hidl_vec<uint8_t>& invalidResponse,
        vector<uint8_t>& iv,
        const Pattern& noPattern,
        const vector<SubSample>& subSamples) {
    auto sessionId = openSession();

    auto res = drmPlugin->provideKeyResponse(
        sessionId, invalidResponse,
        [&](Status status, const hidl_vec<uint8_t>& myKeySetId) {
            EXPECT_EQ(Status::OK, status);
            EXPECT_EQ(0u, myKeySetId.size());
        });
    ASSERT_OK(res);

    ASSERT_TRUE(cryptoPlugin->setMediaDrmSession(sessionId).isOk());

    uint32_t byteCount = decrypt(Mode::AES_CTR, &iv[0], subSamples,
            noPattern, Status::ERROR_DRM_NO_LICENSE);
    EXPECT_EQ(0u, byteCount);

    closeSession(sessionId);
}

/**
 * Negative decrypt test. Decrypt with invalid key.
 */
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithEmptyKey) {
    vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
    const Pattern noPattern = {0, 0};
    const vector<SubSample> subSamples = {
        {.numBytesOfClearData = k512SubSampleClearBytes,
         .numBytesOfEncryptedData = k512SubSampleEncryptedBytes}};

    // base 64 encoded JSON response string, must not contain padding character '='
    const hidl_string emptyKeyResponse =
            "{\"keys\":[" \
                "{" \
                    "\"kty\":\"oct\"" \
                    "\"alg\":\"A128KW2\"" \
                    "\"k\":\"SGVsbG8gRnJpZW5kIQ\"" \
                    "\"kid\":\"Y2xlYXJrZXlrZXlpZDAyAy\"" \
                "}" \
                "{" \
                    "\"kty\":\"oct\"," \
                    "\"alg\":\"A128KW2\"" \
                    "\"kid\":\"Y2xlYXJrZXlrZXlpZDAzAy\"," \
                    // empty key follows
                    "\"k\":\"R\"" \
                "}]" \
            "}";
    const size_t kEmptyKeyResponseSize = emptyKeyResponse.size();

    hidl_vec<uint8_t> invalidResponse;
    invalidResponse.resize(kEmptyKeyResponseSize);
    memcpy(invalidResponse.data(), emptyKeyResponse.c_str(), kEmptyKeyResponseSize);
    decryptWithInvalidKeys(invalidResponse, iv, noPattern, subSamples);
}

/**
 * Negative decrypt test. Decrypt with a key exceeds AES_BLOCK_SIZE.
 */
TEST_F(DrmHalClearkeyDecryptTest, DecryptWithKeyTooLong) {
    vector<uint8_t> iv(AES_BLOCK_SIZE, 0);
    const Pattern noPattern = {0, 0};
    const vector<SubSample> subSamples = {
        {.numBytesOfClearData = k512SubSampleClearBytes,
         .numBytesOfEncryptedData = k512SubSampleEncryptedBytes}};

    // base 64 encoded JSON response string, must not contain padding character '='
    const hidl_string keyTooLongResponse =
            "{\"keys\":[" \
                "{" \
                    "\"kty\":\"oct\"," \
                    "\"alg\":\"A128KW2\"" \
                    "\"kid\":\"Y2xlYXJrZXlrZXlpZDAzAy\"," \
                    // key too long
                    "\"k\":\"V2lubmllIHRoZSBwb29oIVdpbm5pZSB0aGUgcG9vaCE=\"" \
                "}]" \
            "}";
    const size_t kKeyTooLongResponseSize = keyTooLongResponse.size();

    hidl_vec<uint8_t> invalidResponse;
    invalidResponse.resize(kKeyTooLongResponseSize);
    memcpy(invalidResponse.data(), keyTooLongResponse.c_str(), kKeyTooLongResponseSize);
    decryptWithInvalidKeys(invalidResponse, iv, noPattern, subSamples);
}

radio/1.2/vts/OWNERS

0 → 100644
+9 −0
Original line number Diff line number Diff line
# Telephony team
amitmahajan@google.com
sanketpadawe@google.com
shuoq@google.com
sasindran@google.com

# VTS team
yuexima@google.com
yim@google.com
+33 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2017 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

cc_test {
    name: "VtsHalRadioV1_2TargetTest",
    defaults: ["VtsHalTargetTestDefaults"],
    srcs: [
        "radio_hidl_hal_api.cpp",
        "radio_hidl_hal_test.cpp",
        "radio_response.cpp",
        "radio_indication.cpp",
    ],
    static_libs: [
        "RadioVtsTestUtilBase",
        "android.hardware.radio@1.2",
        "android.hardware.radio@1.1",
        "android.hardware.radio@1.0",
    ],
    header_libs: ["radio.util.header@1.0"],
}
+395 −0

File added.

Preview size limit exceeded, changes collapsed.

+67 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <radio_hidl_hal_utils_v1_2.h>

void RadioHidlTest_v1_2::SetUp() {
    radio_v1_2 = ::testing::VtsHalHidlTargetTestBase::getService<V1_2::IRadio>(
        hidl_string(RADIO_SERVICE_NAME));
    ASSERT_NE(nullptr, radio_v1_2.get());

    radioRsp_v1_2 = new (std::nothrow) RadioResponse_v1_2(*this);
    ASSERT_NE(nullptr, radioRsp_v1_2.get());

    count_ = 0;

    radioInd_v1_2 = new (std::nothrow) RadioIndication_v1_2(*this);
    ASSERT_NE(nullptr, radioInd_v1_2.get());

    radio_v1_2->setResponseFunctions(radioRsp_v1_2, radioInd_v1_2);

    int serial = GetRandomSerialNumber();
    radio_v1_2->getIccCardStatus(serial);
    EXPECT_EQ(std::cv_status::no_timeout, wait());
    EXPECT_EQ(RadioResponseType::SOLICITED, radioRsp_v1_2->rspInfo.type);
    EXPECT_EQ(serial, radioRsp_v1_2->rspInfo.serial);
    EXPECT_EQ(RadioError::NONE, radioRsp_v1_2->rspInfo.error);
}

/*
 * Notify that the response message is received.
 */
void RadioHidlTest_v1_2::notify() {
    std::unique_lock<std::mutex> lock(mtx_);
    count_++;
    cv_.notify_one();
}

/*
 * Wait till the response message is notified or till TIMEOUT_PERIOD.
 */
std::cv_status RadioHidlTest_v1_2::wait() {
    std::unique_lock<std::mutex> lock(mtx_);

    std::cv_status status = std::cv_status::no_timeout;
    auto now = std::chrono::system_clock::now();
    while (count_ == 0) {
        status = cv_.wait_until(lock, now + std::chrono::seconds(TIMEOUT_PERIOD));
        if (status == std::cv_status::timeout) {
            return status;
        }
    }
    count_--;
    return status;
}
Loading