GnuPG 2.1: Fix importing newly generated (secret) keys using GnuPG 2.1

pull/5498/head
Aleksander Machniak 9 years ago
parent fba3e1ae0c
commit 7829da358d

@ -99,7 +99,7 @@ rcube_webmail.prototype.enigma_key_create_save = function()
size = $('#key-size').val();
$('[name="identity[]"]:checked').each(function() {
users.push(this.value);
users.push(this.value);
});
// validate the form
@ -124,7 +124,8 @@ rcube_webmail.prototype.enigma_key_create_save = function()
openpgp.generateKeyPair(options).then(function(keypair) {
// success
var post = {_a: 'import', _keys: keypair.privateKeyArmored, _generated: 1};
var post = {_a: 'import', _keys: keypair.privateKeyArmored, _generated: 1,
_passwd: password, _keyid: keypair.key.primaryKey.fingerprint};
// send request to server
rcmail.http_post('plugin.enigmakeys', post, lock);

@ -77,12 +77,13 @@ abstract class enigma_driver
/**
* Key/Cert file import.
*
* @param string File name or file content
* @param bollean True if first argument is a filename
* @param string File name or file content
* @param bolean True if first argument is a filename
* @param array Optional key => password map
*
* @return mixed Import status array or enigma_error
*/
abstract function import($content, $isfile = false);
abstract function import($content, $isfile = false, $passwords = array());
/**
* Key/Cert export.

@ -201,14 +201,20 @@ class enigma_driver_gnupg extends enigma_driver
/**
* Key file import.
*
* @param string File name or file content
* @param bollean True if first argument is a filename
* @param string File name or file content
* @param bolean True if first argument is a filename
* @param array Optional key => password map
*
* @return mixed Import status array or enigma_error
*/
public function import($content, $isfile=false)
public function import($content, $isfile = false, $passwords = array())
{
try {
// GnuPG 2.1 requires secret key passphrases on import
foreach ($passwords as $keyid => $pass) {
$this->gpg->addPassphrase($keyid, $pass);
}
if ($isfile)
return $this->gpg->importKeyFile($content);
else
@ -251,7 +257,7 @@ class enigma_driver_gnupg extends enigma_driver
*
* @return mixed Array of enigma_key objects or enigma_error
*/
public function list_keys($pattern='')
public function list_keys($pattern = '')
{
try {
$keys = $this->gpg->getKeys($pattern);

@ -122,7 +122,7 @@ class enigma_driver_phpssl extends enigma_driver
return $sig;
}
public function import($content, $isfile=false)
public function import($content, $isfile = false, $passwords = array())
{
}

@ -1113,10 +1113,10 @@ class enigma_engine
*
* @return mixed Import status data array or enigma_error
*/
function import_key($content, $isfile=false)
function import_key($content, $isfile = false)
{
$this->load_pgp_driver();
$result = $this->pgp_driver->import($content, $isfile);
$result = $this->pgp_driver->import($content, $isfile, $this->get_passwords());
if ($result instanceof enigma_error) {
rcube::raise_error(array(
@ -1174,7 +1174,7 @@ class enigma_engine
$passwd = rcube_utils::get_input_value('_passwd', rcube_utils::INPUT_POST, true);
if ($keyid && $passwd !== null && strlen($passwd)) {
$this->save_password($keyid, $passwd);
$this->save_password(strtoupper($keyid), $passwd);
}
}

@ -498,8 +498,9 @@ class enigma_ui
{
// Import process
if ($data = rcube_utils::get_input_value('_keys', rcube_utils::INPUT_POST)) {
// Import from generation form (ajax request)
$this->enigma->load_engine();
$this->enigma->engine->password_handler();
$result = $this->enigma->engine->import_key($data);
if (is_array($result)) {

Loading…
Cancel
Save