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 // Custom binding for the platformKeys API. | 5 // Custom binding for the platformKeys API. |
6 | 6 |
7 var binding = require('binding').Binding.create('platformKeys'); | 7 var binding = require('binding').Binding.create('platformKeys'); |
8 var SubtleCrypto = require('platformKeys.SubtleCrypto').SubtleCrypto; | 8 var SubtleCrypto = require('platformKeys.SubtleCrypto').SubtleCrypto; |
9 var getPublicKey = require('platformKeys.getPublicKey').getPublicKey; | |
9 var internalAPI = require('platformKeys.internalAPI'); | 10 var internalAPI = require('platformKeys.internalAPI'); |
10 | 11 |
12 var keyModule = require('platformKeys.Key'); | |
13 var Key = keyModule.Key; | |
14 var KeyType = keyModule.KeyType; | |
15 var KeyUsage = keyModule.KeyUsage; | |
16 | |
17 function createPublicKey(publicKeySpki, algorithm) { | |
18 return new Key(KeyType.public, publicKeySpki, algorithm, [KeyUsage.verify], | |
19 true /* extractable */); | |
20 } | |
21 | |
22 function createPrivateKey(publicKeySpki, algorithm) { | |
23 return new Key(KeyType.private, publicKeySpki, algorithm, [KeyUsage.sign], | |
24 false /* not extractable */); | |
25 } | |
26 | |
11 binding.registerCustomHook(function(api) { | 27 binding.registerCustomHook(function(api) { |
12 var apiFunctions = api.apiFunctions; | 28 var apiFunctions = api.apiFunctions; |
13 var subtleCrypto = new SubtleCrypto('' /* tokenId */); | 29 var subtleCrypto = new SubtleCrypto('' /* tokenId */); |
14 | 30 |
15 apiFunctions.setHandleRequest( | 31 apiFunctions.setHandleRequest( |
16 'selectClientCertificates', function(details, callback) { | 32 'selectClientCertificates', function(details, callback) { |
17 internalAPI.selectClientCertificates(details, callback); | 33 internalAPI.selectClientCertificates(details, function(matches) { |
34 callback($Array.map(matches, function(match) { | |
35 if (match.keyAlgorithm.publicExponent) { | |
36 match.keyAlgorithm.publicExponent = | |
37 new Uint8Array(match.keyAlgorithm.publicExponent); | |
Ryan Sleevi
2015/02/03 01:44:50
Ditto remarks here
pneubeck (no reviews)
2015/02/03 20:15:00
added a comment here as well.
| |
38 } | |
39 return match; | |
40 })); | |
41 }); | |
18 }); | 42 }); |
19 | 43 |
20 apiFunctions.setHandleRequest( | 44 apiFunctions.setHandleRequest( |
21 'subtleCrypto', function() { return subtleCrypto }); | 45 'subtleCrypto', function() { return subtleCrypto }); |
46 | |
47 apiFunctions.setHandleRequest( | |
48 'getKeyPair', function(cert, params, callback) { | |
49 getPublicKey(cert, params, function(publicKey, algorithm) { | |
50 callback(createPublicKey(publicKey, algorithm), | |
51 createPrivateKey(publicKey, algorithm)); | |
52 }); | |
53 }); | |
22 }); | 54 }); |
23 | 55 |
24 exports.binding = binding.generate(); | 56 exports.binding = binding.generate(); |
OLD | NEW |