diff options
author | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 23:36:16 +0000 |
---|---|---|
committer | wtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-10 23:36:16 +0000 |
commit | 4156b9a4c1c04ec63eed033865dd33663fca9216 (patch) | |
tree | 3ae4a962ab364b412d487ad8200cdca481a0e315 /base/crypto | |
parent | b7af0f9a510d5bd372e3a589fb1ad2da3a2aeed1 (diff) | |
download | chromium_src-4156b9a4c1c04ec63eed033865dd33663fca9216.zip chromium_src-4156b9a4c1c04ec63eed033865dd33663fca9216.tar.gz chromium_src-4156b9a4c1c04ec63eed033865dd33663fca9216.tar.bz2 |
Separate GetMacSecurityServicesLock from cssm_init.h so that we can use
the function without including CSSM headers.
R=thomasvl
BUG=none
TEST=no compilation errors
Review URL: http://codereview.chromium.org/6659019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/crypto')
-rw-r--r-- | base/crypto/cssm_init.cc | 27 | ||||
-rw-r--r-- | base/crypto/cssm_init.h | 9 | ||||
-rw-r--r-- | base/crypto/mac_security_services_lock.cc | 42 | ||||
-rw-r--r-- | base/crypto/mac_security_services_lock.h | 22 |
4 files changed, 64 insertions, 36 deletions
diff --git a/base/crypto/cssm_init.cc b/base/crypto/cssm_init.cc index 570dcc3..3071716 100644 --- a/base/crypto/cssm_init.cc +++ b/base/crypto/cssm_init.cc @@ -9,7 +9,6 @@ #include "base/logging.h" #include "base/mac/scoped_cftyperef.h" #include "base/singleton.h" -#include "base/synchronization/lock.h" #include "base/sys_string_conversions.h" // When writing crypto code for Mac OS X, you may find the following @@ -154,28 +153,6 @@ class CSSMInitSingleton { friend struct DefaultSingletonTraits<CSSMInitSingleton>; }; -// This singleton is separate as it pertains to Apple's wrappers over -// their own CSSM handles, as opposed to our own CSSM_CSP_HANDLE. -class SecurityServicesSingleton { - public: - static SecurityServicesSingleton* GetInstance() { - return Singleton<SecurityServicesSingleton, - LeakySingletonTraits<SecurityServicesSingleton> >::get(); - } - - base::Lock& lock() { return lock_; } - - private: - friend struct DefaultSingletonTraits<SecurityServicesSingleton>; - - SecurityServicesSingleton() {} - ~SecurityServicesSingleton() {} - - base::Lock lock_; - - DISALLOW_COPY_AND_ASSIGN(SecurityServicesSingleton); -}; - } // namespace namespace base { @@ -213,10 +190,6 @@ void LogCSSMError(const char* fn_name, CSSM_RETURN err) { << " (" << SysCFStringRefToUTF8(cfstr) << ")"; } -base::Lock& GetMacSecurityServicesLock() { - return SecurityServicesSingleton::GetInstance()->lock(); -} - ScopedCSSMData::ScopedCSSMData() { memset(&data_, 0, sizeof(data_)); } diff --git a/base/crypto/cssm_init.h b/base/crypto/cssm_init.h index b51a3b5..bce5954 100644 --- a/base/crypto/cssm_init.h +++ b/base/crypto/cssm_init.h @@ -12,8 +12,6 @@ namespace base { -class Lock; - // Initialize CSSM if it isn't already initialized. This must be called before // any other CSSM functions. This function is thread-safe, and CSSM will only // ever be initialized once. CSSM will be properly shut down on program exit. @@ -38,13 +36,6 @@ void LogCSSMError(const char *function_name, CSSM_RETURN err); void* CSSMMalloc(CSSM_SIZE size); void CSSMFree(void* ptr); -// The OS X certificate and key management wrappers over CSSM are not -// thread-safe. In particular, code that accesses the CSSM database is -// problematic. -// -// http://developer.apple.com/mac/library/documentation/Security/Reference/certifkeytrustservices/Reference/reference.html -Lock& GetMacSecurityServicesLock(); - // Wrapper class for CSSM_DATA type. This should only be used when using the // CL/TP/CSP handles from above, since that's the only time we're guaranteed (or // supposed to be guaranteed) that our memory management functions will be used. diff --git a/base/crypto/mac_security_services_lock.cc b/base/crypto/mac_security_services_lock.cc new file mode 100644 index 0000000..df1e3ce --- /dev/null +++ b/base/crypto/mac_security_services_lock.cc @@ -0,0 +1,42 @@ +// Copyright (c) 2011 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 "base/crypto/mac_security_services_lock.h" + +#include "base/singleton.h" +#include "base/synchronization/lock.h" + +namespace { + +// This singleton pertains to Apple's wrappers over their own CSSM handles, +// as opposed to our own CSSM_CSP_HANDLE in cssm_init.cc. +class SecurityServicesSingleton { + public: + static SecurityServicesSingleton* GetInstance() { + return Singleton<SecurityServicesSingleton, + LeakySingletonTraits<SecurityServicesSingleton> >::get(); + } + + base::Lock& lock() { return lock_; } + + private: + friend struct DefaultSingletonTraits<SecurityServicesSingleton>; + + SecurityServicesSingleton() {} + ~SecurityServicesSingleton() {} + + base::Lock lock_; + + DISALLOW_COPY_AND_ASSIGN(SecurityServicesSingleton); +}; + +} // namespace + +namespace base { + +base::Lock& GetMacSecurityServicesLock() { + return SecurityServicesSingleton::GetInstance()->lock(); +} + +} // namespace base diff --git a/base/crypto/mac_security_services_lock.h b/base/crypto/mac_security_services_lock.h new file mode 100644 index 0000000..42c2bff --- /dev/null +++ b/base/crypto/mac_security_services_lock.h @@ -0,0 +1,22 @@ +// Copyright (c) 2011 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. + +#ifndef BASE_CRYPTO_MAC_SECURITY_SERVICES_LOCK_H_ +#define BASE_CRYPTO_MAC_SECURITY_SERVICES_LOCK_H_ +#pragma once + +namespace base { + +class Lock; + +// The Mac OS X certificate and key management wrappers over CSSM are not +// thread-safe. In particular, code that accesses the CSSM database is +// problematic. +// +// http://developer.apple.com/mac/library/documentation/Security/Reference/certifkeytrustservices/Reference/reference.html +Lock& GetMacSecurityServicesLock(); + +} // namespace base + +#endif // BASE_CRYPTO_MAC_SECURITY_SERVICES_LOCK_H_ |