Enigma: Fix keys import from inside of an encrypted message (#5285)

pull/5754/head
Aleksander Machniak 8 years ago
parent fe1e2b27aa
commit 8a3b80d394

@ -11,6 +11,7 @@ CHANGELOG Roundcube Webmail
- Fix bug where multi-folder search could choose a wrong folder in "this and subfolders" scope (#5282)
- Fix bug where multi-folder search didn't work for unsubscribed INBOX (#5259)
- Fix bug where "no body" alert could be displayed when sending mailvelope email
- Enigma: Fix keys import from inside of an encrypted message (#5285)
RELEASE 1.2.0
-------------

@ -446,17 +446,26 @@ rcube_webmail.prototype.enigma_password_submit = function(data)
return this.enigma_password_compose_submit(data);
}
var lock = this.set_busy(true, 'loading');
// message preview
var form = $('<form>').attr({method: 'post', action: location.href, style: 'display:none'})
var lock = this.set_busy(true, 'loading'),
form = $('<form>').attr({method: 'post', action: data.action || location.href, style: 'display:none'})
.append($('<input>').attr({type: 'hidden', name: '_keyid', value: data.key}))
.append($('<input>').attr({type: 'hidden', name: '_passwd', value: data.password}))
.append($('<input>').attr({type: 'hidden', name: '_token', value: this.env.request_token}))
.append($('<input>').attr({type: 'hidden', name: '_unlock', value: lock}))
.appendTo(document.body);
.append($('<input>').attr({type: 'hidden', name: '_unlock', value: lock}));
// Additional form fields for request parameters
$.each(data, function(i, v) {
if (i.indexOf('input') == 0)
form.append($('<input>').attr({type: 'hidden', name: i.substring(5), value: v}))
});
if (data.iframe) {
var name = 'enigma_frame_' + (new Date()).getTime(),
frame = $('<iframe>').attr({style: 'display:none', name: name}).appendTo(document.body);
form.attr('target', name);
}
form.submit();
form.appendTo(document.body).submit();
}
// submit entered password - in mail compose page

@ -462,9 +462,9 @@ class enigma extends rcube_plugin
*/
function import_file()
{
$this->load_engine();
$this->load_ui();
$this->engine->import_file();
$this->ui->import_file();
}
/**

@ -1051,7 +1051,7 @@ class enigma_engine
}
/**
* PGP keys/certs importing.
* PGP keys/certs import.
*
* @param mixed Import file name or content
* @param boolean True if first argument is a filename
@ -1071,7 +1071,7 @@ class enigma_engine
), true, false);
}
else {
$result['imported'] = $result['public_imported'] + $result['private_imported'];
$result['imported'] = $result['public_imported'] + $result['private_imported'];
$result['unchanged'] = $result['public_unchanged'] + $result['private_unchanged'];
}
@ -1079,32 +1079,7 @@ class enigma_engine
}
/**
* Handler for keys/certs import request action
*/
function import_file()
{
$uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
$mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
$mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
$storage = $this->rc->get_storage();
if ($uid && $mime_id) {
$storage->set_folder($mbox);
$part = $storage->get_message_part($uid, $mime_id);
}
if ($part && is_array($result = $this->import_key($part))) {
$this->rc->output->show_message('enigma.keysimportsuccess', 'confirmation',
array('new' => $result['imported'], 'old' => $result['unchanged']));
}
else
$this->rc->output->show_message('enigma.keysimportfailed', 'error');
$this->rc->output->send();
}
/**
* PGP keys/certs export..
* PGP keys/certs export.
*
* @param string Key ID
* @param resource Optional output stream

@ -161,7 +161,7 @@ class enigma_ui
$data = array_merge($params, $data);
}
if ($this->rc->action == 'send') {
if ($this->rc->action == 'send' || $this->rc->action == 'plugin.enigmaimport') {
$this->rc->output->command('enigma_password_request', $data);
}
else {
@ -1059,6 +1059,57 @@ class enigma_ui
return $p;
}
/**
* Handler for keys/certs import request action
*/
function import_file()
{
$uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
$mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
$mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
$storage = $this->rc->get_storage();
$engine = $this->enigma->load_engine();
if ($uid && $mime_id) {
// Note: we get the attachment body via rcube_message class
// to support keys inside encrypted messages (#5285)
$message = new rcube_message($uid, $mbox);
// Check if we don't need to ask for password again
foreach ($engine->decryptions as $status) {
if ($status instanceof enigma_error) {
if ($status->getCode() == enigma_error::BADPASS) {
$this->password_prompt($status, array(
'input_uid' => $uid,
'input_mbox' => $mbox,
'input_part' => $mime_id,
'input_task' => 'mail',
'input_action' => 'plugin.enigmaimport',
'action' => '?',
'iframe' => true,
));
$this->rc->output->send($this->rc->output->type == 'html' ? 'iframe' : null);
return;
}
}
}
if ($engine->is_keys_part($message->mime_parts[$mime_id])) {
$part = $message->get_part_body($mime_id);
}
}
if ($part && is_array($result = $engine->import_key($part))) {
$this->rc->output->show_message('enigma.keysimportsuccess', 'confirmation',
array('new' => $result['imported'], 'old' => $result['unchanged']));
}
else {
$this->rc->output->show_message('enigma.keysimportfailed', 'error');
}
$this->rc->output->send($this->rc->output->type == 'html' ? 'iframe' : null);
}
/**
* Check if the part or its parent exists in the array
* of decryptions/signatures. Returns found ID.

Loading…
Cancel
Save