Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" | 6 #include "bindings/modules/v8/ScriptValueSerializerForModules.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/SerializationTag.h" | 8 #include "bindings/core/v8/SerializationTag.h" |
| 9 #include "bindings/core/v8/V8Binding.h" | 9 #include "bindings/core/v8/V8Binding.h" |
| 10 #include "bindings/modules/v8/V8CryptoKey.h" | 10 #include "bindings/modules/v8/V8CryptoKey.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 Sha256Tag = 6, | 23 Sha256Tag = 6, |
| 24 Sha384Tag = 7, | 24 Sha384Tag = 7, |
| 25 Sha512Tag = 8, | 25 Sha512Tag = 8, |
| 26 AesGcmTag = 9, | 26 AesGcmTag = 9, |
| 27 RsaOaepTag = 10, | 27 RsaOaepTag = 10, |
| 28 AesCtrTag = 11, | 28 AesCtrTag = 11, |
| 29 AesKwTag = 12, | 29 AesKwTag = 12, |
| 30 RsaPssTag = 13, | 30 RsaPssTag = 13, |
| 31 EcdsaTag = 14, | 31 EcdsaTag = 14, |
| 32 EcdhTag = 15, | 32 EcdhTag = 15, |
| 33 HkdfTag = 16, | |
| 33 // Maximum allowed value is 2^32-1 | 34 // Maximum allowed value is 2^32-1 |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 enum NamedCurveTag { | 37 enum NamedCurveTag { |
| 37 P256Tag = 1, | 38 P256Tag = 1, |
| 38 P384Tag = 2, | 39 P384Tag = 2, |
| 39 P521Tag = 3, | 40 P521Tag = 3, |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 enum CryptoKeyUsage { | 43 enum CryptoKeyUsage { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 54 DeriveBitsUsage = 1 << 8, | 55 DeriveBitsUsage = 1 << 8, |
| 55 // Maximum allowed value is 1 << 31 | 56 // Maximum allowed value is 1 << 31 |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 enum CryptoKeySubTag { | 59 enum CryptoKeySubTag { |
| 59 AesKeyTag = 1, | 60 AesKeyTag = 1, |
| 60 HmacKeyTag = 2, | 61 HmacKeyTag = 2, |
| 61 // ID 3 was used by RsaKeyTag, while still behind experimental flag. | 62 // ID 3 was used by RsaKeyTag, while still behind experimental flag. |
| 62 RsaHashedKeyTag = 4, | 63 RsaHashedKeyTag = 4, |
| 63 EcKeyTag = 5, | 64 EcKeyTag = 5, |
| 65 NoParamsKeyTag = 6, | |
| 64 // Maximum allowed value is 255 | 66 // Maximum allowed value is 255 |
| 65 }; | 67 }; |
| 66 | 68 |
| 67 enum AssymetricCryptoKeyType { | 69 enum AssymetricCryptoKeyType { |
| 68 PublicKeyType = 1, | 70 PublicKeyType = 1, |
| 69 PrivateKeyType = 2, | 71 PrivateKeyType = 2, |
| 70 // Maximum allowed value is 2^32-1 | 72 // Maximum allowed value is 2^32-1 |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 | 75 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 case WebCryptoKeyAlgorithmParamsTypeHmac: | 117 case WebCryptoKeyAlgorithmParamsTypeHmac: |
| 116 doWriteHmacKey(key); | 118 doWriteHmacKey(key); |
| 117 break; | 119 break; |
| 118 case WebCryptoKeyAlgorithmParamsTypeRsaHashed: | 120 case WebCryptoKeyAlgorithmParamsTypeRsaHashed: |
| 119 doWriteRsaHashedKey(key); | 121 doWriteRsaHashedKey(key); |
| 120 break; | 122 break; |
| 121 case WebCryptoKeyAlgorithmParamsTypeEc: | 123 case WebCryptoKeyAlgorithmParamsTypeEc: |
| 122 doWriteEcKey(key); | 124 doWriteEcKey(key); |
| 123 break; | 125 break; |
| 124 case WebCryptoKeyAlgorithmParamsTypeNone: | 126 case WebCryptoKeyAlgorithmParamsTypeNone: |
| 125 ASSERT_NOT_REACHED(); | 127 ASSERT(WebCryptoAlgorithm::isKdf(key.algorithm().id())); |
|
eroman
2015/01/09 22:12:45
Can you move this assertion into doWriteKeyWithout
nharper
2015/01/09 22:29:02
Done.
| |
| 126 return false; | 128 doWriteKeyWithoutParams(key); |
|
eroman
2015/01/09 22:12:45
Please add a break statement for symmetry with the
nharper
2015/01/09 22:29:02
Done.
| |
| 127 } | 129 } |
| 128 | 130 |
| 129 doWriteKeyUsages(key.usages(), key.extractable()); | 131 doWriteKeyUsages(key.usages(), key.extractable()); |
| 130 | 132 |
| 131 WebVector<uint8_t> keyData; | 133 WebVector<uint8_t> keyData; |
| 132 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData)) | 134 if (!Platform::current()->crypto()->serializeKeyForClone(key, keyData)) |
| 133 return false; | 135 return false; |
| 134 | 136 |
| 135 doWriteUint32(keyData.size()); | 137 doWriteUint32(keyData.size()); |
| 136 append(keyData.data(), keyData.size()); | 138 append(keyData.data(), keyData.size()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 void SerializedScriptValueWriterForModules::doWriteEcKey(const WebCryptoKey& key ) | 179 void SerializedScriptValueWriterForModules::doWriteEcKey(const WebCryptoKey& key ) |
| 178 { | 180 { |
| 179 ASSERT(key.algorithm().ecParams()); | 181 ASSERT(key.algorithm().ecParams()); |
| 180 append(static_cast<uint8_t>(EcKeyTag)); | 182 append(static_cast<uint8_t>(EcKeyTag)); |
| 181 | 183 |
| 182 doWriteAlgorithmId(key.algorithm().id()); | 184 doWriteAlgorithmId(key.algorithm().id()); |
| 183 doWriteAsymmetricKeyType(key.type()); | 185 doWriteAsymmetricKeyType(key.type()); |
| 184 doWriteNamedCurve(key.algorithm().ecParams()->namedCurve()); | 186 doWriteNamedCurve(key.algorithm().ecParams()->namedCurve()); |
| 185 } | 187 } |
| 186 | 188 |
| 189 void SerializedScriptValueWriterForModules::doWriteKeyWithoutParams(const WebCry ptoKey& key) | |
| 190 { | |
| 191 append(static_cast<uint8_t>(NoParamsKeyTag)); | |
| 192 | |
| 193 doWriteAlgorithmId(key.algorithm().id()); | |
| 194 } | |
| 195 | |
| 187 void SerializedScriptValueWriterForModules::doWriteAlgorithmId(WebCryptoAlgorith mId id) | 196 void SerializedScriptValueWriterForModules::doWriteAlgorithmId(WebCryptoAlgorith mId id) |
| 188 { | 197 { |
| 189 switch (id) { | 198 switch (id) { |
| 190 case WebCryptoAlgorithmIdAesCbc: | 199 case WebCryptoAlgorithmIdAesCbc: |
| 191 return doWriteUint32(AesCbcTag); | 200 return doWriteUint32(AesCbcTag); |
| 192 case WebCryptoAlgorithmIdHmac: | 201 case WebCryptoAlgorithmIdHmac: |
| 193 return doWriteUint32(HmacTag); | 202 return doWriteUint32(HmacTag); |
| 194 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: | 203 case WebCryptoAlgorithmIdRsaSsaPkcs1v1_5: |
| 195 return doWriteUint32(RsaSsaPkcs1v1_5Tag); | 204 return doWriteUint32(RsaSsaPkcs1v1_5Tag); |
| 196 case WebCryptoAlgorithmIdSha1: | 205 case WebCryptoAlgorithmIdSha1: |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 208 case WebCryptoAlgorithmIdAesCtr: | 217 case WebCryptoAlgorithmIdAesCtr: |
| 209 return doWriteUint32(AesCtrTag); | 218 return doWriteUint32(AesCtrTag); |
| 210 case WebCryptoAlgorithmIdAesKw: | 219 case WebCryptoAlgorithmIdAesKw: |
| 211 return doWriteUint32(AesKwTag); | 220 return doWriteUint32(AesKwTag); |
| 212 case WebCryptoAlgorithmIdRsaPss: | 221 case WebCryptoAlgorithmIdRsaPss: |
| 213 return doWriteUint32(RsaPssTag); | 222 return doWriteUint32(RsaPssTag); |
| 214 case WebCryptoAlgorithmIdEcdsa: | 223 case WebCryptoAlgorithmIdEcdsa: |
| 215 return doWriteUint32(EcdsaTag); | 224 return doWriteUint32(EcdsaTag); |
| 216 case WebCryptoAlgorithmIdEcdh: | 225 case WebCryptoAlgorithmIdEcdh: |
| 217 return doWriteUint32(EcdhTag); | 226 return doWriteUint32(EcdhTag); |
| 227 case WebCryptoAlgorithmIdHkdf: | |
| 228 return doWriteUint32(HkdfTag); | |
| 218 } | 229 } |
| 219 ASSERT_NOT_REACHED(); | 230 ASSERT_NOT_REACHED(); |
| 220 } | 231 } |
| 221 | 232 |
| 222 void SerializedScriptValueWriterForModules::doWriteAsymmetricKeyType(WebCryptoKe yType keyType) | 233 void SerializedScriptValueWriterForModules::doWriteAsymmetricKeyType(WebCryptoKe yType keyType) |
| 223 { | 234 { |
| 224 switch (keyType) { | 235 switch (keyType) { |
| 225 case WebCryptoKeyTypePublic: | 236 case WebCryptoKeyTypePublic: |
| 226 doWriteUint32(PublicKeyType); | 237 doWriteUint32(PublicKeyType); |
| 227 break; | 238 break; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 return false; | 363 return false; |
| 353 break; | 364 break; |
| 354 case RsaHashedKeyTag: | 365 case RsaHashedKeyTag: |
| 355 if (!doReadRsaHashedKey(algorithm, type)) | 366 if (!doReadRsaHashedKey(algorithm, type)) |
| 356 return false; | 367 return false; |
| 357 break; | 368 break; |
| 358 case EcKeyTag: | 369 case EcKeyTag: |
| 359 if (!doReadEcKey(algorithm, type)) | 370 if (!doReadEcKey(algorithm, type)) |
| 360 return false; | 371 return false; |
| 361 break; | 372 break; |
| 373 case NoParamsKeyTag: | |
| 374 if (!doReadKeyWithoutParams(algorithm, type)) | |
| 375 return false; | |
| 376 break; | |
| 362 default: | 377 default: |
| 363 return false; | 378 return false; |
| 364 } | 379 } |
| 365 | 380 |
| 366 WebCryptoKeyUsageMask usages; | 381 WebCryptoKeyUsageMask usages; |
| 367 bool extractable; | 382 bool extractable; |
| 368 if (!doReadKeyUsages(usages, extractable)) | 383 if (!doReadKeyUsages(usages, extractable)) |
| 369 return false; | 384 return false; |
| 370 | 385 |
| 371 uint32_t keyDataLength; | 386 uint32_t keyDataLength; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 451 return false; | 466 return false; |
| 452 | 467 |
| 453 WebCryptoNamedCurve namedCurve; | 468 WebCryptoNamedCurve namedCurve; |
| 454 if (!doReadNamedCurve(namedCurve)) | 469 if (!doReadNamedCurve(namedCurve)) |
| 455 return false; | 470 return false; |
| 456 | 471 |
| 457 algorithm = WebCryptoKeyAlgorithm::createEc(id, namedCurve); | 472 algorithm = WebCryptoKeyAlgorithm::createEc(id, namedCurve); |
| 458 return !algorithm.isNull(); | 473 return !algorithm.isNull(); |
| 459 } | 474 } |
| 460 | 475 |
| 476 bool SerializedScriptValueReaderForModules::doReadKeyWithoutParams(WebCryptoKeyA lgorithm& algorithm, WebCryptoKeyType& type) | |
| 477 { | |
| 478 WebCryptoAlgorithmId id; | |
| 479 if (!doReadAlgorithmId(id)) | |
| 480 return false; | |
| 481 algorithm = WebCryptoKeyAlgorithm::createWithoutParams(id); | |
| 482 type = WebCryptoKeyTypeSecret; | |
| 483 return !algorithm.isNull(); | |
| 484 } | |
| 485 | |
| 461 bool SerializedScriptValueReaderForModules::doReadAlgorithmId(WebCryptoAlgorithm Id& id) | 486 bool SerializedScriptValueReaderForModules::doReadAlgorithmId(WebCryptoAlgorithm Id& id) |
| 462 { | 487 { |
| 463 uint32_t rawId; | 488 uint32_t rawId; |
| 464 if (!doReadUint32(&rawId)) | 489 if (!doReadUint32(&rawId)) |
| 465 return false; | 490 return false; |
| 466 | 491 |
| 467 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { | 492 switch (static_cast<CryptoKeyAlgorithmTag>(rawId)) { |
| 468 case AesCbcTag: | 493 case AesCbcTag: |
| 469 id = WebCryptoAlgorithmIdAesCbc; | 494 id = WebCryptoAlgorithmIdAesCbc; |
| 470 return true; | 495 return true; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 500 return true; | 525 return true; |
| 501 case RsaPssTag: | 526 case RsaPssTag: |
| 502 id = WebCryptoAlgorithmIdRsaPss; | 527 id = WebCryptoAlgorithmIdRsaPss; |
| 503 return true; | 528 return true; |
| 504 case EcdsaTag: | 529 case EcdsaTag: |
| 505 id = WebCryptoAlgorithmIdEcdsa; | 530 id = WebCryptoAlgorithmIdEcdsa; |
| 506 return true; | 531 return true; |
| 507 case EcdhTag: | 532 case EcdhTag: |
| 508 id = WebCryptoAlgorithmIdEcdh; | 533 id = WebCryptoAlgorithmIdEcdh; |
| 509 return true; | 534 return true; |
| 535 case HkdfTag: | |
| 536 id = WebCryptoAlgorithmIdHkdf; | |
| 537 return true; | |
| 510 } | 538 } |
| 511 | 539 |
| 512 return false; | 540 return false; |
| 513 } | 541 } |
| 514 | 542 |
| 515 bool SerializedScriptValueReaderForModules::doReadAsymmetricKeyType(WebCryptoKey Type& type) | 543 bool SerializedScriptValueReaderForModules::doReadAsymmetricKeyType(WebCryptoKey Type& type) |
| 516 { | 544 { |
| 517 uint32_t rawType; | 545 uint32_t rawType; |
| 518 if (!doReadUint32(&rawType)) | 546 if (!doReadUint32(&rawType)) |
| 519 return false; | 547 return false; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents) | 621 : ScriptValueDeserializer(reader, messagePorts, arrayBufferContents) |
| 594 { | 622 { |
| 595 } | 623 } |
| 596 | 624 |
| 597 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) | 625 bool ScriptValueDeserializerForModules::read(v8::Local<v8::Value>* value) |
| 598 { | 626 { |
| 599 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); | 627 return toSerializedScriptValueReaderForModules(reader()).read(value, *this); |
| 600 } | 628 } |
| 601 | 629 |
| 602 } // namespace blink | 630 } // namespace blink |
| OLD | NEW |