From a2cf7c41b97a587d90188b83e4d15da1567a54b4 Mon Sep 17 00:00:00 2001
From: Thomas Bruederli <thomas@roundcube.net>
Date: Wed, 09 Apr 2014 02:48:28 -0400
Subject: [PATCH] Fix accidental key replacements

---
 plugins/enigma/lib/enigma_engine.php |  107 ++++++++++++++++++++++++++++-------------------------
 1 files changed, 57 insertions(+), 50 deletions(-)

diff --git a/plugins/enigma/lib/enigma_engine.php b/plugins/enigma/lib/enigma_engine.php
index 89cb4b7..e4972c6 100644
--- a/plugins/enigma/lib/enigma_engine.php
+++ b/plugins/enigma/lib/enigma_engine.php
@@ -65,7 +65,7 @@
         $this->pgp_driver = new $driver($username);
 
         if (!$this->pgp_driver) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: Unable to load PGP driver: $driver"
@@ -76,7 +76,7 @@
         $result = $this->pgp_driver->init();
 
         if ($result instanceof enigma_error) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: ".$result->getMessage()
@@ -92,9 +92,6 @@
         if ($this->smime_driver)
             return;
 
-        // NOT IMPLEMENTED!
-        return;
-
         $driver = 'enigma_driver_' . $this->rc->config->get('enigma_smime_driver', 'phpssl');
         $username = $this->rc->user->get_username();
 
@@ -102,7 +99,7 @@
         $this->smime_driver = new $driver($username);
 
         if (!$this->smime_driver) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: Unable to load S/MIME driver: $driver"
@@ -113,7 +110,7 @@
         $result = $this->smime_driver->init();
 
         if ($result instanceof enigma_error) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: ".$result->getMessage()
@@ -246,7 +243,7 @@
 
         fclose($fh);
     }
