Chromium Code Reviews| Index: chrome/test/data/extensions/api_test/enterprise_certificates/import.js |
| diff --git a/chrome/test/data/extensions/api_test/enterprise_certificates/import.js b/chrome/test/data/extensions/api_test/enterprise_certificates/import.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e286f1c0d8557f6d84bf0cf3f06823d027164db |
| --- /dev/null |
| +++ b/chrome/test/data/extensions/api_test/enterprise_certificates/import.js |
| @@ -0,0 +1,128 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +var assertEq = chrome.test.assertEq; |
| +var assertTrue = chrome.test.assertTrue; |
| +var fail = chrome.test.fail; |
| +var succeed = chrome.test.succeed; |
| +var callback = chrome.test.callback; |
| + |
| +// openssl genrsa > privkey.pem |
| +// openssl pkcs8 -inform pem -in privkey.pem -topk8 \ |
| +// -outform der -out privkey8.der -nocrypt |
| +// xxd -i privkey8.der |
| +var privateKeyDer = new Uint8Array([ |
| + 0x30, 0x82, 0x01, 0x56, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
| + 0x01, 0x40, 0x30, 0x82, 0x01, 0x3c, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, |
| + 0xac, 0x6c, 0x72, 0x46, 0xa2, 0xde, 0x88, 0x30, 0x54, 0x06, 0xad, 0xc7, |
| + 0x2d, 0x64, 0x6e, 0xf6, 0x0f, 0x72, 0x3e, 0x92, 0x31, 0xcc, 0x0b, 0xa0, |
| + 0x18, 0x20, 0xb0, 0xdb, 0x86, 0xab, 0x11, 0xc6, 0xa5, 0x78, 0xea, 0x64, |
| + 0xe8, 0xeb, 0xa5, 0xb3, 0x78, 0x5d, 0xbb, 0x10, 0x57, 0xe6, 0x12, 0x23, |
| + 0x89, 0x92, 0x1d, 0xa0, 0xe5, 0x1e, 0xd1, 0xc9, 0x0e, 0x62, 0xcb, 0xc9, |
| + 0xaf, 0xde, 0x4e, 0x83, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x43, |
| + 0xa4, 0x2f, 0x98, 0x82, 0x60, 0x66, 0x70, 0xff, 0x25, 0xb7, 0x9a, 0xc1, |
| + 0xb5, 0xfa, 0xc9, 0xd0, 0xf9, 0x72, 0x8e, 0x8b, 0xb6, 0x8e, 0x80, 0xf9, |
| + 0xb6, 0x29, 0x6b, 0x95, 0x83, 0x1a, 0xef, 0x7b, 0x98, 0xf1, 0x91, 0x52, |
| + 0xe8, 0x07, 0x8e, 0x6d, 0x3f, 0xca, 0x37, 0x12, 0x3b, 0x77, 0xc6, 0x65, |
| + 0xa0, 0xfd, 0xf6, 0x58, 0x24, 0xfd, 0x88, 0xb2, 0x56, 0x99, 0x7c, 0x3f, |
| + 0x3b, 0x27, 0x31, 0x02, 0x21, 0x00, 0xe5, 0x16, 0x34, 0x1c, 0x60, 0x35, |
| + 0x6d, 0x54, 0x4d, 0xe2, 0xc6, 0x40, 0xf4, 0xc5, 0x19, 0x1b, 0x58, 0xbe, |
| + 0x30, 0xca, 0x72, 0xc7, 0x03, 0x31, 0x74, 0xe8, 0xf7, 0xad, 0xf5, 0xdd, |
| + 0xba, 0x8f, 0x02, 0x21, 0x00, 0xc0, 0xae, 0x18, 0xb2, 0xa2, 0x26, 0x22, |
| + 0x7b, 0x32, 0x8b, 0x21, 0xd3, 0xfb, 0xa5, 0xe6, 0xca, 0xae, 0x55, 0xab, |
| + 0xf6, 0x8c, 0x32, 0xd4, 0x40, 0x41, 0x8f, 0x89, 0x7b, 0x02, 0x8e, 0x76, |
| + 0xcd, 0x02, 0x21, 0x00, 0xbf, 0x67, 0xa6, 0xd0, 0x92, 0x9d, 0xf1, 0x24, |
| + 0x00, 0x13, 0x5a, 0xbc, 0x09, 0x06, 0xe9, 0x2c, 0x4d, 0x20, 0x53, 0x99, |
| + 0xc2, 0xfe, 0x7e, 0xaf, 0x82, 0xd3, 0xe7, 0xa5, 0x64, 0x89, 0x07, 0x07, |
| + 0x02, 0x21, 0x00, 0xc0, 0x26, 0x9e, 0xd0, 0xbe, 0x6e, 0x03, 0x63, 0x13, |
| + 0x03, 0xb7, 0x87, 0x9c, 0xe5, 0x54, 0xe4, 0xf9, 0xb8, 0xcc, 0x56, 0x82, |
| + 0x78, 0x4a, 0x3d, 0x8e, 0x64, 0x23, 0xb9, 0xbd, 0xd1, 0xef, 0x5d, 0x02, |
| + 0x21, 0x00, 0xdd, 0x15, 0xd3, 0x12, 0xe2, 0x85, 0xcf, 0x41, 0x70, 0xad, |
| + 0xeb, 0xf6, 0xa0, 0x6d, 0xe6, 0x78, 0x10, 0x44, 0xdf, 0xce, 0xc4, 0x62, |
| + 0x25, 0x3a, 0x98, 0x46, 0x9e, 0x7c, 0xc6, 0x01, 0x6c, 0x3d |
| +]); |
| + |
| +// openssl req -new -x509 -key privkey.pem -out cacert.pem -days 36500 |
| +var certDer = new Uint8Array([ |
| + 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
| + 0x02, 0x02, 0x09, 0x00, 0x9e, 0x11, 0x7e, 0xff, 0x43, 0x84, 0xd4, 0xe6, |
| + 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
| + 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
| + 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
| + 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
| + 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| + 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
| + 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
| + 0x74, 0x64, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x34, 0x30, 0x37, |
| + 0x31, 0x35, 0x35, 0x30, 0x30, 0x38, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x31, |
| + 0x34, 0x30, 0x33, 0x31, 0x34, 0x31, 0x35, 0x35, 0x30, 0x30, 0x38, 0x5a, |
| + 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, |
| + 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, |
| + 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, |
| + 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, |
| + 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, |
| + 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, |
| + 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, |
| + 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, |
| + 0xac, 0x6c, 0x72, 0x46, 0xa2, 0xde, 0x88, 0x30, 0x54, 0x06, 0xad, 0xc7, |
| + 0x2d, 0x64, 0x6e, 0xf6, 0x0f, 0x72, 0x3e, 0x92, 0x31, 0xcc, 0x0b, 0xa0, |
| + 0x18, 0x20, 0xb0, 0xdb, 0x86, 0xab, 0x11, 0xc6, 0xa5, 0x78, 0xea, 0x64, |
| + 0xe8, 0xeb, 0xa5, 0xb3, 0x78, 0x5d, 0xbb, 0x10, 0x57, 0xe6, 0x12, 0x23, |
| + 0x89, 0x92, 0x1d, 0xa0, 0xe5, 0x1e, 0xd1, 0xc9, 0x0e, 0x62, 0xcb, 0xc9, |
| + 0xaf, 0xde, 0x4e, 0x83, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, |
| + 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, |
| + 0x75, 0x6c, 0x61, 0xfb, 0xb0, 0x6e, 0x37, 0x32, 0x41, 0x62, 0x3b, 0x55, |
| + 0xbd, 0x5f, 0x6b, 0xe0, 0xdb, 0xb9, 0xc7, 0xec, 0x30, 0x1f, 0x06, 0x03, |
| + 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x75, 0x6c, 0x61, |
| + 0xfb, 0xb0, 0x6e, 0x37, 0x32, 0x41, 0x62, 0x3b, 0x55, 0xbd, 0x5f, 0x6b, |
| + 0xe0, 0xdb, 0xb9, 0xc7, 0xec, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, |
| + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
| + 0x00, 0xa5, 0xe8, 0x9d, 0x3d, 0xc4, 0x1a, 0x6e, 0xd2, 0x92, 0x42, 0x37, |
| + 0xb9, 0x3a, 0xb3, 0x8e, 0x2f, 0x55, 0xb5, 0xf2, 0xe4, 0x6e, 0x39, 0x0d, |
| + 0xa8, 0xba, 0x10, 0x43, 0x57, 0xdd, 0x4e, 0x4e, 0x52, 0xc6, 0xbe, 0x07, |
| + 0xdb, 0x83, 0x05, 0x97, 0x97, 0xc1, 0x7b, 0xd5, 0x5c, 0x50, 0x64, 0x0f, |
| + 0x96, 0xff, 0x3d, 0x83, 0x37, 0x8f, 0x3a, 0x85, 0x08, 0x62, 0x5c, 0xb1, |
| + 0x2f, 0x68, 0xb2, 0x4a, 0x4a |
| +]); |
| + |
| +function checkPropertyIsDefined(prop) { |
| + if (!chrome.enterprise.certificates) { |
| + fail('chrome.enterprise.certificates is not defined'); |
| + return false; |
| + } |
| + if (!chrome.enterprise.certificates[prop]) { |
| + fail('chrome.enterprise.certificates.' + prop + ' is not undefined'); |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +chrome.test.runTests([function importClientCert() { |
| + var algorithmKeyGen = {name: "RSASSA-PKCS1-v1_5", hash: {name: "SHA-256"}}; |
|
eroman
2014/04/10 18:45:46
nit: "algorithmKeyGen" --> "importAlgorithm" ?
pneubeck (no reviews)
2014/04/11 14:13:59
Done.
|
| + |
| + if (!window.crypto.subtle) { |
| + fail('window.crypto.subtle is not defined.'); |
| + return; |
| + } |
| + window.crypto.subtle |
| + .importKey('pkcs8', privateKeyDer, algorithmKeyGen, false, ["sign"]) |
|
eroman
2014/04/10 18:45:46
The tests should also exercise calling importClien
pneubeck (no reviews)
2014/04/11 14:13:59
Done.
|
| + .then(callback(function(key) { |
| + if (!checkPropertyIsDefined('importClientCertificate')) |
| + return; |
| + console.log('Imported/generated a key'); |
| + chrome.enterprise.certificates.importClientCertificate( |
| + key, |
| + certDer.buffer, |
| + 'user', |
| + callback(function() { |
| + succeed(); |
| + })); |
| + }), |
| + callback(function(e) { |
| + console.error("Unable to import/generate key " + e); |
| + fail(); |
| + })) |
| +}]); |