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

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: Small fix Created 4 years, 5 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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv ice.h" 15 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv ice.h"
15 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv ice_factory.h" 16 #include "chrome/browser/chromeos/certificate_provider/certificate_provider_serv ice_factory.h"
16 #include "chrome/common/extensions/api/certificate_provider.h" 17 #include "chrome/common/extensions/api/certificate_provider.h"
17 #include "chrome/common/extensions/api/certificate_provider_internal.h" 18 #include "chrome/common/extensions/api/certificate_provider_internal.h"
18 #include "content/public/common/console_message_level.h" 19 #include "content/public/common/console_message_level.h"
19 #include "net/cert/x509_certificate.h" 20 #include "net/cert/x509_certificate.h"
20 #include "net/ssl/ssl_private_key.h" 21 #include "net/ssl/ssl_private_key.h"
21 22
22 namespace extensions { 23 namespace extensions {
23 24
24 namespace api_cp = api::certificate_provider; 25 namespace api_cp = api::certificate_provider;
25 namespace api_cpi = api::certificate_provider_internal; 26 namespace api_cpi = api::certificate_provider_internal;
26 27
27 namespace { 28 namespace {
28 29
29 const char kErrorInvalidX509Cert[] = 30 const char kErrorInvalidX509Cert[] =
30 "Certificate is not a valid X.509 certificate."; 31 "Certificate is not a valid X.509 certificate.";
31 const char kErrorECDSANotSupported[] = "Key type ECDSA not supported."; 32 const char kErrorECDSANotSupported[] = "Key type ECDSA not supported.";
32 const char kErrorUnknownKeyType[] = "Key type unknown."; 33 const char kErrorUnknownKeyType[] = "Key type unknown.";
33 const char kErrorAborted[] = "Request was aborted."; 34 const char kErrorAborted[] = "Request was aborted.";
34 const char kErrorTimeout[] = "Request timed out, reply rejected."; 35 const char kErrorTimeout[] = "Request timed out, reply rejected.";
35 36
36 } // namespace 37 } // namespace
37 38
39 const int MAX_CLOSED_DIALOGS_PER_10_MINUTES = 2;
40
38 CertificateProviderInternalReportCertificatesFunction:: 41 CertificateProviderInternalReportCertificatesFunction::
39 ~CertificateProviderInternalReportCertificatesFunction() {} 42 ~CertificateProviderInternalReportCertificatesFunction() {}
40 43
41 ExtensionFunction::ResponseAction 44 ExtensionFunction::ResponseAction
42 CertificateProviderInternalReportCertificatesFunction::Run() { 45 CertificateProviderInternalReportCertificatesFunction::Run() {
43 std::unique_ptr<api_cpi::ReportCertificates::Params> params( 46 std::unique_ptr<api_cpi::ReportCertificates::Params> params(
44 api_cpi::ReportCertificates::Params::Create(*args_)); 47 api_cpi::ReportCertificates::Params::Create(*args_));
45 EXTENSION_FUNCTION_VALIDATE(params); 48 EXTENSION_FUNCTION_VALIDATE(params);
46 49
47 chromeos::CertificateProviderService* const service = 50 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); 144 out_info->supported_hashes.push_back(net::SSLPrivateKey::Hash::SHA512);
142 break; 145 break;
143 case api_cp::HASH_NONE: 146 case api_cp::HASH_NONE:
144 NOTREACHED(); 147 NOTREACHED();
145 return false; 148 return false;
146 } 149 }
147 } 150 }
148 return true; 151 return true;
149 } 152 }
150 153
154 CertificateProviderClosePinDialogFunction::
155 ~CertificateProviderClosePinDialogFunction() {}
156
157 ExtensionFunction::ResponseAction
158 CertificateProviderClosePinDialogFunction::Run() {
159 chromeos::CertificateProviderService* const service =
160 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
161 browser_context());
162 DCHECK(service);
163 bool dialog_closed = service->CloseDialog(extension_id());
164 if (!dialog_closed) {
165 // This might happen if the user closed the dialog while extension was
166 // processing the input.
167 LOG(ERROR) << "Wrong extension requesting to close the dialog";
168 return RespondNow(Error("The extension doesn't own the active dialog"));
169 }
170
171 std::unique_ptr<base::ListValue> create_results(new base::ListValue());
172
173 return RespondNow(ArgumentList(std::move(create_results)));
174 }
175
176 CertificateProviderShowPinDialogFunction::
177 ~CertificateProviderShowPinDialogFunction() {}
178
179 bool CertificateProviderShowPinDialogFunction::ShouldSkipQuotaLimiting() const {
180 chromeos::CertificateProviderService* const service =
181 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
182 browser_context());
183 DCHECK(service);
184
185 return !service->LastPinDialogClosed(extension_id());
186 }
187
188 void CertificateProviderShowPinDialogFunction::GetQuotaLimitHeuristics(
189 extensions::QuotaLimitHeuristics* heuristics) const {
190 QuotaLimitHeuristic::Config short_limit_config = {
191 extensions::MAX_CLOSED_DIALOGS_PER_10_MINUTES,
192 base::TimeDelta::FromMinutes(1)};
193 heuristics->push_back(new QuotaService::TimedLimit(
194 short_limit_config, new QuotaLimitHeuristic::SingletonBucketMapper(),
195 "MAX_SHOW_DIALOGS_PER_MINUTE"));
196 }
197
198 ExtensionFunction::ResponseAction
199 CertificateProviderShowPinDialogFunction::Run() {
200 std::unique_ptr<api_cp::ShowPinDialog::Params> params(
201 api_cp::ShowPinDialog::Params::Create(*args_));
202 EXTENSION_FUNCTION_VALIDATE(params.get());
203
204 api_cp::PinDialogType pin_dialog_type =
205 (params->details && params->details->type) ?
206 params->details->type :
207 api_cp::PinDialogType::PIN_DIALOG_TYPE_PIN;
208
209 base::string16 error_message;
210 if (params->details && params->details->error_message) {
211 std::basic_string<char>* err_msg = params->details->error_message.get();
212 error_message = base::ASCIIToUTF16(err_msg->c_str());
213 }
214
215 bool accept_input = true;
216 if (params->details && params->details->accept_input) {
217 accept_input = *(params->details->accept_input.get());
218 }
219
220 const std::string dialog_type =
221 (pin_dialog_type == api_cp::PinDialogType::PIN_DIALOG_TYPE_PIN) ?
222 "PIN: " : "PUK: ";
223
224 chromeos::CertificateProviderService* const service =
225 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
226 browser_context());
227 DCHECK(service);
228
229 bool success = service->ShowPinDialog(
230 extension()->id(),
231 extension()->name(),
232 dialog_type,
233 error_message,
234 accept_input,
235 base::Bind(&CertificateProviderShowPinDialogFunction::OnInputReceived,
236 this));
237 if (!success) {
238 return RespondNow(Error("Other flow in progress"));
239 }
240
241 return RespondLater();
242 }
243
244 void CertificateProviderShowPinDialogFunction::OnInputReceived(
245 const base::string16& value) {
246 std::unique_ptr<base::ListValue> create_results(new base::ListValue());
247 chromeos::CertificateProviderService* const service =
248 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
249 browser_context());
250 DCHECK(service);
251 if (!value.empty()) {
252 api::certificate_provider::PinResponseDetails details;
253 details.user_input.reset(new std::string(value.begin(), value.end()));
254 create_results->Append(details.ToValue());
255 }
256
257 Respond(ArgumentList(std::move(create_results)));
258 service->OnPinDialogInput(extension_id(), value.empty());
259 }
260
151 CertificateProviderInternalReportSignatureFunction:: 261 CertificateProviderInternalReportSignatureFunction::
152 ~CertificateProviderInternalReportSignatureFunction() {} 262 ~CertificateProviderInternalReportSignatureFunction() {}
153 263
154 ExtensionFunction::ResponseAction 264 ExtensionFunction::ResponseAction
155 CertificateProviderInternalReportSignatureFunction::Run() { 265 CertificateProviderInternalReportSignatureFunction::Run() {
156 std::unique_ptr<api_cpi::ReportSignature::Params> params( 266 std::unique_ptr<api_cpi::ReportSignature::Params> params(
157 api_cpi::ReportSignature::Params::Create(*args_)); 267 api_cpi::ReportSignature::Params::Create(*args_));
158 EXTENSION_FUNCTION_VALIDATE(params); 268 EXTENSION_FUNCTION_VALIDATE(params);
159 269
160 chromeos::CertificateProviderService* const service = 270 chromeos::CertificateProviderService* const service =
161 chromeos::CertificateProviderServiceFactory::GetForBrowserContext( 271 chromeos::CertificateProviderServiceFactory::GetForBrowserContext(
162 browser_context()); 272 browser_context());
163 DCHECK(service); 273 DCHECK(service);
164 274
165 std::vector<uint8_t> signature; 275 std::vector<uint8_t> signature;
166 // If an error occurred, |signature| will not be set. 276 // If an error occurred, |signature| will not be set.
167 if (params->signature) 277 if (params->signature)
168 signature.assign(params->signature->begin(), params->signature->end()); 278 signature.assign(params->signature->begin(), params->signature->end());
169 279
170 service->ReplyToSignRequest(extension_id(), params->request_id, signature); 280 service->ReplyToSignRequest(extension_id(), params->request_id, signature);
171 return RespondNow(NoArguments()); 281 return RespondNow(NoArguments());
172 } 282 }
173 283
174 } // namespace extensions 284 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698