Skip to content

Commit

Permalink
Move *keychain_mac* files to crypto/
Browse files Browse the repository at this point in the history
This is in preparation for moving password_manager/encryptor* to
crypto/.

This also fixes an ODR violation; mock_keychain_mac.cc was being
compiled in two targets which are linked together.

BUG=118564
TEST=


Review URL: http://codereview.chromium.org/9699112

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127358 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
akalin@chromium.org committed Mar 17, 2012
1 parent 236790f commit b9d3d00
Show file tree
Hide file tree
Showing 16 changed files with 270 additions and 200 deletions.
8 changes: 5 additions & 3 deletions chrome/browser/password_manager/encryptor_mac.mm
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.


Expand All @@ -9,10 +9,12 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/encryptor_password_mac.h"
#include "crypto/encryptor.h" #include "crypto/encryptor.h"
#include "crypto/keychain_mac.h"
#include "crypto/symmetric_key.h" #include "crypto/symmetric_key.h"
#include "chrome/browser/password_manager/encryptor_password_mac.h"
#include "chrome/browser/keychain_mac.h" using crypto::MacKeychain;


namespace { namespace {


Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/password_manager/encryptor_password_mac.h
Expand Up @@ -10,11 +10,13 @@


#include "base/basictypes.h" #include "base/basictypes.h"


namespace crypto {
class MacKeychain; class MacKeychain;
} // namespace crypto


class EncryptorPassword { class EncryptorPassword {
public: public:
explicit EncryptorPassword(const MacKeychain& keychain) explicit EncryptorPassword(const crypto::MacKeychain& keychain)
: keychain_(keychain) { : keychain_(keychain) {
} }


Expand All @@ -28,7 +30,7 @@ class EncryptorPassword {


private: private:
DISALLOW_COPY_AND_ASSIGN(EncryptorPassword); DISALLOW_COPY_AND_ASSIGN(EncryptorPassword);
const MacKeychain& keychain_; const crypto::MacKeychain& keychain_;
}; };


#endif // CHROME_BROWSER_PASSWORD_MANAGER_ENCRYPTOR_PASSWORD_H__ #endif // CHROME_BROWSER_PASSWORD_MANAGER_ENCRYPTOR_PASSWORD_H__
4 changes: 3 additions & 1 deletion chrome/browser/password_manager/encryptor_password_mac.mm
Expand Up @@ -9,9 +9,11 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/mac/mac_logging.h" #include "base/mac/mac_logging.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "chrome/browser/keychain_mac.h" #include "crypto/keychain_mac.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"


using crypto::MacKeychain;

namespace { namespace {


// Generates a random password and adds it to the Keychain. The added password // Generates a random password and adds it to the Keychain. The added password
Expand Down
Expand Up @@ -2,12 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.


#include "chrome/browser/mock_keychain_mac.h"
#include "chrome/browser/password_manager/encryptor_password_mac.h" #include "chrome/browser/password_manager/encryptor_password_mac.h"
#include "crypto/mock_keychain_mac.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"


namespace { namespace {


using crypto::MockKeychain;

// Test that if we have an existing password in the Keychain and we are // Test that if we have an existing password in the Keychain and we are
// authorized by the user to read it then we get it back correctly. // authorized by the user to read it then we get it back correctly.
TEST(EncryptorPasswordTest, FindPasswordSuccess) { TEST(EncryptorPasswordTest, FindPasswordSuccess) {
Expand Down
8 changes: 4 additions & 4 deletions chrome/browser/password_manager/password_store_factory.cc
Expand Up @@ -18,9 +18,9 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "chrome/browser/password_manager/password_store_win.h" #include "chrome/browser/password_manager/password_store_win.h"
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
#include "chrome/browser/keychain_mac.h"
#include "chrome/browser/mock_keychain_mac.h"
#include "chrome/browser/password_manager/password_store_mac.h" #include "chrome/browser/password_manager/password_store_mac.h"
#include "crypto/keychain_mac.h"
#include "crypto/mock_keychain_mac.h"
#elif defined(OS_CHROMEOS) || defined(OS_ANDROID) #elif defined(OS_CHROMEOS) || defined(OS_ANDROID)
// Don't do anything. We're going to use the default store. // Don't do anything. We're going to use the default store.
#elif defined(OS_POSIX) #elif defined(OS_POSIX)
Expand Down Expand Up @@ -111,9 +111,9 @@ PasswordStoreFactory::BuildServiceInstanceFor(Profile* profile) const {
profile->GetWebDataService(Profile::IMPLICIT_ACCESS)); profile->GetWebDataService(Profile::IMPLICIT_ACCESS));
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) { if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) {
ps = new PasswordStoreMac(new MockKeychain(), login_db); ps = new PasswordStoreMac(new crypto::MockKeychain(), login_db);
} else { } else {
ps = new PasswordStoreMac(new MacKeychain(), login_db); ps = new PasswordStoreMac(new crypto::MacKeychain(), login_db);
} }
#elif defined(OS_CHROMEOS) || defined(OS_ANDROID) #elif defined(OS_CHROMEOS) || defined(OS_ANDROID)
// For now, we use PasswordStoreDefault. We might want to make a native // For now, we use PasswordStoreDefault. We might want to make a native
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/password_manager/password_store_mac.cc
Expand Up @@ -18,12 +18,13 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/keychain_mac.h"
#include "chrome/browser/password_manager/login_database.h" #include "chrome/browser/password_manager/login_database.h"
#include "chrome/browser/password_manager/password_store_change.h" #include "chrome/browser/password_manager/password_store_change.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "crypto/keychain_mac.h"


using crypto::MacKeychain;
using webkit::forms::PasswordForm; using webkit::forms::PasswordForm;


// Utility class to handle the details of constructing and running a keychain // Utility class to handle the details of constructing and running a keychain
Expand Down
10 changes: 6 additions & 4 deletions chrome/browser/password_manager/password_store_mac.h
Expand Up @@ -14,12 +14,14 @@
#include "chrome/browser/password_manager/login_database.h" #include "chrome/browser/password_manager/login_database.h"
#include "chrome/browser/password_manager/password_store.h" #include "chrome/browser/password_manager/password_store.h"


class MacKeychain;

namespace content { namespace content {
class NotificationService; class NotificationService;
} }


namespace crypto {
class MacKeychain;
}

// Implements PasswordStore on top of the OS X Keychain, with an internal // Implements PasswordStore on top of the OS X Keychain, with an internal
// database for extra metadata. For an overview of the interactions with the // database for extra metadata. For an overview of the interactions with the
// Keychain, as well as the rationale for some of the behaviors, see the // Keychain, as well as the rationale for some of the behaviors, see the
Expand All @@ -29,7 +31,7 @@ class PasswordStoreMac : public PasswordStore {
public: public:
// Takes ownership of |keychain| and |login_db|, both of which must be // Takes ownership of |keychain| and |login_db|, both of which must be
// non-NULL. // non-NULL.
PasswordStoreMac(MacKeychain* keychain, LoginDatabase* login_db); PasswordStoreMac(crypto::MacKeychain* keychain, LoginDatabase* login_db);


// Initializes |thread_| and |notification_service_|. // Initializes |thread_| and |notification_service_|.
virtual bool Init() OVERRIDE; virtual bool Init() OVERRIDE;
Expand Down Expand Up @@ -86,7 +88,7 @@ class PasswordStoreMac : public PasswordStore {
// thread. // thread.
void CreateNotificationService(); void CreateNotificationService();


scoped_ptr<MacKeychain> keychain_; scoped_ptr<crypto::MacKeychain> keychain_;
scoped_ptr<LoginDatabase> login_metadata_db_; scoped_ptr<LoginDatabase> login_metadata_db_;


// Thread that the synchronous methods are run on. // Thread that the synchronous methods are run on.
Expand Down
6 changes: 4 additions & 2 deletions chrome/browser/password_manager/password_store_mac_internal.h
@@ -1,4 +1,4 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.


Expand All @@ -12,7 +12,9 @@
#include <vector> #include <vector>


#include "base/time.h" #include "base/time.h"
#include "chrome/browser/keychain_mac.h" #include "crypto/keychain_mac.h"

using crypto::MacKeychain;


// Adapter that wraps a MacKeychain and provides interaction in terms of // Adapter that wraps a MacKeychain and provides interaction in terms of
// PasswordForms instead of Keychain items. // PasswordForms instead of Keychain items.
Expand Down
Expand Up @@ -12,14 +12,15 @@
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/mock_keychain_mac.h"
#include "chrome/browser/password_manager/password_store_consumer.h" #include "chrome/browser/password_manager/password_store_consumer.h"
#include "chrome/browser/password_manager/password_store_mac.h" #include "chrome/browser/password_manager/password_store_mac.h"
#include "chrome/browser/password_manager/password_store_mac_internal.h" #include "chrome/browser/password_manager/password_store_mac_internal.h"
#include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_paths.h"
#include "content/test/test_browser_thread.h" #include "content/test/test_browser_thread.h"
#include "crypto/mock_keychain_mac.h"


using content::BrowserThread; using content::BrowserThread;
using crypto::MockKeychain;
using webkit::forms::PasswordForm; using webkit::forms::PasswordForm;
using testing::_; using testing::_;
using testing::DoAll; using testing::DoAll;
Expand Down
4 changes: 0 additions & 4 deletions chrome/chrome_browser.gypi
Expand Up @@ -1319,8 +1319,6 @@
'browser/jankometer_mac.cc', 'browser/jankometer_mac.cc',
'browser/jumplist_win.cc', 'browser/jumplist_win.cc',
'browser/jumplist_win.h', 'browser/jumplist_win.h',
'browser/keychain_mac.cc',
'browser/keychain_mac.h',
'browser/language_usage_metrics.cc', 'browser/language_usage_metrics.cc',
'browser/language_usage_metrics.h', 'browser/language_usage_metrics.h',
'browser/low_memory_observer.cc', 'browser/low_memory_observer.cc',
Expand Down Expand Up @@ -1377,8 +1375,6 @@
'browser/metrics/metrics_service.h', 'browser/metrics/metrics_service.h',
'browser/metrics/thread_watcher.cc', 'browser/metrics/thread_watcher.cc',
'browser/metrics/thread_watcher.h', 'browser/metrics/thread_watcher.h',
'browser/mock_keychain_mac.cc',
'browser/mock_keychain_mac.h',
'browser/native_window_notification_source.h', 'browser/native_window_notification_source.h',
'browser/net/browser_url_util.cc', 'browser/net/browser_url_util.cc',
'browser/net/browser_url_util.h', 'browser/net/browser_url_util.h',
Expand Down
2 changes: 0 additions & 2 deletions chrome/chrome_tests.gypi
Expand Up @@ -1523,8 +1523,6 @@
'browser/metrics/metrics_response_unittest.cc', 'browser/metrics/metrics_response_unittest.cc',
'browser/metrics/metrics_service_unittest.cc', 'browser/metrics/metrics_service_unittest.cc',
'browser/metrics/thread_watcher_unittest.cc', 'browser/metrics/thread_watcher_unittest.cc',
'browser/mock_keychain_mac.cc',
'browser/mock_keychain_mac.h',
'browser/net/browser_url_util_unittest.cc', 'browser/net/browser_url_util_unittest.cc',
'browser/net/chrome_fraudulent_certificate_reporter_unittest.cc', 'browser/net/chrome_fraudulent_certificate_reporter_unittest.cc',
'browser/net/chrome_net_log_unittest.cc', 'browser/net/chrome_net_log_unittest.cc',
Expand Down
4 changes: 4 additions & 0 deletions crypto/crypto.gyp
Expand Up @@ -157,8 +157,12 @@
'hmac_nss.cc', 'hmac_nss.cc',
'hmac_openssl.cc', 'hmac_openssl.cc',
'hmac_win.cc', 'hmac_win.cc',
'keychain_mac.cc',
'keychain_mac.h',
'mac_security_services_lock.cc', 'mac_security_services_lock.cc',
'mac_security_services_lock.h', 'mac_security_services_lock.h',
'mock_keychain_mac.cc',
'mock_keychain_mac.h',
'p224_spake.cc', 'p224_spake.cc',
'p224_spake.h', 'p224_spake.h',
'nss_util.cc', 'nss_util.cc',
Expand Down
84 changes: 52 additions & 32 deletions chrome/browser/keychain_mac.cc → crypto/keychain_mac.cc
@@ -1,26 +1,38 @@
// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.


#include "chrome/browser/keychain_mac.h" #include "crypto/keychain_mac.h"

namespace crypto {

MacKeychain::MacKeychain() {}

MacKeychain::~MacKeychain() {}


OSStatus MacKeychain::ItemCopyAttributesAndData( OSStatus MacKeychain::ItemCopyAttributesAndData(
SecKeychainItemRef itemRef, SecKeychainAttributeInfo *info, SecKeychainItemRef itemRef,
SecItemClass *itemClass, SecKeychainAttributeList **attrList, SecKeychainAttributeInfo* info,
UInt32 *length, void **outData) const { SecItemClass* itemClass,
SecKeychainAttributeList** attrList,
UInt32* length,
void** outData) const {
return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass, return SecKeychainItemCopyAttributesAndData(itemRef, info, itemClass,
attrList, length, outData); attrList, length, outData);
} }


OSStatus MacKeychain::ItemModifyAttributesAndData( OSStatus MacKeychain::ItemModifyAttributesAndData(
SecKeychainItemRef itemRef, const SecKeychainAttributeList *attrList, SecKeychainItemRef itemRef,
UInt32 length, const void *data) const { const SecKeychainAttributeList* attrList,
UInt32 length,
const void* data) const {
return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length, return SecKeychainItemModifyAttributesAndData(itemRef, attrList, length,
data); data);
} }


OSStatus MacKeychain::ItemFreeAttributesAndData( OSStatus MacKeychain::ItemFreeAttributesAndData(
SecKeychainAttributeList *attrList, void *data) const { SecKeychainAttributeList* attrList,
void* data) const {
return SecKeychainItemFreeAttributesAndData(attrList, data); return SecKeychainItemFreeAttributesAndData(attrList, data);
} }


Expand All @@ -29,28 +41,35 @@ OSStatus MacKeychain::ItemDelete(SecKeychainItemRef itemRef) const {
} }


OSStatus MacKeychain::SearchCreateFromAttributes( OSStatus MacKeychain::SearchCreateFromAttributes(
CFTypeRef keychainOrArray, SecItemClass itemClass, CFTypeRef keychainOrArray,
const SecKeychainAttributeList *attrList, SecItemClass itemClass,
SecKeychainSearchRef *searchRef) const { const SecKeychainAttributeList* attrList,
SecKeychainSearchRef* searchRef) const {
return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass, return SecKeychainSearchCreateFromAttributes(keychainOrArray, itemClass,
attrList, searchRef); attrList, searchRef);
} }


OSStatus MacKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, OSStatus MacKeychain::SearchCopyNext(SecKeychainSearchRef searchRef,
SecKeychainItemRef *itemRef) const { SecKeychainItemRef* itemRef) const {
return SecKeychainSearchCopyNext(searchRef, itemRef); return SecKeychainSearchCopyNext(searchRef, itemRef);
} }


OSStatus MacKeychain::AddInternetPassword( OSStatus MacKeychain::AddInternetPassword(
SecKeychainRef keychain, SecKeychainRef keychain,
UInt32 serverNameLength, const char *serverName, UInt32 serverNameLength,
UInt32 securityDomainLength, const char *securityDomain, const char* serverName,
UInt32 accountNameLength, const char *accountName, UInt32 securityDomainLength,
UInt32 pathLength, const char *path, const char* securityDomain,
UInt16 port, SecProtocolType protocol, UInt32 accountNameLength,
const char* accountName,
UInt32 pathLength,
const char* path,
UInt16 port,
SecProtocolType protocol,
SecAuthenticationType authenticationType, SecAuthenticationType authenticationType,
UInt32 passwordLength, const void *passwordData, UInt32 passwordLength,
SecKeychainItemRef *itemRef) const { const void* passwordData,
SecKeychainItemRef* itemRef) const {
return SecKeychainAddInternetPassword(keychain, return SecKeychainAddInternetPassword(keychain,
serverNameLength, serverName, serverNameLength, serverName,
securityDomainLength, securityDomain, securityDomainLength, securityDomain,
Expand All @@ -63,12 +82,12 @@ OSStatus MacKeychain::AddInternetPassword(


OSStatus MacKeychain::FindGenericPassword(CFTypeRef keychainOrArray, OSStatus MacKeychain::FindGenericPassword(CFTypeRef keychainOrArray,
UInt32 serviceNameLength, UInt32 serviceNameLength,
const char *serviceName, const char* serviceName,
UInt32 accountNameLength, UInt32 accountNameLength,
const char *accountName, const char* accountName,
UInt32 *passwordLength, UInt32* passwordLength,
void **passwordData, void** passwordData,
SecKeychainItemRef *itemRef) const { SecKeychainItemRef* itemRef) const {
return SecKeychainFindGenericPassword(keychainOrArray, return SecKeychainFindGenericPassword(keychainOrArray,
serviceNameLength, serviceNameLength,
serviceName, serviceName,
Expand All @@ -79,19 +98,19 @@ OSStatus MacKeychain::FindGenericPassword(CFTypeRef keychainOrArray,
itemRef); itemRef);
} }


OSStatus MacKeychain::ItemFreeContent(SecKeychainAttributeList *attrList, OSStatus MacKeychain::ItemFreeContent(SecKeychainAttributeList* attrList,
void *data) const { void* data) const {
return SecKeychainItemFreeContent(attrList, data); return SecKeychainItemFreeContent(attrList, data);
} }


OSStatus MacKeychain::AddGenericPassword(SecKeychainRef keychain, OSStatus MacKeychain::AddGenericPassword(SecKeychainRef keychain,
UInt32 serviceNameLength, UInt32 serviceNameLength,
const char *serviceName, const char* serviceName,
UInt32 accountNameLength, UInt32 accountNameLength,
const char *accountName, const char* accountName,
UInt32 passwordLength, UInt32 passwordLength,
const void *passwordData, const void* passwordData,
SecKeychainItemRef *itemRef) const { SecKeychainItemRef* itemRef) const {
return SecKeychainAddGenericPassword(keychain, return SecKeychainAddGenericPassword(keychain,
serviceNameLength, serviceNameLength,
serviceName, serviceName,
Expand All @@ -103,7 +122,8 @@ OSStatus MacKeychain::AddGenericPassword(SecKeychainRef keychain,
} }


void MacKeychain::Free(CFTypeRef ref) const { void MacKeychain::Free(CFTypeRef ref) const {
if (ref) { if (ref)
CFRelease(ref); CFRelease(ref);
}
} }

} // namespace crypto

0 comments on commit b9d3d00

Please sign in to comment.