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

Unified Diff: chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js

Issue 298073009: Reuse WebCrypto's normalizeCryptoAlgorithm in enterprise.platformKeys. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 6 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
Index: chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js
diff --git a/chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js b/chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js
index d94722c79985f7ac9345f363ce216ce456be922f..6a37d27a5f04142dbfcb712adced48f1530bb2c4 100644
--- a/chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js
+++ b/chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js
@@ -10,6 +10,9 @@ var keyModule = require('enterprise.platformKeys.Key');
var getSpki = keyModule.getSpki;
var KeyUsage = keyModule.KeyUsage;
+var normalizeAlgorithm =
+ requireNative('enterprise_platform_keys_natives').NormalizeAlgorithm;
+
// This error is thrown by the internal and public API's token functions and
// must be rethrown by this custom binding. Keep this in sync with the C++ part
// of this API.
@@ -72,29 +75,30 @@ SubtleCryptoImpl.prototype.generateKey =
keyUsages.length) {
throw CreateDataError();
}
- if (!algorithm.name) {
+ var normalizedAlgorithmParameters =
+ normalizeAlgorithm(algorithm, 'GenerateKey');
+ if (!normalizedAlgorithmParameters) {
// TODO(pneubeck): It's not clear from the WebCrypto spec which error to
// throw here.
throw CreateSyntaxError();
}
- if (algorithm.name.toUpperCase() !== 'RSASSA-PKCS1-V1_5') {
+ if (normalizedAlgorithmParameters.name !== 'RSASSA-PKCS1-V1_5') {
// Note: This deviates from WebCrypto.SubtleCrypto.
throw CreateNotSupportedError();
}
- if (!algorithm.modulusLength || !algorithm.publicExponent)
- throw CreateSyntaxError();
- internalAPI.generateKey(
- subtleCrypto.tokenId, algorithm.modulusLength, function(spki) {
- if (catchInvalidTokenError(reject))
- return;
- if (chrome.runtime.lastError) {
- reject(CreateOperationError());
- return;
- }
- resolve(new KeyPair(spki, algorithm, keyUsages));
- });
+ internalAPI.generateKey(subtleCrypto.tokenId,
eroman 2014/06/05 23:38:28 where does the hash come into play? i don't see it
pneubeck (no reviews) 2014/06/06 12:39:45 -> follow up CL.
+ normalizedAlgorithmParameters.modulusLength,
+ function(spki) {
+ if (catchInvalidTokenError(reject))
+ return;
+ if (chrome.runtime.lastError) {
+ reject(CreateOperationError());
+ return;
+ }
+ resolve(new KeyPair(spki, algorithm, keyUsages));
+ });
});
};
@@ -104,6 +108,14 @@ SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) {
if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1)
throw CreateInvalidAccessError();
+ var normalizedAlgorithmParameters =
+ normalizeAlgorithm(algorithm, 'Sign');
+ if (!normalizedAlgorithmParameters) {
+ // TODO(pneubeck): It's not clear from the WebCrypto spec which error to
eroman 2014/06/05 23:38:28 The methods you plumbed through set the exception
pneubeck (no reviews) 2014/06/06 12:39:45 Yeah, this comment is not accurate. a follow up CL
+ // throw here.
+ throw CreateSyntaxError();
+ }
+
// Create an ArrayBuffer that equals the dataView. Note that dataView.buffer
// might contain more data than dataView.
var data = dataView.buffer.slice(dataView.byteOffset,

Powered by Google App Engine
This is Rietveld 408576698