| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/cert_database.h" | 5 #include "net/base/cert_database.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <certdb.h> | 8 #include <certdb.h> |
| 9 #include <keyhi.h> | 9 #include <keyhi.h> |
| 10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 CryptoModule* CertDatabase::GetDefaultModule() const { | 111 CryptoModule* CertDatabase::GetDefaultModule() const { |
| 112 CryptoModule* module = | 112 CryptoModule* module = |
| 113 CryptoModule::CreateFromHandle(base::GetDefaultNSSKeySlot()); | 113 CryptoModule::CreateFromHandle(base::GetDefaultNSSKeySlot()); |
| 114 // The module is already referenced when returned from GetDefaultNSSKeymodule, | 114 // The module is already referenced when returned from GetDefaultNSSKeymodule, |
| 115 // so we need to deref it once. | 115 // so we need to deref it once. |
| 116 PK11_FreeSlot(module->os_module_handle()); | 116 PK11_FreeSlot(module->os_module_handle()); |
| 117 | 117 |
| 118 return module; | 118 return module; |
| 119 } | 119 } |
| 120 | 120 |
| 121 void CertDatabase::ListModules(CryptoModuleList* modules, bool need_rw) const { |
| 122 modules->clear(); |
| 123 |
| 124 PK11SlotList* slot_list = NULL; |
| 125 // The wincx arg is unused since we don't call PK11_SetIsLoggedInFunc. |
| 126 slot_list = PK11_GetAllTokens(CKM_INVALID_MECHANISM, |
| 127 need_rw ? PR_TRUE : PR_FALSE, // needRW |
| 128 PR_TRUE, // loadCerts (unused) |
| 129 NULL); // wincx |
| 130 if (!slot_list) { |
| 131 LOG(ERROR) << "PK11_GetAllTokens failed: " << PORT_GetError(); |
| 132 return; |
| 133 } |
| 134 |
| 135 PK11SlotListElement* slot_element = PK11_GetFirstSafe(slot_list); |
| 136 while (slot_element) { |
| 137 modules->push_back(CryptoModule::CreateFromHandle(slot_element->slot)); |
| 138 slot_element = PK11_GetNextSafe(slot_list, slot_element, |
| 139 PR_FALSE); // restart |
| 140 } |
| 141 |
| 142 PK11_FreeSlotList(slot_list); |
| 143 } |
| 144 |
| 121 int CertDatabase::ImportFromPKCS12( | 145 int CertDatabase::ImportFromPKCS12( |
| 122 net::CryptoModule* module, | 146 net::CryptoModule* module, |
| 123 const std::string& data, | 147 const std::string& data, |
| 124 const string16& password) { | 148 const string16& password) { |
| 125 return psm::nsPKCS12Blob_Import(module->os_module_handle(), | 149 return psm::nsPKCS12Blob_Import(module->os_module_handle(), |
| 126 data.data(), data.size(), | 150 data.data(), data.size(), |
| 127 password); | 151 password); |
| 128 } | 152 } |
| 129 | 153 |
| 130 int CertDatabase::ExportToPKCS12( | 154 int CertDatabase::ExportToPKCS12( |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 243 } |
| 220 return true; | 244 return true; |
| 221 } | 245 } |
| 222 | 246 |
| 223 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { | 247 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { |
| 224 PK11SlotInfo* slot = cert->os_cert_handle()->slot; | 248 PK11SlotInfo* slot = cert->os_cert_handle()->slot; |
| 225 return slot && PK11_IsReadOnly(slot); | 249 return slot && PK11_IsReadOnly(slot); |
| 226 } | 250 } |
| 227 | 251 |
| 228 } // namespace net | 252 } // namespace net |
| OLD | NEW |