Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(154)

Side by Side Diff: net/base/cert_database_nss.cc

Issue 6805019: Move crypto files out of base, to a top level directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes comments by eroman Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/cert_database_mac.cc ('k') | net/base/cert_database_nss_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 #include <secmod.h> 11 #include <secmod.h>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/nss_util.h" 15 #include "crypto/nss_util.h"
16 #include "base/nss_util_internal.h" 16 #include "crypto/nss_util_internal.h"
17 #include "net/base/crypto_module.h" 17 #include "net/base/crypto_module.h"
18 #include "net/base/net_errors.h" 18 #include "net/base/net_errors.h"
19 #include "net/base/x509_certificate.h" 19 #include "net/base/x509_certificate.h"
20 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h" 20 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h"
21 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h" 21 #include "net/third_party/mozilla_security_manager/nsNSSCertTrust.h"
22 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h" 22 #include "net/third_party/mozilla_security_manager/nsPKCS12Blob.h"
23 23
24 // PSM = Mozilla's Personal Security Manager. 24 // PSM = Mozilla's Personal Security Manager.
25 namespace psm = mozilla_security_manager; 25 namespace psm = mozilla_security_manager;
26 26
27 namespace net { 27 namespace net {
28 28
29 CertDatabase::CertDatabase() { 29 CertDatabase::CertDatabase() {
30 base::EnsureNSSInit(); 30 crypto::EnsureNSSInit();
31 psm::EnsurePKCS12Init(); 31 psm::EnsurePKCS12Init();
32 } 32 }
33 33
34 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) { 34 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) {
35 if (!cert_obj) 35 if (!cert_obj)
36 return ERR_CERT_INVALID; 36 return ERR_CERT_INVALID;
37 if (cert_obj->HasExpired()) 37 if (cert_obj->HasExpired())
38 return ERR_CERT_DATE_INVALID; 38 return ERR_CERT_DATE_INVALID;
39 39
40 // Check if the private key corresponding to the certificate exist 40 // Check if the private key corresponding to the certificate exist
(...skipping 30 matching lines...) Expand all
71 username = temp_username; 71 username = temp_username;
72 PORT_Free(temp_username); 72 PORT_Free(temp_username);
73 } 73 }
74 if (temp_ca_name) { 74 if (temp_ca_name) {
75 ca_name = temp_ca_name; 75 ca_name = temp_ca_name;
76 PORT_Free(temp_ca_name); 76 PORT_Free(temp_ca_name);
77 } 77 }
78 nickname = username + "'s " + ca_name + " ID"; 78 nickname = username + "'s " + ca_name + " ID";
79 79
80 { 80 {
81 base::AutoNSSWriteLock lock; 81 crypto::AutoNSSWriteLock lock;
82 slot = PK11_ImportCertForKey(cert, 82 slot = PK11_ImportCertForKey(cert,
83 const_cast<char*>(nickname.c_str()), 83 const_cast<char*>(nickname.c_str()),
84 NULL); 84 NULL);
85 } 85 }
86 86
87 if (!slot) { 87 if (!slot) {
88 LOG(ERROR) << "Couldn't import user certificate."; 88 LOG(ERROR) << "Couldn't import user certificate.";
89 return ERR_ADD_USER_CERT_FAILED; 89 return ERR_ADD_USER_CERT_FAILED;
90 } 90 }
91 PK11_FreeSlot(slot); 91 PK11_FreeSlot(slot);
(...skipping 12 matching lines...) Expand all
104 certs->push_back(X509Certificate::CreateFromHandle( 104 certs->push_back(X509Certificate::CreateFromHandle(
105 node->cert, 105 node->cert,
106 X509Certificate::SOURCE_LONE_CERT_IMPORT, 106 X509Certificate::SOURCE_LONE_CERT_IMPORT,
107 X509Certificate::OSCertHandles())); 107 X509Certificate::OSCertHandles()));
108 } 108 }
109 CERT_DestroyCertList(cert_list); 109 CERT_DestroyCertList(cert_list);
110 } 110 }
111 111
112 CryptoModule* CertDatabase::GetPublicModule() const { 112 CryptoModule* CertDatabase::GetPublicModule() const {
113 CryptoModule* module = 113 CryptoModule* module =
114 CryptoModule::CreateFromHandle(base::GetPublicNSSKeySlot()); 114 CryptoModule::CreateFromHandle(crypto::GetPublicNSSKeySlot());
115 // The module is already referenced when returned from 115 // The module is already referenced when returned from
116 // GetPublicNSSKeySlot, so we need to deref it once. 116 // GetPublicNSSKeySlot, so we need to deref it once.
117 PK11_FreeSlot(module->os_module_handle()); 117 PK11_FreeSlot(module->os_module_handle());
118 118
119 return module; 119 return module;
120 } 120 }
121 121
122 CryptoModule* CertDatabase::GetPrivateModule() const { 122 CryptoModule* CertDatabase::GetPrivateModule() const {
123 CryptoModule* module = 123 CryptoModule* module =
124 CryptoModule::CreateFromHandle(base::GetPrivateNSSKeySlot()); 124 CryptoModule::CreateFromHandle(crypto::GetPrivateNSSKeySlot());
125 // The module is already referenced when returned from 125 // The module is already referenced when returned from
126 // GetPrivateNSSKeySlot, so we need to deref it once. 126 // GetPrivateNSSKeySlot, so we need to deref it once.
127 PK11_FreeSlot(module->os_module_handle()); 127 PK11_FreeSlot(module->os_module_handle());
128 128
129 return module; 129 return module;
130 } 130 }
131 131
132 void CertDatabase::ListModules(CryptoModuleList* modules, bool need_rw) const { 132 void CertDatabase::ListModules(CryptoModuleList* modules, bool need_rw) const {
133 modules->clear(); 133 modules->clear();
134 134
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 } 254 }
255 return true; 255 return true;
256 } 256 }
257 257
258 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const { 258 bool CertDatabase::IsReadOnly(const X509Certificate* cert) const {
259 PK11SlotInfo* slot = cert->os_cert_handle()->slot; 259 PK11SlotInfo* slot = cert->os_cert_handle()->slot;
260 return slot && PK11_IsReadOnly(slot); 260 return slot && PK11_IsReadOnly(slot);
261 } 261 }
262 262
263 } // namespace net 263 } // namespace net
OLDNEW
« no previous file with comments | « net/base/cert_database_mac.cc ('k') | net/base/cert_database_nss_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698