| 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 "chrome/common/net/x509_certificate_model.h" | 5 #include "chrome/common/net/x509_certificate_model.h" |
| 6 | 6 |
| 7 #include <cert.h> | 7 #include <cert.h> |
| 8 #include <cms.h> | 8 #include <cms.h> |
| 9 #include <hasht.h> | 9 #include <hasht.h> |
| 10 #include <keyhi.h> // SECKEY_DestroyPrivateKey | 10 #include <keyhi.h> // SECKEY_DestroyPrivateKey |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 DCHECK_EQ(cert_nicknames->numnicknames, | 251 DCHECK_EQ(cert_nicknames->numnicknames, |
| 252 static_cast<int>(certs.size())); | 252 static_cast<int>(certs.size())); |
| 253 | 253 |
| 254 for (int i = 0; i < cert_nicknames->numnicknames; ++i) | 254 for (int i = 0; i < cert_nicknames->numnicknames; ++i) |
| 255 nick_names->push_back(cert_nicknames->nicknames[i]); | 255 nick_names->push_back(cert_nicknames->nicknames[i]); |
| 256 | 256 |
| 257 CERT_FreeNicknames(cert_nicknames); | 257 CERT_FreeNicknames(cert_nicknames); |
| 258 CERT_DestroyCertList(cert_list); | 258 CERT_DestroyCertList(cert_list); |
| 259 } | 259 } |
| 260 | 260 |
| 261 // For background see this discussion on dev-tech-crypto.lists.mozilla.org: | |
| 262 // http://web.archiveorange.com/archive/v/6JJW7E40sypfZGtbkzxX | |
| 263 // | |
| 264 // NOTE: This function relies on the convention that the same PKCS#11 ID | |
| 265 // is shared between a certificate and its associated private and public | |
| 266 // keys. I tried to implement this with PK11_GetLowLevelKeyIDForCert(), | |
| 267 // but that always returns NULL on Chrome OS for me. | |
| 268 std::string GetPkcs11Id(net::X509Certificate::OSCertHandle cert_handle) { | |
| 269 std::string pkcs11_id; | |
| 270 SECKEYPrivateKey *priv_key = PK11_FindKeyByAnyCert(cert_handle, | |
| 271 NULL /* wincx */); | |
| 272 if (priv_key) { | |
| 273 // Get the CKA_ID attribute for a key. | |
| 274 SECItem* sec_item = PK11_GetLowLevelKeyIDForPrivateKey(priv_key); | |
| 275 if (sec_item) { | |
| 276 pkcs11_id = base::HexEncode(sec_item->data, sec_item->len); | |
| 277 SECITEM_FreeItem(sec_item, PR_TRUE); | |
| 278 } | |
| 279 SECKEY_DestroyPrivateKey(priv_key); | |
| 280 } | |
| 281 return pkcs11_id; | |
| 282 } | |
| 283 | |
| 284 void GetExtensions( | 261 void GetExtensions( |
| 285 const string& critical_label, | 262 const string& critical_label, |
| 286 const string& non_critical_label, | 263 const string& non_critical_label, |
| 287 X509Certificate::OSCertHandle cert_handle, | 264 X509Certificate::OSCertHandle cert_handle, |
| 288 Extensions* extensions) { | 265 Extensions* extensions) { |
| 289 if (cert_handle->extensions) { | 266 if (cert_handle->extensions) { |
| 290 for (size_t i = 0; cert_handle->extensions[i] != NULL; ++i) { | 267 for (size_t i = 0; cert_handle->extensions[i] != NULL; ++i) { |
| 291 Extension extension; | 268 Extension extension; |
| 292 extension.name = psm::GetOIDText(&cert_handle->extensions[i]->id); | 269 extension.name = psm::GetOIDText(&cert_handle->extensions[i]->id); |
| 293 extension.value = ProcessExtension( | 270 extension.value = ProcessExtension( |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 string ProcessRawBitsSignatureWrap(X509Certificate::OSCertHandle cert_handle) { | 381 string ProcessRawBitsSignatureWrap(X509Certificate::OSCertHandle cert_handle) { |
| 405 return ProcessRawBits(cert_handle->signatureWrap.signature.data, | 382 return ProcessRawBits(cert_handle->signatureWrap.signature.data, |
| 406 cert_handle->signatureWrap.signature.len); | 383 cert_handle->signatureWrap.signature.len); |
| 407 } | 384 } |
| 408 | 385 |
| 409 void RegisterDynamicOids() { | 386 void RegisterDynamicOids() { |
| 410 psm::RegisterDynamicOids(); | 387 psm::RegisterDynamicOids(); |
| 411 } | 388 } |
| 412 | 389 |
| 413 } // namespace x509_certificate_model | 390 } // namespace x509_certificate_model |
| OLD | NEW |