| 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 #ifndef CRYPTO_NSS_UTIL_H_ | 5 #ifndef CRYPTO_NSS_UTIL_H_ |
| 6 #define CRYPTO_NSS_UTIL_H_ | 6 #define CRYPTO_NSS_UTIL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" |
| 12 #include "crypto/crypto_export.h" | 14 #include "crypto/crypto_export.h" |
| 13 | 15 |
| 14 namespace base { | 16 namespace base { |
| 15 class FilePath; | 17 class FilePath; |
| 16 class Lock; | 18 class Lock; |
| 17 class Time; | 19 class Time; |
| 18 } // namespace base | 20 } // namespace base |
| 19 | 21 |
| 20 // This file specifically doesn't depend on any NSS or NSPR headers because it | 22 // This file specifically doesn't depend on any NSS or NSPR headers because it |
| 21 // is included by various (non-crypto) parts of chrome to call the | 23 // is included by various (non-crypto) parts of chrome to call the |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // thread with true if the token and slot were successfully loaded or were | 67 // thread with true if the token and slot were successfully loaded or were |
| 66 // already initialized. |callback| will be passed false if loading failed. Once | 68 // already initialized. |callback| will be passed false if loading failed. Once |
| 67 // called, InitializeTPMTokenAndSystemSlot must not be called again until the | 69 // called, InitializeTPMTokenAndSystemSlot must not be called again until the |
| 68 // |callback| has been run. | 70 // |callback| has been run. |
| 69 CRYPTO_EXPORT void InitializeTPMTokenAndSystemSlot( | 71 CRYPTO_EXPORT void InitializeTPMTokenAndSystemSlot( |
| 70 int system_slot_id, | 72 int system_slot_id, |
| 71 const base::Callback<void(bool)>& callback); | 73 const base::Callback<void(bool)>& callback); |
| 72 #endif | 74 #endif |
| 73 | 75 |
| 74 // Convert a NSS PRTime value into a base::Time object. | 76 // Convert a NSS PRTime value into a base::Time object. |
| 75 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 77 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. |
| 76 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64 prtime); | 78 CRYPTO_EXPORT base::Time PRTimeToBaseTime(int64_t prtime); |
| 77 | 79 |
| 78 // Convert a base::Time object into a PRTime value. | 80 // Convert a base::Time object into a PRTime value. |
| 79 // We use a int64 instead of PRTime here to avoid depending on NSPR headers. | 81 // We use a int64_t instead of PRTime here to avoid depending on NSPR headers. |
| 80 CRYPTO_EXPORT int64 BaseTimeToPRTime(base::Time time); | 82 CRYPTO_EXPORT int64_t BaseTimeToPRTime(base::Time time); |
| 81 | 83 |
| 82 #if defined(USE_NSS_CERTS) | 84 #if defined(USE_NSS_CERTS) |
| 83 // NSS has a bug which can cause a deadlock or stall in some cases when writing | 85 // NSS has a bug which can cause a deadlock or stall in some cases when writing |
| 84 // to the certDB and keyDB. It also has a bug which causes concurrent key pair | 86 // to the certDB and keyDB. It also has a bug which causes concurrent key pair |
| 85 // generations to scribble over each other. To work around this, we synchronize | 87 // generations to scribble over each other. To work around this, we synchronize |
| 86 // writes to the NSS databases with a global lock. The lock is hidden beneath a | 88 // writes to the NSS databases with a global lock. The lock is hidden beneath a |
| 87 // function for easy disabling when the bug is fixed. Callers should allow for | 89 // function for easy disabling when the bug is fixed. Callers should allow for |
| 88 // it to return NULL in the future. | 90 // it to return NULL in the future. |
| 89 // | 91 // |
| 90 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 | 92 // See https://bugzilla.mozilla.org/show_bug.cgi?id=564011 |
| 91 base::Lock* GetNSSWriteLock(); | 93 base::Lock* GetNSSWriteLock(); |
| 92 | 94 |
| 93 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock | 95 // A helper class that acquires the NSS write Lock while the AutoNSSWriteLock |
| 94 // is in scope. | 96 // is in scope. |
| 95 class CRYPTO_EXPORT AutoNSSWriteLock { | 97 class CRYPTO_EXPORT AutoNSSWriteLock { |
| 96 public: | 98 public: |
| 97 AutoNSSWriteLock(); | 99 AutoNSSWriteLock(); |
| 98 ~AutoNSSWriteLock(); | 100 ~AutoNSSWriteLock(); |
| 99 private: | 101 private: |
| 100 base::Lock *lock_; | 102 base::Lock *lock_; |
| 101 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); | 103 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock); |
| 102 }; | 104 }; |
| 103 #endif // defined(USE_NSS_CERTS) | 105 #endif // defined(USE_NSS_CERTS) |
| 104 | 106 |
| 105 } // namespace crypto | 107 } // namespace crypto |
| 106 | 108 |
| 107 #endif // CRYPTO_NSS_UTIL_H_ | 109 #endif // CRYPTO_NSS_UTIL_H_ |
| OLD | NEW |