Enigma: Varius fixes and cleanup in code for attaching pubkeys
| | |
| | | + 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: |
| | |
| | | - 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?) |
| | |
| | | "type": "roundcube-plugin", |
| | | "description": "PGP Encryption for Roundcube", |
| | | "license": "GPLv3+", |
| | | "version": "0.4", |
| | | "version": "0.5", |
| | | "authors": [ |
| | | { |
| | | "name": "Aleksander Machniak", |
| | |
| | | ], |
| | | "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" |
| | | } |
| | | } |
| | |
| | | // 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). |
| | |
| | | '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), |
| | | ); |
| | |
| | | } |
| | | } |
| | | |
| | | 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 |
| | | * |
| | |
| | | } |
| | | |
| | | /** |
| | | * 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. |
| | | * |
| | |
| | | { |
| | | $this->load_pgp_driver(); |
| | | $result = $this->pgp_driver->list_keys($pattern); |
| | | |
| | | 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_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( |
| | |
| | | $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)) { |
| | |
| | | } |
| | | |
| | | $this->rc->output->send('iframe'); |
| | | } |
| | | |
| | | 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; |