From a99c34159d03f2b5b525d6d8cc38509c4ac2f0a1 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Tue, 31 Mar 2015 12:56:32 -0400
Subject: [PATCH] Enigma: Implemented messages signing and encrypting

---
 plugins/enigma/lib/enigma_driver_gnupg.php |   62 +++++++++++++++++--------------
 1 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/plugins/enigma/lib/enigma_driver_gnupg.php b/plugins/enigma/lib/enigma_driver_gnupg.php
index 09e23d3..52a0ad6 100644
--- a/plugins/enigma/lib/enigma_driver_gnupg.php
+++ b/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)

--
Gitblit v1.9.1