From 34cc0a1bab176a227f83a0f91b020f95ac340563 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 6 Dec 2007 15:23:28 +0000 Subject: [PATCH] little test script for perl - php socket communication git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8049 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/daemon/gosa-sd | 5 +- contrib/daemon/modules/GosaPackages.pm | 2 +- contrib/daemon/testGosa.pl | 77 ++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 contrib/daemon/testGosa.pl diff --git a/contrib/daemon/gosa-sd b/contrib/daemon/gosa-sd index 22d7ed7d3..43f4c3a35 100755 --- a/contrib/daemon/gosa-sd +++ b/contrib/daemon/gosa-sd @@ -933,11 +933,12 @@ 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); + daemon_log("iv: $iv", 7); + daemon_log("key: $passwd", 7); my $my_cipher = Crypt::CBC->new(-key=>$passwd , -cipher => 'Rijndael', -iv => $iv, diff --git a/contrib/daemon/modules/GosaPackages.pm b/contrib/daemon/modules/GosaPackages.pm index 2435161c9..a2450cb9d 100644 --- a/contrib/daemon/modules/GosaPackages.pm +++ b/contrib/daemon/modules/GosaPackages.pm @@ -24,7 +24,6 @@ END{} # create general settings for this module my $gosa_cipher = &main::create_ciphering($main::gosa_passwd); -#$gosa_cipher->set_iv("hallo"); sub get_module_tags { @@ -62,6 +61,7 @@ sub process_incoming_msg { &main::daemon_log("GosaPackages: host_key: $host", 7); &main::daemon_log("GosaPackages: key_passwd: $main::gosa_passwd", 7); + $gosa_cipher = &main::create_ciphering($main::gosa_passwd); # determine the correct passwd for deciphering of the incoming msgs my $msg = ""; my $msg_hash; diff --git a/contrib/daemon/testGosa.pl b/contrib/daemon/testGosa.pl new file mode 100644 index 000000000..3e120b661 --- /dev/null +++ b/contrib/daemon/testGosa.pl @@ -0,0 +1,77 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: testGosa.pl +# +# USAGE: ./testGosa.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: (), <> +# COMPANY: +# VERSION: 1.0 +# CREATED: 06.12.2007 14:31:37 CET +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use IO::Socket::INET; +use Digest::MD5 qw(md5 md5_hex md5_base64); +use Crypt::CBC; + + +sub create_ciphering { + my ($passwd) = @_; + $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", + ); + return $my_cipher; +} + +sub decrypt_msg { + my ($crypted_msg, $my_cipher) = @_ ; + my $msg = $my_cipher->decrypt($crypted_msg); + return $msg; +} + + + +my $gosa_server = IO::Socket::INET->new(LocalPort => "9999", + Type => SOCK_STREAM, + Reuse => 1, + Listen => 1, + ); + + + + + +my $client = $gosa_server->accept(); +my $other_end = getpeername($client); +if(not defined $other_end) { + print "client cannot be identified:"; +} else { + my ($port, $iaddr) = unpack_sockaddr_in($other_end); + 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"; + + my $cipher = &create_ciphering("ferdinand_frost"); + + my $msg = &decrypt_msg($crypted_msg, $cipher); + print "msg: >>>$msg<<<\n"; +} -- 2.30.2