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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" | 10 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" |
11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
12 #include "extensions/browser/state_store.h" | 12 #include "extensions/browser/state_store.h" |
| 13 #include "net/cert/x509_certificate.h" |
13 | 14 |
14 using content::BrowserThread; | 15 using content::BrowserThread; |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const char kErrorKeyNotAllowedForSigning[] = | 21 const char kErrorKeyNotAllowedForSigning[] = |
21 "This key is not allowed for signing. Either it was used for signing " | 22 "This key is not allowed for signing. Either it was used for signing " |
22 "before or it was not correctly generated."; | 23 "before or it was not correctly generated."; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 extensions::StateStore* state_store) | 68 extensions::StateStore* state_store) |
68 : browser_context_(browser_context), | 69 : browser_context_(browser_context), |
69 state_store_(state_store), | 70 state_store_(state_store), |
70 weak_factory_(this) { | 71 weak_factory_(this) { |
71 DCHECK(state_store); | 72 DCHECK(state_store); |
72 } | 73 } |
73 | 74 |
74 PlatformKeysService::~PlatformKeysService() { | 75 PlatformKeysService::~PlatformKeysService() { |
75 } | 76 } |
76 | 77 |
| 78 void PlatformKeysService::DisablePermissionCheckForTesting() { |
| 79 permission_check_enabled_ = false; |
| 80 } |
| 81 |
77 void PlatformKeysService::GenerateRSAKey(const std::string& token_id, | 82 void PlatformKeysService::GenerateRSAKey(const std::string& token_id, |
78 unsigned int modulus_length, | 83 unsigned int modulus_length, |
79 const std::string& extension_id, | 84 const std::string& extension_id, |
80 const GenerateKeyCallback& callback) { | 85 const GenerateKeyCallback& callback) { |
81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
82 | 87 |
83 platform_keys::subtle::GenerateRSAKey( | 88 platform_keys::subtle::GenerateRSAKey( |
84 token_id, | 89 token_id, |
85 modulus_length, | 90 modulus_length, |
86 base::Bind(&PlatformKeysService::GenerateRSAKeyCallback, | 91 base::Bind(&PlatformKeysService::GenerateRSAKeyCallback, |
(...skipping 14 matching lines...) Expand all Loading... |
101 public_key_spki_der, | 106 public_key_spki_der, |
102 base::Bind(&CheckValidityAndSign, | 107 base::Bind(&CheckValidityAndSign, |
103 token_id, | 108 token_id, |
104 public_key_spki_der, | 109 public_key_spki_der, |
105 hash_algorithm, | 110 hash_algorithm, |
106 data, | 111 data, |
107 callback, | 112 callback, |
108 browser_context_)); | 113 browser_context_)); |
109 } | 114 } |
110 | 115 |
| 116 void PlatformKeysService::SelectClientCertificates( |
| 117 const platform_keys::ClientCertificateRequest& request, |
| 118 const std::string& extension_id, |
| 119 const SelectCertificatesCallback& callback) { |
| 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 121 |
| 122 platform_keys::subtle::SelectClientCertificates( |
| 123 request, |
| 124 base::Bind(&PlatformKeysService::SelectClientCertificatesCallback, |
| 125 weak_factory_.GetWeakPtr(), extension_id, callback), |
| 126 browser_context_); |
| 127 } |
| 128 |
111 void PlatformKeysService::RegisterPublicKey( | 129 void PlatformKeysService::RegisterPublicKey( |
112 const std::string& extension_id, | 130 const std::string& extension_id, |
113 const std::string& public_key_spki_der, | 131 const std::string& public_key_spki_der, |
114 const base::Closure& callback) { | 132 const base::Closure& callback) { |
115 GetPlatformKeysOfExtension( | 133 GetPlatformKeysOfExtension( |
116 extension_id, | 134 extension_id, |
117 base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys, | 135 base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys, |
118 weak_factory_.GetWeakPtr(), | 136 weak_factory_.GetWeakPtr(), |
119 extension_id, | 137 extension_id, |
120 public_key_spki_der, | 138 public_key_spki_der, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const std::string& error_message) { | 174 const std::string& error_message) { |
157 if (!error_message.empty()) { | 175 if (!error_message.empty()) { |
158 callback.Run(std::string() /* no public key */, error_message); | 176 callback.Run(std::string() /* no public key */, error_message); |
159 return; | 177 return; |
160 } | 178 } |
161 base::Closure wrapped_callback( | 179 base::Closure wrapped_callback( |
162 base::Bind(&RunGenerateKeyCallback, callback, public_key_spki_der)); | 180 base::Bind(&RunGenerateKeyCallback, callback, public_key_spki_der)); |
163 RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback); | 181 RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback); |
164 } | 182 } |
165 | 183 |
| 184 void PlatformKeysService::SelectClientCertificatesCallback( |
| 185 const std::string& extension_id, |
| 186 const SelectCertificatesCallback& callback, |
| 187 scoped_ptr<net::CertificateList> matches, |
| 188 const std::string& error_message) { |
| 189 if (permission_check_enabled_) |
| 190 matches->clear(); |
| 191 |
| 192 // TODO(pneubeck): Remove all certs that the extension doesn't have access to. |
| 193 callback.Run(matches.Pass(), error_message); |
| 194 } |
| 195 |
166 void PlatformKeysService::RegisterPublicKeyGotPlatformKeys( | 196 void PlatformKeysService::RegisterPublicKeyGotPlatformKeys( |
167 const std::string& extension_id, | 197 const std::string& extension_id, |
168 const std::string& public_key_spki_der, | 198 const std::string& public_key_spki_der, |
169 const base::Closure& callback, | 199 const base::Closure& callback, |
170 scoped_ptr<base::ListValue> platform_keys) { | 200 scoped_ptr<base::ListValue> platform_keys) { |
171 scoped_ptr<base::StringValue> key_value( | 201 scoped_ptr<base::StringValue> key_value( |
172 GetPublicKeyValue(public_key_spki_der)); | 202 GetPublicKeyValue(public_key_spki_der)); |
173 | 203 |
174 DCHECK(platform_keys->end() == platform_keys->Find(*key_value)) | 204 DCHECK(platform_keys->end() == platform_keys->Find(*key_value)) |
175 << "Keys are assumed to be generated and not to be registered multiple " | 205 << "Keys are assumed to be generated and not to be registered multiple " |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 241 |
212 keys = new base::ListValue; | 242 keys = new base::ListValue; |
213 value.reset(keys); | 243 value.reset(keys); |
214 } | 244 } |
215 | 245 |
216 ignore_result(value.release()); | 246 ignore_result(value.release()); |
217 callback.Run(make_scoped_ptr(keys)); | 247 callback.Run(make_scoped_ptr(keys)); |
218 } | 248 } |
219 | 249 |
220 } // namespace chromeos | 250 } // namespace chromeos |
OLD | NEW |