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:uint32_t, algorithmId:ui
nt32_t |
| 220 // If subtag=HmacKeyTag: |
| 221 // props = keyLengthBytes:uint32_t, 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 255 |
| 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 Sha256Tag = 6, |
| 272 Sha384Tag = 7, |
| 273 Sha512Tag = 8, |
| 274 AesGcmTag = 9, |
| 275 RsaOaepTag = 10, |
| 276 AesCtrTag = 11, |
| 277 AesKwTag = 12, |
| 278 // Maximum allowed value is 2^32-1 |
| 279 }; |
| 280 |
| 281 enum CryptoKeyUsage { |
| 282 // Extractability is not a "usage" in the WebCryptoKeyUsages sense, however |
| 283 // it fits conveniently into this bitfield. |
| 284 ExtractableUsage = 1 << 0, |
| 285 |
| 286 EncryptUsage = 1 << 1, |
| 287 DecryptUsage = 1 << 2, |
| 288 SignUsage = 1 << 3, |
| 289 VerifyUsage = 1 << 4, |
| 290 DeriveKeyUsage = 1 << 5, |
| 291 WrapKeyUsage = 1 << 6, |
| 292 UnwrapKeyUsage = 1 << 7, |
| 293 // Maximum allowed value is 1 << 31 |
| 294 }; |
| 295 |
237 static bool shouldCheckForCycles(int depth) | 296 static bool shouldCheckForCycles(int depth) |
238 { | 297 { |
239 ASSERT(depth >= 0); | 298 ASSERT(depth >= 0); |
240 // Since we are not required to spot the cycle as soon as it | 299 // 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 | 300 // happens we can check for cycles only when the current depth |
242 // is a power of two. | 301 // is a power of two. |
243 return !(depth & (depth - 1)); | 302 return !(depth & (depth - 1)); |
244 } | 303 } |
245 | 304 |
246 static const int maxDepth = 20000; | 305 static const int maxDepth = 20000; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 | 474 |
416 void writeFileList(const FileList& fileList) | 475 void writeFileList(const FileList& fileList) |
417 { | 476 { |
418 append(FileListTag); | 477 append(FileListTag); |
419 uint32_t length = fileList.length(); | 478 uint32_t length = fileList.length(); |
420 doWriteUint32(length); | 479 doWriteUint32(length); |
421 for (unsigned i = 0; i < length; ++i) | 480 for (unsigned i = 0; i < length; ++i) |
422 doWriteFile(*fileList.item(i)); | 481 doWriteFile(*fileList.item(i)); |
423 } | 482 } |
424 | 483 |
| 484 bool writeCryptoKey(const blink::WebCryptoKey& key) |
| 485 { |
| 486 append(static_cast<uint8_t>(CryptoKeyTag)); |
| 487 |
| 488 switch (key.algorithm().paramsType()) { |
| 489 case blink::WebCryptoKeyAlgorithmParamsTypeAes: |
| 490 doWriteAesKey(key); |
| 491 break; |
| 492 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: |
| 493 doWriteHmacKey(key); |
| 494 break; |
| 495 case blink::WebCryptoKeyAlgorithmParamsTypeRsa: |
| 496 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
| 497 doWriteRsaKey(key); |
| 498 break; |
| 499 case blink::WebCryptoKeyAlgorithmParamsTypeNone: |
| 500 ASSERT_NOT_REACHED(); |
| 501 return false; |
| 502 } |
| 503 |
| 504 doWriteKeyUsages(key.usages(), key.extractable()); |
| 505 |
| 506 blink::WebVector<uint8_t> keyData; |
| 507 if (!blink::Platform::current()->crypto()->serializeKeyForClone(key, key
Data)) |
| 508 return false; |
| 509 |
| 510 doWriteUint32(keyData.size()); |
| 511 append(keyData.data(), keyData.size()); |
| 512 return true; |
| 513 } |
| 514 |
425 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 515 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) |
426 { | 516 { |
427 append(ArrayBufferTag); | 517 append(ArrayBufferTag); |
428 doWriteArrayBuffer(arrayBuffer); | 518 doWriteArrayBuffer(arrayBuffer); |
429 } | 519 } |
430 | 520 |
431 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) | 521 void writeArrayBufferView(const ArrayBufferView& arrayBufferView) |
432 { | 522 { |
433 append(ArrayBufferViewTag); | 523 append(ArrayBufferViewTag); |
434 #ifndef NDEBUG | 524 #ifndef NDEBUG |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 doWriteUint32(static_cast<uint32_t>(length)); | 676 doWriteUint32(static_cast<uint32_t>(length)); |
587 append(reinterpret_cast<const uint8_t*>(data), length); | 677 append(reinterpret_cast<const uint8_t*>(data), length); |
588 } | 678 } |
589 | 679 |
590 void doWriteWebCoreString(const String& string) | 680 void doWriteWebCoreString(const String& string) |
591 { | 681 { |
592 StringUTF8Adaptor stringUTF8(string); | 682 StringUTF8Adaptor stringUTF8(string); |
593 doWriteString(stringUTF8.data(), stringUTF8.length()); | 683 doWriteString(stringUTF8.data(), stringUTF8.length()); |
594 } | 684 } |
595 | 685 |
| 686 void doWriteHmacKey(const blink::WebCryptoKey& key) |
| 687 { |
| 688 ASSERT(key.algorithm().paramsType() == blink::WebCryptoKeyAlgorithmParam
sTypeHmac); |
| 689 |
| 690 append(static_cast<uint8_t>(HmacKeyTag)); |
| 691 ASSERT(!(key.algorithm().hmacParams()->lengthBits() % 8)); |
| 692 doWriteUint32(key.algorithm().hmacParams()->lengthBits() / 8); |
| 693 doWriteAlgorithmId(key.algorithm().hmacParams()->hash().id()); |
| 694 } |
| 695 |
| 696 void doWriteAesKey(const blink::WebCryptoKey& key) |
| 697 { |
| 698 ASSERT(key.algorithm().paramsType() == blink::WebCryptoKeyAlgorithmParam
sTypeAes); |
| 699 |
| 700 append(static_cast<uint8_t>(AesKeyTag)); |
| 701 doWriteAlgorithmId(key.algorithm().id()); |
| 702 // Converting the key length from bits to bytes is lossless and makes |
| 703 // it fit in 1 byte. |
| 704 ASSERT(!(key.algorithm().aesParams()->lengthBits() % 8)); |
| 705 doWriteUint32(key.algorithm().aesParams()->lengthBits() / 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::WebCryptoAlgorithmIdSha256: |
| 751 return doWriteUint32(Sha256Tag); |
| 752 case blink::WebCryptoAlgorithmIdSha384: |
| 753 return doWriteUint32(Sha384Tag); |
| 754 case blink::WebCryptoAlgorithmIdSha512: |
| 755 return doWriteUint32(Sha512Tag); |
| 756 case blink::WebCryptoAlgorithmIdAesGcm: |
| 757 return doWriteUint32(AesGcmTag); |
| 758 case blink::WebCryptoAlgorithmIdRsaOaep: |
| 759 return doWriteUint32(RsaOaepTag); |
| 760 case blink::WebCryptoAlgorithmIdAesCtr: |
| 761 return doWriteUint32(AesCtrTag); |
| 762 case blink::WebCryptoAlgorithmIdAesKw: |
| 763 return doWriteUint32(AesKwTag); |
| 764 } |
| 765 ASSERT_NOT_REACHED(); |
| 766 } |
| 767 |
| 768 void doWriteKeyUsages(const blink::WebCryptoKeyUsageMask usages, bool extrac
table) |
| 769 { |
| 770 // Reminder to update this when adding new key usages. |
| 771 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 6) + 1, UpdateMe); |
| 772 |
| 773 uint32_t value = 0; |
| 774 |
| 775 if (extractable) |
| 776 value |= ExtractableUsage; |
| 777 |
| 778 if (usages & blink::WebCryptoKeyUsageEncrypt) |
| 779 value |= EncryptUsage; |
| 780 if (usages & blink::WebCryptoKeyUsageDecrypt) |
| 781 value |= DecryptUsage; |
| 782 if (usages & blink::WebCryptoKeyUsageSign) |
| 783 value |= SignUsage; |
| 784 if (usages & blink::WebCryptoKeyUsageVerify) |
| 785 value |= VerifyUsage; |
| 786 if (usages & blink::WebCryptoKeyUsageDeriveKey) |
| 787 value |= DeriveKeyUsage; |
| 788 if (usages & blink::WebCryptoKeyUsageWrapKey) |
| 789 value |= WrapKeyUsage; |
| 790 if (usages & blink::WebCryptoKeyUsageUnwrapKey) |
| 791 value |= UnwrapKeyUsage; |
| 792 |
| 793 doWriteUint32(value); |
| 794 } |
| 795 |
596 int bytesNeededToWireEncode(uint32_t value) | 796 int bytesNeededToWireEncode(uint32_t value) |
597 { | 797 { |
598 int bytes = 1; | 798 int bytes = 1; |
599 while (true) { | 799 while (true) { |
600 value >>= varIntShift; | 800 value >>= varIntShift; |
601 if (!value) | 801 if (!value) |
602 break; | 802 break; |
603 ++bytes; | 803 ++bytes; |
604 } | 804 } |
605 | 805 |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 { | 1291 { |
1092 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); | 1292 FileList* fileList = V8FileList::toNative(value.As<v8::Object>()); |
1093 if (!fileList) | 1293 if (!fileList) |
1094 return; | 1294 return; |
1095 m_writer.writeFileList(*fileList); | 1295 m_writer.writeFileList(*fileList); |
1096 unsigned length = fileList->length(); | 1296 unsigned length = fileList->length(); |
1097 for (unsigned i = 0; i < length; ++i) | 1297 for (unsigned i = 0; i < length; ++i) |
1098 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)->
blobDataHandle()); | 1298 m_blobDataHandles.add(fileList->item(i)->uuid(), fileList->item(i)->
blobDataHandle()); |
1099 } | 1299 } |
1100 | 1300 |
| 1301 bool writeCryptoKey(v8::Handle<v8::Value> value) |
| 1302 { |
| 1303 Key* key = V8Key::toNative(value.As<v8::Object>()); |
| 1304 if (!key) |
| 1305 return 0; |
| 1306 return m_writer.writeCryptoKey(key->key()); |
| 1307 } |
| 1308 |
1101 void writeImageData(v8::Handle<v8::Value> value) | 1309 void writeImageData(v8::Handle<v8::Value> value) |
1102 { | 1310 { |
1103 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); | 1311 ImageData* imageData = V8ImageData::toNative(value.As<v8::Object>()); |
1104 if (!imageData) | 1312 if (!imageData) |
1105 return; | 1313 return; |
1106 Uint8ClampedArray* pixelArray = imageData->data(); | 1314 Uint8ClampedArray* pixelArray = imageData->data(); |
1107 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); | 1315 m_writer.writeImageData(imageData->width(), imageData->height(), pixelAr
ray->data(), pixelArray->length()); |
1108 } | 1316 } |
1109 | 1317 |
1110 void writeRegExp(v8::Handle<v8::Value> value) | 1318 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()) { | 1494 else if (value->IsArray()) { |
1287 return startArrayState(value.As<v8::Array>(), next); | 1495 return startArrayState(value.As<v8::Array>(), next); |
1288 } else if (V8File::hasInstance(value, m_isolate)) | 1496 } else if (V8File::hasInstance(value, m_isolate)) |
1289 return writeFile(value, next); | 1497 return writeFile(value, next); |
1290 else if (V8Blob::hasInstance(value, m_isolate)) | 1498 else if (V8Blob::hasInstance(value, m_isolate)) |
1291 return writeBlob(value, next); | 1499 return writeBlob(value, next); |
1292 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) | 1500 else if (V8DOMFileSystem::hasInstance(value, m_isolate)) |
1293 return writeDOMFileSystem(value, next); | 1501 return writeDOMFileSystem(value, next); |
1294 else if (V8FileList::hasInstance(value, m_isolate)) | 1502 else if (V8FileList::hasInstance(value, m_isolate)) |
1295 writeFileList(value); | 1503 writeFileList(value); |
1296 else if (V8ImageData::hasInstance(value, m_isolate)) | 1504 else if (V8Key::hasInstance(value, m_isolate)) { |
| 1505 if (!writeCryptoKey(value)) |
| 1506 return handleError(DataCloneError, "Couldn't serialize key data"
, next); |
| 1507 } else if (V8ImageData::hasInstance(value, m_isolate)) |
1297 writeImageData(value); | 1508 writeImageData(value); |
1298 else if (value->IsRegExp()) | 1509 else if (value->IsRegExp()) |
1299 writeRegExp(value); | 1510 writeRegExp(value); |
1300 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) | 1511 else if (V8ArrayBuffer::hasInstance(value, m_isolate)) |
1301 return writeArrayBuffer(value, next); | 1512 return writeArrayBuffer(value, next); |
1302 else if (value->IsObject()) { | 1513 else if (value->IsObject()) { |
1303 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) | 1514 if (isHostObject(jsObject) || jsObject->IsCallable() || value->IsNat
iveError()) |
1304 return handleError(DataCloneError, "An object could not be clone
d.", next); | 1515 return handleError(DataCloneError, "An object could not be clone
d.", next); |
1305 return startObjectState(jsObject, next); | 1516 return startObjectState(jsObject, next); |
1306 } else | 1517 } else |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1439 case DOMFileSystemTag: | 1650 case DOMFileSystemTag: |
1440 if (!readDOMFileSystem(value)) | 1651 if (!readDOMFileSystem(value)) |
1441 return false; | 1652 return false; |
1442 creator.pushObjectReference(*value); | 1653 creator.pushObjectReference(*value); |
1443 break; | 1654 break; |
1444 case FileListTag: | 1655 case FileListTag: |
1445 if (!readFileList(value)) | 1656 if (!readFileList(value)) |
1446 return false; | 1657 return false; |
1447 creator.pushObjectReference(*value); | 1658 creator.pushObjectReference(*value); |
1448 break; | 1659 break; |
| 1660 case CryptoKeyTag: |
| 1661 if (!readCryptoKey(value)) |
| 1662 return false; |
| 1663 creator.pushObjectReference(*value); |
| 1664 break; |
1449 case ImageDataTag: | 1665 case ImageDataTag: |
1450 if (!readImageData(value)) | 1666 if (!readImageData(value)) |
1451 return false; | 1667 return false; |
1452 creator.pushObjectReference(*value); | 1668 creator.pushObjectReference(*value); |
1453 break; | 1669 break; |
1454 | 1670 |
1455 case RegExpTag: | 1671 case RegExpTag: |
1456 if (!readRegExp(value)) | 1672 if (!readRegExp(value)) |
1457 return false; | 1673 return false; |
1458 creator.pushObjectReference(*value); | 1674 creator.pushObjectReference(*value); |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 for (unsigned i = 0; i < length; ++i) { | 2118 for (unsigned i = 0; i < length; ++i) { |
1903 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); | 2119 RefPtrWillBeRawPtr<File> file = doReadFileHelper(); |
1904 if (!file) | 2120 if (!file) |
1905 return false; | 2121 return false; |
1906 fileList->append(file.release()); | 2122 fileList->append(file.release()); |
1907 } | 2123 } |
1908 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); | 2124 *value = toV8(fileList.release(), v8::Handle<v8::Object>(), m_isolate); |
1909 return true; | 2125 return true; |
1910 } | 2126 } |
1911 | 2127 |
| 2128 bool readCryptoKey(v8::Handle<v8::Value>* value) |
| 2129 { |
| 2130 uint32_t rawKeyType; |
| 2131 if (!doReadUint32(&rawKeyType)) |
| 2132 return false; |
| 2133 |
| 2134 blink::WebCryptoKeyAlgorithm algorithm; |
| 2135 blink::WebCryptoKeyType type; |
| 2136 |
| 2137 switch (static_cast<CryptoKeySubTag>(rawKeyType)) { |
| 2138 case AesKeyTag: |
| 2139 if (!doReadAesKey(algorithm, type)) |
| 2140 return false; |
| 2141 break; |
| 2142 case HmacKeyTag: |
| 2143 if (!doReadHmacKey(algorithm, type)) |
| 2144 return false; |
| 2145 break; |
| 2146 case RsaKeyTag: |
| 2147 if (!doReadRsaKey(false, algorithm, type)) |
| 2148 return false; |
| 2149 break; |
| 2150 case RsaHashedKeyTag: |
| 2151 if (!doReadRsaKey(true, algorithm, type)) |
| 2152 return false; |
| 2153 break; |
| 2154 default: |
| 2155 return false; |
| 2156 } |
| 2157 |
| 2158 blink::WebCryptoKeyUsageMask usages; |
| 2159 bool extractable; |
| 2160 if (!doReadKeyUsages(usages, extractable)) |
| 2161 return false; |
| 2162 |
| 2163 uint32_t keyDataLength; |
| 2164 if (!doReadUint32(&keyDataLength)) |
| 2165 return false; |
| 2166 |
| 2167 if (m_position + keyDataLength > m_length) |
| 2168 return false; |
| 2169 |
| 2170 const uint8_t* keyData = m_buffer + m_position; |
| 2171 m_position += keyDataLength; |
| 2172 |
| 2173 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| 2174 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( |
| 2175 algorithm, type, extractable, usages, keyData, keyDataLength, key))
{ |
| 2176 return false; |
| 2177 } |
| 2178 |
| 2179 RefPtrWillBeRawPtr<Key> k = Key::create(key); |
| 2180 *value = toV8(k.release(), v8::Handle<v8::Object>(), m_isolate); |
| 2181 return true; |
| 2182 } |
| 2183 |
1912 PassRefPtrWillBeRawPtr<File> doReadFileHelper() | 2184 PassRefPtrWillBeRawPtr<File> doReadFileHelper() |
1913 { | 2185 { |
1914 if (m_version < 3) | 2186 if (m_version < 3) |
1915 return nullptr; | 2187 return nullptr; |
1916 String path; | 2188 String path; |
1917 String name; | 2189 String name; |
1918 String relativePath; | 2190 String relativePath; |
1919 String uuid; | 2191 String uuid; |
1920 String type; | 2192 String type; |
1921 uint32_t hasSnapshot = 0; | 2193 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. | 2263 // 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(...). | 2264 // For example in sharedWorker.postMesssage(...). |
1993 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); | 2265 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); |
1994 if (it != m_blobDataHandles.end()) { | 2266 if (it != m_blobDataHandles.end()) { |
1995 // make assertions about type and size? | 2267 // make assertions about type and size? |
1996 return it->value; | 2268 return it->value; |
1997 } | 2269 } |
1998 return BlobDataHandle::create(uuid, type, size); | 2270 return BlobDataHandle::create(uuid, type, size); |
1999 } | 2271 } |
2000 | 2272 |
| 2273 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto
KeyType& type) |
| 2274 { |
| 2275 uint32_t lengthBytes; |
| 2276 if (!doReadUint32(&lengthBytes)) |
| 2277 return false; |
| 2278 blink::WebCryptoAlgorithmId hash; |
| 2279 if (!doReadAlgorithmId(hash)) |
| 2280 return false; |
| 2281 algorithm = blink::WebCryptoKeyAlgorithm::createHmac(hash, lengthBytes *
8); |
| 2282 type = blink::WebCryptoKeyTypeSecret; |
| 2283 return !algorithm.isNull(); |
| 2284 } |
| 2285 |
| 2286 bool doReadAesKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCryptoK
eyType& type) |
| 2287 { |
| 2288 blink::WebCryptoAlgorithmId id; |
| 2289 if (!doReadAlgorithmId(id)) |
| 2290 return false; |
| 2291 uint32_t lengthBytes; |
| 2292 if (!doReadUint32(&lengthBytes)) |
| 2293 return false; |
| 2294 algorithm = blink::WebCryptoKeyAlgorithm::createAes(id, lengthBytes * 8)
; |
| 2295 type = blink::WebCryptoKeyTypeSecret; |
| 2296 return !algorithm.isNull(); |
| 2297 } |
| 2298 |
| 2299 bool doReadRsaKey(bool hasHash, blink::WebCryptoKeyAlgorithm& algorithm, bli
nk::WebCryptoKeyType& type) |
| 2300 { |
| 2301 blink::WebCryptoAlgorithmId id; |
| 2302 if (!doReadAlgorithmId(id)) |
| 2303 return false; |
| 2304 |
| 2305 uint32_t rawType; |
| 2306 if (!doReadUint32(&rawType)) |
| 2307 return false; |
| 2308 |
| 2309 switch (static_cast<AssymetricCryptoKeyType>(rawType)) { |
| 2310 case PublicKeyType: |
| 2311 type = blink::WebCryptoKeyTypePublic; |
| 2312 break; |
| 2313 case PrivateKeyType: |
| 2314 type = blink::WebCryptoKeyTypePrivate; |
| 2315 break; |
| 2316 default: |
| 2317 return false; |
| 2318 } |
| 2319 |
| 2320 uint32_t modulusLengthBits; |
| 2321 if (!doReadUint32(&modulusLengthBits)) |
| 2322 return false; |
| 2323 |
| 2324 uint32_t publicExponentSize; |
| 2325 if (!doReadUint32(&publicExponentSize)) |
| 2326 return false; |
| 2327 |
| 2328 if (m_position + publicExponentSize > m_length) |
| 2329 return false; |
| 2330 |
| 2331 const uint8_t* publicExponent = m_buffer + m_position; |
| 2332 m_position += publicExponentSize; |
| 2333 |
| 2334 if (hasHash) { |
| 2335 blink::WebCryptoAlgorithmId hash; |
| 2336 if (!doReadAlgorithmId(hash)) |
| 2337 return false; |
| 2338 algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed(id, modulu
sLengthBits, publicExponent, publicExponentSize, hash); |
| 2339 } else { |
| 2340 algorithm = blink::WebCryptoKeyAlgorithm::createRsa(id, modulusLengt
hBits, publicExponent, publicExponentSize); |
| 2341 } |
| 2342 |
| 2343 return !algorithm.isNull(); |
| 2344 } |
| 2345 |
| 2346 bool doReadAlgorithmId(blink::WebCryptoAlgorithmId& id) |
| 2347 { |
| 2348 uint32_t rawId; |
| 2349 if (!doReadUint32(&rawId)) |
| 2350 return false; |
| 2351 |
| 2352 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { |
| 2353 case AesCbcTag: |
| 2354 id = blink::WebCryptoAlgorithmIdAesCbc; |
| 2355 return true; |
| 2356 case HmacTag: |
| 2357 id = blink::WebCryptoAlgorithmIdHmac; |
| 2358 return true; |
| 2359 case RsaSsaPkcs1v1_5Tag: |
| 2360 id = blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; |
| 2361 return true; |
| 2362 case RsaEsPkcs1v1_5Tag: |
| 2363 id = blink::WebCryptoAlgorithmIdRsaEsPkcs1v1_5; |
| 2364 return true; |
| 2365 case Sha1Tag: |
| 2366 id = blink::WebCryptoAlgorithmIdSha1; |
| 2367 return true; |
| 2368 case Sha256Tag: |
| 2369 id = blink::WebCryptoAlgorithmIdSha256; |
| 2370 return true; |
| 2371 case Sha384Tag: |
| 2372 id = blink::WebCryptoAlgorithmIdSha384; |
| 2373 return true; |
| 2374 case Sha512Tag: |
| 2375 id = blink::WebCryptoAlgorithmIdSha512; |
| 2376 return true; |
| 2377 case AesGcmTag: |
| 2378 id = blink::WebCryptoAlgorithmIdAesGcm; |
| 2379 return true; |
| 2380 case RsaOaepTag: |
| 2381 id = blink::WebCryptoAlgorithmIdRsaOaep; |
| 2382 return true; |
| 2383 case AesCtrTag: |
| 2384 id = blink::WebCryptoAlgorithmIdAesCtr; |
| 2385 return true; |
| 2386 case AesKwTag: |
| 2387 id = blink::WebCryptoAlgorithmIdAesKw; |
| 2388 return true; |
| 2389 } |
| 2390 |
| 2391 return false; |
| 2392 } |
| 2393 |
| 2394 bool doReadKeyUsages(blink::WebCryptoKeyUsageMask& usages, bool& extractable
) |
| 2395 { |
| 2396 // Reminder to update this when adding new key usages. |
| 2397 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 6) + 1, UpdateMe); |
| 2398 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec
ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU
sage; |
| 2399 |
| 2400 uint32_t rawUsages; |
| 2401 if (!doReadUint32(&rawUsages)) |
| 2402 return false; |
| 2403 |
| 2404 // Make sure it doesn't contain an unrecognized usage value. |
| 2405 if (rawUsages & ~allPossibleUsages) |
| 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 return true; |
| 2428 } |
| 2429 |
2001 const uint8_t* m_buffer; | 2430 const uint8_t* m_buffer; |
2002 const unsigned m_length; | 2431 const unsigned m_length; |
2003 unsigned m_position; | 2432 unsigned m_position; |
2004 uint32_t m_version; | 2433 uint32_t m_version; |
2005 v8::Isolate* m_isolate; | 2434 v8::Isolate* m_isolate; |
2006 const BlobDataHandleMap& m_blobDataHandles; | 2435 const BlobDataHandleMap& m_blobDataHandles; |
2007 }; | 2436 }; |
2008 | 2437 |
2009 | 2438 |
2010 typedef Vector<WTF::ArrayBufferContents, 1> ArrayBufferContentsArray; | 2439 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 | 2939 // 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 | 2940 // 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. | 2941 // current v8 context is not guaranteed. Avoid calling v8 then. |
2513 if (m_externallyAllocatedMemory) { | 2942 if (m_externallyAllocatedMemory) { |
2514 ASSERT(v8::Isolate::GetCurrent()); | 2943 ASSERT(v8::Isolate::GetCurrent()); |
2515 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 2944 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
2516 } | 2945 } |
2517 } | 2946 } |
2518 | 2947 |
2519 } // namespace WebCore | 2948 } // namespace WebCore |
OLD | NEW |