| OLD | NEW |
| 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); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 assertEq('public', publicKey.type); | 173 assertEq('public', publicKey.type); |
| 174 assertEq(true, publicKey.extractable); | 174 assertEq(true, publicKey.extractable); |
| 175 checkPropertyIsReadOnly(publicKey, 'algorithm'); | 175 checkPropertyIsReadOnly(publicKey, 'algorithm'); |
| 176 checkAlgorithmIsCopiedOnRead(publicKey); | 176 checkAlgorithmIsCopiedOnRead(publicKey); |
| 177 } | 177 } |
| 178 | 178 |
| 179 function testStaticMethods() { | 179 function testStaticMethods() { |
| 180 assertTrue(!!chrome.platformKeys, "No platformKeys namespace."); | 180 assertTrue(!!chrome.platformKeys, "No platformKeys namespace."); |
| 181 assertTrue(!!chrome.platformKeys.selectClientCertificates, | 181 assertTrue(!!chrome.platformKeys.selectClientCertificates, |
| 182 "No selectClientCertificates function."); | 182 "No selectClientCertificates function."); |
| 183 assertTrue(!!chrome.platformKeys.getKeyPair, "No getKeyPair method."); |
| 184 assertTrue(!!chrome.platformKeys.subtleCrypto, "No subtleCrypto getter."); |
| 185 assertTrue(!!chrome.platformKeys.subtleCrypto(), "No subtleCrypto object."); |
| 186 assertTrue(!!chrome.platformKeys.subtleCrypto().sign, "No sign method."); |
| 187 assertTrue(!!chrome.platformKeys.subtleCrypto().exportKey, |
| 188 "No exportKey method."); |
| 183 succeed(); | 189 succeed(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 function testHasSubtleCryptoMethods(token) { | |
| 187 assertTrue(!!token.subtleCrypto.generateKey, | |
| 188 "token has no generateKey method"); | |
| 189 assertTrue(!!token.subtleCrypto.sign, "token has no sign method"); | |
| 190 assertTrue(!!token.subtleCrypto.exportKey, "token has no exportKey method"); | |
| 191 succeed(); | |
| 192 } | |
| 193 | |
| 194 var requestAll = { | 192 var requestAll = { |
| 195 certificateTypes: [], | 193 certificateTypes: [], |
| 196 certificateAuthorities: [] | 194 certificateAuthorities: [] |
| 197 }; | 195 }; |
| 198 | 196 |
| 199 // Depends on |data|, thus it cannot be created immediately. | 197 // Depends on |data|, thus it cannot be created immediately. |
| 200 function requestCA1() { | 198 function requestCA1() { |
| 201 return { | 199 return { |
| 202 certificateTypes: [], | 200 certificateTypes: [], |
| 203 certificateAuthorities: [data.client_1_issuer_dn.buffer] | 201 certificateAuthorities: [data.client_1_issuer_dn.buffer] |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 name: "RSASSA-PKCS1-v1_5", | 243 name: "RSASSA-PKCS1-v1_5", |
| 246 publicExponent: new Uint8Array([0x01, 0x00, 0x01]) | 244 publicExponent: new Uint8Array([0x01, 0x00, 0x01]) |
| 247 }; | 245 }; |
| 248 var actualAlgorithm = matches[0].keyAlgorithm; | 246 var actualAlgorithm = matches[0].keyAlgorithm; |
| 249 assertEq( | 247 assertEq( |
| 250 expectedAlgorithm, actualAlgorithm, | 248 expectedAlgorithm, actualAlgorithm, |
| 251 'Member algorithm of Match does not equal the expected algorithm'); | 249 'Member algorithm of Match does not equal the expected algorithm'); |
| 252 })); | 250 })); |
| 253 } | 251 } |
| 254 | 252 |
| 253 function testGetKeyPairMissingAlgorithName() { |
| 254 var keyParams = { |
| 255 // This is missing the algorithm name. |
| 256 hash: {name: 'SHA-1'} |
| 257 }; |
| 258 try { |
| 259 chrome.platformKeys.getKeyPair( |
| 260 data.client_1.buffer, keyParams, function(error) { |
| 261 fail('getKeyPair call was expected to fail.'); |
| 262 }); |
| 263 fail('getKeyPair did not throw error'); |
| 264 } catch (e) { |
| 265 assertEq('Algorithm: name: Missing or not a string', e.message); |
| 266 succeed(); |
| 267 } |
| 268 } |
| 269 |
| 255 function testGetKeyPair() { | 270 function testGetKeyPair() { |
| 256 var keyParams = { | 271 var keyParams = { |
| 257 // Algorithm names are case-insensitive. | 272 // Algorithm names are case-insensitive. |
| 258 'hash': {'name': 'sha-1'} | 273 name: 'RSASSA-Pkcs1-V1_5', |
| 274 hash: {name: 'sha-1'} |
| 259 }; | 275 }; |
| 260 chrome.platformKeys.getKeyPair( | 276 chrome.platformKeys.getKeyPair( |
| 261 data.client_1.buffer, keyParams, | 277 data.client_1.buffer, keyParams, |
| 262 callbackPass(function(publicKey, privateKey) { | 278 callbackPass(function(publicKey, privateKey) { |
| 263 var expectedAlgorithm = { | 279 var expectedAlgorithm = { |
| 264 modulusLength: 2048, | 280 modulusLength: 2048, |
| 265 name: "RSASSA-PKCS1-v1_5", | 281 name: "RSASSA-PKCS1-v1_5", |
| 266 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), | 282 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
| 267 hash: {name: 'SHA-1'} | 283 hash: {name: 'SHA-1'} |
| 268 }; | 284 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 279 compareArrays(data.client_1_spki, actualPublicKeySpki) == 0, | 295 compareArrays(data.client_1_spki, actualPublicKeySpki) == 0, |
| 280 'Match did not contain correct public key'); | 296 'Match did not contain correct public key'); |
| 281 }), | 297 }), |
| 282 function(error) { fail("Export failed: " + error); }); | 298 function(error) { fail("Export failed: " + error); }); |
| 283 })); | 299 })); |
| 284 } | 300 } |
| 285 | 301 |
| 286 function testSignNoHash() { | 302 function testSignNoHash() { |
| 287 var keyParams = { | 303 var keyParams = { |
| 288 // Algorithm names are case-insensitive. | 304 // Algorithm names are case-insensitive. |
| 305 name: 'RSASSA-PKCS1-V1_5', |
| 289 hash: {name: 'NONE'} | 306 hash: {name: 'NONE'} |
| 290 }; | 307 }; |
| 291 var signParams = { | 308 var signParams = { |
| 292 name: 'RSASSA-PKCS1-v1_5' | 309 name: 'RSASSA-PKCS1-v1_5' |
| 293 }; | 310 }; |
| 294 chrome.platformKeys.getKeyPair( | 311 chrome.platformKeys.getKeyPair( |
| 295 data.client_1.buffer, keyParams, | 312 data.client_1.buffer, keyParams, |
| 296 callbackPass(function(publicKey, privateKey) { | 313 callbackPass(function(publicKey, privateKey) { |
| 297 chrome.platformKeys.subtleCrypto() | 314 chrome.platformKeys.subtleCrypto() |
| 298 .sign(signParams, privateKey, data.raw_data) | 315 .sign(signParams, privateKey, data.raw_data) |
| 299 .then(callbackPass(function(signature) { | 316 .then(callbackPass(function(signature) { |
| 300 var actualSignature = new Uint8Array(signature); | 317 var actualSignature = new Uint8Array(signature); |
| 301 assertTrue(compareArrays(data.signature_nohash_pkcs, | 318 assertTrue(compareArrays(data.signature_nohash_pkcs, |
| 302 actualSignature) == 0, | 319 actualSignature) == 0, |
| 303 'Incorrect signature'); | 320 'Incorrect signature'); |
| 304 })); | 321 })); |
| 305 })); | 322 })); |
| 306 } | 323 } |
| 307 | 324 |
| 308 function testSignSha1Client1() { | 325 function testSignSha1Client1() { |
| 309 var keyParams = { | 326 var keyParams = { |
| 327 name: 'RSASSA-PKCS1-v1_5', |
| 310 // Algorithm names are case-insensitive. | 328 // Algorithm names are case-insensitive. |
| 311 hash: {name: 'Sha-1'} | 329 hash: {name: 'Sha-1'} |
| 312 }; | 330 }; |
| 313 var signParams = { | 331 var signParams = { |
| 314 // Algorithm names are case-insensitive. | 332 // Algorithm names are case-insensitive. |
| 315 name: 'RSASSA-Pkcs1-v1_5' | 333 name: 'RSASSA-Pkcs1-v1_5' |
| 316 }; | 334 }; |
| 317 chrome.platformKeys.getKeyPair( | 335 chrome.platformKeys.getKeyPair( |
| 318 data.client_1.buffer, keyParams, | 336 data.client_1.buffer, keyParams, |
| 319 callbackPass(function(publicKey, privateKey) { | 337 callbackPass(function(publicKey, privateKey) { |
| 320 chrome.platformKeys.subtleCrypto() | 338 chrome.platformKeys.subtleCrypto() |
| 321 .sign(signParams, privateKey, data.raw_data) | 339 .sign(signParams, privateKey, data.raw_data) |
| 322 .then(callbackPass(function(signature) { | 340 .then(callbackPass(function(signature) { |
| 323 var actualSignature = new Uint8Array(signature); | 341 var actualSignature = new Uint8Array(signature); |
| 324 assertTrue( | 342 assertTrue( |
| 325 compareArrays(data.signature_sha1_pkcs, actualSignature) == 0, | 343 compareArrays(data.signature_sha1_pkcs, actualSignature) == 0, |
| 326 'Incorrect signature'); | 344 'Incorrect signature'); |
| 327 })); | 345 })); |
| 328 })); | 346 })); |
| 329 } | 347 } |
| 330 | 348 |
| 331 // TODO(pneubeck): Test this by verifying that no private key is returned, once | 349 // TODO(pneubeck): Test this by verifying that no private key is returned, once |
| 332 // that's implemented. | 350 // that's implemented. |
| 333 function testSignFails(cert) { | 351 function testSignFails(cert) { |
| 334 var keyParams = { | 352 var keyParams = { |
| 353 name: 'RSASSA-PKCS1-v1_5', |
| 335 hash: {name: 'SHA-1'} | 354 hash: {name: 'SHA-1'} |
| 336 }; | 355 }; |
| 337 var signParams = { | 356 var signParams = { |
| 338 name: 'RSASSA-PKCS1-v1_5' | 357 name: 'RSASSA-PKCS1-v1_5' |
| 339 }; | 358 }; |
| 340 chrome.platformKeys.getKeyPair( | 359 chrome.platformKeys.getKeyPair( |
| 341 cert.buffer, keyParams, callbackPass(function(publicKey, privateKey) { | 360 cert.buffer, keyParams, callbackPass(function(publicKey, privateKey) { |
| 342 chrome.platformKeys.subtleCrypto() | 361 chrome.platformKeys.subtleCrypto() |
| 343 .sign(signParams, privateKey, data.raw_data) | 362 .sign(signParams, privateKey, data.raw_data) |
| 344 .then(function(signature) { fail('sign was expected to fail.'); }, | 363 .then(function(signature) { fail('sign was expected to fail.'); }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 363 // These tests assume already granted permissions for client_1 and client_2. | 382 // These tests assume already granted permissions for client_1 and client_2. |
| 364 // On interactive selectClientCertificates calls, the simulated user does not | 383 // On interactive selectClientCertificates calls, the simulated user does not |
| 365 // select any cert. | 384 // select any cert. |
| 366 basicTests: function() { | 385 basicTests: function() { |
| 367 var tests = [ | 386 var tests = [ |
| 368 testStaticMethods, | 387 testStaticMethods, |
| 369 testSelectAllCerts, | 388 testSelectAllCerts, |
| 370 testSelectCA1Certs, | 389 testSelectCA1Certs, |
| 371 testInteractiveSelectNoCerts, | 390 testInteractiveSelectNoCerts, |
| 372 testMatchResult, | 391 testMatchResult, |
| 392 testGetKeyPairMissingAlgorithName, |
| 373 testGetKeyPair, | 393 testGetKeyPair, |
| 374 testSignNoHash, | 394 testSignNoHash, |
| 375 testSignSha1Client1, | 395 testSignSha1Client1, |
| 376 ]; | 396 ]; |
| 377 | 397 |
| 378 chrome.test.runTests(tests); | 398 chrome.test.runTests(tests); |
| 379 }, | 399 }, |
| 380 | 400 |
| 381 // This test suite starts without any granted permissions. | 401 // This test suite starts without any granted permissions. |
| 382 // On interactive selectClientCertificates calls, the simulated user selects | 402 // On interactive selectClientCertificates calls, the simulated user selects |
| (...skipping 21 matching lines...) Expand all Loading... |
| 404 // Verify that client_1 but not client_2 is selected in non-interactive | 424 // Verify that client_1 but not client_2 is selected in non-interactive |
| 405 // calls. | 425 // calls. |
| 406 testSelectAllReturnsClient1, | 426 testSelectAllReturnsClient1, |
| 407 ]; | 427 ]; |
| 408 | 428 |
| 409 chrome.test.runTests(tests); | 429 chrome.test.runTests(tests); |
| 410 } | 430 } |
| 411 }; | 431 }; |
| 412 | 432 |
| 413 setUp(testSuites[selectedTestSuite]); | 433 setUp(testSuites[selectedTestSuite]); |
| OLD | NEW |