Chromium Code Reviews| Index: Source/modules/crypto/NormalizeAlgorithm.cpp |
| diff --git a/Source/modules/crypto/NormalizeAlgorithm.cpp b/Source/modules/crypto/NormalizeAlgorithm.cpp |
| index 630580c4f51ac78aa15866550b64d234f0fddb8b..52f9dc8604b6f0f84744c477d86c58877dbb0cb6 100644 |
| --- a/Source/modules/crypto/NormalizeAlgorithm.cpp |
| +++ b/Source/modules/crypto/NormalizeAlgorithm.cpp |
| @@ -67,6 +67,7 @@ struct OperationParamsMapping { |
| const AlgorithmNameMapping algorithmNameMappings[] = { |
| {"AES-CBC", WebKit::WebCryptoAlgorithmIdAesCbc}, |
| {"HMAC", WebKit::WebCryptoAlgorithmIdHmac}, |
| + {"RSASSA-PKCS1-v1_5", WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5}, |
| {"SHA-1", WebKit::WebCryptoAlgorithmIdSha1}, |
| {"SHA-224", WebKit::WebCryptoAlgorithmIdSha224}, |
| {"SHA-256", WebKit::WebCryptoAlgorithmIdSha256}, |
| @@ -88,6 +89,12 @@ const OperationParamsMapping operationParamsMappings[] = { |
| {WebKit::WebCryptoAlgorithmIdHmac, GenerateKey, WebKit::WebCryptoAlgorithmParamsTypeHmacParams}, |
| {WebKit::WebCryptoAlgorithmIdHmac, ImportKey, WebKit::WebCryptoAlgorithmParamsTypeHmacParams}, |
| + // RSASSA-PKCS1-v1_5 (section 18.4.) |
| + {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Sign, WebKit::WebCryptoAlgorithmParamsTypeRsaSsaParams}, |
| + {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, Verify, WebKit::WebCryptoAlgorithmParamsTypeRsaSsaParams}, |
| + {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, GenerateKey, WebKit::WebCryptoAlgorithmParamsTypeRsaKeyGenParams}, |
| + {WebKit::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, ImportKey, WebKit::WebCryptoAlgorithmParamsTypeNone}, |
| + |
| // SHA-1 (section 18.16.) |
| {WebKit::WebCryptoAlgorithmIdSha1, Digest, WebKit::WebCryptoAlgorithmParamsTypeNone}, |
| @@ -183,20 +190,45 @@ PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseAesKeyGenParams(const Dictiona |
| return adoptPtr(new WebKit::WebCryptoAesKeyGenParams(length)); |
| } |
| -PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseHmacParams(const Dictionary& raw) |
| +bool parseHash(const Dictionary& raw, WebKit::WebCryptoAlgorithm& hash) |
| { |
| Dictionary rawHash; |
| if (!raw.get("hash", rawHash)) |
| + return false; |
| + |
| + NonThrowExceptionState es; |
| + return normalizeAlgorithm(rawHash, Digest, hash, es); |
| +} |
| + |
| +PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseHmacParams(const Dictionary& raw) |
| +{ |
| + WebKit::WebCryptoAlgorithm hash; |
| + if (!parseHash(raw, hash)) |
| return nullptr; |
| + return adoptPtr(new WebKit::WebCryptoHmacParams(hash)); |
| +} |
| - // Normalizing the algorithm for a Digest operation means it will only |
| - // match the SHA-* algorithms. |
| +PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseRsaSsaParams(const Dictionary& raw) |
| +{ |
| WebKit::WebCryptoAlgorithm hash; |
| - NonThrowExceptionState es; |
| - if (!normalizeAlgorithm(rawHash, Digest, hash, es)) |
| + if (!parseHash(raw, hash)) |
| return nullptr; |
| + return adoptPtr(new WebKit::WebCryptoRsaSsaParams(hash)); |
| +} |
| - return adoptPtr(new WebKit::WebCryptoHmacParams(hash)); |
| +PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseRsaKeyGenParams(const Dictionary& raw) |
| +{ |
| + // FIXME: This is losing precision; modulusLength is supposed to be a uint32 |
|
abarth-chromium
2013/08/02 17:56:56
Should we make dictionary understand uint32? I do
eroman
2013/08/02 19:25:42
I need to do a bit of follow-up on what WebIDL int
|
| + int32_t modulusLength; |
| + if (!raw.get("modulusLength", modulusLength)) |
| + return nullptr; |
| + if (modulusLength < 0) |
| + return nullptr; |
| + |
| + RefPtr<Uint8Array> publicExponent; |
| + if (!raw.get("publicExponent", publicExponent) || !publicExponent) |
| + return nullptr; |
| + return adoptPtr(new WebKit::WebCryptoRsaKeyGenParams(modulusLength, static_cast<const unsigned char*>(publicExponent->baseAddress()), publicExponent->byteLength())); |
| } |
| PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseAlgorithmParams(const Dictionary& raw, WebKit::WebCryptoAlgorithmParamsType type) |
| @@ -210,6 +242,10 @@ PassOwnPtr<WebKit::WebCryptoAlgorithmParams> parseAlgorithmParams(const Dictiona |
| return parseAesKeyGenParams(raw); |
| case WebKit::WebCryptoAlgorithmParamsTypeHmacParams: |
| return parseHmacParams(raw); |
| + case WebKit::WebCryptoAlgorithmParamsTypeRsaSsaParams: |
| + return parseRsaSsaParams(raw); |
| + case WebKit::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
| + return parseRsaKeyGenParams(raw); |
| } |
| ASSERT_NOT_REACHED(); |
| return nullptr; |