1
0
mirror of https://github.com/moparisthebest/mail synced 2025-02-12 05:00:19 -05:00

[WO-53] change key export to include public key

This commit is contained in:
Felix Hammerl 2013-10-22 16:12:18 +02:00
parent 36c8d1e003
commit e00b1ab44e
2 changed files with 16 additions and 5 deletions

View File

@ -20,14 +20,14 @@ define(function(require) {
}; };
$scope.exportKeyFile = function() { $scope.exportKeyFile = function() {
var userId = emailDao._account.emailAddress; emailDao._crypto.exportKeys(function(err, keys) {
emailDao._keychain.getUserKeyPair(userId, function(err, keypair) {
if (err) { if (err) {
console.error(err); console.error(err);
return; 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');
}); });
}; };

View File

@ -26,7 +26,7 @@ define(function(require) {
keypair.privateKey = { keypair.privateKey = {
_id: keypair.publicKey._id, _id: keypair.publicKey._id,
userId: userId, userId: userId,
encryptedKey: $scope.key encryptedKey: $scope.key.privateKeyArmored
}; };
emailDao.unlock(keypair, passphrase, function(err) { emailDao.unlock(keypair, passphrase, function(err) {
if (err) { if (err) {
@ -75,7 +75,18 @@ define(function(require) {
reader.onload = (function(scope) { reader.onload = (function(scope) {
return function(e) { 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); })(scope);
reader.readAsText(files[0]); reader.readAsText(files[0]);