system/hardware/interfaces
リビジョン | a34e152b563c395cc42216f9294491ef93b6c591 (tree) |
---|---|
日時 | 2019-02-01 01:19:50 |
作者 | Branden Archer <brarcher@goog...> |
コミッター | android-build-merger |
Add VTS for Wifi Keystore HAL's getPublicKey()
am: 9e45561f00
Change-Id: I9325b8a63726b37a1b9bf2494471c0a900a6124c
@@ -312,4 +312,67 @@ TEST_F(WifiKeystoreHalTest, GetBlob) { | ||
312 | 312 | EXPECT_EQ(result, true); |
313 | 313 | } |
314 | 314 | |
315 | +/** | |
316 | + * Test for the Wifi Keystore HAL's getPublicKey() call. | |
317 | + */ | |
318 | +TEST_F(WifiKeystoreHalTest, GetPublicKey) { | |
319 | + IKeystore::KeystoreStatusCode statusCode; | |
320 | + | |
321 | + auto callback = [&statusCode](IKeystore::KeystoreStatusCode status, | |
322 | + const ::android::hardware::hidl_vec<uint8_t>& /*value*/) { | |
323 | + statusCode = status; | |
324 | + return; | |
325 | + }; | |
326 | + | |
327 | + // Attempting to export a non-existent key should fail. | |
328 | + | |
329 | + statusCode = IKeystore::KeystoreStatusCode::SUCCESS; | |
330 | + keystore->getPublicKey(nullptr, callback); | |
331 | + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); | |
332 | + | |
333 | + statusCode = IKeystore::KeystoreStatusCode::SUCCESS; | |
334 | + keystore->getPublicKey("", callback); | |
335 | + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); | |
336 | + | |
337 | + statusCode = IKeystore::KeystoreStatusCode::SUCCESS; | |
338 | + keystore->getPublicKey(kTestKeyName, callback); | |
339 | + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); | |
340 | + | |
341 | + // The HAL is expecting the key to belong to the process' user. | |
342 | + // If the key belongs to another user's space (e.g. wifi) it should | |
343 | + // not be accessible and should fail. | |
344 | + | |
345 | + bool result = generateKey(kTestKeyName, KeyPurpose::SIGNING, AID_WIFI); | |
346 | + EXPECT_EQ(result, true); | |
347 | + | |
348 | + keystore->getPublicKey(kTestKeyName, callback); | |
349 | + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); | |
350 | + | |
351 | + result = deleteKey(kTestKeyName, AID_WIFI); | |
352 | + EXPECT_EQ(result, true); | |
353 | + | |
354 | + // Accessing the key belonging to the process' uid should succeed. | |
355 | + | |
356 | + result = generateKey(kTestKeyName, KeyPurpose::SIGNING, UID_SELF); | |
357 | + EXPECT_EQ(result, true); | |
358 | + | |
359 | + keystore->getPublicKey(kTestKeyName, callback); | |
360 | + EXPECT_EQ(IKeystore::KeystoreStatusCode::SUCCESS, statusCode); | |
361 | + | |
362 | + result = deleteKey(kTestKeyName, UID_SELF); | |
363 | + EXPECT_EQ(result, true); | |
364 | + | |
365 | + // A TYPE_GENERIC key (instead of a TYPE_KEYMASTER_10 key) | |
366 | + // should also fail. | |
367 | + | |
368 | + result = insert(kTestKeyName, UID_SELF); | |
369 | + EXPECT_EQ(result, true); | |
370 | + | |
371 | + keystore->getPublicKey(kTestKeyName, callback); | |
372 | + EXPECT_EQ(IKeystore::KeystoreStatusCode::ERROR_UNKNOWN, statusCode); | |
373 | + | |
374 | + result = deleteKey(kTestKeyName, UID_SELF); | |
375 | + EXPECT_EQ(result, true); | |
376 | +} | |
377 | + | |
315 | 378 | } // namespace |