Aleksander Machniak
2015-03-31 a99c34159d03f2b5b525d6d8cc38509c4ac2f0a1
plugins/enigma/lib/enigma_driver_gnupg.php
@@ -3,18 +3,11 @@
 +-------------------------------------------------------------------------+
 | GnuPG (PGP) driver for the Enigma Plugin                                |
 |                                                                         |
 | This program is free software; you can redistribute it and/or modify    |
 | it under the terms of the GNU General Public License version 2          |
 | as published by the Free Software Foundation.                           |
 | Copyright (C) 2010-2015 The Roundcube Dev Team                          |
 |                                                                         |
 | This program is distributed in the hope that it will be useful,         |
 | but WITHOUT ANY WARRANTY; without even the implied warranty of          |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
 | GNU General Public License for more details.                            |
 |                                                                         |
 | You should have received a copy of the GNU General Public License along |
 | with this program; if not, write to the Free Software Foundation, Inc., |
 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.             |
 | Licensed under the GNU General Public License version 3 or              |
 | any later version with exceptions for skins & plugins.                  |
 | See the README file for a full license statement.                       |
 |                                                                         |
 +-------------------------------------------------------------------------+
 | Author: Aleksander Machniak <alec@alec.pl>                              |
@@ -29,6 +22,7 @@
    private $gpg;
    private $homedir;
    private $user;
    function __construct($user)
    {
@@ -86,30 +80,40 @@
        }
    }
    /**
     * Encrypt a message
     *
     * @param string The message
     * @param array  List of keys
     */
    function encrypt($text, $keys)
    {
/*
        foreach ($keys as $key) {
            $this->gpg->addEncryptKey($key);
        try {
            foreach ($keys as $key) {
                $this->gpg->addEncryptKey($key);
            }
            $dec = $this->gpg->encrypt($text, true);
            return $dec;
        }
        $enc = $this->gpg->encrypt($text);
        return $enc;
*/
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
    /**
     * Register private keys and passwords
     * Decrypt a message
     *
     * @param string Encrypted message
     * @param array  List of key-password mapping
     */
    function decrypt($text, $keys = array())
    {
        foreach ($keys as $key => $password) {
            $this->gpg->addDecryptKey($key, $password);
        }
        try {
            foreach ($keys as $key => $password) {
                $this->gpg->addDecryptKey($key, $password);
            }
            $dec = $this->gpg->decrypt($text);
            return $dec;
        }
@@ -118,13 +122,15 @@
        }
    }
    function sign($text, $key, $passwd)
    function sign($text, $key, $passwd, $mode = null)
    {
/*
        $this->gpg->addSignKey($key, $passwd);
        $signed = $this->gpg->sign($text, Crypt_GPG::SIGN_MODE_DETACHED);
        return $signed;
*/
        try {
            $this->gpg->addSignKey($key, $passwd);
            return $this->gpg->sign($text, $mode, CRYPT_GPG::ARMOR_ASCII, true);
        }
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
    function verify($text, $signature)