| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "content/browser/net/sqlite_persistent_cookie_store.h" | 5 #include "content/browser/net/sqlite_persistent_cookie_store.h" | 
| 6 | 6 | 
| 7 #include <map> | 7 #include <map> | 
| 8 #include <set> | 8 #include <set> | 
| 9 | 9 | 
| 10 #include "base/bind.h" | 10 #include "base/bind.h" | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
| 34 namespace content { | 34 namespace content { | 
| 35 | 35 | 
| 36 namespace { | 36 namespace { | 
| 37 | 37 | 
| 38 const base::FilePath::CharType kCookieFilename[] = FILE_PATH_LITERAL("Cookies"); | 38 const base::FilePath::CharType kCookieFilename[] = FILE_PATH_LITERAL("Cookies"); | 
| 39 | 39 | 
| 40 class CookieCryptor : public content::CookieCryptoDelegate { | 40 class CookieCryptor : public content::CookieCryptoDelegate { | 
| 41  public: | 41  public: | 
| 42   CookieCryptor(); | 42   CookieCryptor(); | 
| 43   virtual bool EncryptString(const std::string& plaintext, | 43   virtual bool EncryptString(const std::string& plaintext, | 
| 44                              std::string* ciphertext) OVERRIDE; | 44                              std::string* ciphertext) override; | 
| 45   virtual bool DecryptString(const std::string& ciphertext, | 45   virtual bool DecryptString(const std::string& ciphertext, | 
| 46                              std::string* plaintext) OVERRIDE; | 46                              std::string* plaintext) override; | 
| 47 | 47 | 
| 48  private: | 48  private: | 
| 49   scoped_ptr<crypto::SymmetricKey> key_; | 49   scoped_ptr<crypto::SymmetricKey> key_; | 
| 50   crypto::Encryptor encryptor_; | 50   crypto::Encryptor encryptor_; | 
| 51 }; | 51 }; | 
| 52 | 52 | 
| 53 CookieCryptor::CookieCryptor() : key_( | 53 CookieCryptor::CookieCryptor() : key_( | 
| 54     crypto::SymmetricKey::DeriveKeyFromPassword( | 54     crypto::SymmetricKey::DeriveKeyFromPassword( | 
| 55         crypto::SymmetricKey::AES, "password", "saltiest", 1000, 256)) { | 55         crypto::SymmetricKey::AES, "password", "saltiest", 1000, 256)) { | 
| 56   std::string iv("the iv: 16 bytes"); | 56   std::string iv("the iv: 16 bytes"); | 
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 166   } | 166   } | 
| 167 | 167 | 
| 168   std::string ReadRawDBContents() { | 168   std::string ReadRawDBContents() { | 
| 169     std::string contents; | 169     std::string contents; | 
| 170     if (!base::ReadFileToString(temp_dir_.path().Append(kCookieFilename), | 170     if (!base::ReadFileToString(temp_dir_.path().Append(kCookieFilename), | 
| 171                                 &contents)) | 171                                 &contents)) | 
| 172       return std::string(); | 172       return std::string(); | 
| 173     return contents; | 173     return contents; | 
| 174   } | 174   } | 
| 175 | 175 | 
| 176   virtual void SetUp() OVERRIDE { | 176   virtual void SetUp() override { | 
| 177     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 177     ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 
| 178   } | 178   } | 
| 179 | 179 | 
| 180   virtual void TearDown() OVERRIDE { | 180   virtual void TearDown() override { | 
| 181     DestroyStore(); | 181     DestroyStore(); | 
| 182     pool_owner_->pool()->Shutdown(); | 182     pool_owner_->pool()->Shutdown(); | 
| 183   } | 183   } | 
| 184 | 184 | 
| 185  protected: | 185  protected: | 
| 186   base::MessageLoop main_loop_; | 186   base::MessageLoop main_loop_; | 
| 187   scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 187   scoped_ptr<base::SequencedWorkerPoolOwner> pool_owner_; | 
| 188   base::WaitableEvent loaded_event_; | 188   base::WaitableEvent loaded_event_; | 
| 189   base::WaitableEvent key_loaded_event_; | 189   base::WaitableEvent key_loaded_event_; | 
| 190   base::WaitableEvent db_thread_event_; | 190   base::WaitableEvent db_thread_event_; | 
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 599   EXPECT_EQ(2, resultcount); | 599   EXPECT_EQ(2, resultcount); | 
| 600 | 600 | 
| 601   // Verify that "encrypted_value" is NOT visible in the file. | 601   // Verify that "encrypted_value" is NOT visible in the file. | 
| 602   contents = ReadRawDBContents(); | 602   contents = ReadRawDBContents(); | 
| 603   EXPECT_NE(0U, contents.length()); | 603   EXPECT_NE(0U, contents.length()); | 
| 604   EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); | 604   EXPECT_EQ(contents.find("encrypted_value123XYZ"), std::string::npos); | 
| 605   EXPECT_EQ(contents.find("something456ABC"), std::string::npos); | 605   EXPECT_EQ(contents.find("something456ABC"), std::string::npos); | 
| 606 } | 606 } | 
| 607 | 607 | 
| 608 }  // namespace content | 608 }  // namespace content | 
| OLD | NEW | 
|---|