| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef BASE_CRYPTO_CSSM_INIT_H_ | 5 #ifndef BASE_CRYPTO_MAC_SECURITY_SERVICES_LOCK_H_ |
| 6 #define BASE_CRYPTO_CSSM_INIT_H_ | 6 #define BASE_CRYPTO_MAC_SECURITY_SERVICES_LOCK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <Security/cssm.h> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 | |
| 13 namespace base { | 9 namespace base { |
| 14 | 10 |
| 15 class Lock; | 11 class Lock; |
| 16 | 12 |
| 17 // Initialize CSSM if it isn't already initialized. This must be called before | 13 // The Mac OS X certificate and key management wrappers over CSSM are not |
| 18 // any other CSSM functions. This function is thread-safe, and CSSM will only | |
| 19 // ever be initialized once. CSSM will be properly shut down on program exit. | |
| 20 void EnsureCSSMInit(); | |
| 21 | |
| 22 // Returns the shared CSP handle used by CSSM functions. | |
| 23 CSSM_CSP_HANDLE GetSharedCSPHandle(); | |
| 24 | |
| 25 // Returns the shared CL handle used by CSSM functions. | |
| 26 CSSM_CL_HANDLE GetSharedCLHandle(); | |
| 27 | |
| 28 // Returns the shared TP handle used by CSSM functions. | |
| 29 CSSM_TP_HANDLE GetSharedTPHandle(); | |
| 30 | |
| 31 // Set of pointers to memory function wrappers that are required for CSSM | |
| 32 extern const CSSM_API_MEMORY_FUNCS kCssmMemoryFunctions; | |
| 33 | |
| 34 // Utility function to log an error message including the error name. | |
| 35 void LogCSSMError(const char *function_name, CSSM_RETURN err); | |
| 36 | |
| 37 // Utility functions to allocate and release CSSM memory. | |
| 38 void* CSSMMalloc(CSSM_SIZE size); | |
| 39 void CSSMFree(void* ptr); | |
| 40 | |
| 41 // The OS X certificate and key management wrappers over CSSM are not | |
| 42 // thread-safe. In particular, code that accesses the CSSM database is | 14 // thread-safe. In particular, code that accesses the CSSM database is |
| 43 // problematic. | 15 // problematic. |
| 44 // | 16 // |
| 45 // http://developer.apple.com/mac/library/documentation/Security/Reference/certi
fkeytrustservices/Reference/reference.html | 17 // http://developer.apple.com/mac/library/documentation/Security/Reference/certi
fkeytrustservices/Reference/reference.html |
| 46 Lock& GetMacSecurityServicesLock(); | 18 Lock& GetMacSecurityServicesLock(); |
| 47 | 19 |
| 48 // Wrapper class for CSSM_DATA type. This should only be used when using the | |
| 49 // CL/TP/CSP handles from above, since that's the only time we're guaranteed (or | |
| 50 // supposed to be guaranteed) that our memory management functions will be used. | |
| 51 // Apple's Sec* APIs manage their own memory so it shouldn't be used for those. | |
| 52 // The constructor initializes data_ to zero and the destructor releases the | |
| 53 // data properly. | |
| 54 class ScopedCSSMData { | |
| 55 public: | |
| 56 ScopedCSSMData(); | |
| 57 ~ScopedCSSMData(); | |
| 58 operator CSSM_DATA*() { return &data_; } | |
| 59 CSSM_DATA* operator ->() { return &data_; } | |
| 60 | |
| 61 private: | |
| 62 CSSM_DATA data_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(ScopedCSSMData); | |
| 65 }; | |
| 66 | |
| 67 } // namespace base | 20 } // namespace base |
| 68 | 21 |
| 69 #endif // BASE_CRYPTO_CSSM_INIT_H_ | 22 #endif // BASE_CRYPTO_MAC_SECURITY_SERVICES_LOCK_H_ |
| OLD | NEW |