diff options
author | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 01:51:45 +0000 |
---|---|---|
committer | dhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 01:51:45 +0000 |
commit | ecbf289873708bcbaa35780063570e346faafd57 (patch) | |
tree | 524953253f35fb0c095f90aaff16a6103b5e8a18 /chrome/browser/password_manager/encryptor_unittest.cc | |
parent | d5975c6b5d408767db7934347b7d4d137c657d30 (diff) | |
download | chromium_src-ecbf289873708bcbaa35780063570e346faafd57.zip chromium_src-ecbf289873708bcbaa35780063570e346faafd57.tar.gz chromium_src-ecbf289873708bcbaa35780063570e346faafd57.tar.bz2 |
AutoFill credit cards should be encrypted on the Mac
These changes add encryption support on Mac for the Encryptor class. AES 128 bit is used for the encryption, and the auto-generated password is stored now in the Mac Keychain. This implies the Encryptor class on Mac can now block for user input, and can fail if access is denied.
BUG=42038, 49131
TEST=EncryptorTest.CypherTextDiffers, EncryptorTest.DecryptError, EncryptorPasswordTest.*
Review URL: http://codereview.chromium.org/2943014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52590 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/password_manager/encryptor_unittest.cc')
-rw-r--r-- | chrome/browser/password_manager/encryptor_unittest.cc | 96 |
1 files changed, 82 insertions, 14 deletions
diff --git a/chrome/browser/password_manager/encryptor_unittest.cc b/chrome/browser/password_manager/encryptor_unittest.cc index 29e518d8..8ca176f 100644 --- a/chrome/browser/password_manager/encryptor_unittest.cc +++ b/chrome/browser/password_manager/encryptor_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -12,25 +12,46 @@ namespace { -TEST(EncryptorTest, String16EncryptionDecryption) { +class EncryptorTest : public testing::Test { + public: + EncryptorTest() {} + + virtual void SetUp() { +#if defined(OS_MACOSX) + Encryptor::UseMockKeychain(true); +#endif + } + + private: + DISALLOW_COPY_AND_ASSIGN(EncryptorTest); +}; + +TEST_F(EncryptorTest, String16EncryptionDecryption) { string16 plaintext; string16 result; std::string utf8_plaintext; std::string utf8_result; std::string ciphertext; - // test borderline cases (empty strings) + // Test borderline cases (empty strings). EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext)); EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result)); EXPECT_EQ(plaintext, result); - // test a simple string + // Test a simple string. plaintext = ASCIIToUTF16("hello"); EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext)); EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result)); EXPECT_EQ(plaintext, result); - // test unicode + // Test a 16-byte aligned string. This previously hit a boundary error in + // base::Encryptor::Crypt() on Mac. + plaintext = ASCIIToUTF16("1234567890123456"); + EXPECT_TRUE(Encryptor::EncryptString16(plaintext, &ciphertext)); + EXPECT_TRUE(Encryptor::DecryptString16(ciphertext, &result)); + EXPECT_EQ(plaintext, result); + + // Test Unicode. char16 wchars[] = { 0xdbeb, 0xdf1b, 0x4e03, 0x6708, 0x8849, 0x661f, 0x671f, 0x56db, 0x597c, 0x4e03, 0x6708, 0x56db, 0x6708, 0xe407, 0xdbaf, @@ -53,27 +74,74 @@ TEST(EncryptorTest, String16EncryptionDecryption) { EXPECT_EQ(utf8_plaintext, UTF16ToUTF8(result)); } -TEST(EncryptorTest, EncryptionDecryption) { +TEST_F(EncryptorTest, EncryptionDecryption) { std::string plaintext; std::string result; std::string ciphertext; - // test borderline cases (empty strings) - EXPECT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); - EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &result)); + // Test borderline cases (empty strings). + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); EXPECT_EQ(plaintext, result); - // test a simple string + // Test a simple string. plaintext = "hello"; - EXPECT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); - EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &result)); + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); EXPECT_EQ(plaintext, result); // Make sure it null terminates. plaintext.assign("hello", 3); - EXPECT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); - EXPECT_TRUE(Encryptor::DecryptString(ciphertext, &result)); + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); EXPECT_EQ(plaintext, "hel"); } +// Encryption currently only enabled on Mac and Windows. +// TODO(dhollowa): http://crbug.com/49115 Implement secure store on Linux. +#if defined(OS_WIN) || defined(OS_MACOSX) +TEST_F(EncryptorTest, CypherTextDiffers) { + std::string plaintext; + std::string result; + std::string ciphertext; + + // Test borderline cases (empty strings). + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); + // |cyphertext| is empty on the Mac, different on Windows. + EXPECT_TRUE(ciphertext.empty() || plaintext != ciphertext); + EXPECT_EQ(plaintext, result); + + // Test a simple string. + plaintext = "hello"; + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); + EXPECT_NE(plaintext, ciphertext); + EXPECT_EQ(plaintext, result); + + // Make sure it null terminates. + plaintext.assign("hello", 3); + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + ASSERT_TRUE(Encryptor::DecryptString(ciphertext, &result)); + EXPECT_NE(plaintext, ciphertext); + EXPECT_EQ(result, "hel"); +} + +TEST_F(EncryptorTest, DecryptError) { + std::string plaintext; + std::string result; + std::string ciphertext; + + // Test a simple string, messing with ciphertext prior to decrypting. + plaintext = "hello"; + ASSERT_TRUE(Encryptor::EncryptString(plaintext, &ciphertext)); + EXPECT_NE(plaintext, ciphertext); + ASSERT_LT(4UL, ciphertext.size()); + ciphertext[3] = ciphertext[0] + 1; + EXPECT_FALSE(Encryptor::DecryptString(ciphertext, &result)); + EXPECT_NE(plaintext, result); + EXPECT_TRUE(result.empty()); +} +#endif + } // namespace |