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/nss_cert_database.h" | 5 #include "net/cert/nss_cert_database.h" |
6 | 6 |
7 #include <cert.h> | 7 #include <cert.h> |
8 #include <certdb.h> | 8 #include <certdb.h> |
9 #include <keyhi.h> | 9 #include <keyhi.h> |
10 #include <pk11pub.h> | 10 #include <pk11pub.h> |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 scoped_refptr<X509Certificate> cert, | 448 scoped_refptr<X509Certificate> cert, |
449 const DeleteCertCallback& callback, | 449 const DeleteCertCallback& callback, |
450 bool success) { | 450 bool success) { |
451 if (success) | 451 if (success) |
452 NotifyObserversOfCertRemoved(cert.get()); | 452 NotifyObserversOfCertRemoved(cert.get()); |
453 callback.Run(success); | 453 callback.Run(success); |
454 } | 454 } |
455 | 455 |
456 void NSSCertDatabase::NotifyObserversOfCertAdded(const X509Certificate* cert) { | 456 void NSSCertDatabase::NotifyObserversOfCertAdded(const X509Certificate* cert) { |
457 observer_list_->Notify(FROM_HERE, &Observer::OnCertAdded, | 457 observer_list_->Notify(FROM_HERE, &Observer::OnCertAdded, |
458 make_scoped_refptr(cert)); | 458 base::RetainedRef(cert)); |
459 } | 459 } |
460 | 460 |
461 void NSSCertDatabase::NotifyObserversOfCertRemoved( | 461 void NSSCertDatabase::NotifyObserversOfCertRemoved( |
462 const X509Certificate* cert) { | 462 const X509Certificate* cert) { |
463 observer_list_->Notify(FROM_HERE, &Observer::OnCertRemoved, | 463 observer_list_->Notify(FROM_HERE, &Observer::OnCertRemoved, |
464 make_scoped_refptr(cert)); | 464 base::RetainedRef(cert)); |
465 } | 465 } |
466 | 466 |
467 void NSSCertDatabase::NotifyObserversOfCACertChanged( | 467 void NSSCertDatabase::NotifyObserversOfCACertChanged( |
468 const X509Certificate* cert) { | 468 const X509Certificate* cert) { |
469 observer_list_->Notify(FROM_HERE, &Observer::OnCACertChanged, | 469 observer_list_->Notify(FROM_HERE, &Observer::OnCACertChanged, |
470 make_scoped_refptr(cert)); | 470 base::RetainedRef(cert)); |
471 } | 471 } |
472 | 472 |
473 // static | 473 // static |
474 bool NSSCertDatabase::DeleteCertAndKeyImpl( | 474 bool NSSCertDatabase::DeleteCertAndKeyImpl( |
475 scoped_refptr<X509Certificate> cert) { | 475 scoped_refptr<X509Certificate> cert) { |
476 // For some reason, PK11_DeleteTokenCertAndKey only calls | 476 // For some reason, PK11_DeleteTokenCertAndKey only calls |
477 // SEC_DeletePermCertificate if the private key is found. So, we check | 477 // SEC_DeletePermCertificate if the private key is found. So, we check |
478 // whether a private key exists before deciding which function to call to | 478 // whether a private key exists before deciding which function to call to |
479 // delete the cert. | 479 // delete the cert. |
480 SECKEYPrivateKey* privKey = | 480 SECKEYPrivateKey* privKey = |
481 PK11_FindKeyByAnyCert(cert->os_cert_handle(), NULL); | 481 PK11_FindKeyByAnyCert(cert->os_cert_handle(), NULL); |
482 if (privKey) { | 482 if (privKey) { |
483 SECKEY_DestroyPrivateKey(privKey); | 483 SECKEY_DestroyPrivateKey(privKey); |
484 if (PK11_DeleteTokenCertAndKey(cert->os_cert_handle(), NULL)) { | 484 if (PK11_DeleteTokenCertAndKey(cert->os_cert_handle(), NULL)) { |
485 LOG(ERROR) << "PK11_DeleteTokenCertAndKey failed: " << PORT_GetError(); | 485 LOG(ERROR) << "PK11_DeleteTokenCertAndKey failed: " << PORT_GetError(); |
486 return false; | 486 return false; |
487 } | 487 } |
488 } else { | 488 } else { |
489 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { | 489 if (SEC_DeletePermCertificate(cert->os_cert_handle())) { |
490 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); | 490 LOG(ERROR) << "SEC_DeletePermCertificate failed: " << PORT_GetError(); |
491 return false; | 491 return false; |
492 } | 492 } |
493 } | 493 } |
494 return true; | 494 return true; |
495 } | 495 } |
496 | 496 |
497 } // namespace net | 497 } // namespace net |
OLD | NEW |