OSDN Git Service

Add VTS for Wifi Keystore HAL's getPublicKey()
authorBranden Archer <brarcher@google.com>
Fri, 4 Jan 2019 20:44:25 +0000 (12:44 -0800)
committerBranden Archer <brarcher@google.com>
Tue, 29 Jan 2019 19:17:43 +0000 (11:17 -0800)
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

wifi/keystore/1.0/vts/functional/VtsHalWifiKeystoreV1_0TargetTest.cpp

index e769b1b..fdf4288 100644 (file)
@@ -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<uint8_t>& /*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