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 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 | 498 |
499 void writeFileListIndex(const Vector<int>& blobIndices) | 499 void writeFileListIndex(const Vector<int>& blobIndices) |
500 { | 500 { |
501 append(FileListIndexTag); | 501 append(FileListIndexTag); |
502 uint32_t length = blobIndices.size(); | 502 uint32_t length = blobIndices.size(); |
503 doWriteUint32(length); | 503 doWriteUint32(length); |
504 for (unsigned i = 0; i < length; ++i) | 504 for (unsigned i = 0; i < length; ++i) |
505 doWriteUint32(blobIndices[i]); | 505 doWriteUint32(blobIndices[i]); |
506 } | 506 } |
507 | 507 |
508 bool writeCryptoKey(const blink::WebCryptoKey& key) | 508 bool writeCryptoKey(const WebCryptoKey& key) |
509 { | 509 { |
510 append(static_cast<uint8_t>(CryptoKeyTag)); | 510 append(static_cast<uint8_t>(CryptoKeyTag)); |
511 | 511 |
512 switch (key.algorithm().paramsType()) { | 512 switch (key.algorithm().paramsType()) { |
513 case blink::WebCryptoKeyAlgorithmParamsTypeAes: | 513 case WebCryptoKeyAlgorithmParamsTypeAes: |
514 doWriteAesKey(key); | 514 doWriteAesKey(key); |
515 break; | 515 break; |
516 case blink::WebCryptoKeyAlgorithmParamsTypeHmac: | 516 case WebCryptoKeyAlgorithmParamsTypeHmac: |
517 doWriteHmacKey(key); | 517 doWriteHmacKey(key); |
518 break; | 518 break; |
519 case blink::WebCryptoKeyAlgorithmParamsTypeRsaHashed: | 519 case WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
520 doWriteRsaHashedKey(key); | 520 doWriteRsaHashedKey(key); |
521 break; | 521 break; |
522 case blink::WebCryptoKeyAlgorithmParamsTypeNone: | 522 case WebCryptoKeyAlgorithmParamsTypeNone: |
523 ASSERT_NOT_REACHED(); | 523 ASSERT_NOT_REACHED(); |
524 return false; | 524 return false; |
525 } | 525 } |
526 | 526 |
527 doWriteKeyUsages(key.usages(), key.extractable()); | 527 doWriteKeyUsages(key.usages(), key.extractable()); |
528 | 528 |
529 blink::WebVector<uint8_t> keyData; | 529 WebVector<uint8_t> keyData; |
530 if (!blink::Platform::current()->crypto()->serializeKeyForClone(key, key
Data)) | 530 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData)) |
531 return false; | 531 return false; |
532 | 532 |
533 doWriteUint32(keyData.size()); | 533 doWriteUint32(keyData.size()); |
534 append(keyData.data(), keyData.size()); | 534 append(keyData.data(), keyData.size()); |
535 return true; | 535 return true; |
536 } | 536 } |
537 | 537 |
538 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) | 538 void writeArrayBuffer(const ArrayBuffer& arrayBuffer) |
539 { | 539 { |
540 append(ArrayBufferTag); | 540 append(ArrayBufferTag); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 doWriteUint32(static_cast<uint32_t>(length)); | 701 doWriteUint32(static_cast<uint32_t>(length)); |
702 append(reinterpret_cast<const uint8_t*>(data), length); | 702 append(reinterpret_cast<const uint8_t*>(data), length); |
703 } | 703 } |
704 | 704 |
705 void doWriteWebCoreString(const String& string) | 705 void doWriteWebCoreString(const String& string) |
706 { | 706 { |
707 StringUTF8Adaptor stringUTF8(string); | 707 StringUTF8Adaptor stringUTF8(string); |
708 doWriteString(stringUTF8.data(), stringUTF8.length()); | 708 doWriteString(stringUTF8.data(), stringUTF8.length()); |
709 } | 709 } |
710 | 710 |
711 void doWriteHmacKey(const blink::WebCryptoKey& key) | 711 void doWriteHmacKey(const WebCryptoKey& key) |
712 { | 712 { |
713 ASSERT(key.algorithm().paramsType() == blink::WebCryptoKeyAlgorithmParam
sTypeHmac); | 713 ASSERT(key.algorithm().paramsType() == WebCryptoKeyAlgorithmParamsTypeHm
ac); |
714 | 714 |
715 append(static_cast<uint8_t>(HmacKeyTag)); | 715 append(static_cast<uint8_t>(HmacKeyTag)); |
716 ASSERT(!(key.algorithm().hmacParams()->lengthBits() % 8)); | 716 ASSERT(!(key.algorithm().hmacParams()->lengthBits() % 8)); |
717 doWriteUint32(key.algorithm().hmacParams()->lengthBits() / 8); | 717 doWriteUint32(key.algorithm().hmacParams()->lengthBits() / 8); |
718 doWriteAlgorithmId(key.algorithm().hmacParams()->hash().id()); | 718 doWriteAlgorithmId(key.algorithm().hmacParams()->hash().id()); |
719 } | 719 } |
720 | 720 |
721 void doWriteAesKey(const blink::WebCryptoKey& key) | 721 void doWriteAesKey(const WebCryptoKey& key) |
722 { | 722 { |
723 ASSERT(key.algorithm().paramsType() == blink::WebCryptoKeyAlgorithmParam
sTypeAes); | 723 ASSERT(key.algorithm().paramsType() == WebCryptoKeyAlgorithmParamsTypeAe
s); |
724 | 724 |
725 append(static_cast<uint8_t>(AesKeyTag)); | 725 append(static_cast<uint8_t>(AesKeyTag)); |
726 doWriteAlgorithmId(key.algorithm().id()); | 726 doWriteAlgorithmId(key.algorithm().id()); |
727 // Converting the key length from bits to bytes is lossless and makes | 727 // Converting the key length from bits to bytes is lossless and makes |
728 // it fit in 1 byte. | 728 // it fit in 1 byte. |
729 ASSERT(!(key.algorithm().aesParams()->lengthBits() % 8)); | 729 ASSERT(!(key.algorithm().aesParams()->lengthBits() % 8)); |
730 doWriteUint32(key.algorithm().aesParams()->lengthBits() / 8); | 730 doWriteUint32(key.algorithm().aesParams()->lengthBits() / 8); |
731 } | 731 } |
732 | 732 |
733 void doWriteRsaHashedKey(const blink::WebCryptoKey& key) | 733 void doWriteRsaHashedKey(const WebCryptoKey& key) |
734 { | 734 { |
735 ASSERT(key.algorithm().rsaHashedParams()); | 735 ASSERT(key.algorithm().rsaHashedParams()); |
736 append(static_cast<uint8_t>(RsaHashedKeyTag)); | 736 append(static_cast<uint8_t>(RsaHashedKeyTag)); |
737 | 737 |
738 doWriteAlgorithmId(key.algorithm().id()); | 738 doWriteAlgorithmId(key.algorithm().id()); |
739 | 739 |
740 switch (key.type()) { | 740 switch (key.type()) { |
741 case blink::WebCryptoKeyTypePublic: | 741 case WebCryptoKeyTypePublic: |
742 doWriteUint32(PublicKeyType); | 742 doWriteUint32(PublicKeyType); |
743 break; | 743 break; |
744 case blink::WebCryptoKeyTypePrivate: | 744 case WebCryptoKeyTypePrivate: |
745 doWriteUint32(PrivateKeyType); | 745 doWriteUint32(PrivateKeyType); |
746 break; | 746 break; |
747 case blink::WebCryptoKeyTypeSecret: | 747 case WebCryptoKeyTypeSecret: |
748 ASSERT_NOT_REACHED(); | 748 ASSERT_NOT_REACHED(); |
749 } | 749 } |
750 | 750 |
751 const blink::WebCryptoRsaHashedKeyAlgorithmParams* params = key.algorith
m().rsaHashedParams(); | 751 const WebCryptoRsaHashedKeyAlgorithmParams* params = key.algorithm().rsa
HashedParams(); |
752 doWriteUint32(params->modulusLengthBits()); | 752 doWriteUint32(params->modulusLengthBits()); |
753 doWriteUint32(params->publicExponent().size()); | 753 doWriteUint32(params->publicExponent().size()); |
754 append(params->publicExponent().data(), params->publicExponent().size())
; | 754 append(params->publicExponent().data(), params->publicExponent().size())
; |
755 doWriteAlgorithmId(key.algorithm().rsaHashedParams()->hash().id()); | 755 doWriteAlgorithmId(key.algorithm().rsaHashedParams()->hash().id()); |
756 } | 756 } |
757 | 757 |
758 void doWriteAlgorithmId(blink::WebCryptoAlgorithmId id) | 758 void doWriteAlgorithmId(WebCryptoAlgorithmId id) |
759 { | 759 { |
760 switch (id) { | 760 switch (id) { |
761 case blink::WebCryptoAlgorithmIdAesCbc: | 761 case WebCryptoAlgorithmIdAesCbc: |
762 return doWriteUint32(AesCbcTag); | 762 return doWriteUint32(AesCbcTag); |
763 case blink::WebCryptoAlgorithmIdHmac: | 763 case WebCryptoAlgorithmIdHmac: |
764 return doWriteUint32(HmacTag); | 764 return doWriteUint32(HmacTag); |
765 case blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: | 765 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
766 return doWriteUint32(RsaSsaPkcs1v1_5Tag); | 766 return doWriteUint32(RsaSsaPkcs1v1_5Tag); |
767 case blink::WebCryptoAlgorithmIdSha1: | 767 case WebCryptoAlgorithmIdSha1: |
768 return doWriteUint32(Sha1Tag); | 768 return doWriteUint32(Sha1Tag); |
769 case blink::WebCryptoAlgorithmIdSha256: | 769 case WebCryptoAlgorithmIdSha256: |
770 return doWriteUint32(Sha256Tag); | 770 return doWriteUint32(Sha256Tag); |
771 case blink::WebCryptoAlgorithmIdSha384: | 771 case WebCryptoAlgorithmIdSha384: |
772 return doWriteUint32(Sha384Tag); | 772 return doWriteUint32(Sha384Tag); |
773 case blink::WebCryptoAlgorithmIdSha512: | 773 case WebCryptoAlgorithmIdSha512: |
774 return doWriteUint32(Sha512Tag); | 774 return doWriteUint32(Sha512Tag); |
775 case blink::WebCryptoAlgorithmIdAesGcm: | 775 case WebCryptoAlgorithmIdAesGcm: |
776 return doWriteUint32(AesGcmTag); | 776 return doWriteUint32(AesGcmTag); |
777 case blink::WebCryptoAlgorithmIdRsaOaep: | 777 case WebCryptoAlgorithmIdRsaOaep: |
778 return doWriteUint32(RsaOaepTag); | 778 return doWriteUint32(RsaOaepTag); |
779 case blink::WebCryptoAlgorithmIdAesCtr: | 779 case WebCryptoAlgorithmIdAesCtr: |
780 return doWriteUint32(AesCtrTag); | 780 return doWriteUint32(AesCtrTag); |
781 case blink::WebCryptoAlgorithmIdAesKw: | 781 case WebCryptoAlgorithmIdAesKw: |
782 return doWriteUint32(AesKwTag); | 782 return doWriteUint32(AesKwTag); |
783 case blink::WebCryptoAlgorithmIdRsaPss: | 783 case WebCryptoAlgorithmIdRsaPss: |
784 return doWriteUint32(RsaPssTag); | 784 return doWriteUint32(RsaPssTag); |
785 } | 785 } |
786 ASSERT_NOT_REACHED(); | 786 ASSERT_NOT_REACHED(); |
787 } | 787 } |
788 | 788 |
789 void doWriteKeyUsages(const blink::WebCryptoKeyUsageMask usages, bool extrac
table) | 789 void doWriteKeyUsages(const WebCryptoKeyUsageMask usages, bool extractable) |
790 { | 790 { |
791 // Reminder to update this when adding new key usages. | 791 // Reminder to update this when adding new key usages. |
792 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); | 792 COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
793 | 793 |
794 uint32_t value = 0; | 794 uint32_t value = 0; |
795 | 795 |
796 if (extractable) | 796 if (extractable) |
797 value |= ExtractableUsage; | 797 value |= ExtractableUsage; |
798 | 798 |
799 if (usages & blink::WebCryptoKeyUsageEncrypt) | 799 if (usages & WebCryptoKeyUsageEncrypt) |
800 value |= EncryptUsage; | 800 value |= EncryptUsage; |
801 if (usages & blink::WebCryptoKeyUsageDecrypt) | 801 if (usages & WebCryptoKeyUsageDecrypt) |
802 value |= DecryptUsage; | 802 value |= DecryptUsage; |
803 if (usages & blink::WebCryptoKeyUsageSign) | 803 if (usages & WebCryptoKeyUsageSign) |
804 value |= SignUsage; | 804 value |= SignUsage; |
805 if (usages & blink::WebCryptoKeyUsageVerify) | 805 if (usages & WebCryptoKeyUsageVerify) |
806 value |= VerifyUsage; | 806 value |= VerifyUsage; |
807 if (usages & blink::WebCryptoKeyUsageDeriveKey) | 807 if (usages & WebCryptoKeyUsageDeriveKey) |
808 value |= DeriveKeyUsage; | 808 value |= DeriveKeyUsage; |
809 if (usages & blink::WebCryptoKeyUsageWrapKey) | 809 if (usages & WebCryptoKeyUsageWrapKey) |
810 value |= WrapKeyUsage; | 810 value |= WrapKeyUsage; |
811 if (usages & blink::WebCryptoKeyUsageUnwrapKey) | 811 if (usages & WebCryptoKeyUsageUnwrapKey) |
812 value |= UnwrapKeyUsage; | 812 value |= UnwrapKeyUsage; |
813 if (usages & blink::WebCryptoKeyUsageDeriveBits) | 813 if (usages & WebCryptoKeyUsageDeriveBits) |
814 value |= DeriveBitsUsage; | 814 value |= DeriveBitsUsage; |
815 | 815 |
816 doWriteUint32(value); | 816 doWriteUint32(value); |
817 } | 817 } |
818 | 818 |
819 int bytesNeededToWireEncode(uint32_t value) | 819 int bytesNeededToWireEncode(uint32_t value) |
820 { | 820 { |
821 int bytes = 1; | 821 int bytes = 1; |
822 while (true) { | 822 while (true) { |
823 value >>= varIntShift; | 823 value >>= varIntShift; |
(...skipping 1329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 if (m_version < 3) | 2153 if (m_version < 3) |
2154 return false; | 2154 return false; |
2155 Blob* blob = nullptr; | 2155 Blob* blob = nullptr; |
2156 if (isIndexed) { | 2156 if (isIndexed) { |
2157 if (m_version < 6) | 2157 if (m_version < 6) |
2158 return false; | 2158 return false; |
2159 ASSERT(m_blobInfo); | 2159 ASSERT(m_blobInfo); |
2160 uint32_t index; | 2160 uint32_t index; |
2161 if (!doReadUint32(&index) || index >= m_blobInfo->size()) | 2161 if (!doReadUint32(&index) || index >= m_blobInfo->size()) |
2162 return false; | 2162 return false; |
2163 const blink::WebBlobInfo& info = (*m_blobInfo)[index]; | 2163 const WebBlobInfo& info = (*m_blobInfo)[index]; |
2164 blob = Blob::create(getOrCreateBlobDataHandle(info.uuid(), info.type
(), info.size())); | 2164 blob = Blob::create(getOrCreateBlobDataHandle(info.uuid(), info.type
(), info.size())); |
2165 } else { | 2165 } else { |
2166 ASSERT(!m_blobInfo); | 2166 ASSERT(!m_blobInfo); |
2167 String uuid; | 2167 String uuid; |
2168 String type; | 2168 String type; |
2169 uint64_t size; | 2169 uint64_t size; |
2170 ASSERT(!m_blobInfo); | 2170 ASSERT(!m_blobInfo); |
2171 if (!readWebCoreString(&uuid)) | 2171 if (!readWebCoreString(&uuid)) |
2172 return false; | 2172 return false; |
2173 if (!readWebCoreString(&type)) | 2173 if (!readWebCoreString(&type)) |
(...skipping 10 matching lines...) Expand all Loading... |
2184 { | 2184 { |
2185 uint32_t type; | 2185 uint32_t type; |
2186 String name; | 2186 String name; |
2187 String url; | 2187 String url; |
2188 if (!doReadUint32(&type)) | 2188 if (!doReadUint32(&type)) |
2189 return false; | 2189 return false; |
2190 if (!readWebCoreString(&name)) | 2190 if (!readWebCoreString(&name)) |
2191 return false; | 2191 return false; |
2192 if (!readWebCoreString(&url)) | 2192 if (!readWebCoreString(&url)) |
2193 return false; | 2193 return false; |
2194 DOMFileSystem* fs = DOMFileSystem::create(m_scriptState->executionContex
t(), name, static_cast<blink::FileSystemType>(type), KURL(ParsedURLString, url))
; | 2194 DOMFileSystem* fs = DOMFileSystem::create(m_scriptState->executionContex
t(), name, static_cast<FileSystemType>(type), KURL(ParsedURLString, url)); |
2195 *value = toV8(fs, m_scriptState->context()->Global(), isolate()); | 2195 *value = toV8(fs, m_scriptState->context()->Global(), isolate()); |
2196 return true; | 2196 return true; |
2197 } | 2197 } |
2198 | 2198 |
2199 bool readFile(v8::Handle<v8::Value>* value, bool isIndexed) | 2199 bool readFile(v8::Handle<v8::Value>* value, bool isIndexed) |
2200 { | 2200 { |
2201 File* file = nullptr; | 2201 File* file = nullptr; |
2202 if (isIndexed) { | 2202 if (isIndexed) { |
2203 if (m_version < 6) | 2203 if (m_version < 6) |
2204 return false; | 2204 return false; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2236 *value = toV8(fileList, m_scriptState->context()->Global(), isolate()); | 2236 *value = toV8(fileList, m_scriptState->context()->Global(), isolate()); |
2237 return true; | 2237 return true; |
2238 } | 2238 } |
2239 | 2239 |
2240 bool readCryptoKey(v8::Handle<v8::Value>* value) | 2240 bool readCryptoKey(v8::Handle<v8::Value>* value) |
2241 { | 2241 { |
2242 uint32_t rawKeyType; | 2242 uint32_t rawKeyType; |
2243 if (!doReadUint32(&rawKeyType)) | 2243 if (!doReadUint32(&rawKeyType)) |
2244 return false; | 2244 return false; |
2245 | 2245 |
2246 blink::WebCryptoKeyAlgorithm algorithm; | 2246 WebCryptoKeyAlgorithm algorithm; |
2247 blink::WebCryptoKeyType type = blink::WebCryptoKeyTypeSecret; | 2247 WebCryptoKeyType type = WebCryptoKeyTypeSecret; |
2248 | 2248 |
2249 switch (static_cast<CryptoKeySubTag>(rawKeyType)) { | 2249 switch (static_cast<CryptoKeySubTag>(rawKeyType)) { |
2250 case AesKeyTag: | 2250 case AesKeyTag: |
2251 if (!doReadAesKey(algorithm, type)) | 2251 if (!doReadAesKey(algorithm, type)) |
2252 return false; | 2252 return false; |
2253 break; | 2253 break; |
2254 case HmacKeyTag: | 2254 case HmacKeyTag: |
2255 if (!doReadHmacKey(algorithm, type)) | 2255 if (!doReadHmacKey(algorithm, type)) |
2256 return false; | 2256 return false; |
2257 break; | 2257 break; |
2258 case RsaHashedKeyTag: | 2258 case RsaHashedKeyTag: |
2259 if (!doReadRsaHashedKey(algorithm, type)) | 2259 if (!doReadRsaHashedKey(algorithm, type)) |
2260 return false; | 2260 return false; |
2261 break; | 2261 break; |
2262 default: | 2262 default: |
2263 return false; | 2263 return false; |
2264 } | 2264 } |
2265 | 2265 |
2266 blink::WebCryptoKeyUsageMask usages; | 2266 WebCryptoKeyUsageMask usages; |
2267 bool extractable; | 2267 bool extractable; |
2268 if (!doReadKeyUsages(usages, extractable)) | 2268 if (!doReadKeyUsages(usages, extractable)) |
2269 return false; | 2269 return false; |
2270 | 2270 |
2271 uint32_t keyDataLength; | 2271 uint32_t keyDataLength; |
2272 if (!doReadUint32(&keyDataLength)) | 2272 if (!doReadUint32(&keyDataLength)) |
2273 return false; | 2273 return false; |
2274 | 2274 |
2275 if (m_position + keyDataLength > m_length) | 2275 if (m_position + keyDataLength > m_length) |
2276 return false; | 2276 return false; |
2277 | 2277 |
2278 const uint8_t* keyData = m_buffer + m_position; | 2278 const uint8_t* keyData = m_buffer + m_position; |
2279 m_position += keyDataLength; | 2279 m_position += keyDataLength; |
2280 | 2280 |
2281 blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); | 2281 WebCryptoKey key = WebCryptoKey::createNull(); |
2282 if (!blink::Platform::current()->crypto()->deserializeKeyForClone( | 2282 if (!Platform::current()->crypto()->deserializeKeyForClone( |
2283 algorithm, type, extractable, usages, keyData, keyDataLength, key))
{ | 2283 algorithm, type, extractable, usages, keyData, keyDataLength, key))
{ |
2284 return false; | 2284 return false; |
2285 } | 2285 } |
2286 | 2286 |
2287 *value = toV8(CryptoKey::create(key), m_scriptState->context()->Global()
, isolate()); | 2287 *value = toV8(CryptoKey::create(key), m_scriptState->context()->Global()
, isolate()); |
2288 return true; | 2288 return true; |
2289 } | 2289 } |
2290 | 2290 |
2291 File* readFileHelper() | 2291 File* readFileHelper() |
2292 { | 2292 { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2387 // the blob in the src process happens to still exist at the time the de
st process is deserializing. | 2387 // the blob in the src process happens to still exist at the time the de
st process is deserializing. |
2388 // For example in sharedWorker.postMessage(...). | 2388 // For example in sharedWorker.postMessage(...). |
2389 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); | 2389 BlobDataHandleMap::const_iterator it = m_blobDataHandles.find(uuid); |
2390 if (it != m_blobDataHandles.end()) { | 2390 if (it != m_blobDataHandles.end()) { |
2391 // make assertions about type and size? | 2391 // make assertions about type and size? |
2392 return it->value; | 2392 return it->value; |
2393 } | 2393 } |
2394 return BlobDataHandle::create(uuid, type, size); | 2394 return BlobDataHandle::create(uuid, type, size); |
2395 } | 2395 } |
2396 | 2396 |
2397 bool doReadHmacKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCrypto
KeyType& type) | 2397 bool doReadHmacKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type) |
2398 { | 2398 { |
2399 uint32_t lengthBytes; | 2399 uint32_t lengthBytes; |
2400 if (!doReadUint32(&lengthBytes)) | 2400 if (!doReadUint32(&lengthBytes)) |
2401 return false; | 2401 return false; |
2402 blink::WebCryptoAlgorithmId hash; | 2402 WebCryptoAlgorithmId hash; |
2403 if (!doReadAlgorithmId(hash)) | 2403 if (!doReadAlgorithmId(hash)) |
2404 return false; | 2404 return false; |
2405 algorithm = blink::WebCryptoKeyAlgorithm::createHmac(hash, lengthBytes *
8); | 2405 algorithm = WebCryptoKeyAlgorithm::createHmac(hash, lengthBytes * 8); |
2406 type = blink::WebCryptoKeyTypeSecret; | 2406 type = WebCryptoKeyTypeSecret; |
2407 return !algorithm.isNull(); | 2407 return !algorithm.isNull(); |
2408 } | 2408 } |
2409 | 2409 |
2410 bool doReadAesKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebCryptoK
eyType& type) | 2410 bool doReadAesKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType& type) |
2411 { | 2411 { |
2412 blink::WebCryptoAlgorithmId id; | 2412 WebCryptoAlgorithmId id; |
2413 if (!doReadAlgorithmId(id)) | 2413 if (!doReadAlgorithmId(id)) |
2414 return false; | 2414 return false; |
2415 uint32_t lengthBytes; | 2415 uint32_t lengthBytes; |
2416 if (!doReadUint32(&lengthBytes)) | 2416 if (!doReadUint32(&lengthBytes)) |
2417 return false; | 2417 return false; |
2418 algorithm = blink::WebCryptoKeyAlgorithm::createAes(id, lengthBytes * 8)
; | 2418 algorithm = WebCryptoKeyAlgorithm::createAes(id, lengthBytes * 8); |
2419 type = blink::WebCryptoKeyTypeSecret; | 2419 type = WebCryptoKeyTypeSecret; |
2420 return !algorithm.isNull(); | 2420 return !algorithm.isNull(); |
2421 } | 2421 } |
2422 | 2422 |
2423 bool doReadRsaHashedKey(blink::WebCryptoKeyAlgorithm& algorithm, blink::WebC
ryptoKeyType& type) | 2423 bool doReadRsaHashedKey(WebCryptoKeyAlgorithm& algorithm, WebCryptoKeyType&
type) |
2424 { | 2424 { |
2425 blink::WebCryptoAlgorithmId id; | 2425 WebCryptoAlgorithmId id; |
2426 if (!doReadAlgorithmId(id)) | 2426 if (!doReadAlgorithmId(id)) |
2427 return false; | 2427 return false; |
2428 | 2428 |
2429 uint32_t rawType; | 2429 uint32_t rawType; |
2430 if (!doReadUint32(&rawType)) | 2430 if (!doReadUint32(&rawType)) |
2431 return false; | 2431 return false; |
2432 | 2432 |
2433 switch (static_cast<AssymetricCryptoKeyType>(rawType)) { | 2433 switch (static_cast<AssymetricCryptoKeyType>(rawType)) { |
2434 case PublicKeyType: | 2434 case PublicKeyType: |
2435 type = blink::WebCryptoKeyTypePublic; | 2435 type = WebCryptoKeyTypePublic; |
2436 break; | 2436 break; |
2437 case PrivateKeyType: | 2437 case PrivateKeyType: |
2438 type = blink::WebCryptoKeyTypePrivate; | 2438 type = WebCryptoKeyTypePrivate; |
2439 break; | 2439 break; |
2440 default: | 2440 default: |
2441 return false; | 2441 return false; |
2442 } | 2442 } |
2443 | 2443 |
2444 uint32_t modulusLengthBits; | 2444 uint32_t modulusLengthBits; |
2445 if (!doReadUint32(&modulusLengthBits)) | 2445 if (!doReadUint32(&modulusLengthBits)) |
2446 return false; | 2446 return false; |
2447 | 2447 |
2448 uint32_t publicExponentSize; | 2448 uint32_t publicExponentSize; |
2449 if (!doReadUint32(&publicExponentSize)) | 2449 if (!doReadUint32(&publicExponentSize)) |
2450 return false; | 2450 return false; |
2451 | 2451 |
2452 if (m_position + publicExponentSize > m_length) | 2452 if (m_position + publicExponentSize > m_length) |
2453 return false; | 2453 return false; |
2454 | 2454 |
2455 const uint8_t* publicExponent = m_buffer + m_position; | 2455 const uint8_t* publicExponent = m_buffer + m_position; |
2456 m_position += publicExponentSize; | 2456 m_position += publicExponentSize; |
2457 | 2457 |
2458 blink::WebCryptoAlgorithmId hash; | 2458 WebCryptoAlgorithmId hash; |
2459 if (!doReadAlgorithmId(hash)) | 2459 if (!doReadAlgorithmId(hash)) |
2460 return false; | 2460 return false; |
2461 algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed(id, modulusLen
gthBits, publicExponent, publicExponentSize, hash); | 2461 algorithm = WebCryptoKeyAlgorithm::createRsaHashed(id, modulusLengthBits
, publicExponent, publicExponentSize, hash); |
2462 | 2462 |
2463 return !algorithm.isNull(); | 2463 return !algorithm.isNull(); |
2464 } | 2464 } |
2465 | 2465 |
2466 bool doReadAlgorithmId(blink::WebCryptoAlgorithmId& id) | 2466 bool doReadAlgorithmId(WebCryptoAlgorithmId& id) |
2467 { | 2467 { |
2468 uint32_t rawId; | 2468 uint32_t rawId; |
2469 if (!doReadUint32(&rawId)) | 2469 if (!doReadUint32(&rawId)) |
2470 return false; | 2470 return false; |
2471 | 2471 |
2472 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { | 2472 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { |
2473 case AesCbcTag: | 2473 case AesCbcTag: |
2474 id = blink::WebCryptoAlgorithmIdAesCbc; | 2474 id = WebCryptoAlgorithmIdAesCbc; |
2475 return true; | 2475 return true; |
2476 case HmacTag: | 2476 case HmacTag: |
2477 id = blink::WebCryptoAlgorithmIdHmac; | 2477 id = WebCryptoAlgorithmIdHmac; |
2478 return true; | 2478 return true; |
2479 case RsaSsaPkcs1v1_5Tag: | 2479 case RsaSsaPkcs1v1_5Tag: |
2480 id = blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; | 2480 id = WebCryptoAlgorithmIdRsaSsaPkcs1v1_5; |
2481 return true; | 2481 return true; |
2482 case Sha1Tag: | 2482 case Sha1Tag: |
2483 id = blink::WebCryptoAlgorithmIdSha1; | 2483 id = WebCryptoAlgorithmIdSha1; |
2484 return true; | 2484 return true; |
2485 case Sha256Tag: | 2485 case Sha256Tag: |
2486 id = blink::WebCryptoAlgorithmIdSha256; | 2486 id = WebCryptoAlgorithmIdSha256; |
2487 return true; | 2487 return true; |
2488 case Sha384Tag: | 2488 case Sha384Tag: |
2489 id = blink::WebCryptoAlgorithmIdSha384; | 2489 id = WebCryptoAlgorithmIdSha384; |
2490 return true; | 2490 return true; |
2491 case Sha512Tag: | 2491 case Sha512Tag: |
2492 id = blink::WebCryptoAlgorithmIdSha512; | 2492 id = WebCryptoAlgorithmIdSha512; |
2493 return true; | 2493 return true; |
2494 case AesGcmTag: | 2494 case AesGcmTag: |
2495 id = blink::WebCryptoAlgorithmIdAesGcm; | 2495 id = WebCryptoAlgorithmIdAesGcm; |
2496 return true; | 2496 return true; |
2497 case RsaOaepTag: | 2497 case RsaOaepTag: |
2498 id = blink::WebCryptoAlgorithmIdRsaOaep; | 2498 id = WebCryptoAlgorithmIdRsaOaep; |
2499 return true; | 2499 return true; |
2500 case AesCtrTag: | 2500 case AesCtrTag: |
2501 id = blink::WebCryptoAlgorithmIdAesCtr; | 2501 id = WebCryptoAlgorithmIdAesCtr; |
2502 return true; | 2502 return true; |
2503 case AesKwTag: | 2503 case AesKwTag: |
2504 id = blink::WebCryptoAlgorithmIdAesKw; | 2504 id = WebCryptoAlgorithmIdAesKw; |
2505 return true; | 2505 return true; |
2506 case RsaPssTag: | 2506 case RsaPssTag: |
2507 id = blink::WebCryptoAlgorithmIdRsaPss; | 2507 id = WebCryptoAlgorithmIdRsaPss; |
2508 return true; | 2508 return true; |
2509 } | 2509 } |
2510 | 2510 |
2511 return false; | 2511 return false; |
2512 } | 2512 } |
2513 | 2513 |
2514 bool doReadKeyUsages(blink::WebCryptoKeyUsageMask& usages, bool& extractable
) | 2514 bool doReadKeyUsages(WebCryptoKeyUsageMask& usages, bool& extractable) |
2515 { | 2515 { |
2516 // Reminder to update this when adding new key usages. | 2516 // Reminder to update this when adding new key usages. |
2517 COMPILE_ASSERT(blink::EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); | 2517 COMPILE_ASSERT(EndOfWebCryptoKeyUsage == (1 << 7) + 1, UpdateMe); |
2518 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec
ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU
sage | DeriveBitsUsage; | 2518 const uint32_t allPossibleUsages = ExtractableUsage | EncryptUsage | Dec
ryptUsage | SignUsage | VerifyUsage | DeriveKeyUsage | WrapKeyUsage | UnwrapKeyU
sage | DeriveBitsUsage; |
2519 | 2519 |
2520 uint32_t rawUsages; | 2520 uint32_t rawUsages; |
2521 if (!doReadUint32(&rawUsages)) | 2521 if (!doReadUint32(&rawUsages)) |
2522 return false; | 2522 return false; |
2523 | 2523 |
2524 // Make sure it doesn't contain an unrecognized usage value. | 2524 // Make sure it doesn't contain an unrecognized usage value. |
2525 if (rawUsages & ~allPossibleUsages) | 2525 if (rawUsages & ~allPossibleUsages) |
2526 return false; | 2526 return false; |
2527 | 2527 |
2528 usages = 0; | 2528 usages = 0; |
2529 | 2529 |
2530 extractable = rawUsages & ExtractableUsage; | 2530 extractable = rawUsages & ExtractableUsage; |
2531 | 2531 |
2532 if (rawUsages & EncryptUsage) | 2532 if (rawUsages & EncryptUsage) |
2533 usages |= blink::WebCryptoKeyUsageEncrypt; | 2533 usages |= WebCryptoKeyUsageEncrypt; |
2534 if (rawUsages & DecryptUsage) | 2534 if (rawUsages & DecryptUsage) |
2535 usages |= blink::WebCryptoKeyUsageDecrypt; | 2535 usages |= WebCryptoKeyUsageDecrypt; |
2536 if (rawUsages & SignUsage) | 2536 if (rawUsages & SignUsage) |
2537 usages |= blink::WebCryptoKeyUsageSign; | 2537 usages |= WebCryptoKeyUsageSign; |
2538 if (rawUsages & VerifyUsage) | 2538 if (rawUsages & VerifyUsage) |
2539 usages |= blink::WebCryptoKeyUsageVerify; | 2539 usages |= WebCryptoKeyUsageVerify; |
2540 if (rawUsages & DeriveKeyUsage) | 2540 if (rawUsages & DeriveKeyUsage) |
2541 usages |= blink::WebCryptoKeyUsageDeriveKey; | 2541 usages |= WebCryptoKeyUsageDeriveKey; |
2542 if (rawUsages & WrapKeyUsage) | 2542 if (rawUsages & WrapKeyUsage) |
2543 usages |= blink::WebCryptoKeyUsageWrapKey; | 2543 usages |= WebCryptoKeyUsageWrapKey; |
2544 if (rawUsages & UnwrapKeyUsage) | 2544 if (rawUsages & UnwrapKeyUsage) |
2545 usages |= blink::WebCryptoKeyUsageUnwrapKey; | 2545 usages |= WebCryptoKeyUsageUnwrapKey; |
2546 if (rawUsages & DeriveBitsUsage) | 2546 if (rawUsages & DeriveBitsUsage) |
2547 usages |= blink::WebCryptoKeyUsageDeriveBits; | 2547 usages |= WebCryptoKeyUsageDeriveBits; |
2548 | 2548 |
2549 return true; | 2549 return true; |
2550 } | 2550 } |
2551 | 2551 |
2552 RefPtr<ScriptState> m_scriptState; | 2552 RefPtr<ScriptState> m_scriptState; |
2553 const uint8_t* m_buffer; | 2553 const uint8_t* m_buffer; |
2554 const unsigned m_length; | 2554 const unsigned m_length; |
2555 unsigned m_position; | 2555 unsigned m_position; |
2556 uint32_t m_version; | 2556 uint32_t m_version; |
2557 const WebBlobInfoArray* m_blobInfo; | 2557 const WebBlobInfoArray* m_blobInfo; |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3065 // If the allocated memory was not registered before, then this class is lik
ely | 3065 // If the allocated memory was not registered before, then this class is lik
ely |
3066 // used in a context other then Worker's onmessage environment and the prese
nce of | 3066 // used in a context other then Worker's onmessage environment and the prese
nce of |
3067 // current v8 context is not guaranteed. Avoid calling v8 then. | 3067 // current v8 context is not guaranteed. Avoid calling v8 then. |
3068 if (m_externallyAllocatedMemory) { | 3068 if (m_externallyAllocatedMemory) { |
3069 ASSERT(v8::Isolate::GetCurrent()); | 3069 ASSERT(v8::Isolate::GetCurrent()); |
3070 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); | 3070 v8::Isolate::GetCurrent()->AdjustAmountOfExternalAllocatedMemory(-m_exte
rnallyAllocatedMemory); |
3071 } | 3071 } |
3072 } | 3072 } |
3073 | 3073 |
3074 } // namespace blink | 3074 } // namespace blink |
OLD | NEW |