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

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

Issue 847333004: Move parts from enterprise.platformKeysInternal to platformKeysInternal for reuse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_idl
Patch Set: Rebased. Created 5 years, 11 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/platform_keys/subtle_crypto.js
diff --git a/chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js b/chrome/renderer/resources/extensions/platform_keys/subtle_crypto.js
similarity index 54%
copy from chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js
copy to chrome/renderer/resources/extensions/platform_keys/subtle_crypto.js
index 017a3e26d7f06a1fa036fcfaa7b5194f54085c19..14a5388cef3ad8f189b8b05287e0b8da9c79f6c9 100644
--- a/chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js
+++ b/chrome/renderer/resources/extensions/platform_keys/subtle_crypto.js
@@ -1,17 +1,15 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
+// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var utils = require('utils');
-var internalAPI = require('enterprise.platformKeys.internalAPI');
-var intersect = require('enterprise.platformKeys.utils').intersect;
-var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair;
-var keyModule = require('enterprise.platformKeys.Key');
+var internalAPI = require('platformKeys.internalAPI');
+var keyModule = require('platformKeys.Key');
var getSpki = keyModule.getSpki;
var KeyUsage = keyModule.KeyUsage;
var normalizeAlgorithm =
- requireNative('enterprise_platform_keys_natives').NormalizeAlgorithm;
+ requireNative('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
@@ -51,27 +49,9 @@ function catchInvalidTokenError(reject) {
return false;
}
-// Returns true if |array| is a BigInteger describing the standard public
-// exponent 65537. In particular, it ignores leading zeros as required by the
-// BigInteger definition in WebCrypto.
-function equalsStandardPublicExponent(array) {
- var expected = [0x01, 0x00, 0x01];
- if (array.length < expected.length)
- return false;
- for (var i = 0; i < array.length; i++) {
- var expectedDigit = 0;
- if (i < expected.length) {
- // |expected| is symmetric, endianness doesn't matter.
- expectedDigit = expected[i];
- }
- if (array[array.length - 1 - i] !== expectedDigit)
- return false;
- }
- return true;
-}
-
/**
- * Implementation of WebCrypto.SubtleCrypto used in enterprise.platformKeys.
+ * Implementation of WebCrypto.SubtleCrypto used in platformKeys and
+ * enterprise.platformKeys.
* @param {string} tokenId The id of the backing Token.
* @constructor
*/
@@ -79,55 +59,6 @@ var SubtleCryptoImpl = function(tokenId) {
this.tokenId = tokenId;
};
-SubtleCryptoImpl.prototype.generateKey =
- function(algorithm, extractable, keyUsages) {
- var subtleCrypto = this;
- return new Promise(function(resolve, reject) {
- // TODO(pneubeck): Apply the algorithm normalization of the WebCrypto
- // implementation.
-
- if (extractable) {
- // Note: This deviates from WebCrypto.SubtleCrypto.
- throw CreateNotSupportedError();
- }
- if (intersect(keyUsages, [KeyUsage.sign, KeyUsage.verify]).length !=
- keyUsages.length) {
- throw CreateDataError();
- }
- var normalizedAlgorithmParameters =
- normalizeAlgorithm(algorithm, 'GenerateKey');
- if (!normalizedAlgorithmParameters) {
- // TODO(pneubeck): It's not clear from the WebCrypto spec which error to
- // throw here.
- throw CreateSyntaxError();
- }
-
- // normalizeAlgorithm returns an array, but publicExponent should be a
- // Uint8Array.
- normalizedAlgorithmParameters.publicExponent =
- new Uint8Array(normalizedAlgorithmParameters.publicExponent);
-
- if (normalizedAlgorithmParameters.name !== 'RSASSA-PKCS1-v1_5' ||
- !equalsStandardPublicExponent(
- normalizedAlgorithmParameters.publicExponent)) {
- // Note: This deviates from WebCrypto.SubtleCrypto.
- throw CreateNotSupportedError();
- }
-
- internalAPI.generateKey(subtleCrypto.tokenId,
- normalizedAlgorithmParameters.modulusLength,
- function(spki) {
- if (catchInvalidTokenError(reject))
- return;
- if (chrome.runtime.lastError) {
- reject(CreateOperationError());
- return;
- }
- resolve(new KeyPair(spki, normalizedAlgorithmParameters, keyUsages));
- });
- });
-};
-
SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) {
var subtleCrypto = this;
return new Promise(function(resolve, reject) {
@@ -179,7 +110,10 @@ SubtleCryptoImpl.prototype.exportKey = function(format, key) {
});
};
+// Required for subclassing.
+exports.SubtleCryptoImpl = SubtleCryptoImpl
+
exports.SubtleCrypto =
utils.expose('SubtleCrypto',
SubtleCryptoImpl,
- {functions:['generateKey', 'sign', 'exportKey']});
+ {functions:['sign', 'exportKey']});
« no previous file with comments | « chrome/renderer/resources/extensions/platform_keys/key.js ('k') | chrome/renderer/resources/extensions/platform_keys/utils.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698