OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 var assertEq = chrome.test.assertEq; |
| 6 var assertTrue = chrome.test.assertTrue; |
| 7 var assertThrows = chrome.test.assertThrows; |
| 8 var fail = chrome.test.fail; |
| 9 var succeed = chrome.test.succeed; |
| 10 var callbackPass = chrome.test.callbackPass; |
| 11 var callbackFail= chrome.test.callbackFail; |
| 12 |
| 13 // openssl req -new -x509 -key privkey.pem \ |
| 14 // -outform der -out cert.der -days 36500 |
| 15 // xxd -i cert.der |
| 16 // based on privateKeyPkcs8 |
| 17 var cert1a = new Uint8Array([ |
| 18 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
| 19 0x02, 0x02, 0x09, 0x00, 0xd2, 0xcc, 0x76, 0xeb, 0x19, 0xb9, 0x3a, 0x33, |
| 20 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
| 21 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
| 22 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
| 23 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
| 24 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| 25 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
| 26 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
| 27 0x74, 0x64, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x34, 0x31, 0x35, |
| 28 0x31, 0x34, 0x35, 0x32, 0x30, 0x33, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x31, |
| 29 0x34, 0x30, 0x33, 0x32, 0x32, 0x31, 0x34, 0x35, 0x32, 0x30, 0x33, 0x5a, |
| 30 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, |
| 31 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, |
| 32 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, |
| 33 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, |
| 34 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, |
| 35 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, |
| 36 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, |
| 37 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, |
| 38 0xc7, 0xc1, 0x4d, 0xd5, 0xdc, 0x3a, 0x2e, 0x1f, 0x42, 0x30, 0x3d, 0x21, |
| 39 0x1e, 0xa2, 0x1f, 0x60, 0xcb, 0x71, 0x11, 0x53, 0xb0, 0x75, 0xa0, 0x62, |
| 40 0xfe, 0x5e, 0x0a, 0xde, 0xb0, 0x0f, 0x48, 0x97, 0x5e, 0x42, 0xa7, 0x3a, |
| 41 0xd1, 0xca, 0x4c, 0xe3, 0xdb, 0x5f, 0x31, 0xc2, 0x99, 0x08, 0x89, 0xcd, |
| 42 0x6d, 0x20, 0xaa, 0x75, 0xe6, 0x2b, 0x98, 0xd2, 0xf3, 0x7b, 0x4b, 0xe5, |
| 43 0x9b, 0xfe, 0xe2, 0x6d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, |
| 44 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, |
| 45 0xbd, 0x85, 0x6b, 0xdd, 0x84, 0xd1, 0x54, 0x2e, 0xad, 0xb4, 0x5e, 0xdd, |
| 46 0x24, 0x7e, 0x16, 0x9c, 0x84, 0x1e, 0x19, 0xf0, 0x30, 0x1f, 0x06, 0x03, |
| 47 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xbd, 0x85, 0x6b, |
| 48 0xdd, 0x84, 0xd1, 0x54, 0x2e, 0xad, 0xb4, 0x5e, 0xdd, 0x24, 0x7e, 0x16, |
| 49 0x9c, 0x84, 0x1e, 0x19, 0xf0, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, |
| 50 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| 51 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
| 52 0x00, 0x37, 0x23, 0x2f, 0x81, 0x24, 0xfc, 0xec, 0x2d, 0x0b, 0xd1, 0xa0, |
| 53 0x74, 0xdf, 0x2e, 0x34, 0x9a, 0x92, 0x33, 0xae, 0x75, 0xd6, 0x60, 0xfc, |
| 54 0x44, 0x1d, 0x65, 0x8c, 0xb7, 0xd9, 0x60, 0x3b, 0xc7, 0x20, 0x30, 0xdf, |
| 55 0x17, 0x07, 0xd1, 0x87, 0xda, 0x2b, 0x7f, 0x84, 0xf3, 0xfc, 0xb0, 0x31, |
| 56 0x42, 0x08, 0x17, 0x96, 0xd2, 0x1b, 0xdc, 0x28, 0xae, 0xf8, 0xbd, 0xf9, |
| 57 0x4e, 0x78, 0xc3, 0xe8, 0x80 |
| 58 ]); |
| 59 |
| 60 // based on privateKeyPkcs8, different from cert1a |
| 61 var cert1b = new Uint8Array([ |
| 62 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
| 63 0x02, 0x02, 0x09, 0x00, 0xe7, 0x1e, 0x6e, 0xb0, 0x12, 0x87, 0xf5, 0x09, |
| 64 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
| 65 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
| 66 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
| 67 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
| 68 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| 69 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
| 70 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
| 71 0x74, 0x64, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x34, 0x31, 0x35, |
| 72 0x31, 0x35, 0x31, 0x39, 0x30, 0x30, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x31, |
| 73 0x34, 0x30, 0x33, 0x32, 0x32, 0x31, 0x35, 0x31, 0x39, 0x30, 0x30, 0x5a, |
| 74 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, |
| 75 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, |
| 76 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, |
| 77 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, |
| 78 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, |
| 79 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, |
| 80 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, |
| 81 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, |
| 82 0xc7, 0xc1, 0x4d, 0xd5, 0xdc, 0x3a, 0x2e, 0x1f, 0x42, 0x30, 0x3d, 0x21, |
| 83 0x1e, 0xa2, 0x1f, 0x60, 0xcb, 0x71, 0x11, 0x53, 0xb0, 0x75, 0xa0, 0x62, |
| 84 0xfe, 0x5e, 0x0a, 0xde, 0xb0, 0x0f, 0x48, 0x97, 0x5e, 0x42, 0xa7, 0x3a, |
| 85 0xd1, 0xca, 0x4c, 0xe3, 0xdb, 0x5f, 0x31, 0xc2, 0x99, 0x08, 0x89, 0xcd, |
| 86 0x6d, 0x20, 0xaa, 0x75, 0xe6, 0x2b, 0x98, 0xd2, 0xf3, 0x7b, 0x4b, 0xe5, |
| 87 0x9b, 0xfe, 0xe2, 0x6d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, |
| 88 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, |
| 89 0xbd, 0x85, 0x6b, 0xdd, 0x84, 0xd1, 0x54, 0x2e, 0xad, 0xb4, 0x5e, 0xdd, |
| 90 0x24, 0x7e, 0x16, 0x9c, 0x84, 0x1e, 0x19, 0xf0, 0x30, 0x1f, 0x06, 0x03, |
| 91 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0xbd, 0x85, 0x6b, |
| 92 0xdd, 0x84, 0xd1, 0x54, 0x2e, 0xad, 0xb4, 0x5e, 0xdd, 0x24, 0x7e, 0x16, |
| 93 0x9c, 0x84, 0x1e, 0x19, 0xf0, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, |
| 94 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| 95 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
| 96 0x00, 0x82, 0x95, 0xa7, 0x08, 0x6c, 0xbd, 0x49, 0xe6, 0x1e, 0xc1, 0xd9, |
| 97 0x58, 0x54, 0x11, 0x11, 0x84, 0x77, 0x1e, 0xad, 0xe9, 0x73, 0x69, 0x1c, |
| 98 0x5c, 0xaa, 0x26, 0x3e, 0x5f, 0x1d, 0x89, 0x20, 0xc3, 0x90, 0xa4, 0x67, |
| 99 0xfa, 0x26, 0x20, 0xd7, 0x1f, 0xae, 0x42, 0x89, 0x30, 0x61, 0x43, 0x8a, |
| 100 0x8c, 0xbe, 0xd4, 0x32, 0xf7, 0x96, 0x71, 0x2a, 0xcd, 0xeb, 0x26, 0xf6, |
| 101 0xdb, 0x54, 0x95, 0xca, 0x5a |
| 102 ]); |
| 103 |
| 104 // based on a private key different than privateKeyPkcs8 |
| 105 var cert2 = new Uint8Array([ |
| 106 0x30, 0x82, 0x01, 0xd5, 0x30, 0x82, 0x01, 0x7f, 0xa0, 0x03, 0x02, 0x01, |
| 107 0x02, 0x02, 0x09, 0x00, 0x9e, 0x11, 0x7e, 0xff, 0x43, 0x84, 0xd4, 0xe6, |
| 108 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, |
| 109 0x05, 0x05, 0x00, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, |
| 110 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, |
| 111 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, |
| 112 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, |
| 113 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, |
| 114 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, |
| 115 0x74, 0x64, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x34, 0x30, 0x37, |
| 116 0x31, 0x35, 0x35, 0x30, 0x30, 0x38, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x31, |
| 117 0x34, 0x30, 0x33, 0x31, 0x34, 0x31, 0x35, 0x35, 0x30, 0x30, 0x38, 0x5a, |
| 118 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, |
| 119 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, |
| 120 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, |
| 121 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, |
| 122 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, |
| 123 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, |
| 124 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, |
| 125 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, |
| 126 0xac, 0x6c, 0x72, 0x46, 0xa2, 0xde, 0x88, 0x30, 0x54, 0x06, 0xad, 0xc7, |
| 127 0x2d, 0x64, 0x6e, 0xf6, 0x0f, 0x72, 0x3e, 0x92, 0x31, 0xcc, 0x0b, 0xa0, |
| 128 0x18, 0x20, 0xb0, 0xdb, 0x86, 0xab, 0x11, 0xc6, 0xa5, 0x78, 0xea, 0x64, |
| 129 0xe8, 0xeb, 0xa5, 0xb3, 0x78, 0x5d, 0xbb, 0x10, 0x57, 0xe6, 0x12, 0x23, |
| 130 0x89, 0x92, 0x1d, 0xa0, 0xe5, 0x1e, 0xd1, 0xc9, 0x0e, 0x62, 0xcb, 0xc9, |
| 131 0xaf, 0xde, 0x4e, 0x83, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x50, 0x30, |
| 132 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, |
| 133 0x75, 0x6c, 0x61, 0xfb, 0xb0, 0x6e, 0x37, 0x32, 0x41, 0x62, 0x3b, 0x55, |
| 134 0xbd, 0x5f, 0x6b, 0xe0, 0xdb, 0xb9, 0xc7, 0xec, 0x30, 0x1f, 0x06, 0x03, |
| 135 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, 0x75, 0x6c, 0x61, |
| 136 0xfb, 0xb0, 0x6e, 0x37, 0x32, 0x41, 0x62, 0x3b, 0x55, 0xbd, 0x5f, 0x6b, |
| 137 0xe0, 0xdb, 0xb9, 0xc7, 0xec, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x1d, 0x13, |
| 138 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
| 139 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, |
| 140 0x00, 0xa5, 0xe8, 0x9d, 0x3d, 0xc4, 0x1a, 0x6e, 0xd2, 0x92, 0x42, 0x37, |
| 141 0xb9, 0x3a, 0xb3, 0x8e, 0x2f, 0x55, 0xb5, 0xf2, 0xe4, 0x6e, 0x39, 0x0d, |
| 142 0xa8, 0xba, 0x10, 0x43, 0x57, 0xdd, 0x4e, 0x4e, 0x52, 0xc6, 0xbe, 0x07, |
| 143 0xdb, 0x83, 0x05, 0x97, 0x97, 0xc1, 0x7b, 0xd5, 0x5c, 0x50, 0x64, 0x0f, |
| 144 0x96, 0xff, 0x3d, 0x83, 0x37, 0x8f, 0x3a, 0x85, 0x08, 0x62, 0x5c, 0xb1, |
| 145 0x2f, 0x68, 0xb2, 0x4a, 0x4a |
| 146 ]); |
| 147 |
| 148 function runAsyncSequence(funcs) { |
| 149 if (funcs.length == 0) |
| 150 return; |
| 151 function go(i) { |
| 152 var current = funcs[i]; |
| 153 console.log('#' + (i + 1) + ' of ' + funcs.length); |
| 154 if (i == funcs.length - 1) { |
| 155 current(callbackPass()); |
| 156 } else { |
| 157 current(callbackPass(go.bind(undefined, i + 1))); |
| 158 } |
| 159 }; |
| 160 go(0); |
| 161 } |
| 162 |
| 163 // Some array comparison. Note: not lexicographical! |
| 164 function compareArrays(array1, array2) { |
| 165 if (array1.length < array2.length) |
| 166 return -1; |
| 167 if (array1.length > array2.length) |
| 168 return 1; |
| 169 for (var i = 0; i < array1.length; i++) { |
| 170 if (array1[i] < array2[i]) |
| 171 return -1; |
| 172 if (array1[i] > array2[i]) |
| 173 return 1; |
| 174 } |
| 175 return 0; |
| 176 } |
| 177 |
| 178 function sortCerts(certs) { |
| 179 return certs.sort(compareArrays); |
| 180 } |
| 181 |
| 182 function assertCertsStored(token, expectedCerts, callback) { |
| 183 chrome.enterprise.platformKeys.getCertificates( |
| 184 token.id, |
| 185 callbackPass(function(actualCerts) { |
| 186 assertEq(expectedCerts.length, |
| 187 actualCerts.length, |
| 188 'Number of stored certs not as expected'); |
| 189 if (expectedCerts.length == actualCerts.length) { |
| 190 actualCerts = actualCerts.map( |
| 191 function(buffer) { return new Uint8Array(buffer); }); |
| 192 actualCerts = sortCerts(actualCerts); |
| 193 expectedCerts = sortCerts(expectedCerts); |
| 194 for (var i = 0; i < expectedCerts.length; i++) { |
| 195 assertTrue(compareArrays(expectedCerts[i], actualCerts[i]) == 0, |
| 196 'Certs at index ' + i + ' differ'); |
| 197 } |
| 198 } |
| 199 if (callback) |
| 200 callback(); |
| 201 })); |
| 202 } |
| 203 |
| 204 function getUserToken(callback) { |
| 205 chrome.enterprise.platformKeys.getTokens(function(tokens) { |
| 206 for (var i = 0; i < tokens.length; i++) { |
| 207 if (tokens[i].id == 'user') { |
| 208 callback(tokens[i]); |
| 209 return; |
| 210 } |
| 211 } |
| 212 callback(undefined); |
| 213 }); |
| 214 } |
| 215 |
| 216 function beforeTests(callback) { |
| 217 getUserToken(function(userToken) { |
| 218 if (!userToken) |
| 219 chrome.test.fail('no user token'); |
| 220 if (userToken.id != 'user') |
| 221 chrome.test.fail('token is not named "user".'); |
| 222 |
| 223 callback(userToken); |
| 224 }); |
| 225 } |
| 226 |
| 227 assertTrue(!!chrome.enterprise, "No enterprise namespace."); |
| 228 assertTrue(!!chrome.enterprise.platformKeys, "No platformKeys namespace."); |
| 229 assertTrue(!!chrome.enterprise.platformKeys.getTokens, |
| 230 "No getTokens function."); |
| 231 assertTrue(!!chrome.enterprise.platformKeys.importCertificate, |
| 232 "No importCertificate function."); |
| 233 assertTrue(!!chrome.enterprise.platformKeys.removeCertificate, |
| 234 "No removeCertificate function."); |
| 235 |
| 236 function runTests(userToken) { |
| 237 chrome.test.runTests([ |
| 238 function hasSubtleCryptoMethods() { |
| 239 assertTrue(!!userToken.subtleCrypto.generateKey, |
| 240 "user token has no generateKey method"); |
| 241 assertTrue(!!userToken.subtleCrypto.sign, |
| 242 "user token has no sign method"); |
| 243 assertTrue(!!userToken.subtleCrypto.exportKey, |
| 244 "user token has no exportKey method"); |
| 245 succeed(); |
| 246 }, |
| 247 function initiallyNoCerts() { assertCertsStored(userToken, []); }, |
| 248 function generateKeyAndSign() { |
| 249 var algorithm = { |
| 250 name: "RSASSA-PKCS1-v1_5", |
| 251 // RsaHashedKeyGenParams |
| 252 modulusLength: 512, |
| 253 publicExponent: |
| 254 new Uint8Array([0x01, 0x00, 0x01]), // Equivalent to 65537 |
| 255 hash: { |
| 256 name: "SHA-1", |
| 257 } |
| 258 }; |
| 259 // Some random data to sign. |
| 260 var data = new Uint8Array([0, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6]); |
| 261 var cachedKeyPair; |
| 262 var cachedSpki; |
| 263 var cachedSignature; |
| 264 userToken.subtleCrypto.generateKey(algorithm, false, ["sign"]) |
| 265 .then(callbackPass(function(keyPair) { |
| 266 assertTrue(!!keyPair, "No key pair."); |
| 267 cachedKeyPair = keyPair; |
| 268 return userToken.subtleCrypto.exportKey('spki', |
| 269 keyPair.publicKey); |
| 270 }), |
| 271 function(error) { |
| 272 assertTrue(false, "GenerateKey failed: " + error); |
| 273 }) |
| 274 .then(callbackPass(function(publicKeySpki) { |
| 275 // TODO: remove Uint8Array once WebCrypto supports |
| 276 // ArrayBuffers. |
| 277 cachedSpki = new Uint8Array(publicKeySpki); |
| 278 return userToken.subtleCrypto.sign( |
| 279 {}, cachedKeyPair.privateKey, data); |
| 280 }), |
| 281 function(error) { |
| 282 assertTrue(false, "Export failed: " + error); |
| 283 }) |
| 284 .then(callbackPass(function(signature) { |
| 285 assertTrue(!!signature, "No signature."); |
| 286 assertTrue(signature.length != 0, "Signature is empty."); |
| 287 // TODO: remove Uint8Array once WebCrypto supports |
| 288 // ArrayBuffers. |
| 289 cachedSignature = new Uint8Array(signature); |
| 290 return window.crypto.subtle.importKey( |
| 291 "spki", cachedSpki, algorithm, false, ["verify"]); |
| 292 }), |
| 293 function(error) { assertTrue(false, "Sign failed: " + error); }) |
| 294 .then(callbackPass(function(webCryptoPublicKey) { |
| 295 assertTrue(!!webCryptoPublicKey); |
| 296 return window.crypto.subtle.verify( |
| 297 algorithm, webCryptoPublicKey, cachedSignature, data); |
| 298 }), |
| 299 function(error) { |
| 300 assertTrue(false, "Import failed: " + error); |
| 301 }) |
| 302 .then(callbackPass(function(success) { |
| 303 assertEq(true, success, "Signature invalid."); |
| 304 }), |
| 305 function(error) { |
| 306 assertTrue(false, "Verification failed: " + error); |
| 307 }); |
| 308 }, |
| 309 function importAndRemoveCerts() { |
| 310 runAsyncSequence([ |
| 311 chrome.enterprise.platformKeys.importCertificate.bind( |
| 312 null, userToken.id, cert1a.buffer), |
| 313 assertCertsStored.bind(null, userToken, [cert1a]), |
| 314 // Importing the same cert again shouldn't change anything. |
| 315 chrome.enterprise.platformKeys.importCertificate.bind( |
| 316 null, userToken.id, cert1a.buffer), |
| 317 assertCertsStored.bind(null, userToken, [cert1a]), |
| 318 chrome.enterprise.platformKeys.importCertificate.bind( |
| 319 null, userToken.id, cert1b.buffer), |
| 320 assertCertsStored.bind(null, userToken, [cert1a, cert1b]), |
| 321 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 322 null, userToken.id, cert1a.buffer), |
| 323 assertCertsStored.bind(null, userToken, [cert1b]), |
| 324 chrome.enterprise.platformKeys.removeCertificate.bind( |
| 325 null, userToken.id, cert1b.buffer), |
| 326 assertCertsStored.bind(null, userToken, []) |
| 327 ]); |
| 328 }, |
| 329 function missingPrivateKey() { |
| 330 chrome.enterprise.platformKeys.importCertificate( |
| 331 userToken.id, cert2.buffer, callbackFail('Key not found.')); |
| 332 }, |
| 333 function importInvalidCert() { |
| 334 var invalidCert = new ArrayBuffer(16); |
| 335 chrome.enterprise.platformKeys.importCertificate( |
| 336 userToken.id, |
| 337 invalidCert, |
| 338 callbackFail('Certificate is not a valid X.509 certificate.')); |
| 339 }, |
| 340 function removeInvalidCert() { |
| 341 var invalidCert = new ArrayBuffer(16); |
| 342 chrome.enterprise.platformKeys.removeCertificate( |
| 343 userToken.id, |
| 344 invalidCert, |
| 345 callbackFail('Certificate is not a valid X.509 certificate.')); |
| 346 } |
| 347 ]); |
| 348 } |
| 349 |
| 350 beforeTests(runTests); |
OLD | NEW |