OLD | NEW |
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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/observer_list_threadsafe.h" | 12 #include "base/observer_list_threadsafe.h" |
13 #include "crypto/nss_util.h" | 13 #include "crypto/nss_util.h" |
14 #include "crypto/scoped_nss_types.h" | 14 #include "crypto/scoped_nss_types.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/cert/nss_cert_database.h" | |
17 #include "net/cert/x509_certificate.h" | 16 #include "net/cert/x509_certificate.h" |
18 #include "net/cert/x509_util_nss.h" | 17 #include "net/cert/x509_util_nss.h" |
19 | 18 |
20 namespace net { | 19 namespace net { |
21 | 20 |
22 // Helper that observes events from the NSSCertDatabase and forwards them to | |
23 // the given CertDatabase. | |
24 class CertDatabase::Notifier : public NSSCertDatabase::Observer { | |
25 public: | |
26 explicit Notifier(CertDatabase* cert_db) : cert_db_(cert_db) {} | |
27 | |
28 virtual ~Notifier() {} | |
29 | |
30 // NSSCertDatabase::Observer implementation: | |
31 virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE { | |
32 cert_db_->NotifyObserversOfCertAdded(cert); | |
33 } | |
34 | |
35 virtual void OnCertRemoved(const X509Certificate* cert) OVERRIDE { | |
36 cert_db_->NotifyObserversOfCertRemoved(cert); | |
37 } | |
38 | |
39 virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE { | |
40 cert_db_->NotifyObserversOfCACertChanged(cert); | |
41 } | |
42 | |
43 private: | |
44 CertDatabase* cert_db_; | |
45 | |
46 DISALLOW_COPY_AND_ASSIGN(Notifier); | |
47 }; | |
48 | |
49 CertDatabase::CertDatabase() | 21 CertDatabase::CertDatabase() |
50 : observer_list_(new ObserverListThreadSafe<Observer>), | 22 : observer_list_(new ObserverListThreadSafe<Observer>) { |
51 notifier_(new Notifier(this)) { | |
52 crypto::EnsureNSSInit(); | 23 crypto::EnsureNSSInit(); |
53 } | 24 } |
54 | 25 |
55 CertDatabase::~CertDatabase() {} | 26 CertDatabase::~CertDatabase() {} |
56 | 27 |
57 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) { | 28 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) { |
58 if (!cert_obj) | 29 if (!cert_obj) |
59 return ERR_CERT_INVALID; | 30 return ERR_CERT_INVALID; |
60 if (cert_obj->HasExpired()) | 31 if (cert_obj->HasExpired()) |
61 return ERR_CERT_DATE_INVALID; | 32 return ERR_CERT_DATE_INVALID; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 68 |
98 if (rv != SECSuccess) { | 69 if (rv != SECSuccess) { |
99 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); | 70 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); |
100 return ERR_ADD_USER_CERT_FAILED; | 71 return ERR_ADD_USER_CERT_FAILED; |
101 } | 72 } |
102 | 73 |
103 NotifyObserversOfCertAdded(cert_obj); | 74 NotifyObserversOfCertAdded(cert_obj); |
104 return OK; | 75 return OK; |
105 } | 76 } |
106 | 77 |
107 void CertDatabase::ObserveNSSCertDatabase(NSSCertDatabase* source) { | |
108 source->AddObserver(this->notifier_.get()); | |
109 } | |
110 | |
111 } // namespace net | 78 } // namespace net |
OLD | NEW |