Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_sftp/FIPS.pm

raw
1 package ProFTPD::Tests::Modules::mod_sftp::FIPS;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use File::Copy;
8 use File::Spec;
9 use IO::Handle;
10 use POSIX qw(:fcntl_h);
11
12 use ProFTPD::TestSuite::FTP;
13 use ProFTPD::TestSuite::Utils qw(:auth :config :running :test :testsuite);
14
15 $| = 1;
16
17 my $order = 0;
18
19 my $TESTS = {
20 sftp_fips_cipher_cast128_cbc => {
21 order => ++$order,
22 test_class => [qw(forking)],
23 },
24
25 sftp_fips_cipher_blowfish_cbc => {
26 order => ++$order,
27 test_class => [qw(forking)],
28 },
29
30 sftp_fips_cipher_3des_cbc => {
31 order => ++$order,
32 test_class => [qw(forking)],
33 },
34
35 sftp_fips_cipher_aes128_cbc => {
36 order => ++$order,
37 test_class => [qw(forking)],
38 },
39
40 sftp_fips_cipher_aes128_cbc_auth_publickey_rsa => {
41 order => ++$order,
42 test_class => [qw(forking)],
43 },
44
45 sftp_fips_cipher_aes128_cbc_auth_publickey_dsa => {
46 order => ++$order,
47 test_class => [qw(forking)],
48 },
49
50 sftp_fips_cipher_aes128_ctr => {
51 order => ++$order,
52 test_class => [qw(forking)],
53 },
54
55 sftp_fips_mac_hmac_md5 => {
56 order => ++$order,
57 test_class => [qw(forking)],
58 },
59
60 sftp_fips_mac_hmac_md5_96 => {
61 order => ++$order,
62 test_class => [qw(forking)],
63 },
64
65 sftp_fips_mac_ripemd160 => {
66 order => ++$order,
67 test_class => [qw(forking)],
68 },
69
70 sftp_fips_mac_hmac_sha1 => {
71 order => ++$order,
72 test_class => [qw(forking)],
73 },
74
75 };
76
77 sub new {
78 return shift()->SUPER::new(@_);
79 }
80
81 sub list_tests {
82
83 # Check for the required Perl modules:
84 #
85 # Net-SSH2
86 # Net-SSH2-SFTP
87
88 my $required = [qw(
89 Net::SSH2
90 Net::SSH2::SFTP
91 )];
92
93 foreach my $req (@$required) {
94 eval "use $req";
95 if ($@) {
96 print STDERR "\nWARNING:\n + Module '$req' not found, skipping all tests\n";
97
98 if ($ENV{TEST_VERBOSE}) {
99 print STDERR "Unable to load $req: $@\n";
100 }
101
102 return qw(testsuite_empty_test);
103 }
104 }
105
106 return testsuite_get_runnable_tests($TESTS);
107 }
108
109 sub set_up {
110 my $self = shift;
111 $self->SUPER::set_up(@_);
112
113 # Make sure that mod_sftp does not complain about permissions on the hostkey
114 # files.
115
116 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
117 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
118
119 unless (chmod(0400, $rsa_host_key, $dsa_host_key)) {
120 die("Can't set perms on $rsa_host_key, $dsa_host_key: $!");
121 }
122 }
123
124 sub sftp_fips_cipher_cast128_cbc {
125 my $self = shift;
126 my $tmpdir = $self->{tmpdir};
127
128 my $config_file = "$tmpdir/fips.conf";
129 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
130 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
131
132 my $log_file = test_get_logfile();
133
134 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
135 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
136
137 my $user = 'proftpd';
138 my $passwd = 'test';
139 my $group = 'ftpd';
140 my $home_dir = File::Spec->rel2abs($tmpdir);
141 my $uid = 500;
142 my $gid = 500;
143
144 # Make sure that, if we're running as root, that the home directory has
145 # permissions/privs set for the account we create
146 if ($< == 0) {
147 unless (chmod(0755, $home_dir)) {
148 die("Can't set perms on $home_dir to 0755: $!");
149 }
150
151 unless (chown($uid, $gid, $home_dir)) {
152 die("Can't set owner of $home_dir to $uid/$gid: $!");
153 }
154 }
155
156 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
157 '/bin/bash');
158 auth_group_write($auth_group_file, $group, $gid, $user);
159
160 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
161 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
162
163 my $config = {
164 PidFile => $pid_file,
165 ScoreboardFile => $scoreboard_file,
166 SystemLog => $log_file,
167 TraceLog => $log_file,
168 Trace => 'ssh2:20 sftp:20',
169
170 AuthUserFile => $auth_user_file,
171 AuthGroupFile => $auth_group_file,
172 AuthOrder => 'mod_auth_file.c',
173
174 IfModules => {
175 'mod_delay.c' => {
176 DelayEngine => 'off',
177 },
178
179 'mod_sftp.c' => [
180 "SFTPEngine on",
181 "SFTPLog $log_file",
182 "SFTPHostKey $rsa_host_key",
183 "SFTPHostKey $dsa_host_key",
184 ],
185 },
186 };
187
188 my ($port, $config_user, $config_group) = config_write($config_file, $config);
189
190 # Open pipes, for use between the parent and child processes. Specifically,
191 # the child will indicate when it's done with its test by writing a message
192 # to the parent.
193 my ($rfh, $wfh);
194 unless (pipe($rfh, $wfh)) {
195 die("Can't open pipe: $!");
196 }
197
198 require Net::SSH2;
199
200 my $ex;
201
202 # Fork child
203 $self->handle_sigchld();
204 defined(my $pid = fork()) or die("Can't fork: $!");
205 if ($pid) {
206 eval {
207 my $ssh2 = Net::SSH2->new();
208
209 # Allow for longer startup time, due to the FIPS self-tests
210 sleep(2);
211
212 my $cipher = 'cast128-cbc';
213 $ssh2->method('crypt_cs', $cipher);
214 $ssh2->method('crypt_sc', $cipher);
215
216 if ($ssh2->connect('127.0.0.1', $port)) {
217 die("Connected to SSH2 server unexpectedly");
218 }
219
220 my ($err_code, $err_name, $err_str) = $ssh2->error();
221
222 my $expected = 'LIBSSH2_ERROR_KEX_FAILURE';
223 $self->assert($expected eq $err_name,
224 test_msg("Expected error name '$expected', got '$err_name'"));
225
226 $ssh2->disconnect();
227 };
228
229 if ($@) {
230 $ex = $@;
231 }
232
233 $wfh->print("done\n");
234 $wfh->flush();
235
236 } else {
237 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
238 if ($@) {
239 warn($@);
240 exit 1;
241 }
242
243 exit 0;
244 }
245
246 # Stop server
247 server_stop($pid_file);
248
249 $self->assert_child_ok($pid);
250
251 if ($ex) {
252 test_append_logfile($log_file, $ex);
253 unlink($log_file);
254
255 die($ex);
256 }
257
258 unlink($log_file);
259 }
260
261 sub sftp_fips_cipher_blowfish_cbc {
262 my $self = shift;
263 my $tmpdir = $self->{tmpdir};
264
265 my $config_file = "$tmpdir/fips.conf";
266 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
267 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
268
269 my $log_file = test_get_logfile();
270
271 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
272 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
273
274 my $user = 'proftpd';
275 my $passwd = 'test';
276 my $group = 'ftpd';
277 my $home_dir = File::Spec->rel2abs($tmpdir);
278 my $uid = 500;
279 my $gid = 500;
280
281 # Make sure that, if we're running as root, that the home directory has
282 # permissions/privs set for the account we create
283 if ($< == 0) {
284 unless (chmod(0755, $home_dir)) {
285 die("Can't set perms on $home_dir to 0755: $!");
286 }
287
288 unless (chown($uid, $gid, $home_dir)) {
289 die("Can't set owner of $home_dir to $uid/$gid: $!");
290 }
291 }
292
293 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
294 '/bin/bash');
295 auth_group_write($auth_group_file, $group, $gid, $user);
296
297 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
298 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
299
300 my $config = {
301 PidFile => $pid_file,
302 ScoreboardFile => $scoreboard_file,
303 SystemLog => $log_file,
304 TraceLog => $log_file,
305 Trace => 'ssh2:20 sftp:20',
306
307 AuthUserFile => $auth_user_file,
308 AuthGroupFile => $auth_group_file,
309 AuthOrder => 'mod_auth_file.c',
310
311 IfModules => {
312 'mod_delay.c' => {
313 DelayEngine => 'off',
314 },
315
316 'mod_sftp.c' => [
317 "SFTPEngine on",
318 "SFTPLog $log_file",
319 "SFTPHostKey $rsa_host_key",
320 "SFTPHostKey $dsa_host_key",
321 ],
322 },
323 };
324
325 my ($port, $config_user, $config_group) = config_write($config_file, $config);
326
327 # Open pipes, for use between the parent and child processes. Specifically,
328 # the child will indicate when it's done with its test by writing a message
329 # to the parent.
330 my ($rfh, $wfh);
331 unless (pipe($rfh, $wfh)) {
332 die("Can't open pipe: $!");
333 }
334
335 require Net::SSH2;
336
337 my $ex;
338
339 # Fork child
340 $self->handle_sigchld();
341 defined(my $pid = fork()) or die("Can't fork: $!");
342 if ($pid) {
343 eval {
344 my $ssh2 = Net::SSH2->new();
345
346 # Allow for longer startup time, due to the FIPS self-tests
347 sleep(2);
348
349 my $cipher = 'blowfish-cbc';
350 $ssh2->method('crypt_cs', $cipher);
351 $ssh2->method('crypt_sc', $cipher);
352
353 if ($ssh2->connect('127.0.0.1', $port)) {
354 die("Connected to SSH2 server unexpectedly");
355 }
356
357 my ($err_code, $err_name, $err_str) = $ssh2->error();
358
359 my $expected = 'LIBSSH2_ERROR_KEX_FAILURE';
360 $self->assert($expected eq $err_name,
361 test_msg("Expected error name '$expected', got '$err_name'"));
362
363 $ssh2->disconnect();
364 };
365
366 if ($@) {
367 $ex = $@;
368 }
369
370 $wfh->print("done\n");
371 $wfh->flush();
372
373 } else {
374 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
375 if ($@) {
376 warn($@);
377 exit 1;
378 }
379
380 exit 0;
381 }
382
383 # Stop server
384 server_stop($pid_file);
385
386 $self->assert_child_ok($pid);
387
388 if ($ex) {
389 test_append_logfile($log_file, $ex);
390 unlink($log_file);
391
392 die($ex);
393 }
394
395 unlink($log_file);
396 }
397
398 sub sftp_fips_cipher_3des_cbc {
399 my $self = shift;
400 my $tmpdir = $self->{tmpdir};
401
402 my $config_file = "$tmpdir/fips.conf";
403 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
404 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
405
406 my $log_file = test_get_logfile();
407
408 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
409 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
410
411 my $user = 'proftpd';
412 my $passwd = 'test';
413 my $group = 'ftpd';
414 my $home_dir = File::Spec->rel2abs($tmpdir);
415 my $uid = 500;
416 my $gid = 500;
417
418 # Make sure that, if we're running as root, that the home directory has
419 # permissions/privs set for the account we create
420 if ($< == 0) {
421 unless (chmod(0755, $home_dir)) {
422 die("Can't set perms on $home_dir to 0755: $!");
423 }
424
425 unless (chown($uid, $gid, $home_dir)) {
426 die("Can't set owner of $home_dir to $uid/$gid: $!");
427 }
428 }
429
430 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
431 '/bin/bash');
432 auth_group_write($auth_group_file, $group, $gid, $user);
433
434 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
435 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
436
437 my $config = {
438 PidFile => $pid_file,
439 ScoreboardFile => $scoreboard_file,
440 SystemLog => $log_file,
441 TraceLog => $log_file,
442 Trace => 'ssh2:20 sftp:20',
443
444 AuthUserFile => $auth_user_file,
445 AuthGroupFile => $auth_group_file,
446 AuthOrder => 'mod_auth_file.c',
447
448 IfModules => {
449 'mod_delay.c' => {
450 DelayEngine => 'off',
451 },
452
453 'mod_sftp.c' => [
454 "SFTPEngine on",
455 "SFTPLog $log_file",
456 "SFTPHostKey $rsa_host_key",
457 "SFTPHostKey $dsa_host_key",
458 ],
459 },
460 };
461
462 my ($port, $config_user, $config_group) = config_write($config_file, $config);
463
464 # Open pipes, for use between the parent and child processes. Specifically,
465 # the child will indicate when it's done with its test by writing a message
466 # to the parent.
467 my ($rfh, $wfh);
468 unless (pipe($rfh, $wfh)) {
469 die("Can't open pipe: $!");
470 }
471
472 require Net::SSH2;
473
474 my $ex;
475
476 # Fork child
477 $self->handle_sigchld();
478 defined(my $pid = fork()) or die("Can't fork: $!");
479 if ($pid) {
480 eval {
481 my $ssh2 = Net::SSH2->new();
482
483 # Allow for longer startup time, due to the FIPS self-tests
484 sleep(2);
485
486 my $cipher = '3des-cbc';
487 $ssh2->method('crypt_cs', $cipher);
488 $ssh2->method('crypt_sc', $cipher);
489
490 unless ($ssh2->connect('127.0.0.1', $port)) {
491 my ($err_code, $err_name, $err_str) = $ssh2->error();
492 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
493 }
494
495 my $cipher_used = $ssh2->method('crypt_cs');
496 $self->assert($cipher eq $cipher_used,
497 test_msg("Expected client-to-server cipher '$cipher', got '$cipher_used'"));
498
499 $cipher_used = $ssh2->method('crypt_sc');
500 $self->assert($cipher eq $cipher_used,
501 test_msg("Expected server-to-client MAC '$cipher', got '$cipher_used'"));
502
503 $ssh2->disconnect();
504 };
505
506 if ($@) {
507 $ex = $@;
508 }
509
510 $wfh->print("done\n");
511 $wfh->flush();
512
513 } else {
514 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
515 if ($@) {
516 warn($@);
517 exit 1;
518 }
519
520 exit 0;
521 }
522
523 # Stop server
524 server_stop($pid_file);
525
526 $self->assert_child_ok($pid);
527
528 if ($ex) {
529 test_append_logfile($log_file, $ex);
530 unlink($log_file);
531
532 die($ex);
533 }
534
535 unlink($log_file);
536 }
537
538 sub sftp_fips_cipher_aes128_cbc {
539 my $self = shift;
540 my $tmpdir = $self->{tmpdir};
541
542 my $config_file = "$tmpdir/fips.conf";
543 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
544 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
545
546 my $log_file = test_get_logfile();
547
548 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
549 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
550
551 my $user = 'proftpd';
552 my $passwd = 'test';
553 my $group = 'ftpd';
554 my $home_dir = File::Spec->rel2abs($tmpdir);
555 my $uid = 500;
556 my $gid = 500;
557
558 # Make sure that, if we're running as root, that the home directory has
559 # permissions/privs set for the account we create
560 if ($< == 0) {
561 unless (chmod(0755, $home_dir)) {
562 die("Can't set perms on $home_dir to 0755: $!");
563 }
564
565 unless (chown($uid, $gid, $home_dir)) {
566 die("Can't set owner of $home_dir to $uid/$gid: $!");
567 }
568 }
569
570 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
571 '/bin/bash');
572 auth_group_write($auth_group_file, $group, $gid, $user);
573
574 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
575 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
576
577 my $config = {
578 PidFile => $pid_file,
579 ScoreboardFile => $scoreboard_file,
580 SystemLog => $log_file,
581 TraceLog => $log_file,
582 Trace => 'ssh2:20 sftp:20',
583
584 AuthUserFile => $auth_user_file,
585 AuthGroupFile => $auth_group_file,
586 AuthOrder => 'mod_auth_file.c',
587
588 IfModules => {
589 'mod_delay.c' => {
590 DelayEngine => 'off',
591 },
592
593 'mod_sftp.c' => [
594 "SFTPEngine on",
595 "SFTPLog $log_file",
596 "SFTPHostKey $rsa_host_key",
597 "SFTPHostKey $dsa_host_key",
598 ],
599 },
600 };
601
602 my ($port, $config_user, $config_group) = config_write($config_file, $config);
603
604 # Open pipes, for use between the parent and child processes. Specifically,
605 # the child will indicate when it's done with its test by writing a message
606 # to the parent.
607 my ($rfh, $wfh);
608 unless (pipe($rfh, $wfh)) {
609 die("Can't open pipe: $!");
610 }
611
612 require Net::SSH2;
613
614 my $ex;
615
616 # Fork child
617 $self->handle_sigchld();
618 defined(my $pid = fork()) or die("Can't fork: $!");
619 if ($pid) {
620 eval {
621 my $ssh2 = Net::SSH2->new();
622
623 # Allow for longer startup time, due to the FIPS self-tests
624 sleep(2);
625
626 my $cipher = 'aes128-cbc';
627 $ssh2->method('crypt_cs', $cipher);
628 $ssh2->method('crypt_sc', $cipher);
629
630 unless ($ssh2->connect('127.0.0.1', $port)) {
631 my ($err_code, $err_name, $err_str) = $ssh2->error();
632 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
633 }
634
635 my $cipher_used = $ssh2->method('crypt_cs');
636 $self->assert($cipher eq $cipher_used,
637 test_msg("Expected client-to-server cipher '$cipher', got '$cipher_used'"));
638
639 $cipher_used = $ssh2->method('crypt_sc');
640 $self->assert($cipher eq $cipher_used,
641 test_msg("Expected server-to-client MAC '$cipher', got '$cipher_used'"));
642
643 $ssh2->disconnect();
644 };
645
646 if ($@) {
647 $ex = $@;
648 }
649
650 $wfh->print("done\n");
651 $wfh->flush();
652
653 } else {
654 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
655 if ($@) {
656 warn($@);
657 exit 1;
658 }
659
660 exit 0;
661 }
662
663 # Stop server
664 server_stop($pid_file);
665
666 $self->assert_child_ok($pid);
667
668 if ($ex) {
669 test_append_logfile($log_file, $ex);
670 unlink($log_file);
671
672 die($ex);
673 }
674
675 unlink($log_file);
676 }
677
678 sub sftp_fips_cipher_aes128_cbc_auth_publickey_rsa {
679 my $self = shift;
680 my $tmpdir = $self->{tmpdir};
681
682 my $config_file = "$tmpdir/fips.conf";
683 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
684 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
685
686 my $log_file = test_get_logfile();
687
688 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
689 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
690
691 my $user = 'proftpd';
692 my $passwd = 'test';
693 my $group = 'ftpd';
694 my $home_dir = File::Spec->rel2abs($tmpdir);
695 my $uid = 500;
696 my $gid = 500;
697
698 # Make sure that, if we're running as root, that the home directory has
699 # permissions/privs set for the account we create
700 if ($< == 0) {
701 unless (chmod(0755, $home_dir)) {
702 die("Can't set perms on $home_dir to 0755: $!");
703 }
704
705 unless (chown($uid, $gid, $home_dir)) {
706 die("Can't set owner of $home_dir to $uid/$gid: $!");
707 }
708 }
709
710 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
711 '/bin/bash');
712 auth_group_write($auth_group_file, $group, $gid, $user);
713
714 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
715 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
716
717 my $rsa_priv_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/test_rsa_key');
718 my $rsa_pub_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/test_rsa_key.pub');
719 my $rsa_rfc4716_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/authorized_rsa_subj_keys');
720
721 my $authorized_keys = File::Spec->rel2abs("$tmpdir/.authorized_keys");
722 unless (copy($rsa_rfc4716_key, $authorized_keys)) {
723 die("Can't copy $rsa_rfc4716_key to $authorized_keys: $!");
724 }
725
726 my $config = {
727 PidFile => $pid_file,
728 ScoreboardFile => $scoreboard_file,
729 SystemLog => $log_file,
730 TraceLog => $log_file,
731 Trace => 'ssh2:20 sftp:20',
732
733 AuthUserFile => $auth_user_file,
734 AuthGroupFile => $auth_group_file,
735 AuthOrder => 'mod_auth_file.c',
736
737 IfModules => {
738 'mod_delay.c' => {
739 DelayEngine => 'off',
740 },
741
742 'mod_sftp.c' => [
743 "SFTPEngine on",
744 "SFTPLog $log_file",
745 "SFTPHostKey $rsa_host_key",
746 "SFTPHostKey $dsa_host_key",
747 "SFTPAuthorizedUserKeys file:~/.authorized_keys",
748 ],
749 },
750 };
751
752 my ($port, $config_user, $config_group) = config_write($config_file, $config);
753
754 # Open pipes, for use between the parent and child processes. Specifically,
755 # the child will indicate when it's done with its test by writing a message
756 # to the parent.
757 my ($rfh, $wfh);
758 unless (pipe($rfh, $wfh)) {
759 die("Can't open pipe: $!");
760 }
761
762 require Net::SSH2;
763
764 my $ex;
765
766 # Fork child
767 $self->handle_sigchld();
768 defined(my $pid = fork()) or die("Can't fork: $!");
769 if ($pid) {
770 eval {
771 my $ssh2 = Net::SSH2->new();
772
773 # Allow for longer startup time, due to the FIPS self-tests
774 sleep(2);
775
776 my $cipher = 'aes128-cbc';
777 $ssh2->method('crypt_cs', $cipher);
778 $ssh2->method('crypt_sc', $cipher);
779
780 unless ($ssh2->connect('127.0.0.1', $port)) {
781 my ($err_code, $err_name, $err_str) = $ssh2->error();
782 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
783 }
784
785 my $cipher_used = $ssh2->method('crypt_cs');
786 $self->assert($cipher eq $cipher_used,
787 test_msg("Expected client-to-server cipher '$cipher', got '$cipher_used'"));
788
789 $cipher_used = $ssh2->method('crypt_sc');
790 $self->assert($cipher eq $cipher_used,
791 test_msg("Expected server-to-client MAC '$cipher', got '$cipher_used'"));
792
793 unless ($ssh2->auth_publickey($user, $rsa_pub_key, $rsa_priv_key)) {
794 my ($err_code, $err_name, $err_str) = $ssh2->error();
795 die("RSA publickey authentication failed: [$err_name] ($err_code) $err_str");
796 }
797
798 $ssh2->disconnect();
799 };
800
801 if ($@) {
802 $ex = $@;
803 }
804
805 $wfh->print("done\n");
806 $wfh->flush();
807
808 } else {
809 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
810 if ($@) {
811 warn($@);
812 exit 1;
813 }
814
815 exit 0;
816 }
817
818 # Stop server
819 server_stop($pid_file);
820
821 $self->assert_child_ok($pid);
822
823 if ($ex) {
824 test_append_logfile($log_file, $ex);
825 unlink($log_file);
826
827 die($ex);
828 }
829
830 unlink($log_file);
831 }
832
833 sub sftp_fips_cipher_aes128_cbc_auth_publickey_dsa {
834 my $self = shift;
835 my $tmpdir = $self->{tmpdir};
836
837 my $config_file = "$tmpdir/fips.conf";
838 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
839 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
840
841 my $log_file = test_get_logfile();
842
843 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
844 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
845
846 my $user = 'proftpd';
847 my $passwd = 'test';
848 my $group = 'ftpd';
849 my $home_dir = File::Spec->rel2abs($tmpdir);
850 my $uid = 500;
851 my $gid = 500;
852
853 # Make sure that, if we're running as root, that the home directory has
854 # permissions/privs set for the account we create
855 if ($< == 0) {
856 unless (chmod(0755, $home_dir)) {
857 die("Can't set perms on $home_dir to 0755: $!");
858 }
859
860 unless (chown($uid, $gid, $home_dir)) {
861 die("Can't set owner of $home_dir to $uid/$gid: $!");
862 }
863 }
864
865 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
866 '/bin/bash');
867 auth_group_write($auth_group_file, $group, $gid, $user);
868
869 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
870 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
871
872 my $dsa_priv_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/test_dsa_key');
873 my $dsa_pub_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/test_dsa_key.pub');
874 my $dsa_rfc4716_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/authorized_dsa_keys');
875
876 my $authorized_keys = File::Spec->rel2abs("$tmpdir/.authorized_keys");
877 unless (copy($dsa_rfc4716_key, $authorized_keys)) {
878 die("Can't copy $dsa_rfc4716_key to $authorized_keys: $!");
879 }
880
881 my $config = {
882 PidFile => $pid_file,
883 ScoreboardFile => $scoreboard_file,
884 SystemLog => $log_file,
885 TraceLog => $log_file,
886 Trace => 'ssh2:20 sftp:20',
887
888 AuthUserFile => $auth_user_file,
889 AuthGroupFile => $auth_group_file,
890 AuthOrder => 'mod_auth_file.c',
891
892 IfModules => {
893 'mod_delay.c' => {
894 DelayEngine => 'off',
895 },
896
897 'mod_sftp.c' => [
898 "SFTPEngine on",
899 "SFTPLog $log_file",
900 "SFTPHostKey $rsa_host_key",
901 "SFTPHostKey $dsa_host_key",
902 "SFTPAuthorizedUserKeys file:~/.authorized_keys",
903 ],
904 },
905 };
906
907 my ($port, $config_user, $config_group) = config_write($config_file, $config);
908
909 # Open pipes, for use between the parent and child processes. Specifically,
910 # the child will indicate when it's done with its test by writing a message
911 # to the parent.
912 my ($rfh, $wfh);
913 unless (pipe($rfh, $wfh)) {
914 die("Can't open pipe: $!");
915 }
916
917 require Net::SSH2;
918
919 my $ex;
920
921 # Fork child
922 $self->handle_sigchld();
923 defined(my $pid = fork()) or die("Can't fork: $!");
924 if ($pid) {
925 eval {
926 my $ssh2 = Net::SSH2->new();
927
928 # Allow for longer startup time, due to the FIPS self-tests
929 sleep(2);
930
931 my $cipher = 'aes128-cbc';
932 $ssh2->method('crypt_cs', $cipher);
933 $ssh2->method('crypt_sc', $cipher);
934
935 unless ($ssh2->connect('127.0.0.1', $port)) {
936 my ($err_code, $err_name, $err_str) = $ssh2->error();
937 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
938 }
939
940 my $cipher_used = $ssh2->method('crypt_cs');
941 $self->assert($cipher eq $cipher_used,
942 test_msg("Expected client-to-server cipher '$cipher', got '$cipher_used'"));
943
944 $cipher_used = $ssh2->method('crypt_sc');
945 $self->assert($cipher eq $cipher_used,
946 test_msg("Expected server-to-client MAC '$cipher', got '$cipher_used'"));
947
948 unless ($ssh2->auth_publickey($user, $dsa_pub_key, $dsa_priv_key)) {
949 my ($err_code, $err_name, $err_str) = $ssh2->error();
950 die("DSA publickey authentication failed: [$err_name] ($err_code) $err_str");
951 }
952
953 $ssh2->disconnect();
954 };
955
956 if ($@) {
957 $ex = $@;
958 }
959
960 $wfh->print("done\n");
961 $wfh->flush();
962
963 } else {
964 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
965 if ($@) {
966 warn($@);
967 exit 1;
968 }
969
970 exit 0;
971 }
972
973 # Stop server
974 server_stop($pid_file);
975
976 $self->assert_child_ok($pid);
977
978 if ($ex) {
979 test_append_logfile($log_file, $ex);
980 unlink($log_file);
981
982 die($ex);
983 }
984
985 unlink($log_file);
986 }
987
988 sub sftp_fips_cipher_aes128_ctr {
989 my $self = shift;
990 my $tmpdir = $self->{tmpdir};
991
992 my $config_file = "$tmpdir/fips.conf";
993 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
994 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
995
996 my $log_file = test_get_logfile();
997
998 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
999 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
1000
1001 my $user = 'proftpd';
1002 my $passwd = 'test';
1003 my $group = 'ftpd';
1004 my $home_dir = File::Spec->rel2abs($tmpdir);
1005 my $uid = 500;
1006 my $gid = 500;
1007
1008 # Make sure that, if we're running as root, that the home directory has
1009 # permissions/privs set for the account we create
1010 if ($< == 0) {
1011 unless (chmod(0755, $home_dir)) {
1012 die("Can't set perms on $home_dir to 0755: $!");
1013 }
1014
1015 unless (chown($uid, $gid, $home_dir)) {
1016 die("Can't set owner of $home_dir to $uid/$gid: $!");
1017 }
1018 }
1019
1020 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1021 '/bin/bash');
1022 auth_group_write($auth_group_file, $group, $gid, $user);
1023
1024 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
1025 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
1026
1027 my $config = {
1028 PidFile => $pid_file,
1029 ScoreboardFile => $scoreboard_file,
1030 SystemLog => $log_file,
1031 TraceLog => $log_file,
1032 Trace => 'ssh2:20 sftp:20',
1033
1034 AuthUserFile => $auth_user_file,
1035 AuthGroupFile => $auth_group_file,
1036 AuthOrder => 'mod_auth_file.c',
1037
1038 IfModules => {
1039 'mod_delay.c' => {
1040 DelayEngine => 'off',
1041 },
1042
1043 'mod_sftp.c' => [
1044 "SFTPEngine on",
1045 "SFTPLog $log_file",
1046 "SFTPHostKey $rsa_host_key",
1047 "SFTPHostKey $dsa_host_key",
1048 ],
1049 },
1050 };
1051
1052 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1053
1054 # Open pipes, for use between the parent and child processes. Specifically,
1055 # the child will indicate when it's done with its test by writing a message
1056 # to the parent.
1057 my ($rfh, $wfh);
1058 unless (pipe($rfh, $wfh)) {
1059 die("Can't open pipe: $!");
1060 }
1061
1062 require Net::SSH2;
1063
1064 my $ex;
1065
1066 # Fork child
1067 $self->handle_sigchld();
1068 defined(my $pid = fork()) or die("Can't fork: $!");
1069 if ($pid) {
1070 eval {
1071 my $ssh2 = Net::SSH2->new();
1072
1073 # Allow for longer startup time, due to the FIPS self-tests
1074 sleep(2);
1075
1076 my $cipher = 'aes128-ctr';
1077 $ssh2->method('crypt_cs', $cipher);
1078 $ssh2->method('crypt_sc', $cipher);
1079
1080 unless ($ssh2->connect('127.0.0.1', $port)) {
1081 my ($err_code, $err_name, $err_str) = $ssh2->error();
1082 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
1083 }
1084
1085 my $cipher_used = $ssh2->method('crypt_cs');
1086 $self->assert($cipher eq $cipher_used,
1087 test_msg("Expected client-to-server cipher '$cipher', got '$cipher_used'"));
1088
1089 $cipher_used = $ssh2->method('crypt_sc');
1090 $self->assert($cipher eq $cipher_used,
1091 test_msg("Expected server-to-client MAC '$cipher', got '$cipher_used'"));
1092
1093 $ssh2->disconnect();
1094 };
1095
1096 if ($@) {
1097 $ex = $@;
1098 }
1099
1100 $wfh->print("done\n");
1101 $wfh->flush();
1102
1103 } else {
1104 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
1105 if ($@) {
1106 warn($@);
1107 exit 1;
1108 }
1109
1110 exit 0;
1111 }
1112
1113 # Stop server
1114 server_stop($pid_file);
1115
1116 $self->assert_child_ok($pid);
1117
1118 if ($ex) {
1119 test_append_logfile($log_file, $ex);
1120 unlink($log_file);
1121
1122 die($ex);
1123 }
1124
1125 unlink($log_file);
1126 }
1127
1128 sub sftp_fips_mac_hmac_md5 {
1129 my $self = shift;
1130 my $tmpdir = $self->{tmpdir};
1131
1132 my $config_file = "$tmpdir/fips.conf";
1133 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
1134 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
1135
1136 my $log_file = test_get_logfile();
1137
1138 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
1139 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
1140
1141 my $user = 'proftpd';
1142 my $passwd = 'test';
1143 my $group = 'ftpd';
1144 my $home_dir = File::Spec->rel2abs($tmpdir);
1145 my $uid = 500;
1146 my $gid = 500;
1147
1148 # Make sure that, if we're running as root, that the home directory has
1149 # permissions/privs set for the account we create
1150 if ($< == 0) {
1151 unless (chmod(0755, $home_dir)) {
1152 die("Can't set perms on $home_dir to 0755: $!");
1153 }
1154
1155 unless (chown($uid, $gid, $home_dir)) {
1156 die("Can't set owner of $home_dir to $uid/$gid: $!");
1157 }
1158 }
1159
1160 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1161 '/bin/bash');
1162 auth_group_write($auth_group_file, $group, $gid, $user);
1163
1164 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
1165 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
1166
1167 my $config = {
1168 PidFile => $pid_file,
1169 ScoreboardFile => $scoreboard_file,
1170 SystemLog => $log_file,
1171 TraceLog => $log_file,
1172 Trace => 'ssh2:20 sftp:20',
1173
1174 AuthUserFile => $auth_user_file,
1175 AuthGroupFile => $auth_group_file,
1176 AuthOrder => 'mod_auth_file.c',
1177
1178 IfModules => {
1179 'mod_delay.c' => {
1180 DelayEngine => 'off',
1181 },
1182
1183 'mod_sftp.c' => [
1184 "SFTPEngine on",
1185 "SFTPLog $log_file",
1186 "SFTPHostKey $rsa_host_key",
1187 "SFTPHostKey $dsa_host_key",
1188 ],
1189 },
1190 };
1191
1192 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1193
1194 # Open pipes, for use between the parent and child processes. Specifically,
1195 # the child will indicate when it's done with its test by writing a message
1196 # to the parent.
1197 my ($rfh, $wfh);
1198 unless (pipe($rfh, $wfh)) {
1199 die("Can't open pipe: $!");
1200 }
1201
1202 require Net::SSH2;
1203
1204 my $ex;
1205
1206 # Fork child
1207 $self->handle_sigchld();
1208 defined(my $pid = fork()) or die("Can't fork: $!");
1209 if ($pid) {
1210 eval {
1211 my $ssh2 = Net::SSH2->new();
1212
1213 # Allow for longer startup time, due to the FIPS self-tests
1214 sleep(2);
1215
1216 my $mac = 'hmac-md5';
1217 $ssh2->method('mac_cs', $mac);
1218 $ssh2->method('mac_sc', $mac);
1219
1220 if ($ssh2->connect('127.0.0.1', $port)) {
1221 die("Connected to SSH2 server unexpectedly");
1222 }
1223
1224 my ($err_code, $err_name, $err_str) = $ssh2->error();
1225
1226 my $expected = 'LIBSSH2_ERROR_KEX_FAILURE';
1227 $self->assert($expected eq $err_name,
1228 test_msg("Expected error name '$expected', got '$err_name'"));
1229
1230 $ssh2->disconnect();
1231 };
1232
1233 if ($@) {
1234 $ex = $@;
1235 }
1236
1237 $wfh->print("done\n");
1238 $wfh->flush();
1239
1240 } else {
1241 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
1242 if ($@) {
1243 warn($@);
1244 exit 1;
1245 }
1246
1247 exit 0;
1248 }
1249
1250 # Stop server
1251 server_stop($pid_file);
1252
1253 $self->assert_child_ok($pid);
1254
1255 if ($ex) {
1256 test_append_logfile($log_file, $ex);
1257 unlink($log_file);
1258
1259 die($ex);
1260 }
1261
1262 unlink($log_file);
1263 }
1264
1265 sub sftp_fips_mac_hmac_md5_96 {
1266 my $self = shift;
1267 my $tmpdir = $self->{tmpdir};
1268
1269 my $config_file = "$tmpdir/fips.conf";
1270 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
1271 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
1272
1273 my $log_file = test_get_logfile();
1274
1275 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
1276 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
1277
1278 my $user = 'proftpd';
1279 my $passwd = 'test';
1280 my $group = 'ftpd';
1281 my $home_dir = File::Spec->rel2abs($tmpdir);
1282 my $uid = 500;
1283 my $gid = 500;
1284
1285 # Make sure that, if we're running as root, that the home directory has
1286 # permissions/privs set for the account we create
1287 if ($< == 0) {
1288 unless (chmod(0755, $home_dir)) {
1289 die("Can't set perms on $home_dir to 0755: $!");
1290 }
1291
1292 unless (chown($uid, $gid, $home_dir)) {
1293 die("Can't set owner of $home_dir to $uid/$gid: $!");
1294 }
1295 }
1296
1297 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1298 '/bin/bash');
1299 auth_group_write($auth_group_file, $group, $gid, $user);
1300
1301 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
1302 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
1303
1304 my $config = {
1305 PidFile => $pid_file,
1306 ScoreboardFile => $scoreboard_file,
1307 SystemLog => $log_file,
1308 TraceLog => $log_file,
1309 Trace => 'ssh2:20 sftp:20',
1310
1311 AuthUserFile => $auth_user_file,
1312 AuthGroupFile => $auth_group_file,
1313 AuthOrder => 'mod_auth_file.c',
1314
1315 IfModules => {
1316 'mod_delay.c' => {
1317 DelayEngine => 'off',
1318 },
1319
1320 'mod_sftp.c' => [
1321 "SFTPEngine on",
1322 "SFTPLog $log_file",
1323 "SFTPHostKey $rsa_host_key",
1324 "SFTPHostKey $dsa_host_key",
1325 ],
1326 },
1327 };
1328
1329 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1330
1331 # Open pipes, for use between the parent and child processes. Specifically,
1332 # the child will indicate when it's done with its test by writing a message
1333 # to the parent.
1334 my ($rfh, $wfh);
1335 unless (pipe($rfh, $wfh)) {
1336 die("Can't open pipe: $!");
1337 }
1338
1339 require Net::SSH2;
1340
1341 my $ex;
1342
1343 # Fork child
1344 $self->handle_sigchld();
1345 defined(my $pid = fork()) or die("Can't fork: $!");
1346 if ($pid) {
1347 eval {
1348 my $ssh2 = Net::SSH2->new();
1349
1350 # Allow for longer startup time, due to the FIPS self-tests
1351 sleep(2);
1352
1353 my $mac = 'hmac-md5-96';
1354 $ssh2->method('mac_cs', $mac);
1355 $ssh2->method('mac_sc', $mac);
1356
1357 if ($ssh2->connect('127.0.0.1', $port)) {
1358 die("Connected to SSH2 server unexpectedly");
1359 }
1360
1361 my ($err_code, $err_name, $err_str) = $ssh2->error();
1362
1363 my $expected = 'LIBSSH2_ERROR_KEX_FAILURE';
1364 $self->assert($expected eq $err_name,
1365 test_msg("Expected error name '$expected', got '$err_name'"));
1366
1367 $ssh2->disconnect();
1368 };
1369
1370 if ($@) {
1371 $ex = $@;
1372 }
1373
1374 $wfh->print("done\n");
1375 $wfh->flush();
1376
1377 } else {
1378 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
1379 if ($@) {
1380 warn($@);
1381 exit 1;
1382 }
1383
1384 exit 0;
1385 }
1386
1387 # Stop server
1388 server_stop($pid_file);
1389
1390 $self->assert_child_ok($pid);
1391
1392 if ($ex) {
1393 test_append_logfile($log_file, $ex);
1394 unlink($log_file);
1395
1396 die($ex);
1397 }
1398
1399 unlink($log_file);
1400 }
1401
1402 sub sftp_fips_mac_ripemd160 {
1403 my $self = shift;
1404 my $tmpdir = $self->{tmpdir};
1405
1406 my $config_file = "$tmpdir/fips.conf";
1407 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
1408 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
1409
1410 my $log_file = test_get_logfile();
1411
1412 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
1413 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
1414
1415 my $user = 'proftpd';
1416 my $passwd = 'test';
1417 my $group = 'ftpd';
1418 my $home_dir = File::Spec->rel2abs($tmpdir);
1419 my $uid = 500;
1420 my $gid = 500;
1421
1422 # Make sure that, if we're running as root, that the home directory has
1423 # permissions/privs set for the account we create
1424 if ($< == 0) {
1425 unless (chmod(0755, $home_dir)) {
1426 die("Can't set perms on $home_dir to 0755: $!");
1427 }
1428
1429 unless (chown($uid, $gid, $home_dir)) {
1430 die("Can't set owner of $home_dir to $uid/$gid: $!");
1431 }
1432 }
1433
1434 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1435 '/bin/bash');
1436 auth_group_write($auth_group_file, $group, $gid, $user);
1437
1438 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
1439 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
1440
1441 my $config = {
1442 PidFile => $pid_file,
1443 ScoreboardFile => $scoreboard_file,
1444 SystemLog => $log_file,
1445 TraceLog => $log_file,
1446 Trace => 'ssh2:20 sftp:20',
1447
1448 AuthUserFile => $auth_user_file,
1449 AuthGroupFile => $auth_group_file,
1450 AuthOrder => 'mod_auth_file.c',
1451
1452 IfModules => {
1453 'mod_delay.c' => {
1454 DelayEngine => 'off',
1455 },
1456
1457 'mod_sftp.c' => [
1458 "SFTPEngine on",
1459 "SFTPLog $log_file",
1460 "SFTPHostKey $rsa_host_key",
1461 "SFTPHostKey $dsa_host_key",
1462 ],
1463 },
1464 };
1465
1466 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1467
1468 # Open pipes, for use between the parent and child processes. Specifically,
1469 # the child will indicate when it's done with its test by writing a message
1470 # to the parent.
1471 my ($rfh, $wfh);
1472 unless (pipe($rfh, $wfh)) {
1473 die("Can't open pipe: $!");
1474 }
1475
1476 require Net::SSH2;
1477
1478 my $ex;
1479
1480 # Fork child
1481 $self->handle_sigchld();
1482 defined(my $pid = fork()) or die("Can't fork: $!");
1483 if ($pid) {
1484 eval {
1485 my $ssh2 = Net::SSH2->new();
1486
1487 # Allow for longer startup time, due to the FIPS self-tests
1488 sleep(2);
1489
1490 my $mac = 'hmac-ripemd160';
1491 $ssh2->method('mac_cs', $mac);
1492 $ssh2->method('mac_sc', $mac);
1493
1494 if ($ssh2->connect('127.0.0.1', $port)) {
1495 die("Connected to SSH2 server unexpectedly");
1496 }
1497
1498 my ($err_code, $err_name, $err_str) = $ssh2->error();
1499
1500 my $expected = 'LIBSSH2_ERROR_KEX_FAILURE';
1501 $self->assert($expected eq $err_name,
1502 test_msg("Expected error name '$expected', got '$err_name'"));
1503
1504 $ssh2->disconnect();
1505 };
1506
1507 if ($@) {
1508 $ex = $@;
1509 }
1510
1511 $wfh->print("done\n");
1512 $wfh->flush();
1513
1514 } else {
1515 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
1516 if ($@) {
1517 warn($@);
1518 exit 1;
1519 }
1520
1521 exit 0;
1522 }
1523
1524 # Stop server
1525 server_stop($pid_file);
1526
1527 $self->assert_child_ok($pid);
1528
1529 if ($ex) {
1530 test_append_logfile($log_file, $ex);
1531 unlink($log_file);
1532
1533 die($ex);
1534 }
1535
1536 unlink($log_file);
1537 }
1538
1539 sub sftp_fips_mac_hmac_sha1 {
1540 my $self = shift;
1541 my $tmpdir = $self->{tmpdir};
1542
1543 my $config_file = "$tmpdir/fips.conf";
1544 my $pid_file = File::Spec->rel2abs("$tmpdir/fips.pid");
1545 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/fips.scoreboard");
1546
1547 my $log_file = test_get_logfile();
1548
1549 my $auth_user_file = File::Spec->rel2abs("$tmpdir/fips.passwd");
1550 my $auth_group_file = File::Spec->rel2abs("$tmpdir/fips.group");
1551
1552 my $user = 'proftpd';
1553 my $passwd = 'test';
1554 my $group = 'ftpd';
1555 my $home_dir = File::Spec->rel2abs($tmpdir);
1556 my $uid = 500;
1557 my $gid = 500;
1558
1559 # Make sure that, if we're running as root, that the home directory has
1560 # permissions/privs set for the account we create
1561 if ($< == 0) {
1562 unless (chmod(0755, $home_dir)) {
1563 die("Can't set perms on $home_dir to 0755: $!");
1564 }
1565
1566 unless (chown($uid, $gid, $home_dir)) {
1567 die("Can't set owner of $home_dir to $uid/$gid: $!");
1568 }
1569 }
1570
1571 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1572 '/bin/bash');
1573 auth_group_write($auth_group_file, $group, $gid, $user);
1574
1575 my $rsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_rsa_key');
1576 my $dsa_host_key = File::Spec->rel2abs('t/etc/modules/mod_sftp/ssh_host_dsa_key');
1577
1578 my $config = {
1579 PidFile => $pid_file,
1580 ScoreboardFile => $scoreboard_file,
1581 SystemLog => $log_file,
1582 TraceLog => $log_file,
1583 Trace => 'ssh2:20 sftp:20',
1584
1585 AuthUserFile => $auth_user_file,
1586 AuthGroupFile => $auth_group_file,
1587 AuthOrder => 'mod_auth_file.c',
1588
1589 IfModules => {
1590 'mod_delay.c' => {
1591 DelayEngine => 'off',
1592 },
1593
1594 'mod_sftp.c' => [
1595 "SFTPEngine on",
1596 "SFTPLog $log_file",
1597 "SFTPHostKey $rsa_host_key",
1598 "SFTPHostKey $dsa_host_key",
1599 ],
1600 },
1601 };
1602
1603 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1604
1605 # Open pipes, for use between the parent and child processes. Specifically,
1606 # the child will indicate when it's done with its test by writing a message
1607 # to the parent.
1608 my ($rfh, $wfh);
1609 unless (pipe($rfh, $wfh)) {
1610 die("Can't open pipe: $!");
1611 }
1612
1613 require Net::SSH2;
1614
1615 my $ex;
1616
1617 # Fork child
1618 $self->handle_sigchld();
1619 defined(my $pid = fork()) or die("Can't fork: $!");
1620 if ($pid) {
1621 eval {
1622 my $ssh2 = Net::SSH2->new();
1623
1624 # Allow for longer startup time, due to the FIPS self-tests
1625 sleep(2);
1626
1627 my $mac = 'hmac-sha1';
1628 $ssh2->method('mac_cs', $mac);
1629 $ssh2->method('mac_sc', $mac);
1630
1631 unless ($ssh2->connect('127.0.0.1', $port)) {
1632 my ($err_code, $err_name, $err_str) = $ssh2->error();
1633 die("Can't connect to SSH2 server: [$err_name] ($err_code) $err_str");
1634 }
1635
1636 my $mac_used = $ssh2->method('mac_cs');
1637 $self->assert($mac eq $mac_used,
1638 test_msg("Expected client-to-server MAC '$mac', got '$mac_used'"));
1639
1640 $mac_used = $ssh2->method('mac_sc');
1641 $self->assert($mac eq $mac_used,
1642 test_msg("Expected server-to-client MAC '$mac', got '$mac_used'"));
1643
1644 $ssh2->disconnect();
1645 };
1646
1647 if ($@) {
1648 $ex = $@;
1649 }
1650
1651 $wfh->print("done\n");
1652 $wfh->flush();
1653
1654 } else {
1655 eval { server_wait($config_file, $rfh, { define => ['SFTP_USE_FIPS'] }) };
1656 if ($@) {
1657 warn($@);
1658 exit 1;
1659 }
1660
1661 exit 0;
1662 }
1663
1664 # Stop server
1665 server_stop($pid_file);
1666
1667 $self->assert_child_ok($pid);
1668
1669 if ($ex) {
1670 test_append_logfile($log_file, $ex);
1671 unlink($log_file);
1672
1673 die($ex);
1674 }
1675
1676 unlink($log_file);
1677 }
1678
1679 1;