From: Branden Archer Date: Fri, 4 Jan 2019 20:44:25 +0000 (-0800) Subject: Add VTS for Wifi Keystore HAL's getPublicKey() X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=9e45561f00;p=android-x86%2Fsystem-hardware-interfaces.git 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 --- 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