| 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 14 matching lines...) Expand all Loading... |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "modules/crypto/NormalizeAlgorithm.h" | 32 #include "modules/crypto/NormalizeAlgorithm.h" |
| 33 | 33 |
| 34 #include "bindings/v8/Dictionary.h" | 34 #include "bindings/v8/Dictionary.h" |
| 35 #include "bindings/v8/ExceptionState.h" | 35 #include "platform/CryptoResult.h" |
| 36 #include "bindings/v8/ExceptionStatePlaceholder.h" | |
| 37 #include "core/dom/ExceptionCode.h" | |
| 38 #include "platform/NotImplemented.h" | 36 #include "platform/NotImplemented.h" |
| 39 #include "public/platform/WebCryptoAlgorithmParams.h" | 37 #include "public/platform/WebCryptoAlgorithmParams.h" |
| 38 #include "public/platform/WebString.h" |
| 40 #include "wtf/ArrayBuffer.h" | 39 #include "wtf/ArrayBuffer.h" |
| 41 #include "wtf/ArrayBufferView.h" | 40 #include "wtf/ArrayBufferView.h" |
| 42 #include "wtf/HashMap.h" | 41 #include "wtf/HashMap.h" |
| 43 #include "wtf/MathExtras.h" | 42 #include "wtf/MathExtras.h" |
| 44 #include "wtf/Uint8Array.h" | 43 #include "wtf/Uint8Array.h" |
| 45 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 46 #include "wtf/text/StringBuilder.h" | 45 #include "wtf/text/StringBuilder.h" |
| 47 #include "wtf/text/StringHash.h" | 46 #include "wtf/text/StringHash.h" |
| 48 | 47 |
| 49 namespace WebCore { | 48 namespace WebCore { |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) | 369 bool parseAesKeyGenParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorith
mParams>& params, const ErrorContext& context, String& errorDetails) |
| 371 { | 370 { |
| 372 uint16_t length; | 371 uint16_t length; |
| 373 if (!getUint16(raw, "length", length, context, errorDetails)) | 372 if (!getUint16(raw, "length", length, context, errorDetails)) |
| 374 return false; | 373 return false; |
| 375 | 374 |
| 376 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); | 375 params = adoptPtr(new blink::WebCryptoAesKeyGenParams(length)); |
| 377 return true; | 376 return true; |
| 378 } | 377 } |
| 379 | 378 |
| 380 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor
ithm&, ErrorContext, String&, ExceptionState&); | 379 bool parseAlgorithm(const Dictionary&, AlgorithmOperation, blink::WebCryptoAlgor
ithm&, ErrorContext, String&); |
| 381 | 380 |
| 382 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
ext context, String& errorDetails) | 381 bool parseHash(const Dictionary& raw, blink::WebCryptoAlgorithm& hash, ErrorCont
ext context, String& errorDetails) |
| 383 { | 382 { |
| 384 Dictionary rawHash; | 383 Dictionary rawHash; |
| 385 if (!raw.get("hash", rawHash)) { | 384 if (!raw.get("hash", rawHash)) { |
| 386 errorDetails = context.toString("hash", "Missing or not a dictionary"); | 385 errorDetails = context.toString("hash", "Missing or not a dictionary"); |
| 387 return false; | 386 return false; |
| 388 } | 387 } |
| 389 | 388 |
| 390 context.add("hash"); | 389 context.add("hash"); |
| 391 IgnorableExceptionState exceptionState; | 390 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails); |
| 392 return parseAlgorithm(rawHash, Digest, hash, context, errorDetails, exceptio
nState); | |
| 393 } | 391 } |
| 394 | 392 |
| 395 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ErrorContext& context, String& errorDetails) | 393 bool parseHmacParams(const Dictionary& raw, OwnPtr<blink::WebCryptoAlgorithmPara
ms>& params, const ErrorContext& context, String& errorDetails) |
| 396 { | 394 { |
| 397 blink::WebCryptoAlgorithm hash; | 395 blink::WebCryptoAlgorithm hash; |
| 398 if (!parseHash(raw, hash, context, errorDetails)) | 396 if (!parseHash(raw, hash, context, errorDetails)) |
| 399 return false; | 397 return false; |
| 400 | 398 |
| 401 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); | 399 params = adoptPtr(new blink::WebCryptoHmacParams(hash)); |
| 402 return true; | 400 return true; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: | 482 case blink::WebCryptoAlgorithmParamsTypeAesGcmParams: |
| 485 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: | 483 case blink::WebCryptoAlgorithmParamsTypeRsaOaepParams: |
| 486 // TODO | 484 // TODO |
| 487 notImplemented(); | 485 notImplemented(); |
| 488 break; | 486 break; |
| 489 } | 487 } |
| 490 ASSERT_NOT_REACHED(); | 488 ASSERT_NOT_REACHED(); |
| 491 return false; | 489 return false; |
| 492 } | 490 } |
| 493 | 491 |
| 494 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, ErrorContext context, String& errorDetails, ExceptionSta
te& exceptionState) | 492 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, ErrorContext context, String& errorDetails) |
| 495 { | 493 { |
| 496 context.add("Algorithm"); | 494 context.add("Algorithm"); |
| 497 | 495 |
| 498 if (!raw.isObject()) { | 496 if (!raw.isObject()) { |
| 499 errorDetails = context.toString("Not an object"); | 497 errorDetails = context.toString("Not an object"); |
| 500 exceptionState.throwTypeError(errorDetails); | |
| 501 return false; | 498 return false; |
| 502 } | 499 } |
| 503 | 500 |
| 504 String algorithmName; | 501 String algorithmName; |
| 505 if (!raw.get("name", algorithmName)) { | 502 if (!raw.get("name", algorithmName)) { |
| 506 errorDetails = context.toString("name", "Missing or not a string"); | 503 errorDetails = context.toString("name", "Missing or not a string"); |
| 507 exceptionState.throwDOMException(NotSupportedError, errorDetails); | |
| 508 return false; | 504 return false; |
| 509 } | 505 } |
| 510 | 506 |
| 511 const AlgorithmInfo* info = AlgorithmRegistry::instance().lookupAlgorithmByN
ame(algorithmName); | 507 const AlgorithmInfo* info = AlgorithmRegistry::instance().lookupAlgorithmByN
ame(algorithmName); |
| 512 if (!info) { | 508 if (!info) { |
| 513 errorDetails = context.toString("Unrecognized algorithm name"); | 509 errorDetails = context.toString("Unrecognized algorithm name"); |
| 514 exceptionState.throwDOMException(NotSupportedError, errorDetails); | |
| 515 return false; | 510 return false; |
| 516 } | 511 } |
| 517 | 512 |
| 518 context.add(info->algorithmName); | 513 context.add(info->algorithmName); |
| 519 | 514 |
| 520 if (info->paramsForOperation[op] == UnsupportedOp) { | 515 if (info->paramsForOperation[op] == UnsupportedOp) { |
| 521 errorDetails = context.toString("Unsupported operation"); | 516 errorDetails = context.toString("Unsupported operation"); |
| 522 exceptionState.throwDOMException(NotSupportedError, errorDetails); | |
| 523 return false; | 517 return false; |
| 524 } | 518 } |
| 525 | 519 |
| 526 blink::WebCryptoAlgorithmParamsType paramsType = static_cast<blink::WebCrypt
oAlgorithmParamsType>(info->paramsForOperation[op]); | 520 blink::WebCryptoAlgorithmParamsType paramsType = static_cast<blink::WebCrypt
oAlgorithmParamsType>(info->paramsForOperation[op]); |
| 527 OwnPtr<blink::WebCryptoAlgorithmParams> params; | 521 OwnPtr<blink::WebCryptoAlgorithmParams> params; |
| 528 if (!parseAlgorithmParams(raw, paramsType, params, context, errorDetails)) | 522 if (!parseAlgorithmParams(raw, paramsType, params, context, errorDetails)) |
| 529 return false; | 523 return false; |
| 530 | 524 |
| 531 algorithm = blink::WebCryptoAlgorithm(info->algorithmId, params.release()); | 525 algorithm = blink::WebCryptoAlgorithm(info->algorithmId, params.release()); |
| 532 return true; | 526 return true; |
| 533 } | 527 } |
| 534 | 528 |
| 535 } // namespace | 529 } // namespace |
| 536 | 530 |
| 537 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, String& errorDetails, ExceptionState& exceptionState) | 531 bool parseAlgorithm(const Dictionary& raw, AlgorithmOperation op, blink::WebCryp
toAlgorithm& algorithm, CryptoResult* result) |
| 538 { | 532 { |
| 539 return parseAlgorithm(raw, op, algorithm, ErrorContext(), errorDetails, exce
ptionState); | 533 String errorDetails; |
| 534 if (!parseAlgorithm(raw, op, algorithm, ErrorContext(), errorDetails)) { |
| 535 result->completeWithError(errorDetails); |
| 536 return false; |
| 537 } |
| 538 return true; |
| 540 } | 539 } |
| 541 | 540 |
| 542 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) | 541 const char* algorithmIdToName(blink::WebCryptoAlgorithmId id) |
| 543 { | 542 { |
| 544 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; | 543 return AlgorithmRegistry::instance().lookupAlgorithmById(id)->algorithmName; |
| 545 } | 544 } |
| 546 | 545 |
| 547 } // namespace WebCore | 546 } // namespace WebCore |
| OLD | NEW |