Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: chrome/renderer/resources/extensions/platform_keys_custom_bindings.js

Issue 884073002: Implement chrome.platformKeys.getKeyPair(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cert_impl2
Patch Set: Rebased. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
diff --git a/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js b/chrome/renderer/resources/extensions/platform_keys_custom_bindings.js
index c9eb65956994cbb80d7cf254eee766f26d365b4c..9320e021722770c8020e6753d9d49d439038f32c 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();
« no previous file with comments | « chrome/renderer/resources/extensions/platform_keys/internal_api.js ('k') | chrome/renderer/resources/renderer_resources.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698