GnuPG 2.1: Fix secret keys export

pull/5514/head
Aleksander Machniak 8 years ago
parent 7e90de4ef5
commit ed44a73ca5

@ -241,8 +241,8 @@ class enigma_driver_gnupg extends enigma_driver
if ($with_private) {
// GnuPG 2.1 requires secret key passphrases on export
foreach ($passwords as $keyid => $pass) {
$this->gpg->addPassphrase($keyid, $pass);
foreach ($passwords as $_keyid => $pass) {
$this->gpg->addPassphrase($_keyid, $pass);
}
$priv = $this->gpg->exportPrivateKey($keyid, true);

@ -155,15 +155,25 @@ class enigma_ui
$data = $status->getData('bad');
}
$data = array('keyid' => key($data), 'user' => $data[key($data)]);
$keyid = key($data);
$data = array(
'keyid' => $params['keyid'] ?: $keyid,
'user' => $data[$keyid]
);
// With GnuPG 2.1 user name may not be specified (e.g. on private
// key export), we'll get the key information and set the name appropriately
if ($keyid && $params['keyid'] && strpos($data['user'], $keyid) !== false) {
$key = $this->enigma->engine->get_key($params['keyid']);
if ($key && $key->name) {
$data['user'] = $key->name;
}
}
if (!empty($params)) {
$data = array_merge($params, $data);
}
// @TODO: Get user name/address when keyid == user,
// it may happen on GnuPG 2.1
if (preg_match('/^(send|plugin.enigmaimport|plugin.enigmakeys)$/', $this->rc->action)) {
$this->rc->output->command('enigma_password_request', $data);
}
@ -480,7 +490,8 @@ class enigma_ui
$status = null;
foreach ($list as $key) {
$status = $engine->export_key(is_object($key) ? $key->id : $key, $fp, (bool) $priv);
$keyid = is_object($key) ? $key->id : $key;
$status = $engine->export_key($keyid, $fp, (bool) $priv);
if ($status instanceof enigma_error) {
$code = $status->getCode();
@ -495,6 +506,7 @@ class enigma_ui
'action' => '?',
'iframe' => true,
'nolock' => true,
'keyid' => $keyid,
));
fclose($fp);
$this->rc->output->send('iframe');

Loading…
Cancel
Save