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

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

Issue 1141253003: chrome.platformKeys: Add filtering by certificate types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed pneubeck's comments Created 5 years, 7 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 "chrome/browser/chromeos/platform_keys/platform_keys_service.h" 5 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 service_->TaskFinished(this); 474 service_->TaskFinished(this);
475 // |this| might be invalid now. 475 // |this| might be invalid now.
476 return; 476 return;
477 } 477 }
478 } 478 }
479 479
480 // Retrieves all certificates matching |request_|. Will call back to 480 // Retrieves all certificates matching |request_|. Will call back to
481 // |GotMatchingCerts()|. 481 // |GotMatchingCerts()|.
482 void GetMatchingCerts() { 482 void GetMatchingCerts() {
483 platform_keys::subtle::SelectClientCertificates( 483 platform_keys::subtle::SelectClientCertificates(
484 request_, 484 request_.certificate_authorities,
485 base::Bind(&SelectTask::GotMatchingCerts, weak_factory_.GetWeakPtr()), 485 base::Bind(&SelectTask::GotMatchingCerts, weak_factory_.GetWeakPtr()),
486 service_->browser_context_); 486 service_->browser_context_);
487 } 487 }
488 488
489 // If the certificate request could be processed successfully, |matches| will 489 // If the certificate request could be processed successfully, |matches| will
490 // contain the list of matching certificates (maybe empty) and |error_message| 490 // contain the list of matching certificates (maybe empty) and |error_message|
491 // will be empty. If an error occurred, |matches| will be null and 491 // will be empty. If an error occurred, |matches| will be null and
492 // |error_message| contain an error message. 492 // |error_message| contain an error message.
493 void GotMatchingCerts(scoped_ptr<net::CertificateList> matches, 493 void GotMatchingCerts(scoped_ptr<net::CertificateList> matches,
494 const std::string& error_message) { 494 const std::string& error_message) {
495 if (!error_message.empty()) { 495 if (!error_message.empty()) {
496 next_step_ = Step::DONE; 496 next_step_ = Step::DONE;
497 callback_.Run(nullptr /* no certificates */, error_message); 497 callback_.Run(nullptr /* no certificates */, error_message);
498 DoStep(); 498 DoStep();
499 return; 499 return;
500 } 500 }
501 matches_.swap(*matches); 501
502 // If the type field does not contain any entries, certificates of all types
503 // shall be returned.
504 if (request_.certificate_key_types.size() == 0) {
505 matches_.swap(*matches);
506 DoStep();
507 return;
508 }
509
510 // Filter the retrieved certificates returning only those whose type is
511 // equal to one of the entries in the type field of the certificate request.
512 for (scoped_refptr<net::X509Certificate>& certificate : *matches) {
513 net::X509Certificate::PublicKeyType actual_key_type =
514 net::X509Certificate::kPublicKeyTypeUnknown;
515 size_t unused_key_size = 0;
516 net::X509Certificate::GetPublicKeyInfo(
517 certificate->os_cert_handle(), &unused_key_size, &actual_key_type);
518 const std::vector<net::X509Certificate::PublicKeyType>& accepted_types =
519 request_.certificate_key_types;
520 if (std::find(accepted_types.begin(), accepted_types.end(),
521 actual_key_type) != accepted_types.end()) {
522 matches_.push_back(certificate.Pass());
523 }
524 }
502 DoStep(); 525 DoStep();
503 } 526 }
504 527
505 // Calls |service_->select_delegate_->Select()| to select a cert from 528 // Calls |service_->select_delegate_->Select()| to select a cert from
506 // |matches_|, which will be stored in |selected_cert_|. 529 // |matches_|, which will be stored in |selected_cert_|.
507 // Will call back to |GotSelection()|. 530 // Will call back to |GotSelection()|.
508 void SelectCerts() { 531 void SelectCerts() {
509 CHECK(interactive_); 532 CHECK(interactive_);
510 if (matches_.empty()) { 533 if (matches_.empty()) {
511 // Don't show a select dialog if no certificate is matching. 534 // Don't show a select dialog if no certificate is matching.
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 const GetPlatformKeysCallback& callback, 784 const GetPlatformKeysCallback& callback,
762 scoped_ptr<base::Value> value) { 785 scoped_ptr<base::Value> value) {
763 scoped_ptr<KeyEntries> key_entries(new KeyEntries); 786 scoped_ptr<KeyEntries> key_entries(new KeyEntries);
764 if (value) 787 if (value)
765 key_entries = KeyEntriesFromState(*value); 788 key_entries = KeyEntriesFromState(*value);
766 789
767 callback.Run(key_entries.Pass()); 790 callback.Run(key_entries.Pass());
768 } 791 }
769 792
770 } // namespace chromeos 793 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698