| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chromeos/cert_loader.h" | 5 #include "chromeos/cert_loader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 const net::X509Certificate* cert) const { | 108 const net::X509Certificate* cert) const { |
| 109 if (!database_) | 109 if (!database_) |
| 110 return false; | 110 return false; |
| 111 return database_->IsHardwareBacked(cert); | 111 return database_->IsHardwareBacked(cert); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool CertLoader::CertificatesLoading() const { | 114 bool CertLoader::CertificatesLoading() const { |
| 115 return database_ && !certificates_loaded_; | 115 return database_ && !certificates_loaded_; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // This is copied from chrome/common/net/x509_certificate_model_nss.cc. | 118 // static |
| 119 // |
| 119 // For background see this discussion on dev-tech-crypto.lists.mozilla.org: | 120 // For background see this discussion on dev-tech-crypto.lists.mozilla.org: |
| 120 // http://web.archiveorange.com/archive/v/6JJW7E40sypfZGtbkzxX | 121 // http://web.archiveorange.com/archive/v/6JJW7E40sypfZGtbkzxX |
| 121 // | 122 // |
| 122 // NOTE: This function relies on the convention that the same PKCS#11 ID | 123 // NOTE: This function relies on the convention that the same PKCS#11 ID |
| 123 // is shared between a certificate and its associated private and public | 124 // is shared between a certificate and its associated private and public |
| 124 // keys. I tried to implement this with PK11_GetLowLevelKeyIDForCert(), | 125 // keys. I tried to implement this with PK11_GetLowLevelKeyIDForCert(), |
| 125 // but that always returns NULL on Chrome OS for me. | 126 // but that always returns NULL on Chrome OS for me. |
| 126 | |
| 127 // static | |
| 128 std::string CertLoader::GetPkcs11IdForCert(const net::X509Certificate& cert) { | 127 std::string CertLoader::GetPkcs11IdForCert(const net::X509Certificate& cert) { |
| 129 CERTCertificateStr* cert_handle = cert.os_cert_handle(); | 128 CERTCertificateStr* cert_handle = cert.os_cert_handle(); |
| 130 SECKEYPrivateKey *priv_key = | 129 SECKEYPrivateKey *priv_key = |
| 131 PK11_FindKeyByAnyCert(cert_handle, NULL /* wincx */); | 130 PK11_FindKeyByAnyCert(cert_handle, NULL /* wincx */); |
| 132 if (!priv_key) | 131 if (!priv_key) |
| 133 return std::string(); | 132 return std::string(); |
| 134 | 133 |
| 135 // Get the CKA_ID attribute for a key. | 134 // Get the CKA_ID attribute for a key. |
| 136 SECItem* sec_item = PK11_GetLowLevelKeyIDForPrivateKey(priv_key); | 135 SECItem* sec_item = PK11_GetLowLevelKeyIDForPrivateKey(priv_key); |
| 137 std::string pkcs11_id; | 136 std::string pkcs11_id; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 VLOG(1) << "OnCertAdded"; | 193 VLOG(1) << "OnCertAdded"; |
| 195 LoadCertificates(); | 194 LoadCertificates(); |
| 196 } | 195 } |
| 197 | 196 |
| 198 void CertLoader::OnCertRemoved(const net::X509Certificate* cert) { | 197 void CertLoader::OnCertRemoved(const net::X509Certificate* cert) { |
| 199 VLOG(1) << "OnCertRemoved"; | 198 VLOG(1) << "OnCertRemoved"; |
| 200 LoadCertificates(); | 199 LoadCertificates(); |
| 201 } | 200 } |
| 202 | 201 |
| 203 } // namespace chromeos | 202 } // namespace chromeos |
| OLD | NEW |