| 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 'use strict'; | 8 'use strict'; |
| 9 | 9 |
| 10 var assertEq = chrome.test.assertEq; | 10 var assertEq = chrome.test.assertEq; |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 getUserToken(function(userToken) { | 253 getUserToken(function(userToken) { |
| 254 if (!userToken) | 254 if (!userToken) |
| 255 fail('no user token'); | 255 fail('no user token'); |
| 256 if (userToken.id != 'user') | 256 if (userToken.id != 'user') |
| 257 fail('token is not named "user".'); | 257 fail('token is not named "user".'); |
| 258 | 258 |
| 259 callback(userToken); | 259 callback(userToken); |
| 260 }); | 260 }); |
| 261 } | 261 } |
| 262 | 262 |
| 263 function checkAlgorithmIsCopiedOnRead(key) { |
| 264 var algorithm = key.algorithm; |
| 265 var originalAlgorithm = { |
| 266 name: algorithm.name, |
| 267 modulusLength: algorithm.modulusLength, |
| 268 publicExponent: algorithm.publicExponent, |
| 269 hash: {name: algorithm.hash.name} |
| 270 }; |
| 271 var originalModulusLength = algorithm.modulusLength; |
| 272 algorithm.hash.name = null; |
| 273 algorithm.hash = null; |
| 274 algorithm.name = null; |
| 275 algorithm.modulusLength = null; |
| 276 algorithm.publicExponent = null; |
| 277 assertEq(originalAlgorithm, key.algorithm); |
| 278 } |
| 279 |
| 280 function checkPropertyIsReadOnly(object, key) { |
| 281 var original = object[key]; |
| 282 try { |
| 283 object[key] = {}; |
| 284 fail('Expected the property to be read-only and an exception to be thrown'); |
| 285 } catch (error) { |
| 286 assertEq(original, object[key]); |
| 287 } |
| 288 } |
| 289 |
| 290 function checkKeyPairCommonFormat(keyPair) { |
| 291 checkPropertyIsReadOnly(keyPair, 'privateKey'); |
| 292 var privateKey = keyPair.privateKey; |
| 293 assertEq('private', privateKey.type); |
| 294 assertEq(false, privateKey.extractable); |
| 295 checkPropertyIsReadOnly(privateKey, 'algorithm'); |
| 296 checkAlgorithmIsCopiedOnRead(privateKey); |
| 297 |
| 298 checkPropertyIsReadOnly(keyPair, 'publicKey'); |
| 299 var publicKey = keyPair.publicKey; |
| 300 assertEq('public', publicKey.type); |
| 301 assertEq(true, publicKey.extractable); |
| 302 checkPropertyIsReadOnly(publicKey, 'algorithm'); |
| 303 checkAlgorithmIsCopiedOnRead(publicKey); |
| 304 } |
| 305 |
| 263 function runTests(userToken) { | 306 function runTests(userToken) { |
| 264 chrome.test.runTests([ | 307 chrome.test.runTests([ |
| 265 function hasSubtleCryptoMethods() { | 308 function hasSubtleCryptoMethods() { |
| 266 assertTrue(!!userToken.subtleCrypto.generateKey, | 309 assertTrue(!!userToken.subtleCrypto.generateKey, |
| 267 "user token has no generateKey method"); | 310 "user token has no generateKey method"); |
| 268 assertTrue(!!userToken.subtleCrypto.sign, | 311 assertTrue(!!userToken.subtleCrypto.sign, |
| 269 "user token has no sign method"); | 312 "user token has no sign method"); |
| 270 assertTrue(!!userToken.subtleCrypto.exportKey, | 313 assertTrue(!!userToken.subtleCrypto.exportKey, |
| 271 "user token has no exportKey method"); | 314 "user token has no exportKey method"); |
| 272 succeed(); | 315 succeed(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 301 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) | 344 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) |
| 302 .then(callbackPass(function(keyPair) { | 345 .then(callbackPass(function(keyPair) { |
| 303 assertTrue(!!keyPair, "No key pair."); | 346 assertTrue(!!keyPair, "No key pair."); |
| 304 cachedKeyPair = keyPair; | 347 cachedKeyPair = keyPair; |
| 305 return userToken.subtleCrypto.exportKey('spki', | 348 return userToken.subtleCrypto.exportKey('spki', |
| 306 keyPair.publicKey); | 349 keyPair.publicKey); |
| 307 }), | 350 }), |
| 308 function(error) { fail("GenerateKey failed: " + error); }) | 351 function(error) { fail("GenerateKey failed: " + error); }) |
| 309 .then(callbackPass(function(publicKeySpki) { | 352 .then(callbackPass(function(publicKeySpki) { |
| 310 // Ensure that the returned key pair has the expected format. | 353 // Ensure that the returned key pair has the expected format. |
| 354 // Some parameter independent checks: |
| 355 checkKeyPairCommonFormat(cachedKeyPair); |
| 356 |
| 311 // Checks depending on the generateKey arguments: | 357 // Checks depending on the generateKey arguments: |
| 312 var privateKey = cachedKeyPair.privateKey; | 358 var privateKey = cachedKeyPair.privateKey; |
| 313 assertEq(['sign'], privateKey.usages); | 359 assertEq(['sign'], privateKey.usages); |
| 314 assertEq(algorithm, privateKey.algorithm); | 360 assertEq(algorithm, privateKey.algorithm); |
| 315 | 361 |
| 316 var publicKey = cachedKeyPair.publicKey; | 362 var publicKey = cachedKeyPair.publicKey; |
| 317 assertEq([], publicKey.usages); | 363 assertEq([], publicKey.usages); |
| 318 assertEq(algorithm, publicKey.algorithm); | 364 assertEq(algorithm, publicKey.algorithm); |
| 319 | 365 |
| 320 cachedSpki = publicKeySpki; | 366 cachedSpki = publicKeySpki; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 callbackFail('Certificate is not a valid X.509 certificate.')); | 518 callbackFail('Certificate is not a valid X.509 certificate.')); |
| 473 }, | 519 }, |
| 474 function getCertsInvalidToken() { | 520 function getCertsInvalidToken() { |
| 475 chrome.enterprise.platformKeys.getCertificates( | 521 chrome.enterprise.platformKeys.getCertificates( |
| 476 'invalid token id', callbackFail('The token is not valid.')); | 522 'invalid token id', callbackFail('The token is not valid.')); |
| 477 } | 523 } |
| 478 ]); | 524 ]); |
| 479 } | 525 } |
| 480 | 526 |
| 481 beforeTests(runTests); | 527 beforeTests(runTests); |
| OLD | NEW |