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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 if (!slot) { | 84 if (!slot) { |
85 LOG(ERROR) << "Couldn't import user certificate."; | 85 LOG(ERROR) << "Couldn't import user certificate."; |
86 return ERR_ADD_USER_CERT_FAILED; | 86 return ERR_ADD_USER_CERT_FAILED; |
87 } | 87 } |
88 PK11_FreeSlot(slot); | 88 PK11_FreeSlot(slot); |
89 return OK; | 89 return OK; |
90 } | 90 } |
91 | 91 |
| 92 void CertDatabase::ListCerts(CertificateList* certs) { |
| 93 certs->clear(); |
| 94 |
| 95 CERTCertList* cert_list = PK11_ListCerts(PK11CertListUnique, NULL); |
| 96 CERTCertListNode* node; |
| 97 for (node = CERT_LIST_HEAD(cert_list); |
| 98 !CERT_LIST_END(node, cert_list); |
| 99 node = CERT_LIST_NEXT(node)) { |
| 100 certs->push_back(X509Certificate::CreateFromHandle( |
| 101 node->cert, |
| 102 X509Certificate::SOURCE_LONE_CERT_IMPORT, |
| 103 X509Certificate::OSCertHandles())); |
| 104 } |
| 105 CERT_DestroyCertList(cert_list); |
| 106 } |
| 107 |
92 int CertDatabase::ImportFromPKCS12( | 108 int CertDatabase::ImportFromPKCS12( |
93 const std::string& data, const string16& password) { | 109 const std::string& data, const string16& password) { |
94 return psm::nsPKCS12Blob_Import(data.data(), data.size(), password); | 110 return psm::nsPKCS12Blob_Import(data.data(), data.size(), password); |
95 } | 111 } |
96 | 112 |
97 int CertDatabase::ExportToPKCS12( | 113 int CertDatabase::ExportToPKCS12( |
98 const CertificateList& certs, | 114 const CertificateList& certs, |
99 const string16& password, | 115 const string16& password, |
100 std::string* output) { | 116 std::string* output) { |
101 return psm::nsPKCS12Blob_Export(output, certs, password); | 117 return psm::nsPKCS12Blob_Export(output, certs, password); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 } else { | 169 } else { |
154 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { | 170 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { |
155 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); | 171 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); |
156 return false; | 172 return false; |
157 } | 173 } |
158 } | 174 } |
159 return true; | 175 return true; |
160 } | 176 } |
161 | 177 |
162 } // namespace net | 178 } // namespace net |
OLD | NEW |