Enigma: GPG keys export

pull/297/head
Aleksander Machniak 9 years ago
parent 4c53e78915
commit 211929876b

@ -8,25 +8,19 @@ The plugin uses gpg binary on the server and stores all keys
Encryption/decryption is done server-side. So, this plugin
is for users that trust the server.
WARNING! The plugin is in very early state. See below for a list
of missing features and known issues.
Implemented features:
---------------------
+ PGP: signatures verification
+ PGP: messages decryption
+ PGP: Sending of encrypted/signed messages
+ PGP: keys management UI (key import, delete)
+ PGP: keys management UI (key import, export, delete)
+ PGP: key generation (client- or server-side)
+ Handling of PGP keys attached to incoming messages
+ User preferences to disable plugin features
TODO (must have):
-----------------
- Keys export to file
TODO (later):
TODO:
-------------
- Handling of big messages with temp files
- Key info in contact details page (optional)
@ -35,6 +29,7 @@ TODO (later):
- revoke,
- change expiration date, change passphrase, add photo,
- manage user IDs
- export private keys
- Generate revocation certs
- Search filter to see invalid/expired keys
- Key server(s) support (search, import, upload, refresh)
@ -53,10 +48,3 @@ TODO (later):
- S/MIME: Sending signed/encrypted messages
- S/MIME: Handling of certs attached to incoming messages
- S/MIME: Certificate info in Contacts details page (optional)
Known issues:
-------------
1. There are Crypt_GPG issues when using gnupg >= 2.0
- http://pear.php.net/bugs/bug.php?id=19914
- http://pear.php.net/bugs/bug.php?id=20453
- http://pear.php.net/bugs/bug.php?id=20527

