| OLD | NEW |
| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ptr_util.h" |
| 15 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 18 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "extensions/browser/state_store.h" | 20 #include "extensions/browser/state_store.h" |
| 20 #include "net/cert/x509_certificate.h" | 21 #include "net/cert/x509_certificate.h" |
| 21 | 22 |
| 22 using content::BrowserThread; | 23 using content::BrowserThread; |
| 23 | 24 |
| 24 namespace chromeos { | 25 namespace chromeos { |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 DoStep(); | 128 DoStep(); |
| 128 } | 129 } |
| 129 | 130 |
| 130 // Gets the permissions for the extension with id |extension_id|. | 131 // Gets the permissions for the extension with id |extension_id|. |
| 131 void GetExtensionPermissions() { | 132 void GetExtensionPermissions() { |
| 132 key_permissions_->GetPermissionsForExtension( | 133 key_permissions_->GetPermissionsForExtension( |
| 133 extension_id_, base::Bind(&GenerateRSAKeyTask::GotPermissions, | 134 extension_id_, base::Bind(&GenerateRSAKeyTask::GotPermissions, |
| 134 base::Unretained(this))); | 135 base::Unretained(this))); |
| 135 } | 136 } |
| 136 | 137 |
| 137 void GotPermissions(scoped_ptr<KeyPermissions::PermissionsForExtension> | 138 void GotPermissions(std::unique_ptr<KeyPermissions::PermissionsForExtension> |
| 138 extension_permissions) { | 139 extension_permissions) { |
| 139 extension_permissions_ = std::move(extension_permissions); | 140 extension_permissions_ = std::move(extension_permissions); |
| 140 DoStep(); | 141 DoStep(); |
| 141 } | 142 } |
| 142 | 143 |
| 143 Step next_step_ = Step::GENERATE_KEY; | 144 Step next_step_ = Step::GENERATE_KEY; |
| 144 | 145 |
| 145 const std::string token_id_; | 146 const std::string token_id_; |
| 146 const unsigned int modulus_length_; | 147 const unsigned int modulus_length_; |
| 147 std::string public_key_spki_der_; | 148 std::string public_key_spki_der_; |
| 148 const std::string extension_id_; | 149 const std::string extension_id_; |
| 149 GenerateKeyCallback callback_; | 150 GenerateKeyCallback callback_; |
| 150 scoped_ptr<KeyPermissions::PermissionsForExtension> extension_permissions_; | 151 std::unique_ptr<KeyPermissions::PermissionsForExtension> |
| 152 extension_permissions_; |
| 151 KeyPermissions* const key_permissions_; | 153 KeyPermissions* const key_permissions_; |
| 152 PlatformKeysService* const service_; | 154 PlatformKeysService* const service_; |
| 153 content::BrowserContext* const browser_context_; | 155 content::BrowserContext* const browser_context_; |
| 154 base::WeakPtrFactory<GenerateRSAKeyTask> weak_factory_; | 156 base::WeakPtrFactory<GenerateRSAKeyTask> weak_factory_; |
| 155 | 157 |
| 156 DISALLOW_COPY_AND_ASSIGN(GenerateRSAKeyTask); | 158 DISALLOW_COPY_AND_ASSIGN(GenerateRSAKeyTask); |
| 157 }; | 159 }; |
| 158 | 160 |
| 159 class PlatformKeysService::SignTask : public Task { | 161 class PlatformKeysService::SignTask : public Task { |
| 160 public: | 162 public: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 return; | 228 return; |
| 227 } | 229 } |
| 228 } | 230 } |
| 229 | 231 |
| 230 void GetExtensionPermissions() { | 232 void GetExtensionPermissions() { |
| 231 key_permissions_->GetPermissionsForExtension( | 233 key_permissions_->GetPermissionsForExtension( |
| 232 extension_id_, | 234 extension_id_, |
| 233 base::Bind(&SignTask::GotPermissions, base::Unretained(this))); | 235 base::Bind(&SignTask::GotPermissions, base::Unretained(this))); |
| 234 } | 236 } |
| 235 | 237 |
| 236 void GotPermissions(scoped_ptr<KeyPermissions::PermissionsForExtension> | 238 void GotPermissions(std::unique_ptr<KeyPermissions::PermissionsForExtension> |
| 237 extension_permissions) { | 239 extension_permissions) { |
| 238 extension_permissions_ = std::move(extension_permissions); | 240 extension_permissions_ = std::move(extension_permissions); |
| 239 DoStep(); | 241 DoStep(); |
| 240 } | 242 } |
| 241 | 243 |
| 242 // Updates the permissions for |public_key_|, starts the actual signing | 244 // Updates the permissions for |public_key_|, starts the actual signing |
| 243 // operation and afterwards passes the signature (or error) to |callback_|. | 245 // operation and afterwards passes the signature (or error) to |callback_|. |
| 244 void Sign() { | 246 void Sign() { |
| 245 extension_permissions_->SetKeyUsedForSigning(public_key_); | 247 extension_permissions_->SetKeyUsedForSigning(public_key_); |
| 246 | 248 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 268 const std::string data_; | 270 const std::string data_; |
| 269 const std::string public_key_; | 271 const std::string public_key_; |
| 270 | 272 |
| 271 // If true, |data_| will not be hashed before signing. Only PKCS#1 v1.5 | 273 // If true, |data_| will not be hashed before signing. Only PKCS#1 v1.5 |
| 272 // padding will be applied before signing. | 274 // padding will be applied before signing. |
| 273 // If false, |hash_algorithm_| is set to a value != NONE. | 275 // If false, |hash_algorithm_| is set to a value != NONE. |
| 274 const bool sign_direct_pkcs_padded_; | 276 const bool sign_direct_pkcs_padded_; |
| 275 const platform_keys::HashAlgorithm hash_algorithm_; | 277 const platform_keys::HashAlgorithm hash_algorithm_; |
| 276 const std::string extension_id_; | 278 const std::string extension_id_; |
| 277 const SignCallback callback_; | 279 const SignCallback callback_; |
| 278 scoped_ptr<KeyPermissions::PermissionsForExtension> extension_permissions_; | 280 std::unique_ptr<KeyPermissions::PermissionsForExtension> |
| 281 extension_permissions_; |
| 279 KeyPermissions* const key_permissions_; | 282 KeyPermissions* const key_permissions_; |
| 280 PlatformKeysService* const service_; | 283 PlatformKeysService* const service_; |
| 281 base::WeakPtrFactory<SignTask> weak_factory_; | 284 base::WeakPtrFactory<SignTask> weak_factory_; |
| 282 | 285 |
| 283 DISALLOW_COPY_AND_ASSIGN(SignTask); | 286 DISALLOW_COPY_AND_ASSIGN(SignTask); |
| 284 }; | 287 }; |
| 285 | 288 |
| 286 class PlatformKeysService::SelectTask : public Task { | 289 class PlatformKeysService::SelectTask : public Task { |
| 287 public: | 290 public: |
| 288 enum class Step { | 291 enum class Step { |
| 289 GET_EXTENSION_PERMISSIONS, | 292 GET_EXTENSION_PERMISSIONS, |
| 290 GET_MATCHING_CERTS, | 293 GET_MATCHING_CERTS, |
| 291 INTERSECT_WITH_INPUT_CERTS, | 294 INTERSECT_WITH_INPUT_CERTS, |
| 292 SELECT_CERTS, | 295 SELECT_CERTS, |
| 293 UPDATE_PERMISSION, | 296 UPDATE_PERMISSION, |
| 294 FILTER_BY_PERMISSIONS, | 297 FILTER_BY_PERMISSIONS, |
| 295 DONE, | 298 DONE, |
| 296 }; | 299 }; |
| 297 | 300 |
| 298 // This task determines all known client certs matching |request| and that are | 301 // This task determines all known client certs matching |request| and that are |
| 299 // elements of |input_client_certificates|, if given. If |interactive| is | 302 // elements of |input_client_certificates|, if given. If |interactive| is |
| 300 // true, calls |service->select_delegate_->Select()| to select a cert from all | 303 // true, calls |service->select_delegate_->Select()| to select a cert from all |
| 301 // matches. The extension with |extension_id| will be granted unlimited sign | 304 // matches. The extension with |extension_id| will be granted unlimited sign |
| 302 // permission for the selected cert. Finally, either the selection or, if | 305 // permission for the selected cert. Finally, either the selection or, if |
| 303 // |interactive| is false, matching certs that the extension has permission | 306 // |interactive| is false, matching certs that the extension has permission |
| 304 // for are passed to |callback|. | 307 // for are passed to |callback|. |
| 305 SelectTask(const platform_keys::ClientCertificateRequest& request, | 308 SelectTask(const platform_keys::ClientCertificateRequest& request, |
| 306 scoped_ptr<net::CertificateList> input_client_certificates, | 309 std::unique_ptr<net::CertificateList> input_client_certificates, |
| 307 bool interactive, | 310 bool interactive, |
| 308 const std::string& extension_id, | 311 const std::string& extension_id, |
| 309 const SelectCertificatesCallback& callback, | 312 const SelectCertificatesCallback& callback, |
| 310 content::WebContents* web_contents, | 313 content::WebContents* web_contents, |
| 311 KeyPermissions* key_permissions, | 314 KeyPermissions* key_permissions, |
| 312 PlatformKeysService* service) | 315 PlatformKeysService* service) |
| 313 : request_(request), | 316 : request_(request), |
| 314 input_client_certificates_(std::move(input_client_certificates)), | 317 input_client_certificates_(std::move(input_client_certificates)), |
| 315 interactive_(interactive), | 318 interactive_(interactive), |
| 316 extension_id_(extension_id), | 319 extension_id_(extension_id), |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 return; | 367 return; |
| 365 } | 368 } |
| 366 } | 369 } |
| 367 | 370 |
| 368 void GetExtensionPermissions() { | 371 void GetExtensionPermissions() { |
| 369 key_permissions_->GetPermissionsForExtension( | 372 key_permissions_->GetPermissionsForExtension( |
| 370 extension_id_, | 373 extension_id_, |
| 371 base::Bind(&SelectTask::GotPermissions, base::Unretained(this))); | 374 base::Bind(&SelectTask::GotPermissions, base::Unretained(this))); |
| 372 } | 375 } |
| 373 | 376 |
| 374 void GotPermissions(scoped_ptr<KeyPermissions::PermissionsForExtension> | 377 void GotPermissions(std::unique_ptr<KeyPermissions::PermissionsForExtension> |
| 375 extension_permissions) { | 378 extension_permissions) { |
| 376 extension_permissions_ = std::move(extension_permissions); | 379 extension_permissions_ = std::move(extension_permissions); |
| 377 DoStep(); | 380 DoStep(); |
| 378 } | 381 } |
| 379 | 382 |
| 380 // Retrieves all certificates matching |request_|. Will call back to | 383 // Retrieves all certificates matching |request_|. Will call back to |
| 381 // |GotMatchingCerts()|. | 384 // |GotMatchingCerts()|. |
| 382 void GetMatchingCerts() { | 385 void GetMatchingCerts() { |
| 383 platform_keys::subtle::SelectClientCertificates( | 386 platform_keys::subtle::SelectClientCertificates( |
| 384 request_.certificate_authorities, | 387 request_.certificate_authorities, |
| 385 base::Bind(&SelectTask::GotMatchingCerts, weak_factory_.GetWeakPtr()), | 388 base::Bind(&SelectTask::GotMatchingCerts, weak_factory_.GetWeakPtr()), |
| 386 service_->browser_context_); | 389 service_->browser_context_); |
| 387 } | 390 } |
| 388 | 391 |
| 389 // If the certificate request could be processed successfully, |matches| will | 392 // If the certificate request could be processed successfully, |matches| will |
| 390 // contain the list of matching certificates (maybe empty) and |error_message| | 393 // contain the list of matching certificates (maybe empty) and |error_message| |
| 391 // will be empty. If an error occurred, |matches| will be null and | 394 // will be empty. If an error occurred, |matches| will be null and |
| 392 // |error_message| contain an error message. | 395 // |error_message| contain an error message. |
| 393 // Note that the order of |matches|, based on the expiration/issuance date, is | 396 // Note that the order of |matches|, based on the expiration/issuance date, is |
| 394 // relevant and must be preserved in any processing of the list. | 397 // relevant and must be preserved in any processing of the list. |
| 395 void GotMatchingCerts(scoped_ptr<net::CertificateList> matches, | 398 void GotMatchingCerts(std::unique_ptr<net::CertificateList> matches, |
| 396 const std::string& error_message) { | 399 const std::string& error_message) { |
| 397 if (!error_message.empty()) { | 400 if (!error_message.empty()) { |
| 398 next_step_ = Step::DONE; | 401 next_step_ = Step::DONE; |
| 399 callback_.Run(nullptr /* no certificates */, error_message); | 402 callback_.Run(nullptr /* no certificates */, error_message); |
| 400 DoStep(); | 403 DoStep(); |
| 401 return; | 404 return; |
| 402 } | 405 } |
| 403 | 406 |
| 404 for (scoped_refptr<net::X509Certificate>& certificate : *matches) { | 407 for (scoped_refptr<net::X509Certificate>& certificate : *matches) { |
| 405 const std::string public_key_spki_der( | 408 const std::string public_key_spki_der( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 void IntersectWithInputCerts() { | 441 void IntersectWithInputCerts() { |
| 439 if (!input_client_certificates_) { | 442 if (!input_client_certificates_) { |
| 440 DoStep(); | 443 DoStep(); |
| 441 return; | 444 return; |
| 442 } | 445 } |
| 443 platform_keys::IntersectCertificates( | 446 platform_keys::IntersectCertificates( |
| 444 matches_, *input_client_certificates_, | 447 matches_, *input_client_certificates_, |
| 445 base::Bind(&SelectTask::GotIntersection, weak_factory_.GetWeakPtr())); | 448 base::Bind(&SelectTask::GotIntersection, weak_factory_.GetWeakPtr())); |
| 446 } | 449 } |
| 447 | 450 |
| 448 void GotIntersection(scoped_ptr<net::CertificateList> intersection) { | 451 void GotIntersection(std::unique_ptr<net::CertificateList> intersection) { |
| 449 matches_.swap(*intersection); | 452 matches_.swap(*intersection); |
| 450 DoStep(); | 453 DoStep(); |
| 451 } | 454 } |
| 452 | 455 |
| 453 // Calls |service_->select_delegate_->Select()| to select a cert from | 456 // Calls |service_->select_delegate_->Select()| to select a cert from |
| 454 // |matches_|, which will be stored in |selected_cert_|. | 457 // |matches_|, which will be stored in |selected_cert_|. |
| 455 // Will call back to |GotSelection()|. | 458 // Will call back to |GotSelection()|. |
| 456 void SelectCerts() { | 459 void SelectCerts() { |
| 457 CHECK(interactive_); | 460 CHECK(interactive_); |
| 458 if (matches_.empty()) { | 461 if (matches_.empty()) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 484 const std::string public_key_spki_der( | 487 const std::string public_key_spki_der( |
| 485 platform_keys::GetSubjectPublicKeyInfo(selected_cert_)); | 488 platform_keys::GetSubjectPublicKeyInfo(selected_cert_)); |
| 486 extension_permissions_->SetUserGrantedPermission(public_key_spki_der); | 489 extension_permissions_->SetUserGrantedPermission(public_key_spki_der); |
| 487 DoStep(); | 490 DoStep(); |
| 488 } | 491 } |
| 489 | 492 |
| 490 // Filters from all matches (if not interactive) or from the selection (if | 493 // Filters from all matches (if not interactive) or from the selection (if |
| 491 // interactive), the certificates that the extension has unlimited sign | 494 // interactive), the certificates that the extension has unlimited sign |
| 492 // permission for. Passes the filtered certs to |callback_|. | 495 // permission for. Passes the filtered certs to |callback_|. |
| 493 void FilterSelectionByPermission() { | 496 void FilterSelectionByPermission() { |
| 494 scoped_ptr<net::CertificateList> selection(new net::CertificateList); | 497 std::unique_ptr<net::CertificateList> selection(new net::CertificateList); |
| 495 if (interactive_) { | 498 if (interactive_) { |
| 496 if (selected_cert_) | 499 if (selected_cert_) |
| 497 selection->push_back(selected_cert_); | 500 selection->push_back(selected_cert_); |
| 498 } else { | 501 } else { |
| 499 selection->assign(matches_.begin(), matches_.end()); | 502 selection->assign(matches_.begin(), matches_.end()); |
| 500 } | 503 } |
| 501 | 504 |
| 502 scoped_ptr<net::CertificateList> filtered_certs(new net::CertificateList); | 505 std::unique_ptr<net::CertificateList> filtered_certs( |
| 506 new net::CertificateList); |
| 503 for (scoped_refptr<net::X509Certificate> selected_cert : *selection) { | 507 for (scoped_refptr<net::X509Certificate> selected_cert : *selection) { |
| 504 const std::string public_key_spki_der( | 508 const std::string public_key_spki_der( |
| 505 platform_keys::GetSubjectPublicKeyInfo(selected_cert)); | 509 platform_keys::GetSubjectPublicKeyInfo(selected_cert)); |
| 506 | 510 |
| 507 if (!extension_permissions_->CanUseKeyForSigning(public_key_spki_der)) | 511 if (!extension_permissions_->CanUseKeyForSigning(public_key_spki_der)) |
| 508 continue; | 512 continue; |
| 509 | 513 |
| 510 filtered_certs->push_back(selected_cert); | 514 filtered_certs->push_back(selected_cert); |
| 511 } | 515 } |
| 512 // Note: In the interactive case this should have filtered exactly the | 516 // Note: In the interactive case this should have filtered exactly the |
| 513 // one selected cert. Checking the permissions again is not striclty | 517 // one selected cert. Checking the permissions again is not striclty |
| 514 // necessary but this ensures that the permissions were updated correctly. | 518 // necessary but this ensures that the permissions were updated correctly. |
| 515 CHECK(!selected_cert_ || (filtered_certs->size() == 1 && | 519 CHECK(!selected_cert_ || (filtered_certs->size() == 1 && |
| 516 filtered_certs->front() == selected_cert_)); | 520 filtered_certs->front() == selected_cert_)); |
| 517 callback_.Run(std::move(filtered_certs), std::string() /* no error */); | 521 callback_.Run(std::move(filtered_certs), std::string() /* no error */); |
| 518 DoStep(); | 522 DoStep(); |
| 519 } | 523 } |
| 520 | 524 |
| 521 Step next_step_ = Step::GET_EXTENSION_PERMISSIONS; | 525 Step next_step_ = Step::GET_EXTENSION_PERMISSIONS; |
| 522 | 526 |
| 523 net::CertificateList matches_; | 527 net::CertificateList matches_; |
| 524 scoped_refptr<net::X509Certificate> selected_cert_; | 528 scoped_refptr<net::X509Certificate> selected_cert_; |
| 525 platform_keys::ClientCertificateRequest request_; | 529 platform_keys::ClientCertificateRequest request_; |
| 526 scoped_ptr<net::CertificateList> input_client_certificates_; | 530 std::unique_ptr<net::CertificateList> input_client_certificates_; |
| 527 const bool interactive_; | 531 const bool interactive_; |
| 528 const std::string extension_id_; | 532 const std::string extension_id_; |
| 529 const SelectCertificatesCallback callback_; | 533 const SelectCertificatesCallback callback_; |
| 530 content::WebContents* const web_contents_; | 534 content::WebContents* const web_contents_; |
| 531 scoped_ptr<KeyPermissions::PermissionsForExtension> extension_permissions_; | 535 std::unique_ptr<KeyPermissions::PermissionsForExtension> |
| 536 extension_permissions_; |
| 532 KeyPermissions* const key_permissions_; | 537 KeyPermissions* const key_permissions_; |
| 533 PlatformKeysService* const service_; | 538 PlatformKeysService* const service_; |
| 534 base::WeakPtrFactory<SelectTask> weak_factory_; | 539 base::WeakPtrFactory<SelectTask> weak_factory_; |
| 535 | 540 |
| 536 DISALLOW_COPY_AND_ASSIGN(SelectTask); | 541 DISALLOW_COPY_AND_ASSIGN(SelectTask); |
| 537 }; | 542 }; |
| 538 | 543 |
| 539 PlatformKeysService::SelectDelegate::SelectDelegate() { | 544 PlatformKeysService::SelectDelegate::SelectDelegate() { |
| 540 } | 545 } |
| 541 | 546 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 555 state_store), | 560 state_store), |
| 556 weak_factory_(this) { | 561 weak_factory_(this) { |
| 557 DCHECK(browser_context); | 562 DCHECK(browser_context); |
| 558 DCHECK(state_store); | 563 DCHECK(state_store); |
| 559 } | 564 } |
| 560 | 565 |
| 561 PlatformKeysService::~PlatformKeysService() { | 566 PlatformKeysService::~PlatformKeysService() { |
| 562 } | 567 } |
| 563 | 568 |
| 564 void PlatformKeysService::SetSelectDelegate( | 569 void PlatformKeysService::SetSelectDelegate( |
| 565 scoped_ptr<SelectDelegate> delegate) { | 570 std::unique_ptr<SelectDelegate> delegate) { |
| 566 select_delegate_ = std::move(delegate); | 571 select_delegate_ = std::move(delegate); |
| 567 } | 572 } |
| 568 | 573 |
| 569 void PlatformKeysService::GenerateRSAKey(const std::string& token_id, | 574 void PlatformKeysService::GenerateRSAKey(const std::string& token_id, |
| 570 unsigned int modulus_length, | 575 unsigned int modulus_length, |
| 571 const std::string& extension_id, | 576 const std::string& extension_id, |
| 572 const GenerateKeyCallback& callback) { | 577 const GenerateKeyCallback& callback) { |
| 573 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 578 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 574 StartOrQueueTask(make_scoped_ptr( | 579 StartOrQueueTask(base::WrapUnique( |
| 575 new GenerateRSAKeyTask(token_id, modulus_length, extension_id, callback, | 580 new GenerateRSAKeyTask(token_id, modulus_length, extension_id, callback, |
| 576 &key_permissions_, this, browser_context_))); | 581 &key_permissions_, this, browser_context_))); |
| 577 } | 582 } |
| 578 | 583 |
| 579 void PlatformKeysService::SignRSAPKCS1Digest( | 584 void PlatformKeysService::SignRSAPKCS1Digest( |
| 580 const std::string& token_id, | 585 const std::string& token_id, |
| 581 const std::string& data, | 586 const std::string& data, |
| 582 const std::string& public_key, | 587 const std::string& public_key, |
| 583 platform_keys::HashAlgorithm hash_algorithm, | 588 platform_keys::HashAlgorithm hash_algorithm, |
| 584 const std::string& extension_id, | 589 const std::string& extension_id, |
| 585 const SignCallback& callback) { | 590 const SignCallback& callback) { |
| 586 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 591 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 587 StartOrQueueTask(make_scoped_ptr(new SignTask( | 592 StartOrQueueTask(base::WrapUnique(new SignTask( |
| 588 token_id, data, public_key, false /* digest before signing */, | 593 token_id, data, public_key, false /* digest before signing */, |
| 589 hash_algorithm, extension_id, callback, &key_permissions_, this))); | 594 hash_algorithm, extension_id, callback, &key_permissions_, this))); |
| 590 } | 595 } |
| 591 | 596 |
| 592 void PlatformKeysService::SignRSAPKCS1Raw(const std::string& token_id, | 597 void PlatformKeysService::SignRSAPKCS1Raw(const std::string& token_id, |
| 593 const std::string& data, | 598 const std::string& data, |
| 594 const std::string& public_key, | 599 const std::string& public_key, |
| 595 const std::string& extension_id, | 600 const std::string& extension_id, |
| 596 const SignCallback& callback) { | 601 const SignCallback& callback) { |
| 597 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 602 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 598 StartOrQueueTask(make_scoped_ptr(new SignTask( | 603 StartOrQueueTask(base::WrapUnique(new SignTask( |
| 599 token_id, data, public_key, true /* sign directly without hashing */, | 604 token_id, data, public_key, true /* sign directly without hashing */, |
| 600 platform_keys::HASH_ALGORITHM_NONE, extension_id, callback, | 605 platform_keys::HASH_ALGORITHM_NONE, extension_id, callback, |
| 601 &key_permissions_, this))); | 606 &key_permissions_, this))); |
| 602 } | 607 } |
| 603 | 608 |
| 604 void PlatformKeysService::SelectClientCertificates( | 609 void PlatformKeysService::SelectClientCertificates( |
| 605 const platform_keys::ClientCertificateRequest& request, | 610 const platform_keys::ClientCertificateRequest& request, |
| 606 scoped_ptr<net::CertificateList> client_certificates, | 611 std::unique_ptr<net::CertificateList> client_certificates, |
| 607 bool interactive, | 612 bool interactive, |
| 608 const std::string& extension_id, | 613 const std::string& extension_id, |
| 609 const SelectCertificatesCallback& callback, | 614 const SelectCertificatesCallback& callback, |
| 610 content::WebContents* web_contents) { | 615 content::WebContents* web_contents) { |
| 611 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 616 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 612 StartOrQueueTask(make_scoped_ptr(new SelectTask( | 617 StartOrQueueTask(base::WrapUnique(new SelectTask( |
| 613 request, std::move(client_certificates), interactive, extension_id, | 618 request, std::move(client_certificates), interactive, extension_id, |
| 614 callback, web_contents, &key_permissions_, this))); | 619 callback, web_contents, &key_permissions_, this))); |
| 615 } | 620 } |
| 616 | 621 |
| 617 void PlatformKeysService::StartOrQueueTask(scoped_ptr<Task> task) { | 622 void PlatformKeysService::StartOrQueueTask(std::unique_ptr<Task> task) { |
| 618 tasks_.push(make_linked_ptr(task.release())); | 623 tasks_.push(make_linked_ptr(task.release())); |
| 619 if (tasks_.size() == 1) | 624 if (tasks_.size() == 1) |
| 620 tasks_.front()->Start(); | 625 tasks_.front()->Start(); |
| 621 } | 626 } |
| 622 | 627 |
| 623 void PlatformKeysService::TaskFinished(Task* task) { | 628 void PlatformKeysService::TaskFinished(Task* task) { |
| 624 DCHECK(!tasks_.empty()); | 629 DCHECK(!tasks_.empty()); |
| 625 DCHECK(task == tasks_.front().get()); | 630 DCHECK(task == tasks_.front().get()); |
| 626 // Remove all finished tasks from the queue (should be at most one). | 631 // Remove all finished tasks from the queue (should be at most one). |
| 627 while (!tasks_.empty() && tasks_.front()->IsDone()) | 632 while (!tasks_.empty() && tasks_.front()->IsDone()) |
| 628 tasks_.pop(); | 633 tasks_.pop(); |
| 629 | 634 |
| 630 // Now either the queue is empty or the next task is not finished yet and it | 635 // Now either the queue is empty or the next task is not finished yet and it |
| 631 // can be started. | 636 // can be started. |
| 632 if (!tasks_.empty()) | 637 if (!tasks_.empty()) |
| 633 tasks_.front()->Start(); | 638 tasks_.front()->Start(); |
| 634 } | 639 } |
| 635 | 640 |
| 636 } // namespace chromeos | 641 } // namespace chromeos |
| OLD | NEW |