blob: 10bbdfb41eb734f6f80ab104cf45cb87cb5fcd53 [file] [log] [blame]
[email protected]1b1a264a2010-01-14 22:36:351// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]bc1e07c72008-09-16 14:32:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]1b1a264a2010-01-14 22:36:355#ifndef BASE_NSS_UTIL_H_
6#define BASE_NSS_UTIL_H_
[email protected]32b76ef2010-07-26 23:08:247#pragma once
[email protected]1b1a264a2010-01-14 22:36:358
9#include "base/basictypes.h"
[email protected]bc1e07c72008-09-16 14:32:4410
[email protected]69138472010-06-25 22:44:4811#if defined(USE_NSS)
[email protected]bb6390382010-08-12 19:49:4012class FilePath;
[email protected]69138472010-06-25 22:44:4813#endif // defined(USE_NSS)
14
[email protected]41c78fa2010-03-22 20:08:4115// This file specifically doesn't depend on any NSS or NSPR headers because it
16// is included by various (non-crypto) parts of chrome to call the
17// initialization functions.
[email protected]bc1e07c72008-09-16 14:32:4418namespace base {
19
[email protected]bc581a682011-01-01 23:16:2020class Lock;
[email protected]1b1a264a2010-01-14 22:36:3521class Time;
22
[email protected]ac3d5972011-01-13 20:33:4523#if defined(USE_NSS)
24// EarlySetupForNSSInit performs lightweight setup which must occur before the
25// process goes multithreaded. This does not initialise NSS. For test, see
26// EnsureNSSInit.
27void EarlySetupForNSSInit();
28#endif
29
[email protected]730fb132009-09-02 22:50:2530// Initialize NRPR if it isn't already initialized. This function is
31// thread-safe, and NSPR will only ever be initialized once. NSPR will be
32// properly shut down on program exit.
33void EnsureNSPRInit();
34
[email protected]bc1e07c72008-09-16 14:32:4435// Initialize NSS if it isn't already initialized. This must be called before
36// any other NSS functions. This function is thread-safe, and NSS will only
37// ever be initialized once. NSS will be properly shut down on program exit.
38void EnsureNSSInit();
39
[email protected]f61c3972010-12-23 09:54:1540// Check if the current NSS version is greater than or equals to |version|.
41// A sample version string is "3.12.3".
42bool CheckNSSVersion(const char* version);
43
[email protected]dcce6cf2010-04-29 17:50:0644#if defined(OS_CHROMEOS)
45// Open the r/w nssdb that's stored inside the user's encrypted home directory.
46void OpenPersistentNSSDB();
47#endif
48
[email protected]1b1a264a2010-01-14 22:36:3549// Convert a NSS PRTime value into a base::Time object.
50// We use a int64 instead of PRTime here to avoid depending on NSPR headers.
51Time PRTimeToBaseTime(int64 prtime);
52
[email protected]69138472010-06-25 22:44:4853#if defined(USE_NSS)
[email protected]bb6390382010-08-12 19:49:4054// Exposed for unittests only. |path| should be an existing directory under
55// which the DB files will be placed. |description| is a user-visible name for
56// the DB, as a utf8 string, which will be truncated at 32 bytes.
57bool OpenTestNSSDB(const FilePath& path, const char* description);
58void CloseTestNSSDB();
59
[email protected]69138472010-06-25 22:44:4860// NSS has a bug which can cause a deadlock or stall in some cases when writing
61// to the certDB and keyDB. It also has a bug which causes concurrent key pair
62// generations to scribble over each other. To work around this, we synchronize
63// writes to the NSS databases with a global lock. The lock is hidden beneath a
64// function for easy disabling when the bug is fixed. Callers should allow for
65// it to return NULL in the future.
66//
67// See https://bugzilla.mozilla.org/show_bug.cgi?id=564011
68Lock* GetNSSWriteLock();
69
70// A helper class that acquires the NSS write Lock while the AutoNSSWriteLock
71// is in scope.
72class AutoNSSWriteLock {
73 public:
74 AutoNSSWriteLock();
75 ~AutoNSSWriteLock();
76 private:
77 Lock *lock_;
78 DISALLOW_COPY_AND_ASSIGN(AutoNSSWriteLock);
79};
80
81#endif // defined(USE_NSS)
82
[email protected]bc1e07c72008-09-16 14:32:4483} // namespace base
84
[email protected]1b1a264a2010-01-14 22:36:3585#endif // BASE_NSS_UTIL_H_