From 6221c8a2441e265cff8d3eae872ea2a896550eed Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 30 Nov 2007 12:45:32 +0000 Subject: [PATCH] Added base64_encoding to encrypted transmissions. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@7955 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/socket_server/client.php | 2 +- contrib/socket_server/server.php | 10 +++++----- include/class_socketClient.inc | 7 ++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/contrib/socket_server/client.php b/contrib/socket_server/client.php index b1f9e2ae8..c41f1d12b 100755 --- a/contrib/socket_server/client.php +++ b/contrib/socket_server/client.php @@ -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"; diff --git a/contrib/socket_server/server.php b/contrib/socket_server/server.php index b09493022..66663517a 100755 --- a/contrib/socket_server/server.php +++ b/contrib/socket_server/server.php @@ -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); } diff --git a/include/class_socketClient.inc b/include/class_socketClient.inc index 45d427c2e..74066e4bb 100755 --- a/include/class_socketClient.inc +++ b/include/class_socketClient.inc @@ -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); -- 2.30.2