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

Side by Side Diff: chrome/renderer/resources/extensions/enterprise_platform_keys/subtle_crypto.js

Issue 331173002: enterprise.platformKeys: Respect the 'hash' argument of generateKey. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 var utils = require('utils'); 5 var utils = require('utils');
6 var internalAPI = require('enterprise.platformKeys.internalAPI'); 6 var internalAPI = require('enterprise.platformKeys.internalAPI');
7 var intersect = require('enterprise.platformKeys.utils').intersect; 7 var intersect = require('enterprise.platformKeys.utils').intersect;
8 var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair; 8 var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair;
9 var keyModule = require('enterprise.platformKeys.Key'); 9 var keyModule = require('enterprise.platformKeys.Key');
10 var getSpki = keyModule.getSpki; 10 var getSpki = keyModule.getSpki;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 internalAPI.generateKey(subtleCrypto.tokenId, 112 internalAPI.generateKey(subtleCrypto.tokenId,
113 normalizedAlgorithmParameters.modulusLength, 113 normalizedAlgorithmParameters.modulusLength,
114 function(spki) { 114 function(spki) {
115 if (catchInvalidTokenError(reject)) 115 if (catchInvalidTokenError(reject))
116 return; 116 return;
117 if (chrome.runtime.lastError) { 117 if (chrome.runtime.lastError) {
118 reject(CreateOperationError()); 118 reject(CreateOperationError());
119 return; 119 return;
120 } 120 }
121 resolve(new KeyPair(spki, algorithm, keyUsages)); 121 resolve(new KeyPair(spki, normalizedAlgorithmParameters, keyUsages));
122 }); 122 });
123 }); 123 });
124 }; 124 };
125 125
126 SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) { 126 SubtleCryptoImpl.prototype.sign = function(algorithm, key, dataView) {
127 var subtleCrypto = this; 127 var subtleCrypto = this;
128 return new Promise(function(resolve, reject) { 128 return new Promise(function(resolve, reject) {
129 if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1) 129 if (key.type != 'private' || key.usages.indexOf(KeyUsage.sign) == -1)
130 throw CreateInvalidAccessError(); 130 throw CreateInvalidAccessError();
131 131
132 var normalizedAlgorithmParameters = 132 var normalizedAlgorithmParameters =
133 normalizeAlgorithm(algorithm, 'Sign'); 133 normalizeAlgorithm(algorithm, 'Sign');
134 if (!normalizedAlgorithmParameters) { 134 if (!normalizedAlgorithmParameters) {
135 // TODO(pneubeck): It's not clear from the WebCrypto spec which error to 135 // TODO(pneubeck): It's not clear from the WebCrypto spec which error to
136 // throw here. 136 // throw here.
137 throw CreateSyntaxError(); 137 throw CreateSyntaxError();
138 } 138 }
139 139
140 // Create an ArrayBuffer that equals the dataView. Note that dataView.buffer 140 // Create an ArrayBuffer that equals the dataView. Note that dataView.buffer
141 // might contain more data than dataView. 141 // might contain more data than dataView.
142 var data = dataView.buffer.slice(dataView.byteOffset, 142 var data = dataView.buffer.slice(dataView.byteOffset,
143 dataView.byteOffset + dataView.byteLength); 143 dataView.byteOffset + dataView.byteLength);
144 internalAPI.sign( 144 internalAPI.sign(subtleCrypto.tokenId,
145 subtleCrypto.tokenId, getSpki(key), data, function(signature) { 145 getSpki(key),
146 if (catchInvalidTokenError(reject)) 146 key.algorithm.hash.name,
147 return; 147 data,
148 if (chrome.runtime.lastError) { 148 function(signature) {
149 reject(CreateOperationError()); 149 if (catchInvalidTokenError(reject))
150 return; 150 return;
151 } 151 if (chrome.runtime.lastError) {
152 resolve(signature); 152 reject(CreateOperationError());
153 }); 153 return;
154 }
155 resolve(signature);
156 });
154 }); 157 });
155 }; 158 };
156 159
157 SubtleCryptoImpl.prototype.exportKey = function(format, key) { 160 SubtleCryptoImpl.prototype.exportKey = function(format, key) {
158 return new Promise(function(resolve, reject) { 161 return new Promise(function(resolve, reject) {
159 if (format == 'pkcs8') { 162 if (format == 'pkcs8') {
160 // Either key.type is not 'private' or the key is not extractable. In both 163 // Either key.type is not 'private' or the key is not extractable. In both
161 // cases the error is the same. 164 // cases the error is the same.
162 throw CreateInvalidAccessError(); 165 throw CreateInvalidAccessError();
163 } else if (format == 'spki') { 166 } else if (format == 'spki') {
164 if (key.type != 'public') 167 if (key.type != 'public')
165 throw CreateInvalidAccessError(); 168 throw CreateInvalidAccessError();
166 resolve(getSpki(key)); 169 resolve(getSpki(key));
167 } else { 170 } else {
168 // TODO(pneubeck): It should be possible to export to format 'jwk'. 171 // TODO(pneubeck): It should be possible to export to format 'jwk'.
169 throw CreateNotSupportedError(); 172 throw CreateNotSupportedError();
170 } 173 }
171 }); 174 });
172 }; 175 };
173 176
174 exports.SubtleCrypto = 177 exports.SubtleCrypto =
175 utils.expose('SubtleCrypto', 178 utils.expose('SubtleCrypto',
176 SubtleCryptoImpl, 179 SubtleCryptoImpl,
177 {functions:['generateKey', 'sign', 'exportKey']}); 180 {functions:['generateKey', 'sign', 'exportKey']});
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698