Aleksander Machniak
2016-04-02 96c3d84cddb861956cfbc719d694eb972343f1c3
Enigma: Varius fixes and cleanup in code for attaching pubkeys
7 files modified
103 ■■■■■ changed files
plugins/enigma/README 2 ●●● patch | view | raw | blame | history
plugins/enigma/composer.json 6 ●●●● patch | view | raw | blame | history
plugins/enigma/config.inc.php.dist 2 ●●● patch | view | raw | blame | history
plugins/enigma/enigma.php 2 ●●● patch | view | raw | blame | history
plugins/enigma/lib/enigma_driver_gnupg.php 11 ●●●●● patch | view | raw | blame | history
plugins/enigma/lib/enigma_engine.php 59 ●●●● patch | view | raw | blame | history
plugins/enigma/lib/enigma_ui.php 21 ●●●●● patch | view | raw | blame | history
plugins/enigma/README
@@ -18,6 +18,7 @@
+ 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 @@
- 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?)
plugins/enigma/composer.json
@@ -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"
    }
}
plugins/enigma/config.inc.php.dist
@@ -28,7 +28,7 @@
// 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).
plugins/enigma/enigma.php
@@ -352,7 +352,7 @@
                    '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),
            );
plugins/enigma/lib/enigma_driver_gnupg.php
@@ -339,17 +339,6 @@
        }
    }
    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
     *
plugins/enigma/lib/enigma_engine.php
@@ -313,6 +313,33 @@
    }
    /**
     * 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.
     *
@@ -909,38 +936,6 @@
    {
        $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(
plugins/enigma/lib/enigma_ui.php
@@ -941,7 +941,8 @@
        $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)) {
@@ -975,24 +976,6 @@
            }
            $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;