Code

little test script for perl - php socket communication
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 6 Dec 2007 15:23:28 +0000 (15:23 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Thu, 6 Dec 2007 15:23:28 +0000 (15:23 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8049 594d385d-05f5-0310-b6e9-bd551577e9d8

contrib/daemon/gosa-sd
contrib/daemon/modules/GosaPackages.pm
contrib/daemon/testGosa.pl [new file with mode: 0644]

index 22d7ed7d31d018bab4455bfe676699ec49193f54..43f4c3a35bca498df9fa53249366dac46e4363ab 100755 (executable)
@@ -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,
index 2435161c9b1891123a782cef45e0da36e75b60f9..a2450cb9d5b9ef62cf101b6db3a5fddf99e7bd60 100644 (file)
@@ -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 (file)
index 0000000..3e120b6
--- /dev/null
@@ -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";
+}