Clean up OEMCrypto unit tests for Android

Remove some stale tests.

Bug: 175122314
Change-Id: Ie110ffc28353fcdafaf7774d81a625f5d99f4213
This commit is contained in:
Fred Gylys-Colwell
2023-09-03 10:15:59 -07:00
committed by Robert Shih
parent fd28f10559
commit c89ca732f0

View File

@@ -21,15 +21,12 @@
namespace wvoec { namespace wvoec {
// These tests are required for LollyPop Android devices. /** These tests are required for LollyPop Android devices.*/
class OEMCryptoAndroidLMPTest : public ::testing::Test { class OEMCryptoAndroidLMPTest : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
OEMCrypto_SetSandbox(kTestSandbox, sizeof(kTestSandbox)); OEMCrypto_SetSandbox(kTestSandbox, sizeof(kTestSandbox));
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize()); ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_Initialize());
if (OEMCrypto_GetProvisioningMethod() == OEMCrypto_BootCertificateChain) {
GTEST_SKIP() << "Test for non Prov 4.0 devices only.";
}
OEMCrypto_SetMaxAPIVersion(kCurrentAPI); OEMCrypto_SetMaxAPIVersion(kCurrentAPI);
OEMCrypto_EnterTestMode(); OEMCrypto_EnterTestMode();
} }
@@ -37,34 +34,7 @@ class OEMCryptoAndroidLMPTest : public ::testing::Test {
void TearDown() override { OEMCrypto_Terminate(); } void TearDown() override { OEMCrypto_Terminate(); }
}; };
// Android devices must have a keybox, or use provisioning 3.0. /** Android devices that use Provisioning 2.0 must have a valid keybox. */
TEST_F(OEMCryptoAndroidLMPTest, GetKeyDataImplemented) {
if (global_features.provisioning_method != OEMCrypto_Keybox &&
global_features.provisioning_method != OEMCrypto_OEMCertificate) {
GTEST_SKIP() << "Test for Prov 2.0 and 3.0 devices only.";
}
uint8_t key_data[256];
size_t key_data_len = sizeof(key_data);
if (OEMCrypto_Keybox == OEMCrypto_GetProvisioningMethod()) {
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
OEMCrypto_GetKeyData(key_data, &key_data_len));
} else {
ASSERT_EQ(OEMCrypto_OEMCertificate, OEMCrypto_GetProvisioningMethod());
}
}
// Android devices must have a valid keybox.
TEST_F(OEMCryptoAndroidLMPTest, ValidKeybox) {
if (OEMCrypto_GetProvisioningMethod() == OEMCrypto_Keybox) {
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_IsKeyboxValid());
}
}
TEST_F(OEMCryptoAndroidLMPTest, MinVersionNumber9) {
uint32_t version = OEMCrypto_APIVersion();
ASSERT_LE(9u, version);
}
TEST_F(OEMCryptoAndroidLMPTest, ValidKeyboxTest) { TEST_F(OEMCryptoAndroidLMPTest, ValidKeyboxTest) {
if (global_features.provisioning_method != OEMCrypto_Keybox) { if (global_features.provisioning_method != OEMCrypto_Keybox) {
GTEST_SKIP() << "Test for Prov 2.0 devices only."; GTEST_SKIP() << "Test for Prov 2.0 devices only.";
@@ -72,13 +42,15 @@ TEST_F(OEMCryptoAndroidLMPTest, ValidKeyboxTest) {
ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_IsKeyboxValid()); ASSERT_EQ(OEMCrypto_SUCCESS, OEMCrypto_IsKeyboxValid());
} }
/** Android devices must support remote provisioning. Either Provisioning 2, 3
* or 4. */
TEST_F(OEMCryptoAndroidLMPTest, RewrapDeviceRSAKeyImplemented) { TEST_F(OEMCryptoAndroidLMPTest, RewrapDeviceRSAKeyImplemented) {
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED, ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
OEMCrypto_LoadProvisioning(0, nullptr, 0, 0, nullptr, 0, nullptr, OEMCrypto_LoadProvisioning(0, nullptr, 0, 0, nullptr, 0, nullptr,
nullptr)); nullptr));
} }
// The Generic Crypto API functions are required for Android. /** The Generic Crypto API functions are required for Android. */
TEST_F(OEMCryptoAndroidLMPTest, GenericCryptoImplemented) { TEST_F(OEMCryptoAndroidLMPTest, GenericCryptoImplemented) {
ASSERT_NE( ASSERT_NE(
OEMCrypto_ERROR_NOT_IMPLEMENTED, OEMCrypto_ERROR_NOT_IMPLEMENTED,
@@ -96,13 +68,15 @@ TEST_F(OEMCryptoAndroidLMPTest, GenericCryptoImplemented) {
OEMCrypto_HMAC_SHA256, nullptr, 0)); OEMCrypto_HMAC_SHA256, nullptr, 0));
} }
// Android requires support of usage table. The usage table is used for Secure /** Android requires support of usage table. The usage table is used for
// Stops and for offline licenses. * offline licenses. */
TEST_F(OEMCryptoAndroidLMPTest, SupportsUsageTable) { TEST_F(OEMCryptoAndroidLMPTest, SupportsUsageTable) {
ASSERT_TRUE(OEMCrypto_SupportsUsageTable()); ASSERT_TRUE(OEMCrypto_SupportsUsageTable());
} }
// Android devices require L1 OEMCrypto. /** Most Android GMS devices require L1 OEMCrypto. This is not a hard
* requirement for all devices, but is a source of common errors, so we test for
* it here. */
TEST_F(OEMCryptoAndroidLMPTest, Level1Required) { TEST_F(OEMCryptoAndroidLMPTest, Level1Required) {
OEMCrypto_Security_Level security_level = OEMCrypto_SecurityLevel(); OEMCrypto_Security_Level security_level = OEMCrypto_SecurityLevel();
EXPECT_EQ(OEMCrypto_Level1, security_level) EXPECT_EQ(OEMCrypto_Level1, security_level)
@@ -111,32 +85,24 @@ TEST_F(OEMCryptoAndroidLMPTest, Level1Required) {
<< "repeat the tests with the flag --gtest_filter=\"*-*Level1Required\""; << "repeat the tests with the flag --gtest_filter=\"*-*Level1Required\"";
} }
// These tests are required for M Android devices. /** These tests are required for M Android devices. */
class OEMCryptoAndroidMNCTest : public OEMCryptoAndroidLMPTest {}; class OEMCryptoAndroidMNCTest : public OEMCryptoAndroidLMPTest {};
TEST_F(OEMCryptoAndroidMNCTest, MinVersionNumber10) { /** Android devices using Provisioning 2.0 must be able to load a test keybox.
uint32_t version = OEMCrypto_APIVersion(); * If they are not using Provisioning 2.0, then they must use Provisioning 3 or
ASSERT_GE(version, 10u); * 4. */
}
// Android devices using Provisioning 2.0 must be able to load a test keybox.
// If they are not using Provisioning 2.0, then they must use Provisioning 3.0.
TEST_F(OEMCryptoAndroidMNCTest, LoadsTestKeyboxImplemented) { TEST_F(OEMCryptoAndroidMNCTest, LoadsTestKeyboxImplemented) {
if (global_features.provisioning_method != OEMCrypto_Keybox) { if (global_features.provisioning_method != OEMCrypto_Keybox) {
GTEST_SKIP() << "Test for Prov 2.0 devices only."; GTEST_SKIP() << "Test for Prov 2.0 devices only.";
} }
if (OEMCrypto_Keybox == OEMCrypto_GetProvisioningMethod()) { ASSERT_EQ(
ASSERT_EQ( OEMCrypto_SUCCESS,
OEMCrypto_SUCCESS, OEMCrypto_LoadTestKeybox(reinterpret_cast<const uint8_t*>(&kTestKeybox),
OEMCrypto_LoadTestKeybox(reinterpret_cast<const uint8_t*>(&kTestKeybox), sizeof(kTestKeybox)));
sizeof(kTestKeybox)));
} else {
// Android should use keybox or provisioning 3.0.
ASSERT_EQ(OEMCrypto_OEMCertificate, OEMCrypto_GetProvisioningMethod());
}
} }
// Android requires implementation of these functions. /** Android requires implementation of functions that report how many open
* sesions are available. */
TEST_F(OEMCryptoAndroidMNCTest, NumberOfSessionsImplemented) { TEST_F(OEMCryptoAndroidMNCTest, NumberOfSessionsImplemented) {
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED, ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
OEMCrypto_GetNumberOfOpenSessions(nullptr)); OEMCrypto_GetNumberOfOpenSessions(nullptr));
@@ -144,34 +110,20 @@ TEST_F(OEMCryptoAndroidMNCTest, NumberOfSessionsImplemented) {
OEMCrypto_GetMaxNumberOfSessions(nullptr)); OEMCrypto_GetMaxNumberOfSessions(nullptr));
} }
// Android requires implementation of these functions. /** Android requires implementation of `OEMCrypto_QueryKeyControl`. */
TEST_F(OEMCryptoAndroidMNCTest, QueryKeyControlImplemented) { TEST_F(OEMCryptoAndroidMNCTest, QueryKeyControlImplemented) {
ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED, ASSERT_NE(OEMCrypto_ERROR_NOT_IMPLEMENTED,
OEMCrypto_QueryKeyControl(0, nullptr, 0, nullptr, nullptr)); OEMCrypto_QueryKeyControl(0, nullptr, 0, nullptr, nullptr));
} }
// These tests are required for N Android devices. /** These tests are required for R Android devices. */
class OEMCryptoAndroidNYCTest : public OEMCryptoAndroidMNCTest {}; class OEMCryptoAndroidRVCTest : public OEMCryptoAndroidMNCTest {};
TEST_F(OEMCryptoAndroidNYCTest, MinVersionNumber11) { /** Minimum OEMCrypto version 16 is required for all Android R and later
* releases. */
TEST_F(OEMCryptoAndroidRVCTest, MinVersionNumber16) {
uint32_t version = OEMCrypto_APIVersion(); uint32_t version = OEMCrypto_APIVersion();
ASSERT_GE(version, 11u); ASSERT_GE(version, 16u);
}
// These tests are required for O MR1 Android devices.
class OEMCryptoAndroidOCTest : public OEMCryptoAndroidNYCTest {};
TEST_F(OEMCryptoAndroidOCTest, MinVersionNumber13) {
uint32_t version = OEMCrypto_APIVersion();
ASSERT_GE(version, 13u);
}
// These tests are required for Q Android devices.
class OEMCryptoAndroidQTest : public OEMCryptoAndroidOCTest {};
TEST_F(OEMCryptoAndroidQTest, MinVersionNumber14) {
uint32_t version = OEMCrypto_APIVersion();
ASSERT_GE(version, 15u);
} }
} // namespace wvoec } // namespace wvoec