From 2afb35967f2fbee13f3dafa5fc883691a066d89e Mon Sep 17 00:00:00 2001 From: rettenbe Date: Mon, 10 Dec 2007 08:41:54 +0000 Subject: [PATCH] fixed communication between daemon, client and bus git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8063 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/daemon/gosa-sc | 59 ++++++++++++++++-------- contrib/daemon/gosa-sd | 15 +++--- contrib/daemon/gosa-sd-bus | 7 ++- contrib/daemon/modules/GosaPackages.pm | 4 +- contrib/daemon/modules/ServerPackages.pm | 6 +-- 5 files changed, 56 insertions(+), 35 deletions(-) diff --git a/contrib/daemon/gosa-sc b/contrib/daemon/gosa-sc index 3be132922..9f5113427 100755 --- a/contrib/daemon/gosa-sc +++ b/contrib/daemon/gosa-sc @@ -27,7 +27,8 @@ use Time::HiRes qw( gettimeofday ); 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; @@ -313,6 +314,7 @@ sub register_at_server { push(@events, $file_name); } my $events = join(",", @events); + daemon_log("found events: $events", 1); # fill in all possible servers my @servers; @@ -373,11 +375,12 @@ sub register_at_server { my $msg_hash; eval { my $decrypted_msg = &decrypt_msg($crypted_msg, $new_server_cipher); + daemon_log("decrypted register msg: $decrypted_msg", 5); $msg_hash = $xml->XMLin($decrypted_msg, ForceArray=>1); }; if($@) { - daemon_log("cannot register at $server", 1); - daemon_log("ERROR: do not understand the message:\n\t$crypted_msg" , 5); + daemon_log("ERROR: do not understand the incoming message:" , 5); + daemon_log("$@", 7); } else { my $header = &get_content_from_xml_hash($msg_hash, "header"); if($header eq "registered") { @@ -507,9 +510,9 @@ sub get_content_from_xml_hash { 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; } @@ -522,7 +525,9 @@ sub encrypt_msg { #=============================================================================== sub decrypt_msg { my ($crypted_msg, $my_cipher) = @_ ; + $crypted_msg = &decode_base64($crypted_msg); my $msg = $my_cipher->decrypt($crypted_msg); + $msg =~ s/\0*//g; return $msg; } @@ -535,16 +540,13 @@ sub decrypt_msg { #=============================================================================== 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; } @@ -657,15 +659,30 @@ sub open_socket { 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 } + + $socket->blocking(1); + $result = <$socket>; + + $socket->blocking(0); + while ( my $char = <$socket> ) { + if (not defined $char) { last } $result .= $char; } return $result; + + + +# 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; +# } +# return $result; } @@ -789,10 +806,12 @@ sub process_incoming_msg { daemon_log("crypted msg:", 7); daemon_log("\t$crypted_msg", 7); + my $act_cipher = &create_ciphering($server_passwd); + # try to decrypt incoming msg my ($msg, $msg_hash); eval{ - $msg = &decrypt_msg($crypted_msg, $server_cipher); + $msg = &decrypt_msg($crypted_msg, $act_cipher); $msg_hash = $xml->XMLin($msg, ForceArray=>1); }; if($@) { diff --git a/contrib/daemon/gosa-sd b/contrib/daemon/gosa-sd index ee96e6205..1b161528e 100755 --- a/contrib/daemon/gosa-sd +++ b/contrib/daemon/gosa-sd @@ -852,8 +852,8 @@ sub create_xml_string { my ($xml_hash) = @_ ; my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml'); $xml_string =~ s/[\n]+//g; - daemon_log("create_xml_string:",7); - daemon_log("$xml_string\n", 7); + #daemon_log("create_xml_string:",7); + #daemon_log("$xml_string\n", 7); return $xml_string; } @@ -923,6 +923,7 @@ sub decrypt_msg { my ($crypted_msg, $my_cipher) = @_ ; $crypted_msg = &decode_base64($crypted_msg); my $msg = $my_cipher->decrypt($crypted_msg); + $msg =~ s/\0*//g; return $msg; } @@ -938,8 +939,8 @@ sub create_ciphering { $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); + #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; @@ -1987,11 +1988,12 @@ while(1) { } $in_msg .= $part_in_msg; } + chomp($in_msg); - daemon_log("process child read: $in_msg\n", 5); + daemon_log("process child read: $in_msg", 5); if (not defined $in_msg) { next; - } elsif ($in_msg eq "done") { + } elsif ($in_msg =~ "done") { delete $busy_child{$pid}; $free_child{$pid} = $child_hash; @@ -1999,6 +2001,7 @@ while(1) { my $act_client = $busy_child{$pid}{client_ref}; print $act_client $in_msg."\n"; my $act_pipe = $busy_child{$pid}{pipe_rd}; + sleep(10); close ($act_client); delete $busy_child{$pid}; $free_child{$pid} = $child_hash; diff --git a/contrib/daemon/gosa-sd-bus b/contrib/daemon/gosa-sd-bus index 9987d47f3..7b6dbe3ef 100755 --- a/contrib/daemon/gosa-sd-bus +++ b/contrib/daemon/gosa-sd-bus @@ -585,8 +585,8 @@ sub create_ciphering { $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); + #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; @@ -621,6 +621,7 @@ sub decrypt_msg { my ($crypted_msg, $my_cipher) = @_ ; $crypted_msg = &decode_base64($crypted_msg); my $msg = $my_cipher->decrypt($crypted_msg); + $msg =~ s/^\0*//g; return $msg; } @@ -971,8 +972,6 @@ sub delete_client { my $header = &get_content_from_xml_hash($msg_hash, "header"); my $del_client = (&get_content_from_xml_hash($msg_hash, $header))[0]; - print Dumper $msg_hash; - if (not exists $known_daemons->{$source}->{$del_client}) { daemon_log } diff --git a/contrib/daemon/modules/GosaPackages.pm b/contrib/daemon/modules/GosaPackages.pm index 48a9a60d0..fbce4bf9a 100644 --- a/contrib/daemon/modules/GosaPackages.pm +++ b/contrib/daemon/modules/GosaPackages.pm @@ -64,7 +64,7 @@ sub process_incoming_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); @@ -76,7 +76,7 @@ sub process_incoming_msg { &main::daemon_log("GosaPackages: msg to process:", 5); &main::daemon_log("\t$msg", 5); - $msg = "GosaPackages got msg: ".$msg; + $msg = "gosaPackages hat was bekommen"; my $out_cipher = &main::create_ciphering($main::gosa_passwd); my $out_msg = &main::encrypt_msg($msg, $out_cipher); diff --git a/contrib/daemon/modules/ServerPackages.pm b/contrib/daemon/modules/ServerPackages.pm index 80d4c54fc..78093aa53 100644 --- a/contrib/daemon/modules/ServerPackages.pm +++ b/contrib/daemon/modules/ServerPackages.pm @@ -108,10 +108,10 @@ sub process_incoming_msg { &main::daemon_log("ServerPackage: key_passwd: $key_passwd", 7); my $key_cipher = &main::create_ciphering($key_passwd); $msg = &main::decrypt_msg($crypted_msg, $key_cipher); - &main::daemon_log("DEBUG: ServerPackages: decrypted msg: $msg", 7); + &main::daemon_log("ServerPackages: decrypted msg: $msg", 7); $msg_hash = $main::xml->XMLin($msg, ForceArray=>1); - my $tmp = printf Dumper $msg_hash; - &main::daemon_log("DEBUG: ServerPackages: xml hash: $tmp", 7); + #my $tmp = printf Dumper $msg_hash; + #&main::daemon_log("DEBUG: ServerPackages: xml hash: $tmp", 7); }; if($@) { &main::daemon_log("ServerPackage: key raise error: $@", 7); -- 2.30.2