OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "bindings/v8/SerializedScriptValue.h" | 32 #include "bindings/v8/SerializedScriptValue.h" |
33 | 33 |
34 #include "V8Blob.h" | 34 #include "V8Blob.h" |
35 #include "V8DOMFileSystem.h" | 35 #include "V8DOMFileSystem.h" |
36 #include "V8File.h" | 36 #include "V8File.h" |
37 #include "V8FileList.h" | 37 #include "V8FileList.h" |
38 #include "V8ImageData.h" | 38 #include "V8ImageData.h" |
| 39 #include "V8Key.h" |
39 #include "V8MessagePort.h" | 40 #include "V8MessagePort.h" |
40 #include "bindings/v8/ExceptionState.h" | 41 #include "bindings/v8/ExceptionState.h" |
41 #include "bindings/v8/ScriptScope.h" | 42 #include "bindings/v8/ScriptScope.h" |
42 #include "bindings/v8/ScriptState.h" | 43 #include "bindings/v8/ScriptState.h" |
43 #include "bindings/v8/V8Binding.h" | 44 #include "bindings/v8/V8Binding.h" |
44 #include "bindings/v8/WorkerScriptController.h" | 45 #include "bindings/v8/WorkerScriptController.h" |
45 #include "bindings/v8/custom/V8ArrayBufferCustom.h" | 46 #include "bindings/v8/custom/V8ArrayBufferCustom.h" |
46 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" | 47 #include "bindings/v8/custom/V8ArrayBufferViewCustom.h" |
47 #include "bindings/v8/custom/V8DataViewCustom.h" | 48 #include "bindings/v8/custom/V8DataViewCustom.h" |
48 #include "bindings/v8/custom/V8Float32ArrayCustom.h" | 49 #include "bindings/v8/custom/V8Float32ArrayCustom.h" |
49 #include "bindings/v8/custom/V8Float64ArrayCustom.h" | 50 #include "bindings/v8/custom/V8Float64ArrayCustom.h" |
50 #include "bindings/v8/custom/V8Int16ArrayCustom.h" | 51 #include "bindings/v8/custom/V8Int16ArrayCustom.h" |
51 #include "bindings/v8/custom/V8Int32ArrayCustom.h" | 52 #include "bindings/v8/custom/V8Int32ArrayCustom.h" |
52 #include "bindings/v8/custom/V8Int8ArrayCustom.h" | 53 #include "bindings/v8/custom/V8Int8ArrayCustom.h" |
53 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" | 54 #include "bindings/v8/custom/V8Uint16ArrayCustom.h" |
54 #include "bindings/v8/custom/V8Uint32ArrayCustom.h" | 55 #include "bindings/v8/custom/V8Uint32ArrayCustom.h" |
55 #include "bindings/v8/custom/V8Uint8ArrayCustom.h" | 56 #include "bindings/v8/custom/V8Uint8ArrayCustom.h" |
56 #include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h" | 57 #include "bindings/v8/custom/V8Uint8ClampedArrayCustom.h" |
57 #include "core/dom/ExceptionCode.h" | 58 #include "core/dom/ExceptionCode.h" |
58 #include "core/dom/MessagePort.h" | 59 #include "core/dom/MessagePort.h" |
59 #include "core/fileapi/Blob.h" | 60 #include "core/fileapi/Blob.h" |
60 #include "core/fileapi/File.h" | 61 #include "core/fileapi/File.h" |
61 #include "core/fileapi/FileList.h" | 62 #include "core/fileapi/FileList.h" |
62 #include "core/html/ImageData.h" | 63 #include "core/html/ImageData.h" |
63 #include "core/html/canvas/DataView.h" | 64 #include "core/html/canvas/DataView.h" |
64 #include "heap/Handle.h" | 65 #include "heap/Handle.h" |
65 #include "platform/SharedBuffer.h" | 66 #include "platform/SharedBuffer.h" |
| 67 #include "public/platform/Platform.h" |
| 68 #include "public/platform/WebCrypto.h" |
| 69 #include "public/platform/WebCryptoKey.h" |
| 70 #include "public/platform/WebCryptoKeyAlgorithm.h" |
66 #include "wtf/ArrayBuffer.h" | 71 #include "wtf/ArrayBuffer.h" |
67 #include "wtf/ArrayBufferContents.h" | 72 #include "wtf/ArrayBufferContents.h" |
68 #include "wtf/ArrayBufferView.h" | 73 #include "wtf/ArrayBufferView.h" |
69 #include "wtf/Assertions.h" | 74 #include "wtf/Assertions.h" |
70 #include "wtf/ByteOrder.h" | 75 #include "wtf/ByteOrder.h" |
71 #include "wtf/Float32Array.h" | 76 #include "wtf/Float32Array.h" |
72 #include "wtf/Float64Array.h" | 77 #include "wtf/Float64Array.h" |
73 #include "wtf/Int16Array.h" | 78 #include "wtf/Int16Array.h" |
74 #include "wtf/Int32Array.h" | 79 #include "wtf/Int32Array.h" |
75 #include "wtf/Int8Array.h" | 80 #include "wtf/Int8Array.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the
open stack; | 207 ObjectTag = '{', // numProperties:uint32_t -> pops the last object from the
open stack; |
203 // fills it with the last numProp
erties name,value pairs pushed onto the deserialization stack | 208 // fills it with the last numProp
erties name,value pairs pushed onto the deserialization stack |
204 SparseArrayTag = '@', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; | 209 SparseArrayTag = '@', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; |
205 // fills it
with the last numProperties name,value pairs pushed onto the deserialization st
ack | 210 // fills it
with the last numProperties name,value pairs pushed onto the deserialization st
ack |
206 DenseArrayTag = '$', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; | 211 DenseArrayTag = '$', // numProperties:uint32_t, length:uint32_t -> pops the
last object from the open stack; |
207 // fills it
with the last length elements and numProperties name,value pairs pushed onto des
erialization stack | 212 // fills it
with the last length elements and numProperties name,value pairs pushed onto des
erialization stack |
208 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) | 213 RegExpTag = 'R', // pattern:RawString, flags:uint32_t -> RegExp (ref) |
209 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array
Buffer (ref) | 214 ArrayBufferTag = 'B', // byteLength:uint32_t, data:byte[byteLength] -> Array
Buffer (ref) |
210 ArrayBufferTransferTag = 't', // index:uint32_t -> ArrayBuffer. For ArrayBuf
fer transfer | 215 ArrayBufferTransferTag = 't', // index:uint32_t -> ArrayBuffer. For ArrayBuf
fer transfer |
211 ArrayBufferViewTag = 'V', // subtag:byte, byteOffset:uint32_t, byteLength:ui
nt32_t -> ArrayBufferView (ref). Consumes an ArrayBuffer from the top of the des
erialization stack. | 216 ArrayBufferViewTag = 'V', // subtag:byte, byteOffset:uint32_t, byteLength:ui
nt32_t -> ArrayBufferView (ref). Consumes an ArrayBuffer from the top of the des
erialization stack. |
| 217 CryptoKeyTag = 'K', // subtag:byte, props, usages:uint32_t, keyDataLength:ui
nt32_t, keyData:byte[keyDataLength] |
| 218 // If subtag=AesKeyTag: |
| 219 // props = keyLengthBytes:byte, algorithmId:uint32
_t |
| 220 // If subtag=HmacKeyTag: |
| 221 // props = hashId:uint32_t |
| 222 // If subtag=RsaKeyTag: |
| 223 // props = algorithmId:uint32_t, type:uint32_t, mo
dulusLengthBits:uint32_t, publicExponentLength:uint32_t, publicExponent:byte[pub
licExponentLength] |
| 224 // If subtag=RsaHashedKeyTag: |
| 225 // props = <same as for RsaKeyTag>, hashId:uint32_
t |
212 ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref] | 226 ObjectReferenceTag = '^', // ref:uint32_t -> reference table[ref] |
213 GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and
pushed onto the open stack (ref) | 227 GenerateFreshObjectTag = 'o', // -> empty object allocated an object ID and
pushed onto the open stack (ref) |
214 GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length]
allocated an object ID and pushed onto the open stack (ref) | 228 GenerateFreshSparseArrayTag = 'a', // length:uint32_t -> empty array[length]
allocated an object ID and pushed onto the open stack (ref) |
215 GenerateFreshDenseArrayTag = 'A', // length:uint32_t -> empty array[length]
allocated an object ID and pushed onto the open stack (ref) | 229 GenerateFreshDenseArrayTag = 'A', // length:uint32_t -> empty array[length]
allocated an object ID and pushed onto the open stack (ref) |
216 ReferenceCountTag = '?', // refTableSize:uint32_t -> If the reference table
is not refTableSize big, fails. | 230 ReferenceCountTag = '?', // refTableSize:uint32_t -> If the reference table
is not refTableSize big, fails. |
217 StringObjectTag = 's', // string:RawString -> new String(string) (ref) | 231 StringObjectTag = 's', // string:RawString -> new String(string) (ref) |
218 NumberObjectTag = 'n', // value:double -> new Number(value) (ref) | 232 NumberObjectTag = 'n', // value:double -> new Number(value) (ref) |
219 TrueObjectTag = 'y', // new Boolean(true) (ref) | 233 TrueObjectTag = 'y', // new Boolean(true) (ref) |
220 FalseObjectTag = 'x', // new Boolean(false) (ref) | 234 FalseObjectTag = 'x', // new Boolean(false) (ref) |
221 VersionTag = 0xFF // version:uint32_t -> Uses this as the file version. | 235 VersionTag = 0xFF // version:uint32_t -> Uses this as the file version. |
222 }; | 236 }; |
223 | 237 |
224 enum ArrayBufferViewSubTag { | 238 enum ArrayBufferViewSubTag { |
225 ByteArrayTag = 'b', | 239 ByteArrayTag = 'b', |
226 UnsignedByteArrayTag = 'B', | 240 UnsignedByteArrayTag = 'B', |
227 UnsignedByteClampedArrayTag = 'C', | 241 UnsignedByteClampedArrayTag = 'C', |
228 ShortArrayTag = 'w', | 242 ShortArrayTag = 'w', |
229 UnsignedShortArrayTag = 'W', | 243 UnsignedShortArrayTag = 'W', |
230 IntArrayTag = 'd', | 244 IntArrayTag = 'd', |
231 UnsignedIntArrayTag = 'D', | 245 UnsignedIntArrayTag = 'D', |
232 FloatArrayTag = 'f', | 246 FloatArrayTag = 'f', |
233 DoubleArrayTag = 'F', | 247 DoubleArrayTag = 'F', |
234 DataViewTag = '?' | 248 DataViewTag = '?' |
235 }; | 249 }; |
236 | 250 |
| 251 enum CryptoKeySubTag { |
| 252 AesKeyTag = 1, |
| 253 HmacKeyTag = 2, |
| 254 RsaKeyTag = 3, |
| 255 RsaHashedKeyTag = 4, |
| 256 // Maximum allowed value is 2^32-1 |
| 257 }; |
| 258 |
| 259 enum AssymetricCryptoKeyType { |
| 260 PublicKeyType = 1, |
| 261 PrivateKeyType = 2, |
| 262 // Maximum allowed value is 2^32-1 |
| 263 }; |
| 264 |
| 265 enum CryptoKeyAlgorithmTag { |
| 266 AesCbcTag = 1, |
| 267 HmacTag = 2, |
| 268 RsaSsaPkcs1v1_5Tag = 3, |
| 269 RsaEsPkcs1v1_5Tag = 4, |
| 270 Sha1Tag = 5, |
| 271 Sha224Tag = 6, |
| 272 Sha256Tag = 7, |
| 273 Sha384Tag = 8, |
| 274 Sha512Tag = 9, |
| 275 AesGcmTag = 10, |
| 276 RsaOaepTag = 11, |
| 277 AesCtrTag = 12, |
| 278 AesKwTag = 13, |
| 279 // Maximum allowed value is 2^32-1 |
| 280 }; |
| 281 |
| 282 enum CryptoKeyUsage { |
| 283 // Extractability is not a "usage" in the WebCryptoKeyUsages sense, however |
| 284 // it fits conveniently into this bitfield. |
| 285 ExtractableUsage = 1 << 0, |
| 286 |
| 287 EncryptUsage = 1 << 1, |
| 288 DecryptUsage = 1 << 2, |
| 289 SignUsage = 1 << 3, |
| 290 VerifyUsage = 1 << 4, |
| 291 DeriveKeyUsage = 1 << 5, |
| 292 WrapKeyUsage = 1 << 6, |
| 293 UnwrapKeyUsage = 1 << 7, |
| 294 // Maximum allowed value is 1 << 31 |
| 295 }; |
| 296 |
237 static bool shouldCheckForCycles(int depth) | 297 static bool shouldCheckForCycles(int depth) |
238 { | 298 { |
239 ASSERT(depth >= 0); | 299 ASSERT(depth >= 0); |
240 // Since we are not required to spot the cycle as soon as it | 300 // Since we are not required to spot the cycle as soon as it |
241 // happens we can check for cycles only when the current depth | 301 // happens we can check for cycles only when the current depth |
242 // is a power of two. | 302 // is a power of two. |
243 return !(depth & (depth - 1)); | 303 return !(depth & (depth - 1)); |
244 } | 304 } |
245 | 305 |
246 static const int maxDepth = 20000; | 306 static const int maxDepth = 20000; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 475 |
416 void writeFileList(const FileList& fileList) | 476 void writeFileList(const FileList& fileList) |
417 { | 477 { |
418 append(FileListTag); | 478 append(FileListTag); |
419 uint32_t length = fileList.length(); | 479 uint32_t length = fileList.length(); |
420 doWriteUint32(length); | 480 doWriteUint32(length); |
421 for (unsigned i = 0; i < length; ++i) | 481 for (unsigned i = 0; i < length; ++i) |
422 doWriteFile(*fileList.item(i)); | 482 doWriteFile(*fileList.item(i)); |
423 } | 483 } |
424 | 484 |
| 485 bool writeCryptoKey(const blink::WebCryptoKey& key, String& errorMessage) |
| 486 { |
| 487 append(static_cast<uint8_t>(CryptoKeyTag)); |
| 488 |
| 489 switch (key.algorithm().paramsType()) { |
| 490 case blink::WebCryptoKeyAlgorithmParamsTypeAes: |
| 491 doWriteAesKey(key); |
| 492 break; |
| 493 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
| 494 doWriteHmacKey(key); |
| 495 break; |
| 496 case blink::WebCryptoKeyAlgorithmParamsTypeRsa: |
| 497 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
| 498 doWriteRsaKey(key); |
| 499 break; |
| 500 case blink::WebCryptoKeyAlgorithmParamsTypeNone: |
| 501 ASSERT_NOT_REACHED(); |
| 502 return false; |
| 503 } |
| 504 |
| 505 doWriteKeyUsages(key.usages(), key.extractable()); |
| 506 |
| 507 blink::WebVector<uint8_t> keyData; |
| 508 if (!blink::Platform::current()->crypto()->serializeKeyForClone(key, key
Data)) { |
| 509 errorMessage = "Couldn't export the key data"; |
| 510 return false; |
| 511 } |
| 512 |
| 513 doWriteUint32(keyData.size()); |
| 514 append(keyData.data(), keyData.size()); |
| 515 return true; |
| 516 } |
| 517 |
425 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 518 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) |
426 { | 519 { |
427 append(ArrayBufferTag); | 520 append(ArrayBufferTag); |
428 doWriteArrayBuffer(arrayBuffer); | 521 doWriteArrayBuffer(arrayBuffer); |
429 } | 522 } |
430 | 523 |
431 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) | 524 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) |
432 { | 525 { |
433 append(ArrayBufferViewTag); | 526 append(ArrayBufferViewTag); |
434 #ifndef NDEBUG | 527 #ifndef NDEBUG |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 doWriteUint32(static_cast<uint32_t>(length)); | 679 doWriteUint32(static_cast<uint32_t>(length)); |
587 append(reinterpret_cast<const uint8_t*>(data), length); | 680 append(reinterpret_cast<const uint8_t*>(data), length); |
588 } | 681 } |
589 | 682 |
590 void doWriteWebCoreString(const String& string) | 683 void doWriteWebCoreString(const String& string) |
591 { | 684 { |
592 StringUTF8Adaptor stringUTF8(string); | 685 StringUTF8Adaptor stringUTF8(string); |
593 doWriteString(stringUTF8.data(), stringUTF8.length()); | 686 doWriteString(stringUTF8.data(), stringUTF8.length()); |
594 } | 687 } |
595 | 688 |
| 689 void doWriteHmacKey(const blink::WebCryptoKey& key) |
| 690 { |
| 691 ASSERT(key.algorithm().paramsType() == blink::WebCryptoKeyAlgorithmParam
sTypeHmac); |
| 692 |
| 693 append(static_cast<uint8_t>(HmacKeyTag)); |
| 694 doWriteAlgorithmId(key.algorithm().hmacParams()->hash().id()); |
| 695 } |
| 696 |
| 697 void doWriteAesKey(const blink::WebCryptoKey& key) |
| 698 { |
| 699 ASSERT(key.algorithm().paramsType() == blink::WebCryptoKeyAlgorithmParam
sTypeAes); |
| 700 |
| 701 append(static_cast<uint8_t>(AesKeyTag)); |
| 702 doWriteAlgorithmId(key.algorithm().id()); |
| 703 // Converting the key length from bits to bytes is lossless and makes |
| 704 // it fit in 1 byte. |
| 705 doWriteUint32(static_cast<uint8_t>(key.algorithm().aesParams()->lengthBi
ts() / 8)); |
| 706 } |
| 707 |
| 708 void doWriteRsaKey(const blink::WebCryptoKey& key) |
| 709 { |
| 710 if (key.algorithm().rsaHashedParams()) |
| 711 append(static_cast<uint8_t>(RsaHashedKeyTag)); |
| 712 else |
| 713 append(static_cast<uint8_t>(RsaKeyTag)); |
| 714 |
| 715 doWriteAlgorithmId(key.algorithm().id()); |
| 716 |
| 717 switch (key.type()) { |
| 718 case blink::WebCryptoKeyTypePublic: |
| 719 doWriteUint32(PublicKeyType); |
| 720 break; |
| 721 case blink::WebCryptoKeyTypePrivate: |
| 722 doWriteUint32(PrivateKeyType); |
| 723 break; |
| 724 case blink::WebCryptoKeyTypeSecret: |
| 725 ASSERT_NOT_REACHED(); |
| 726 } |
| 727 |
| 728 const blink::WebCryptoRsaKeyAlgorithmParams* params = key.algorithm().rs
aParams(); |
| 729 doWriteUint32(params->modulusLengthBits()); |
| 730 doWriteUint32(params->publicExponent().size()); |
| 731 append(params->publicExponent().data(), params->publicExponent().size())
; |
| 732 |
| 733 if (key.algorithm().rsaHashedParams()) |
| 734 doWriteAlgorithmId(key.algorithm().rsaHashedParams()->hash().id()); |
| 735 } |
| 736 |
| 737 void doWriteAlgorithmId(blink::WebCryptoAlgorithmId id) |
| 738 { |
| 739 switch (id) { |
| 740 case blink::WebCryptoAlgorithmIdAesCbc: |
| 741 return doWriteUint32(AesCbcTag); |
| 742 case blink::WebCryptoAlgorithmIdHmac: |
| 743 return doWriteUint32(HmacTag); |
| 744 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 745 return doWriteUint32(RsaSsaPkcs1v1_5Tag); |
| 746 case blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5: |
| 747 return doWriteUint32(RsaEsPkcs1v1_5Tag); |
| 748 case blink::WebCryptoAlgorithmIdSha1: |
| 749 return doWriteUint32(Sha1Tag); |
| 750 case blink::WebCryptoAlgorithmIdSha224: |
| 751 return doWriteUint32(Sha224Tag); |
| 752 case blink::WebCryptoAlgorithmIdSha256: |
| 753 return doWriteUint32(Sha256Tag); |
| 754 case blink::WebCryptoAlgorithmIdSha384: |
| 755 return doWriteUint32(Sha384Tag); |
| 756 case blink::WebCryptoAlgorithmIdSha512: |
| 757 return doWriteUint32(Sha512Tag); |
| 758 case blink::WebCryptoAlgorithmIdAesGcm: |
| 759 return doWriteUint32(AesGcmTag); |
| 760 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 761 return doWriteUint32(RsaOaepTag); |
| 762 case blink::WebCryptoAlgorithmIdAesCtr: |
| 763 return doWriteUint32(AesCtrTag); |
| 764 case blink::WebCryptoAlgorithmIdAesKw: |
| 765 return doWriteUint32(AesKwTag); |
| 766 } |
| 767 ASSERT_NOT_REACHED(); |
| 768 } |
| 769 |
| 770 void doWriteKeyUsages(const blink::WebCryptoKeyUsageMask usages, bool extrac
table) |
| 771 { |
| 772 // Reminder to update this when adding new key usages. |
| 773 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
| 774 |
| 775 uint32_t value = 0; |
| 776 |
| 777 if (extractable) |
| 778 value |= ExtractableUsage; |
| 779 |
| 780 if (usages & blink::WebCryptoKeyUsageEncrypt) |
| 781 value |= EncryptUsage; |
| 782 if (usages & blink::WebCryptoKeyUsageDecrypt) |
| 783 value |= DecryptUsage; |
| 784 if (usages & blink::WebCryptoKeyUsageSign) |
| 785 value |= SignUsage; |
| 786 if (usages & blink::WebCryptoKeyUsageVerify) |
| 787 value |= VerifyUsage; |
| 788 if (usages & blink::WebCryptoKeyUsageDeriveKey) |
| 789 value |= DeriveKeyUsage; |
| 790 if (usages & blink::WebCryptoKeyUsageWrapKey) |
| 791 value |= WrapKeyUsage; |
| 792 if (usages & blink::WebCryptoKeyUsageUnwrapKey) |
| 793 value |= UnwrapKeyUsage; |
| 794 |
| 795 doWriteUint32(value); |
| 796 } |
| 797 |
596 int bytesNeededToWireEncode(uint32_t value) | 798 int bytesNeededToWireEncode(uint32_t value) |
597 { | 799 { |
598 int bytes = 1; | 800 int bytes = 1; |
599 while (true) { | 801 while (true) { |
600 value >>= varIntShift; | 802 value >>= varIntShift; |
601 if (!value) | 803 if (!value) |
602 break; | 804 break; |
603 ++bytes; | 805 ++bytes; |
604 } | 806 } |
605 | 807 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 { | 1293 { |
1092 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1294 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); |
1093 if (!fileList) | 1295 if (!fileList) |
1094 return; | 1296 return; |
1095 m_writer.writeFileList(*fileList); | 1297 m_writer.writeFileList(*fileList); |
1096 unsigned length = fileList->length(); | 1298 unsigned length = fileList->length(); |
1097 for (unsigned i = 0; i < length; ++i) | 1299 for (unsigned i = 0; i < length; ++i) |
1098 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)->
blobDataHandle()); | 1300 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)->
blobDataHandle()); |
1099 } | 1301 } |
1100 | 1302 |
| 1303 StateBase* writeCryptoKey(v8::Handle<v8::Value> value, StateBase* next) |
| 1304 { |
| 1305 Key* key = V8Key::toNative(value.As<v8::Object>()); |
| 1306 if (!key) |
| 1307 return 0; |
| 1308 |
| 1309 String errorMessage; |
| 1310 if (!m_writer.writeCryptoKey(key->key(), errorMessage)) |
| 1311 return handleError(DataCloneError, errorMessage, next); |
| 1312 return 0; |
| 1313 } |
| 1314 |
1101 void writeImageData(v8::Handle<v8::Value> value) | 1315 void writeImageData(v8::Handle<v8::Value> value) |
1102 { | 1316 { |
1103 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1317 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); |
1104 if (!imageData) | 1318 if (!imageData) |
1105 return; | 1319 return; |
1106 Uint8ClampedArray* pixelArray = imageData->data(); | 1320 Uint8ClampedArray* pixelArray = imageData->data(); |
1107 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); | 1321 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); |
1108 } | 1322 } |
1109 | 1323 |
1110 void writeRegExp(v8::Handle<v8::Value> value) | 1324 void writeRegExp(v8::Handle<v8::Value> value) |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 else if (value->IsArray()) { | 1500 else if (value->IsArray()) { |
1287 return startArrayState(value.As<v8::Array>(), next); | 1501 return startArrayState(value.As<v8::Array>(), next); |
1288 } else if (V8File::hasInstance(value, m_isolate)) | 1502 } else if (V8File::hasInstance(value, m_isolate)) |
1289 return writeFile(value, next); | 1503 return writeFile(value, next); |
1290 else if (V8Blob::hasInstance(value, m_isolate)) | 1504 else if (V8Blob::hasInstance(value, m_isolate)) |
1291 return writeBlob(value, next); | 1505 return writeBlob(value, next); |
1292 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) | 1506 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) |
1293 return writeDOMFileSystem(value, next); | 1507 return writeDOMFileSystem(value, next); |
1294 else if (V8FileList::hasInstance(value, m_isolate)) | 1508 else if (V8FileList::hasInstance(value, m_isolate)) |
1295 writeFileList(value); | 1509 writeFileList(value); |
| 1510 else if (V8Key::hasInstance(value, m_isolate)) |
| 1511 return writeCryptoKey(value, next); |
1296 else if (V8ImageData::hasInstance(value, m_isolate)) | 1512 else if (V8ImageData::hasInstance(value, m_isolate)) |
1297 writeImageData(value); | 1513 writeImageData(value); |
1298 else if (value->IsRegExp()) | 1514 else if (value->IsRegExp()) |
1299 writeRegExp(value); | 1515 writeRegExp(value); |
1300 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) | 1516 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) |
1301 return writeArrayBuffer(value, next); | 1517 return writeArrayBuffer(value, next); |
1302 else if (value->IsObject()) { | 1518 else if (value->IsObject()) { |
1303 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) | 1519 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) |
1304 return handleError(DataCloneError, "An object could not be clone
d.", next); | 1520 return handleError(DataCloneError, "An object could not be clone
d.", next); |
1305 return startObjectState(jsObject, next); | 1521 return startObjectState(jsObject, next); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 case DOMFileSystemTag: | 1655 case DOMFileSystemTag: |
1440 if (!readDOMFileSystem(value)) | 1656 if (!readDOMFileSystem(value)) |
1441 return false; | 1657 return false; |
1442 creator.pushObjectReference(*value); | 1658 creator.pushObjectReference(*value); |
1443 break; | 1659 break; |
1444 case FileListTag: | 1660 case FileListTag: |
1445 if (!readFileList(value)) | 1661 if (!readFileList(value)) |
1446 return false; | 1662 return false; |
1447 creator.pushObjectReference(*value); | 1663 creator.pushObjectReference(*value); |
1448 break; | 1664 break; |
| 1665 case CryptoKeyTag: |
| 1666 if (!readCryptoKey(value)) |
| 1667 return false; |
| 1668 creator.pushObjectReference(*value); |
| 1669 break; |
1449 case ImageDataTag: | 1670 case ImageDataTag: |
1450 if (!readImageData(value)) | 1671 if (!readImageData(value)) |
1451 return false; | 1672 return false; |
1452 creator.pushObjectReference(*value); | 1673 creator.pushObjectReference(*value); |
1453 break; | 1674 break; |
1454 | 1675 |
1455 case RegExpTag: | 1676 case RegExpTag: |
1456 if (!readRegExp(value)) | 1677 if (!readRegExp(value)) |
1457 return false; | 1678 return false; |
1458 creator.pushObjectReference(*value); | 1679 creator.pushObjectReference(*value); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 for (unsigned i = 0; i < length; ++i) { | 2123 for (unsigned i = 0; i < length; ++i) { |
1903 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); | 2124 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); |
1904 if (!file) | 2125 if (!file) |
1905 return false; | 2126 return false; |
1906 fileList->append(file.release()); | 2127 fileList->append(file.release()); |
1907 } | 2128 } |
1908 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); | 2129 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); |
1909 return true; | 2130 return true; |
1910 } | 2131 } |
1911 | 2132 |
| 2133 bool readCryptoKey(v8::Handle<v8::Value>* value) |
| 2134 { |
| 2135 uint32_t rawKeyType; |
| 2136 if (!doReadUint32(&rawKeyType)) |
| 2137 return false; |
| 2138 |
| 2139 blink::WebCryptoKeyAlgorithm algorithm; |
| 2140 blink::WebCryptoKeyType type; |
| 2141 |
| 2142 switch (static_cast<CryptoKeySubTag>(rawKeyType)) { |
| 2143 case AesKeyTag: |
| 2144 if (!doReadAesKey(algorithm, type)) |
| 2145 return false; |
| 2146 break; |
| 2147 case HmacKeyTag: |
| 2148 if (!doReadHmacKey(algorithm, type)) |
| 2149 return false; |
| 2150 break; |
| 2151 case RsaKeyTag: |
| 2152 if (!doReadRsaKey(false, algorithm, type)) |
| 2153 return false; |
| 2154 break; |
| 2155 case RsaHashedKeyTag: |
| 2156 if (!doReadRsaKey(true, algorithm, type)) |
| 2157 return false; |
| 2158 break; |
| 2159 default: |
| 2160 return false; |
| 2161 } |
| 2162 |
| 2163 blink::WebCryptoKeyUsageMask usages; |
| 2164 bool extractable; |
| 2165 if (!doReadKeyUsages(usages, extractable)) |
| 2166 return false; |
| 2167 |
| 2168 uint32_t keyDataLength; |
| 2169 if (!doReadUint32(&keyDataLength)) |
| 2170 return false; |
| 2171 |
| 2172 if (m_position + keyDataLength > m_length) |
| 2173 return false; |
| 2174 |
| 2175 const uint8_t* keyData = m_buffer + m_position; |
| 2176 m_position += keyDataLength; |
| 2177 |
| 2178 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 2179 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( |
| 2180 algorithm, type, extractable, usages, keyData, keyDataLength, key))
{ |
| 2181 return false; |
| 2182 } |
| 2183 |
| 2184 RefPtrWillBeRawPtr<Key> k = Key::create(key); |
| 2185 *value = toV8(k.release(), v8::Handle<v8::Object>(), m_isolate); |
| 2186 return true; |
| 2187 } |
| 2188 |
1912 PassRefPtrWillBeRawPtr<File> doReadFileHelper() | 2189 PassRefPtrWillBeRawPtr<File> doReadFileHelper() |
1913 { | 2190 { |
1914 if (m_version < 3) | 2191 if (m_version < 3) |
1915 return nullptr; | 2192 return nullptr; |
1916 String path; | 2193 String path; |
1917 String name; | 2194 String name; |
1918 String relativePath; | 2195 String relativePath; |
1919 String uuid; | 2196 String uuid; |
1920 String type; | 2197 String type; |
1921 uint32_t hasSnapshot = 0; | 2198 uint32_t hasSnapshot = 0; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 // the blob in the src process happens to still exist at the time the de
st process is deserializing. | 2268 // the blob in the src process happens to still exist at the time the de
st process is deserializing. |
1992 // For example in sharedWorker.postMesssage(...). | 2269 // For example in sharedWorker.postMesssage(...). |
1993 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); | 2270 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); |
1994 if (it != m_blobDataHandles.end()) { | 2271 if (it != m_blobDataHandles.end()) { |
1995 // make assertions about type and size? | 2272 // make assertions about type and size? |
1996 return it->value; | 2273 return it->value; |
1997 } | 2274 } |
1998 return BlobDataHandle::create(uuid, type, size); | 2275 return BlobDataHandle::create(uuid, type, size); |
1999 } | 2276 } |
2000 | 2277 |
| 2278 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto
KeyType& type) |
| 2279 { |
| 2280 blink::WebCryptoAlgorithmId hash; |
| 2281 if (!doReadAlgorithmId(hash)) |
| 2282 return false; |
| 2283 algorithm = blink::WebCryptoKeyAlgorithm::createHmac(hash); |
| 2284 type = blink::WebCryptoKeyTypeSecret; |
| 2285 return !algorithm.isNull(); |
| 2286 } |
| 2287 |
| 2288 bool doReadAesKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCryptoK
eyType& type) |
| 2289 { |
| 2290 blink::WebCryptoAlgorithmId id; |
| 2291 if (!doReadAlgorithmId(id)) |
| 2292 return false; |
| 2293 uint32_t lengthBytes; |
| 2294 if (!doReadUint32(&lengthBytes)) |
| 2295 return false; |
| 2296 algorithm = blink::WebCryptoKeyAlgorithm::createAes(id, lengthBytes * 8)
; |
| 2297 type = blink::WebCryptoKeyTypeSecret; |
| 2298 return !algorithm.isNull(); |
| 2299 } |
| 2300 |
| 2301 bool doReadRsaKey(bool hasHash, blink::WebCryptoKeyAlgorithm& algorithm, bli
nk::WebCryptoKeyType& type) |
| 2302 { |
| 2303 blink::WebCryptoAlgorithmId id; |
| 2304 if (!doReadAlgorithmId(id)) |
| 2305 return false; |
| 2306 |
| 2307 uint32_t rawType; |
| 2308 if (!doReadUint32(&rawType)) |
| 2309 return false; |
| 2310 |
| 2311 switch (static_cast<AssymetricCryptoKeyType>(rawType)) { |
| 2312 case PublicKeyType: |
| 2313 type = blink::WebCryptoKeyTypePublic; |
| 2314 break; |
| 2315 case PrivateKeyType: |
| 2316 type = blink::WebCryptoKeyTypePrivate; |
| 2317 break; |
| 2318 default: |
| 2319 return false; |
| 2320 } |
| 2321 |
| 2322 uint32_t modulusLengthBits; |
| 2323 if (!doReadUint32(&modulusLengthBits)) |
| 2324 return false; |
| 2325 |
| 2326 uint32_t publicExponentSize; |
| 2327 if (!doReadUint32(&publicExponentSize)) |
| 2328 return false; |
| 2329 |
| 2330 if (m_position + publicExponentSize > m_length) |
| 2331 return false; |
| 2332 |
| 2333 const uint8_t* publicExponent = m_buffer + m_position; |
| 2334 m_position += publicExponentSize; |
| 2335 |
| 2336 if (hasHash) { |
| 2337 blink::WebCryptoAlgorithmId hash; |
| 2338 if (!doReadAlgorithmId(hash)) |
| 2339 return false; |
| 2340 algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed(id, modulu
sLengthBits, publicExponent, publicExponentSize, hash); |
| 2341 } else { |
| 2342 algorithm = blink::WebCryptoKeyAlgorithm::createRsa(id, modulusLengt
hBits, publicExponent, publicExponentSize); |
| 2343 } |
| 2344 |
| 2345 return !algorithm.isNull(); |
| 2346 } |
| 2347 |
| 2348 bool doReadAlgorithmId(blink::WebCryptoAlgorithmId& id) |
| 2349 { |
| 2350 uint32_t rawId; |
| 2351 if (!doReadUint32(&rawId)) |
| 2352 return false; |
| 2353 |
| 2354 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { |
| 2355 case AesCbcTag: |
| 2356 id = blink::WebCryptoAlgorithmIdAesCbc; |
| 2357 return true; |
| 2358 case HmacTag: |
| 2359 id = blink::WebCryptoAlgorithmIdHmac; |
| 2360 return true; |
| 2361 case RsaSsaPkcs1v1_5Tag: |
| 2362 id = blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; |
| 2363 return true; |
| 2364 case RsaEsPkcs1v1_5Tag: |
| 2365 id = blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5; |
| 2366 return true; |
| 2367 case Sha1Tag: |
| 2368 id = blink::WebCryptoAlgorithmIdSha1; |
| 2369 return true; |
| 2370 case Sha224Tag: |
| 2371 id = blink::WebCryptoAlgorithmIdSha224; |
| 2372 return true; |
| 2373 case Sha256Tag: |
| 2374 id = blink::WebCryptoAlgorithmIdSha256; |
| 2375 return true; |
| 2376 case Sha384Tag: |
| 2377 id = blink::WebCryptoAlgorithmIdSha384; |
| 2378 return true; |
| 2379 case Sha512Tag: |
| 2380 id = blink::WebCryptoAlgorithmIdSha512; |
| 2381 return true; |
| 2382 case AesGcmTag: |
| 2383 id = blink::WebCryptoAlgorithmIdAesGcm; |
| 2384 return true; |
| 2385 case RsaOaepTag: |
| 2386 id = blink::WebCryptoAlgorithmIdRsaOaep; |
| 2387 return true; |
| 2388 case AesCtrTag: |
| 2389 id = blink::WebCryptoAlgorithmIdAesCtr; |
| 2390 return true; |
| 2391 case AesKwTag: |
| 2392 id = blink::WebCryptoAlgorithmIdAesKw; |
| 2393 return true; |
| 2394 } |
| 2395 |
| 2396 return false; |
| 2397 } |
| 2398 |
| 2399 bool doReadKeyUsages(blink::WebCryptoKeyUsageMask& usages, bool& extractable
) |
| 2400 { |
| 2401 // Reminder to update this when adding new key usages. |
| 2402 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
| 2403 |
| 2404 uint32_t rawUsages; |
| 2405 if (!doReadUint32(&rawUsages)) |
| 2406 return false; |
| 2407 |
| 2408 usages = 0; |
| 2409 |
| 2410 extractable = rawUsages & ExtractableUsage; |
| 2411 |
| 2412 if (rawUsages & EncryptUsage) |
| 2413 usages |= blink::WebCryptoKeyUsageEncrypt; |
| 2414 if (rawUsages & DecryptUsage) |
| 2415 usages |= blink::WebCryptoKeyUsageDecrypt; |
| 2416 if (rawUsages & SignUsage) |
| 2417 usages |= blink::WebCryptoKeyUsageSign; |
| 2418 if (rawUsages & VerifyUsage) |
| 2419 usages |= blink::WebCryptoKeyUsageVerify; |
| 2420 if (rawUsages & DeriveKeyUsage) |
| 2421 usages |= blink::WebCryptoKeyUsageDeriveKey; |
| 2422 if (rawUsages & WrapKeyUsage) |
| 2423 usages |= blink::WebCryptoKeyUsageWrapKey; |
| 2424 if (rawUsages & UnwrapKeyUsage) |
| 2425 usages |= blink::WebCryptoKeyUsageUnwrapKey; |
| 2426 |
| 2427 // Note that if the serialized data contained an unrecognized usage it |
| 2428 // is silenty discarded here rather than erroring. |
| 2429 |
| 2430 return true; |
| 2431 } |
| 2432 |
2001 const uint8_t* m_buffer; | 2433 const uint8_t* m_buffer; |
2002 const unsigned m_length; | 2434 const unsigned m_length; |
2003 unsigned m_position; | 2435 unsigned m_position; |
2004 uint32_t m_version; | 2436 uint32_t m_version; |
2005 v8::Isolate* m_isolate; | 2437 v8::Isolate* m_isolate; |
2006 const BlobDataHandleMap& m_blobDataHandles; | 2438 const BlobDataHandleMap& m_blobDataHandles; |
2007 }; | 2439 }; |
2008 | 2440 |
2009 | 2441 |
2010 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 2442 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2510 // If the allocated memory was not registered before, then this class is lik
ely | 2942 // If the allocated memory was not registered before, then this class is lik
ely |
2511 // used in a context other then Worker's onmessage environment and the prese
nce of | 2943 // used in a context other then Worker's onmessage environment and the prese
nce of |
2512 // current v8 context is not guaranteed. Avoid calling v8 then. | 2944 // current v8 context is not guaranteed. Avoid calling v8 then. |
2513 if (m_externallyAllocatedMemory) { | 2945 if (m_externallyAllocatedMemory) { |
2514 ASSERT(v8::Isolate::GetCurrent()); | 2946 ASSERT(v8::Isolate::GetCurrent()); |
2515 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 2947 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
2516 } | 2948 } |
2517 } | 2949 } |
2518 | 2950 |
2519 } // namespace WebCore | 2951 } // namespace WebCore |
OLD | NEW |