Enigma: Varius fixes and cleanup in code for attaching pubkeys

pull/5184/head
Aleksander Machniak 8 years ago
parent 4c7ce7bfc9
commit 96c3d84cdd

@ -18,6 +18,7 @@ Implemented features:
+ PGP: key generation (client- or server-side)
+ Handling of PGP keys attached to incoming messages
+ User preferences to disable plugin features
+ Attaching public keys to email
TODO:
@ -33,7 +34,6 @@ TODO:
- Generate revocation certs
- Search filter to see invalid/expired keys
- Key server(s) support (search, import, upload, refresh)
- Attaching public keys to email
- Mark keys as trusted/untrasted, display appropriate message in verify/decrypt status
- Change attachment icon on messages list for encrypted messages (like vcard_attachment plugin does)
- Support for multi-server installations (store keys in sql database?)

@ -3,7 +3,7 @@
"type": "roundcube-plugin",
"description": "PGP Encryption for Roundcube",
"license": "GPLv3+",
"version": "0.4",
"version": "0.5",
"authors": [
{
"name": "Aleksander Machniak",
@ -23,7 +23,7 @@
],
"require": {
"php": ">=5.3.0",
"roundcube/plugin-installer": ">=0.1.3",
"pear-pear.php.net/crypt_gpg": "*"
"roundcube/plugin-installer": "~0.1.6",
"pear-pear.php.net/crypt_gpg": "~1.4.0"
}
}

@ -28,7 +28,7 @@ $config['enigma_sign_all'] = false;
// Enable encrypting all messages by default
$config['enigma_encrypt_all'] = false;
// Enable signing all messages by default
// Enable attaching a public key to all messages by default
$config['enigma_attach_pubkey'] = false;
// Default for how long to store private key passwords (in minutes).

@ -352,7 +352,7 @@ class enigma extends rcube_plugin
'value' => 1,
));
$p['blocks']['main']['options']['enigma_encrypt_all'] = array(
$p['blocks']['main']['options']['enigma_attach_pubkey'] = array(
'title' => html::label($field_id, $this->gettext('attachpubkeydefault')),
'content' => $input->show($this->rc->config->get('enigma_attach_pubkey') ? 1 : 0),
);

@ -339,17 +339,6 @@ class enigma_driver_gnupg extends enigma_driver
}
}
public function pubkey_for_attach($email)
{
try {
$pubkey = $this->gpg->exportPublicKey($email, true);
return $pubkey;
}
catch (Exception $e) {
return $this->get_error_from_exception($e);
}
}
/**
* Converts Crypt_GPG exception into Enigma's error object
*

@ -312,6 +312,33 @@ class enigma_engine
}
}
/**
* Handler for attaching public key to a message
*
* @param Mail_mime Original message
*
* @return bool True on success, False on failure
*/
function attach_public_key(&$message)
{
$headers = $message->headers();
$from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true);
$from = $from[1];
// find my key
if ($from && ($key = $this->find_key($from))) {
$pubkey_armor = $this->export_key($key->id);
if (!$pubkey_armor instanceof enigma_error) {
$pubkey_name = '0x' . enigma_key::format_id($key->id) . '.asc';
$message->addAttachment($pubkey_armor, 'application/pgp-keys', $pubkey_name, false, '7bit');
return true;
}
}
return false;
}
/**
* Handler for message_part_structure hook.
* Called for every part of the message.
@ -921,38 +948,6 @@ class enigma_engine
return $result;
}
function get_gpg_pubkey_for_attach($email)
{
$this->load_pgp_driver();
$result = $this->pgp_driver->pubkey_for_attach($email);
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;
}
function get_keyID($email)
{
$this->load_pgp_driver();
$result = $this->pgp_driver->get_keyID($email);
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;
}
/**
* Find PGP private/public key
*

@ -941,7 +941,8 @@ class enigma_ui
$savedraft = !empty($_POST['_draft']) && empty($_GET['_saveonly']);
if (!$savedraft && rcube_utils::get_input_value('_enigma_attachpubkey', rcube_utils::INPUT_POST)) {
$p = $this->attach_public($p);
$this->enigma->load_engine();
$this->enigma->engine->attach_public_key($p['message']);
}
if (!$savedraft && rcube_utils::get_input_value('_enigma_sign', rcube_utils::INPUT_POST)) {
@ -980,24 +981,6 @@ class enigma_ui
return $p;
}
/**
* Add sender's public key (PGP).
*/
function attach_public($p)
{
// get sender's PGP pubkey for attachment
$this->enigma->load_engine();
$key = $this->enigma->engine->list_keys($p['message']->headers()['From']);
$keyID = $key[0]->subkeys[0]->get_short_id();
$pubkey_armor = $this->enigma->engine->get_gpg_pubkey_for_attach($p['message']->headers()['From']);
if(!$pubkey_armor instanceof enigma_error) {
$p['message']->addAttachment($pubkey_armor, 'application/pgp-keys', "0x$keyID.asc", false);
}
return $p;
}
/**
* Handler for message_compose_body hook
* Display error when the message cannot be encrypted

Loading…
Cancel
Save