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.h" | 5 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/threading/worker_pool.h" | 18 #include "base/threading/worker_pool.h" |
19 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat
form_keys_api.h" | 19 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat
form_keys_api.h" |
20 #include "chrome/browser/net/nss_context.h" | 20 #include "chrome/browser/net/cert_database_service_factory.h" |
| 21 #include "components/cert_database/public/cert_database_service.h" |
| 22 #include "components/cert_database/public/cert_database_service_io_part.h" |
21 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
23 #include "crypto/rsa_private_key.h" | 25 #include "crypto/rsa_private_key.h" |
24 #include "net/base/crypto_module.h" | 26 #include "net/base/crypto_module.h" |
25 #include "net/base/net_errors.h" | 27 #include "net/base/net_errors.h" |
26 #include "net/cert/cert_database.h" | 28 #include "net/cert/cert_database.h" |
27 #include "net/cert/nss_cert_database.h" | 29 #include "net/cert/nss_cert_database.h" |
28 #include "net/cert/x509_certificate.h" | 30 #include "net/cert/x509_certificate.h" |
29 | 31 |
30 using content::BrowserContext; | 32 using content::BrowserContext; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 return; | 101 return; |
100 } | 102 } |
101 } | 103 } |
102 | 104 |
103 callback.Run(cert_db); | 105 callback.Run(cert_db); |
104 } | 106 } |
105 | 107 |
106 // Retrieves the NSSCertDatabase from |context| and, if |token_id| is not empty, | 108 // Retrieves the NSSCertDatabase from |context| and, if |token_id| is not empty, |
107 // the slot for |token_id|. | 109 // the slot for |token_id|. |
108 // Must be called on the IO thread. | 110 // Must be called on the IO thread. |
109 void GetCertDatabaseOnIOThread(const std::string& token_id, | 111 void GetCertDatabaseOnIOThread( |
110 const GetCertDBCallback& callback, | 112 const std::string& token_id, |
111 content::ResourceContext* context, | 113 const GetCertDBCallback& callback, |
112 NSSOperationState* state) { | 114 base::WeakPtr<CertDatabaseServiceIOPart> db_io_part, |
| 115 NSSOperationState* state) { |
113 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
114 net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext( | 117 if (!db_io_part) { |
115 context, base::Bind(&DidGetCertDBOnIOThread, token_id, callback, state)); | 118 LOG(ERROR) << "CertDatabase shutdown."; |
| 119 state->OnError(FROM_HERE, kErrorInternal); |
| 120 return; |
| 121 } |
| 122 net::NSSCertDatabase* cert_db = db_io_part->GetNSSCertDatabase( |
| 123 base::Bind(&DidGetCertDBOnIOThread, token_id, callback, state)); |
116 | 124 |
117 if (cert_db) | 125 if (cert_db) |
118 DidGetCertDBOnIOThread(token_id, callback, state, cert_db); | 126 DidGetCertDBOnIOThread(token_id, callback, state, cert_db); |
119 } | 127 } |
120 | 128 |
121 // Asynchronously fetches the NSSCertDatabase for |browser_context| and, if | 129 // Asynchronously fetches the NSSCertDatabase for |browser_context| and, if |
122 // |token_id| is not empty, the slot for |token_id|. Stores the slot in |state| | 130 // |token_id| is not empty, the slot for |token_id|. Stores the slot in |state| |
123 // and passes the database to |callback|. Will run |callback| on the IO thread. | 131 // and passes the database to |callback|. Will run |callback| on the IO thread. |
124 void GetCertDatabase(const std::string& token_id, | 132 void GetCertDatabase(const std::string& token_id, |
125 const GetCertDBCallback& callback, | 133 const GetCertDBCallback& callback, |
126 BrowserContext* browser_context, | 134 BrowserContext* browser_context, |
127 NSSOperationState* state) { | 135 NSSOperationState* state) { |
| 136 CertDatabaseService* cert_db_service = |
| 137 CertDatabaseServiceFactory::GetForBrowserContext(browser_context); |
128 BrowserThread::PostTask(BrowserThread::IO, | 138 BrowserThread::PostTask(BrowserThread::IO, |
129 FROM_HERE, | 139 FROM_HERE, |
130 base::Bind(&GetCertDatabaseOnIOThread, | 140 base::Bind(&GetCertDatabaseOnIOThread, |
131 token_id, | 141 token_id, |
132 callback, | 142 callback, |
133 browser_context->GetResourceContext(), | 143 cert_db_service->GetIOPart(), |
134 state)); | 144 state)); |
135 } | 145 } |
136 | 146 |
137 class GenerateRSAKeyState : public NSSOperationState { | 147 class GenerateRSAKeyState : public NSSOperationState { |
138 public: | 148 public: |
139 GenerateRSAKeyState(unsigned int modulus_length_bits, | 149 GenerateRSAKeyState(unsigned int modulus_length_bits, |
140 const subtle::GenerateKeyCallback& callback); | 150 const subtle::GenerateKeyCallback& callback); |
141 virtual ~GenerateRSAKeyState() {} | 151 virtual ~GenerateRSAKeyState() {} |
142 | 152 |
143 virtual void OnError(const tracked_objects::Location& from, | 153 virtual void OnError(const tracked_objects::Location& from, |
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 NSSOperationState* state_ptr = state.get(); | 666 NSSOperationState* state_ptr = state.get(); |
657 GetCertDatabase(std::string() /* don't get any specific slot */, | 667 GetCertDatabase(std::string() /* don't get any specific slot */, |
658 base::Bind(&GetTokensWithDB, base::Passed(&state)), | 668 base::Bind(&GetTokensWithDB, base::Passed(&state)), |
659 browser_context, | 669 browser_context, |
660 state_ptr); | 670 state_ptr); |
661 } | 671 } |
662 | 672 |
663 } // namespace platform_keys | 673 } // namespace platform_keys |
664 | 674 |
665 } // namespace chromeos | 675 } // namespace chromeos |
OLD | NEW |