Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1587)

Unified Diff: Source/modules/crypto/NormalizeAlgorithm.cpp

Issue 21759002: WebCrypto: Add algorithm normalization rules for RSASSA-PKCS1-v1_5. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase onto master Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/crypto/HmacParams.cpp ('k') | Source/modules/crypto/RsaKeyGenParams.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+ 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;
« no previous file with comments | « Source/modules/crypto/HmacParams.cpp ('k') | Source/modules/crypto/RsaKeyGenParams.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698