This is a merge from the Widevine repository of http://go/wvgerrit/14024 Add Level 3 Oemcrypto Unit Tests To Run All Tests Script This CL adds the ability to restrict the oemcrypto unit tests to only use the fall back level 3. This restriction is per-process, and is only used while running the unit tests. This allows us to automate running the unit tests on an android device as both level 1 and level 3 without modifying files in /system/lib. To turn on the restriction, set the environment variable: FORCE_LEVEL3_OEMCRYPTO=yes. New level 3 library versions are: level3/arm/libwvlevel3.a Level3 Library Apr 8 2015 13:09:05 level3/x86/libwvlevel3.a Level3 Library Apr 8 2015 13:15:42 http://go/wvgerrit/14055 Remove Redundant Tests This CL modifies the UsageTableTests in oemcrypto_test.cpp so that they are not all parameterized by new_mac_keys_. This parameter is used when testing signatures. In particular, we do not need to verify timing twice. Also, I modified the run_all_unit_tests.sh script so that the environment variable GTEST_FILTER is passed down to the android process. This allows us to use the script to run a limited list of tests while debugging. http://go/wvgerrit/14054 Filter Out API Version 10 Tests This CL updates the OEMCrypto tests so that all but one test will pass for a device that implements the version 9 API. Android LMP devices should pass tests with GTEST_FILTER="*-*MNC*:*CanLoadTestKeys*" http://go/wvgerrit/13886 Update Documentation about Optional Features The intergration guide has been updated to include reference to OEMCrypto_LoadTestRSAKey. It also now discusses optional features. The Delta 10 document now mentions OEMCrypto_LoadTestRSAKey. The android supplement warns that most optional features are required. This also adds clarification about which functions should save the usage table, in answer to: b/16799904 OEMCrypto v9 ambiguous about saving usage table information Change-Id: Ifb517d58952c9b332b2958ca99af64bc293b985f
106 lines
3.6 KiB
C++
106 lines
3.6 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
//
|
|
// OEMCrypto unit tests - extra tests required for Android platform.
|
|
//
|
|
// The Widevine CDM system can be built on many platforms, with different
|
|
// capabilities. For example, some platforms do not require usage tables,
|
|
// and some can have a pre-installed certificate and do not need a keybox.
|
|
// On Android, these features are not optional. This set of unit tests
|
|
// verify that these features are implemented.
|
|
//
|
|
// In the file oemcrypto_test.cpp, the unit tests only verify correct
|
|
// functionality for functions that are implemented. Android devices must pass
|
|
// unit tests in both files.
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "OEMCryptoCENC.h"
|
|
|
|
namespace wvoec {
|
|
|
|
// These tests are required for LollyPop Android devices.
|
|
class OEMCryptoAndroidLMPTest : public ::testing::Test {
|
|
protected:
|
|
virtual void SetUp() {
|
|
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
|
|
}
|
|
|
|
virtual void TearDown() {
|
|
OEMCrypto_Terminate();
|
|
}
|
|
};
|
|
|
|
// Android devices must have a keybox.
|
|
TEST_F(OEMCryptoAndroidLMPTest, GetKeyDataImplemented) {
|
|
uint8_t key_data[256];
|
|
size_t key_data_len = sizeof(key_data);
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_GetKeyData(key_data, &key_data_len));
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidLMPTest, MinVersionNumber9) {
|
|
uint32_t version = OEMCrypto_APIVersion();
|
|
ASSERT_LE(9u, version);
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidLMPTest, ValidKeyboxTest) {
|
|
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_IsKeyboxValid());
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidLMPTest, RewrapDeviceRSAKeyImplemented) {
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_RewrapDeviceRSAKey(0, NULL, 0, NULL, 0, NULL,
|
|
NULL, 0, NULL, NULL, NULL));
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidLMPTest, RSASignatureImplemented) {
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_GenerateRSASignature(0, NULL, 0, NULL, NULL,
|
|
kSign_RSASSA_PSS));
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidLMPTest, GenericCryptoImplemented) {
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_Generic_Encrypt(0, NULL, 0, NULL,
|
|
OEMCrypto_AES_CBC_128_NO_PADDING, NULL));
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_Generic_Decrypt(0, NULL, 0, NULL,
|
|
OEMCrypto_AES_CBC_128_NO_PADDING, NULL));
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_Generic_Sign(0, NULL, 0,
|
|
OEMCrypto_HMAC_SHA256, NULL, NULL));
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_Generic_Verify(0, NULL, 0,
|
|
OEMCrypto_HMAC_SHA256, NULL, 0));
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidLMPTest, SupportsUsageTable) {
|
|
ASSERT_TRUE(OEMCrypto_SupportsUsageTable());
|
|
}
|
|
|
|
// These tests are required for M Android devices.
|
|
class OEMCryptoAndroidMNCTest : public OEMCryptoAndroidLMPTest {};
|
|
|
|
TEST_F(OEMCryptoAndroidMNCTest, MinVersionNumber10) {
|
|
uint32_t version = OEMCrypto_APIVersion();
|
|
ASSERT_GE(version, 10u);
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidMNCTest, LoadsTestKeyboxImplemented) {
|
|
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_LoadTestKeybox());
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidMNCTest, NumberOfSessionsImplemented) {
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_GetNumberOfOpenSessions(NULL));
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_GetMaxNumberOfSessions(NULL));
|
|
}
|
|
|
|
TEST_F(OEMCryptoAndroidMNCTest, QueryKeyControlImplemented) {
|
|
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
|
|
OEMCrypto_QueryKeyControl(0, NULL, 0, NULL, NULL));
|
|
}
|
|
|
|
} // namespace wvoec
|