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 <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> |
11 | 11 |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/bind_helpers.h" | 15 #include "base/bind_helpers.h" |
16 #include "base/callback.h" | 16 #include "base/callback.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/location.h" | 18 #include "base/location.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/task_scheduler/post_task.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
24 #include "base/threading/worker_pool.h" | |
25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
26 #include "chrome/browser/browser_process_platform_part_chromeos.h" | 26 #include "chrome/browser/browser_process_platform_part_chromeos.h" |
27 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" | 27 #include "chrome/browser/chromeos/certificate_provider/certificate_provider.h" |
28 #include "chrome/browser/chromeos/net/client_cert_filter_chromeos.h" | 28 #include "chrome/browser/chromeos/net/client_cert_filter_chromeos.h" |
29 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h" | 29 #include "chrome/browser/chromeos/net/client_cert_store_chromeos.h" |
30 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 30 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
31 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 31 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
32 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat
form_keys_api.h" | 32 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat
form_keys_api.h" |
33 #include "chrome/browser/net/nss_context.h" | 33 #include "chrome/browser/net/nss_context.h" |
34 #include "chrome/browser/profiles/profile.h" | 34 #include "chrome/browser/profiles/profile.h" |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 public_key_der->len), | 434 public_key_der->len), |
435 std::string() /* no error */); | 435 std::string() /* no error */); |
436 } | 436 } |
437 | 437 |
438 // Continues generating a RSA key with the obtained NSSCertDatabase. Used by | 438 // Continues generating a RSA key with the obtained NSSCertDatabase. Used by |
439 // GenerateRSAKey(). | 439 // GenerateRSAKey(). |
440 void GenerateRSAKeyWithDB(std::unique_ptr<GenerateRSAKeyState> state, | 440 void GenerateRSAKeyWithDB(std::unique_ptr<GenerateRSAKeyState> state, |
441 net::NSSCertDatabase* cert_db) { | 441 net::NSSCertDatabase* cert_db) { |
442 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 442 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
443 // Only the slot and not the NSSCertDatabase is required. Ignore |cert_db|. | 443 // Only the slot and not the NSSCertDatabase is required. Ignore |cert_db|. |
444 base::WorkerPool::PostTask( | 444 // This task interacts with the TPM, hence WithFileIO() and WithWait(). |
445 FROM_HERE, | 445 base::PostTaskWithTraits( |
446 base::Bind(&GenerateRSAKeyOnWorkerThread, base::Passed(&state)), | 446 FROM_HERE, base::TaskTraits() |
447 true /*task is slow*/); | 447 .WithFileIO() |
| 448 .WithWait() |
| 449 .WithPriority(base::TaskPriority::BACKGROUND) |
| 450 .WithShutdownBehavior( |
| 451 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 452 base::Bind(&GenerateRSAKeyOnWorkerThread, base::Passed(&state))); |
448 } | 453 } |
449 | 454 |
450 // Does the actual signing on a worker thread. Used by SignRSAWithDB(). | 455 // Does the actual signing on a worker thread. Used by SignRSAWithDB(). |
451 void SignRSAOnWorkerThread(std::unique_ptr<SignRSAState> state) { | 456 void SignRSAOnWorkerThread(std::unique_ptr<SignRSAState> state) { |
452 const uint8_t* public_key_uint8 = | 457 const uint8_t* public_key_uint8 = |
453 reinterpret_cast<const uint8_t*>(state->public_key_.data()); | 458 reinterpret_cast<const uint8_t*>(state->public_key_.data()); |
454 std::vector<uint8_t> public_key_vector( | 459 std::vector<uint8_t> public_key_vector( |
455 public_key_uint8, public_key_uint8 + state->public_key_.size()); | 460 public_key_uint8, public_key_uint8 + state->public_key_.size()); |
456 | 461 |
457 crypto::ScopedSECKEYPrivateKey rsa_key; | 462 crypto::ScopedSECKEYPrivateKey rsa_key; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 } | 531 } |
527 | 532 |
528 state->CallBack(FROM_HERE, signature_str, std::string() /* no error */); | 533 state->CallBack(FROM_HERE, signature_str, std::string() /* no error */); |
529 } | 534 } |
530 | 535 |
531 // Continues signing with the obtained NSSCertDatabase. Used by Sign(). | 536 // Continues signing with the obtained NSSCertDatabase. Used by Sign(). |
532 void SignRSAWithDB(std::unique_ptr<SignRSAState> state, | 537 void SignRSAWithDB(std::unique_ptr<SignRSAState> state, |
533 net::NSSCertDatabase* cert_db) { | 538 net::NSSCertDatabase* cert_db) { |
534 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 539 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
535 // Only the slot and not the NSSCertDatabase is required. Ignore |cert_db|. | 540 // Only the slot and not the NSSCertDatabase is required. Ignore |cert_db|. |
536 base::WorkerPool::PostTask( | 541 // This task interacts with the TPM, hence WithFileIO() and WithWait(). |
537 FROM_HERE, base::Bind(&SignRSAOnWorkerThread, base::Passed(&state)), | 542 base::PostTaskWithTraits( |
538 true /*task is slow*/); | 543 FROM_HERE, base::TaskTraits() |
| 544 .WithFileIO() |
| 545 .WithWait() |
| 546 .WithPriority(base::TaskPriority::BACKGROUND) |
| 547 .WithShutdownBehavior( |
| 548 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 549 base::Bind(&SignRSAOnWorkerThread, base::Passed(&state))); |
539 } | 550 } |
540 | 551 |
541 // Called when ClientCertStoreChromeOS::GetClientCerts is done. Builds the list | 552 // Called when ClientCertStoreChromeOS::GetClientCerts is done. Builds the list |
542 // of net::CertificateList and calls back. Used by | 553 // of net::CertificateList and calls back. Used by |
543 // SelectCertificatesOnIOThread(). | 554 // SelectCertificatesOnIOThread(). |
544 void DidSelectCertificatesOnIOThread( | 555 void DidSelectCertificatesOnIOThread( |
545 std::unique_ptr<SelectCertificatesState> state) { | 556 std::unique_ptr<SelectCertificatesState> state) { |
546 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 557 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
547 state->CallBack(FROM_HERE, std::move(state->certs_), | 558 state->CallBack(FROM_HERE, std::move(state->certs_), |
548 std::string() /* no error */); | 559 std::string() /* no error */); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 state->CallBack(FROM_HERE, std::move(client_certs), | 602 state->CallBack(FROM_HERE, std::move(client_certs), |
592 std::string() /* no error */); | 603 std::string() /* no error */); |
593 } | 604 } |
594 | 605 |
595 // Passes the obtained certificates to the worker thread for filtering. Used by | 606 // Passes the obtained certificates to the worker thread for filtering. Used by |
596 // GetCertificatesWithDB(). | 607 // GetCertificatesWithDB(). |
597 void DidGetCertificates(std::unique_ptr<GetCertificatesState> state, | 608 void DidGetCertificates(std::unique_ptr<GetCertificatesState> state, |
598 std::unique_ptr<net::CertificateList> all_certs) { | 609 std::unique_ptr<net::CertificateList> all_certs) { |
599 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 610 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
600 state->certs_ = std::move(all_certs); | 611 state->certs_ = std::move(all_certs); |
601 base::WorkerPool::PostTask( | 612 // This task interacts with the TPM, hence WithFileIO() and WithWait(). |
602 FROM_HERE, | 613 base::PostTaskWithTraits( |
603 base::Bind(&FilterCertificatesOnWorkerThread, base::Passed(&state)), | 614 FROM_HERE, base::TaskTraits() |
604 true /*task is slow*/); | 615 .WithFileIO() |
| 616 .WithWait() |
| 617 .WithPriority(base::TaskPriority::BACKGROUND) |
| 618 .WithShutdownBehavior( |
| 619 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), |
| 620 base::Bind(&FilterCertificatesOnWorkerThread, base::Passed(&state))); |
605 } | 621 } |
606 | 622 |
607 // Continues getting certificates with the obtained NSSCertDatabase. Used by | 623 // Continues getting certificates with the obtained NSSCertDatabase. Used by |
608 // GetCertificates(). | 624 // GetCertificates(). |
609 void GetCertificatesWithDB(std::unique_ptr<GetCertificatesState> state, | 625 void GetCertificatesWithDB(std::unique_ptr<GetCertificatesState> state, |
610 net::NSSCertDatabase* cert_db) { | 626 net::NSSCertDatabase* cert_db) { |
611 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 627 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
612 // Get the pointer to slot before base::Passed releases |state|. | 628 // Get the pointer to slot before base::Passed releases |state|. |
613 PK11SlotInfo* slot = state->slot_.get(); | 629 PK11SlotInfo* slot = state->slot_.get(); |
614 cert_db->ListCertsInSlot( | 630 cert_db->ListCertsInSlot( |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 NSSOperationState* state_ptr = state.get(); | 910 NSSOperationState* state_ptr = state.get(); |
895 GetCertDatabase(std::string() /* don't get any specific slot */, | 911 GetCertDatabase(std::string() /* don't get any specific slot */, |
896 base::Bind(&GetTokensWithDB, base::Passed(&state)), | 912 base::Bind(&GetTokensWithDB, base::Passed(&state)), |
897 browser_context, | 913 browser_context, |
898 state_ptr); | 914 state_ptr); |
899 } | 915 } |
900 | 916 |
901 } // namespace platform_keys | 917 } // namespace platform_keys |
902 | 918 |
903 } // namespace chromeos | 919 } // namespace chromeos |
OLD | NEW |