summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4ffe9a5)
raw | patch | inline | side by side (parent: 4ffe9a5)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 7 Dec 2007 11:00:13 +0000 (11:00 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 7 Dec 2007 11:00:13 +0000 (11:00 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8057 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/contrib/daemon/gosa-sd b/contrib/daemon/gosa-sd
index 43f4c3a35bca498df9fa53249366dac46e4363ab..ee96e6205c06643ab1c10e0ecdc5ea1d412f73da 100755 (executable)
--- a/contrib/daemon/gosa-sd
+++ b/contrib/daemon/gosa-sd
use Fcntl;
use IO::Socket::INET;
-use Crypt::CBC;
+use Crypt::Rijndael;
+use MIME::Base64;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use XML::Simple;
use Data::Dumper;
sub create_xml_string {
my ($xml_hash) = @_ ;
my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml');
- #$xml_string =~ s/[\n]+//g;
+ $xml_string =~ s/[\n]+//g;
daemon_log("create_xml_string:",7);
daemon_log("$xml_string\n", 7);
return $xml_string;
sub encrypt_msg {
my ($msg, $my_cipher) = @_;
if(not defined $my_cipher) { print "no cipher object\n"; }
-
+ $msg = "\0"x(16-length($msg)%16).$msg;
my $crypted_msg = $my_cipher->encrypt($msg);
-
+ chomp($crypted_msg = &encode_base64($crypted_msg));
return $crypted_msg;
}
#===============================================================================
sub decrypt_msg {
my ($crypted_msg, $my_cipher) = @_ ;
+ $crypted_msg = &decode_base64($crypted_msg);
my $msg = $my_cipher->decrypt($crypted_msg);
return $msg;
}
sub create_ciphering {
my ($passwd) = @_;
$passwd = substr(md5_hex("$passwd") x 32, 0, 32);
-
my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
daemon_log("iv: $iv", 7);
daemon_log("key: $passwd", 7);
- my $my_cipher = Crypt::CBC->new(-key=>$passwd ,
- -cipher => 'Rijndael',
- -iv => $iv,
- -header => "none",
- );
+ my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC());
+ $my_cipher->set_iv($iv);
return $my_cipher;
}
if (vec($rout, fileno $fhd, 1) ) {
daemon_log("process child $pid is ready to read", 5);
- chomp( my $in_msg = <$fhd> );
+
+ $fhd->blocking(1);
+ my $in_msg = <$fhd>;
+ $fhd->blocking(0);
+ my $part_in_msg;
+ while ($part_in_msg = <$fhd>) {
+ if (not defined $part_in_msg) {
+ last;
+ }
+ $in_msg .= $part_in_msg;
+ }
+
daemon_log("process child read: $in_msg\n", 5);
if (not defined $in_msg) {
next;
index b1e118f0e258fe82824f761c1cc33bf5d6ff5fca..9987d47f30681a08076658c71278309ba31b3975 100755 (executable)
use Time::HiRes qw( gettimeofday );
use IO::Socket::INET;
-use Crypt::CBC;
+use Crypt::Rijndael;
+use MIME::Base64;
use Digest::MD5 qw(md5 md5_hex md5_base64);
use XML::Simple;
use Data::Dumper;
daemon_log("daemon_passwd: $key_passwd\n", 7);
my $key_cipher = &create_ciphering($key_passwd);
$msg = &decrypt_msg($crypted_msg, $key_cipher);
- daemon_log("daemon decrypted msg: $msg", 7);
+ daemon_log("daemon decrypted msg:$msg", 7);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
+ print Dumper $msg_hash;
};
if($@) {
daemon_log("msg processing raise error", 7);
}
if($msg_flag >= $l) {
- daemon_log("\nERROR: do not understand the message:\n\t$msg" , 1);
+ daemon_log("\nERROR: do not understand the message:\n$msg" , 1);
return;
}
#===============================================================================
sub create_ciphering {
my ($passwd) = @_;
- $passwd = substr("$passwd" x 32, 0, 32);
- daemon_log("create_ciphering: new passwd: $passwd", 7);
-
+ $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
- my $my_cipher = Crypt::CBC->new(-key=>$passwd ,
- -cipher => 'Rijndael',
- -iv => $iv,
- -header => "none",
- );
+ daemon_log("iv: $iv", 7);
+ daemon_log("key: $passwd", 7);
+ my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC());
+ $my_cipher->set_iv($iv);
return $my_cipher;
}
sub encrypt_msg {
my ($msg, $my_cipher) = @_;
if(not defined $my_cipher) { print "no cipher object\n"; }
-
+ $msg = "\0"x(16-length($msg)%16).$msg;
my $crypted_msg = $my_cipher->encrypt($msg);
-
+ chomp($crypted_msg = &encode_base64($crypted_msg));
return $crypted_msg;
}
#===============================================================================
sub decrypt_msg {
my ($crypted_msg, $my_cipher) = @_ ;
+ $crypted_msg = &decode_base64($crypted_msg);
my $msg = $my_cipher->decrypt($crypted_msg);
return $msg;
}
#===============================================================================
sub read_from_socket {
my ($socket) = @_;
- my $result = "";
- my $len = 16;
- while($len == 16){
- my $char;
- $len = sysread($socket, $char, 16);
- if($len != 16) { last }
- if($len != 16) { last }
- $result .= $char;
+
+ $socket->blocking(1);
+ my $result = <$socket>;
+ $socket->blocking(0);
+ my $part_msg;
+ while ($part_msg = <$socket>) {
+ if (not defined $part_msg) { last; }
+ $result .= $part_msg;
}
+
+ #my $result = "";
+ #my $len = 16;
+ #while($len == 16){
+ # my $char;
+ # $len = sysread($socket, $char, 16);
+ # if($len != 16) { last }
+ # if($len != 16) { last }
+ # $result .= $char;
+ #}
return $result;
}
index a2450cb9d5b9ef62cf101b6db3a5fddf99e7bd60..48a9a60d07597cce7aae2c9827f14c199de4d267 100644 (file)
return \%tag_hash;
}
-#sub read_configfile {
-# &main::read_configfile();
-# return;
-#}
-
sub process_incoming_msg {
my ($crypted_msg) = @_ ;
$msg = &main::decrypt_msg($crypted_msg, $gosa_cipher);
&main::daemon_log("GosaPackages: decrypted_msg: $msg", 7);
- $msg_hash = $main::xml->XMLin($msg, ForceArray=>1);
+ #$msg_hash = $main::xml->XMLin($msg, ForceArray=>1);
};
if($@) {
&main::daemon_log("ERROR: GosaPackages do not understand the message: $@", 1);
&main::daemon_log("\t$host", 1);
&main::daemon_log("GosaPackages: msg to process:", 5);
&main::daemon_log("\t$msg", 5);
-
-
-
-
- return "GosaPackages got msg: $msg";
+
+ $msg = "GosaPackages got msg: ".$msg;
+
+ my $out_cipher = &main::create_ciphering($main::gosa_passwd);
+ my $out_msg = &main::encrypt_msg($msg, $out_cipher);
+ return $out_msg;
}
index 3e120b66147a05333b280f0260bc271ce3870b22..9ecb8f385ddd8099c0f844ce033af45da369a269 100644 (file)
use warnings;
use IO::Socket::INET;
use Digest::MD5 qw(md5 md5_hex md5_base64);
-use Crypt::CBC;
-
+use Crypt::Rijndael;
+use MIME::Base64;
sub create_ciphering {
my ($passwd) = @_;
- $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
+ $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
-
print "iv: $iv\n";
print "key: $passwd\n";
- my $my_cipher = Crypt::CBC->new(-key=>$passwd ,
- -cipher => 'Rijndael',
- -iv => $iv,
- -header => "none",
- );
+
+ my $my_cipher = Crypt::Rijndael->new($passwd ,Crypt::Rijndael::MODE_CBC() );
+ $my_cipher->set_iv($iv);
return $my_cipher;
}
sub decrypt_msg {
my ($crypted_msg, $my_cipher) = @_ ;
+ $crypted_msg = &decode_base64($crypted_msg);
my $msg = $my_cipher->decrypt($crypted_msg);
return $msg;
}
+sub encrypt_msg {
+ my ($msg, $my_cipher) = @_;
+ if(not defined $my_cipher) { print "no cipher object\n"; }
+ $msg = "\0"x(16-length($msg)%16).$msg;
+ my $crypted_msg = $my_cipher->encrypt($msg);
+ chomp($crypted_msg = &encode_base64($crypted_msg));
+ return $crypted_msg;
+}
+
my $gosa_server = IO::Socket::INET->new(LocalPort => "9999",
my $actual_ip = inet_ntoa($iaddr);
print "accept client at gosa socket from $actual_ip\n";
chomp(my $crypted_msg = <$client>);
- print "crypted msg: >>>$crypted_msg<<<\n";
+ print "crypted msg: <<<$crypted_msg<<<\n";
my $cipher = &create_ciphering("ferdinand_frost");
my $msg = &decrypt_msg($crypted_msg, $cipher);
- print "msg: >>>$msg<<<\n";
+ print "msg: <<<$msg<<<\n";
+
+ print "\n#################################\n\n";
+
+ my $answer = "gosa answer: $msg";
+
+ print "answer: $answer\n";
+
+ my $out_cipher = &create_ciphering("ferdinand_frost");
+ my $crypted_answer = &encrypt_msg($answer, $out_cipher);
+
+ print $client $crypted_answer."\n";
+
}
+
+sleep(3);
+close($client);
+
+
+
+
+
+
+
+
index d3a1b396b68ebc0c2fbc18a69915b604f6cb0463..8d88d88f459e24ddc96dfea6c52d5ae2829f6c05 100755 (executable)
require_once("../../include/class_socketClient.inc");
error_reporting(E_ALL);
-$sock = new Socket_Client("10.89.1.182","10000",TRUE,1);
+$sock = new Socket_Client("10.89.1.155","9999",TRUE,1);
$sock->setEncryptionKey("ferdinand_frost");
if($sock->connected()){
/* Prepare a hunge bunch of data to be send */
- $data = "Hallo Andi. Alles wird toll.";
+ $data = "Hallo Andi. Alles Wird Toll.";
$sock->write($data);
- echo $sock->read();
+
+ #$sock->setEncryptionKey("ferdinand_frost");
+
+ $answer = $sock->read();
+ echo "$answer\n";
$sock->close();
}else{
echo "... FAILED!\n";
index d31e6764f50b6c8cfb73b2e9021dab32c1c15831..ae72d105115a6fdc8a85a15d5db2256e08ea9559 100755 (executable)
private function encrypt($data)
{
mcrypt_generic_init($this->td, $this->ckey, $this->iv);
- return mcrypt_generic($this->td, $data);
+ return base64_encode(mcrypt_generic($this->td, $data));
}
private function decrypt($data)
{
/* decrypt data */
+ $data = base64_decode($data);
mcrypt_generic_init($this->td, $this->ckey, $this->iv);
return mdecrypt_generic($this->td, $data);
}