From e00b1ab44e5c98001bc085cdce039e1f95a15d03 Mon Sep 17 00:00:00 2001 From: Felix Hammerl Date: Tue, 22 Oct 2013 16:12:18 +0200 Subject: [PATCH] [WO-53] change key export to include public key --- src/js/controller/account.js | 6 +++--- src/js/controller/login-new-device.js | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/js/controller/account.js b/src/js/controller/account.js index ca2d2d3..982706f 100644 --- a/src/js/controller/account.js +++ b/src/js/controller/account.js @@ -20,14 +20,14 @@ define(function(require) { }; $scope.exportKeyFile = function() { - var userId = emailDao._account.emailAddress; - emailDao._keychain.getUserKeyPair(userId, function(err, keypair) { + emailDao._crypto.exportKeys(function(err, keys) { if (err) { console.error(err); return; } - download(keypair.privateKey.encryptedKey, 'key_' + userId + '.asc', 'text/plain'); + var id = keys.keyId.substring(8,keys.keyId.length); + download(keys.publicKeyArmored + keys.privateKeyArmored, id + '.asc', 'text/plain'); }); }; diff --git a/src/js/controller/login-new-device.js b/src/js/controller/login-new-device.js index cb4f6ce..0d3f184 100644 --- a/src/js/controller/login-new-device.js +++ b/src/js/controller/login-new-device.js @@ -26,7 +26,7 @@ define(function(require) { keypair.privateKey = { _id: keypair.publicKey._id, userId: userId, - encryptedKey: $scope.key + encryptedKey: $scope.key.privateKeyArmored }; emailDao.unlock(keypair, passphrase, function(err) { if (err) { @@ -75,7 +75,18 @@ define(function(require) { reader.onload = (function(scope) { return function(e) { - scope.key = e.target.result; + var rawKeys = e.target.result, + index = rawKeys.indexOf('-----BEGIN PGP PRIVATE KEY BLOCK-----'); + + if (index === -1) { + console.error('Erroneous key file format!'); + return; + } + + scope.key = { + publicKeyArmored: rawKeys.substring(0,index), + privateKeyArmored: rawKeys.substring(index,rawKeys.length) + }; }; })(scope); reader.readAsText(files[0]);