OLD | NEW |
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 // Must be packed to ../enterprise_platform_keys.crx using the private key | 5 // Must be packed to ../enterprise_platform_keys.crx using the private key |
6 // ../enterprise_platform_keys.pem . | 6 // ../enterprise_platform_keys.pem . |
7 | 7 |
8 var assertEq = chrome.test.assertEq; | 8 var assertEq = chrome.test.assertEq; |
9 var assertTrue = chrome.test.assertTrue; | 9 var assertTrue = chrome.test.assertTrue; |
10 var assertThrows = chrome.test.assertThrows; | 10 var assertThrows = chrome.test.assertThrows; |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 .then(callbackPass(function(publicKeySpki) { | 302 .then(callbackPass(function(publicKeySpki) { |
303 cachedSpki = publicKeySpki; | 303 cachedSpki = publicKeySpki; |
304 var signParams = {name: 'RSASSA-PKCS1-v1_5'}; | 304 var signParams = {name: 'RSASSA-PKCS1-v1_5'}; |
305 return userToken.subtleCrypto.sign( | 305 return userToken.subtleCrypto.sign( |
306 signParams, cachedKeyPair.privateKey, data); | 306 signParams, cachedKeyPair.privateKey, data); |
307 }), | 307 }), |
308 function(error) { | 308 function(error) { |
309 assertTrue(false, "Export failed: " + error); | 309 assertTrue(false, "Export failed: " + error); |
310 }) | 310 }) |
311 .then(callbackPass(function(signature) { | 311 .then(callbackPass(function(signature) { |
| 312 var importParams = { |
| 313 name: algorithm.name, |
| 314 // RsaHashedImportParams |
| 315 hash: { |
| 316 name: "SHA-1", |
| 317 } |
| 318 }; |
312 assertTrue(!!signature, "No signature."); | 319 assertTrue(!!signature, "No signature."); |
313 assertTrue(signature.length != 0, "Signature is empty."); | 320 assertTrue(signature.length != 0, "Signature is empty."); |
314 cachedSignature = signature; | 321 cachedSignature = signature; |
315 return window.crypto.subtle.importKey( | 322 return window.crypto.subtle.importKey( |
316 "spki", cachedSpki, algorithm, false, ["verify"]); | 323 "spki", cachedSpki, importParams, false, ["verify"]); |
317 }), | 324 }), |
318 function(error) { assertTrue(false, "Sign failed: " + error); }) | 325 function(error) { assertTrue(false, "Sign failed: " + error); }) |
319 .then(callbackPass(function(webCryptoPublicKey) { | 326 .then(callbackPass(function(webCryptoPublicKey) { |
320 assertTrue(!!webCryptoPublicKey); | 327 assertTrue(!!webCryptoPublicKey); |
321 assertEq(algorithm.modulusLength, | 328 assertEq(algorithm.modulusLength, |
322 webCryptoPublicKey.algorithm.modulusLength); | 329 webCryptoPublicKey.algorithm.modulusLength); |
| 330 assertEq(algorithm.publicExponent, |
| 331 webCryptoPublicKey.algorithm.publicExponent); |
323 return window.crypto.subtle.verify( | 332 return window.crypto.subtle.verify( |
324 algorithm, webCryptoPublicKey, cachedSignature, data); | 333 algorithm, webCryptoPublicKey, cachedSignature, data); |
325 }), | 334 }), |
326 function(error) { | 335 function(error) { |
327 assertTrue(false, "Import failed: " + error); | 336 assertTrue(false, "Import failed: " + error); |
328 }) | 337 }) |
329 .then(callbackPass(function(success) { | 338 .then(callbackPass(function(success) { |
330 assertEq(true, success, "Signature invalid."); | 339 assertEq(true, success, "Signature invalid."); |
331 }), | 340 }), |
332 function(error) { | 341 function(error) { |
(...skipping 24 matching lines...) Expand all Loading... |
357 null, userToken.id, cert1b.buffer), | 366 null, userToken.id, cert1b.buffer), |
358 assertCertsStored.bind(null, userToken, []) | 367 assertCertsStored.bind(null, userToken, []) |
359 ]); | 368 ]); |
360 }, | 369 }, |
361 | 370 |
362 // Call generate key with invalid algorithm parameter, missing | 371 // Call generate key with invalid algorithm parameter, missing |
363 // modulusLength. | 372 // modulusLength. |
364 function algorithmParameterMissingModulusLength() { | 373 function algorithmParameterMissingModulusLength() { |
365 var algorithm = { | 374 var algorithm = { |
366 name: "RSASSA-PKCS1-v1_5", | 375 name: "RSASSA-PKCS1-v1_5", |
367 publicExponent: | 376 // Equivalent to 65537 |
368 new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 | 377 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
369 hash: { | 378 hash: { |
370 name: "SHA-1", | 379 name: "SHA-1", |
371 } | 380 } |
372 }; | 381 }; |
373 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | 382 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
374 function(keyPair) { | 383 function(keyPair) { |
375 assertTrue(false, 'generateKey was expected to fail'); | 384 assertTrue(false, 'generateKey was expected to fail'); |
376 }, | 385 }, |
377 callbackPass(function(error) { | 386 callbackPass(function(error) { |
378 assertTrue(error instanceof Error); | 387 assertTrue(error instanceof Error); |
379 assertEq('A required parameter was missing or out-of-range', | 388 assertEq('A required parameter was missing or out-of-range', |
380 error.message); | 389 error.message); |
381 })); | 390 })); |
382 }, | 391 }, |
383 | 392 |
384 // Call generate key with invalid algorithm parameter, missing hash. | 393 // Call generate key with invalid algorithm parameter, missing hash. |
385 function algorithmParameterMissingHash() { | 394 function algorithmParameterMissingHash() { |
386 var algorithm = { | 395 var algorithm = { |
387 name: 'RSASSA-PKCS1-v1_5', | 396 name: 'RSASSA-PKCS1-v1_5', |
388 modulusLength: 512, | 397 modulusLength: 512, |
389 publicExponent: | 398 // Equivalent to 65537 |
390 new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 | 399 publicExponent: new Uint8Array([0x01, 0x00, 0x01]), |
391 }; | 400 }; |
392 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( | 401 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
393 function(keyPair) { | 402 function(keyPair) { |
| 403 assertTrue(false, 'generateKey was expected to fail'); |
| 404 }, |
| 405 callbackPass(function(error) { |
| 406 assertEq( |
| 407 new Error('Error: A required parameter was missing our out-of-range'), |
| 408 error); |
| 409 })); |
| 410 }, |
| 411 |
| 412 // Call generate key with invalid algorithm parameter, unsupported public |
| 413 // exponent. |
| 414 function algorithmParameterUnsupportedPublicExponent() { |
| 415 var algorithm = { |
| 416 name: 'RSASSA-PKCS1-v1_5', |
| 417 modulusLength: 512, |
| 418 // Different from 65537. |
| 419 publicExponent: new Uint8Array([0x01, 0x01]), |
| 420 }; |
| 421 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
| 422 function(keyPair) { |
394 assertTrue(false, 'generateKey was expected to fail'); | 423 assertTrue(false, 'generateKey was expected to fail'); |
395 }, | 424 }, |
396 callbackPass(function(error) { | 425 callbackPass(function(error) { |
397 assertTrue(error instanceof Error); | 426 assertTrue(error instanceof Error); |
398 assertEq('A required parameter was missing or out-of-range', | 427 assertEq('A required parameter was missing or out-of-range', |
399 error.message); | 428 error.message); |
400 })); | 429 })); |
401 }, | 430 }, |
402 | 431 |
403 // Imports a certificate for which now private key was imported/generated | 432 // Imports a certificate for which now private key was imported/generated |
(...skipping 23 matching lines...) Expand all Loading... |
427 callbackFail('Certificate is not a valid X.509 certificate.')); | 456 callbackFail('Certificate is not a valid X.509 certificate.')); |
428 }, | 457 }, |
429 function getCertsInvalidToken() { | 458 function getCertsInvalidToken() { |
430 chrome.enterprise.platformKeys.getCertificates( | 459 chrome.enterprise.platformKeys.getCertificates( |
431 'invalid token id', callbackFail('The token is not valid.')); | 460 'invalid token id', callbackFail('The token is not valid.')); |
432 } | 461 } |
433 ]); | 462 ]); |
434 } | 463 } |
435 | 464 |
436 beforeTests(runTests); | 465 beforeTests(runTests); |
OLD | NEW |