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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 assertTrue(!!keyPair, "No key pair."); | 294 assertTrue(!!keyPair, "No key pair."); |
295 cachedKeyPair = keyPair; | 295 cachedKeyPair = keyPair; |
296 return userToken.subtleCrypto.exportKey('spki', | 296 return userToken.subtleCrypto.exportKey('spki', |
297 keyPair.publicKey); | 297 keyPair.publicKey); |
298 }), | 298 }), |
299 function(error) { | 299 function(error) { |
300 assertTrue(false, "GenerateKey failed: " + error); | 300 assertTrue(false, "GenerateKey failed: " + error); |
301 }) | 301 }) |
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 return userToken.subtleCrypto.sign( | 305 return userToken.subtleCrypto.sign( |
305 {}, cachedKeyPair.privateKey, data); | 306 signParams, cachedKeyPair.privateKey, data); |
306 }), | 307 }), |
307 function(error) { | 308 function(error) { |
308 assertTrue(false, "Export failed: " + error); | 309 assertTrue(false, "Export failed: " + error); |
309 }) | 310 }) |
310 .then(callbackPass(function(signature) { | 311 .then(callbackPass(function(signature) { |
311 assertTrue(!!signature, "No signature."); | 312 assertTrue(!!signature, "No signature."); |
312 assertTrue(signature.length != 0, "Signature is empty."); | 313 assertTrue(signature.length != 0, "Signature is empty."); |
313 cachedSignature = signature; | 314 cachedSignature = signature; |
314 return window.crypto.subtle.importKey( | 315 return window.crypto.subtle.importKey( |
315 "spki", cachedSpki, algorithm, false, ["verify"]); | 316 "spki", cachedSpki, algorithm, false, ["verify"]); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), | 352 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), |
352 chrome.enterprise.platformKeys.removeCertificate.bind( | 353 chrome.enterprise.platformKeys.removeCertificate.bind( |
353 null, userToken.id, cert1a.buffer), | 354 null, userToken.id, cert1a.buffer), |
354 assertCertsStored.bind(null, userToken, [cert1b]), | 355 assertCertsStored.bind(null, userToken, [cert1b]), |
355 chrome.enterprise.platformKeys.removeCertificate.bind( | 356 chrome.enterprise.platformKeys.removeCertificate.bind( |
356 null, userToken.id, cert1b.buffer), | 357 null, userToken.id, cert1b.buffer), |
357 assertCertsStored.bind(null, userToken, []) | 358 assertCertsStored.bind(null, userToken, []) |
358 ]); | 359 ]); |
359 }, | 360 }, |
360 | 361 |
| 362 // Call generate key with invalid algorithm parameter, missing |
| 363 // modulusLength. |
| 364 function algorithmParameterMissingModulusLength() { |
| 365 var algorithm = { |
| 366 name: "RSASSA-PKCS1-v1_5", |
| 367 publicExponent: |
| 368 new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 |
| 369 hash: { |
| 370 name: "SHA-1", |
| 371 } |
| 372 }; |
| 373 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
| 374 function(keyPair) { |
| 375 assertTrue(false, 'generateKey was expected to fail'); |
| 376 }, |
| 377 callbackPass(function(error) { |
| 378 assertTrue(error instanceof Error); |
| 379 assertEq('A required parameter was missing or out-of-range', |
| 380 error.message); |
| 381 })); |
| 382 }, |
| 383 |
| 384 // Call generate key with invalid algorithm parameter, missing hash. |
| 385 function algorithmParameterMissingHash() { |
| 386 var algorithm = { |
| 387 name: 'RSASSA-PKCS1-v1_5', |
| 388 modulusLength: 512, |
| 389 publicExponent: |
| 390 new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 |
| 391 }; |
| 392 userToken.subtleCrypto.generateKey(algorithm, false, ['sign']).then( |
| 393 function(keyPair) { |
| 394 assertTrue(false, 'generateKey was expected to fail'); |
| 395 }, |
| 396 callbackPass(function(error) { |
| 397 assertTrue(error instanceof Error); |
| 398 assertEq('A required parameter was missing or out-of-range', |
| 399 error.message); |
| 400 })); |
| 401 }, |
| 402 |
361 // Imports a certificate for which now private key was imported/generated | 403 // Imports a certificate for which now private key was imported/generated |
362 // before. | 404 // before. |
363 function missingPrivateKey() { | 405 function missingPrivateKey() { |
364 chrome.enterprise.platformKeys.importCertificate( | 406 chrome.enterprise.platformKeys.importCertificate( |
365 userToken.id, cert2.buffer, callbackFail('Key not found.')); | 407 userToken.id, cert2.buffer, callbackFail('Key not found.')); |
366 }, | 408 }, |
367 function importInvalidCert() { | 409 function importInvalidCert() { |
368 var invalidCert = new ArrayBuffer(16); | 410 var invalidCert = new ArrayBuffer(16); |
369 chrome.enterprise.platformKeys.importCertificate( | 411 chrome.enterprise.platformKeys.importCertificate( |
370 userToken.id, | 412 userToken.id, |
(...skipping 14 matching lines...) Expand all Loading... |
385 callbackFail('Certificate is not a valid X.509 certificate.')); | 427 callbackFail('Certificate is not a valid X.509 certificate.')); |
386 }, | 428 }, |
387 function getCertsInvalidToken() { | 429 function getCertsInvalidToken() { |
388 chrome.enterprise.platformKeys.getCertificates( | 430 chrome.enterprise.platformKeys.getCertificates( |
389 'invalid token id', callbackFail('The token is not valid.')); | 431 'invalid token id', callbackFail('The token is not valid.')); |
390 } | 432 } |
391 ]); | 433 ]); |
392 } | 434 } |
393 | 435 |
394 beforeTests(runTests); | 436 beforeTests(runTests); |
OLD | NEW |