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

Side by Side Diff: chrome/test/data/extensions/api_test/platform_keys/basic.js

Issue 998293002: chrome.platformKeys.getKeyPair: Check requested algorithm against certificate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@require_alg_name
Patch Set: Created 5 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 'use strict'; 5 'use strict';
6 6
7 var systemTokenEnabled = (location.search.indexOf("systemTokenEnabled") != -1); 7 var systemTokenEnabled = (location.search.indexOf("systemTokenEnabled") != -1);
8 var selectedTestSuite = location.hash.slice(1); 8 var selectedTestSuite = location.hash.slice(1);
9 console.log('[SELECTED TEST SUITE] ' + selectedTestSuite + 9 console.log('[SELECTED TEST SUITE] ' + selectedTestSuite +
10 ', systemTokenEnable ' + systemTokenEnabled); 10 ', systemTokenEnable ' + systemTokenEnabled);
11 11
12 var assertEq = chrome.test.assertEq; 12 var assertEq = chrome.test.assertEq;
13 var assertTrue = chrome.test.assertTrue; 13 var assertTrue = chrome.test.assertTrue;
14 var fail = chrome.test.fail; 14 var fail = chrome.test.fail;
15 var succeed = chrome.test.succeed; 15 var succeed = chrome.test.succeed;
16 var callbackPass = chrome.test.callbackPass; 16 var callbackPass = chrome.test.callbackPass;
17 var callbackFail= chrome.test.callbackFail; 17 var callbackFail= chrome.test.callbackFail;
18 18
19 // Each value is the path to a file in this extension's folder that will be 19 // Each value is the path to a file in this extension's folder that will be
20 // loaded and replaced by a Uint8Array in the setUp() function below. 20 // loaded and replaced by a Uint8Array in the setUp() function below.
21 var data = { 21 var data = {
22 // X.509 client certificates in DER encoding. 22 // X.509 client certificate in DER encoding.
23 // Algorithm in SPKI: rsaEncryption.
23 // openssl x509 -in net/data/ssl/certificates/client_1.pem -outform DER -out 24 // openssl x509 -in net/data/ssl/certificates/client_1.pem -outform DER -out
24 // client_1.der 25 // client_1.der
25 client_1: 'client_1.der', 26 client_1: 'client_1.der',
26 27
28 // X.509 client certificate in DER encoding.
29 // Algorithm in SPKI: rsaEncryption.
27 // openssl x509 -in net/data/ssl/certificates/client_2.pem -outform DER -out 30 // openssl x509 -in net/data/ssl/certificates/client_2.pem -outform DER -out
28 // client_2.der 31 // client_2.der
29 client_2: 'client_2.der', 32 client_2: 'client_2.der',
30 33
31 // The public key of client_1 as Subject Public Key Info in DER encoding. 34 // The public key of client_1 as Subject Public Key Info in DER encoding.
32 // openssl rsa -in net/data/ssl/certificates/client_1.key -inform PEM -out 35 // openssl rsa -in net/data/ssl/certificates/client_1.key -inform PEM -out
33 // pubkey.der -pubout -outform DER 36 // pubkey.der -pubout -outform DER
34 client_1_spki: 'client_1_spki.der', 37 client_1_spki: 'client_1_spki.der',
35 38
36 // The distinguished name of the CA that issued client_1 in DER encoding. 39 // The distinguished name of the CA that issued client_1 in DER encoding.
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 data.client_1.buffer, keyParams, function(error) { 263 data.client_1.buffer, keyParams, function(error) {
261 fail('getKeyPair call was expected to fail.'); 264 fail('getKeyPair call was expected to fail.');
262 }); 265 });
263 fail('getKeyPair did not throw error'); 266 fail('getKeyPair did not throw error');
264 } catch (e) { 267 } catch (e) {
265 assertEq('Algorithm: name: Missing or not a string', e.message); 268 assertEq('Algorithm: name: Missing or not a string', e.message);
266 succeed(); 269 succeed();
267 } 270 }
268 } 271 }
269 272
273 function testGetKeyPairRejectsRSAPSS() {
274 var keyParams = {
275 name: 'RSA-PSS',
276 hash: {name: 'SHA-1'}
277 };
278 chrome.platformKeys.getKeyPair(
279 data.client_1.buffer, keyParams,
280 callbackFail('The requested Algorithm is not permitted by Certificate.'));
281 }
282
270 function testGetKeyPair() { 283 function testGetKeyPair() {
271 var keyParams = { 284 var keyParams = {
272 // Algorithm names are case-insensitive. 285 // Algorithm names are case-insensitive.
273 name: 'RSASSA-Pkcs1-V1_5', 286 name: 'RSASSA-Pkcs1-V1_5',
274 hash: {name: 'sha-1'} 287 hash: {name: 'sha-1'}
275 }; 288 };
276 chrome.platformKeys.getKeyPair( 289 chrome.platformKeys.getKeyPair(
277 data.client_1.buffer, keyParams, 290 data.client_1.buffer, keyParams,
278 callbackPass(function(publicKey, privateKey) { 291 callbackPass(function(publicKey, privateKey) {
279 var expectedAlgorithm = { 292 var expectedAlgorithm = {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 // On interactive selectClientCertificates calls, the simulated user does not 396 // On interactive selectClientCertificates calls, the simulated user does not
384 // select any cert. 397 // select any cert.
385 basicTests: function() { 398 basicTests: function() {
386 var tests = [ 399 var tests = [
387 testStaticMethods, 400 testStaticMethods,
388 testSelectAllCerts, 401 testSelectAllCerts,
389 testSelectCA1Certs, 402 testSelectCA1Certs,
390 testInteractiveSelectNoCerts, 403 testInteractiveSelectNoCerts,
391 testMatchResult, 404 testMatchResult,
392 testGetKeyPairMissingAlgorithName, 405 testGetKeyPairMissingAlgorithName,
406 testGetKeyPairRejectsRSAPSS,
393 testGetKeyPair, 407 testGetKeyPair,
394 testSignNoHash, 408 testSignNoHash,
395 testSignSha1Client1, 409 testSignSha1Client1,
396 ]; 410 ];
397 411
398 chrome.test.runTests(tests); 412 chrome.test.runTests(tests);
399 }, 413 },
400 414
401 // This test suite starts without any granted permissions. 415 // This test suite starts without any granted permissions.
402 // On interactive selectClientCertificates calls, the simulated user selects 416 // On interactive selectClientCertificates calls, the simulated user selects
(...skipping 21 matching lines...) Expand all
424 // Verify that client_1 but not client_2 is selected in non-interactive 438 // Verify that client_1 but not client_2 is selected in non-interactive
425 // calls. 439 // calls.
426 testSelectAllReturnsClient1, 440 testSelectAllReturnsClient1,
427 ]; 441 ];
428 442
429 chrome.test.runTests(tests); 443 chrome.test.runTests(tests);
430 } 444 }
431 }; 445 };
432 446
433 setUp(testSuites[selectedTestSuite]); 447 setUp(testSuites[selectedTestSuite]);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698