Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: chrome/browser/chromeos/platform_keys/platform_keys_service.cc

Issue 875373002: First implementation of chrome.platformKeys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_idl
Patch Set: Rebased. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 public_key_spki_der, 104 public_key_spki_der,
104 base::Bind(&CheckValidityAndSign, 105 base::Bind(&CheckValidityAndSign,
105 token_id, 106 token_id,
106 public_key_spki_der, 107 public_key_spki_der,
107 hash_algorithm, 108 hash_algorithm,
108 data, 109 data,
109 callback, 110 callback,
110 browser_context_)); 111 browser_context_));
111 } 112 }
112 113
114 void PlatformKeysService::SelectClientCertificates(
115 const platform_keys::ClientCertificateRequest& request,
116 const std::string& extension_id,
117 const SelectCertificatesCallback& callback) {
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
119
120 platform_keys::subtle::SelectClientCertificates(
121 request,
122 base::Bind(&PlatformKeysService::SelectClientCertificatesCallback,
123 weak_factory_.GetWeakPtr(), extension_id, callback),
124 browser_context_);
125 }
126
113 void PlatformKeysService::RegisterPublicKey( 127 void PlatformKeysService::RegisterPublicKey(
114 const std::string& extension_id, 128 const std::string& extension_id,
115 const std::string& public_key_spki_der, 129 const std::string& public_key_spki_der,
116 const base::Closure& callback) { 130 const base::Closure& callback) {
117 GetPlatformKeysOfExtension( 131 GetPlatformKeysOfExtension(
118 extension_id, 132 extension_id,
119 base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys, 133 base::Bind(&PlatformKeysService::RegisterPublicKeyGotPlatformKeys,
120 weak_factory_.GetWeakPtr(), 134 weak_factory_.GetWeakPtr(),
121 extension_id, 135 extension_id,
122 public_key_spki_der, 136 public_key_spki_der,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const std::string& error_message) { 172 const std::string& error_message) {
159 if (!error_message.empty()) { 173 if (!error_message.empty()) {
160 callback.Run(std::string() /* no public key */, error_message); 174 callback.Run(std::string() /* no public key */, error_message);
161 return; 175 return;
162 } 176 }
163 base::Closure wrapped_callback( 177 base::Closure wrapped_callback(
164 base::Bind(&WrapGenerateKeyCallback, callback, public_key_spki_der)); 178 base::Bind(&WrapGenerateKeyCallback, callback, public_key_spki_der));
165 RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback); 179 RegisterPublicKey(extension_id, public_key_spki_der, wrapped_callback);
166 } 180 }
167 181
182 void PlatformKeysService::SelectClientCertificatesCallback(
183 const std::string& extension_id,
184 const SelectCertificatesCallback& callback,
185 scoped_ptr<net::CertificateList> matches,
186 const std::string& error_message) {
187 // TODO(pneubeck): Remove all certs that the extension doesn't have access to.
188 callback.Run(matches.Pass(), error_message);
189 }
190
168 void PlatformKeysService::RegisterPublicKeyGotPlatformKeys( 191 void PlatformKeysService::RegisterPublicKeyGotPlatformKeys(
169 const std::string& extension_id, 192 const std::string& extension_id,
170 const std::string& public_key_spki_der, 193 const std::string& public_key_spki_der,
171 const base::Closure& callback, 194 const base::Closure& callback,
172 scoped_ptr<base::ListValue> platform_keys) { 195 scoped_ptr<base::ListValue> platform_keys) {
173 scoped_ptr<base::StringValue> key_value( 196 scoped_ptr<base::StringValue> key_value(
174 GetPublicKeyValue(public_key_spki_der)); 197 GetPublicKeyValue(public_key_spki_der));
175 198
176 DCHECK(platform_keys->end() == platform_keys->Find(*key_value)) 199 DCHECK(platform_keys->end() == platform_keys->Find(*key_value))
177 << "Keys are assumed to be generated and not to be registered multiple " 200 << "Keys are assumed to be generated and not to be registered multiple "
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 236
214 keys = new base::ListValue; 237 keys = new base::ListValue;
215 value.reset(keys); 238 value.reset(keys);
216 } 239 }
217 240
218 ignore_result(value.release()); 241 ignore_result(value.release());
219 callback.Run(make_scoped_ptr(keys)); 242 callback.Run(make_scoped_ptr(keys));
220 } 243 }
221 244
222 } // namespace chromeos 245 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698