1cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 2cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// found in the LICENSE file. 4cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 5cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// Custom binding for the enterprise.platformKeys API. 6cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 7cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The platformKeys API consists of two major parts: 8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// - the certificate management. 9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// - the key generation and crypto operations and 10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The former is implemented without custom binding as static functions. 11cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The latter is exposed by implementing WebCrypto's SubtleCrypto interface. 12cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The internal API provides the key and crypto operations through static 13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// functions expecting token IDs and this custom binding adds the SubtleCrypto 14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// wrapper. 15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The Token object holds the token id and the SubtleCrypto member. 16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)var binding = require('binding').Binding.create('enterprise.platformKeys'); 18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)var Token = require('enterprise.platformKeys.Token').Token; 19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)var internalAPI = require('enterprise.platformKeys.internalAPI'); 20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)binding.registerCustomHook(function(api) { 22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) var apiFunctions = api.apiFunctions; 23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) var ret = apiFunctions.setHandleRequest('getTokens', function(callback) { 25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) internalAPI.getTokens(function(tokenIds) { 26cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) callback($Array.map(tokenIds, 27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) function(tokenId) { return new Token(tokenId); })); 28cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) }); 29cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) }); 30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)}); 31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 32cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)exports.binding = binding.generate(); 33