Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 internalAPI = require('platformKeys.internalAPI'); | 5 var internalAPI = require('platformKeys.internalAPI'); |
| 6 | 6 |
| 7 var normalizeAlgorithm = | 7 var normalizeAlgorithm = |
| 8 requireNative('platform_keys_natives').NormalizeAlgorithm; | 8 requireNative('platform_keys_natives').NormalizeAlgorithm; |
| 9 | 9 |
| 10 function combineAlgorithms(algorithm, importParams) { | 10 function normalizeImportParams(importParams) { |
| 11 if (importParams.name === undefined) { | 11 if (!importParams.name) { |
| 12 importParams.name = algorithm.name; | 12 throw new Error('Algorithm: name: Missing or not a string'); |
|
Andrew T Wilson (Slow)
2015/03/19 07:31:49
I guess some other code is checking if the supplie
pneubeck (no reviews)
2015/03/23 13:20:59
Done.
| |
| 13 } | 13 } |
| 14 | 14 |
| 15 // Verify whether importParams.hash equals | 15 // Check whether importParams.hash equals |
| 16 // { name: 'none' } | 16 // { name: 'none' } |
| 17 // and temporarily replace it by a valid WebCrypto Hash for normalization. | |
| 18 var hashIsNone = false; | |
| 17 if (importParams.hash && | 19 if (importParams.hash && |
| 18 importParams.hash.name.toLowerCase() === 'none') { | 20 importParams.hash.name.toLowerCase() === 'none') { |
|
Andrew T Wilson (Slow)
2015/03/19 07:31:49
Also, note that there's kind of an implicit contra
Andrew T Wilson (Slow)
2015/03/19 07:31:49
SO, if I pass in :
importParams.hash = { name: 'n
pneubeck (no reviews)
2015/03/23 13:20:59
Done.
pneubeck (no reviews)
2015/03/23 13:20:59
yes. extraneous attributes shall be removed. I add
| |
| 19 if (Object.keys(importParams.hash).length != 1 || | 21 hashIsNone = true; |
| 20 Object.keys(importParams).length != 2) { | 22 // Will be reverted to 'none' after normalization. |
| 21 // 'name' must be the only hash property in this case. | 23 importParams.hash = { name: 'SHA-1' }; |
| 22 throw new Error('A required parameter was missing or out-of-range'); | |
| 23 } | |
| 24 importParams.hash.name = 'none'; | |
| 25 } else { | |
| 26 // Otherwise apply WebCrypto's algorithm normalization. | |
| 27 importParams = normalizeAlgorithm(importParams, 'ImportKey'); | |
| 28 if (!importParams) { | |
| 29 // throw CreateSyntaxError(); | |
| 30 throw new Error('A required parameter was missing or out-of-range'); | |
| 31 } | |
| 32 } | 24 } |
| 33 | 25 |
| 26 // Apply WebCrypto's algorithm normalization. | |
| 27 importParams = normalizeAlgorithm(importParams, 'ImportKey'); | |
| 28 if (!importParams) { | |
| 29 throw new Error('A required parameter was missing or out-of-range'); | |
| 30 } | |
| 31 if (hashIsNone) { | |
| 32 importParams.hash = { name: 'none' }; | |
| 33 } | |
| 34 return importParams; | |
| 35 } | |
| 36 | |
| 37 function combineAlgorithms(algorithm, importParams) { | |
| 34 // internalAPI.getPublicKey returns publicExponent as ArrayBuffer, but it | 38 // internalAPI.getPublicKey returns publicExponent as ArrayBuffer, but it |
| 35 // should be a Uint8Array. | 39 // should be a Uint8Array. |
| 36 if (algorithm.publicExponent) { | 40 if (algorithm.publicExponent) { |
| 37 algorithm.publicExponent = new Uint8Array(algorithm.publicExponent); | 41 algorithm.publicExponent = new Uint8Array(algorithm.publicExponent); |
| 38 } | 42 } |
| 39 | 43 |
| 40 for (var key in importParams) { | 44 algorithm.hash = importParams.hash; |
| 41 algorithm[key] = importParams[key]; | |
| 42 } | |
| 43 | |
| 44 return algorithm; | 45 return algorithm; |
| 45 } | 46 } |
| 46 | 47 |
| 47 function getPublicKey(cert, importParams, callback) { | 48 function getPublicKey(cert, importParams, callback) { |
| 49 importParams = normalizeImportParams(importParams); | |
| 50 // TODO(pneubeck): pass importParams.name to the internal getPublicKey and | |
| 51 // verify on the C++ side that the requested algorithm is compatible with the | |
| 52 // given SubjectPublicKeyInfo of the certificate. | |
| 53 // https://crbug.com/466584 | |
| 48 internalAPI.getPublicKey(cert, function(publicKey, algorithm) { | 54 internalAPI.getPublicKey(cert, function(publicKey, algorithm) { |
| 49 var combinedAlgorithm = combineAlgorithms(algorithm, importParams); | 55 var combinedAlgorithm = combineAlgorithms(algorithm, importParams); |
| 50 callback(publicKey, combinedAlgorithm); | 56 callback(publicKey, combinedAlgorithm); |
| 51 }); | 57 }); |
| 52 } | 58 } |
| 53 | 59 |
| 54 exports.getPublicKey = getPublicKey; | 60 exports.getPublicKey = getPublicKey; |
| OLD | NEW |