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

Side by Side Diff: chrome/browser/extensions/api/certificate_provider/certificate_provider_api.cc

Issue 2094333002: Implementation for chrome.certificateProvider.requestPin/stopPinRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Externalized back the constant Created 4 years, 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/certificate_provider/certificate_provide r_api.h" 5 #include "chrome/browser/extensions/api/certificate_provider/certificate_provide r_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 17 matching lines...) Expand all
28 28
29 const char kErrorInvalidX509Cert[] = 29 const char kErrorInvalidX509Cert[] =
30 "Certificate is not a valid X.509 certificate."; 30 "Certificate is not a valid X.509 certificate.";
31 const char kErrorECDSANotSupported[] = "Key type ECDSA not supported."; 31 const char kErrorECDSANotSupported[] = "Key type ECDSA not supported.";
32 const char kErrorUnknownKeyType[] = "Key type unknown."; 32 const char kErrorUnknownKeyType[] = "Key type unknown.";
33 const char kErrorAborted[] = "Request was aborted."; 33 const char kErrorAborted[] = "Request was aborted.";
34 const char kErrorTimeout[] = "Request timed out, reply rejected."; 34 const char kErrorTimeout[] = "Request timed out, reply rejected.";
35 35
36 } // namespace 36 } // namespace
37 37
38 const int MAX_CLOSED_DIALOGS_PER_10_MINUTES = 2;
39
38 CertificateProviderInternalReportCertificatesFunction:: 40 CertificateProviderInternalReportCertificatesFunction::
39 ~CertificateProviderInternalReportCertificatesFunction() {} 41 ~CertificateProviderInternalReportCertificatesFunction() {}
40 42
41 ExtensionFunction::ResponseAction 43 ExtensionFunction::ResponseAction
42 CertificateProviderInternalReportCertificatesFunction::Run() { 44 CertificateProviderInternalReportCertificatesFunction::Run() {
43 std::unique_ptr<api_cpi::ReportCertificates::Params> params( 45 std::unique_ptr<api_cpi::ReportCertificates::Params> params(
44 api_cpi::ReportCertificates::Params::Create(*args_)); 46 api_cpi::ReportCertificates::Params::Create(*args_));
45 EXTENSION_FUNCTION_VALIDATE(params); 47 EXTENSION_FUNCTION_VALIDATE(params);
46 48
47 chromeos::CertificateProviderService* const service = 49 chromeos::CertificateProviderService* const service =
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 out_info->supported_hashes.push_back(net::SSLPrivateKey::Hash::SHA512); 143 out_info->supported_hashes.push_back(net::SSLPrivateKey::Hash::SHA512);
142 break; 144 break;
143 case api_cp::HASH_NONE: 145 case api_cp::HASH_NONE:
144 NOTREACHED(); 146 NOTREACHED();
145 return false; 147 return false;
146 } 148 }
147 } 149 }
148 return true; 150 return true;
149 } 151 }
150 152
153 chromeos::RequestPinErrorType GetErrorTypeForView(
154 api_cp::PinRequestErrorType error_type) {
155 switch (error_type) {
156 case api_cp::PinRequestErrorType::PIN_REQUEST_ERROR_TYPE_INVALID_PIN:
157 return chromeos::RequestPinErrorType::INVALID_PIN;
158 case api_cp::PinRequestErrorType::PIN_REQUEST_ERROR_TYPE_INVALID_PUK:
159 return chromeos::RequestPinErrorType::INVALID_PUK;
160 case
161 api_cp::PinRequestErrorType::PIN_REQUEST_ERROR_TYPE_MAX_ATTEMPTS_EXCEEDED:
162 return chromeos::RequestPinErrorType::MAX_ATTEMPTS_EXCEEDED;
163 case api_cp::PinRequestErrorType::PIN_REQUEST_ERROR_TYPE_UNKNOWN_ERROR:
164 return chromeos::RequestPinErrorType::UNKNOWN_ERROR;
165 case api_cp::PinRequestErrorType::PIN_REQUEST_ERROR_TYPE_NONE:
166 return chromeos::RequestPinErrorType::NONE;
167 }
stevenjb 2016/08/11 18:12:02 NOTREACHED(); return chromeos::RequestPinErrorType
igorcov 2016/09/06 13:22:02 It compiles because all the possible values from e
168 }
169
170 CertificateProviderStopPinRequestFunction::
171 ~CertificateProviderStopPinRequestFunction() {}
172
173 ExtensionFunction::ResponseAction
174 CertificateProviderStopPinRequestFunction::Run() {
175 std::unique_ptr<api_cp::RequestPin::Params> params(
176 api_cp::RequestPin::Params::Create(*args_));
177 EXTENSION_FUNCTION_VALIDATE(params.get());
178
179 chromeos::CertificateProviderService* const service =
180 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
181 browser_context());
182 DCHECK(service);
183 if (params->details.error_type ==
184 api_cp::PinRequestErrorType::PIN_REQUEST_ERROR_TYPE_NONE) {
185 bool dialog_closed =
186 service->pin_dialog_manager()->CloseDialog(extension_id());
187 if (!dialog_closed) {
188 // This might happen if the user closed the dialog while extension was
189 // processing the input.
190 LOG(ERROR) << "Wrong extension requesting to close the dialog";
191 return RespondNow(Error("No active dialog from extension."));
192 }
193
194 std::unique_ptr<base::ListValue> create_results(new base::ListValue());
195 return RespondNow(ArgumentList(std::move(create_results)));
196 }
197
198 chromeos::RequestPinErrorType error_type = GetErrorTypeForView(
199 params->details.error_type);
200 bool success = service->pin_dialog_manager()->UpdatePinDialog(
201 extension()->id(),
202 error_type,
203 false, // Don't accept any input.
204 base::Bind(&CertificateProviderStopPinRequestFunction::DialogClosed,
205 this));
206 if (!success) {
207 return RespondNow(Error("No active dialog from extension."));
208 }
209
210 return RespondLater();
211 }
212
213 void CertificateProviderStopPinRequestFunction::DialogClosed(
214 const base::string16& value) {
215 std::unique_ptr<base::ListValue> create_results(new base::ListValue());
216 chromeos::CertificateProviderService* const service =
217 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
218 browser_context());
219 DCHECK(service);
220
221 Respond(ArgumentList(std::move(create_results)));
222 service->pin_dialog_manager()->OnPinDialogInput(extension_id(), true);
223 }
224
225 CertificateProviderRequestPinFunction::
226 ~CertificateProviderRequestPinFunction() {}
227
228 bool CertificateProviderRequestPinFunction::ShouldSkipQuotaLimiting() const {
229 chromeos::CertificateProviderService* const service =
230 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
231 browser_context());
232 DCHECK(service);
233
234 return !service->pin_dialog_manager()->LastPinDialogClosed(extension_id());
235 }
236
237 void CertificateProviderRequestPinFunction::GetQuotaLimitHeuristics(
238 extensions::QuotaLimitHeuristics* heuristics) const {
239 QuotaLimitHeuristic::Config short_limit_config = {
240 extensions::MAX_CLOSED_DIALOGS_PER_10_MINUTES,
241 base::TimeDelta::FromMinutes(1)};
242 heuristics->push_back(new QuotaService::TimedLimit(
243 short_limit_config, new QuotaLimitHeuristic::SingletonBucketMapper(),
244 "MAX_SHOW_DIALOGS_PER_MINUTE"));
245 }
246
247 ExtensionFunction::ResponseAction
248 CertificateProviderRequestPinFunction::Run() {
249 std::unique_ptr<api_cp::RequestPin::Params> params(
250 api_cp::RequestPin::Params::Create(*args_));
251 EXTENSION_FUNCTION_VALIDATE(params.get());
252
253 api_cp::PinRequestType pin_request_type =
254 (params->details.request_type) ?
255 params->details.request_type :
stevenjb 2016/08/11 18:12:02 Shouldn't this be *params->details.request_type ??
igorcov 2016/09/06 13:22:02 params is a unique_ptr and request_type from IDL i
256 api_cp::PinRequestType::PIN_REQUEST_TYPE_PIN;
257
258 chromeos::RequestPinErrorType error_type = GetErrorTypeForView(
259 params->details.error_type);
260
261 chromeos::RequestPinCodeType code_type =
262 (pin_request_type == api_cp::PinRequestType::PIN_REQUEST_TYPE_PIN) ?
263 chromeos::RequestPinCodeType::PIN : chromeos::RequestPinCodeType::PUK;
264
265 chromeos::CertificateProviderService* const service =
266 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
267 browser_context());
268 DCHECK(service);
269
270 chromeos::RequestPinResponse result =
271 service->pin_dialog_manager()->ShowPinDialog(
272 extension()->id(),
273 extension()->name(),
274 params->details.sign_request_id,
275 code_type,
276 error_type,
277 std::move(params->details.attempts_left),
278 base::Bind(&CertificateProviderRequestPinFunction::OnInputReceived,
279 this));
280 switch (result) {
281 case chromeos::RequestPinResponse::SUCCESS:
282 return RespondLater();
283 case chromeos::RequestPinResponse::INVALID_ID:
284 return RespondNow(Error("Invalid signRequestId"));
285 case chromeos::RequestPinResponse::OTHER_FLOW_IN_PROGRESS:
286 return RespondNow(Error("Other flow in progress"));
287 case chromeos::RequestPinResponse::DIALOG_DISPLAYED_ALREADY:
288 return RespondNow(Error("Previous request not finished"));
289 }
290 }
291
292 void CertificateProviderRequestPinFunction::OnInputReceived(
293 const base::string16& value) {
294 std::unique_ptr<base::ListValue> create_results(new base::ListValue());
295 chromeos::CertificateProviderService* const service =
296 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
297 browser_context());
298 DCHECK(service);
299 if (!value.empty()) {
300 api::certificate_provider::PinResponseDetails details;
301 details.user_input.reset(new std::string(value.begin(), value.end()));
302 create_results->Append(details.ToValue());
303 }
304
305 Respond(ArgumentList(std::move(create_results)));
306 service->pin_dialog_manager()->
307 OnPinDialogInput(extension_id(), value.empty());
308 }
309
151 CertificateProviderInternalReportSignatureFunction:: 310 CertificateProviderInternalReportSignatureFunction::
152 ~CertificateProviderInternalReportSignatureFunction() {} 311 ~CertificateProviderInternalReportSignatureFunction() {}
153 312
154 ExtensionFunction::ResponseAction 313 ExtensionFunction::ResponseAction
155 CertificateProviderInternalReportSignatureFunction::Run() { 314 CertificateProviderInternalReportSignatureFunction::Run() {
156 std::unique_ptr<api_cpi::ReportSignature::Params> params( 315 std::unique_ptr<api_cpi::ReportSignature::Params> params(
157 api_cpi::ReportSignature::Params::Create(*args_)); 316 api_cpi::ReportSignature::Params::Create(*args_));
158 EXTENSION_FUNCTION_VALIDATE(params); 317 EXTENSION_FUNCTION_VALIDATE(params);
159 318
160 chromeos::CertificateProviderService* const service = 319 chromeos::CertificateProviderService* const service =
161 chromeos::CertificateProviderServiceFactory::GetForBrowserContext( 320 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
162 browser_context()); 321 browser_context());
163 DCHECK(service); 322 DCHECK(service);
164 323
165 std::vector<uint8_t> signature; 324 std::vector<uint8_t> signature;
166 // If an error occurred, |signature| will not be set. 325 // If an error occurred, |signature| will not be set.
167 if (params->signature) 326 if (params->signature)
168 signature.assign(params->signature->begin(), params->signature->end()); 327 signature.assign(params->signature->begin(), params->signature->end());
169 328
170 service->ReplyToSignRequest(extension_id(), params->request_id, signature); 329 service->ReplyToSignRequest(extension_id(), params->request_id, signature);
171 return RespondNow(NoArguments()); 330 return RespondNow(NoArguments());
172 } 331 }
173 332
174 } // namespace extensions 333 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698