[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() {
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');
});
};

View File

@ -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]);