Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1232)

Unified Diff: chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc

Issue 729803002: Easy Sign-in: Use TPM RSA key to sign nonce in sign-in protocol (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
diff --git a/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9e6a5d9b454b0d0d269ff77380141cbf4a539231
--- /dev/null
+++ b/chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_unittest.cc
@@ -0,0 +1,463 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <cryptohi.h>
+
+#include "base/base64.h"
+#include "base/macros.h"
+#include "base/message_loop/message_loop.h"
+#include "base/prefs/testing_pref_service.h"
+#include "base/run_loop.h"
+#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager.h"
+#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_factory.h"
+#include "chrome/browser/chromeos/login/users/fake_user_manager.h"
+#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
+#include "chrome/browser/prefs/browser_prefs.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/scoped_testing_local_state.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chrome/test/base/testing_pref_service_syncable.h"
+#include "chrome/test/base/testing_profile.h"
+#include "chrome/test/base/testing_profile_manager.h"
+#include "crypto/scoped_test_system_nss_key_slot.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+// User that is associated with test user profile.
+const char kTestUserId[] = "user_id@somewhere.com";
+
+// Public part of the RSA key pair used as the RSA key pair associated with
+// test user's Easy Unlock service.
+const char kTestPublicKey[] = {
+ 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+ 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00,
+ 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, 0xcb, 0x5a, 0x8d,
+ 0x34, 0xa2, 0xe3, 0x43, 0x16, 0x94, 0x8d, 0xce, 0xa9, 0x92, 0xb0, 0x35,
+ 0x5a, 0x34, 0x50, 0xd4, 0x7f, 0x14, 0x1f, 0xa3, 0x8e, 0x48, 0x2c, 0x42,
+ 0xe8, 0xe4, 0xf6, 0x38, 0x5a, 0xdf, 0x08, 0x6b, 0x0e, 0x78, 0xc9, 0xfc,
+ 0x72, 0x03, 0xb8, 0xd2, 0x75, 0x1d, 0x56, 0x8f, 0x6d, 0x8d, 0xe2, 0x65,
+ 0x3b, 0x66, 0xbb, 0x66, 0xe3, 0x3a, 0x00, 0xc1, 0x4a, 0xe2, 0xf2, 0xc8,
+ 0x2d, 0x95, 0x74, 0x5b, 0x65, 0xaa, 0xfd, 0xe1, 0x11, 0xf9, 0x9e, 0x73,
+ 0x3d, 0x96, 0xb5, 0xae, 0x19, 0x03, 0x74, 0x0f, 0xfa, 0xbd, 0x52, 0x72,
+ 0x83, 0x08, 0x1e, 0x53, 0x08, 0x30, 0xb6, 0xd3, 0xef, 0x4b, 0x2d, 0x65,
+ 0x3c, 0x7d, 0xba, 0x55, 0xfe, 0x7d, 0x1c, 0xc5, 0xf1, 0x4e, 0x9c, 0xae,
+ 0x27, 0xe2, 0x1b, 0x42, 0x2c, 0xd9, 0x6a, 0x81, 0x6c, 0x51, 0x2d, 0x7b,
+ 0x7d, 0x28, 0xe3, 0xab, 0xaf, 0x30, 0x33, 0xd1, 0x46, 0xd1, 0xbe, 0x62,
+ 0x2e, 0xd5, 0xfd, 0x32, 0x68, 0xb6, 0xe2, 0x95, 0x59, 0x6e, 0x69, 0xe9,
+ 0x9c, 0x24, 0xf7, 0x71, 0xde, 0x5f, 0xd5, 0xc5, 0x8a, 0x71, 0xb3, 0x65,
+ 0x77, 0xf9, 0x29, 0xf3, 0xce, 0x0a, 0x00, 0xca, 0xd7, 0xf9, 0x2e, 0x45,
+ 0x04, 0xb5, 0x68, 0x1f, 0xfe, 0x4e, 0xac, 0xdd, 0xaa, 0xc5, 0x24, 0x6e,
+ 0xec, 0x63, 0x36, 0x5f, 0xb9, 0x94, 0x0c, 0x7c, 0xf3, 0xcf, 0xa9, 0x44,
+ 0x80, 0x99, 0x13, 0x89, 0x68, 0xbc, 0x6c, 0xfb, 0xe7, 0x2c, 0x94, 0x2e,
+ 0x99, 0x31, 0xf1, 0x02, 0xd7, 0x27, 0xaf, 0xae, 0x69, 0xa9, 0x95, 0xd5,
+ 0xf2, 0x6a, 0x6c, 0x46, 0x95, 0xdb, 0x30, 0xc9, 0x9f, 0xbe, 0xa0, 0x71,
+ 0xc9, 0x74, 0xfb, 0xbb, 0x0a, 0x8b, 0xa1, 0x7c, 0x1a, 0xdf, 0xa3, 0xb2,
+ 0x18, 0x29, 0xe5, 0xf6, 0x94, 0x9f, 0xa3, 0x50, 0x11, 0x4b, 0xfe, 0x05,
+ 0xcb, 0x02, 0x03, 0x01, 0x00, 0x01
+};
+
+// Private part of the RSA key pair used as the RSA key pair associated with
+// test user's Easy Unlock service.
+const unsigned char kTestPrivateKey[] = {
+ 0x30, 0x82, 0x04, 0xbf, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 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6, 0x47, 0x97, 0xae, 0xae, 0x96, 0xc0, 0x3a, 0x59, 0x67, 0x9e, 0x3b,
+ 0xe5, 0xbb, 0x57, 0x61, 0x8f, 0x4f, 0x9a, 0x01, 0x02, 0x81, 0x80, 0x57,
+ 0xfa, 0x17, 0x0a, 0x87, 0x99, 0xdb, 0x93, 0x94, 0x10, 0x3f, 0xa9, 0xbf,
+ 0xa4, 0x02, 0x7d, 0xf1, 0x04, 0x41, 0x08, 0x68, 0x6a, 0x9b, 0x79, 0xfd,
+ 0xf4, 0x10, 0x8f, 0xc8, 0xdd, 0xfe, 0x0c, 0xc7, 0xc3, 0x42, 0x2d, 0xac,
+ 0x80, 0xc3, 0xfb, 0xa0, 0x8d, 0x31, 0x9b, 0x5b, 0xf8, 0xbb, 0x8c, 0x05,
+ 0x56, 0xaf, 0x49, 0xca, 0xa9, 0xe5, 0xab, 0x80, 0xa9, 0x39, 0xfd, 0xd4,
+ 0x78, 0x45, 0xaa, 0xd6, 0x27, 0x91, 0xa8, 0x76, 0x01, 0x98, 0xf0, 0x4f,
+ 0x48, 0xe0, 0x4e, 0x53, 0x53, 0x55, 0x5e, 0x2b, 0x1a, 0x4f, 0x00, 0x62,
+ 0xe4, 0x0e, 0x05, 0xa0, 0x94, 0x6e, 0xff, 0xd4, 0x13, 0x6f, 0x2e, 0x7c,
+ 0x08, 0x92, 0x20, 0xa9, 0x29, 0xee, 0xb0, 0xbb, 0x14, 0x52, 0xf9, 0x6d,
+ 0x28, 0xd9, 0xbd, 0x84, 0x11, 0x43, 0x71, 0xc2, 0x60, 0x69, 0xb3, 0x34,
+ 0xe5, 0xae, 0xd7, 0x75, 0x4c, 0xb8, 0x3d, 0x0a
+};
+
+// Closure that fail the test if it's called.
+void ExpectNotCalledCallback() {
+ EXPECT_FALSE(true) << "Not reached";
xiyuan 2014/12/02 23:15:58 nit: ADD_FAILURE() << "Not reached";
tbarzic 2014/12/03 19:10:28 Done.
+}
+
+// Used to track how may |EasyUnlockTpmKeyManager::IsTpmKeyPresent| callbacks
+// have been called. It increases |*count| by 1.
+void IncreaseCount(int* count) {
+ ++(*count);
+}
+
+class EasyUnlockTpmKeyManagerTest : public testing::Test {
+ public:
+ EasyUnlockTpmKeyManagerTest()
+ : user_manager_(new chromeos::FakeUserManager),
+ user_manager_enabler_(user_manager_),
+ profile_manager_(TestingBrowserProcess::GetGlobal()) {
+ }
+ ~EasyUnlockTpmKeyManagerTest() override {}
+
+ void SetUp() override {
+ ASSERT_TRUE(profile_manager_.SetUp());
+ user_manager_->AddUser(kTestUserId);
+
+ scoped_ptr<TestingPrefServiceSyncable> user_prefs(
+ new TestingPrefServiceSyncable());
+ chrome::RegisterUserProfilePrefs(user_prefs->registry());
+
+ signin_profile_ = profile_manager_.CreateTestingProfile(
+ chrome::kInitialProfile,
+ scoped_ptr<TestingPrefServiceSyncable>(),
+ base::UTF8ToUTF16(chrome::kInitialProfile),
+ 0 /* avatar id */,
+ std::string() /* supervized user id */,
+ TestingProfile::TestingFactories());
+
+ user_profile_ = profile_manager_.CreateTestingProfile(
+ kTestUserId,
+ user_prefs.Pass(),
+ base::UTF8ToUTF16(kTestUserId),
+ 0 /* avatar id */,
+ std::string() /* supervized user id */,
+ TestingProfile::TestingFactories());
+ }
+
+ void TearDown() override {
+ profile_manager_.DeleteTestingProfile(kTestUserId);
+ profile_manager_.DeleteTestingProfile(chrome::kInitialProfile);
+ }
+
+ // Creates and sets test system NSS key slot.
+ bool SetUpTestSystemSlot() {
+ test_system_slot_.reset(new crypto::ScopedTestSystemNSSKeySlot());
+ return test_system_slot_->ConstructedSuccessfully();
+ }
+
+ // Imports a private RSA key to the test system slot.
+ // It returns whether the key has been imported. In order for the methos to
+ // succeed, the test system slot must have been set up
+ // (using |SetUpTestSystemSlot|).
+ bool ImportPrivateKey(const unsigned char* key, int key_size) {
+ if (!test_system_slot_ || !test_system_slot_->slot()) {
+ LOG(ERROR) << "System slot not initialized.";
+ return false;
+ }
+
+ SECItem pki_der_user = {
+ siBuffer,
+ // NSS requires non-const data even though it is just for input.
+ const_cast<unsigned char*>(key),
+ key_size
+ };
+
+ SECKEYPrivateKey* seckey = NULL;
+ return SECSuccess ==
+ PK11_ImportDERPrivateKeyInfoAndReturnKey(test_system_slot_->slot(),
+ &pki_der_user,
+ NULL, // nickname
+ NULL, // publicValue
+ true, // isPerm
+ true, // isPrivate
+ KU_ALL, // usage
+ &seckey,
+ NULL);
+ }
+
+ // Returns EasyUnlockTPMKeyManager for user profile.
+ EasyUnlockTpmKeyManager* user_key_manager() {
+ return EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(user_profile_);
+ }
+
+ // Returns EasyUnlockTPMKeyManager for signin profile.
+ EasyUnlockTpmKeyManager* signin_key_manager() {
+ return EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(signin_profile_);
+ }
+
+ // Sets TPM public key pref in the test user's profile prefs.
+ void SetUserPrefPublicKey(const std::string& value) {
+ PrefService* prefs = user_profile_->GetPrefs();
+ std::string encoded;
+ base::Base64Encode(value, &encoded);
+ prefs->SetString(prefs::kEasyUnlockUserTpmKey, encoded);
+ }
+
+ private:
+ // The NSS system slot used by EasyUnlockTPMKeyManagers in tests.
+ scoped_ptr<crypto::ScopedTestSystemNSSKeySlot> test_system_slot_;
+
+ base::MessageLoop message_loop_;
+
+ // Needed to properly set up signin and user profiles for test.
+ chromeos::FakeUserManager* user_manager_;
+ chromeos::ScopedUserManagerEnabler user_manager_enabler_;
+ TestingProfileManager profile_manager_;
+
+ // The testing profiles that own EasyUnlockTPMKeyManager services.
+ // Owned by |profile_manager_|.
+ TestingProfile* user_profile_;
+ TestingProfile* signin_profile_;
+
+ DISALLOW_COPY_AND_ASSIGN(EasyUnlockTpmKeyManagerTest);
+};
+
+TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPair) {
+ base::RunLoop run_loop;
+ EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ EXPECT_TRUE(signin_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ run_loop.QuitClosure()));
+ EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+
+ ASSERT_TRUE(SetUpTestSystemSlot());
+ run_loop.Run();
+
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ signin_key_manager()->GetPublicTpmKey(kTestUserId));
+
+ EXPECT_TRUE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ base::Bind(&ExpectNotCalledCallback)));
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
+ int callback_count = 0;
+ base::RunLoop run_loop;
+
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ run_loop.QuitClosure()));
+ EXPECT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ base::Bind(&IncreaseCount, &callback_count)));
+ EXPECT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ base::Bind(&IncreaseCount, &callback_count)));
+ // Verify that the method works with empty callback.
+ EXPECT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId, false /* check_private_key */, base::Closure()));
+
+ ASSERT_TRUE(SetUpTestSystemSlot());
+ EXPECT_EQ(0, callback_count);
+
+ run_loop.Run();
+
+ EXPECT_EQ(2, callback_count);
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ signin_key_manager()->GetPublicTpmKey(kTestUserId));
+
+ EXPECT_TRUE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ base::Bind(&ExpectNotCalledCallback)));
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInUserPrefs) {
+ SetUserPrefPublicKey(std::string(kTestPublicKey, arraysize(kTestPublicKey)));
+
+ EXPECT_TRUE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ base::Bind(&ExpectNotCalledCallback)));
+
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ std::string(kTestPublicKey, arraysize(kTestPublicKey)));
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ signin_key_manager()->GetPublicTpmKey(kTestUserId));
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInUserPrefsCheckPrivateKey) {
+ SetUserPrefPublicKey(std::string(kTestPublicKey, arraysize(kTestPublicKey)));
+
+ base::RunLoop run_loop;
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ true /* check_private_key */,
+ run_loop.QuitClosure()));
+
+ ASSERT_TRUE(SetUpTestSystemSlot());
+ run_loop.Run();
+
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ EXPECT_NE(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ std::string(kTestPublicKey, arraysize(kTestPublicKey)));
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ signin_key_manager()->GetPublicTpmKey(kTestUserId));
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInUserPrefsCheckPrivateKey_OK) {
+ ASSERT_TRUE(SetUpTestSystemSlot());
+ ASSERT_TRUE(ImportPrivateKey(kTestPrivateKey, arraysize(kTestPrivateKey)));
+ SetUserPrefPublicKey(std::string(kTestPublicKey, arraysize(kTestPublicKey)));
+
+ int callback_count = 0;
+ base::RunLoop run_loop;
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ true /* check_private_key */,
+ run_loop.QuitClosure()));
+
+ EXPECT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ base::Bind(&IncreaseCount, &callback_count)));
+
+ run_loop.Run();
+
+ EXPECT_EQ(1, callback_count);
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ std::string(kTestPublicKey, arraysize(kTestPublicKey)));
+ EXPECT_EQ(user_key_manager()->GetPublicTpmKey(kTestUserId),
+ signin_key_manager()->GetPublicTpmKey(kTestUserId));
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutTriggers) {
+ base::RunLoop run_loop_1;
+ base::RunLoop run_loop_2;
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ run_loop_1.QuitClosure()));
+
+ ASSERT_TRUE(user_key_manager()->SetGetSystemSlotTimeoutMs(0));
+ run_loop_2.RunUntilIdle();
+
+ ASSERT_TRUE(SetUpTestSystemSlot());
+
+ run_loop_1.Run();
+
+ EXPECT_TRUE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeout_SlotFetchedInTime) {
+ base::RunLoop run_loop;
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ run_loop.QuitClosure()));
+
+ ASSERT_TRUE(user_key_manager()->SetGetSystemSlotTimeoutMs(0));
+
+ ASSERT_TRUE(SetUpTestSystemSlot());
+
+ run_loop.Run();
+
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+}
+
+TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutAfterSlotFetched) {
+ base::RunLoop run_loop;
+ ASSERT_FALSE(user_key_manager()->IsTpmKeyPresent(
+ kTestUserId,
+ false /* check_private_key */,
+ run_loop.QuitClosure()));
+
+ ASSERT_TRUE(SetUpTestSystemSlot());
+
+ ASSERT_FALSE(user_key_manager()->SetGetSystemSlotTimeoutMs(0));
+
+ run_loop.Run();
+
+ EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(kTestUserId).empty());
+}
+
+} // namespace

Powered by Google App Engine
This is Rietveld 408576698