summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
diff options
context:
space:
mode:
authorpneubeck <pneubeck@chromium.org>2015-02-15 01:05:48 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-15 09:06:31 +0000
commitbae26c1d31de27e89f358bca44e738925bb431ef (patch)
tree09dbec2bdfa92960393389d64b5d61bc5d74edad /chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
parent69a960210633bb95599c531965d783b91fe70956 (diff)
downloadchromium_src-bae26c1d31de27e89f358bca44e738925bb431ef.zip
chromium_src-bae26c1d31de27e89f358bca44e738925bb431ef.tar.gz
chromium_src-bae26c1d31de27e89f358bca44e738925bb431ef.tar.bz2
Implement chrome.platformKeys.getKeyPair().
This also makes the chrome.platformKeys.subtleCrypto().sign() working. Still missing: per extension key permissions and UI changes. Reland of https://codereview.chromium.org/884073002/ BUG=450167 TBR=arv@chromium.org (for renderer_resources.grd change) Review URL: https://codereview.chromium.org/927883002 Cr-Commit-Position: refs/heads/master@{#316410}
Diffstat (limited to 'chrome/renderer/resources/extensions/platform_keys_custom_bindings.js')
-rw-r--r--chrome/renderer/resources/extensions/platform_keys_custom_bindings.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js b/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
index c9eb659..9320e02 100644
--- a/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
+++ b/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
@@ -6,19 +6,53 @@
var binding = require('binding').Binding.create('platformKeys');
var SubtleCrypto = require('platformKeys.SubtleCrypto').SubtleCrypto;
+var getPublicKey = require('platformKeys.getPublicKey').getPublicKey;
var internalAPI = require('platformKeys.internalAPI');
+var keyModule = require('platformKeys.Key');
+var Key = keyModule.Key;
+var KeyType = keyModule.KeyType;
+var KeyUsage = keyModule.KeyUsage;
+
+function createPublicKey(publicKeySpki, algorithm) {
+ return new Key(KeyType.public, publicKeySpki, algorithm, [KeyUsage.verify],
+ true /* extractable */);
+}
+
+function createPrivateKey(publicKeySpki, algorithm) {
+ return new Key(KeyType.private, publicKeySpki, algorithm, [KeyUsage.sign],
+ false /* not extractable */);
+}
+
binding.registerCustomHook(function(api) {
var apiFunctions = api.apiFunctions;
var subtleCrypto = new SubtleCrypto('' /* tokenId */);
apiFunctions.setHandleRequest(
'selectClientCertificates', function(details, callback) {
- internalAPI.selectClientCertificates(details, callback);
+ internalAPI.selectClientCertificates(details, function(matches) {
+ callback($Array.map(matches, function(match) {
+ // internalAPI.selectClientCertificates returns publicExponent as
+ // ArrayBuffer, but it should be a Uint8Array.
+ if (match.keyAlgorithm.publicExponent) {
+ match.keyAlgorithm.publicExponent =
+ new Uint8Array(match.keyAlgorithm.publicExponent);
+ }
+ return match;
+ }));
+ });
});
apiFunctions.setHandleRequest(
'subtleCrypto', function() { return subtleCrypto });
+
+ apiFunctions.setHandleRequest(
+ 'getKeyPair', function(cert, params, callback) {
+ getPublicKey(cert, params, function(publicKey, algorithm) {
+ callback(createPublicKey(publicKey, algorithm),
+ createPrivateKey(publicKey, algorithm));
+ });
+ });
});
exports.binding = binding.generate();