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

Side by Side Diff: chrome/browser/extensions/api/enterprise_platform_keys/enterprise_platform_keys_api.cc

Issue 820673004: json_schema_compiler: Use std::vector<char> for binary values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@simplify_json_schema
Patch Set: Fix merge error. Created 5 years, 11 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/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h" 5 #include "chrome/browser/extensions/api/enterprise_platform_keys/enterprise_plat form_keys_api.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/stl_util.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "chrome/browser/chromeos/platform_keys/platform_keys.h" 10 #include "chrome/browser/chromeos/platform_keys/platform_keys.h"
10 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h" 11 #include "chrome/browser/chromeos/platform_keys/platform_keys_service.h"
11 #include "chrome/browser/chromeos/platform_keys/platform_keys_service_factory.h" 12 #include "chrome/browser/chromeos/platform_keys/platform_keys_service_factory.h"
12 #include "chrome/common/extensions/api/enterprise_platform_keys.h" 13 #include "chrome/common/extensions/api/enterprise_platform_keys.h"
13 #include "chrome/common/extensions/api/enterprise_platform_keys_internal.h" 14 #include "chrome/common/extensions/api/enterprise_platform_keys_internal.h"
14 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
15 #include "net/cert/x509_certificate.h" 16 #include "net/cert/x509_certificate.h"
16 17
17 namespace extensions { 18 namespace extensions {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 &EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey, 87 &EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey,
87 this)); 88 this));
88 return RespondLater(); 89 return RespondLater();
89 } 90 }
90 91
91 void EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey( 92 void EnterprisePlatformKeysInternalGenerateKeyFunction::OnGeneratedKey(
92 const std::string& public_key_der, 93 const std::string& public_key_der,
93 const std::string& error_message) { 94 const std::string& error_message) {
94 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 95 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
95 if (error_message.empty()) { 96 if (error_message.empty()) {
96 Respond( 97 Respond(ArgumentList(api_epki::GenerateKey::Results::Create(
97 ArgumentList(api_epki::GenerateKey::Results::Create(public_key_der))); 98 std::vector<char>(public_key_der.begin(), public_key_der.end()))));
98 } else { 99 } else {
99 Respond(Error(error_message)); 100 Respond(Error(error_message));
100 } 101 }
101 } 102 }
102 103
103 EnterprisePlatformKeysInternalSignFunction:: 104 EnterprisePlatformKeysInternalSignFunction::
104 ~EnterprisePlatformKeysInternalSignFunction() { 105 ~EnterprisePlatformKeysInternalSignFunction() {
105 } 106 }
106 107
107 ExtensionFunction::ResponseAction 108 ExtensionFunction::ResponseAction
(...skipping 17 matching lines...) Expand all
125 else 126 else
126 return RespondNow(Error(kErrorAlgorithmNotSupported)); 127 return RespondNow(Error(kErrorAlgorithmNotSupported));
127 128
128 chromeos::PlatformKeysService* service = 129 chromeos::PlatformKeysService* service =
129 chromeos::PlatformKeysServiceFactory::GetForBrowserContext( 130 chromeos::PlatformKeysServiceFactory::GetForBrowserContext(
130 browser_context()); 131 browser_context());
131 DCHECK(service); 132 DCHECK(service);
132 133
133 service->Sign( 134 service->Sign(
134 platform_keys_token_id, 135 platform_keys_token_id,
135 params->public_key, 136 std::string(params->public_key.begin(), params->public_key.end()),
136 hash_algorithm, 137 hash_algorithm, std::string(params->data.begin(), params->data.end()),
137 params->data,
138 extension_id(), 138 extension_id(),
139 base::Bind(&EnterprisePlatformKeysInternalSignFunction::OnSigned, this)); 139 base::Bind(&EnterprisePlatformKeysInternalSignFunction::OnSigned, this));
140 return RespondLater(); 140 return RespondLater();
141 } 141 }
142 142
143 void EnterprisePlatformKeysInternalSignFunction::OnSigned( 143 void EnterprisePlatformKeysInternalSignFunction::OnSigned(
144 const std::string& signature, 144 const std::string& signature,
145 const std::string& error_message) { 145 const std::string& error_message) {
146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 146 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
147 if (error_message.empty()) 147 if (error_message.empty()) {
148 Respond(ArgumentList(api_epki::Sign::Results::Create(signature))); 148 Respond(ArgumentList(api_epki::Sign::Results::Create(
149 else 149 std::vector<char>(signature.begin(), signature.end()))));
150 } else {
150 Respond(Error(error_message)); 151 Respond(Error(error_message));
152 }
151 } 153 }
152 154
153 EnterprisePlatformKeysGetCertificatesFunction:: 155 EnterprisePlatformKeysGetCertificatesFunction::
154 ~EnterprisePlatformKeysGetCertificatesFunction() { 156 ~EnterprisePlatformKeysGetCertificatesFunction() {
155 } 157 }
156 158
157 ExtensionFunction::ResponseAction 159 ExtensionFunction::ResponseAction
158 EnterprisePlatformKeysGetCertificatesFunction::Run() { 160 EnterprisePlatformKeysGetCertificatesFunction::Run() {
159 scoped_ptr<api_epk::GetCertificates::Params> params( 161 scoped_ptr<api_epk::GetCertificates::Params> params(
160 api_epk::GetCertificates::Params::Create(*args_)); 162 api_epk::GetCertificates::Params::Create(*args_));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 204
203 ExtensionFunction::ResponseAction 205 ExtensionFunction::ResponseAction
204 EnterprisePlatformKeysImportCertificateFunction::Run() { 206 EnterprisePlatformKeysImportCertificateFunction::Run() {
205 scoped_ptr<api_epk::ImportCertificate::Params> params( 207 scoped_ptr<api_epk::ImportCertificate::Params> params(
206 api_epk::ImportCertificate::Params::Create(*args_)); 208 api_epk::ImportCertificate::Params::Create(*args_));
207 EXTENSION_FUNCTION_VALIDATE(params); 209 EXTENSION_FUNCTION_VALIDATE(params);
208 std::string platform_keys_token_id; 210 std::string platform_keys_token_id;
209 if (!ValidateToken(params->token_id, &platform_keys_token_id)) 211 if (!ValidateToken(params->token_id, &platform_keys_token_id))
210 return RespondNow(Error(kErrorInvalidToken)); 212 return RespondNow(Error(kErrorInvalidToken));
211 213
212 const std::string& cert_der = params->certificate; 214 const std::vector<char>& cert_der = params->certificate;
213 scoped_refptr<net::X509Certificate> cert_x509 = 215 scoped_refptr<net::X509Certificate> cert_x509 =
214 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); 216 net::X509Certificate::CreateFromBytes(vector_as_array(&cert_der),
217 cert_der.size());
215 if (!cert_x509.get()) 218 if (!cert_x509.get())
216 return RespondNow(Error(kErrorInvalidX509Cert)); 219 return RespondNow(Error(kErrorInvalidX509Cert));
217 220
218 chromeos::platform_keys::ImportCertificate( 221 chromeos::platform_keys::ImportCertificate(
219 platform_keys_token_id, 222 platform_keys_token_id,
220 cert_x509, 223 cert_x509,
221 base::Bind(&EnterprisePlatformKeysImportCertificateFunction:: 224 base::Bind(&EnterprisePlatformKeysImportCertificateFunction::
222 OnImportedCertificate, 225 OnImportedCertificate,
223 this), 226 this),
224 browser_context()); 227 browser_context());
(...skipping 15 matching lines...) Expand all
240 243
241 ExtensionFunction::ResponseAction 244 ExtensionFunction::ResponseAction
242 EnterprisePlatformKeysRemoveCertificateFunction::Run() { 245 EnterprisePlatformKeysRemoveCertificateFunction::Run() {
243 scoped_ptr<api_epk::RemoveCertificate::Params> params( 246 scoped_ptr<api_epk::RemoveCertificate::Params> params(
244 api_epk::RemoveCertificate::Params::Create(*args_)); 247 api_epk::RemoveCertificate::Params::Create(*args_));
245 EXTENSION_FUNCTION_VALIDATE(params); 248 EXTENSION_FUNCTION_VALIDATE(params);
246 std::string platform_keys_token_id; 249 std::string platform_keys_token_id;
247 if (!ValidateToken(params->token_id, &platform_keys_token_id)) 250 if (!ValidateToken(params->token_id, &platform_keys_token_id))
248 return RespondNow(Error(kErrorInvalidToken)); 251 return RespondNow(Error(kErrorInvalidToken));
249 252
250 const std::string& cert_der = params->certificate; 253 const std::vector<char>& cert_der = params->certificate;
251 scoped_refptr<net::X509Certificate> cert_x509 = 254 scoped_refptr<net::X509Certificate> cert_x509 =
252 net::X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); 255 net::X509Certificate::CreateFromBytes(vector_as_array(&cert_der),
256 cert_der.size());
253 if (!cert_x509.get()) 257 if (!cert_x509.get())
254 return RespondNow(Error(kErrorInvalidX509Cert)); 258 return RespondNow(Error(kErrorInvalidX509Cert));
255 259
256 chromeos::platform_keys::RemoveCertificate( 260 chromeos::platform_keys::RemoveCertificate(
257 platform_keys_token_id, 261 platform_keys_token_id,
258 cert_x509, 262 cert_x509,
259 base::Bind(&EnterprisePlatformKeysRemoveCertificateFunction:: 263 base::Bind(&EnterprisePlatformKeysRemoveCertificateFunction::
260 OnRemovedCertificate, 264 OnRemovedCertificate,
261 this), 265 this),
262 browser_context()); 266 browser_context());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 Respond(Error(kErrorInternal)); 310 Respond(Error(kErrorInternal));
307 return; 311 return;
308 } 312 }
309 token_ids.push_back(token_id); 313 token_ids.push_back(token_id);
310 } 314 }
311 315
312 Respond(ArgumentList(api_epki::GetTokens::Results::Create(token_ids))); 316 Respond(ArgumentList(api_epki::GetTokens::Results::Create(token_ids)));
313 } 317 }
314 318
315 } // namespace extensions 319 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698