-    
+
     /**
      * Handler for PGP/MIME signed message.
      * Verifies signature.
@@ -255,14 +252,14 @@
      */
     private function parse_pgp_signed(&$p)
     {
-        $this->load_pgp_driver();
-        $struct = $p['structure'];
-        
         // Verify signature
         if ($this->rc->action == 'show' || $this->rc->action == 'preview') {
+            $this->load_pgp_driver();
+            $struct = $p['structure'];
+
             $msg_part = $struct->parts[0];
             $sig_part = $struct->parts[1];
-        
+
             // Get bodies
             $this->set_part_body($msg_part, $p['object']->uid);
             $this->set_part_body($sig_part, $p['object']->uid);
@@ -294,7 +291,31 @@
      */
     private function parse_smime_signed(&$p)
     {
-        $this->load_smime_driver();
+        // Verify signature
+        if ($this->rc->action == 'show' || $this->rc->action == 'preview') {
+            $this->load_smime_driver();
+
+            $struct   = $p['structure'];
+            $msg_part = $struct->parts[0];
+
+            // Verify
+            $sig = $this->smime_driver->verify($struct, $p['object']);
+
+            // Store signature data for display
+            $this->signatures[$struct->mime_id] = $sig;
+
+            // Message can be multipart (assign signature to each subpart)
+            if (!empty($msg_part->parts)) {
+                foreach ($msg_part->parts as $part)
+                    $this->signed_parts[$part->mime_id] = $struct->mime_id;
+            }
+            else {
+                $this->signed_parts[$msg_part->mime_id] = $struct->mime_id;
+            }
+
+            // Remove signature file from attachments list
+            unset($struct->parts[1]);
+        }
     }
 
     /**
@@ -306,22 +327,22 @@
     {
         $this->load_pgp_driver();
         $part = $p['structure'];
-        
+
         // Get body
         $this->set_part_body($part, $p['object']->uid);
 
-        // Decrypt 
+        // Decrypt
         $result = $this->pgp_decrypt($part->body);
-        
+
         // Store decryption status
         $this->decryptions[$part->mime_id] = $result;
-        
+
         // Parse decrypted message
         if ($result === true) {
             // @TODO
         }
     }
-    
+
     /**
      * Handler for PGP/MIME encrypted message.
      *
@@ -359,7 +380,7 @@
      */
     private function parse_smime_encrypted(&$p)
     {
-        $this->load_smime_driver();
+//        $this->load_smime_driver();
     }
 
     /**
@@ -374,17 +395,15 @@
     {
         // @TODO: Handle big bodies using (temp) files
         // @TODO: caching of verification result
-        
-         $sig = $this->pgp_driver->verify($msg_body, $sig_body);
+        $sig = $this->pgp_driver->verify($msg_body, $sig_body);
 
-         if (($sig instanceof enigma_error) && $sig->getCode() != enigma_error::E_KEYNOTFOUND)
-             raise_error(array(
+        if (($sig instanceof enigma_error) && $sig->getCode() != enigma_error::E_KEYNOTFOUND)
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
-                'message' => "Enigma plugin: " . $error->getMessage()
+                'message' => "Enigma plugin: " . $sig->getMessage()
                 ), true, false);
 
-//print_r($sig);
         return $sig;
     }
 
@@ -399,15 +418,13 @@
     {
         // @TODO: Handle big bodies using (temp) files
         // @TODO: caching of verification result
-        
+        $key = ''; $pass = ''; // @TODO
         $result = $this->pgp_driver->decrypt($msg_body, $key, $pass);
-
-//print_r($result);
 
         if ($result instanceof enigma_error) {
             $err_code = $result->getCode();
             if (!in_array($err_code, array(enigma_error::E_KEYNOTFOUND, enigma_error::E_BADPASS)))
-                raise_error(array(
+                rcube::raise_error(array(
                     'code' => 600, 'type' => 'php',
                     'file' => __FILE__, 'line' => __LINE__,
                     'message' => "Enigma plugin: " . $result->getMessage()
@@ -430,15 +447,15 @@
     {
         $this->load_pgp_driver();
         $result = $this->pgp_driver->list_keys($pattern);
-    
+
         if ($result instanceof enigma_error) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: " . $result->getMessage()
                 ), true, false);
         }
-        
+
         return $result;
     }
 
@@ -455,7 +472,7 @@
         $result = $this->pgp_driver->get_key($keyid);
     
         if ($result instanceof enigma_error) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: " . $result->getMessage()
@@ -479,7 +496,7 @@
         $result = $this->pgp_driver->import($content, $isfile);
 
         if ($result instanceof enigma_error) {
-            raise_error(array(
+            rcube::raise_error(array(
                 'code' => 600, 'type' => 'php',
                 'file' => __FILE__, 'line' => __LINE__,
                 'message' => "Enigma plugin: " . $result->getMessage()
@@ -498,12 +515,14 @@
      */
     function import_file()
     {
-        $uid = get_input_value('_uid', RCUBE_INPUT_POST);
-        $mbox = get_input_value('_mbox', RCUBE_INPUT_POST);
-        $mime_id = get_input_value('_part', RCUBE_INPUT_POST);
+        $uid     = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST);
+        $mbox    = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST);
+        $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST);
+        $storage = $this->rc->get_storage();
 
         if ($uid && $mime_id) {
-            $part = $this->rc->storage->get_message_part($uid, $mime_id);
+            $storage->set_folder($mbox);
+            $part = $storage->get_message_part($uid, $mime_id);
         }
 
         if ($part && is_array($result = $this->import_key($part))) {
@@ -531,17 +550,5 @@
             $part->body = $this->rc->storage->get_message_part(
                 $uid, $part->mime_id, $part);
         }
-    }
-
-    /**
-     * Adds CSS style file to the page header.
-     */
-    private function add_css()
-    {
-        $skin = $this->rc->config->get('skin');
-        if (!file_exists($this->home . "/skins/$skin/enigma.css"))
-            $skin = 'default';
-
-        $this->include_stylesheet("skins/$skin/enigma.css");                                                
     }
 }

--
Gitblit v1.9.1