OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 AlgorithmError error; | 54 AlgorithmError error; |
55 bool success = NormalizeAlgorithm(raw, op, algorithm, &error); | 55 bool success = NormalizeAlgorithm(raw, op, algorithm, &error); |
56 if (!success) | 56 if (!success) |
57 result->CompleteWithError(error.error_type, error.error_details); | 57 result->CompleteWithError(error.error_type, error.error_details); |
58 return success; | 58 return success; |
59 } | 59 } |
60 | 60 |
61 static bool CanAccessWebCrypto(ScriptState* script_state, | 61 static bool CanAccessWebCrypto(ScriptState* script_state, |
62 CryptoResult* result) { | 62 CryptoResult* result) { |
63 String error_message; | 63 String error_message; |
64 if (!ExecutionContext::From(script_state) | 64 if (!script_state->GetExecutionContext()->IsSecureContext( |
65 ->IsSecureContext(error_message, | 65 error_message, ExecutionContext::kWebCryptoSecureContextCheck)) { |
66 ExecutionContext::kWebCryptoSecureContextCheck)) { | |
67 result->CompleteWithError(kWebCryptoErrorTypeNotSupported, error_message); | 66 result->CompleteWithError(kWebCryptoErrorTypeNotSupported, error_message); |
68 return false; | 67 return false; |
69 } | 68 } |
70 | 69 |
71 if (!ExecutionContext::From(script_state)->IsSecureContext()) { | 70 if (!script_state->GetExecutionContext()->IsSecureContext()) { |
72 Deprecation::CountDeprecation( | 71 Deprecation::CountDeprecation( |
73 ExecutionContext::From(script_state), | 72 script_state->GetExecutionContext(), |
74 UseCounter::kSubtleCryptoOnlyStrictSecureContextCheckFailed); | 73 UseCounter::kSubtleCryptoOnlyStrictSecureContextCheckFailed); |
75 } | 74 } |
76 | 75 |
77 return true; | 76 return true; |
78 } | 77 } |
79 | 78 |
80 static bool CopyStringProperty(const char* property, | 79 static bool CopyStringProperty(const char* property, |
81 const Dictionary& source, | 80 const Dictionary& source, |
82 JSONObject* destination) { | 81 JSONObject* destination) { |
83 String value; | 82 String value; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // 14.3.1.8: If the name member of normalizedAlgorithm is not equal to the | 206 // 14.3.1.8: If the name member of normalizedAlgorithm is not equal to the |
208 // name attribute of the [[algorithm]] internal slot of key then | 207 // name attribute of the [[algorithm]] internal slot of key then |
209 // throw an InvalidAccessError. | 208 // throw an InvalidAccessError. |
210 // | 209 // |
211 // 14.3.1.9: If the [[usages]] internal slot of key does not contain an | 210 // 14.3.1.9: If the [[usages]] internal slot of key does not contain an |
212 // entry that is "encrypt", then throw an InvalidAccessError. | 211 // entry that is "encrypt", then throw an InvalidAccessError. |
213 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, | 212 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, |
214 kWebCryptoKeyUsageEncrypt, result)) | 213 kWebCryptoKeyUsageEncrypt, result)) |
215 return promise; | 214 return promise; |
216 | 215 |
217 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 216 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
218 normalized_algorithm, key->Key()); | 217 normalized_algorithm, key->Key()); |
219 Platform::Current()->Crypto()->Encrypt(normalized_algorithm, key->Key(), | 218 Platform::Current()->Crypto()->Encrypt(normalized_algorithm, key->Key(), |
220 std::move(data), result->Result()); | 219 std::move(data), result->Result()); |
221 return promise; | 220 return promise; |
222 } | 221 } |
223 | 222 |
224 ScriptPromise SubtleCrypto::decrypt(ScriptState* script_state, | 223 ScriptPromise SubtleCrypto::decrypt(ScriptState* script_state, |
225 const AlgorithmIdentifier& raw_algorithm, | 224 const AlgorithmIdentifier& raw_algorithm, |
226 CryptoKey* key, | 225 CryptoKey* key, |
227 const BufferSource& raw_data) { | 226 const BufferSource& raw_data) { |
(...skipping 20 matching lines...) Expand all Loading... |
248 // 14.3.2.8: If the name member of normalizedAlgorithm is not equal to the | 247 // 14.3.2.8: If the name member of normalizedAlgorithm is not equal to the |
249 // name attribute of the [[algorithm]] internal slot of key then | 248 // name attribute of the [[algorithm]] internal slot of key then |
250 // throw an InvalidAccessError. | 249 // throw an InvalidAccessError. |
251 // | 250 // |
252 // 14.3.2.9: If the [[usages]] internal slot of key does not contain an | 251 // 14.3.2.9: If the [[usages]] internal slot of key does not contain an |
253 // entry that is "decrypt", then throw an InvalidAccessError. | 252 // entry that is "decrypt", then throw an InvalidAccessError. |
254 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, | 253 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, |
255 kWebCryptoKeyUsageDecrypt, result)) | 254 kWebCryptoKeyUsageDecrypt, result)) |
256 return promise; | 255 return promise; |
257 | 256 |
258 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 257 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
259 normalized_algorithm, key->Key()); | 258 normalized_algorithm, key->Key()); |
260 Platform::Current()->Crypto()->Decrypt(normalized_algorithm, key->Key(), | 259 Platform::Current()->Crypto()->Decrypt(normalized_algorithm, key->Key(), |
261 std::move(data), result->Result()); | 260 std::move(data), result->Result()); |
262 return promise; | 261 return promise; |
263 } | 262 } |
264 | 263 |
265 ScriptPromise SubtleCrypto::sign(ScriptState* script_state, | 264 ScriptPromise SubtleCrypto::sign(ScriptState* script_state, |
266 const AlgorithmIdentifier& raw_algorithm, | 265 const AlgorithmIdentifier& raw_algorithm, |
267 CryptoKey* key, | 266 CryptoKey* key, |
268 const BufferSource& raw_data) { | 267 const BufferSource& raw_data) { |
(...skipping 20 matching lines...) Expand all Loading... |
289 // 14.3.3.8: If the name member of normalizedAlgorithm is not equal to the | 288 // 14.3.3.8: If the name member of normalizedAlgorithm is not equal to the |
290 // name attribute of the [[algorithm]] internal slot of key then | 289 // name attribute of the [[algorithm]] internal slot of key then |
291 // throw an InvalidAccessError. | 290 // throw an InvalidAccessError. |
292 // | 291 // |
293 // 14.3.3.9: If the [[usages]] internal slot of key does not contain an | 292 // 14.3.3.9: If the [[usages]] internal slot of key does not contain an |
294 // entry that is "sign", then throw an InvalidAccessError. | 293 // entry that is "sign", then throw an InvalidAccessError. |
295 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, kWebCryptoKeyUsageSign, | 294 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, kWebCryptoKeyUsageSign, |
296 result)) | 295 result)) |
297 return promise; | 296 return promise; |
298 | 297 |
299 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 298 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
300 normalized_algorithm, key->Key()); | 299 normalized_algorithm, key->Key()); |
301 Platform::Current()->Crypto()->Sign(normalized_algorithm, key->Key(), | 300 Platform::Current()->Crypto()->Sign(normalized_algorithm, key->Key(), |
302 std::move(data), result->Result()); | 301 std::move(data), result->Result()); |
303 return promise; | 302 return promise; |
304 } | 303 } |
305 | 304 |
306 ScriptPromise SubtleCrypto::verifySignature( | 305 ScriptPromise SubtleCrypto::verifySignature( |
307 ScriptState* script_state, | 306 ScriptState* script_state, |
308 const AlgorithmIdentifier& raw_algorithm, | 307 const AlgorithmIdentifier& raw_algorithm, |
309 CryptoKey* key, | 308 CryptoKey* key, |
(...skipping 26 matching lines...) Expand all Loading... |
336 // 14.3.4.9: If the name member of normalizedAlgorithm is not equal to the | 335 // 14.3.4.9: If the name member of normalizedAlgorithm is not equal to the |
337 // name attribute of the [[algorithm]] internal slot of key then | 336 // name attribute of the [[algorithm]] internal slot of key then |
338 // throw an InvalidAccessError. | 337 // throw an InvalidAccessError. |
339 // | 338 // |
340 // 14.3.4.10: If the [[usages]] internal slot of key does not contain an | 339 // 14.3.4.10: If the [[usages]] internal slot of key does not contain an |
341 // entry that is "verify", then throw an InvalidAccessError. | 340 // entry that is "verify", then throw an InvalidAccessError. |
342 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, | 341 if (!key->CanBeUsedForAlgorithm(normalized_algorithm, |
343 kWebCryptoKeyUsageVerify, result)) | 342 kWebCryptoKeyUsageVerify, result)) |
344 return promise; | 343 return promise; |
345 | 344 |
346 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 345 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
347 normalized_algorithm, key->Key()); | 346 normalized_algorithm, key->Key()); |
348 Platform::Current()->Crypto()->VerifySignature( | 347 Platform::Current()->Crypto()->VerifySignature( |
349 normalized_algorithm, key->Key(), std::move(signature), std::move(data), | 348 normalized_algorithm, key->Key(), std::move(signature), std::move(data), |
350 result->Result()); | 349 result->Result()); |
351 return promise; | 350 return promise; |
352 } | 351 } |
353 | 352 |
354 ScriptPromise SubtleCrypto::digest(ScriptState* script_state, | 353 ScriptPromise SubtleCrypto::digest(ScriptState* script_state, |
355 const AlgorithmIdentifier& raw_algorithm, | 354 const AlgorithmIdentifier& raw_algorithm, |
356 const BufferSource& raw_data) { | 355 const BufferSource& raw_data) { |
(...skipping 10 matching lines...) Expand all Loading... |
367 // by the data parameter passed to the digest method. | 366 // by the data parameter passed to the digest method. |
368 WebVector<uint8_t> data = CopyBytes(raw_data); | 367 WebVector<uint8_t> data = CopyBytes(raw_data); |
369 | 368 |
370 // 14.3.5.3: Let normalizedAlgorithm be the result of normalizing an | 369 // 14.3.5.3: Let normalizedAlgorithm be the result of normalizing an |
371 // algorithm, with alg set to algorithm and op set to "digest". | 370 // algorithm, with alg set to algorithm and op set to "digest". |
372 WebCryptoAlgorithm normalized_algorithm; | 371 WebCryptoAlgorithm normalized_algorithm; |
373 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDigest, | 372 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDigest, |
374 normalized_algorithm, result)) | 373 normalized_algorithm, result)) |
375 return promise; | 374 return promise; |
376 | 375 |
377 HistogramAlgorithm(ExecutionContext::From(script_state), | 376 HistogramAlgorithm(script_state->GetExecutionContext(), normalized_algorithm); |
378 normalized_algorithm); | |
379 Platform::Current()->Crypto()->Digest(normalized_algorithm, std::move(data), | 377 Platform::Current()->Crypto()->Digest(normalized_algorithm, std::move(data), |
380 result->Result()); | 378 result->Result()); |
381 return promise; | 379 return promise; |
382 } | 380 } |
383 | 381 |
384 ScriptPromise SubtleCrypto::generateKey( | 382 ScriptPromise SubtleCrypto::generateKey( |
385 ScriptState* script_state, | 383 ScriptState* script_state, |
386 const AlgorithmIdentifier& raw_algorithm, | 384 const AlgorithmIdentifier& raw_algorithm, |
387 bool extractable, | 385 bool extractable, |
388 const Vector<String>& raw_key_usages) { | 386 const Vector<String>& raw_key_usages) { |
(...skipping 15 matching lines...) Expand all Loading... |
404 // "generateKey". | 402 // "generateKey". |
405 WebCryptoAlgorithm normalized_algorithm; | 403 WebCryptoAlgorithm normalized_algorithm; |
406 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationGenerateKey, | 404 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationGenerateKey, |
407 normalized_algorithm, result)) | 405 normalized_algorithm, result)) |
408 return promise; | 406 return promise; |
409 | 407 |
410 // NOTE: Steps (8) and (9) disallow empty usages on secret and private | 408 // NOTE: Steps (8) and (9) disallow empty usages on secret and private |
411 // keys. This normative requirement is enforced by the platform | 409 // keys. This normative requirement is enforced by the platform |
412 // implementation in the call below. | 410 // implementation in the call below. |
413 | 411 |
414 HistogramAlgorithm(ExecutionContext::From(script_state), | 412 HistogramAlgorithm(script_state->GetExecutionContext(), normalized_algorithm); |
415 normalized_algorithm); | |
416 Platform::Current()->Crypto()->GenerateKey(normalized_algorithm, extractable, | 413 Platform::Current()->Crypto()->GenerateKey(normalized_algorithm, extractable, |
417 key_usages, result->Result()); | 414 key_usages, result->Result()); |
418 return promise; | 415 return promise; |
419 } | 416 } |
420 | 417 |
421 ScriptPromise SubtleCrypto::importKey( | 418 ScriptPromise SubtleCrypto::importKey( |
422 ScriptState* script_state, | 419 ScriptState* script_state, |
423 const String& raw_format, | 420 const String& raw_format, |
424 const ArrayBufferOrArrayBufferViewOrDictionary& raw_key_data, | 421 const ArrayBufferOrArrayBufferViewOrDictionary& raw_key_data, |
425 const AlgorithmIdentifier& raw_algorithm, | 422 const AlgorithmIdentifier& raw_algorithm, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 } | 488 } |
492 | 489 |
493 // 14.3.9.3: Let normalizedAlgorithm be the result of normalizing an | 490 // 14.3.9.3: Let normalizedAlgorithm be the result of normalizing an |
494 // algorithm, with alg set to algorithm and op set to | 491 // algorithm, with alg set to algorithm and op set to |
495 // "importKey". | 492 // "importKey". |
496 WebCryptoAlgorithm normalized_algorithm; | 493 WebCryptoAlgorithm normalized_algorithm; |
497 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationImportKey, | 494 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationImportKey, |
498 normalized_algorithm, result)) | 495 normalized_algorithm, result)) |
499 return promise; | 496 return promise; |
500 | 497 |
501 HistogramAlgorithm(ExecutionContext::From(script_state), | 498 HistogramAlgorithm(script_state->GetExecutionContext(), normalized_algorithm); |
502 normalized_algorithm); | |
503 Platform::Current()->Crypto()->ImportKey(format, std::move(key_data), | 499 Platform::Current()->Crypto()->ImportKey(format, std::move(key_data), |
504 normalized_algorithm, extractable, | 500 normalized_algorithm, extractable, |
505 key_usages, result->Result()); | 501 key_usages, result->Result()); |
506 return promise; | 502 return promise; |
507 } | 503 } |
508 | 504 |
509 ScriptPromise SubtleCrypto::exportKey(ScriptState* script_state, | 505 ScriptPromise SubtleCrypto::exportKey(ScriptState* script_state, |
510 const String& raw_format, | 506 const String& raw_format, |
511 CryptoKey* key) { | 507 CryptoKey* key) { |
512 // Method described by: | 508 // Method described by: |
(...skipping 10 matching lines...) Expand all Loading... |
523 return promise; | 519 return promise; |
524 | 520 |
525 // 14.3.10.6: If the [[extractable]] internal slot of key is false, then | 521 // 14.3.10.6: If the [[extractable]] internal slot of key is false, then |
526 // throw an InvalidAccessError. | 522 // throw an InvalidAccessError. |
527 if (!key->extractable()) { | 523 if (!key->extractable()) { |
528 result->CompleteWithError(kWebCryptoErrorTypeInvalidAccess, | 524 result->CompleteWithError(kWebCryptoErrorTypeInvalidAccess, |
529 "key is not extractable"); | 525 "key is not extractable"); |
530 return promise; | 526 return promise; |
531 } | 527 } |
532 | 528 |
533 HistogramKey(ExecutionContext::From(script_state), key->Key()); | 529 HistogramKey(script_state->GetExecutionContext(), key->Key()); |
534 Platform::Current()->Crypto()->ExportKey(format, key->Key(), | 530 Platform::Current()->Crypto()->ExportKey(format, key->Key(), |
535 result->Result()); | 531 result->Result()); |
536 return promise; | 532 return promise; |
537 } | 533 } |
538 | 534 |
539 ScriptPromise SubtleCrypto::wrapKey( | 535 ScriptPromise SubtleCrypto::wrapKey( |
540 ScriptState* script_state, | 536 ScriptState* script_state, |
541 const String& raw_format, | 537 const String& raw_format, |
542 CryptoKey* key, | 538 CryptoKey* key, |
543 CryptoKey* wrapping_key, | 539 CryptoKey* wrapping_key, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 // the spec order. | 578 // the spec order. |
583 | 579 |
584 // 14.3.11.12: If the [[extractable]] internal slot of key is false, then | 580 // 14.3.11.12: If the [[extractable]] internal slot of key is false, then |
585 // throw an InvalidAccessError. | 581 // throw an InvalidAccessError. |
586 if (!key->extractable()) { | 582 if (!key->extractable()) { |
587 result->CompleteWithError(kWebCryptoErrorTypeInvalidAccess, | 583 result->CompleteWithError(kWebCryptoErrorTypeInvalidAccess, |
588 "key is not extractable"); | 584 "key is not extractable"); |
589 return promise; | 585 return promise; |
590 } | 586 } |
591 | 587 |
592 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 588 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
593 normalized_algorithm, wrapping_key->Key()); | 589 normalized_algorithm, wrapping_key->Key()); |
594 HistogramKey(ExecutionContext::From(script_state), key->Key()); | 590 HistogramKey(script_state->GetExecutionContext(), key->Key()); |
595 Platform::Current()->Crypto()->WrapKey( | 591 Platform::Current()->Crypto()->WrapKey( |
596 format, key->Key(), wrapping_key->Key(), normalized_algorithm, | 592 format, key->Key(), wrapping_key->Key(), normalized_algorithm, |
597 result->Result()); | 593 result->Result()); |
598 return promise; | 594 return promise; |
599 } | 595 } |
600 | 596 |
601 ScriptPromise SubtleCrypto::unwrapKey( | 597 ScriptPromise SubtleCrypto::unwrapKey( |
602 ScriptState* script_state, | 598 ScriptState* script_state, |
603 const String& raw_format, | 599 const String& raw_format, |
604 const BufferSource& raw_wrapped_key, | 600 const BufferSource& raw_wrapped_key, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 // contain an entry that is "unwrapKey", then throw an | 653 // contain an entry that is "unwrapKey", then throw an |
658 // InvalidAccessError. | 654 // InvalidAccessError. |
659 if (!unwrapping_key->CanBeUsedForAlgorithm( | 655 if (!unwrapping_key->CanBeUsedForAlgorithm( |
660 normalized_algorithm, kWebCryptoKeyUsageUnwrapKey, result)) | 656 normalized_algorithm, kWebCryptoKeyUsageUnwrapKey, result)) |
661 return promise; | 657 return promise; |
662 | 658 |
663 // NOTE: Step (16) disallows empty usages on secret and private keys. This | 659 // NOTE: Step (16) disallows empty usages on secret and private keys. This |
664 // normative requirement is enforced by the platform implementation in the | 660 // normative requirement is enforced by the platform implementation in the |
665 // call below. | 661 // call below. |
666 | 662 |
667 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 663 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
668 normalized_algorithm, unwrapping_key->Key()); | 664 normalized_algorithm, unwrapping_key->Key()); |
669 HistogramAlgorithm(ExecutionContext::From(script_state), | 665 HistogramAlgorithm(script_state->GetExecutionContext(), |
670 normalized_key_algorithm); | 666 normalized_key_algorithm); |
671 Platform::Current()->Crypto()->UnwrapKey( | 667 Platform::Current()->Crypto()->UnwrapKey( |
672 format, std::move(wrapped_key), unwrapping_key->Key(), | 668 format, std::move(wrapped_key), unwrapping_key->Key(), |
673 normalized_algorithm, normalized_key_algorithm, extractable, key_usages, | 669 normalized_algorithm, normalized_key_algorithm, extractable, key_usages, |
674 result->Result()); | 670 result->Result()); |
675 return promise; | 671 return promise; |
676 } | 672 } |
677 | 673 |
678 ScriptPromise SubtleCrypto::deriveBits(ScriptState* script_state, | 674 ScriptPromise SubtleCrypto::deriveBits(ScriptState* script_state, |
679 const AlgorithmIdentifier& raw_algorithm, | 675 const AlgorithmIdentifier& raw_algorithm, |
(...skipping 19 matching lines...) Expand all Loading... |
699 // 14.3.8.7: If the name member of normalizedAlgorithm is not equal to the | 695 // 14.3.8.7: If the name member of normalizedAlgorithm is not equal to the |
700 // name attribute of the [[algorithm]] internal slot of baseKey | 696 // name attribute of the [[algorithm]] internal slot of baseKey |
701 // then throw an InvalidAccessError. | 697 // then throw an InvalidAccessError. |
702 // | 698 // |
703 // 14.3.8.8: If the [[usages]] internal slot of baseKey does not contain an | 699 // 14.3.8.8: If the [[usages]] internal slot of baseKey does not contain an |
704 // entry that is "deriveBits", then throw an InvalidAccessError. | 700 // entry that is "deriveBits", then throw an InvalidAccessError. |
705 if (!base_key->CanBeUsedForAlgorithm(normalized_algorithm, | 701 if (!base_key->CanBeUsedForAlgorithm(normalized_algorithm, |
706 kWebCryptoKeyUsageDeriveBits, result)) | 702 kWebCryptoKeyUsageDeriveBits, result)) |
707 return promise; | 703 return promise; |
708 | 704 |
709 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 705 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
710 normalized_algorithm, base_key->Key()); | 706 normalized_algorithm, base_key->Key()); |
711 Platform::Current()->Crypto()->DeriveBits( | 707 Platform::Current()->Crypto()->DeriveBits( |
712 normalized_algorithm, base_key->Key(), length_bits, result->Result()); | 708 normalized_algorithm, base_key->Key(), length_bits, result->Result()); |
713 return promise; | 709 return promise; |
714 } | 710 } |
715 | 711 |
716 ScriptPromise SubtleCrypto::deriveKey( | 712 ScriptPromise SubtleCrypto::deriveKey( |
717 ScriptState* script_state, | 713 ScriptState* script_state, |
718 const AlgorithmIdentifier& raw_algorithm, | 714 const AlgorithmIdentifier& raw_algorithm, |
719 CryptoKey* base_key, | 715 CryptoKey* base_key, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 // 14.3.7.12: If the [[usages]] internal slot of baseKey does not contain | 765 // 14.3.7.12: If the [[usages]] internal slot of baseKey does not contain |
770 // an entry that is "deriveKey", then throw an InvalidAccessError. | 766 // an entry that is "deriveKey", then throw an InvalidAccessError. |
771 if (!base_key->CanBeUsedForAlgorithm(normalized_algorithm, | 767 if (!base_key->CanBeUsedForAlgorithm(normalized_algorithm, |
772 kWebCryptoKeyUsageDeriveKey, result)) | 768 kWebCryptoKeyUsageDeriveKey, result)) |
773 return promise; | 769 return promise; |
774 | 770 |
775 // NOTE: Step (16) disallows empty usages on secret and private keys. This | 771 // NOTE: Step (16) disallows empty usages on secret and private keys. This |
776 // normative requirement is enforced by the platform implementation in the | 772 // normative requirement is enforced by the platform implementation in the |
777 // call below. | 773 // call below. |
778 | 774 |
779 HistogramAlgorithmAndKey(ExecutionContext::From(script_state), | 775 HistogramAlgorithmAndKey(script_state->GetExecutionContext(), |
780 normalized_algorithm, base_key->Key()); | 776 normalized_algorithm, base_key->Key()); |
781 HistogramAlgorithm(ExecutionContext::From(script_state), | 777 HistogramAlgorithm(script_state->GetExecutionContext(), |
782 normalized_derived_key_algorithm); | 778 normalized_derived_key_algorithm); |
783 Platform::Current()->Crypto()->DeriveKey( | 779 Platform::Current()->Crypto()->DeriveKey( |
784 normalized_algorithm, base_key->Key(), normalized_derived_key_algorithm, | 780 normalized_algorithm, base_key->Key(), normalized_derived_key_algorithm, |
785 key_length_algorithm, extractable, key_usages, result->Result()); | 781 key_length_algorithm, extractable, key_usages, result->Result()); |
786 return promise; | 782 return promise; |
787 } | 783 } |
788 | 784 |
789 } // namespace blink | 785 } // namespace blink |
OLD | NEW |