Code

new functionality: periodical jobs
[gosa.git] / gosa-si / tests / testGOsa.pl
1 #!/usr/bin/perl 
2 #===============================================================================
3 #
4 #         FILE:  testGosa.pl
5 #
6 #        USAGE:  ./testGosa.pl 
7 #
8 #  DESCRIPTION:  
9 #
10 #      OPTIONS:  ---
11 # REQUIREMENTS:  ---
12 #         BUGS:  ---
13 #        NOTES:  ---
14 #       AUTHOR:   (), <>
15 #      COMPANY:  
16 #      VERSION:  1.0
17 #      CREATED:  06.12.2007 14:31:37 CET
18 #     REVISION:  ---
19 #===============================================================================
21 use strict;
22 use warnings;
23 use IO::Socket::INET;
24 use Digest::MD5  qw(md5 md5_hex md5_base64);
25 use Crypt::Rijndael;
26 use MIME::Base64;
28 sub create_ciphering {
29     my ($passwd) = @_;
31     $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
32     my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
33     print "iv: $iv\n";
34     print "key: $passwd\n";
36     my $my_cipher = Crypt::Rijndael->new($passwd ,Crypt::Rijndael::MODE_CBC() );
37     $my_cipher->set_iv($iv);
38     return $my_cipher;
39 }
41 sub decrypt_msg {
42     my ($crypted_msg, $my_cipher) = @_ ;
43     $crypted_msg = &decode_base64($crypted_msg);
44     my $msg = $my_cipher->decrypt($crypted_msg); 
45     return $msg;
46 }
48 sub encrypt_msg {
49     my ($msg, $my_cipher) = @_;
50     if(not defined $my_cipher) { print "no cipher object\n"; }
51     $msg = "\0"x(16-length($msg)%16).$msg;
52     my $crypted_msg = $my_cipher->encrypt($msg);
53     chomp($crypted_msg = &encode_base64($crypted_msg));
54     return $crypted_msg;
55 }
59 my $gosa_server = IO::Socket::INET->new(LocalPort => "9999",
60         Type => SOCK_STREAM,
61         Reuse => 1,
62         Listen => 1,
63         );
69 my $client = $gosa_server->accept();
70 my $other_end = getpeername($client);
71 if(not defined $other_end) {
72     print "client cannot be identified:";
73 } else {
74     my ($port, $iaddr) = unpack_sockaddr_in($other_end);
75     my $actual_ip = inet_ntoa($iaddr);
76     print "accept client at gosa socket from $actual_ip\n";
77     chomp(my $crypted_msg = <$client>);
78     print "crypted msg: <<<$crypted_msg<<<\n";
80     my $cipher = &create_ciphering("ferdinand_frost");
82     my $msg = &decrypt_msg($crypted_msg, $cipher);
83     print "msg: <<<$msg<<<\n";
85     print "\n#################################\n\n";
87     my $answer = "gosa answer: $msg";
89     print "answer: $answer\n";
90     
91     my $out_cipher = &create_ciphering("ferdinand_frost");
92     my $crypted_answer = &encrypt_msg($answer, $out_cipher);
93     
94     print $client $crypted_answer."\n";
96 }
98 sleep(3);
99 close($client);