Code

Added base64_encoding to encrypted transmissions.
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 30 Nov 2007 12:45:32 +0000 (12:45 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Fri, 30 Nov 2007 12:45:32 +0000 (12:45 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7955 594d385d-05f5-0310-b6e9-bd551577e9d8

contrib/socket_server/client.php
contrib/socket_server/server.php
include/class_socketClient.inc

index b1f9e2ae8a1b2830addfdd4e814db0e8118af417..c41f1d12b19c418a38a19a1fb630807cb7470802 100755 (executable)
@@ -7,7 +7,7 @@ error_reporting(E_ALL);
 
 echo "\n\nTry to connect";
 $sock = new Socket_Client("localhost","10000",TRUE,1);
-#$sock->SetEncryptionKey("Hallo hier bin ich.");
+$sock->SetEncryptionKey("Hallo hier bin ich.");
 if($sock->connected()){
        echo "... successful\n";
        echo "|--Reading welcome message : \n";
index b094930224ae6ec536bb20a6e6aab382965102ac..66663517aa9930adc259e0d83d510bcda893ad7f 100755 (executable)
@@ -13,7 +13,7 @@ $bind_port = 10000;
 $max_clients = 3;
 
 // Rijndal encrypt key 
-$enable_encryption = FALSE;
+$enable_encryption = TRUE;
 $encrypt_key = "Hallo hier bin ich.";
 
 
@@ -70,7 +70,7 @@ while(TRUE) {
                                socket_write($clients[$i]['socket'],encrypt(
 "Welcome to GOsa Test Server 
 ============================
-Type some text here:\n",$encrypt_key));
+Type some text here:",$encrypt_key)."\n");
 
                                echo("New client connected: " . $clients[$i]['ipaddy'] . " \n");
                                break;
@@ -93,7 +93,7 @@ Type some text here:\n",$encrypt_key));
                if(isset($clients[$i]) && in_array($clients[$i]['socket'],$read)) {
 
                        /* Read socket data */
-                       $data = socket_read($clients[$i]['socket'],1024000, PHP_NORMAL_READ);
+                       $data = @socket_read($clients[$i]['socket'],1024000, PHP_NORMAL_READ);
 
                        /* Client disconnected */
                        if ($data === FALSE) {
@@ -128,7 +128,7 @@ function encrypt($data,$key)
        if($enable_encryption){
                $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
                $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
-               $data = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB, $iv);
+               $data = base64_encode(mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB, $iv));
        }
        return($data);
 }
@@ -140,7 +140,7 @@ function decrypt($data,$key)
        if($enable_encryption){
                $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
                $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
-               $data = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_ECB, $iv);
+               $data = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($data), MCRYPT_MODE_ECB, $iv);
        }
        return($data);
 }
index 45d427c2e183fec9ffe4f31af53647474dac6b7e..74066e4bb3bcdcd48cd7e118539ef3cdcce58c20 100755 (executable)
@@ -44,7 +44,7 @@ class Socket_Client
        {
                /* Encrypt data */
                if($this->encrypt){
-                       $data = mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_ECB, $this->iv); 
+                       $data = base64_encode(mcrypt_encrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_ECB, $this->iv)); 
                }
                return($data);
        }
@@ -53,7 +53,7 @@ class Socket_Client
        {
                /* decrypt data */
                if($this->encrypt){
-                       $data = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, $data, MCRYPT_MODE_ECB, $this->iv);
+                       $data = mcrypt_decrypt (MCRYPT_RIJNDAEL_256, $this->crypt_key, base64_decode($data), MCRYPT_MODE_ECB, $this->iv);
                }
                return($data);
        }
@@ -114,7 +114,8 @@ class Socket_Client
                        /* Check if there is something to read for us */
                        $read = array("0"=>$this->handle);      
                        $num = @stream_select($read,$write=NULL,$accept=NULL,$this->timeout);
-                               
+                       $str = "";              
+               
                        /* Read data if necessary */
                        while($num && $this->b_data_send){
                                $str.= fread($this->handle, 1024000);