Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/chromeos/platform_keys/platform_keys_nss.cc

Issue 2363653002: Cleanup unreachable cert adding code (Closed)
Patch Set: Rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <cert.h> 5 #include <cert.h>
6 #include <cryptohi.h> 6 #include <cryptohi.h>
7 #include <keyhi.h> 7 #include <keyhi.h>
8 #include <secder.h> 8 #include <secder.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 25 matching lines...) Expand all
36 #include "content/public/browser/browser_context.h" 36 #include "content/public/browser/browser_context.h"
37 #include "content/public/browser/browser_thread.h" 37 #include "content/public/browser/browser_thread.h"
38 #include "crypto/nss_key_util.h" 38 #include "crypto/nss_key_util.h"
39 #include "crypto/scoped_nss_types.h" 39 #include "crypto/scoped_nss_types.h"
40 #include "net/base/crypto_module.h" 40 #include "net/base/crypto_module.h"
41 #include "net/base/net_errors.h" 41 #include "net/base/net_errors.h"
42 #include "net/cert/cert_database.h" 42 #include "net/cert/cert_database.h"
43 #include "net/cert/nss_cert_database.h" 43 #include "net/cert/nss_cert_database.h"
44 #include "net/cert/x509_util_nss.h" 44 #include "net/cert/x509_util_nss.h"
45 #include "net/ssl/ssl_cert_request_info.h" 45 #include "net/ssl/ssl_cert_request_info.h"
46 #include "net/third_party/mozilla_security_manager/nsNSSCertificateDB.h"
46 47
47 using content::BrowserContext; 48 using content::BrowserContext;
48 using content::BrowserThread; 49 using content::BrowserThread;
49 50
50 namespace { 51 namespace {
51 const char kErrorInternal[] = "Internal Error."; 52 const char kErrorInternal[] = "Internal Error.";
52 const char kErrorKeyNotFound[] = "Key not found."; 53 const char kErrorKeyNotFound[] = "Key not found.";
53 const char kErrorCertificateNotFound[] = "Certificate could not be found."; 54 const char kErrorCertificateNotFound[] = "Certificate could not be found.";
54 const char kErrorAlgorithmNotSupported[] = "Algorithm not supported."; 55 const char kErrorAlgorithmNotSupported[] = "Algorithm not supported.";
55 56
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 PK11SlotInfo* slot = state->slot_.get(); 613 PK11SlotInfo* slot = state->slot_.get();
613 cert_db->ListCertsInSlot( 614 cert_db->ListCertsInSlot(
614 base::Bind(&DidGetCertificates, base::Passed(&state)), slot); 615 base::Bind(&DidGetCertificates, base::Passed(&state)), slot);
615 } 616 }
616 617
617 // Does the actual certificate importing on the IO thread. Used by 618 // Does the actual certificate importing on the IO thread. Used by
618 // ImportCertificate(). 619 // ImportCertificate().
619 void ImportCertificateWithDB(std::unique_ptr<ImportCertificateState> state, 620 void ImportCertificateWithDB(std::unique_ptr<ImportCertificateState> state,
620 net::NSSCertDatabase* cert_db) { 621 net::NSSCertDatabase* cert_db) {
621 DCHECK_CURRENTLY_ON(BrowserThread::IO); 622 DCHECK_CURRENTLY_ON(BrowserThread::IO);
622 // TODO(pneubeck): Use |state->slot_| to verify that we're really importing to
623 // the correct token.
624 // |cert_db| is not required, ignore it.
625 net::CertDatabase* db = net::CertDatabase::GetInstance();
626 623
627 const net::Error cert_status = 624 if (!state->certificate_) {
628 static_cast<net::Error>(db->CheckUserCert(state->certificate_.get())); 625 state->OnError(FROM_HERE, net::ErrorToString(net::ERR_CERT_INVALID));
629 if (cert_status == net::ERR_NO_PRIVATE_KEY_FOR_CERT) {
630 state->OnError(FROM_HERE, kErrorKeyNotFound);
631 return; 626 return;
632 } else if (cert_status != net::OK) { 627 }
633 state->OnError(FROM_HERE, net::ErrorToString(cert_status)); 628 if (state->certificate_->HasExpired()) {
629 state->OnError(FROM_HERE, net::ErrorToString(net::ERR_CERT_DATE_INVALID));
634 return; 630 return;
635 } 631 }
636 632
637 // Check that the private key is in the correct slot. 633 // Check that the private key is in the correct slot.
638 PK11SlotInfo* slot = 634 crypto::ScopedPK11Slot slot(
639 PK11_KeyForCertExists(state->certificate_->os_cert_handle(), NULL, NULL); 635 PK11_KeyForCertExists(state->certificate_->os_cert_handle(), NULL, NULL));
640 if (slot != state->slot_.get()) { 636 if (slot.get() != state->slot_.get()) {
641 state->OnError(FROM_HERE, kErrorKeyNotFound); 637 state->OnError(FROM_HERE, kErrorKeyNotFound);
642 return; 638 return;
643 } 639 }
644 640
645 const net::Error import_status = 641 const net::Error import_status = static_cast<net::Error>(
646 static_cast<net::Error>(db->AddUserCert(state->certificate_.get())); 642 cert_db->ImportUserCert(state->certificate_.get()));
647 if (import_status != net::OK) { 643 if (import_status != net::OK) {
648 LOG(ERROR) << "Could not import certificate."; 644 LOG(ERROR) << "Could not import certificate.";
649 state->OnError(FROM_HERE, net::ErrorToString(import_status)); 645 state->OnError(FROM_HERE, net::ErrorToString(import_status));
650 return; 646 return;
651 } 647 }
652 648
653 state->CallBack(FROM_HERE, std::string() /* no error */); 649 state->CallBack(FROM_HERE, std::string() /* no error */);
654 } 650 }
655 651
656 // Called on IO thread after the certificate removal is finished. 652 // Called on IO thread after the certificate removal is finished.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 NSSOperationState* state_ptr = state.get(); 894 NSSOperationState* state_ptr = state.get();
899 GetCertDatabase(std::string() /* don't get any specific slot */, 895 GetCertDatabase(std::string() /* don't get any specific slot */,
900 base::Bind(&GetTokensWithDB, base::Passed(&state)), 896 base::Bind(&GetTokensWithDB, base::Passed(&state)),
901 browser_context, 897 browser_context,
902 state_ptr); 898 state_ptr);
903 } 899 }
904 900
905 } // namespace platform_keys 901 } // namespace platform_keys
906 902
907 } // namespace chromeos 903 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client.cc ('k') | chrome/browser/ssl/ssl_add_certificate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698