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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/cert/cert_database.h" 5 #include "net/cert/cert_database.h"
6 6
7 #include <cert.h> 7 #include <cert.h>
8 #include <pk11pub.h> 8 #include <pk11pub.h>
9 #include <secmod.h> 9 #include <secmod.h>
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 DISALLOW_COPY_AND_ASSIGN(Notifier); 46 DISALLOW_COPY_AND_ASSIGN(Notifier);
47 }; 47 };
48 48
49 CertDatabase::CertDatabase() 49 CertDatabase::CertDatabase()
50 : observer_list_(new ObserverListThreadSafe<Observer>), 50 : observer_list_(new ObserverListThreadSafe<Observer>),
51 notifier_(new Notifier(this)) { 51 notifier_(new Notifier(this)) {
52 crypto::EnsureNSSInit(); 52 crypto::EnsureNSSInit();
53 } 53 }
54 54
55 CertDatabase::~CertDatabase() {} 55 CertDatabase::~CertDatabase() {
56 }
56 57
57 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) { 58 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) {
58 if (!cert_obj) 59 if (!cert_obj)
59 return ERR_CERT_INVALID; 60 return ERR_CERT_INVALID;
60 if (cert_obj->HasExpired()) 61 if (cert_obj->HasExpired())
61 return ERR_CERT_DATE_INVALID; 62 return ERR_CERT_DATE_INVALID;
62 63
63 // Check if the private key corresponding to the certificate exist 64 // Check if the private key corresponding to the certificate exist
64 // We shouldn't accept any random client certificate sent by a CA. 65 // We shouldn't accept any random client certificate sent by a CA.
65 66
(...skipping 12 matching lines...) Expand all
78 } 79 }
79 80
80 int CertDatabase::AddUserCert(X509Certificate* cert_obj) { 81 int CertDatabase::AddUserCert(X509Certificate* cert_obj) {
81 CERTCertificate* cert = cert_obj->os_cert_handle(); 82 CERTCertificate* cert = cert_obj->os_cert_handle();
82 CK_OBJECT_HANDLE key; 83 CK_OBJECT_HANDLE key;
83 crypto::ScopedPK11Slot slot(PK11_KeyForCertExists(cert, &key, NULL)); 84 crypto::ScopedPK11Slot slot(PK11_KeyForCertExists(cert, &key, NULL));
84 if (!slot.get()) 85 if (!slot.get())
85 return ERR_NO_PRIVATE_KEY_FOR_CERT; 86 return ERR_NO_PRIVATE_KEY_FOR_CERT;
86 87
87 std::string nickname = x509_util::GetUniqueNicknameForSlot( 88 std::string nickname = x509_util::GetUniqueNicknameForSlot(
88 cert_obj->GetDefaultNickname(USER_CERT), 89 cert_obj->GetDefaultNickname(USER_CERT), &cert->derSubject, slot.get());
89 &cert->derSubject,
90 slot.get());
91 90
92 SECStatus rv; 91 SECStatus rv;
93 { 92 {
94 crypto::AutoNSSWriteLock lock; 93 crypto::AutoNSSWriteLock lock;
95 rv = PK11_ImportCert(slot.get(), cert, key, nickname.c_str(), PR_FALSE); 94 rv = PK11_ImportCert(slot.get(), cert, key, nickname.c_str(), PR_FALSE);
96 } 95 }
97 96
98 if (rv != SECSuccess) { 97 if (rv != SECSuccess) {
99 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); 98 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError();
100 return ERR_ADD_USER_CERT_FAILED; 99 return ERR_ADD_USER_CERT_FAILED;
101 } 100 }
102 101
103 NotifyObserversOfCertAdded(cert_obj); 102 NotifyObserversOfCertAdded(cert_obj);
104 return OK; 103 return OK;
105 } 104 }
106 105
107 void CertDatabase::ObserveNSSCertDatabase(NSSCertDatabase* source) { 106 void CertDatabase::ObserveNSSCertDatabase(NSSCertDatabase* source) {
108 source->AddObserver(this->notifier_.get()); 107 source->AddObserver(this->notifier_.get());
109 } 108 }
110 109
111 } // namespace net 110 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698