OLD | NEW |
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/easy_unlock_private/easy_unlock_private_
api.h" | 5 #include "chrome/browser/extensions/api/easy_unlock_private/easy_unlock_private_
api.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 | 256 |
257 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: | 257 EasyUnlockPrivatePerformECDHKeyAgreementFunction:: |
258 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} | 258 ~EasyUnlockPrivatePerformECDHKeyAgreementFunction() {} |
259 | 259 |
260 bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { | 260 bool EasyUnlockPrivatePerformECDHKeyAgreementFunction::RunAsync() { |
261 scoped_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = | 261 scoped_ptr<easy_unlock_private::PerformECDHKeyAgreement::Params> params = |
262 easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_); | 262 easy_unlock_private::PerformECDHKeyAgreement::Params::Create(*args_); |
263 EXTENSION_FUNCTION_VALIDATE(params); | 263 EXTENSION_FUNCTION_VALIDATE(params); |
264 | 264 |
265 GetCryptoDelegate(browser_context())->PerformECDHKeyAgreement( | 265 GetCryptoDelegate(browser_context())->PerformECDHKeyAgreement( |
266 params->private_key, | 266 *params, |
267 params->public_key, | |
268 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, | 267 base::Bind(&EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData, |
269 this)); | 268 this)); |
270 return true; | 269 return true; |
271 } | 270 } |
272 | 271 |
273 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( | 272 void EasyUnlockPrivatePerformECDHKeyAgreementFunction::OnData( |
274 const std::string& secret_key) { | 273 const std::string& secret_key) { |
275 // TODO(tbarzic): Improve error handling. | 274 // TODO(tbarzic): Improve error handling. |
276 if (!secret_key.empty()) { | 275 if (!secret_key.empty()) { |
277 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( | 276 results_ = easy_unlock_private::PerformECDHKeyAgreement::Results::Create( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 308 |
310 EasyUnlockPrivateCreateSecureMessageFunction:: | 309 EasyUnlockPrivateCreateSecureMessageFunction:: |
311 ~EasyUnlockPrivateCreateSecureMessageFunction() {} | 310 ~EasyUnlockPrivateCreateSecureMessageFunction() {} |
312 | 311 |
313 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { | 312 bool EasyUnlockPrivateCreateSecureMessageFunction::RunAsync() { |
314 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = | 313 scoped_ptr<easy_unlock_private::CreateSecureMessage::Params> params = |
315 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); | 314 easy_unlock_private::CreateSecureMessage::Params::Create(*args_); |
316 EXTENSION_FUNCTION_VALIDATE(params); | 315 EXTENSION_FUNCTION_VALIDATE(params); |
317 | 316 |
318 GetCryptoDelegate(browser_context())->CreateSecureMessage( | 317 GetCryptoDelegate(browser_context())->CreateSecureMessage( |
319 params->payload, | 318 *params, |
320 params->key, | |
321 params->options.associated_data ? | |
322 *params->options.associated_data : std::string(), | |
323 params->options.public_metadata ? | |
324 *params->options.public_metadata : std::string(), | |
325 params->options.verification_key_id ? | |
326 *params->options.verification_key_id : std::string(), | |
327 params->options.decryption_key_id ? | |
328 *params->options.decryption_key_id : std::string(), | |
329 params->options.encrypt_type, | |
330 params->options.sign_type, | |
331 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, | 319 base::Bind(&EasyUnlockPrivateCreateSecureMessageFunction::OnData, |
332 this)); | 320 this)); |
333 return true; | 321 return true; |
334 } | 322 } |
335 | 323 |
336 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( | 324 void EasyUnlockPrivateCreateSecureMessageFunction::OnData( |
337 const std::string& message) { | 325 const std::string& message) { |
338 // TODO(tbarzic): Improve error handling. | 326 // TODO(tbarzic): Improve error handling. |
339 if (!message.empty()) { | 327 if (!message.empty()) { |
340 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( | 328 results_ = easy_unlock_private::CreateSecureMessage::Results::Create( |
341 message); | 329 message); |
342 } | 330 } |
343 SendResponse(true); | 331 SendResponse(true); |
344 } | 332 } |
345 | 333 |
346 EasyUnlockPrivateUnwrapSecureMessageFunction:: | 334 EasyUnlockPrivateUnwrapSecureMessageFunction:: |
347 EasyUnlockPrivateUnwrapSecureMessageFunction() {} | 335 EasyUnlockPrivateUnwrapSecureMessageFunction() {} |
348 | 336 |
349 EasyUnlockPrivateUnwrapSecureMessageFunction:: | 337 EasyUnlockPrivateUnwrapSecureMessageFunction:: |
350 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} | 338 ~EasyUnlockPrivateUnwrapSecureMessageFunction() {} |
351 | 339 |
352 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { | 340 bool EasyUnlockPrivateUnwrapSecureMessageFunction::RunAsync() { |
353 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = | 341 scoped_ptr<easy_unlock_private::UnwrapSecureMessage::Params> params = |
354 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); | 342 easy_unlock_private::UnwrapSecureMessage::Params::Create(*args_); |
355 EXTENSION_FUNCTION_VALIDATE(params); | 343 EXTENSION_FUNCTION_VALIDATE(params); |
356 | 344 |
357 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( | 345 GetCryptoDelegate(browser_context())->UnwrapSecureMessage( |
358 params->secure_message, | 346 *params, |
359 params->key, | |
360 params->options.associated_data ? | |
361 *params->options.associated_data : std::string(), | |
362 params->options.encrypt_type, | |
363 params->options.sign_type, | |
364 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, | 347 base::Bind(&EasyUnlockPrivateUnwrapSecureMessageFunction::OnData, |
365 this)); | 348 this)); |
366 return true; | 349 return true; |
367 } | 350 } |
368 | 351 |
369 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( | 352 void EasyUnlockPrivateUnwrapSecureMessageFunction::OnData( |
370 const std::string& data) { | 353 const std::string& data) { |
371 // TODO(tbarzic): Improve error handling. | 354 // TODO(tbarzic): Improve error handling. |
372 if (!data.empty()) | 355 if (!data.empty()) |
373 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); | 356 results_ = easy_unlock_private::UnwrapSecureMessage::Results::Create(data); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { | 524 bool EasyUnlockPrivateGetRemoteDevicesFunction::RunSync() { |
542 Profile* profile = Profile::FromBrowserContext(browser_context()); | 525 Profile* profile = Profile::FromBrowserContext(browser_context()); |
543 const base::ListValue* devices = | 526 const base::ListValue* devices = |
544 EasyUnlockService::Get(profile)->GetRemoteDevices(); | 527 EasyUnlockService::Get(profile)->GetRemoteDevices(); |
545 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); | 528 SetResult(devices ? devices->DeepCopy() : new base::ListValue()); |
546 return true; | 529 return true; |
547 } | 530 } |
548 | 531 |
549 } // namespace api | 532 } // namespace api |
550 } // namespace extensions | 533 } // namespace extensions |
OLD | NEW |