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 kErrorInternal[] = "Internal Error."; | 21 const char kErrorInternal[] = "Internal Error."; |
21 const char kErrorKeyNotAllowedForSigning[] = | 22 const char kErrorKeyNotAllowedForSigning[] = |
22 "This key is not allowed for signing. Either it was used for signing " | 23 "This key is not allowed for signing. Either it was used for signing " |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 public_key_spki_der, | 109 public_key_spki_der, |
109 base::Bind(&CheckValidityAndSign, | 110 base::Bind(&CheckValidityAndSign, |
110 token_id, | 111 token_id, |
111 public_key_spki_der, | 112 public_key_spki_der, |
112 hash_algorithm, | 113 hash_algorithm, |
113 data, | 114 data, |
114 callback, | 115 callback, |
115 browser_context_)); | 116 browser_context_)); |
116 } | 117 } |
117 | 118 |
| 119 void PlatformKeysService::SelectClientCertificates( |
| 120 const platform_keys::ClientCertificateRequest& request, |
| 121 const std::string& extension_id, |
| 122 const SelectCertificatesCallback& callback) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 |
| 125 platform_keys::subtle::SelectClientCertificates( |
| 126 request, |
| 127 base::Bind(&PlatformKeysService::SelectClientCertificatesCallback, |
| 128 weak_factory_.GetWeakPtr(), extension_id, callback), |
| 129 browser_context_); |
| 130 } |
| 131 |
118 void PlatformKeysService::RegisterPublicKey( | 132 void PlatformKeysService::RegisterPublicKey( |
119 const std::string& extension_id, | 133 const std::string& extension_id, |
120 const std::string& public_key_spki_der, | 134 const std::string& public_key_spki_der, |
121 const base::Callback<void(bool)>& callback) { | 135 const base::Callback<void(bool)>& callback) { |
122 GetPlatformKeysOfExtension( | 136 GetPlatformKeysOfExtension( |
123 extension_id, | 137 extension_id, |
124 base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys, | 138 base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys, |
125 weak_factory_.GetWeakPtr(), | 139 weak_factory_.GetWeakPtr(), |
126 extension_id, | 140 extension_id, |
127 public_key_spki_der, | 141 public_key_spki_der, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 const std::string& error_message) { | 173 const std::string& error_message) { |
160 if (!error_message.empty()) { | 174 if (!error_message.empty()) { |
161 callback.Run(std::string() /* no public key */, error_message); | 175 callback.Run(std::string() /* no public key */, error_message); |
162 return; | 176 return; |
163 } | 177 } |
164 base::Callback<void(bool)> wrapped_callback( | 178 base::Callback<void(bool)> wrapped_callback( |
165 base::Bind(&WrapGenerateKeyCallback, callback, public_key_spki_der)); | 179 base::Bind(&WrapGenerateKeyCallback, callback, public_key_spki_der)); |
166 RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback); | 180 RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback); |
167 } | 181 } |
168 | 182 |
| 183 void PlatformKeysService::SelectClientCertificatesCallback( |
| 184 const std::string& extension_id, |
| 185 const SelectCertificatesCallback& callback, |
| 186 scoped_ptr<net::CertificateList> matches, |
| 187 const std::string& error_message) { |
| 188 // TODO(pneubeck): Remove all certs that the extension doesn't have access to. |
| 189 callback.Run(matches.Pass(), error_message); |
| 190 } |
| 191 |
169 void PlatformKeysService::RegisterPublicKeyGotPlatformKeys( | 192 void PlatformKeysService::RegisterPublicKeyGotPlatformKeys( |
170 const std::string& extension_id, | 193 const std::string& extension_id, |
171 const std::string& public_key_spki_der, | 194 const std::string& public_key_spki_der, |
172 const base::Callback<void(bool)>& callback, | 195 const base::Callback<void(bool)>& callback, |
173 scoped_ptr<base::ListValue> platform_keys) { | 196 scoped_ptr<base::ListValue> platform_keys) { |
174 if (!platform_keys) { | 197 if (!platform_keys) { |
175 LOG(ERROR) << "Error while reading the platform keys."; | 198 LOG(ERROR) << "Error while reading the platform keys."; |
176 callback.Run(false); | 199 callback.Run(false); |
177 return; | 200 return; |
178 } | 201 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 base::ListValue* keys = NULL; | 243 base::ListValue* keys = NULL; |
221 if (!value->GetAsList(&keys)) { | 244 if (!value->GetAsList(&keys)) { |
222 LOG(ERROR) << "Found a value of wrong type."; | 245 LOG(ERROR) << "Found a value of wrong type."; |
223 value.reset(); | 246 value.reset(); |
224 } | 247 } |
225 ignore_result(value.release()); | 248 ignore_result(value.release()); |
226 callback.Run(make_scoped_ptr(keys)); | 249 callback.Run(make_scoped_ptr(keys)); |
227 } | 250 } |
228 | 251 |
229 } // namespace chromeos | 252 } // namespace chromeos |
OLD | NEW |