1# -*- perl -*-
2#
3
4require 5.004;
5use strict;
6
7eval { require Crypt::DES };
8if ($@ || $Crypt::DES::VERSION < 2.03) {
9    print "1..0\n";
10    exit 0;
11}
12
13require "t/lib.pl";
14
15
16my $numTests = 18;
17my $numTest = 0;
18
19my $hostkey = 'b3a6d83ef3187ac4';
20my $userkey = '9823adc3287efa98';
21
22
23# Create a configfile with host encryption.
24my $cfg = <<"EOF";
25
26require Crypt::DES;
27{
28    clients => [ {
29	'mask'   => '^127\.0\.0\.1\$',
30	'accept' => 1,
31	'cipher' => Crypt::DES->new(pack("H*", "$hostkey")),
32	'users' => [ {
33	    'name' => 'bob'
34	    },
35	    {
36	    'name' => 'jim',
37	    'cipher' => Crypt::DES->new(pack("H*", "$userkey"))
38	    } ] }
39    ]
40}
41EOF
42if (!open(FILE, ">t/crypt.cfg")  ||  !(print FILE ($cfg))  || !close(FILE)) {
43    die "Error while creating config file t/crypt.cfg: $!";
44}
45
46
47my($handle, $port);
48($handle, $port) = Net::Daemon::Test->Child($numTests,
49					    $^X, '-Iblib/lib',
50					    '-Iblib/arch',
51					    't/server', '--mode=single',
52					    '--debug', '--timeout', 60,
53					    '--configfile', 't/crypt.cfg');
54
55
56require Crypt::DES;
57my $hostcipher = Crypt::DES->new(pack("H*", $hostkey));
58my $usercipher = Crypt::DES->new(pack("H*", $userkey));
59
60my @opts = ('peeraddr' => '127.0.0.1', 'peerport' => $port, 'debug' => 1,
61	    'application' => 'CalcServer', 'version' => 0.01,
62	    'timeout' => 20, 'usercipher' => $hostcipher);
63
64
65RunTests('user' => 'bob', @opts);
66
67RunTests('usercipher' => $usercipher, 'user' => 'jim', @opts);
68$handle->Terminate() if $handle;
69
70
71
72
73
74
75
76
77
78