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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 WebCryptoOperation op, | 51 WebCryptoOperation op, |
52 WebCryptoAlgorithm& algorithm, | 52 WebCryptoAlgorithm& algorithm, |
53 CryptoResult* result) { | 53 CryptoResult* result) { |
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, | |
62 CryptoResult* result) { | |
63 String error_message; | |
64 if (!ExecutionContext::From(script_state) | |
65 ->IsSecureContext(error_message, | |
66 ExecutionContext::kWebCryptoSecureContextCheck)) { | |
67 result->CompleteWithError(kWebCryptoErrorTypeNotSupported, error_message); | |
68 return false; | |
69 } | |
70 | |
71 if (!ExecutionContext::From(script_state)->IsSecureContext()) { | |
72 Deprecation::CountDeprecation( | |
73 ExecutionContext::From(script_state), | |
74 UseCounter::kSubtleCryptoOnlyStrictSecureContextCheckFailed); | |
75 } | |
76 | |
77 return true; | |
78 } | |
79 | |
80 static bool CopyStringProperty(const char* property, | 61 static bool CopyStringProperty(const char* property, |
81 const Dictionary& source, | 62 const Dictionary& source, |
82 JSONObject* destination) { | 63 JSONObject* destination) { |
83 String value; | 64 String value; |
84 if (!DictionaryHelper::Get(source, property, value)) | 65 if (!DictionaryHelper::Get(source, property, value)) |
85 return false; | 66 return false; |
86 destination->SetString(property, value); | 67 destination->SetString(property, value); |
87 return true; | 68 return true; |
88 } | 69 } |
89 | 70 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 ScriptPromise SubtleCrypto::encrypt(ScriptState* script_state, | 164 ScriptPromise SubtleCrypto::encrypt(ScriptState* script_state, |
184 const AlgorithmIdentifier& raw_algorithm, | 165 const AlgorithmIdentifier& raw_algorithm, |
185 CryptoKey* key, | 166 CryptoKey* key, |
186 const BufferSource& raw_data) { | 167 const BufferSource& raw_data) { |
187 // Method described by: | 168 // Method described by: |
188 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-encry
pt | 169 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-encry
pt |
189 | 170 |
190 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 171 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
191 ScriptPromise promise = result->Promise(); | 172 ScriptPromise promise = result->Promise(); |
192 | 173 |
193 if (!CanAccessWebCrypto(script_state, result)) | |
194 return promise; | |
195 | |
196 // 14.3.1.2: Let data be the result of getting a copy of the bytes held by | 174 // 14.3.1.2: Let data be the result of getting a copy of the bytes held by |
197 // the data parameter passed to the encrypt method. | 175 // the data parameter passed to the encrypt method. |
198 WebVector<uint8_t> data = CopyBytes(raw_data); | 176 WebVector<uint8_t> data = CopyBytes(raw_data); |
199 | 177 |
200 // 14.3.1.3: Let normalizedAlgorithm be the result of normalizing an | 178 // 14.3.1.3: Let normalizedAlgorithm be the result of normalizing an |
201 // algorithm, with alg set to algorithm and op set to "encrypt". | 179 // algorithm, with alg set to algorithm and op set to "encrypt". |
202 WebCryptoAlgorithm normalized_algorithm; | 180 WebCryptoAlgorithm normalized_algorithm; |
203 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationEncrypt, | 181 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationEncrypt, |
204 normalized_algorithm, result)) | 182 normalized_algorithm, result)) |
205 return promise; | 183 return promise; |
(...skipping 18 matching lines...) Expand all Loading... |
224 ScriptPromise SubtleCrypto::decrypt(ScriptState* script_state, | 202 ScriptPromise SubtleCrypto::decrypt(ScriptState* script_state, |
225 const AlgorithmIdentifier& raw_algorithm, | 203 const AlgorithmIdentifier& raw_algorithm, |
226 CryptoKey* key, | 204 CryptoKey* key, |
227 const BufferSource& raw_data) { | 205 const BufferSource& raw_data) { |
228 // Method described by: | 206 // Method described by: |
229 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-decry
pt | 207 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-decry
pt |
230 | 208 |
231 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 209 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
232 ScriptPromise promise = result->Promise(); | 210 ScriptPromise promise = result->Promise(); |
233 | 211 |
234 if (!CanAccessWebCrypto(script_state, result)) | |
235 return promise; | |
236 | |
237 // 14.3.2.2: Let data be the result of getting a copy of the bytes held by | 212 // 14.3.2.2: Let data be the result of getting a copy of the bytes held by |
238 // the data parameter passed to the decrypt method. | 213 // the data parameter passed to the decrypt method. |
239 WebVector<uint8_t> data = CopyBytes(raw_data); | 214 WebVector<uint8_t> data = CopyBytes(raw_data); |
240 | 215 |
241 // 14.3.2.3: Let normalizedAlgorithm be the result of normalizing an | 216 // 14.3.2.3: Let normalizedAlgorithm be the result of normalizing an |
242 // algorithm, with alg set to algorithm and op set to "decrypt". | 217 // algorithm, with alg set to algorithm and op set to "decrypt". |
243 WebCryptoAlgorithm normalized_algorithm; | 218 WebCryptoAlgorithm normalized_algorithm; |
244 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDecrypt, | 219 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDecrypt, |
245 normalized_algorithm, result)) | 220 normalized_algorithm, result)) |
246 return promise; | 221 return promise; |
(...skipping 18 matching lines...) Expand all Loading... |
265 ScriptPromise SubtleCrypto::sign(ScriptState* script_state, | 240 ScriptPromise SubtleCrypto::sign(ScriptState* script_state, |
266 const AlgorithmIdentifier& raw_algorithm, | 241 const AlgorithmIdentifier& raw_algorithm, |
267 CryptoKey* key, | 242 CryptoKey* key, |
268 const BufferSource& raw_data) { | 243 const BufferSource& raw_data) { |
269 // Method described by: | 244 // Method described by: |
270 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-sign | 245 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-sign |
271 | 246 |
272 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 247 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
273 ScriptPromise promise = result->Promise(); | 248 ScriptPromise promise = result->Promise(); |
274 | 249 |
275 if (!CanAccessWebCrypto(script_state, result)) | |
276 return promise; | |
277 | |
278 // 14.3.3.2: Let data be the result of getting a copy of the bytes held by | 250 // 14.3.3.2: Let data be the result of getting a copy of the bytes held by |
279 // the data parameter passed to the sign method. | 251 // the data parameter passed to the sign method. |
280 WebVector<uint8_t> data = CopyBytes(raw_data); | 252 WebVector<uint8_t> data = CopyBytes(raw_data); |
281 | 253 |
282 // 14.3.3.3: Let normalizedAlgorithm be the result of normalizing an | 254 // 14.3.3.3: Let normalizedAlgorithm be the result of normalizing an |
283 // algorithm, with alg set to algorithm and op set to "sign". | 255 // algorithm, with alg set to algorithm and op set to "sign". |
284 WebCryptoAlgorithm normalized_algorithm; | 256 WebCryptoAlgorithm normalized_algorithm; |
285 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationSign, | 257 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationSign, |
286 normalized_algorithm, result)) | 258 normalized_algorithm, result)) |
287 return promise; | 259 return promise; |
(...skipping 20 matching lines...) Expand all Loading... |
308 const AlgorithmIdentifier& raw_algorithm, | 280 const AlgorithmIdentifier& raw_algorithm, |
309 CryptoKey* key, | 281 CryptoKey* key, |
310 const BufferSource& raw_signature, | 282 const BufferSource& raw_signature, |
311 const BufferSource& raw_data) { | 283 const BufferSource& raw_data) { |
312 // Method described by: | 284 // Method described by: |
313 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-verify | 285 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-verify |
314 | 286 |
315 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 287 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
316 ScriptPromise promise = result->Promise(); | 288 ScriptPromise promise = result->Promise(); |
317 | 289 |
318 if (!CanAccessWebCrypto(script_state, result)) | |
319 return promise; | |
320 | |
321 // 14.3.4.2: Let signature be the result of getting a copy of the bytes | 290 // 14.3.4.2: Let signature be the result of getting a copy of the bytes |
322 // held by the signature parameter passed to the verify method. | 291 // held by the signature parameter passed to the verify method. |
323 WebVector<uint8_t> signature = CopyBytes(raw_signature); | 292 WebVector<uint8_t> signature = CopyBytes(raw_signature); |
324 | 293 |
325 // 14.3.4.3: Let data be the result of getting a copy of the bytes held by | 294 // 14.3.4.3: Let data be the result of getting a copy of the bytes held by |
326 // the data parameter passed to the verify method. | 295 // the data parameter passed to the verify method. |
327 WebVector<uint8_t> data = CopyBytes(raw_data); | 296 WebVector<uint8_t> data = CopyBytes(raw_data); |
328 | 297 |
329 // 14.3.4.4: Let normalizedAlgorithm be the result of normalizing an | 298 // 14.3.4.4: Let normalizedAlgorithm be the result of normalizing an |
330 // algorithm, with alg set to algorithm and op set to "verify". | 299 // algorithm, with alg set to algorithm and op set to "verify". |
(...skipping 22 matching lines...) Expand all Loading... |
353 | 322 |
354 ScriptPromise SubtleCrypto::digest(ScriptState* script_state, | 323 ScriptPromise SubtleCrypto::digest(ScriptState* script_state, |
355 const AlgorithmIdentifier& raw_algorithm, | 324 const AlgorithmIdentifier& raw_algorithm, |
356 const BufferSource& raw_data) { | 325 const BufferSource& raw_data) { |
357 // Method described by: | 326 // Method described by: |
358 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-digest | 327 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-digest |
359 | 328 |
360 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 329 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
361 ScriptPromise promise = result->Promise(); | 330 ScriptPromise promise = result->Promise(); |
362 | 331 |
363 if (!CanAccessWebCrypto(script_state, result)) | |
364 return promise; | |
365 | |
366 // 14.3.5.2: Let data be the result of getting a copy of the bytes held | 332 // 14.3.5.2: Let data be the result of getting a copy of the bytes held |
367 // by the data parameter passed to the digest method. | 333 // by the data parameter passed to the digest method. |
368 WebVector<uint8_t> data = CopyBytes(raw_data); | 334 WebVector<uint8_t> data = CopyBytes(raw_data); |
369 | 335 |
370 // 14.3.5.3: Let normalizedAlgorithm be the result of normalizing an | 336 // 14.3.5.3: Let normalizedAlgorithm be the result of normalizing an |
371 // algorithm, with alg set to algorithm and op set to "digest". | 337 // algorithm, with alg set to algorithm and op set to "digest". |
372 WebCryptoAlgorithm normalized_algorithm; | 338 WebCryptoAlgorithm normalized_algorithm; |
373 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDigest, | 339 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDigest, |
374 normalized_algorithm, result)) | 340 normalized_algorithm, result)) |
375 return promise; | 341 return promise; |
376 | 342 |
377 HistogramAlgorithm(ExecutionContext::From(script_state), | 343 HistogramAlgorithm(ExecutionContext::From(script_state), |
378 normalized_algorithm); | 344 normalized_algorithm); |
379 Platform::Current()->Crypto()->Digest(normalized_algorithm, std::move(data), | 345 Platform::Current()->Crypto()->Digest(normalized_algorithm, std::move(data), |
380 result->Result()); | 346 result->Result()); |
381 return promise; | 347 return promise; |
382 } | 348 } |
383 | 349 |
384 ScriptPromise SubtleCrypto::generateKey( | 350 ScriptPromise SubtleCrypto::generateKey( |
385 ScriptState* script_state, | 351 ScriptState* script_state, |
386 const AlgorithmIdentifier& raw_algorithm, | 352 const AlgorithmIdentifier& raw_algorithm, |
387 bool extractable, | 353 bool extractable, |
388 const Vector<String>& raw_key_usages) { | 354 const Vector<String>& raw_key_usages) { |
389 // Method described by: | 355 // Method described by: |
390 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-generateK
ey | 356 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-generateK
ey |
391 | 357 |
392 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 358 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
393 ScriptPromise promise = result->Promise(); | 359 ScriptPromise promise = result->Promise(); |
394 | 360 |
395 if (!CanAccessWebCrypto(script_state, result)) | |
396 return promise; | |
397 | |
398 WebCryptoKeyUsageMask key_usages; | 361 WebCryptoKeyUsageMask key_usages; |
399 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) | 362 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) |
400 return promise; | 363 return promise; |
401 | 364 |
402 // 14.3.6.2: Let normalizedAlgorithm be the result of normalizing an | 365 // 14.3.6.2: Let normalizedAlgorithm be the result of normalizing an |
403 // algorithm, with alg set to algorithm and op set to | 366 // algorithm, with alg set to algorithm and op set to |
404 // "generateKey". | 367 // "generateKey". |
405 WebCryptoAlgorithm normalized_algorithm; | 368 WebCryptoAlgorithm normalized_algorithm; |
406 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationGenerateKey, | 369 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationGenerateKey, |
407 normalized_algorithm, result)) | 370 normalized_algorithm, result)) |
(...skipping 16 matching lines...) Expand all Loading... |
424 const ArrayBufferOrArrayBufferViewOrDictionary& raw_key_data, | 387 const ArrayBufferOrArrayBufferViewOrDictionary& raw_key_data, |
425 const AlgorithmIdentifier& raw_algorithm, | 388 const AlgorithmIdentifier& raw_algorithm, |
426 bool extractable, | 389 bool extractable, |
427 const Vector<String>& raw_key_usages) { | 390 const Vector<String>& raw_key_usages) { |
428 // Method described by: | 391 // Method described by: |
429 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-importKey | 392 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-importKey |
430 | 393 |
431 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 394 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
432 ScriptPromise promise = result->Promise(); | 395 ScriptPromise promise = result->Promise(); |
433 | 396 |
434 if (!CanAccessWebCrypto(script_state, result)) | |
435 return promise; | |
436 | |
437 WebCryptoKeyFormat format; | 397 WebCryptoKeyFormat format; |
438 if (!CryptoKey::ParseFormat(raw_format, format, result)) | 398 if (!CryptoKey::ParseFormat(raw_format, format, result)) |
439 return promise; | 399 return promise; |
440 | 400 |
441 WebCryptoKeyUsageMask key_usages; | 401 WebCryptoKeyUsageMask key_usages; |
442 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) | 402 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) |
443 return promise; | 403 return promise; |
444 | 404 |
445 // In the case of JWK keyData will hold the UTF8-encoded JSON for the | 405 // In the case of JWK keyData will hold the UTF8-encoded JSON for the |
446 // JsonWebKey, otherwise it holds a copy of the BufferSource. | 406 // JsonWebKey, otherwise it holds a copy of the BufferSource. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 | 468 |
509 ScriptPromise SubtleCrypto::exportKey(ScriptState* script_state, | 469 ScriptPromise SubtleCrypto::exportKey(ScriptState* script_state, |
510 const String& raw_format, | 470 const String& raw_format, |
511 CryptoKey* key) { | 471 CryptoKey* key) { |
512 // Method described by: | 472 // Method described by: |
513 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-expor
tKey | 473 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-expor
tKey |
514 | 474 |
515 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 475 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
516 ScriptPromise promise = result->Promise(); | 476 ScriptPromise promise = result->Promise(); |
517 | 477 |
518 if (!CanAccessWebCrypto(script_state, result)) | |
519 return promise; | |
520 | |
521 WebCryptoKeyFormat format; | 478 WebCryptoKeyFormat format; |
522 if (!CryptoKey::ParseFormat(raw_format, format, result)) | 479 if (!CryptoKey::ParseFormat(raw_format, format, result)) |
523 return promise; | 480 return promise; |
524 | 481 |
525 // 14.3.10.6: If the [[extractable]] internal slot of key is false, then | 482 // 14.3.10.6: If the [[extractable]] internal slot of key is false, then |
526 // throw an InvalidAccessError. | 483 // throw an InvalidAccessError. |
527 if (!key->extractable()) { | 484 if (!key->extractable()) { |
528 result->CompleteWithError(kWebCryptoErrorTypeInvalidAccess, | 485 result->CompleteWithError(kWebCryptoErrorTypeInvalidAccess, |
529 "key is not extractable"); | 486 "key is not extractable"); |
530 return promise; | 487 return promise; |
(...skipping 10 matching lines...) Expand all Loading... |
541 const String& raw_format, | 498 const String& raw_format, |
542 CryptoKey* key, | 499 CryptoKey* key, |
543 CryptoKey* wrapping_key, | 500 CryptoKey* wrapping_key, |
544 const AlgorithmIdentifier& raw_wrap_algorithm) { | 501 const AlgorithmIdentifier& raw_wrap_algorithm) { |
545 // Method described by: | 502 // Method described by: |
546 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-wrapKey | 503 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-wrapKey |
547 | 504 |
548 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 505 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
549 ScriptPromise promise = result->Promise(); | 506 ScriptPromise promise = result->Promise(); |
550 | 507 |
551 if (!CanAccessWebCrypto(script_state, result)) | |
552 return promise; | |
553 | |
554 WebCryptoKeyFormat format; | 508 WebCryptoKeyFormat format; |
555 if (!CryptoKey::ParseFormat(raw_format, format, result)) | 509 if (!CryptoKey::ParseFormat(raw_format, format, result)) |
556 return promise; | 510 return promise; |
557 | 511 |
558 // 14.3.11.2: Let normalizedAlgorithm be the result of normalizing an | 512 // 14.3.11.2: Let normalizedAlgorithm be the result of normalizing an |
559 // algorithm, with alg set to algorithm and op set to "wrapKey". | 513 // algorithm, with alg set to algorithm and op set to "wrapKey". |
560 // | 514 // |
561 // 14.3.11.3: If an error occurred, let normalizedAlgorithm be the result | 515 // 14.3.11.3: If an error occurred, let normalizedAlgorithm be the result |
562 // of normalizing an algorithm, with alg set to algorithm and op | 516 // of normalizing an algorithm, with alg set to algorithm and op |
563 // set to "encrypt". | 517 // set to "encrypt". |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 const AlgorithmIdentifier& raw_unwrap_algorithm, | 560 const AlgorithmIdentifier& raw_unwrap_algorithm, |
607 const AlgorithmIdentifier& raw_unwrapped_key_algorithm, | 561 const AlgorithmIdentifier& raw_unwrapped_key_algorithm, |
608 bool extractable, | 562 bool extractable, |
609 const Vector<String>& raw_key_usages) { | 563 const Vector<String>& raw_key_usages) { |
610 // Method described by: | 564 // Method described by: |
611 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-unwrapKey | 565 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-unwrapKey |
612 | 566 |
613 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 567 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
614 ScriptPromise promise = result->Promise(); | 568 ScriptPromise promise = result->Promise(); |
615 | 569 |
616 if (!CanAccessWebCrypto(script_state, result)) | |
617 return promise; | |
618 | |
619 WebCryptoKeyFormat format; | 570 WebCryptoKeyFormat format; |
620 if (!CryptoKey::ParseFormat(raw_format, format, result)) | 571 if (!CryptoKey::ParseFormat(raw_format, format, result)) |
621 return promise; | 572 return promise; |
622 | 573 |
623 WebCryptoKeyUsageMask key_usages; | 574 WebCryptoKeyUsageMask key_usages; |
624 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) | 575 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) |
625 return promise; | 576 return promise; |
626 | 577 |
627 // 14.3.12.2: Let wrappedKey be the result of getting a copy of the bytes | 578 // 14.3.12.2: Let wrappedKey be the result of getting a copy of the bytes |
628 // held by the wrappedKey parameter passed to the unwrapKey | 579 // held by the wrappedKey parameter passed to the unwrapKey |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 ScriptPromise SubtleCrypto::deriveBits(ScriptState* script_state, | 629 ScriptPromise SubtleCrypto::deriveBits(ScriptState* script_state, |
679 const AlgorithmIdentifier& raw_algorithm, | 630 const AlgorithmIdentifier& raw_algorithm, |
680 CryptoKey* base_key, | 631 CryptoKey* base_key, |
681 unsigned length_bits) { | 632 unsigned length_bits) { |
682 // Method described by: | 633 // Method described by: |
683 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-deriv
eBits | 634 // https://w3c.github.io/webcrypto/Overview.html#dfn-SubtleCrypto-method-deriv
eBits |
684 | 635 |
685 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 636 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
686 ScriptPromise promise = result->Promise(); | 637 ScriptPromise promise = result->Promise(); |
687 | 638 |
688 if (!CanAccessWebCrypto(script_state, result)) | |
689 return promise; | |
690 | |
691 // 14.3.8.2: Let normalizedAlgorithm be the result of normalizing an | 639 // 14.3.8.2: Let normalizedAlgorithm be the result of normalizing an |
692 // algorithm, with alg set to algorithm and op set to | 640 // algorithm, with alg set to algorithm and op set to |
693 // "deriveBits". | 641 // "deriveBits". |
694 WebCryptoAlgorithm normalized_algorithm; | 642 WebCryptoAlgorithm normalized_algorithm; |
695 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDeriveBits, | 643 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDeriveBits, |
696 normalized_algorithm, result)) | 644 normalized_algorithm, result)) |
697 return promise; | 645 return promise; |
698 | 646 |
699 // 14.3.8.7: If the name member of normalizedAlgorithm is not equal to the | 647 // 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 | 648 // name attribute of the [[algorithm]] internal slot of baseKey |
(...skipping 18 matching lines...) Expand all Loading... |
719 CryptoKey* base_key, | 667 CryptoKey* base_key, |
720 const AlgorithmIdentifier& raw_derived_key_type, | 668 const AlgorithmIdentifier& raw_derived_key_type, |
721 bool extractable, | 669 bool extractable, |
722 const Vector<String>& raw_key_usages) { | 670 const Vector<String>& raw_key_usages) { |
723 // Method described by: | 671 // Method described by: |
724 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-deriveKey | 672 // https://w3c.github.io/webcrypto/Overview.html#SubtleCrypto-method-deriveKey |
725 | 673 |
726 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); | 674 CryptoResultImpl* result = CryptoResultImpl::Create(script_state); |
727 ScriptPromise promise = result->Promise(); | 675 ScriptPromise promise = result->Promise(); |
728 | 676 |
729 if (!CanAccessWebCrypto(script_state, result)) | |
730 return promise; | |
731 | |
732 WebCryptoKeyUsageMask key_usages; | 677 WebCryptoKeyUsageMask key_usages; |
733 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) | 678 if (!CryptoKey::ParseUsageMask(raw_key_usages, key_usages, result)) |
734 return promise; | 679 return promise; |
735 | 680 |
736 // 14.3.7.2: Let normalizedAlgorithm be the result of normalizing an | 681 // 14.3.7.2: Let normalizedAlgorithm be the result of normalizing an |
737 // algorithm, with alg set to algorithm and op set to | 682 // algorithm, with alg set to algorithm and op set to |
738 // "deriveBits". | 683 // "deriveBits". |
739 WebCryptoAlgorithm normalized_algorithm; | 684 WebCryptoAlgorithm normalized_algorithm; |
740 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDeriveBits, | 685 if (!ParseAlgorithm(raw_algorithm, kWebCryptoOperationDeriveBits, |
741 normalized_algorithm, result)) | 686 normalized_algorithm, result)) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 normalized_algorithm, base_key->Key()); | 725 normalized_algorithm, base_key->Key()); |
781 HistogramAlgorithm(ExecutionContext::From(script_state), | 726 HistogramAlgorithm(ExecutionContext::From(script_state), |
782 normalized_derived_key_algorithm); | 727 normalized_derived_key_algorithm); |
783 Platform::Current()->Crypto()->DeriveKey( | 728 Platform::Current()->Crypto()->DeriveKey( |
784 normalized_algorithm, base_key->Key(), normalized_derived_key_algorithm, | 729 normalized_algorithm, base_key->Key(), normalized_derived_key_algorithm, |
785 key_length_algorithm, extractable, key_usages, result->Result()); | 730 key_length_algorithm, extractable, key_usages, result->Result()); |
786 return promise; | 731 return promise; |
787 } | 732 } |
788 | 733 |
789 } // namespace blink | 734 } // namespace blink |
OLD | NEW |