| 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" | 16 #include "net/cert/nss_cert_database.h" |
| 17 #include "net/cert/x509_certificate.h" | 17 #include "net/cert/x509_certificate.h" |
| 18 #include "net/cert/x509_util_nss.h" | 18 #include "net/cert/x509_util_nss.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 /* XXX |
| 22 // Helper that observes events from the NSSCertDatabase and forwards them to | 23 // Helper that observes events from the NSSCertDatabase and forwards them to |
| 23 // the given CertDatabase. | 24 // the given CertDatabase. |
| 24 class CertDatabase::Notifier : public NSSCertDatabase::Observer { | 25 class CertDatabase::Notifier : public NSSCertDatabase::Observer { |
| 25 public: | 26 public: |
| 26 explicit Notifier(CertDatabase* cert_db) : cert_db_(cert_db) { | 27 explicit Notifier(CertDatabase* cert_db) : cert_db_(cert_db) { |
| 27 NSSCertDatabase::GetInstance()->AddObserver(this); | 28 NSSCertDatabase::GetInstance()->AddObserver(this); |
| 28 } | 29 } |
| 29 | 30 |
| 30 virtual ~Notifier() { | 31 virtual ~Notifier() { |
| 31 NSSCertDatabase::GetInstance()->RemoveObserver(this); | 32 NSSCertDatabase::GetInstance()->RemoveObserver(this); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 42 | 43 |
| 43 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE { | 44 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE { |
| 44 cert_db_->NotifyObserversOfCertTrustChanged(cert); | 45 cert_db_->NotifyObserversOfCertTrustChanged(cert); |
| 45 } | 46 } |
| 46 | 47 |
| 47 private: | 48 private: |
| 48 CertDatabase* cert_db_; | 49 CertDatabase* cert_db_; |
| 49 | 50 |
| 50 DISALLOW_COPY_AND_ASSIGN(Notifier); | 51 DISALLOW_COPY_AND_ASSIGN(Notifier); |
| 51 }; | 52 }; |
| 53 */ |
| 52 | 54 |
| 53 CertDatabase::CertDatabase() | 55 CertDatabase::CertDatabase() |
| 54 : observer_list_(new ObserverListThreadSafe<Observer>) { | 56 : observer_list_(new ObserverListThreadSafe<Observer>) { |
| 57 // XXX |
| 55 // Observe NSSCertDatabase events and forward them to observers of | 58 // Observe NSSCertDatabase events and forward them to observers of |
| 56 // CertDatabase. This also makes sure that NSS has been initialized. | 59 // CertDatabase. This also makes sure that NSS has been initialized. |
| 57 notifier_.reset(new Notifier(this)); | 60 //notifier_.reset(new Notifier(this)); |
| 61 |
| 62 // This makes sure that NSS has been initialized. |
| 63 NSSCertDatabase::GetInstance(); |
| 58 } | 64 } |
| 59 | 65 |
| 60 CertDatabase::~CertDatabase() {} | 66 CertDatabase::~CertDatabase() {} |
| 61 | 67 |
| 62 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) { | 68 int CertDatabase::CheckUserCert(X509Certificate* cert_obj) { |
| 63 if (!cert_obj) | 69 if (!cert_obj) |
| 64 return ERR_CERT_INVALID; | 70 return ERR_CERT_INVALID; |
| 65 if (cert_obj->HasExpired()) | 71 if (cert_obj->HasExpired()) |
| 66 return ERR_CERT_DATE_INVALID; | 72 return ERR_CERT_DATE_INVALID; |
| 67 | 73 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 if (rv != SECSuccess) { | 109 if (rv != SECSuccess) { |
| 104 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); | 110 LOG(ERROR) << "Couldn't import user certificate. " << PORT_GetError(); |
| 105 return ERR_ADD_USER_CERT_FAILED; | 111 return ERR_ADD_USER_CERT_FAILED; |
| 106 } | 112 } |
| 107 | 113 |
| 108 NotifyObserversOfCertAdded(cert_obj); | 114 NotifyObserversOfCertAdded(cert_obj); |
| 109 return OK; | 115 return OK; |
| 110 } | 116 } |
| 111 | 117 |
| 112 } // namespace net | 118 } // namespace net |
| OLD | NEW |