OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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 #include "base/nss_init.h" | 5 #include "base/nss_init.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
8 #include <nss.h> | 8 #include <nss.h> |
9 #include <plarena.h> | 9 #include <plarena.h> |
10 #include <prerror.h> | 10 #include <prerror.h> |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 // Aw, snap. Can't find/load root cert shared library. | 53 // Aw, snap. Can't find/load root cert shared library. |
54 // This will make it hard to talk to anybody via https. | 54 // This will make it hard to talk to anybody via https. |
55 NOTREACHED(); | 55 NOTREACHED(); |
56 return NULL; | 56 return NULL; |
57 } | 57 } |
58 | 58 |
59 class NSSInitSingleton { | 59 class NSSInitSingleton { |
60 public: | 60 public: |
61 NSSInitSingleton() { | 61 NSSInitSingleton() { |
62 SECStatus status; | 62 SECStatus status = SECFailure; |
63 std::string database_dir = GetDefaultConfigDirectory(); | 63 std::string database_dir = GetDefaultConfigDirectory(); |
64 if (!database_dir.empty()) { | 64 if (!database_dir.empty()) { |
65 // Initialize with a persistant database (~/.pki/nssdb). | 65 // Initialize with a persistant database (~/.pki/nssdb). |
66 // Use "sql:" which can be shared by multiple processes safely. | 66 // Use "sql:" which can be shared by multiple processes safely. |
67 status = NSS_InitReadWrite( | 67 status = NSS_InitReadWrite( |
68 StringPrintf("sql:%s", database_dir.c_str()).c_str()); | 68 StringPrintf("sql:%s", database_dir.c_str()).c_str()); |
69 } else { | 69 if (status != SECSuccess) { |
70 LOG(WARNING) << "Initialize NSS without using a persistent database " | 70 LOG(ERROR) << "Error initializing NSS with a persistent " |
71 << "(~/.pki/nssdb)."; | 71 "databases: NSS error code " << PR_GetError(); |
72 status = NSS_NoDB_Init("."); | 72 } |
73 } | 73 } |
74 if (status != SECSuccess) { | 74 if (status != SECSuccess) { |
75 char buffer[513] = "Couldn't retrieve error"; | 75 LOG(WARNING) << "Initialize NSS without a persistent database " |
76 PRInt32 err_length = PR_GetErrorTextLength(); | 76 "(~/.pki/nssdb)."; |
77 if (err_length > 0 && static_cast<size_t>(err_length) < sizeof(buffer)) | 77 status = NSS_NoDB_Init(NULL); |
78 PR_GetErrorText(buffer); | 78 if (status != SECSuccess) { |
79 | 79 LOG(ERROR) << "Error initializing NSS without a persistent " |
80 NOTREACHED() << "Error initializing NSS: " << buffer; | 80 "database: NSS error code " << PR_GetError(); |
| 81 } |
81 } | 82 } |
82 | 83 |
83 // If we haven't initialized the password for the NSS databases, | 84 // If we haven't initialized the password for the NSS databases, |
84 // initialize an empty-string password so that we don't need to | 85 // initialize an empty-string password so that we don't need to |
85 // log in. | 86 // log in. |
86 PK11SlotInfo* slot = PK11_GetInternalKeySlot(); | 87 PK11SlotInfo* slot = PK11_GetInternalKeySlot(); |
87 if (slot) { | 88 if (slot) { |
88 if (PK11_NeedUserInit(slot)) | 89 if (PK11_NeedUserInit(slot)) |
89 PK11_InitPin(slot, NULL, NULL); | 90 PK11_InitPin(slot, NULL, NULL); |
90 PK11_FreeSlot(slot); | 91 PK11_FreeSlot(slot); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 156 |
156 } // namespace | 157 } // namespace |
157 | 158 |
158 namespace base { | 159 namespace base { |
159 | 160 |
160 void EnsureNSSInit() { | 161 void EnsureNSSInit() { |
161 Singleton<NSSInitSingleton>::get(); | 162 Singleton<NSSInitSingleton>::get(); |
162 } | 163 } |
163 | 164 |
164 } // namespace base | 165 } // namespace base |
OLD | NEW |