Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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( | |
|
emaxx
2016/09/06 15:02:11
nit: Put this function into an anonymous namespace
igorcov
2016/09/09 15:53:42
Done.
| |
| 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 } | |
| 168 } | |
| 169 | |
| 170 CertificateProviderStopPinRequestFunction:: | |
|
emaxx
2016/09/06 15:02:11
nit: Please reorder the method definitions so that
igorcov
2016/09/09 15:53:43
Done.
| |
| 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 : | |
| 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 int attempts_left = params->details.attempts_left ? | |
| 271 *params->details.attempts_left.get() : -1; | |
| 272 chromeos::RequestPinResponse result = | |
| 273 service->pin_dialog_manager()->ShowPinDialog( | |
| 274 extension()->id(), | |
| 275 extension()->name(), | |
| 276 params->details.sign_request_id, | |
| 277 code_type, | |
| 278 error_type, | |
| 279 attempts_left, | |
| 280 base::Bind(&CertificateProviderRequestPinFunction::OnInputReceived, | |
| 281 this)); | |
| 282 switch (result) { | |
| 283 case chromeos::RequestPinResponse::SUCCESS: | |
| 284 return RespondLater(); | |
| 285 case chromeos::RequestPinResponse::INVALID_ID: | |
| 286 return RespondNow(Error("Invalid signRequestId")); | |
| 287 case chromeos::RequestPinResponse::OTHER_FLOW_IN_PROGRESS: | |
| 288 return RespondNow(Error("Other flow in progress")); | |
| 289 case chromeos::RequestPinResponse::DIALOG_DISPLAYED_ALREADY: | |
| 290 return RespondNow(Error("Previous request not finished")); | |
| 291 } | |
| 292 } | |
| 293 | |
| 294 void CertificateProviderRequestPinFunction::OnInputReceived( | |
| 295 const base::string16& value) { | |
| 296 std::unique_ptr<base::ListValue> create_results(new base::ListValue()); | |
| 297 chromeos::CertificateProviderService* const service = | |
| 298 chromeos::CertificateProviderServiceFactory::GetForBrowserContext( | |
| 299 browser_context()); | |
| 300 DCHECK(service); | |
| 301 if (!value.empty()) { | |
| 302 api::certificate_provider::PinResponseDetails details; | |
| 303 details.user_input.reset(new std::string(value.begin(), value.end())); | |
| 304 create_results->Append(details.ToValue()); | |
| 305 } | |
| 306 | |
| 307 Respond(ArgumentList(std::move(create_results))); | |
| 308 service->pin_dialog_manager()-> | |
| 309 OnPinDialogInput(extension_id(), value.empty()); | |
| 310 } | |
| 311 | |
| 151 CertificateProviderInternalReportSignatureFunction:: | 312 CertificateProviderInternalReportSignatureFunction:: |
| 152 ~CertificateProviderInternalReportSignatureFunction() {} | 313 ~CertificateProviderInternalReportSignatureFunction() {} |
| 153 | 314 |
| 154 ExtensionFunction::ResponseAction | 315 ExtensionFunction::ResponseAction |
| 155 CertificateProviderInternalReportSignatureFunction::Run() { | 316 CertificateProviderInternalReportSignatureFunction::Run() { |
| 156 std::unique_ptr<api_cpi::ReportSignature::Params> params( | 317 std::unique_ptr<api_cpi::ReportSignature::Params> params( |
| 157 api_cpi::ReportSignature::Params::Create(*args_)); | 318 api_cpi::ReportSignature::Params::Create(*args_)); |
| 158 EXTENSION_FUNCTION_VALIDATE(params); | 319 EXTENSION_FUNCTION_VALIDATE(params); |
| 159 | 320 |
| 160 chromeos::CertificateProviderService* const service = | 321 chromeos::CertificateProviderService* const service = |
| 161 chromeos::CertificateProviderServiceFactory::GetForBrowserContext( | 322 chromeos::CertificateProviderServiceFactory::GetForBrowserContext( |
| 162 browser_context()); | 323 browser_context()); |
| 163 DCHECK(service); | 324 DCHECK(service); |
| 164 | 325 |
| 165 std::vector<uint8_t> signature; | 326 std::vector<uint8_t> signature; |
| 166 // If an error occurred, |signature| will not be set. | 327 // If an error occurred, |signature| will not be set. |
| 167 if (params->signature) | 328 if (params->signature) |
| 168 signature.assign(params->signature->begin(), params->signature->end()); | 329 signature.assign(params->signature->begin(), params->signature->end()); |
| 169 | 330 |
| 170 service->ReplyToSignRequest(extension_id(), params->request_id, signature); | 331 service->ReplyToSignRequest(extension_id(), params->request_id, signature); |
| 171 return RespondNow(NoArguments()); | 332 return RespondNow(NoArguments()); |
| 172 } | 333 } |
| 173 | 334 |
| 174 } // namespace extensions | 335 } // namespace extensions |
| OLD | NEW |