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 var utils = require('utils'); | 5 var utils = require('utils'); |
6 var internalAPI = require('enterprise.platformKeys.internalAPI'); | 6 var internalAPI = require('enterprise.platformKeys.internalAPI'); |
7 var intersect = require('enterprise.platformKeys.utils').intersect; | 7 var intersect = require('enterprise.platformKeys.utils').intersect; |
8 var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair; | 8 var KeyPair = require('enterprise.platformKeys.KeyPair').KeyPair; |
9 var keyModule = require('enterprise.platformKeys.Key'); | 9 var keyModule = require('enterprise.platformKeys.Key'); |
10 var getSpki = keyModule.getSpki; | 10 var getSpki = keyModule.getSpki; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 // returns true. | 44 // returns true. |
45 function catchInvalidTokenError(reject) { | 45 function catchInvalidTokenError(reject) { |
46 if (chrome.runtime.lastError && | 46 if (chrome.runtime.lastError && |
47 chrome.runtime.lastError.message == errorInvalidToken) { | 47 chrome.runtime.lastError.message == errorInvalidToken) { |
48 reject(chrome.runtime.lastError); | 48 reject(chrome.runtime.lastError); |
49 return true; | 49 return true; |
50 } | 50 } |
51 return false; | 51 return false; |
52 } | 52 } |
53 | 53 |
54 // Returns true if |array| is a BigInteger describing the standard public | |
55 // exponent 65537. | |
eroman
2014/06/09 22:49:01
The description could be clearer, indicating that
pneubeck (no reviews)
2014/06/16 17:54:51
Done.
| |
56 function equalsStandardPublicExponent(array) { | |
57 var expected = [0x01, 0x00, 0x01]; | |
58 if (array.length < expected.length) | |
59 return false; | |
60 for (var i = 0; i < array.length; i++) { | |
61 var expectedDigit = 0; | |
62 if (i < expected.length) { | |
63 // |expected| is symmetric, endianness doesn't matter. | |
64 expectedDigit = expected[i]; | |
65 } | |
66 if (array[array.length - 1 - i] !== expectedDigit) | |
67 return false; | |
68 } | |
69 return true; | |
70 } | |
71 | |
54 /** | 72 /** |
55 * Implementation of WebCrypto.SubtleCrypto used in enterprise.platformKeys. | 73 * Implementation of WebCrypto.SubtleCrypto used in enterprise.platformKeys. |
56 * @param {string} tokenId The id of the backing Token. | 74 * @param {string} tokenId The id of the backing Token. |
57 * @constructor | 75 * @constructor |
58 */ | 76 */ |
59 var SubtleCryptoImpl = function(tokenId) { | 77 var SubtleCryptoImpl = function(tokenId) { |
60 this.tokenId = tokenId; | 78 this.tokenId = tokenId; |
61 }; | 79 }; |
62 | 80 |
63 SubtleCryptoImpl.prototype.generateKey = | 81 SubtleCryptoImpl.prototype.generateKey = |
(...skipping 12 matching lines...) Expand all Loading... | |
76 throw CreateDataError(); | 94 throw CreateDataError(); |
77 } | 95 } |
78 var normalizedAlgorithmParameters = | 96 var normalizedAlgorithmParameters = |
79 normalizeAlgorithm(algorithm, 'GenerateKey'); | 97 normalizeAlgorithm(algorithm, 'GenerateKey'); |
80 if (!normalizedAlgorithmParameters) { | 98 if (!normalizedAlgorithmParameters) { |
81 // TODO(pneubeck): It's not clear from the WebCrypto spec which error to | 99 // TODO(pneubeck): It's not clear from the WebCrypto spec which error to |
82 // throw here. | 100 // throw here. |
83 throw CreateSyntaxError(); | 101 throw CreateSyntaxError(); |
84 } | 102 } |
85 | 103 |
86 if (normalizedAlgorithmParameters.name !== 'RSASSA-PKCS1-v1_5') { | 104 if (normalizedAlgorithmParameters.name !== 'RSASSA-PKCS1-v1_5' || |
105 !equalsStandardPublicExponent( | |
106 normalizedAlgorithmParameters.publicExponent)) { | |
87 // Note: This deviates from WebCrypto.SubtleCrypto. | 107 // Note: This deviates from WebCrypto.SubtleCrypto. |
88 throw CreateNotSupportedError(); | 108 throw CreateNotSupportedError(); |
89 } | 109 } |
90 | 110 |
91 internalAPI.generateKey(subtleCrypto.tokenId, | 111 internalAPI.generateKey(subtleCrypto.tokenId, |
92 normalizedAlgorithmParameters.modulusLength, | 112 normalizedAlgorithmParameters.modulusLength, |
93 function(spki) { | 113 function(spki) { |
94 if (catchInvalidTokenError(reject)) | 114 if (catchInvalidTokenError(reject)) |
95 return; | 115 return; |
96 if (chrome.runtime.lastError) { | 116 if (chrome.runtime.lastError) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 // TODO(pneubeck): It should be possible to export to format 'jwk'. | 167 // TODO(pneubeck): It should be possible to export to format 'jwk'. |
148 throw CreateNotSupportedError(); | 168 throw CreateNotSupportedError(); |
149 } | 169 } |
150 }); | 170 }); |
151 }; | 171 }; |
152 | 172 |
153 exports.SubtleCrypto = | 173 exports.SubtleCrypto = |
154 utils.expose('SubtleCrypto', | 174 utils.expose('SubtleCrypto', |
155 SubtleCryptoImpl, | 175 SubtleCryptoImpl, |
156 {functions:['generateKey', 'sign', 'exportKey']}); | 176 {functions:['generateKey', 'sign', 'exportKey']}); |
OLD | NEW |