@ -6,7 +6,7 @@ window.rcmail && rcmail.addEventListener('init', function(evt) {
if (rcmail.gui_objects.keyslist) {
rcmail.keys_list = new rcube_list_widget(rcmail.gui_objects.keyslist,
{multiselect:false, draggable:false, keyboard:false});
{multiselect:true, draggable:false, keyboard:false});
rcmail.keys_list
.addEventListener('select', function(o) { rcmail.enigma_keylist_select(o); })
.addEventListener('keypress', function(o) { rcmail.enigma_keylist_keypress(o); })
@ -25,11 +25,16 @@ window.rcmail && rcmail.addEventListener('init', function(evt) {
rcmail.register_command('search', function(props) {return rcmail.enigma_search(props); }, true);
rcmail.register_command('reset-search', function(props) {return rcmail.enigma_search_reset(props); }, true);
rcmail.register_command('plugin.enigma-import', function() { rcmail.enigma_import(); }, true);
// rcmail.register_command('plugin.enigma-export', function() { rcmail.enigma_key_export(); }, true);
rcmail.register_command('plugin.enigma-key-import', function() { rcmail.enigma_key_import() }, true);
rcmail.register_command('plugin.enigma-key-delete', function(props) { return rcmail.enigma_key_delete(); });
rcmail.register_command('plugin.enigma-key-export', function() { rcmail.enigma_export(); });
rcmail.register_command('plugin.enigma-key-export-selected', function() { rcmail.enigma_export(true); });
rcmail.register_command('plugin.enigma-key-import', function() { rcmail.enigma_key_import(); }, true);
rcmail.register_command('plugin.enigma-key-delete', function(props) { return rcmail.enigma_delete(); });
rcmail.register_command('plugin.enigma-key-create', function(props) { return rcmail.enigma_key_create(); }, true);
rcmail.register_command('plugin.enigma-key-save', function(props) { return rcmail.enigma_key_create_save(); }, true);
rcmail.addEventListener('responseafterplugin.enigmakeys', function() {
rcmail.enable_command('plugin.enigma-key-export', rcmail.env.rowcount > 0);
});
}
}
else if (rcmail.env.task == 'mail') {
@ -125,7 +130,7 @@ rcube_webmail.prototype.enigma_key_create_success = function()
};
// Delete key(s)
rcube_webmail.prototype.enigma_key_delete = function()
rcube_webmail.prototype.enigma_delete = function()
{
var keys = this.keys_list.get_selection();
@ -139,6 +144,17 @@ rcube_webmail.prototype.enigma_key_delete = function()
this.http_post('plugin.enigmakeys', post, lock);
};
// Export key(s)
rcube_webmail.prototype.enigma_export = function(selected)
{
var keys = selected ? this.keys_list.get_selection().join(',') : '*';
if (!keys.length)
return;
this.goto_url('plugin.enigmakeys', {_a: 'export', _keys: keys});
};
// Submit key(s) import form
rcube_webmail.prototype.enigma_import = function()
{
@ -163,11 +179,13 @@ rcube_webmail.prototype.enigma_import = function()
// list row selection handler
rcube_webmail.prototype.enigma_keylist_select = function(list)
{
var id;
if (id = list.get_single_selection())
this.enigma_loadframe('&_action=plugin.enigmakeys&_a=info&_id=' + id);
var id = list.get_single_selection(), url;
this.enable_command('plugin.enigma-key-delete', list.selection.length > 0);
if (id)
url = '&_action=plugin.enigmakeys&_a=info&_id=' + id;
this.enigma_loadframe(url);
this.enable_command('plugin.enigma-key-delete', 'plugin.enigma-key-export-selected', list.selection.length > 0);
};
rcube_webmail.prototype.enigma_keylist_keypress = function(list)
@ -275,6 +293,8 @@ rcube_webmail.prototype.enigma_clear_list = function()
this.enigma_loadframe();
if (this.keys_list)
this.keys_list.clear(true);
this.enable_command('plugin.enigma-key-delete', 'plugin.enigma-key-delete-selected', false);
}
// Adds a row to the list

@ -69,6 +69,15 @@ abstract class enigma_driver
*/
abstract function import($content, $isfile = false);
/**
* Key/Cert export.
*
* @param string Key ID
*
* @return mixed Key content or enigma_error
*/
abstract function export($key);
/**
* Keys listing.
*

@ -158,6 +158,16 @@ class enigma_driver_gnupg extends enigma_driver
}
}
public function export($keyid)
{
try {
return $this->gpg->exportPublicKey($keyid, true);
}
catch (Exception $e) {
return $this->get_error_from_exception($e);
}
}
public function list_keys($pattern='')
{
try {

@ -1002,6 +1002,37 @@ class enigma_engine
$this->rc->output->send();
}
/**
* PGP keys/certs export..
*
* @param string Key ID
* @param resource Optional output stream
*
* @return mixed Key content or enigma_error
*/
function export_key($key, $fp = null)
{
$this->load_pgp_driver();
$result = $this->pgp_driver->export($key, $fp);
if ($result instanceof enigma_error) {
rcube::raise_error(array(
'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Enigma plugin: " . $result->getMessage()
), true, false);
return $result;
}
if ($fp) {
fwrite($fp, $result);
}
else {
return $result;
}
}
/**
* Registers password for specified key/cert sent by the password prompt.
*/

@ -59,6 +59,10 @@ class enigma_ui
$this->key_import();
break;
case 'export':
$this->key_export();
break;
case 'generate':
$this->key_generate();
break;
@ -260,6 +264,7 @@ class enigma_ui
}
}
$this->rc->output->set_env('rowcount', $size);
$this->rc->output->set_env('search_request', $search);
$this->rc->output->set_env('pagecount', ceil($listsize/$pagesize));
$this->rc->output->set_env('current_page', $page);
@ -400,6 +405,35 @@ class enigma_ui
return $out;
}
/**
* Key(s) export handler
*/
private function key_export()
{
$keys = rcube_utils::get_input_value('_keys', rcube_utils::INPUT_GPC);
$engine = $this->enigma->load_engine();
$list = $keys == '*' ? $engine->list_keys() : explode(',', $keys);
if (is_array($list)) {
$filename = 'export.pgp';
if (count($list) == 1) {
$filename = (is_object($list[0]) ? $list[0]->id : $list[0]) . '.pgp';
}
// send downlaod headers
header('Content-Type: application/pgp-keys');
header('Content-Disposition: attachment; filename="' . $filename . '"');
if ($fp = fopen('php://output', 'w')) {
foreach ($list as $key) {
$engine->export_key(is_object($key) ? $key->id : $key, $fp);
}
}
}
exit;
}
/**
* Key import (page) handler
*/
@ -594,12 +628,11 @@ class enigma_ui
*/
private function key_delete()
{
$keys = rcube_utils::get_input_value('_keys', rcube_utils::INPUT_POST);
$this->enigma->load_engine();
$keys = rcube_utils::get_input_value('_keys', rcube_utils::INPUT_POST);
$engine = $this->enigma->load_engine();
foreach ((array)$keys as $key) {
$res = $this->enigma->engine->delete_key($key);
$res = $engine->delete_key($key);
if ($res !== true) {
$this->rc->output->show_message('enigma.keyremoveerror', 'error');

@ -66,6 +66,7 @@ $labels['signmsg'] = 'Digitally sign this message';
$labels['enterkeypasstitle'] = 'Enter key passphrase';
$labels['enterkeypass'] = 'A passphrase is needed to unlock the secret key ($keyid) for user: $user.';
$labels['arialabelkeyexportoptions'] = 'Keys export options';
$messages = array();
$messages['sigvalid'] = 'Verified signature from $sender.';

@ -163,7 +163,7 @@ div.enigmascreen
width: 32px;
height: 32px;
padding: 0;
margin-right: 10px;
margin: 0 5px;
overflow: hidden;
background: url(keys_toolbar.png) 0 0 no-repeat transparent;
opacity: 0.99; /* this is needed to make buttons appear correctly in Chrome */

@ -24,9 +24,10 @@
<div id="keystoolbar">
<roundcube:button command="plugin.enigma-key-create" type="link" class="buttonPas create" classAct="button create" classSel="button createSel" title="enigma.createkeys" content=" " />
<roundcube:button command="plugin.enigma-key-import" type="link" class="buttonPas import" classAct="button import" classSel="button importSel" title="enigma.importkeys" content=" " />
<!--
<span class="dropbutton">
<roundcube:button command="plugin.enigma-key-export" type="link" class="buttonPas export" classAct="button export" classSel="button exportSel" title="enigma.exportkeys" content=" " />
-->
<span id="exportmenulink" onclick="rcmail_ui.show_popup('exportmenu');return false"></span>
</span>
<roundcube:button name="messagemenulink" id="messagemenulink" type="link" class="button keymenu" title="enigma.keyactions" onclick="rcmail_ui.show_popup('messagemenu');return false" content=" " />
</div>
@ -36,6 +37,7 @@
<roundcube:button command="reset-search" id="searchreset" image="/images/icons/reset.gif" title="resetsearch" />
</div>
<div class="enigmascreen">
<div id="enigmakeyslist">
@ -78,6 +80,13 @@
</ul>
</div>
<div id="exportmenu" class="popupmenu">
<ul>
<li><roundcube:button command="plugin.enigma-key-export" label="exportall" prop="sub" classAct="exportalllink active" class="exportalllink" /></li>
<li><roundcube:button command="plugin.enigma-key-export-selected" label="exportsel" prop="sub" classAct="exportsellink active" class="exportsellink" /></li>
</ul>
</div>
<script type="text/javascript">
rcube_init_mail_ui();
</script>

@ -161,5 +161,5 @@ p.enigmaattachment a {
}
#keystoolbar a.export {
background-position: center 0;
background-position: center -40px;
}

@ -16,9 +16,18 @@
<h2 id="aria-label-toolbar" class="voice"><roundcube:label name="arialabeltoolbar" /></h2>
<div id="keystoolbar" class="toolbar" role="toolbar" aria-labelledby="aria-label-toolbar">
<roundcube:button command="plugin.enigma-key-import" type="link" class="button import disabled" classAct="button import" classSel="button import pressed" label="import" title="enigma.importkeys" />
<!--
<roundcube:button command="plugin.enigma-key-export" type="link" class="button export disabled" classAct="button export" classSel="button export pressed" label="export" title="enigma.exportkeys" />
-->
<span class="dropbutton">
<roundcube:button command="plugin.enigma-key-export" type="link" class="button export disabled" classAct="button export" classSel="button export pressed" label="export" title="enigma.exportkeys" />
<a href="#export" class="dropbuttontip" id="exportmenulink" onclick="return UI.toggle_popup('exportmenu',event)" aria-haspopup="true" aria-expanded="false" aria-owns="exportmenu-menu" tabindex="0"><roundcube:label name="enigma.arialabelkeyexportoptions" /></a>
</span>
</div>
<div id="exportmenu" class="popupmenu" aria-hidden="true">
<h3 id="aria-label-exportmenu" class="voice"><roundcube:label name="enigma.arialabelkeyexportoptions" /></h3>
<ul id="exportmenu-menu" class="toolbarmenu" role="menu" aria-labelledby="aria-label-exportmenu">
<roundcube:button type="link-menuitem" command="plugin.enigma-key-export" label="exportall" prop="sub" class="exportalllink" classAct="exportalllink active" />
<roundcube:button type="link-menuitem" command="plugin.enigma-key-export-selected" label="exportsel" prop="sub" class="exportsellink" classAct="exportsellink active" />
</ul>
</div>
<div id="quicksearchbar" class="searchbox" role="search" aria-labelledby="aria-label-searchform">

Loading…
Cancel
Save