From 9e45561f0054419363cb9ad0286deca82630a2e0 Mon Sep 17 00:00:00 2001 From: Branden Archer Date: Fri, 4 Jan 2019 12:44:25 -0800 Subject: [PATCH] Add VTS for Wifi Keystore HAL's getPublicKey() This exercises paths through the Wifi Keystore HAL's getPublicKey() method. Test: atest system/hardware/interfaces/wifi/keystore/1.0/ vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp Change-Id: Ie549ea1c1cd6c767c013c340ae297ae8dfacca69 --- .../VtsHalWifiKeystoreV1_0TargetTest.cpp | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp b/wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp index e769b1b..fdf4288 100644 --- a/wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp +++ b/wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp @@ -312,4 +312,67 @@ TEST_F(WifiKeystoreHalTest, GetBlob) { EXPECT_EQ(result, true); } +/** + * Test for the Wifi Keystore HAL's getPublicKey() call. + */ +TEST_F(WifiKeystoreHalTest, GetPublicKey) { + IKeystore::KeystoreStatusCode statusCode; + + auto callback = [&statusCode](IKeystore::KeystoreStatusCode status, + const ::android::hardware::hidl_vec& /*value*/) { + statusCode = status; + return; + }; + + // Attempting to export a non-existent key should fail. + + statusCode = IKeystore::KeystoreStatusCode::SUCCESS; + keystore->getPublicKey(nullptr, callback); + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); + + statusCode = IKeystore::KeystoreStatusCode::SUCCESS; + keystore->getPublicKey("", callback); + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); + + statusCode = IKeystore::KeystoreStatusCode::SUCCESS; + keystore->getPublicKey(kTestKeyName, callback); + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); + + // The HAL is expecting the key to belong to the process' user. + // If the key belongs to another user's space (e.g. wifi) it should + // not be accessible and should fail. + + bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, AID_WIFI); + EXPECT_EQ(result, true); + + keystore->getPublicKey(kTestKeyName, callback); + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); + + result = deleteKey(kTestKeyName, AID_WIFI); + EXPECT_EQ(result, true); + + // Accessing the key belonging to the process' uid should succeed. + + result = generateKey(kTestKeyName, KeyPurpose::SIGNING, UID_SELF); + EXPECT_EQ(result, true); + + keystore->getPublicKey(kTestKeyName, callback); + EXPECT_EQ(IKeystore::KeystoreStatusCode::SUCCESS, statusCode); + + result = deleteKey(kTestKeyName, UID_SELF); + EXPECT_EQ(result, true); + + // A TYPE_GENERIC key (instead of a TYPE_KEYMASTER_10 key) + // should also fail. + + result = insert(kTestKeyName, UID_SELF); + EXPECT_EQ(result, true); + + keystore->getPublicKey(kTestKeyName, callback); + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); + + result = deleteKey(kTestKeyName, UID_SELF); + EXPECT_EQ(result, true); +} + } // namespace -- 2.11.0