Debian Codegraph @

tests/t/lib/ProFTPD/Tests/Modules/mod_tls.pm

raw
1 package ProFTPD::Tests::Modules::mod_tls;
2
3 use lib qw(t/lib);
4 use base qw(ProFTPD::TestSuite::Child);
5 use strict;
6
7 use Carp;
8 use File::Copy;
9 use File::Path qw(mkpath);
10 use File::Spec;
11 use IO::Handle;
12 use IPC::Open3;
13 use Socket;
14
15 use ProFTPD::TestSuite::FTP;
16 use ProFTPD::TestSuite::Utils qw(:auth :config :features :running :test :testsuite);
17
18 $| = 1;
19
20 my $order = 0;
21
22 my $TESTS = {
23 tls_login_rsa => {
24 order => ++$order,
25 test_class => [qw(forking)],
26 },
27
28 tls_login_dsa => {
29 order => ++$order,
30 test_class => [qw(forking)],
31 },
32
33 tls_double_auth => {
34 order => ++$order,
35 test_class => [qw(bug forking)],
36 },
37
38 tls_login_pkcs12 => {
39 order => ++$order,
40 test_class => [qw(forking)],
41 },
42
43 tls_dh_ciphersuite => {
44 order => ++$order,
45 test_class => [qw(forking)],
46 },
47
48 tls_crl_file_ok => {
49 order => ++$order,
50 test_class => [qw(forking)],
51 },
52
53 tls_crl_file_other_ca_bug4468 => {
54 order => ++$order,
55 test_class => [qw(bug forking)],
56 },
57
58 tls_crl_file_multiple_cas_crls_issue1960 => {
59 order => ++$order,
60 test_class => [qw(bug forking)],
61 },
62
63 tls_login_with_sni_issue850 => {
64 order => ++$order,
65 test_class => [qw(forking)],
66 },
67
68 tls_login_with_sni_unknown_host_issue850 => {
69 order => ++$order,
70 test_class => [qw(forking)],
71 },
72
73 tls_login_with_sni_unknown_host_no_serveraliases_issue850 => {
74 order => ++$order,
75 test_class => [qw(forking)],
76 },
77
78 tls_login_with_sni_tlsengine_off_issue850 => {
79 order => ++$order,
80 test_class => [qw(forking)],
81 },
82
83 tls_login_with_sni_different_certs_issue850 => {
84 order => ++$order,
85 test_class => [qw(forking)],
86 },
87
88 tls_login_with_sni_ignored_issue850 => {
89 order => ++$order,
90 test_class => [qw(forking)],
91 },
92
93 tls_login_with_sni_mismatched_host_issue850 => {
94 order => ++$order,
95 test_class => [qw(forking)],
96 },
97
98 tls_login_with_sni_matching_host_issue850 => {
99 order => ++$order,
100 test_class => [qw(forking)],
101 },
102
103 tls_login_with_sni_matching_host_case_insensitive_issue850 => {
104 order => ++$order,
105 test_class => [qw(forking)],
106 },
107
108 tls_login_with_sni_mismatched_protocol_version_issue850 => {
109 order => ++$order,
110 test_class => [qw(forking)],
111 },
112
113 tls_login_with_sni_port_zero_issue932 => {
114 order => ++$order,
115 test_class => [qw(bug forking)],
116 },
117
118 tls_login_with_sni_port_nonzero_issue932 => {
119 order => ++$order,
120 test_class => [qw(bug forking)],
121 },
122
123 tls_login_with_sni_port_zero_socketbindtight_on_issue932 => {
124 order => ++$order,
125 test_class => [qw(bug forking)],
126 },
127
128 tls_login_with_sni_port_zero_multi_ports_issue932 => {
129 order => ++$order,
130 test_class => [qw(bug forking)],
131 },
132
133 tls_login_before_auth_without_opt_allow_per_user_issue1533 => {
134 order => ++$order,
135 test_class => [qw(bug forking)],
136 },
137
138 tls_list_no_session_reuse => {
139 order => ++$order,
140 test_class => [qw(forking)],
141 },
142
143 tls_list_with_session_reuse => {
144 order => ++$order,
145 test_class => [qw(forking)],
146 },
147
148 tls_list_with_no_session_reuse_required_opt => {
149 order => ++$order,
150 test_class => [qw(forking)],
151 },
152
153 tls_list_fails_tls_required_by_dir_bug2178 => {
154 order => ++$order,
155 test_class => [qw(bug forking)],
156 },
157
158 tls_list_ok_tls_required_by_dir_bug2178 => {
159 order => ++$order,
160 test_class => [qw(bug forking)],
161 },
162
163 tls_list_fails_tls_required_by_ftpaccess_bug2178 => {
164 order => ++$order,
165 test_class => [qw(bug forking)],
166 },
167
168 tls_list_ok_tls_required_by_ftpaccess_bug2178 => {
169 order => ++$order,
170 test_class => [qw(bug forking)],
171 },
172
173 tls_incompatible_config_bug3247 => {
174 order => ++$order,
175 test_class => [qw(bug forking)],
176 },
177
178 # Note: this test requires rootprivs to bind to port 990
179 tls_implicit_ssl_bug3266 => {
180 order => ++$order,
181 test_class => [qw(bug forking rootprivs)],
182 },
183
184 tls_client_cert_verify_failed_embedded_nul_bug3275 => {
185 order => ++$order,
186 test_class => [qw(bug forking)],
187 },
188
189 tls_opts_std_env_vars => {
190 order => ++$order,
191 test_class => [qw(forking)],
192 },
193
194 tls_opts_std_env_vars_client_vars => {
195 order => ++$order,
196 test_class => [qw(forking)],
197 },
198
199 tls_opts_ipaddr_required_ipv4 => {
200 order => ++$order,
201 test_class => [qw(forking)],
202 },
203
204 tls_opts_ipaddr_required_ipv6 => {
205 order => ++$order,
206 test_class => [qw(forking)],
207 },
208
209 tls_opts_allow_per_user_tlsrequired_on_anon_login_bug3325 => {
210 order => ++$order,
211 test_class => [qw(bug forking rootprivs)],
212 },
213
214 tls_opts_allow_per_user_tlsrequired_on_user_login_bug3325 => {
215 order => ++$order,
216 test_class => [qw(bug forking)],
217 },
218
219 tls_opts_allow_per_user_tlsrequired_auth_user_login_bug3325 => {
220 order => ++$order,
221 test_class => [qw(bug forking)],
222 },
223
224 tls_opts_allow_per_user_tlsrequired_ctrl_user_login_bug3325 => {
225 order => ++$order,
226 test_class => [qw(bug forking)],
227 },
228
229 tls_opts_allow_per_user_tlsrequired_data_user_login_bug3325 => {
230 order => ++$order,
231 test_class => [qw(bug forking)],
232 },
233
234 tls_opts_allow_per_user_tlsrequired_on_ifsess_login_bug3325 => {
235 order => ++$order,
236 test_class => [qw(bug forking mod_ifsession)],
237 },
238
239 tls_opts_allow_per_user_nosessionreuserequired_ifsess_login_issue1175 => {
240 order => ++$order,
241 test_class => [qw(bug forking mod_ifsession)],
242 },
243
244 tls_opts_allow_per_user_tlsrequired_off_ifsess_protocols_issue1679 => {
245 order => ++$order,
246 test_class => [qw(bug forking mod_ifsession)],
247 },
248
249 tls_opts_allow_per_user_tlsrequired_on_ifsess_no_tls_issue1640 => {
250 order => ++$order,
251 test_class => [qw(bug forking mod_ifsession)],
252 },
253
254 tls_opts_allow_weak_security_issue1048 => {
255 order => ++$order,
256 test_class => [qw(forking)],
257 },
258
259 tls_rest_2gb_last_byte => {
260 order => ++$order,
261 test_class => [qw(forking)],
262 },
263
264 tls_rest_4gb_last_byte => {
265 order => ++$order,
266 test_class => [qw(forking)],
267 },
268
269 tls_stor_empty_file => {
270 order => ++$order,
271 test_class => [qw(forking)],
272 },
273
274 tls_retr_empty_file => {
275 order => ++$order,
276 test_class => [qw(forking)],
277 },
278
279 tls_required_on_feat_allowed_bug3420 => {
280 order => ++$order,
281 test_class => [qw(bug forking)],
282 },
283
284 # Note: this test requires rootprivs to bind to port 990
285 tls_implicit_ssl_bug3437 => {
286 order => ++$order,
287 test_class => [qw(bug forking rootprivs)],
288 },
289
290 tls_ccc_list_bug3465 => {
291 order => ++$order,
292 test_class => [qw(bug forking)],
293 },
294
295 tls_ccc_before_login => {
296 order => ++$order,
297 test_class => [qw(bug forking)],
298 },
299
300 tls_opts_commonname_required_bug3512 => {
301 order => ++$order,
302 test_class => [qw(bug forking)],
303 },
304
305 tls_opts_dns_name_required => {
306 order => ++$order,
307 test_class => [qw(forking)],
308 },
309
310 tls_opts_ip_addr_dns_name_cn_required => {
311 order => ++$order,
312 test_class => [qw(forking)],
313 },
314
315 tls_site_chmod_ok => {
316 order => ++$order,
317 test_class => [qw(forking)],
318 },
319
320 tls_default_tlsrequired => {
321 order => ++$order,
322 test_class => [qw(forking)],
323 },
324
325 tls_protocols_default => {
326 order => ++$order,
327 test_class => [qw(forking)],
328 },
329
330 tls_protocols_with_ftps => {
331 order => ++$order,
332 test_class => [qw(forking)],
333 },
334
335 tls_protocols_without_ftps => {
336 order => ++$order,
337 test_class => [qw(forking)],
338 },
339
340 tls_ifsess_protocols_with_ftps => {
341 order => ++$order,
342 test_class => [qw(forking mod_ifsession)],
343 },
344
345 tls_ifsess_protocols_without_ftps => {
346 order => ++$order,
347 test_class => [qw(forking mod_ifsession)],
348 },
349
350 tls_sess_cache_internal_bug3580 => {
351 order => ++$order,
352 test_class => [qw(bug forking)],
353 },
354
355 tls_passphraseprovider_rsacertfile => {
356 order => ++$order,
357 test_class => [qw(forking)],
358 },
359
360 tls_passphraseprovider_rsakeyfile_issue1179 => {
361 order => ++$order,
362 test_class => [qw(forking)],
363 },
364
365 tls_verify_order_crl_bug3658 => {
366 order => ++$order,
367 test_class => [qw(bug forking)],
368 },
369
370 tls_verify_order_ocsp => {
371 order => ++$order,
372 test_class => [qw(bug forking)],
373 },
374
375 # XXX Need to find a working HTTPS OCSP responder for this test;
376 # OpenSSL's ocsp(1) responder does NOT function in HTTPS mode, contrary
377 # to the impression given by its docs.
378 tls_verify_order_ocsp_https => {
379 order => ++$order,
380 test_class => [qw(bug forking inprogress)],
381 },
382
383 tls_client_cert_verify_failed_selfsigned_cert_only_bug3742 => {
384 order => ++$order,
385 test_class => [qw(bug forking)],
386 },
387
388 tls_client_cert_verify_failed_selfsigned_cert_in_chain_bug3742 => {
389 order => ++$order,
390 test_class => [qw(bug forking)],
391 },
392
393 tls_client_cert_verify_ok_server_selfsigned_cert_in_chain_bug3742 => {
394 order => ++$order,
395 test_class => [qw(bug forking)],
396 },
397
398 tls_opts_allow_dot_login_ok => {
399 order => ++$order,
400 test_class => [qw(forking)],
401 },
402
403 tls_opts_allow_dot_login_mismatch => {
404 order => ++$order,
405 test_class => [qw(forking)],
406 },
407
408 tls_opts_multiple_lines_bug3800 => {
409 order => ++$order,
410 test_class => [qw(bug forking)],
411 },
412
413 tls_config_tlsmasqueradeaddress_bug3862 => {
414 order => ++$order,
415 test_class => [qw(bug forking)],
416 },
417
418 tls_config_tlsdhparamfile_bug3868 => {
419 order => ++$order,
420 test_class => [qw(bug forking)],
421 },
422
423 tls_config_tlsciphersuite_bad_cipher => {
424 order => ++$order,
425 test_class => [qw(forking)],
426 },
427
428 tls_config_tlscacertfile_bad_format => {
429 order => ++$order,
430 test_class => [qw(forking)],
431 },
432
433 tls_config_tlscarevocationfile_bad_format => {
434 order => ++$order,
435 test_class => [qw(forking)],
436 },
437
438 tls_config_tlsdsacertfile_bad_format => {
439 order => ++$order,
440 test_class => [qw(forking)],
441 },
442
443 tls_config_tlsdsacertfile_not_dsa => {
444 order => ++$order,
445 test_class => [qw(forking)],
446 },
447
448 tls_config_tlsdsacertkeyfile_bad_format => {
449 order => ++$order,
450 test_class => [qw(forking)],
451 },
452
453 tls_config_tlsrsacertkeyfile_passphrase => {
454 order => ++$order,
455 test_class => [qw(forking)],
456 },
457
458 tls_session_cache_off_bug3869 => {
459 order => ++$order,
460 test_class => [qw(bug forking)],
461 },
462
463 tls_limit_prot_bug3887 => {
464 order => ++$order,
465 test_class => [qw(bug forking)],
466 },
467
468 tls_config_tlsusername_bug3899 => {
469 order => ++$order,
470 test_class => [qw(bug forking)],
471 },
472
473 tls_config_tlsrenegotiate_ctrl => {
474 order => ++$order,
475 test_class => [qw(bug forking)],
476 },
477
478 tls_config_tlsrenegotiate_download => {
479 order => ++$order,
480 test_class => [qw(bug forking)],
481 },
482
483 tls_config_tlsrenegotiate_upload => {
484 order => ++$order,
485 test_class => [qw(bug forking)],
486 },
487
488 tls_sscn_no_args_bug3955 => {
489 order => ++$order,
490 test_class => [qw(bug forking)],
491 },
492
493 tls_sscn_too_many_args_bug3955 => {
494 order => ++$order,
495 test_class => [qw(bug forking)],
496 },
497
498 tls_sscn_bad_arg_bug3955 => {
499 order => ++$order,
500 test_class => [qw(bug forking)],
501 },
502
503 tls_sscn_toggle_bug3955 => {
504 order => ++$order,
505 test_class => [qw(bug forking)],
506 },
507
508 tls_config_limit_sscn_bug3955 => {
509 order => ++$order,
510 test_class => [qw(bug forking)],
511 },
512
513 tls_config_missing_certs => {
514 order => ++$order,
515 test_class => [qw(bug forking)],
516 },
517
518 tls_stapling_on_bug4175 => {
519 order => ++$order,
520 test_class => [qw(bug forking)],
521 },
522
523 tls_session_tickets_on_bug4176 => {
524 order => ++$order,
525 test_class => [qw(bug forking inprogress)],
526 },
527
528 tls_restart_protected_certs_bug4260 => {
529 order => ++$order,
530 test_class => [qw(bug forking)],
531 },
532
533 tls_fxp_issue618 => {
534 order => ++$order,
535 test_class => [qw(bug forking)],
536 },
537
538 tls_old_protocols_issue1273 => {
539 order => ++$order,
540 test_class => [qw(bug forking)],
541 },
542
543 tls_curl_download_largefile_renegotiate_bug4443 => {
544 order => ++$order,
545 test_class => [qw(bug forking slow)],
546 },
547
548 tls_useimplicitssl_tcp_connect_only => {
549 order => ++$order,
550 test_class => [qw(bug forking)],
551 },
552
553 tls_explicit_plaintext_fallback_issue192 => {
554 order => ++$order,
555 test_class => [qw(bug forking)],
556 },
557
558 tls_implicit_plaintext_fallback_issue192 => {
559 order => ++$order,
560 test_class => [qw(bug forking)],
561 },
562
563 };
564
565 sub new {
566 return shift()->SUPER::new(@_);
567 }
568
569 sub list_tests {
570 # Check for the required Perl modules:
571 #
572 # Net-SSLeay
573 # IO-Socket-SSL
574 # Net-FTPSSL
575
576 my $required = [qw(
577 Net::SSLeay
578 IO::Socket::SSL
579 Net::FTPSSL
580 )];
581
582 foreach my $req (@$required) {
583 eval "use $req";
584 if ($@) {
585 print STDERR "\nWARNING:\n + Module '$req' not found, skipping all tests\n";
586
587 if ($ENV{TEST_VERBOSE}) {
588 print STDERR "Unable to load $req: $@\n";
589 }
590
591 return qw(testsuite_empty_test);
592 }
593 }
594
595 return testsuite_get_runnable_tests($TESTS);
596 }
597
598 sub tls_login_rsa {
599 my $self = shift;
600 my $tmpdir = $self->{tmpdir};
601
602 my $config_file = "$tmpdir/tls.conf";
603 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
604 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
605
606 my $log_file = test_get_logfile();
607
608 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
609 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
610
611 my $user = 'proftpd';
612 my $passwd = 'test';
613 my $group = 'ftpd';
614 my $home_dir = File::Spec->rel2abs($tmpdir);
615 my $uid = 500;
616 my $gid = 500;
617
618 # Make sure that, if we're running as root, that the home directory has
619 # permissions/privs set for the account we create
620 if ($< == 0) {
621 unless (chmod(0755, $home_dir)) {
622 die("Can't set perms on $home_dir to 0755: $!");
623 }
624
625 unless (chown($uid, $gid, $home_dir)) {
626 die("Can't set owner of $home_dir to $uid/$gid: $!");
627 }
628 }
629
630 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
631 '/bin/bash');
632 auth_group_write($auth_group_file, $group, $gid, $user);
633
634 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
635 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
636
637 my $config = {
638 PidFile => $pid_file,
639 ScoreboardFile => $scoreboard_file,
640 SystemLog => $log_file,
641 TraceLog => $log_file,
642 Trace => 'binding:20 tls:20',
643
644 AuthUserFile => $auth_user_file,
645 AuthGroupFile => $auth_group_file,
646
647 IfModules => {
648 'mod_delay.c' => {
649 DelayEngine => 'off',
650 },
651
652 'mod_tls.c' => {
653 TLSEngine => 'on',
654 TLSLog => $log_file,
655 TLSRequired => 'on',
656 TLSRSACertificateFile => $cert_file,
657 TLSCACertificateFile => $ca_file,
658 },
659 },
660 };
661
662 my ($port, $config_user, $config_group) = config_write($config_file, $config);
663
664 # Open pipes, for use between the parent and child processes. Specifically,
665 # the child will indicate when it's done with its test by writing a message
666 # to the parent.
667 my ($rfh, $wfh);
668 unless (pipe($rfh, $wfh)) {
669 die("Can't open pipe: $!");
670 }
671
672 require Net::FTPSSL;
673
674 my $ex;
675
676 # Fork child
677 $self->handle_sigchld();
678 defined(my $pid = fork()) or die("Can't fork: $!");
679 if ($pid) {
680 eval {
681 # Give the server a chance to start up
682 sleep(2);
683
684 my $client = Net::FTPSSL->new('127.0.0.1',
685 Encryption => 'E',
686 Port => $port,
687 );
688
689 unless ($client) {
690 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
691 }
692
693 unless ($client->login($user, $passwd)) {
694 die("Can't login: " . $client->last_message());
695 }
696 };
697
698 if ($@) {
699 $ex = $@;
700 }
701
702 $wfh->print("done\n");
703 $wfh->flush();
704
705 } else {
706 eval { server_wait($config_file, $rfh) };
707 if ($@) {
708 warn($@);
709 exit 1;
710 }
711
712 exit 0;
713 }
714
715 # Stop server
716 server_stop($pid_file);
717
718 $self->assert_child_ok($pid);
719
720 if ($ex) {
721 test_append_logfile($log_file, $ex);
722 unlink($log_file);
723
724 die($ex);
725 }
726
727 unlink($log_file);
728 }
729
730 sub tls_login_dsa {
731 my $self = shift;
732 my $tmpdir = $self->{tmpdir};
733 my $setup = test_setup($tmpdir, 'tls');
734
735 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/dsa-server-cert.pem');
736 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/dsa-ca.pem');
737
738 my $config = {
739 PidFile => $setup->{pid_file},
740 ScoreboardFile => $setup->{scoreboard_file},
741 SystemLog => $setup->{log_file},
742 TraceLog => $setup->{log_file},
743 Trace => 'tls:20',
744
745 AuthUserFile => $setup->{auth_user_file},
746 AuthGroupFile => $setup->{auth_group_file},
747
748 IfModules => {
749 'mod_delay.c' => {
750 DelayEngine => 'off',
751 },
752
753 'mod_tls.c' => {
754 TLSEngine => 'on',
755 TLSLog => $setup->{log_file},
756 TLSRequired => 'on',
757 TLSDSACertificateFile => $cert_file,
758 TLSCACertificateFile => $ca_file,
759 TLSOptions => 'AllowWeakSecurity EnableDiags',
760
761 # Needed for DSA certs
762 TLSCipherSuite => 'ALL',
763 },
764 },
765 };
766
767 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
768 $config);
769
770 # Open pipes, for use between the parent and child processes. Specifically,
771 # the child will indicate when it's done with its test by writing a message
772 # to the parent.
773 my ($rfh, $wfh);
774 unless (pipe($rfh, $wfh)) {
775 die("Can't open pipe: $!");
776 }
777
778 require Net::FTPSSL;
779
780 my $ex;
781
782 # Fork child
783 $self->handle_sigchld();
784 defined(my $pid = fork()) or die("Can't fork: $!");
785 if ($pid) {
786 eval {
787 # Give the server a chance to start up
788 sleep(2);
789
790 my $client = Net::FTPSSL->new('127.0.0.1',
791 Encryption => 'E',
792 Port => $port,
793 );
794
795 unless ($client) {
796 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
797 }
798
799 unless ($client->login($setup->{user}, $setup->{passwd})) {
800 die("Can't login: " . $client->last_message());
801 }
802 };
803 if ($@) {
804 $ex = $@;
805 }
806
807 $wfh->print("done\n");
808 $wfh->flush();
809
810 } else {
811 eval { server_wait($setup->{config_file}, $rfh) };
812 if ($@) {
813 warn($@);
814 exit 1;
815 }
816
817 exit 0;
818 }
819
820 # Stop server
821 server_stop($setup->{pid_file});
822 $self->assert_child_ok($pid);
823
824 test_cleanup($setup->{log_file}, $ex);
825 }
826
827 sub tls_double_auth {
828 my $self = shift;
829 my $tmpdir = $self->{tmpdir};
830
831 my $config_file = "$tmpdir/tls.conf";
832 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
833 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
834
835 my $log_file = test_get_logfile();
836
837 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
838 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
839
840 my $user = 'proftpd';
841 my $passwd = 'test';
842 my $group = 'ftpd';
843 my $home_dir = File::Spec->rel2abs($tmpdir);
844 my $uid = 500;
845 my $gid = 500;
846
847 # Make sure that, if we're running as root, that the home directory has
848 # permissions/privs set for the account we create
849 if ($< == 0) {
850 unless (chmod(0755, $home_dir)) {
851 die("Can't set perms on $home_dir to 0755: $!");
852 }
853
854 unless (chown($uid, $gid, $home_dir)) {
855 die("Can't set owner of $home_dir to $uid/$gid: $!");
856 }
857 }
858
859 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
860 '/bin/bash');
861 auth_group_write($auth_group_file, $group, $gid, $user);
862
863 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
864 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
865
866 my $config = {
867 PidFile => $pid_file,
868 ScoreboardFile => $scoreboard_file,
869 SystemLog => $log_file,
870
871 AuthUserFile => $auth_user_file,
872 AuthGroupFile => $auth_group_file,
873
874 IfModules => {
875 'mod_delay.c' => {
876 DelayEngine => 'off',
877 },
878
879 'mod_tls.c' => {
880 TLSEngine => 'on',
881 TLSLog => $log_file,
882 TLSRequired => 'on',
883 TLSRSACertificateFile => $cert_file,
884 TLSCACertificateFile => $ca_file,
885 },
886 },
887 };
888
889 my ($port, $config_user, $config_group) = config_write($config_file, $config);
890
891 # Open pipes, for use between the parent and child processes. Specifically,
892 # the child will indicate when it's done with its test by writing a message
893 # to the parent.
894 my ($rfh, $wfh);
895 unless (pipe($rfh, $wfh)) {
896 die("Can't open pipe: $!");
897 }
898
899 require Net::FTPSSL;
900
901 my $ex;
902
903 # Fork child
904 $self->handle_sigchld();
905 defined(my $pid = fork()) or die("Can't fork: $!");
906 if ($pid) {
907 eval {
908 # Give the server a chance to start up
909 sleep(2);
910
911 my $client = Net::FTPSSL->new('127.0.0.1',
912 Encryption => 'E',
913 Port => $port,
914 );
915
916 unless ($client) {
917 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
918 }
919
920 unless ($client->login($user, $passwd)) {
921 die("Can't login: " . $client->last_message());
922 }
923
924 # Sending AUTH after we've established our SSL/TLS session should
925 # fail.
926 if ($client->auth()) {
927 die("Second AUTH succeeded unexpectedly");
928 }
929 };
930
931 if ($@) {
932 $ex = $@;
933 }
934
935 $wfh->print("done\n");
936 $wfh->flush();
937
938 } else {
939 eval { server_wait($config_file, $rfh) };
940 if ($@) {
941 warn($@);
942 exit 1;
943 }
944
945 exit 0;
946 }
947
948 # Stop server
949 server_stop($pid_file);
950
951 $self->assert_child_ok($pid);
952
953 if ($ex) {
954 test_append_logfile($log_file, $ex);
955 unlink($log_file);
956
957 die($ex);
958 }
959
960 unlink($log_file);
961 }
962
963 sub tls_login_pkcs12 {
964 my $self = shift;
965 my $tmpdir = $self->{tmpdir};
966
967 my $config_file = "$tmpdir/tls.conf";
968 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
969 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
970
971 my $log_file = test_get_logfile();
972
973 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
974 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
975
976 my $user = 'proftpd';
977 my $passwd = 'test';
978 my $group = 'ftpd';
979 my $home_dir = File::Spec->rel2abs($tmpdir);
980 my $uid = 500;
981 my $gid = 500;
982
983 # Make sure that, if we're running as root, that the home directory has
984 # permissions/privs set for the account we create
985 if ($< == 0) {
986 unless (chmod(0755, $home_dir)) {
987 die("Can't set perms on $home_dir to 0755: $!");
988 }
989
990 unless (chown($uid, $gid, $home_dir)) {
991 die("Can't set owner of $home_dir to $uid/$gid: $!");
992 }
993 }
994
995 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
996 '/bin/bash');
997 auth_group_write($auth_group_file, $group, $gid, $user);
998
999 my $pkcs12_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.p12');
1000 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1001
1002 my $config = {
1003 PidFile => $pid_file,
1004 ScoreboardFile => $scoreboard_file,
1005 SystemLog => $log_file,
1006
1007 AuthUserFile => $auth_user_file,
1008 AuthGroupFile => $auth_group_file,
1009
1010 IfModules => {
1011 'mod_delay.c' => {
1012 DelayEngine => 'off',
1013 },
1014
1015 'mod_tls.c' => {
1016 TLSEngine => 'on',
1017 TLSLog => $log_file,
1018 TLSRequired => 'on',
1019 TLSPKCS12File => $pkcs12_file,
1020 TLSCACertificateFile => $ca_file,
1021 },
1022 },
1023 };
1024
1025 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1026
1027 # Open pipes, for use between the parent and child processes. Specifically,
1028 # the child will indicate when it's done with its test by writing a message
1029 # to the parent.
1030 my ($rfh, $wfh);
1031 unless (pipe($rfh, $wfh)) {
1032 die("Can't open pipe: $!");
1033 }
1034
1035 require Net::FTPSSL;
1036
1037 my $ex;
1038
1039 # Fork child
1040 $self->handle_sigchld();
1041 defined(my $pid = fork()) or die("Can't fork: $!");
1042 if ($pid) {
1043 eval {
1044 # Give the server a chance to start up
1045 sleep(2);
1046
1047 my $client = Net::FTPSSL->new('127.0.0.1',
1048 Encryption => 'E',
1049 Port => $port,
1050 );
1051
1052 unless ($client) {
1053 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
1054 }
1055
1056 unless ($client->login($user, $passwd)) {
1057 die("Can't login: " . $client->last_message());
1058 }
1059 };
1060
1061 if ($@) {
1062 $ex = $@;
1063 }
1064
1065 $wfh->print("done\n");
1066 $wfh->flush();
1067
1068 } else {
1069 eval { server_wait($config_file, $rfh) };
1070 if ($@) {
1071 warn($@);
1072 exit 1;
1073 }
1074
1075 exit 0;
1076 }
1077
1078 # Stop server
1079 server_stop($pid_file);
1080
1081 $self->assert_child_ok($pid);
1082
1083 if ($ex) {
1084 test_append_logfile($log_file, $ex);
1085 unlink($log_file);
1086
1087 die($ex);
1088 }
1089
1090 unlink($log_file);
1091 }
1092
1093 sub tls_dh_ciphersuite {
1094 my $self = shift;
1095 my $tmpdir = $self->{tmpdir};
1096
1097 my $config_file = "$tmpdir/tls.conf";
1098 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
1099 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
1100
1101 my $log_file = test_get_logfile();
1102
1103 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
1104 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
1105
1106 my $user = 'proftpd';
1107 my $passwd = 'test';
1108 my $group = 'ftpd';
1109 my $home_dir = File::Spec->rel2abs($tmpdir);
1110 my $uid = 500;
1111 my $gid = 500;
1112
1113 # Make sure that, if we're running as root, that the home directory has
1114 # permissions/privs set for the account we create
1115 if ($< == 0) {
1116 unless (chmod(0755, $home_dir)) {
1117 die("Can't set perms on $home_dir to 0755: $!");
1118 }
1119
1120 unless (chown($uid, $gid, $home_dir)) {
1121 die("Can't set owner of $home_dir to $uid/$gid: $!");
1122 }
1123 }
1124
1125 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
1126 '/bin/bash');
1127 auth_group_write($auth_group_file, $group, $gid, $user);
1128
1129 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1130 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1131
1132 my $config = {
1133 PidFile => $pid_file,
1134 ScoreboardFile => $scoreboard_file,
1135 SystemLog => $log_file,
1136
1137 AuthUserFile => $auth_user_file,
1138 AuthGroupFile => $auth_group_file,
1139
1140 IfModules => {
1141 'mod_delay.c' => {
1142 DelayEngine => 'off',
1143 },
1144
1145 'mod_tls.c' => {
1146 TLSEngine => 'on',
1147 TLSLog => $log_file,
1148 TLSRequired => 'on',
1149 TLSRSACertificateFile => $cert_file,
1150 TLSCACertificateFile => $ca_file,
1151 },
1152 },
1153 };
1154
1155 my ($port, $config_user, $config_group) = config_write($config_file, $config);
1156
1157 # Open pipes, for use between the parent and child processes. Specifically,
1158 # the child will indicate when it's done with its test by writing a message
1159 # to the parent.
1160 my ($rfh, $wfh);
1161 unless (pipe($rfh, $wfh)) {
1162 die("Can't open pipe: $!");
1163 }
1164
1165 require Net::FTPSSL;
1166
1167 my $ex;
1168
1169 # Fork child
1170 $self->handle_sigchld();
1171 defined(my $pid = fork()) or die("Can't fork: $!");
1172 if ($pid) {
1173 eval {
1174 # Give the server a chance to start up
1175 sleep(2);
1176
1177 my $ssl_opts = {
1178 # Results in set_tmp_dh_callback() keylength of 1024 BITS
1179 SSL_cipher_list => 'DHE-RSA-AES256-SHA',
1180 SSL_ca_file => $ca_file,
1181 };
1182
1183 my $client = Net::FTPSSL->new('127.0.0.1',
1184 Encryption => 'E',
1185 Port => $port,
1186 SSL_Client_Certificate => $ssl_opts,
1187 );
1188
1189 unless ($client) {
1190 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
1191 }
1192
1193 unless ($client->login($user, $passwd)) {
1194 die("Can't login: " . $client->last_message());
1195 }
1196
1197 $client->quit();
1198 };
1199
1200 if ($@) {
1201 $ex = $@;
1202 }
1203
1204 $wfh->print("done\n");
1205 $wfh->flush();
1206
1207 } else {
1208 eval { server_wait($config_file, $rfh) };
1209 if ($@) {
1210 warn($@);
1211 exit 1;
1212 }
1213
1214 exit 0;
1215 }
1216
1217 # Stop server
1218 server_stop($pid_file);
1219
1220 $self->assert_child_ok($pid);
1221
1222 if ($ex) {
1223 test_append_logfile($log_file, $ex);
1224 unlink($log_file);
1225
1226 die($ex);
1227 }
1228
1229 unlink($log_file);
1230 }
1231
1232 sub tls_crl_file_ok {
1233 my $self = shift;
1234 my $tmpdir = $self->{tmpdir};
1235 my $setup = test_setup($tmpdir, 'tls');
1236
1237 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-server-cert.pem');
1238 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-client-cert.pem');
1239 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-ca.pem');
1240 my $crl_file = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-ca-revoked.pem');
1241
1242 my $config = {
1243 PidFile => $setup->{pid_file},
1244 ScoreboardFile => $setup->{scoreboard_file},
1245 SystemLog => $setup->{log_file},
1246 TraceLog => $setup->{log_file},
1247 Trace => 'tls:30',
1248
1249 AuthUserFile => $setup->{auth_user_file},
1250 AuthGroupFile => $setup->{auth_group_file},
1251 AuthOrder => 'mod_auth_file.c',
1252
1253 IfModules => {
1254 'mod_delay.c' => {
1255 DelayEngine => 'off',
1256 },
1257
1258 'mod_tls.c' => {
1259 TLSEngine => 'on',
1260 TLSLog => $setup->{log_file},
1261 TLSRequired => 'on',
1262 TLSRSACertificateFile => $server_cert,
1263 TLSCACertificateFile => $ca_cert,
1264
1265 # Verifying clients via CRLs only works when verification is
1266 # explicitly enabled.
1267 TLSCARevocationFile => $crl_file,
1268 TLSVerifyClient => 'on',
1269 },
1270 },
1271 };
1272
1273 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1274 $config);
1275
1276 # Open pipes, for use between the parent and child processes. Specifically,
1277 # the child will indicate when it's done with its test by writing a message
1278 # to the parent.
1279 my ($rfh, $wfh);
1280 unless (pipe($rfh, $wfh)) {
1281 die("Can't open pipe: $!");
1282 }
1283
1284 require Net::FTPSSL;
1285
1286 my $ex;
1287
1288 # Fork child
1289 $self->handle_sigchld();
1290 defined(my $pid = fork()) or die("Can't fork: $!");
1291 if ($pid) {
1292 eval {
1293 # Give the server a chance to start up
1294 sleep(2);
1295
1296 my $client;
1297
1298 eval {
1299 # IO::Socket::SSL options
1300 my $ssl_opts = {
1301 SSL_use_cert => 1,
1302 SSL_cert_file => $client_cert,
1303 SSL_key_file => $client_cert,
1304 SSL_ca_file => $ca_cert,
1305 };
1306
1307 $client = Net::FTPSSL->new('127.0.0.1',
1308 Croak => 1,
1309 Encryption => 'E',
1310 Port => $port,
1311 SSL_Client_Certificate => $ssl_opts,
1312 );
1313 };
1314
1315 my $ex = $@;
1316 unless ($ex) {
1317 die("SSL connection succeeded unexpectedly");
1318 }
1319
1320 my $errstr = IO::Socket::SSL::errstr();
1321
1322 my $expected = 'certificate revoked';
1323 $self->assert(qr/$expected/, $errstr,
1324 test_msg("Expected '$expected', got '$errstr'"));
1325 };
1326 if ($@) {
1327 $ex = $@;
1328 }
1329
1330 $wfh->print("done\n");
1331 $wfh->flush();
1332
1333 } else {
1334 eval { server_wait($setup->{config_file}, $rfh) };
1335 if ($@) {
1336 warn($@);
1337 exit 1;
1338 }
1339
1340 exit 0;
1341 }
1342
1343 # Stop server
1344 server_stop($setup->{pid_file});
1345 $self->assert_child_ok($pid);
1346
1347 test_cleanup($setup->{log_file}, $ex);
1348 }
1349
1350 sub tls_crl_file_other_ca_bug4468 {
1351 my $self = shift;
1352 my $tmpdir = $self->{tmpdir};
1353 my $setup = test_setup($tmpdir, 'tls');
1354
1355 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1356 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
1357 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1358 my $crl_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-crl-empty.pem');
1359
1360 my $config = {
1361 PidFile => $setup->{pid_file},
1362 ScoreboardFile => $setup->{scoreboard_file},
1363 SystemLog => $setup->{log_file},
1364 TraceLog => $setup->{log_file},
1365 Trace => 'tls:30',
1366
1367 AuthUserFile => $setup->{auth_user_file},
1368 AuthGroupFile => $setup->{auth_group_file},
1369 AuthOrder => 'mod_auth_file.c',
1370
1371 IfModules => {
1372 'mod_delay.c' => {
1373 DelayEngine => 'off',
1374 },
1375
1376 'mod_tls.c' => {
1377 TLSEngine => 'on',
1378 TLSLog => $setup->{log_file},
1379 TLSRequired => 'on',
1380 TLSRSACertificateFile => $server_cert,
1381 TLSCACertificateFile => $ca_cert,
1382
1383 # Verifying clients via CRLs only works when verification is
1384 # explicitly enabled.
1385 TLSCARevocationFile => $crl_file,
1386 TLSVerifyClient => 'on',
1387 },
1388 },
1389 };
1390
1391 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1392 $config);
1393
1394 # Open pipes, for use between the parent and child processes. Specifically,
1395 # the child will indicate when it's done with its test by writing a message
1396 # to the parent.
1397 my ($rfh, $wfh);
1398 unless (pipe($rfh, $wfh)) {
1399 die("Can't open pipe: $!");
1400 }
1401
1402 require Net::FTPSSL;
1403
1404 my $ex;
1405
1406 # Fork child
1407 $self->handle_sigchld();
1408 defined(my $pid = fork()) or die("Can't fork: $!");
1409 if ($pid) {
1410 eval {
1411 # Give the server a chance to start up
1412 sleep(2);
1413
1414 my $client;
1415
1416 # IO::Socket::SSL options
1417 my $ssl_opts = {
1418 SSL_use_cert => 1,
1419 SSL_cert_file => $client_cert,
1420 SSL_key_file => $client_cert,
1421 SSL_ca_file => $ca_cert,
1422 };
1423
1424 $client = Net::FTPSSL->new('127.0.0.1',
1425 Croak => 1,
1426 Encryption => 'E',
1427 Port => $port,
1428 SSL_Client_Certificate => $ssl_opts,
1429 );
1430
1431 $client->login($setup->{user}, $setup->{passwd});
1432 $client->quit();
1433 };
1434 if ($@) {
1435 $ex = $@;
1436 }
1437
1438 $wfh->print("done\n");
1439 $wfh->flush();
1440
1441 } else {
1442 eval { server_wait($setup->{config_file}, $rfh) };
1443 if ($@) {
1444 warn($@);
1445 exit 1;
1446 }
1447
1448 exit 0;
1449 }
1450
1451 # Stop server
1452 server_stop($setup->{pid_file});
1453 $self->assert_child_ok($pid);
1454
1455 test_cleanup($setup->{log_file}, $ex);
1456 }
1457
1458 sub tls_crl_file_multiple_cas_crls_issue1960 {
1459 my $self = shift;
1460 my $tmpdir = $self->{tmpdir};
1461 my $setup = test_setup($tmpdir, 'tls');
1462
1463 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-intermediate-server.pem');
1464 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-intermediate-client.pem');
1465 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-intermediate-cas.pem');
1466 my $crl_file = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-intermediate-crls.pem');
1467
1468 my $config = {
1469 PidFile => $setup->{pid_file},
1470 ScoreboardFile => $setup->{scoreboard_file},
1471 SystemLog => $setup->{log_file},
1472 TraceLog => $setup->{log_file},
1473 Trace => 'tls:30',
1474
1475 AuthUserFile => $setup->{auth_user_file},
1476 AuthGroupFile => $setup->{auth_group_file},
1477 AuthOrder => 'mod_auth_file.c',
1478
1479 IfModules => {
1480 'mod_delay.c' => {
1481 DelayEngine => 'off',
1482 },
1483
1484 'mod_tls.c' => {
1485 TLSEngine => 'on',
1486 TLSLog => $setup->{log_file},
1487 TLSRequired => 'on',
1488 TLSRSACertificateFile => $server_cert,
1489 TLSCACertificateFile => $ca_cert,
1490
1491 # Verifying clients via CRLs only works when verification is
1492 # explicitly enabled.
1493 TLSCARevocationFile => $crl_file,
1494 TLSVerifyClient => 'on',
1495 },
1496 },
1497 };
1498
1499 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1500 $config);
1501
1502 # Open pipes, for use between the parent and child processes. Specifically,
1503 # the child will indicate when it's done with its test by writing a message
1504 # to the parent.
1505 my ($rfh, $wfh);
1506 unless (pipe($rfh, $wfh)) {
1507 die("Can't open pipe: $!");
1508 }
1509
1510 require Net::FTPSSL;
1511
1512 my $ex;
1513
1514 # Fork child
1515 $self->handle_sigchld();
1516 defined(my $pid = fork()) or die("Can't fork: $!");
1517 if ($pid) {
1518 eval {
1519 # Give the server a chance to start up
1520 sleep(2);
1521
1522 my $client;
1523
1524 # IO::Socket::SSL options
1525 my $ssl_opts = {
1526 SSL_use_cert => 1,
1527 SSL_cert_file => $client_cert,
1528 SSL_key_file => $client_cert,
1529 SSL_ca_file => $ca_cert,
1530 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
1531
1532 # Disable verification of the CN in the server cert
1533 SSL_verifycn_scheme => 'none',
1534 };
1535
1536 $client = Net::FTPSSL->new('127.0.0.1',
1537 Croak => 1,
1538 Encryption => 'E',
1539 Port => $port,
1540 SSL_Client_Certificate => $ssl_opts,
1541 );
1542 if ($client) {
1543 die("TLS handshake with revoked client cert succeeded unexpectedly");
1544 }
1545 };
1546 if ($@) {
1547 $ex = $@;
1548 }
1549
1550 $wfh->print("done\n");
1551 $wfh->flush();
1552
1553 } else {
1554 eval { server_wait($setup->{config_file}, $rfh) };
1555 if ($@) {
1556 warn($@);
1557 exit 1;
1558 }
1559
1560 exit 0;
1561 }
1562
1563 # Stop server
1564 server_stop($setup->{pid_file});
1565 $self->assert_child_ok($pid);
1566
1567 if ($ex) {
1568 $self->assert(qr/certificate revoked/, $ex,
1569 test_msg("Did not see expected 'certificate revoked' error"));
1570 $ex = undef;
1571 }
1572
1573 test_cleanup($setup->{log_file}, $ex);
1574 }
1575
1576 sub tls_login_with_sni_issue850 {
1577 my $self = shift;
1578 my $tmpdir = $self->{tmpdir};
1579 my $setup = test_setup($tmpdir, 'tls');
1580
1581 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1582 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1583
1584 my $config = {
1585 PidFile => $setup->{pid_file},
1586 ScoreboardFile => $setup->{scoreboard_file},
1587 SystemLog => $setup->{log_file},
1588 TraceLog => $setup->{log_file},
1589 Trace => 'binding:30 tls:30',
1590
1591 AuthUserFile => $setup->{auth_user_file},
1592 AuthGroupFile => $setup->{auth_group_file},
1593 AuthOrder => 'mod_auth_file.c',
1594
1595 IfModules => {
1596 'mod_delay.c' => {
1597 DelayEngine => 'off',
1598 },
1599 },
1600
1601 Limit => {
1602 LOGIN => {
1603 DenyAll => '',
1604 }
1605 },
1606 };
1607
1608 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1609 $config);
1610
1611 my $host = 'castaglia';
1612
1613 # Configure a name-based <VirtualHost> for our testing.
1614 if (open(my $fh, ">> $setup->{config_file}")) {
1615 # NOTE: In the case of multiple <VirtualHost> configs on the same
1616 # IP address/port, the _last_ one defined is usually selected for
1617 # a client connecting to that exact address/port. Surprising? Maybe
1618 # it should be the first matching <VirtualHost> config? Or perhaps the
1619 # "last one wins" approach is less surprising.
1620 #
1621 # This happens because colliding ipbinds are added to the _head_ of
1622 # the list; the last one added is thus first in the list. And we
1623 # return the first matching ipbind in pr_ipbind_find().
1624 #
1625 # As of Issue#1369, we also use first-match-wins.
1626
1627 print $fh <<EOC;
1628 <VirtualHost 127.0.0.1>
1629 ServerName "Alias-based ProFTPD"
1630 ServerAlias $host
1631 Port $port
1632
1633 AuthUserFile $setup->{auth_user_file}
1634 AuthGroupFile $setup->{auth_group_file}
1635 AuthOrder mod_auth_file.c
1636
1637 <IfModule mod_delay.c>
1638 DelayEngine off
1639 </IfModule>
1640 </VirtualHost>
1641
1642 <VirtualHost 127.0.0.1>
1643 ServerName "Name-based ProFTPD"
1644 ServerAlias default
1645 Port $port
1646
1647 AuthUserFile $setup->{auth_user_file}
1648 AuthGroupFile $setup->{auth_group_file}
1649 AuthOrder mod_auth_file.c
1650
1651 <IfModule mod_delay.c>
1652 DelayEngine off
1653 </IfModule>
1654
1655 <IfModule mod_tls.c>
1656 TLSEngine on
1657 TLSLog $setup->{log_file}
1658 TLSOptions EnableDiags
1659 TLSRequired on
1660 TLSRSACertificateFile $cert_file
1661 TLSCACertificateFile $ca_file
1662 </IfModule>
1663 </VirtualHost>
1664 EOC
1665 unless (close($fh)) {
1666 die("Can't write $setup->{config_file}: $!");
1667 }
1668
1669 } else {
1670 die("Can't open $setup->{config_file}: $!");
1671 }
1672
1673 # Open pipes, for use between the parent and child processes. Specifically,
1674 # the child will indicate when it's done with its test by writing a message
1675 # to the parent.
1676 my ($rfh, $wfh);
1677 unless (pipe($rfh, $wfh)) {
1678 die("Can't open pipe: $!");
1679 }
1680
1681 require Net::FTPSSL;
1682
1683 my $ex;
1684
1685 # Fork child
1686 $self->handle_sigchld();
1687 defined(my $pid = fork()) or die("Can't fork: $!");
1688 if ($pid) {
1689 eval {
1690 # Give the server a chance to start up
1691 sleep(2);
1692
1693 my $ssl_opts = {
1694 Encryption => 'E',
1695 Port => $port,
1696 SSL_ca_file => $ca_file,
1697 SSL_hostname => $host,
1698 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
1699 };
1700
1701 if ($ENV{TEST_VERBOSE}) {
1702 $ssl_opts->{Debug} = 2;
1703 }
1704
1705 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
1706
1707 # The named vhost does not have any certs configured, so the handshake
1708 # should fail.
1709 if ($client) {
1710 die("Connected to FTPS server unexpectedly");
1711 }
1712
1713 my $errstr = IO::Socket::SSL::errstr();
1714 if ($errstr) {
1715 if ($ENV{TEST_VERBOSE}) {
1716 print STDERR "# TLS Handshake failed: $errstr\n";
1717 }
1718
1719 my $expected = 'handshake failure|unrecognized name';
1720 $self->assert(qr/$expected/, $errstr,
1721 test_msg("Expected TLS error '$expected', got '$errstr'"));
1722
1723 } else {
1724 my $errstr = $Net::FTPSSL::ERRSTR;
1725
1726 if ($ENV{TEST_VERBOSE}) {
1727 print STDERR "# $errstr\n";
1728 }
1729
1730 # Since the vhost to which we connected (first match wins) does not
1731 # have TLSEngine enabled, the AUTH command will be rejected.
1732 my $expected = '500 AUTH not understood';
1733 $self->assert(qr/$expected/, $errstr,
1734 test_msg("Expected AUTH error '$expected', got '$errstr'"));
1735 }
1736 };
1737 if ($@) {
1738 $ex = $@;
1739 }
1740
1741 $wfh->print("done\n");
1742 $wfh->flush();
1743
1744 } else {
1745 eval { server_wait($setup->{config_file}, $rfh) };
1746 if ($@) {
1747 warn($@);
1748 exit 1;
1749 }
1750
1751 exit 0;
1752 }
1753
1754 # Stop server
1755 server_stop($setup->{pid_file});
1756 $self->assert_child_ok($pid);
1757
1758 test_cleanup($setup->{log_file}, $ex);
1759 }
1760
1761 sub tls_login_with_sni_tlsengine_off_issue850 {
1762 my $self = shift;
1763 my $tmpdir = $self->{tmpdir};
1764 my $setup = test_setup($tmpdir, 'tls');
1765
1766 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1767 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1768
1769 my $config = {
1770 PidFile => $setup->{pid_file},
1771 ScoreboardFile => $setup->{scoreboard_file},
1772 SystemLog => $setup->{log_file},
1773 TraceLog => $setup->{log_file},
1774 Trace => 'tls:20',
1775
1776 AuthUserFile => $setup->{auth_user_file},
1777 AuthGroupFile => $setup->{auth_group_file},
1778
1779 IfModules => {
1780 'mod_delay.c' => {
1781 DelayEngine => 'off',
1782 },
1783 },
1784
1785 Limit => {
1786 LOGIN => {
1787 DenyAll => '',
1788 },
1789 },
1790 };
1791
1792 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1793 $config);
1794
1795 my $host = 'castaglia';
1796
1797 # Configure a name-based <VirtualHost> for our testing.
1798 if (open(my $fh, ">> $setup->{config_file}")) {
1799 print $fh <<EOC;
1800 <VirtualHost 127.0.0.1>
1801 ServerName "Alias-based ProFTPD"
1802 ServerAlias $host
1803 Port $port
1804
1805 AuthUserFile $setup->{auth_user_file}
1806 AuthGroupFile $setup->{auth_group_file}
1807 AuthOrder mod_auth_file.c
1808 TransferLog none
1809 WtmpLog off
1810
1811 <IfModule mod_delay.c>
1812 DelayEngine off
1813 </IfModule>
1814
1815 <IfModule mod_tls.c>
1816 TLSEngine off
1817 TLSOptions EnableDiags
1818 TLSRSACertificateFile $cert_file
1819 TLSCACertificateFile $ca_file
1820 </IfModule>
1821
1822 <Limit LOGIN>
1823 DenyUser $setup->{user}
1824 </Limit>
1825 </VirtualHost>
1826
1827 <VirtualHost 127.0.0.1>
1828 ServerName "Name-based ProFTPD"
1829 ServerAlias default
1830 Port $port
1831
1832 AuthUserFile $setup->{auth_user_file}
1833 AuthGroupFile $setup->{auth_group_file}
1834 AuthOrder mod_auth_file.c
1835 TransferLog none
1836 WtmpLog off
1837
1838 <IfModule mod_delay.c>
1839 DelayEngine off
1840 </IfModule>
1841
1842 <IfModule mod_tls.c>
1843 TLSEngine on
1844 TLSLog $setup->{log_file}
1845 TLSOptions EnableDiags
1846 TLSRequired on
1847 TLSRSACertificateFile $cert_file
1848 TLSCACertificateFile $ca_file
1849 </IfModule>
1850 </VirtualHost>
1851 EOC
1852 unless (close($fh)) {
1853 die("Can't write $setup->{config_file}: $!");
1854 }
1855
1856 } else {
1857 die("Can't open $setup->{config_file}: $!");
1858 }
1859
1860 # Open pipes, for use between the parent and child processes. Specifically,
1861 # the child will indicate when it's done with its test by writing a message
1862 # to the parent.
1863 my ($rfh, $wfh);
1864 unless (pipe($rfh, $wfh)) {
1865 die("Can't open pipe: $!");
1866 }
1867
1868 require Net::FTPSSL;
1869
1870 my $ex;
1871
1872 # Fork child
1873 $self->handle_sigchld();
1874 defined(my $pid = fork()) or die("Can't fork: $!");
1875 if ($pid) {
1876 eval {
1877 # Give the server a chance to start up
1878 sleep(2);
1879
1880 my $ssl_opts = {
1881 Encryption => 'E',
1882 Port => $port,
1883 SSL_ca_file => $ca_file,
1884 SSL_hostname => $host,
1885 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
1886 };
1887
1888 if ($ENV{TEST_VERBOSE}) {
1889 $ssl_opts->{Debug} = 2;
1890 }
1891
1892 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
1893
1894 # The named vhost has mod_tls disabled, so the handshake should fail.
1895 if ($client) {
1896 die("Connected to FTPS server unexpectedly");
1897 }
1898
1899 my $errstr = IO::Socket::SSL::errstr();
1900 if ($errstr) {
1901 if ($ENV{TEST_VERBOSE}) {
1902 print STDERR "# TLS Handshake failed: $errstr\n";
1903 }
1904
1905 my $expected = 'handshake failure|unrecognized name';
1906 $self->assert(qr/$expected/, $errstr,
1907 test_msg("Expected TLS error '$expected', got '$errstr'"));
1908
1909 } else {
1910 my $errstr = $Net::FTPSSL::ERRSTR;
1911
1912 if ($ENV{TEST_VERBOSE}) {
1913 print STDERR "# $errstr\n";
1914 }
1915
1916 # Since the vhost to which we connected (first match wins) does not
1917 # have TLSEngine enabled, the AUTH command will be rejected.
1918 my $expected = '500 AUTH not understood';
1919 $self->assert(qr/$expected/, $errstr,
1920 test_msg("Expected AUTH error '$expected', got '$errstr'"));
1921 }
1922 };
1923 if ($@) {
1924 $ex = $@;
1925 }
1926
1927 $wfh->print("done\n");
1928 $wfh->flush();
1929
1930 } else {
1931 eval { server_wait($setup->{config_file}, $rfh) };
1932 if ($@) {
1933 warn($@);
1934 exit 1;
1935 }
1936
1937 exit 0;
1938 }
1939
1940 # Stop server
1941 server_stop($setup->{pid_file});
1942 $self->assert_child_ok($pid);
1943
1944 test_cleanup($setup->{log_file}, $ex);
1945 }
1946
1947 sub tls_login_with_sni_unknown_host_issue850 {
1948 my $self = shift;
1949 my $tmpdir = $self->{tmpdir};
1950 my $setup = test_setup($tmpdir, 'tls');
1951
1952 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
1953 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
1954
1955 my $config = {
1956 PidFile => $setup->{pid_file},
1957 ScoreboardFile => $setup->{scoreboard_file},
1958 SystemLog => $setup->{log_file},
1959 TraceLog => $setup->{log_file},
1960 Trace => 'binding:30 tls:20',
1961
1962 AuthUserFile => $setup->{auth_user_file},
1963 AuthGroupFile => $setup->{auth_group_file},
1964
1965 IfModules => {
1966 'mod_delay.c' => {
1967 DelayEngine => 'off',
1968 },
1969 },
1970
1971 Limit => {
1972 LOGIN => {
1973 DenyAll => '',
1974 }
1975 },
1976 };
1977
1978 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
1979 $config);
1980
1981 my $host = 'castaglia';
1982
1983 # Configure a name-based <VirtualHost> for our testing.
1984 if (open(my $fh, ">> $setup->{config_file}")) {
1985 print $fh <<EOC;
1986 <VirtualHost 127.0.0.1>
1987 ServerName "Name-based ProFTPD"
1988 ServerAlias ftp.example.com
1989 Port $port
1990
1991 AuthUserFile $setup->{auth_user_file}
1992 AuthGroupFile $setup->{auth_group_file}
1993 AuthOrder mod_auth_file.c
1994
1995 <IfModule mod_delay.c>
1996 DelayEngine off
1997 </IfModule>
1998
1999 <IfModule mod_tls.c>
2000 TLSEngine on
2001 TLSRSACertificateFile $cert_file
2002 TLSCACertificateFile $ca_file
2003 TLSOptions EnableDiags
2004 </IfModule>
2005 </VirtualHost>
2006 EOC
2007 unless (close($fh)) {
2008 die("Can't write $setup->{config_file}: $!");
2009 }
2010
2011 } else {
2012 die("Can't open $setup->{config_file}: $!");
2013 }
2014
2015 # Open pipes, for use between the parent and child processes. Specifically,
2016 # the child will indicate when it's done with its test by writing a message
2017 # to the parent.
2018 my ($rfh, $wfh);
2019 unless (pipe($rfh, $wfh)) {
2020 die("Can't open pipe: $!");
2021 }
2022
2023 require Net::FTPSSL;
2024
2025 my $ex;
2026
2027 # Fork child
2028 $self->handle_sigchld();
2029 defined(my $pid = fork()) or die("Can't fork: $!");
2030 if ($pid) {
2031 eval {
2032 # Give the server a chance to start up
2033 sleep(2);
2034
2035 my $ssl_opts = {
2036 Encryption => 'E',
2037 Port => $port,
2038 SSL_ca_file => $ca_file,
2039 SSL_hostname => $host,
2040 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
2041 };
2042
2043 if ($ENV{TEST_VERBOSE}) {
2044 $ssl_opts->{Debug} = 2;
2045 }
2046
2047 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
2048
2049 # The named vhost has does not exist, so the handshake should fail.
2050 if ($client) {
2051 die("Connected to FTPS server unexpectedly");
2052 }
2053
2054 my $errstr = IO::Socket::SSL::errstr();
2055 if ($ENV{TEST_VERBOSE}) {
2056 print STDERR "# TLS Handshake failed: $errstr\n";
2057 }
2058
2059 my $expected = 'handshake failure|unrecognized name';
2060 $self->assert(qr/$expected/, $errstr,
2061 test_msg("Expected '$expected', got '$errstr'"));
2062 };
2063 if ($@) {
2064 $ex = $@;
2065 }
2066
2067 $wfh->print("done\n");
2068 $wfh->flush();
2069
2070 } else {
2071 eval { server_wait($setup->{config_file}, $rfh) };
2072 if ($@) {
2073 warn($@);
2074 exit 1;
2075 }
2076
2077 exit 0;
2078 }
2079
2080 # Stop server
2081 server_stop($setup->{pid_file});
2082 $self->assert_child_ok($pid);
2083
2084 test_cleanup($setup->{log_file}, $ex);
2085 }
2086
2087 sub tls_login_with_sni_unknown_host_no_serveraliases_issue850 {
2088 my $self = shift;
2089 my $tmpdir = $self->{tmpdir};
2090 my $setup = test_setup($tmpdir, 'tls');
2091
2092 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
2093 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
2094
2095 my $config = {
2096 PidFile => $setup->{pid_file},
2097 ScoreboardFile => $setup->{scoreboard_file},
2098 SystemLog => $setup->{log_file},
2099 TraceLog => $setup->{log_file},
2100 Trace => 'binding:30 tls:20',
2101
2102 AuthUserFile => $setup->{auth_user_file},
2103 AuthGroupFile => $setup->{auth_group_file},
2104
2105 IfModules => {
2106 'mod_delay.c' => {
2107 DelayEngine => 'off',
2108 },
2109
2110 'mod_tls.c' => {
2111 TLSEngine => 'on',
2112 TLSLog => $setup->{log_file},
2113 TLSOptions => 'EnableDiags',
2114 TLSRequired => 'on',
2115 TLSRSACertificateFile => $cert_file,
2116 TLSCACertificateFile => $ca_file,
2117 },
2118 },
2119 };
2120
2121 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2122 $config);
2123
2124 # Open pipes, for use between the parent and child processes. Specifically,
2125 # the child will indicate when it's done with its test by writing a message
2126 # to the parent.
2127 my ($rfh, $wfh);
2128 unless (pipe($rfh, $wfh)) {
2129 die("Can't open pipe: $!");
2130 }
2131
2132 require Net::FTPSSL;
2133
2134 my $ex;
2135
2136 # Fork child
2137 $self->handle_sigchld();
2138 defined(my $pid = fork()) or die("Can't fork: $!");
2139 if ($pid) {
2140 eval {
2141 # Give the server a chance to start up
2142 sleep(2);
2143
2144 my $host = 'castaglia';
2145
2146 my $ssl_opts = {
2147 Encryption => 'E',
2148 Port => $port,
2149 SSL_ca_file => $ca_file,
2150 SSL_hostname => $host,
2151 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
2152 };
2153
2154 if ($ENV{TEST_VERBOSE}) {
2155 $ssl_opts->{Debug} = 2;
2156 }
2157
2158 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
2159
2160 # The named vhost has does not exist, but we have no ServerAliases at
2161 # all, so the handshake should succeed.
2162 unless ($client) {
2163 my $errstr = IO::Socket::SSL::errstr();
2164 die("Failed to connect to FTPS server: $errstr");
2165 }
2166
2167 unless ($client->login($setup->{user}, $setup->{passwd})) {
2168 die("Can't login: " . $client->last_message());
2169 }
2170
2171 $client->quit();
2172 };
2173 if ($@) {
2174 $ex = $@;
2175 }
2176
2177 $wfh->print("done\n");
2178 $wfh->flush();
2179
2180 } else {
2181 eval { server_wait($setup->{config_file}, $rfh) };
2182 if ($@) {
2183 warn($@);
2184 exit 1;
2185 }
2186
2187 exit 0;
2188 }
2189
2190 # Stop server
2191 server_stop($setup->{pid_file});
2192 $self->assert_child_ok($pid);
2193
2194 test_cleanup($setup->{log_file}, $ex);
2195 }
2196
2197 sub tls_login_with_sni_different_certs_issue850 {
2198 my $self = shift;
2199 my $tmpdir = $self->{tmpdir};
2200 my $setup = test_setup($tmpdir, 'tls');
2201
2202 my $ec_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-server-cert.pem');
2203 my $ec_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-ca.pem');
2204
2205 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
2206 # is working as expected.
2207 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
2208 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
2209
2210 my $config = {
2211 PidFile => $setup->{pid_file},
2212 ScoreboardFile => $setup->{scoreboard_file},
2213 SystemLog => $setup->{log_file},
2214 TraceLog => $setup->{log_file},
2215 Trace => 'binding:30 tls:20',
2216
2217 AuthUserFile => $setup->{auth_user_file},
2218 AuthGroupFile => $setup->{auth_group_file},
2219
2220 IfModules => {
2221 'mod_delay.c' => {
2222 DelayEngine => 'off',
2223 },
2224 },
2225 };
2226
2227 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2228 $config);
2229
2230 my $host = 'castaglia';
2231
2232 # Configure a name-based <VirtualHost> for our testing.
2233 if (open(my $fh, ">> $setup->{config_file}")) {
2234 print $fh <<EOC;
2235 <VirtualHost 127.0.0.1>
2236 ServerName "Alias-based ProFTPD"
2237 ServerAlias $host
2238 Port $port
2239
2240 AuthUserFile $setup->{auth_user_file}
2241 AuthGroupFile $setup->{auth_group_file}
2242 AuthOrder mod_auth_file.c
2243 TransferLog none
2244 WtmpLog off
2245
2246 <IfModule mod_delay.c>
2247 DelayEngine off
2248 </IfModule>
2249
2250 <IfModule mod_tls.c>
2251 TLSEngine on
2252 TLSLog $setup->{log_file}
2253 TLSRequired on
2254 TLSRSACertificateFile $rsa_cert_file
2255 TLSCACertificateFile $rsa_ca_file
2256 TLSOptions EnableDiags
2257 TLSProtocol TLSv1.0
2258 </IfModule>
2259
2260 <Limit LOGIN>
2261 DenyUser $setup->{user}
2262 </Limit>
2263 </VirtualHost>
2264
2265 <VirtualHost 127.0.0.1>
2266 ServerName "Name-based ProFTPD"
2267 ServerAlias default
2268 Port $port
2269
2270 AuthUserFile $setup->{auth_user_file}
2271 AuthGroupFile $setup->{auth_group_file}
2272 AuthOrder mod_auth_file.c
2273 TransferLog none
2274 WtmpLog off
2275
2276 <IfModule mod_delay.c>
2277 DelayEngine off
2278 </IfModule>
2279
2280 <IfModule mod_tls.c>
2281 TLSEngine on
2282 TLSLog $setup->{log_file}
2283 TLSRequired on
2284 TLSECCertificateFile $ec_cert_file
2285 TLSCACertificateFile $ec_ca_file
2286 TLSOptions EnableDiags
2287 TLSProtocol TLSv1.0
2288 </IfModule>
2289 </VirtualHost>
2290 EOC
2291 unless (close($fh)) {
2292 die("Can't write $setup->{config_file}: $!");
2293 }
2294
2295 } else {
2296 die("Can't open $setup->{config_file}: $!");
2297 }
2298
2299 # Open pipes, for use between the parent and child processes. Specifically,
2300 # the child will indicate when it's done with its test by writing a message
2301 # to the parent.
2302 my ($rfh, $wfh);
2303 unless (pipe($rfh, $wfh)) {
2304 die("Can't open pipe: $!");
2305 }
2306
2307 require Net::FTPSSL;
2308
2309 my $ex;
2310
2311 # Fork child
2312 $self->handle_sigchld();
2313 defined(my $pid = fork()) or die("Can't fork: $!");
2314 if ($pid) {
2315 eval {
2316 # Give the server a chance to start up
2317 sleep(2);
2318
2319 my $ssl_opts = {
2320 Encryption => 'E',
2321 Port => $port,
2322 SSL_ca_file => $rsa_ca_file,
2323 SSL_hostname => $host,
2324 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
2325 };
2326
2327 if ($ENV{TEST_VERBOSE}) {
2328 $ssl_opts->{Debug} = 2;
2329 }
2330
2331 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
2332 unless ($client) {
2333 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
2334 }
2335
2336 if ($client->login($setup->{user}, $setup->{passwd})) {
2337 die("Login succeeded unexpectedly");
2338 }
2339
2340 $client->quit();
2341 };
2342 if ($@) {
2343 $ex = $@;
2344 }
2345
2346 $wfh->print("done\n");
2347 $wfh->flush();
2348
2349 } else {
2350 eval { server_wait($setup->{config_file}, $rfh) };
2351 if ($@) {
2352 warn($@);
2353 exit 1;
2354 }
2355
2356 exit 0;
2357 }
2358
2359 # Stop server
2360 server_stop($setup->{pid_file});
2361 $self->assert_child_ok($pid);
2362
2363 test_cleanup($setup->{log_file}, $ex);
2364 }
2365
2366 sub tls_login_with_sni_ignored_issue850 {
2367 my $self = shift;
2368 my $tmpdir = $self->{tmpdir};
2369 my $setup = test_setup($tmpdir, 'tls');
2370
2371 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
2372 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
2373
2374 my $config = {
2375 PidFile => $setup->{pid_file},
2376 ScoreboardFile => $setup->{scoreboard_file},
2377 SystemLog => $setup->{log_file},
2378 TraceLog => $setup->{log_file},
2379 Trace => 'binding:30 tls:20',
2380
2381 AuthUserFile => $setup->{auth_user_file},
2382 AuthGroupFile => $setup->{auth_group_file},
2383
2384 IfModules => {
2385 'mod_delay.c' => {
2386 DelayEngine => 'off',
2387 },
2388 },
2389 };
2390
2391 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2392 $config);
2393
2394 my $host = 'castaglia';
2395
2396 # Configure a name-based <VirtualHost> for our testing; remember that first
2397 # IP/port match wins, then first SNI match.
2398 if (open(my $fh, ">> $setup->{config_file}")) {
2399 print $fh <<EOC;
2400 <VirtualHost 127.0.0.1>
2401 ServerName "Name-based ProFTPD"
2402 ServerAlias $host
2403 Port $port
2404
2405 AuthUserFile $setup->{auth_user_file}
2406 AuthGroupFile $setup->{auth_group_file}
2407 AuthOrder mod_auth_file.c
2408 TransferLog none
2409 WtmpLog off
2410
2411 <IfModule mod_delay.c>
2412 DelayEngine off
2413 </IfModule>
2414
2415 <IfModule mod_tls.c>
2416 TLSEngine on
2417 TLSLog $setup->{log_file}
2418 TLSRequired on
2419 TLSRSACertificateFile $cert_file
2420 TLSCACertificateFile $ca_file
2421 TLSOptions EnableDiags IgnoreSNI
2422 </IfModule>
2423 </VirtualHost>
2424
2425 <VirtualHost 127.0.0.1>
2426 ServerName "Alias-based ProFTPD"
2427 ServerAlias default
2428 Port $port
2429
2430 AuthUserFile $setup->{auth_user_file}
2431 AuthGroupFile $setup->{auth_group_file}
2432 AuthOrder mod_auth_file.c
2433 TransferLog none
2434 WtmpLog off
2435
2436 <IfModule mod_delay.c>
2437 DelayEngine off
2438 </IfModule>
2439
2440 <Limit LOGIN>
2441 DenyAll
2442 </Limit>
2443 </VirtualHost>
2444 EOC
2445 unless (close($fh)) {
2446 die("Can't write $setup->{config_file}: $!");
2447 }
2448
2449 } else {
2450 die("Can't open $setup->{config_file}: $!");
2451 }
2452
2453 # Open pipes, for use between the parent and child processes. Specifically,
2454 # the child will indicate when it's done with its test by writing a message
2455 # to the parent.
2456 my ($rfh, $wfh);
2457 unless (pipe($rfh, $wfh)) {
2458 die("Can't open pipe: $!");
2459 }
2460
2461 require Net::FTPSSL;
2462
2463 my $ex;
2464
2465 # Fork child
2466 $self->handle_sigchld();
2467 defined(my $pid = fork()) or die("Can't fork: $!");
2468 if ($pid) {
2469 eval {
2470 # Give the server a chance to start up
2471 sleep(2);
2472
2473 my $ssl_opts = {
2474 Encryption => 'E',
2475 Port => $port,
2476 SSL_hostname => $host,
2477 };
2478
2479 if ($ENV{TEST_VERBOSE}) {
2480 $ssl_opts->{Debug} = 2;
2481 }
2482
2483 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
2484 unless ($client) {
2485 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
2486 }
2487
2488 unless ($client->login($setup->{user}, $setup->{passwd})) {
2489 die("Can't login: " . $client->last_message());
2490 }
2491
2492 $client->quit();
2493 };
2494 if ($@) {
2495 $ex = $@;
2496 }
2497
2498 $wfh->print("done\n");
2499 $wfh->flush();
2500
2501 } else {
2502 eval { server_wait($setup->{config_file}, $rfh) };
2503 if ($@) {
2504 warn($@);
2505 exit 1;
2506 }
2507
2508 exit 0;
2509 }
2510
2511 # Stop server
2512 server_stop($setup->{pid_file});
2513 $self->assert_child_ok($pid);
2514
2515 test_cleanup($setup->{log_file}, $ex);
2516 }
2517
2518 sub tls_login_with_sni_mismatched_host_issue850 {
2519 my $self = shift;
2520 my $tmpdir = $self->{tmpdir};
2521 my $setup = test_setup($tmpdir, 'tls');
2522
2523 my $ec_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-server-cert.pem');
2524 my $ec_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-ca.pem');
2525
2526 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
2527 # is working as expected.
2528 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
2529 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
2530
2531 my $config = {
2532 PidFile => $setup->{pid_file},
2533 ScoreboardFile => $setup->{scoreboard_file},
2534 SystemLog => $setup->{log_file},
2535 TraceLog => $setup->{log_file},
2536 Trace => 'binding:30 tls:20',
2537
2538 AuthUserFile => $setup->{auth_user_file},
2539 AuthGroupFile => $setup->{auth_group_file},
2540 AuthOrder => 'mod_auth_file.c',
2541
2542 IfModules => {
2543 'mod_delay.c' => {
2544 DelayEngine => 'off',
2545 },
2546 },
2547 };
2548
2549 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2550 $config);
2551
2552 my $host = 'castaglia';
2553 my $other_host = 'ftp.nospam.org';
2554
2555 # Configure a name-based <VirtualHost> for our testing; remember that first
2556 # IP/port match wins, then first SNI match.
2557 if (open(my $fh, ">> $setup->{config_file}")) {
2558 print $fh <<EOC;
2559 <VirtualHost 127.0.0.1>
2560 ServerName "Alias-based ProFTPD"
2561 ServerAlias $host
2562 Port $port
2563
2564 AuthUserFile $setup->{auth_user_file}
2565 AuthGroupFile $setup->{auth_group_file}
2566 AuthOrder mod_auth_file.c
2567
2568 <IfModule mod_delay.c>
2569 DelayEngine off
2570 </IfModule>
2571
2572 <IfModule mod_tls.c>
2573 TLSEngine on
2574 TLSLog $setup->{log_file}
2575 TLSRequired on
2576 TLSRSACertificateFile $rsa_cert_file
2577 TLSCACertificateFile $rsa_ca_file
2578 TLSOptions EnableDiags
2579 </IfModule>
2580 </VirtualHost>
2581
2582 <VirtualHost 127.0.0.1>
2583 ServerName "Other ProFTPD"
2584 ServerAlias $other_host
2585 Port $port
2586
2587 AuthUserFile $setup->{auth_user_file}
2588 AuthGroupFile $setup->{auth_group_file}
2589 AuthOrder mod_auth_file.c
2590
2591 <IfModule mod_delay.c>
2592 DelayEngine off
2593 </IfModule>
2594
2595 <IfModule mod_tls.c>
2596 TLSEngine off
2597 </IfModule>
2598
2599 <Limit LOGIN>
2600 DenyAll
2601 </Limit>
2602 </VirtualHost>
2603 EOC
2604 unless (close($fh)) {
2605 die("Can't write $setup->{config_file}: $!");
2606 }
2607
2608 } else {
2609 die("Can't open $setup->{config_file}: $!");
2610 }
2611
2612 # Open pipes, for use between the parent and child processes. Specifically,
2613 # the child will indicate when it's done with its test by writing a message
2614 # to the parent.
2615 my ($rfh, $wfh);
2616 unless (pipe($rfh, $wfh)) {
2617 die("Can't open pipe: $!");
2618 }
2619
2620 require Net::FTPSSL;
2621
2622 my $ex;
2623
2624 # Fork child
2625 $self->handle_sigchld();
2626 defined(my $pid = fork()) or die("Can't fork: $!");
2627 if ($pid) {
2628 eval {
2629 # Give the server a chance to start up
2630 sleep(2);
2631
2632 my $ssl_opts = {
2633 Encryption => 'E',
2634 Port => $port,
2635 SSL_ca_file => $rsa_ca_file,
2636 SSL_hostname => $host,
2637 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
2638 };
2639
2640 if ($ENV{TEST_VERBOSE}) {
2641 $ssl_opts->{Debug} = 2;
2642 }
2643
2644 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
2645 unless ($client) {
2646 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
2647 }
2648
2649 # Deliberately send a HOST command with a name different than our SNI.
2650 my $resp_code = $client->quot('HOST', $other_host);
2651 if ($resp_code != '5') {
2652 die("HOST succeeded unexpectedly");
2653 }
2654
2655 my $resp_msg = $client->last_message();
2656 my $expected = 'Unknown hostname provided';
2657 $self->assert(qr/$expected/, $resp_msg,
2658 test_msg("Expected '$expected', got '$resp_msg'"));
2659 };
2660 if ($@) {
2661 $ex = $@;
2662 }
2663
2664 $wfh->print("done\n");
2665 $wfh->flush();
2666
2667 } else {
2668 eval { server_wait($setup->{config_file}, $rfh) };
2669 if ($@) {
2670 warn($@);
2671 exit 1;
2672 }
2673
2674 exit 0;
2675 }
2676
2677 # Stop server
2678 server_stop($setup->{pid_file});
2679 $self->assert_child_ok($pid);
2680
2681 test_cleanup($setup->{log_file}, $ex);
2682 }
2683
2684 sub tls_login_with_sni_matching_host_issue850 {
2685 my $self = shift;
2686 my $tmpdir = $self->{tmpdir};
2687 my $setup = test_setup($tmpdir, 'tls');
2688
2689 my $ec_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-server-cert.pem');
2690 my $ec_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-ca.pem');
2691
2692 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
2693 # is working as expected.
2694 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
2695 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
2696
2697 my $config = {
2698 PidFile => $setup->{pid_file},
2699 ScoreboardFile => $setup->{scoreboard_file},
2700 SystemLog => $setup->{log_file},
2701 TraceLog => $setup->{log_file},
2702 Trace => 'binding:30 tls:20',
2703
2704 AuthUserFile => $setup->{auth_user_file},
2705 AuthGroupFile => $setup->{auth_group_file},
2706
2707 IfModules => {
2708 'mod_delay.c' => {
2709 DelayEngine => 'off',
2710 },
2711 },
2712 };
2713
2714 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2715 $config);
2716
2717 my $host = 'castaglia';
2718
2719 # Configure a name-based <VirtualHost> for our testing; remember that first
2720 # IP/port match wins, then first SNI match.
2721 if (open(my $fh, ">> $setup->{config_file}")) {
2722 print $fh <<EOC;
2723 <VirtualHost 127.0.0.1>
2724 ServerName "Name-based ProFTPD"
2725 ServerAlias default
2726 Port $port
2727
2728 AuthUserFile $setup->{auth_user_file}
2729 AuthGroupFile $setup->{auth_group_file}
2730 AuthOrder mod_auth_file.c
2731 TransferLog none
2732 WtmpLog off
2733
2734 <IfModule mod_delay.c>
2735 DelayEngine off
2736 </IfModule>
2737
2738 <IfModule mod_tls.c>
2739 TLSEngine on
2740 TLSLog $setup->{log_file}
2741 TLSRequired on
2742 TLSRSACertificateFile $rsa_cert_file
2743 TLSCACertificateFile $rsa_ca_file
2744 TLSOptions EnableDiags
2745 </IfModule>
2746 </VirtualHost>
2747
2748 <VirtualHost 127.0.0.1>
2749 ServerName "Alias-based ProFTPD"
2750 ServerAlias $host
2751 Port $port
2752
2753 AuthUserFile $setup->{auth_user_file}
2754 AuthGroupFile $setup->{auth_group_file}
2755 AuthOrder mod_auth_file.c
2756 TransferLog none
2757 WtmpLog off
2758
2759 <IfModule mod_delay.c>
2760 DelayEngine off
2761 </IfModule>
2762
2763 <IfModule mod_tls.c>
2764 TLSEngine on
2765 TLSLog $setup->{log_file}
2766 TLSRequired on
2767 TLSRSACertificateFile $rsa_cert_file
2768 TLSCACertificateFile $rsa_ca_file
2769 TLSOptions EnableDiags
2770 </IfModule>
2771
2772 <Limit LOGIN>
2773 DenyAll
2774 </Limit>
2775 </VirtualHost>
2776 EOC
2777 unless (close($fh)) {
2778 die("Can't write $setup->{config_file}: $!");
2779 }
2780
2781 } else {
2782 die("Can't open $setup->{config_file}: $!");
2783 }
2784
2785 # Open pipes, for use between the parent and child processes. Specifically,
2786 # the child will indicate when it's done with its test by writing a message
2787 # to the parent.
2788 my ($rfh, $wfh);
2789 unless (pipe($rfh, $wfh)) {
2790 die("Can't open pipe: $!");
2791 }
2792
2793 require Net::FTPSSL;
2794
2795 my $ex;
2796
2797 # Fork child
2798 $self->handle_sigchld();
2799 defined(my $pid = fork()) or die("Can't fork: $!");
2800 if ($pid) {
2801 eval {
2802 # Give the server a chance to start up
2803 sleep(2);
2804
2805 my $ssl_opts = {
2806 Encryption => 'E',
2807 Port => $port,
2808 SSL_ca_file => $rsa_ca_file,
2809 SSL_hostname => $host,
2810 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
2811 };
2812
2813 if ($ENV{TEST_VERBOSE}) {
2814 $ssl_opts->{Debug} = 2;
2815 }
2816
2817 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
2818 unless ($client) {
2819 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
2820 }
2821
2822 # Deliberately send a HOST command with the same name as our SNI.
2823 my $resp_code = $client->quot('HOST', $host);
2824 if ($resp_code != '2') {
2825 die("HOST failed: " . $client->last_message());
2826 }
2827
2828 $client->quit();
2829 };
2830 if ($@) {
2831 $ex = $@;
2832 }
2833
2834 $wfh->print("done\n");
2835 $wfh->flush();
2836
2837 } else {
2838 eval { server_wait($setup->{config_file}, $rfh) };
2839 if ($@) {
2840 warn($@);
2841 exit 1;
2842 }
2843
2844 exit 0;
2845 }
2846
2847 # Stop server
2848 server_stop($setup->{pid_file});
2849 $self->assert_child_ok($pid);
2850
2851 test_cleanup($setup->{log_file}, $ex);
2852 }
2853
2854 sub tls_login_with_sni_matching_host_case_insensitive_issue850 {
2855 my $self = shift;
2856 my $tmpdir = $self->{tmpdir};
2857 my $setup = test_setup($tmpdir, 'tls');
2858
2859 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
2860 # is working as expected.
2861 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
2862 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
2863
2864 my $config = {
2865 PidFile => $setup->{pid_file},
2866 ScoreboardFile => $setup->{scoreboard_file},
2867 SystemLog => $setup->{log_file},
2868 TraceLog => $setup->{log_file},
2869 Trace => 'binding:30 tls:20',
2870
2871 AuthUserFile => $setup->{auth_user_file},
2872 AuthGroupFile => $setup->{auth_group_file},
2873
2874 IfModules => {
2875 'mod_delay.c' => {
2876 DelayEngine => 'off',
2877 },
2878 },
2879 };
2880
2881 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
2882 $config);
2883
2884 # Per the SNI spec:
2885 # https://tools.ietf.org/html/rfc6066#section-3
2886 #
2887 # the comparison of SNI hostnames (like any other DNS name) should be
2888 # case-INSENSITVE. So verify that that is the case.
2889
2890 my $host = 'Castaglia';
2891
2892 # Configure a name-based <VirtualHost> for our testing; remember that first
2893 # IP/port match wins, then first SNI match.
2894 if (open(my $fh, ">> $setup->{config_file}")) {
2895 print $fh <<EOC;
2896 <VirtualHost 127.0.0.1>
2897 ServerName "Name-based ProFTPD"
2898 ServerAlias default
2899 Port $port
2900
2901 AuthUserFile $setup->{auth_user_file}
2902 AuthGroupFile $setup->{auth_group_file}
2903 AuthOrder mod_auth_file.c
2904 TransferLog none
2905 WtmpLog off
2906
2907 <IfModule mod_delay.c>
2908 DelayEngine off
2909 </IfModule>
2910
2911 <IfModule mod_tls.c>
2912 TLSEngine on
2913 TLSLog $setup->{log_file}
2914 TLSRequired on
2915 TLSRSACertificateFile $rsa_cert_file
2916 TLSCACertificateFile $rsa_ca_file
2917 TLSOptions EnableDiags
2918 </IfModule>
2919 </VirtualHost>
2920
2921 <VirtualHost 127.0.0.1>
2922 ServerName "Alias-based ProFTPD"
2923 ServerAlias $host
2924 Port $port
2925
2926 AuthUserFile $setup->{auth_user_file}
2927 AuthGroupFile $setup->{auth_group_file}
2928 AuthOrder mod_auth_file.c
2929 TransferLog none
2930 WtmpLog off
2931
2932 <IfModule mod_delay.c>
2933 DelayEngine off
2934 </IfModule>
2935
2936 <IfModule mod_tls.c>
2937 TLSEngine on
2938 TLSLog $setup->{log_file}
2939 TLSRequired on
2940 TLSRSACertificateFile $rsa_cert_file
2941 TLSCACertificateFile $rsa_ca_file
2942 TLSOptions EnableDiags
2943 </IfModule>
2944
2945 <Limit LOGIN>
2946 DenyAll
2947 </Limit>
2948 </VirtualHost>
2949 EOC
2950 unless (close($fh)) {
2951 die("Can't write $setup->{config_file}: $!");
2952 }
2953
2954 } else {
2955 die("Can't open $setup->{config_file}: $!");
2956 }
2957
2958 # Open pipes, for use between the parent and child processes. Specifically,
2959 # the child will indicate when it's done with its test by writing a message
2960 # to the parent.
2961 my ($rfh, $wfh);
2962 unless (pipe($rfh, $wfh)) {
2963 die("Can't open pipe: $!");
2964 }
2965
2966 require Net::FTPSSL;
2967
2968 my $ex;
2969
2970 # Fork child
2971 $self->handle_sigchld();
2972 defined(my $pid = fork()) or die("Can't fork: $!");
2973 if ($pid) {
2974 eval {
2975 # Give the server a chance to start up
2976 sleep(2);
2977
2978 my $ssl_opts = {
2979 Encryption => 'E',
2980 Port => $port,
2981 SSL_ca_file => $rsa_ca_file,
2982 SSL_hostname => uc($host),
2983 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
2984 };
2985
2986 if ($ENV{TEST_VERBOSE}) {
2987 $ssl_opts->{Debug} = 2;
2988 }
2989
2990 my $client = Net::FTPSSL->new('127.0.0.1', $ssl_opts);
2991 unless ($client) {
2992 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
2993 }
2994
2995 # Deliberately send a HOST command with the same name as our SNI.
2996 my $resp_code = $client->quot('HOST', $host);
2997 if ($resp_code != '2') {
2998 die("HOST failed: " . $client->last_message());
2999 }
3000
3001 $client->quit();
3002 };
3003 if ($@) {
3004 $ex = $@;
3005 }
3006
3007 $wfh->print("done\n");
3008 $wfh->flush();
3009
3010 } else {
3011 eval { server_wait($setup->{config_file}, $rfh) };
3012 if ($@) {
3013 warn($@);
3014 exit 1;
3015 }
3016
3017 exit 0;
3018 }
3019
3020 # Stop server
3021 server_stop($setup->{pid_file});
3022 $self->assert_child_ok($pid);
3023
3024 test_cleanup($setup->{log_file}, $ex);
3025 }
3026
3027 sub tls_login_with_sni_mismatched_protocol_version_issue850 {
3028 my $self = shift;
3029 my $tmpdir = $self->{tmpdir};
3030 my $setup = test_setup($tmpdir, 'tls');
3031
3032 my $ec_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-server-cert.pem');
3033 my $ec_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ec-ca.pem');
3034
3035 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
3036 # is working as expected.
3037 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3038 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3039
3040 my $config = {
3041 PidFile => $setup->{pid_file},
3042 ScoreboardFile => $setup->{scoreboard_file},
3043 SystemLog => $setup->{log_file},
3044 TraceLog => $setup->{log_file},
3045 Trace => 'binding:30 tls:20',
3046
3047 AuthUserFile => $setup->{auth_user_file},
3048 AuthGroupFile => $setup->{auth_group_file},
3049
3050 IfModules => {
3051 'mod_delay.c' => {
3052 DelayEngine => 'off',
3053 },
3054 },
3055 };
3056
3057 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3058 $config);
3059
3060 my $host = 'castaglia';
3061
3062 # Configure a name-based <VirtualHost> for our testing; remember that first
3063 # IP/port match wins, then first SNI match.
3064 if (open(my $fh, ">> $setup->{config_file}")) {
3065 print $fh <<EOC;
3066 <VirtualHost 127.0.0.1>
3067 ServerName "Name-based ProFTPD"
3068 ServerAlias default
3069 Port $port
3070
3071 AuthUserFile $setup->{auth_user_file}
3072 AuthGroupFile $setup->{auth_group_file}
3073 AuthOrder mod_auth_file.c
3074 TransferLog none
3075 WtmpLog off
3076
3077 <IfModule mod_delay.c>
3078 DelayEngine off
3079 </IfModule>
3080
3081 <IfModule mod_tls.c>
3082 TLSEngine on
3083 TLSLog $setup->{log_file}
3084 TLSRequired on
3085 TLSECCertificateFile $ec_cert_file
3086 TLSCACertificateFile $ec_ca_file
3087 TLSOptions EnableDiags
3088 TLSProtocol SSLv3 TLSv1.0
3089 </IfModule>
3090 </VirtualHost>
3091
3092 <VirtualHost 127.0.0.1>
3093 ServerName "Alias-based ProFTPD"
3094 ServerAlias $host
3095 Port $port
3096
3097 AuthUserFile $setup->{auth_user_file}
3098 AuthGroupFile $setup->{auth_group_file}
3099 AuthOrder mod_auth_file.c
3100 TransferLog none
3101 WtmpLog off
3102
3103 <IfModule mod_delay.c>
3104 DelayEngine off
3105 </IfModule>
3106
3107 <IfModule mod_tls.c>
3108 TLSEngine on
3109 TLSLog $setup->{log_file}
3110 TLSRequired on
3111 TLSRSACertificateFile $rsa_cert_file
3112 TLSCACertificateFile $rsa_ca_file
3113 TLSOptions EnableDiags
3114 TLSProtocol TLSv1.2 TLSv1.3
3115 </IfModule>
3116
3117 <Limit LOGIN>
3118 DenyAll
3119 </Limit>
3120 </VirtualHost>
3121 EOC
3122 unless (close($fh)) {
3123 die("Can't write $setup->{config_file}: $!");
3124 }
3125
3126 } else {
3127 die("Can't open $setup->{config_file}: $!");
3128 }
3129
3130 # Open pipes, for use between the parent and child processes. Specifically,
3131 # the child will indicate when it's done with its test by writing a message
3132 # to the parent.
3133 my ($rfh, $wfh);
3134 unless (pipe($rfh, $wfh)) {
3135 die("Can't open pipe: $!");
3136 }
3137
3138 require Net::FTPSSL;
3139
3140 my $ex;
3141
3142 # Fork child
3143 $self->handle_sigchld();
3144 defined(my $pid = fork()) or die("Can't fork: $!");
3145 if ($pid) {
3146 eval {
3147 # Give the server a chance to start up
3148 sleep(2);
3149
3150 my $ssl_opts = {
3151 Encryption => 'E',
3152 Port => $port,
3153 SSL_ca_file => $rsa_ca_file,
3154 SSL_hostname => $host,
3155 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
3156 SSL_version => 'TLSv1',
3157 };
3158
3159 if ($ENV{TEST_VERBOSE}) {
3160 $ssl_opts->{Debug} = 2;
3161 }
3162
3163 my $client = Net::FTPSSL->new('127.0.0.1', $ssl_opts);
3164
3165 # The named vhost has does not support the specified TLS protocol
3166 # version, so the handshake should fail.
3167 if ($client) {
3168 die("Connected to FTPS server unexpectedly");
3169 }
3170
3171 my $errstr = IO::Socket::SSL::errstr();
3172 if ($ENV{TEST_VERBOSE}) {
3173 print STDERR "# TLS Handshake failed: $errstr\n";
3174 }
3175
3176 my $expected = 'handshake failure|protocol version';
3177 $self->assert(qr/$expected/, $errstr,
3178 test_msg("Expected '$expected', got '$errstr'"));
3179 };
3180 if ($@) {
3181 $ex = $@;
3182 }
3183
3184 $wfh->print("done\n");
3185 $wfh->flush();
3186
3187 } else {
3188 eval { server_wait($setup->{config_file}, $rfh) };
3189 if ($@) {
3190 warn($@);
3191 exit 1;
3192 }
3193
3194 exit 0;
3195 }
3196
3197 # Stop server
3198 server_stop($setup->{pid_file});
3199 $self->assert_child_ok($pid);
3200
3201 test_cleanup($setup->{log_file}, $ex);
3202 }
3203
3204 sub tls_login_with_sni_port_zero_issue932 {
3205 my $self = shift;
3206 my $tmpdir = $self->{tmpdir};
3207 my $setup = test_setup($tmpdir, 'tls');
3208
3209 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
3210 # is working as expected.
3211 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3212 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3213
3214 # The key for this issue is the use of:
3215 #
3216 # DefaultServer off
3217 # Port 0
3218 #
3219 # So that the default vhost is DISABLED.
3220
3221 my $config = {
3222 PidFile => $setup->{pid_file},
3223 ScoreboardFile => $setup->{scoreboard_file},
3224 SystemLog => $setup->{log_file},
3225 TraceLog => $setup->{log_file},
3226 Trace => 'binding:30 tls:20',
3227 DefaultServer => 'off',
3228 Port => 0,
3229 };
3230
3231 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3232 $config);
3233
3234 my $host = 'castaglia';
3235 my $other_host = 'ftp.nospam.org';
3236
3237 # Configure name-based <VirtualHost> sections for our testing.
3238 if (open(my $fh, ">> $setup->{config_file}")) {
3239 print $fh <<EOC;
3240 <Global>
3241 AuthOrder mod_auth_file.c
3242 AuthUserFile $setup->{auth_user_file}
3243 AuthGroupFile $setup->{auth_group_file}
3244 TransferLog none
3245 WtmpLog off
3246
3247 <IfModule mod_delay.c>
3248 DelayEngine off
3249 </IfModule>
3250
3251 <IfModule mod_tls.c>
3252 TLSEngine on
3253 TLSLog $setup->{log_file}
3254 TLSRequired on
3255 TLSRSACertificateFile $rsa_cert_file
3256 TLSCACertificateFile $rsa_ca_file
3257 TLSProtocol TLSv1.0
3258 TLSOptions EnableDiags
3259 </IfModule>
3260 </Global>
3261
3262 <VirtualHost 127.0.0.1>
3263 Port $port
3264 ServerAlias $host
3265 ServerName "Alias-based ProFTPD"
3266 </VirtualHost>
3267
3268 <VirtualHost 127.0.0.1>
3269 Port $port
3270 ServerAlias $other_host
3271 ServerName "Other ProFTPD"
3272 </VirtualHost>
3273 EOC
3274 unless (close($fh)) {
3275 die("Can't write $setup->{config_file}: $!");
3276 }
3277
3278 } else {
3279 die("Can't open $setup->{config_file}: $!");
3280 }
3281
3282 # Open pipes, for use between the parent and child processes. Specifically,
3283 # the child will indicate when it's done with its test by writing a message
3284 # to the parent.
3285 my ($rfh, $wfh);
3286 unless (pipe($rfh, $wfh)) {
3287 die("Can't open pipe: $!");
3288 }
3289
3290 require Net::FTPSSL;
3291
3292 my $ex;
3293
3294 # Fork child
3295 $self->handle_sigchld();
3296 defined(my $pid = fork()) or die("Can't fork: $!");
3297 if ($pid) {
3298 eval {
3299 # Give the server a chance to start up
3300 sleep(2);
3301
3302 my $ssl_opts = {
3303 Encryption => 'E',
3304 Port => $port,
3305 SSL_ca_file => $rsa_ca_file,
3306 SSL_hostname => $host,
3307 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
3308 };
3309
3310 if ($ENV{TEST_VERBOSE}) {
3311 $ssl_opts->{Debug} = 2;
3312 }
3313
3314 my $client = Net::FTPSSL->new('127.0.0.1', $ssl_opts);
3315 unless ($client) {
3316 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
3317 }
3318
3319 my $resp_code = $client->quot('HOST', $host);
3320 if ($resp_code != '2') {
3321 die("HOST failed: " . $client->last_message());
3322 }
3323
3324 $client->quit();
3325 };
3326 if ($@) {
3327 $ex = $@;
3328 }
3329
3330 $wfh->print("done\n");
3331 $wfh->flush();
3332
3333 } else {
3334 eval { server_wait($setup->{config_file}, $rfh) };
3335 if ($@) {
3336 warn($@);
3337 exit 1;
3338 }
3339
3340 exit 0;
3341 }
3342
3343 # Stop server
3344 server_stop($setup->{pid_file});
3345 $self->assert_child_ok($pid);
3346
3347 test_cleanup($setup->{log_file}, $ex);
3348 }
3349
3350 sub tls_login_with_sni_port_nonzero_issue932 {
3351 my $self = shift;
3352 my $tmpdir = $self->{tmpdir};
3353 my $setup = test_setup($tmpdir, 'tls');
3354
3355 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
3356 # is working as expected.
3357 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3358 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3359
3360 my $config = {
3361 PidFile => $setup->{pid_file},
3362 ScoreboardFile => $setup->{scoreboard_file},
3363 SystemLog => $setup->{log_file},
3364 TraceLog => $setup->{log_file},
3365 Trace => 'binding:20 tls:20',
3366 DefaultServer => 'off',
3367 };
3368
3369 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3370 $config);
3371
3372 my $host = 'castaglia';
3373 my $other_host = 'ftp.nospam.org';
3374
3375 # Configure name-based <VirtualHost> sections for our testing.
3376 if (open(my $fh, ">> $setup->{config_file}")) {
3377 print $fh <<EOC;
3378 <Global>
3379 AuthOrder mod_auth_file.c
3380 AuthUserFile $setup->{auth_user_file}
3381 AuthGroupFile $setup->{auth_group_file}
3382 TransferLog none
3383 WtmpLog off
3384
3385 <IfModule mod_delay.c>
3386 DelayEngine off
3387 </IfModule>
3388
3389 <IfModule mod_tls.c>
3390 TLSEngine on
3391 TLSLog $setup->{log_file}
3392 TLSRequired on
3393 TLSRSACertificateFile $rsa_cert_file
3394 TLSCACertificateFile $rsa_ca_file
3395 TLSProtocol TLSv1.0
3396 TLSOptions EnableDiags
3397 </IfModule>
3398 </Global>
3399
3400 <VirtualHost 127.0.0.1>
3401 Port $port
3402 ServerAlias $host
3403 ServerName "Alias-based ProFTPD"
3404 </VirtualHost>
3405
3406 <VirtualHost 127.0.0.1>
3407 Port $port
3408 ServerAlias $other_host
3409 ServerName "Other ProFTPD"
3410 </VirtualHost>
3411 EOC
3412 unless (close($fh)) {
3413 die("Can't write $setup->{config_file}: $!");
3414 }
3415
3416 } else {
3417 die("Can't open $setup->{config_file}: $!");
3418 }
3419
3420 # Open pipes, for use between the parent and child processes. Specifically,
3421 # the child will indicate when it's done with its test by writing a message
3422 # to the parent.
3423 my ($rfh, $wfh);
3424 unless (pipe($rfh, $wfh)) {
3425 die("Can't open pipe: $!");
3426 }
3427
3428 require Net::FTPSSL;
3429
3430 my $ex;
3431
3432 # Fork child
3433 $self->handle_sigchld();
3434 defined(my $pid = fork()) or die("Can't fork: $!");
3435 if ($pid) {
3436 eval {
3437 # Give the server a chance to start up
3438 sleep(2);
3439
3440 my $ssl_opts = {
3441 Encryption => 'E',
3442 Port => $port,
3443 SSL_ca_file => $rsa_ca_file,
3444 SSL_hostname => $host,
3445 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
3446 };
3447
3448 if ($ENV{TEST_VERBOSE}) {
3449 $ssl_opts->{Debug} = 2;
3450 }
3451
3452 my $client = Net::FTPSSL->new('127.0.0.1', $ssl_opts);
3453 unless ($client) {
3454 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
3455 }
3456
3457 my $resp_code = $client->quot('HOST', $host);
3458 if ($resp_code != '2') {
3459 die("HOST failed: " . $client->last_message());
3460 }
3461
3462 $client->quit();
3463 };
3464 if ($@) {
3465 $ex = $@;
3466 }
3467
3468 $wfh->print("done\n");
3469 $wfh->flush();
3470
3471 } else {
3472 eval { server_wait($setup->{config_file}, $rfh) };
3473 if ($@) {
3474 warn($@);
3475 exit 1;
3476 }
3477
3478 exit 0;
3479 }
3480
3481 # Stop server
3482 server_stop($setup->{pid_file});
3483 $self->assert_child_ok($pid);
3484
3485 test_cleanup($setup->{log_file}, $ex);
3486 }
3487
3488 sub tls_login_with_sni_port_zero_socketbindtight_on_issue932 {
3489 my $self = shift;
3490 my $tmpdir = $self->{tmpdir};
3491 my $setup = test_setup($tmpdir, 'tls');
3492
3493 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
3494 # is working as expected.
3495 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3496 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3497
3498 # The key for this issue is the use of:
3499 #
3500 # DefaultServer off
3501 # Port 0
3502 #
3503 # So that the default vhost is DISABLED.
3504
3505 my $config = {
3506 PidFile => $setup->{pid_file},
3507 ScoreboardFile => $setup->{scoreboard_file},
3508 SystemLog => $setup->{log_file},
3509 TraceLog => $setup->{log_file},
3510 Trace => 'binding:20 tls:20',
3511 DefaultServer => 'off',
3512 Port => 0,
3513 SocketBindTight => 'on',
3514 };
3515
3516 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3517 $config);
3518
3519 my $host = 'castaglia';
3520 my $other_host = 'ftp.nospam.org';
3521
3522 # Configure name-based <VirtualHost> sections for our testing.
3523 if (open(my $fh, ">> $setup->{config_file}")) {
3524 print $fh <<EOC;
3525 <Global>
3526 AuthOrder mod_auth_file.c
3527 AuthUserFile $setup->{auth_user_file}
3528 AuthGroupFile $setup->{auth_group_file}
3529 TransferLog none
3530 WtmpLog off
3531
3532 <IfModule mod_delay.c>
3533 DelayEngine off
3534 </IfModule>
3535
3536 <IfModule mod_tls.c>
3537 TLSEngine on
3538 TLSLog $setup->{log_file}
3539 TLSRequired on
3540 TLSRSACertificateFile $rsa_cert_file
3541 TLSCACertificateFile $rsa_ca_file
3542 TLSProtocol TLSv1.0
3543 TLSOptions EnableDiags
3544 </IfModule>
3545 </Global>
3546
3547 <VirtualHost 127.0.0.1>
3548 Port $port
3549 ServerAlias $host
3550 ServerName "Alias-based ProFTPD"
3551 </VirtualHost>
3552
3553 <VirtualHost 127.0.0.1>
3554 Port $port
3555 ServerAlias $other_host
3556 ServerName "Other ProFTPD"
3557 </VirtualHost>
3558 EOC
3559 unless (close($fh)) {
3560 die("Can't write $setup->{config_file}: $!");
3561 }
3562
3563 } else {
3564 die("Can't open $setup->{config_file}: $!");
3565 }
3566
3567 # Open pipes, for use between the parent and child processes. Specifically,
3568 # the child will indicate when it's done with its test by writing a message
3569 # to the parent.
3570 my ($rfh, $wfh);
3571 unless (pipe($rfh, $wfh)) {
3572 die("Can't open pipe: $!");
3573 }
3574
3575 require Net::FTPSSL;
3576
3577 my $ex;
3578
3579 # Fork child
3580 $self->handle_sigchld();
3581 defined(my $pid = fork()) or die("Can't fork: $!");
3582 if ($pid) {
3583 eval {
3584 # Give the server a chance to start up
3585 sleep(2);
3586
3587 my $ssl_opts = {
3588 Encryption => 'E',
3589 Port => $port,
3590 SSL_ca_file => $rsa_ca_file,
3591 SSL_hostname => $host,
3592 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
3593 };
3594
3595 if ($ENV{TEST_VERBOSE}) {
3596 $ssl_opts->{Debug} = 2;
3597 }
3598
3599 my $client = Net::FTPSSL->new('127.0.0.1', $ssl_opts);
3600 unless ($client) {
3601 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
3602 }
3603
3604 my $resp_code = $client->quot('HOST', $host);
3605 if ($resp_code != '2') {
3606 die("HOST failed: " . $client->last_message());
3607 }
3608
3609 $client->quit();
3610 };
3611 if ($@) {
3612 $ex = $@;
3613 }
3614
3615 $wfh->print("done\n");
3616 $wfh->flush();
3617
3618 } else {
3619 eval { server_wait($setup->{config_file}, $rfh) };
3620 if ($@) {
3621 warn($@);
3622 exit 1;
3623 }
3624
3625 exit 0;
3626 }
3627
3628 # Stop server
3629 server_stop($setup->{pid_file});
3630 $self->assert_child_ok($pid);
3631
3632 test_cleanup($setup->{log_file}, $ex);
3633 }
3634
3635 sub tls_login_with_sni_port_zero_multi_ports_issue932 {
3636 my $self = shift;
3637 my $tmpdir = $self->{tmpdir};
3638 my $setup = test_setup($tmpdir, 'tls');
3639
3640 # Use RSA certs for our name-based vhost, to test that the SNI vhost switching
3641 # is working as expected.
3642 my $rsa_cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3643 my $rsa_ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3644
3645 # The key for this issue is the use of:
3646 #
3647 # DefaultServer off
3648 # Port 0
3649 #
3650 # So that the default vhost is DISABLED.
3651
3652 my $config = {
3653 PidFile => $setup->{pid_file},
3654 ScoreboardFile => $setup->{scoreboard_file},
3655 SystemLog => $setup->{log_file},
3656 TraceLog => $setup->{log_file},
3657 Trace => 'binding:20 tls:20',
3658 Port => 0,
3659 };
3660
3661 if (feature_have_feature_enabled('ipv6')) {
3662 $config->{UseIPv6} = 'on';
3663 }
3664
3665 my $config_opts = {
3666 NoDefaultAddress => 1,
3667 NoDefaultServer => 1,
3668 };
3669
3670 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3671 $config, $config_opts);
3672
3673 my $address = '0.0.0.0';
3674 my $host = 'castaglia';
3675 my $other_host = 'ftp.nospam.org';
3676 my $other_port = $port + 19;
3677 my $last_host = 'ftp3.example.com';
3678
3679 # Configure name-based <VirtualHost> sections for our testing.
3680 if (open(my $fh, ">> $setup->{config_file}")) {
3681 print $fh <<EOC;
3682 <Global>
3683 AuthOrder mod_auth_file.c
3684 AuthUserFile $setup->{auth_user_file}
3685 AuthGroupFile $setup->{auth_group_file}
3686 TransferLog none
3687 WtmpLog off
3688
3689 <IfModule mod_delay.c>
3690 DelayEngine off
3691 </IfModule>
3692
3693 <IfModule mod_tls.c>
3694 TLSEngine on
3695 TLSLog $setup->{log_file}
3696 TLSRequired on
3697 TLSRSACertificateFile $rsa_cert_file
3698 TLSCACertificateFile $rsa_ca_file
3699 TLSProtocol TLSv1.0
3700 TLSOptions EnableDiags
3701 </IfModule>
3702 </Global>
3703
3704 <VirtualHost $address>
3705 Port $port
3706 ServerAlias $host
3707 ServerName "Alias-based ProFTPD"
3708 </VirtualHost>
3709
3710 <VirtualHost $address>
3711 Port $port
3712 ServerAlias $other_host
3713 ServerName "Other ProFTPD"
3714 </VirtualHost>
3715
3716 <VirtualHost $address>
3717 Port $other_port
3718 ServerAlias $host
3719 ServerName "Alias-based ProFTPD on other port"
3720 </VirtualHost>
3721
3722 <VirtualHost $address>
3723 Port $other_port
3724 ServerAlias $other_host
3725 ServerName "Other ProFTPD on other port"
3726 </VirtualHost>
3727
3728 <VirtualHost $address>
3729 Port $port
3730 ServerAlias $last_host
3731 ServerName "Last ProFTPD"
3732 </VirtualHost>
3733
3734 <VirtualHost $address>
3735 Port $other_port
3736 ServerAlias $last_host
3737 ServerName "Last ProFTPD on other port"
3738 </VirtualHost>
3739 EOC
3740 unless (close($fh)) {
3741 die("Can't write $setup->{config_file}: $!");
3742 }
3743
3744 } else {
3745 die("Can't open $setup->{config_file}: $!");
3746 }
3747
3748 # Open pipes, for use between the parent and child processes. Specifically,
3749 # the child will indicate when it's done with its test by writing a message
3750 # to the parent.
3751 my ($rfh, $wfh);
3752 unless (pipe($rfh, $wfh)) {
3753 die("Can't open pipe: $!");
3754 }
3755
3756 require Net::FTPSSL;
3757
3758 my $ex;
3759
3760 # Fork child
3761 $self->handle_sigchld();
3762 defined(my $pid = fork()) or die("Can't fork: $!");
3763 if ($pid) {
3764 eval {
3765 # Give the server a chance to start up
3766 sleep(2);
3767
3768 my $ssl_opts = {
3769 Encryption => 'E',
3770 Port => $port,
3771 SSL_ca_file => $rsa_ca_file,
3772 SSL_hostname => $host,
3773 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_PEER(),
3774 };
3775
3776 if ($ENV{TEST_VERBOSE}) {
3777 $ssl_opts->{Debug} = 2;
3778 }
3779
3780 my $client = Net::FTPSSL->new('127.0.0.1', %$ssl_opts);
3781 unless ($client) {
3782 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
3783 }
3784
3785 my $resp_code = $client->quot('HOST', $host);
3786 if ($resp_code != '2') {
3787 die("HOST failed: " . $client->last_message());
3788 }
3789
3790 $client->quit();
3791
3792 $ssl_opts->{Port} = $other_port;
3793 $ssl_opts->{SSL_hostname} = $last_host;
3794
3795 $client = Net::FTPSSL->new('127.0.0.1', $ssl_opts);
3796 unless ($client) {
3797 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
3798 }
3799
3800 $resp_code = $client->quot('HOST', $last_host);
3801 if ($resp_code != '2') {
3802 die("HOST failed: " . $client->last_message());
3803 }
3804
3805 $client->quit();
3806 };
3807 if ($@) {
3808 $ex = $@;
3809 }
3810
3811 $wfh->print("done\n");
3812 $wfh->flush();
3813
3814 } else {
3815 eval { server_wait($setup->{config_file}, $rfh) };
3816 if ($@) {
3817 warn($@);
3818 exit 1;
3819 }
3820
3821 exit 0;
3822 }
3823
3824 # Stop server
3825 server_stop($setup->{pid_file});
3826 $self->assert_child_ok($pid);
3827
3828 test_cleanup($setup->{log_file}, $ex);
3829 }
3830
3831 sub tls_login_before_auth_without_opt_allow_per_user_issue1533 {
3832 my $self = shift;
3833 my $tmpdir = $self->{tmpdir};
3834 my $setup = test_setup($tmpdir, 'tls');
3835
3836 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3837 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3838
3839 my $config = {
3840 PidFile => $setup->{pid_file},
3841 ScoreboardFile => $setup->{scoreboard_file},
3842 SystemLog => $setup->{log_file},
3843 TraceLog => $setup->{log_file},
3844 Trace => 'tls:20',
3845
3846 AuthUserFile => $setup->{auth_user_file},
3847 AuthGroupFile => $setup->{auth_group_file},
3848 AuthOrder => 'mod_auth_file.c',
3849
3850 IfModules => {
3851 'mod_delay.c' => {
3852 DelayEngine => 'off',
3853 },
3854
3855 'mod_tls.c' => {
3856 TLSEngine => 'on',
3857 TLSLog => $setup->{log_file},
3858 TLSRequired => 'off',
3859 TLSRSACertificateFile => $cert_file,
3860 TLSCACertificateFile => $ca_file,
3861 },
3862 },
3863 };
3864
3865 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3866 $config);
3867
3868 # Open pipes, for use between the parent and child processes. Specifically,
3869 # the child will indicate when it's done with its test by writing a message
3870 # to the parent.
3871 my ($rfh, $wfh);
3872 unless (pipe($rfh, $wfh)) {
3873 die("Can't open pipe: $!");
3874 }
3875
3876 my $ex;
3877
3878 # Fork child
3879 $self->handle_sigchld();
3880 defined(my $pid = fork()) or die("Can't fork: $!");
3881 if ($pid) {
3882 eval {
3883 # Give the server a chance to start up
3884 sleep(2);
3885
3886 # With this config, we should not be able to do a TLS handshake after
3887 # authenticating.
3888 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
3889 $client->login($setup->{user}, $setup->{passwd});
3890
3891 eval { $client->quote('AUTH', 'TLS') };
3892 unless ($@) {
3893 die("AUTH succeeded unexpectedly");
3894 }
3895
3896 my $resp_code = $client->response_code();
3897 my $resp_msg = $client->response_msg();
3898
3899 my $expected = 534;
3900 $self->assert($expected == $resp_code,
3901 test_msg("Expected response code $expected, got $resp_code"));
3902
3903 $expected = 'Unwilling to accept security parameters';
3904 $self->assert($expected eq $resp_msg,
3905 test_msg("Expected response message '$expected', got '$resp_msg'"));
3906
3907 $client->quit();
3908 };
3909 if ($@) {
3910 $ex = $@;
3911 }
3912
3913 $wfh->print("done\n");
3914 $wfh->flush();
3915
3916 } else {
3917 eval { server_wait($setup->{config_file}, $rfh) };
3918 if ($@) {
3919 warn($@);
3920 exit 1;
3921 }
3922
3923 exit 0;
3924 }
3925
3926 # Stop server
3927 server_stop($setup->{pid_file});
3928 $self->assert_child_ok($pid);
3929
3930 test_cleanup($setup->{log_file}, $ex);
3931 }
3932
3933 sub tls_list_no_session_reuse {
3934 my $self = shift;
3935 my $tmpdir = $self->{tmpdir};
3936 my $setup = test_setup($tmpdir, 'tls');
3937
3938 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
3939 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
3940
3941 my $config = {
3942 PidFile => $setup->{pid_file},
3943 ScoreboardFile => $setup->{scoreboard_file},
3944 SystemLog => $setup->{log_file},
3945
3946 AuthUserFile => $setup->{auth_user_file},
3947 AuthGroupFile => $setup->{auth_group_file},
3948 AuthOrder => 'mod_auth_file.c',
3949
3950 IfModules => {
3951 'mod_delay.c' => {
3952 DelayEngine => 'off',
3953 },
3954
3955 'mod_tls.c' => {
3956 TLSEngine => 'on',
3957 TLSLog => $setup->{log_file},
3958 TLSRequired => 'on',
3959 TLSRSACertificateFile => $cert_file,
3960 TLSCACertificateFile => $ca_file,
3961 },
3962 },
3963 };
3964
3965 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
3966 $config);
3967
3968 # Open pipes, for use between the parent and child processes. Specifically,
3969 # the child will indicate when it's done with its test by writing a message
3970 # to the parent.
3971 my ($rfh, $wfh);
3972 unless (pipe($rfh, $wfh)) {
3973 die("Can't open pipe: $!");
3974 }
3975
3976 require Net::FTPSSL;
3977
3978 my $ex;
3979
3980 # Fork child
3981 $self->handle_sigchld();
3982 defined(my $pid = fork()) or die("Can't fork: $!");
3983 if ($pid) {
3984 eval {
3985 # Give the server a chance to start up
3986 sleep(2);
3987
3988 my $client = Net::FTPSSL->new('127.0.0.1',
3989 Encryption => 'E',
3990 Port => $port,
3991 Croak => 1,
3992 );
3993
3994 unless ($client->login($setup->{user}, $setup->{passwd})) {
3995 die("Can't login: " . $client->last_message());
3996 }
3997
3998 # Since we are requiring SSL session reuse for data transfers,
3999 # and this client is not using SSL session resumption, I expect
4000 # this data transfer to fail.
4001 eval {
4002 my $res = $client->list('.');
4003 if ($res) {
4004 die("LIST succeeded unexpectedly");
4005 }
4006 };
4007
4008 unless ($@) {
4009 die("LIST succeeded unexpectedly");
4010 }
4011
4012 my $resp = $client->message();
4013 my $expected = '425 Unable to build data connection: Operation not permitted';
4014 $self->assert($expected eq $resp,
4015 test_msg("Expected response '$expected', got '$resp'"));
4016 };
4017 if ($@) {
4018 $ex = $@;
4019 }
4020
4021 $wfh->print("done\n");
4022 $wfh->flush();
4023
4024 } else {
4025 eval { server_wait($setup->{config_file}, $rfh) };
4026 if ($@) {
4027 warn($@);
4028 exit 1;
4029 }
4030
4031 exit 0;
4032 }
4033
4034 # Stop server
4035 server_stop($setup->{pid_file});
4036 $self->assert_child_ok($pid);
4037
4038 test_cleanup($setup->{log_file}, $ex);
4039 }
4040
4041 sub tls_list_with_session_reuse {
4042 my $self = shift;
4043 my $tmpdir = $self->{tmpdir};
4044 my $setup = test_setup($tmpdir, 'tls');
4045
4046 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4047 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4048
4049 my $config = {
4050 PidFile => $setup->{pid_file},
4051 ScoreboardFile => $setup->{scoreboard_file},
4052 SystemLog => $setup->{log_file},
4053
4054 AuthUserFile => $setup->{auth_user_file},
4055 AuthGroupFile => $setup->{auth_group_file},
4056 AuthOrder => 'mod_auth_file.c',
4057
4058 IfModules => {
4059 'mod_delay.c' => {
4060 DelayEngine => 'off',
4061 },
4062
4063 'mod_tls.c' => {
4064 TLSEngine => 'on',
4065 TLSLog => $setup->{log_file},
4066 TLSRequired => 'on',
4067 TLSRSACertificateFile => $cert_file,
4068 TLSCACertificateFile => $ca_file,
4069 },
4070 },
4071 };
4072
4073 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4074 $config);
4075
4076 # Open pipes, for use between the parent and child processes. Specifically,
4077 # the child will indicate when it's done with its test by writing a message
4078 # to the parent.
4079 my ($rfh, $wfh);
4080 unless (pipe($rfh, $wfh)) {
4081 die("Can't open pipe: $!");
4082 }
4083
4084 require Net::FTPSSL;
4085
4086 my $ex;
4087
4088 # Fork child
4089 $self->handle_sigchld();
4090 defined(my $pid = fork()) or die("Can't fork: $!");
4091 if ($pid) {
4092 eval {
4093 # Give the server a chance to start up
4094 sleep(2);
4095
4096 my $client = Net::FTPSSL->new('127.0.0.1',
4097 Encryption => 'E',
4098 Port => $port,
4099 Croak => 1,
4100 ReuseSession => 1,
4101 );
4102
4103 unless ($client->login($setup->{user}, $setup->{passwd})) {
4104 die("Can't login: " . $client->last_message());
4105 }
4106
4107 # Since we are requiring SSL session reuse for data transfers,
4108 # and this client IS using SSL session resumption, I expect
4109 # these data transfers to succeed.
4110 for (my $i = 0; $i < 3; $i++) {
4111 my $res = $client->list('.');
4112 unless ($res) {
4113 die("LIST failed unexpectedly");
4114 }
4115
4116 my $resp = $client->message();
4117 my $expected = '226 Transfer complete';
4118 $self->assert($expected eq $resp,
4119 test_msg("Expected response '$expected', got '$resp'"));
4120 }
4121
4122 $client->quit();
4123 };
4124 if ($@) {
4125 $ex = $@;
4126 }
4127
4128 $wfh->print("done\n");
4129 $wfh->flush();
4130
4131 } else {
4132 eval { server_wait($setup->{config_file}, $rfh) };
4133 if ($@) {
4134 warn($@);
4135 exit 1;
4136 }
4137
4138 exit 0;
4139 }
4140
4141 # Stop server
4142 server_stop($setup->{pid_file});
4143 $self->assert_child_ok($pid);
4144
4145 test_cleanup($setup->{log_file}, $ex);
4146 }
4147
4148 sub tls_list_with_no_session_reuse_required_opt {
4149 my $self = shift;
4150 my $tmpdir = $self->{tmpdir};
4151
4152 my $config_file = "$tmpdir/tls.conf";
4153 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
4154 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
4155
4156 my $log_file = test_get_logfile();
4157
4158 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
4159 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
4160
4161 my $user = 'proftpd';
4162 my $passwd = 'test';
4163 my $group = 'ftpd';
4164 my $home_dir = File::Spec->rel2abs($tmpdir);
4165 my $uid = 500;
4166 my $gid = 500;
4167
4168 # Make sure that, if we're running as root, that the home directory has
4169 # permissions/privs set for the account we create
4170 if ($< == 0) {
4171 unless (chmod(0755, $home_dir)) {
4172 die("Can't set perms on $home_dir to 0755: $!");
4173 }
4174
4175 unless (chown($uid, $gid, $home_dir)) {
4176 die("Can't set owner of $home_dir to $uid/$gid: $!");
4177 }
4178 }
4179
4180 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4181 '/bin/bash');
4182 auth_group_write($auth_group_file, $group, $gid, $user);
4183
4184 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4185 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4186
4187 my $config = {
4188 PidFile => $pid_file,
4189 ScoreboardFile => $scoreboard_file,
4190 SystemLog => $log_file,
4191
4192 AuthUserFile => $auth_user_file,
4193 AuthGroupFile => $auth_group_file,
4194
4195 IfModules => {
4196 'mod_delay.c' => {
4197 DelayEngine => 'off',
4198 },
4199
4200 'mod_tls.c' => {
4201 TLSEngine => 'on',
4202 TLSLog => $log_file,
4203 TLSRequired => 'on',
4204 TLSRSACertificateFile => $cert_file,
4205 TLSCACertificateFile => $ca_file,
4206
4207 TLSOptions => 'NoSessionReuseRequired',
4208 },
4209 },
4210 };
4211
4212 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4213
4214 # Open pipes, for use between the parent and child processes. Specifically,
4215 # the child will indicate when it's done with its test by writing a message
4216 # to the parent.
4217 my ($rfh, $wfh);
4218 unless (pipe($rfh, $wfh)) {
4219 die("Can't open pipe: $!");
4220 }
4221
4222 require Net::FTPSSL;
4223
4224 my $ex;
4225
4226 # Fork child
4227 $self->handle_sigchld();
4228 defined(my $pid = fork()) or die("Can't fork: $!");
4229 if ($pid) {
4230 eval {
4231 # Give the server a chance to start up
4232 sleep(2);
4233
4234 my $client = Net::FTPSSL->new('127.0.0.1',
4235 Encryption => 'E',
4236 Port => $port,
4237 Croak => 1,
4238 );
4239
4240 unless ($client->login($user, $passwd)) {
4241 die("Can't login: " . $client->last_message());
4242 }
4243
4244 # Since we are NOT requiring SSL session reuse for data transfers,
4245 # and this client is not using SSL session resumption, I expect
4246 # this data transfer to succeed.
4247 my $res = $client->list('.');
4248 unless ($res) {
4249 die("LIST failed unexpectedly: " . $client->message());
4250 }
4251 };
4252
4253 if ($@) {
4254 $ex = $@;
4255 }
4256
4257 $wfh->print("done\n");
4258 $wfh->flush();
4259
4260 } else {
4261 eval { server_wait($config_file, $rfh) };
4262 if ($@) {
4263 warn($@);
4264 exit 1;
4265 }
4266
4267 exit 0;
4268 }
4269
4270 # Stop server
4271 server_stop($pid_file);
4272
4273 $self->assert_child_ok($pid);
4274
4275 if ($ex) {
4276 test_append_logfile($log_file, $ex);
4277 unlink($log_file);
4278
4279 die($ex);
4280 }
4281
4282 unlink($log_file);
4283 }
4284
4285 sub tls_list_fails_tls_required_by_dir_bug2178 {
4286 my $self = shift;
4287 my $tmpdir = $self->{tmpdir};
4288 my $setup = test_setup($tmpdir, 'tls');
4289
4290 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4291 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
4292 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4293
4294 my $home_dir = $setup->{home_dir};
4295 if ($^O eq 'darwin') {
4296 # MacOS-specific hack
4297 $home_dir = '/private' . $home_dir;
4298 }
4299
4300 my $config = {
4301 PidFile => $setup->{pid_file},
4302 ScoreboardFile => $setup->{scoreboard_file},
4303 SystemLog => $setup->{log_file},
4304
4305 AuthUserFile => $setup->{auth_user_file},
4306 AuthGroupFile => $setup->{auth_group_file},
4307
4308 Directory => {
4309 $home_dir => {
4310 TLSRequired => 'on',
4311 },
4312 },
4313
4314 IfModules => {
4315 'mod_delay.c' => {
4316 DelayEngine => 'off',
4317 },
4318
4319 'mod_tls.c' => {
4320 TLSEngine => 'on',
4321 TLSLog => $setup->{log_file},
4322 TLSRequired => 'off',
4323 TLSRSACertificateFile => $server_cert,
4324 TLSCACertificateFile => $ca_cert,
4325 TLSOptions => 'NoSessionReuseRequired',
4326 },
4327 },
4328 };
4329
4330 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
4331 $config);
4332
4333 # Open pipes, for use between the parent and child processes. Specifically,
4334 # the child will indicate when it's done with its test by writing a message
4335 # to the parent.
4336 my ($rfh, $wfh);
4337 unless (pipe($rfh, $wfh)) {
4338 die("Can't open pipe: $!");
4339 }
4340
4341 require Net::FTPSSL;
4342
4343 my $ex;
4344
4345 # Fork child
4346 $self->handle_sigchld();
4347 defined(my $pid = fork()) or die("Can't fork: $!");
4348 if ($pid) {
4349 eval {
4350 # Give the server a chance to start up
4351 sleep(2);
4352
4353 my $client;
4354
4355 # IO::Socket::SSL options
4356 my $ssl_opts = {
4357 SSL_use_cert => 1,
4358 SSL_cert_file => $client_cert,
4359 SSL_key_file => $client_cert,
4360 SSL_ca_file => $ca_cert,
4361 };
4362
4363 $client = Net::FTPSSL->new('127.0.0.1',
4364 Croak => 1,
4365 DataProtLevel => 'C',
4366 Encryption => 'E',
4367 Port => $port,
4368 SSL_Client_Certificate => $ssl_opts,
4369 );
4370
4371 unless ($client->login($setup->{user}, $setup->{passwd})) {
4372 die("Can't login: " . $client->last_message());
4373 }
4374
4375 my $res;
4376 eval { $res = $client->list() };
4377 if (!$@ &&
4378 defined($res)) {
4379 die("LIST succeeded unexpectedly");
4380 }
4381
4382 my $resp_msg = $client->last_message();
4383
4384 my $expected = '522 SSL/TLS required on the data channel';
4385 $self->assert($expected eq $resp_msg,
4386 test_msg("Expected response '$expected', got '$resp_msg'"));
4387 };
4388 if ($@) {
4389 $ex = $@;
4390 }
4391
4392 $wfh->print("done\n");
4393 $wfh->flush();
4394
4395 } else {
4396 eval { server_wait($setup->{config_file}, $rfh) };
4397 if ($@) {
4398 warn($@);
4399 exit 1;
4400 }
4401
4402 exit 0;
4403 }
4404
4405 # Stop server
4406 server_stop($setup->{pid_file});
4407 $self->assert_child_ok($pid);
4408
4409 test_cleanup($setup->{log_file}, $ex);
4410 }
4411
4412 sub tls_list_ok_tls_required_by_dir_bug2178 {
4413 my $self = shift;
4414 my $tmpdir = $self->{tmpdir};
4415
4416 my $config_file = "$tmpdir/tls.conf";
4417 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
4418 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
4419
4420 my $log_file = test_get_logfile();
4421
4422 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
4423 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
4424
4425 my $user = 'proftpd';
4426 my $passwd = 'test';
4427 my $group = 'ftpd';
4428 my $home_dir = File::Spec->rel2abs($tmpdir);
4429 my $uid = 500;
4430 my $gid = 500;
4431
4432 # Make sure that, if we're running as root, that the home directory has
4433 # permissions/privs set for the account we create
4434 if ($< == 0) {
4435 unless (chmod(0755, $home_dir)) {
4436 die("Can't set perms on $home_dir to 0755: $!");
4437 }
4438
4439 unless (chown($uid, $gid, $home_dir)) {
4440 die("Can't set owner of $home_dir to $uid/$gid: $!");
4441 }
4442 }
4443
4444 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4445 '/bin/bash');
4446 auth_group_write($auth_group_file, $group, $gid, $user);
4447
4448 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4449 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
4450 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4451
4452 my $config = {
4453 PidFile => $pid_file,
4454 ScoreboardFile => $scoreboard_file,
4455 SystemLog => $log_file,
4456
4457 AuthUserFile => $auth_user_file,
4458 AuthGroupFile => $auth_group_file,
4459
4460 Directory => {
4461 $home_dir => {
4462 TLSRequired => 'on',
4463 },
4464 },
4465
4466 IfModules => {
4467 'mod_delay.c' => {
4468 DelayEngine => 'off',
4469 },
4470
4471 'mod_tls.c' => {
4472 TLSEngine => 'on',
4473 TLSLog => $log_file,
4474 TLSRequired => 'off',
4475 TLSRSACertificateFile => $server_cert,
4476 TLSCACertificateFile => $ca_cert,
4477 TLSOptions => 'NoSessionReuseRequired',
4478 },
4479 },
4480 };
4481
4482 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4483
4484 # Open pipes, for use between the parent and child processes. Specifically,
4485 # the child will indicate when it's done with its test by writing a message
4486 # to the parent.
4487 my ($rfh, $wfh);
4488 unless (pipe($rfh, $wfh)) {
4489 die("Can't open pipe: $!");
4490 }
4491
4492 require Net::FTPSSL;
4493
4494 my $ex;
4495
4496 # Fork child
4497 $self->handle_sigchld();
4498 defined(my $pid = fork()) or die("Can't fork: $!");
4499 if ($pid) {
4500 eval {
4501 # Give the server a chance to start up
4502 sleep(2);
4503
4504 my $client;
4505
4506 # IO::Socket::SSL options
4507 my $ssl_opts = {
4508 SSL_use_cert => 1,
4509 SSL_cert_file => $client_cert,
4510 SSL_key_file => $client_cert,
4511 SSL_ca_file => $ca_cert,
4512 };
4513
4514 $client = Net::FTPSSL->new('127.0.0.1',
4515 Croak => 1,
4516 DataProtLevel => 'P',
4517 Encryption => 'E',
4518 Port => $port,
4519 SSL_Client_Certificate => $ssl_opts,
4520 );
4521
4522 unless ($client->login($user, $passwd)) {
4523 die("Can't login: " . $client->last_message());
4524 }
4525
4526 my $res = $client->list();
4527 unless ($res) {
4528 die("LIST failed unexpectedly: " . $client->last_message());
4529 }
4530
4531 my $resp_msg = $client->last_message();
4532 $client->quit();
4533
4534 my $expected = '226 Transfer complete';
4535 $self->assert($expected eq $resp_msg,
4536 test_msg("Expected '$expected', got '$resp_msg'"));
4537 };
4538
4539 if ($@) {
4540 $ex = $@;
4541 }
4542
4543 $wfh->print("done\n");
4544 $wfh->flush();
4545
4546 } else {
4547 eval { server_wait($config_file, $rfh) };
4548 if ($@) {
4549 warn($@);
4550 exit 1;
4551 }
4552
4553 exit 0;
4554 }
4555
4556 # Stop server
4557 server_stop($pid_file);
4558
4559 $self->assert_child_ok($pid);
4560
4561 if ($ex) {
4562 test_append_logfile($log_file, $ex);
4563 unlink($log_file);
4564
4565 die($ex);
4566 }
4567
4568 unlink($log_file);
4569 }
4570
4571 sub tls_list_fails_tls_required_by_ftpaccess_bug2178 {
4572 my $self = shift;
4573 my $tmpdir = $self->{tmpdir};
4574
4575 my $config_file = "$tmpdir/tls.conf";
4576 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
4577 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
4578
4579 my $log_file = test_get_logfile();
4580
4581 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
4582 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
4583
4584 my $user = 'proftpd';
4585 my $passwd = 'test';
4586 my $group = 'ftpd';
4587 my $home_dir = File::Spec->rel2abs($tmpdir);
4588 my $uid = 500;
4589 my $gid = 500;
4590
4591 # Make sure that, if we're running as root, that the home directory has
4592 # permissions/privs set for the account we create
4593 if ($< == 0) {
4594 unless (chmod(0755, $home_dir)) {
4595 die("Can't set perms on $home_dir to 0755: $!");
4596 }
4597
4598 unless (chown($uid, $gid, $home_dir)) {
4599 die("Can't set owner of $home_dir to $uid/$gid: $!");
4600 }
4601 }
4602
4603 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4604 '/bin/bash');
4605 auth_group_write($auth_group_file, $group, $gid, $user);
4606
4607 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4608 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
4609 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4610
4611 my $sub_dir = File::Spec->rel2abs("$home_dir/subdir");
4612 mkpath($sub_dir);
4613
4614 my $access_file = File::Spec->rel2abs("$sub_dir/.ftpaccess");
4615 if (open(my $fh, "> $access_file")) {
4616 print $fh "TLSRequired on\n";
4617 unless (close($fh)) {
4618 die("Can't write $access_file: $!");
4619 }
4620
4621 } else {
4622 die("Can't open $access_file: $!");
4623 }
4624
4625 my $config = {
4626 PidFile => $pid_file,
4627 ScoreboardFile => $scoreboard_file,
4628 SystemLog => $log_file,
4629 TraceLog => $log_file,
4630 Trace => 'DEFAULT:10 directory:20 ftpaccess:20',
4631
4632 AllowOverride => 'on',
4633 AuthUserFile => $auth_user_file,
4634 AuthGroupFile => $auth_group_file,
4635
4636 IfModules => {
4637 'mod_delay.c' => {
4638 DelayEngine => 'off',
4639 },
4640
4641 'mod_tls.c' => {
4642 TLSEngine => 'on',
4643 TLSLog => $log_file,
4644 TLSRequired => 'off',
4645 TLSRSACertificateFile => $server_cert,
4646 TLSCACertificateFile => $ca_cert,
4647 TLSOptions => 'NoSessionReuseRequired',
4648 },
4649 },
4650 };
4651
4652 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4653
4654 # Open pipes, for use between the parent and child processes. Specifically,
4655 # the child will indicate when it's done with its test by writing a message
4656 # to the parent.
4657 my ($rfh, $wfh);
4658 unless (pipe($rfh, $wfh)) {
4659 die("Can't open pipe: $!");
4660 }
4661
4662 require Net::FTPSSL;
4663
4664 my $ex;
4665
4666 # Fork child
4667 $self->handle_sigchld();
4668 defined(my $pid = fork()) or die("Can't fork: $!");
4669 if ($pid) {
4670 eval {
4671 # Give the server a chance to start up
4672 sleep(2);
4673
4674 my $client;
4675
4676 # IO::Socket::SSL options
4677 my $ssl_opts = {
4678 SSL_use_cert => 1,
4679 SSL_cert_file => $client_cert,
4680 SSL_key_file => $client_cert,
4681 SSL_ca_file => $ca_cert,
4682 };
4683
4684 $client = Net::FTPSSL->new('127.0.0.1',
4685 Croak => 1,
4686 DataProtLevel => 'C',
4687 Encryption => 'E',
4688 Port => $port,
4689 SSL_Client_Certificate => $ssl_opts,
4690 );
4691
4692 unless ($client->login($user, $passwd)) {
4693 die("Can't login: " . $client->last_message());
4694 }
4695
4696 $client->cwd('subdir');
4697
4698 my $res;
4699 eval { $res = $client->list() };
4700 unless ($@) {
4701 die("LIST succeeded unexpectedly");
4702 }
4703
4704 my $resp_msg = $client->last_message();
4705
4706 my $expected = '522 SSL/TLS required on the data channel';
4707 $self->assert($expected eq $resp_msg,
4708 test_msg("Expected '$expected', got '$resp_msg'"));
4709 };
4710
4711 if ($@) {
4712 $ex = $@;
4713 }
4714
4715 $wfh->print("done\n");
4716 $wfh->flush();
4717
4718 } else {
4719 eval { server_wait($config_file, $rfh) };
4720 if ($@) {
4721 warn($@);
4722 exit 1;
4723 }
4724
4725 exit 0;
4726 }
4727
4728 # Stop server
4729 server_stop($pid_file);
4730
4731 $self->assert_child_ok($pid);
4732
4733 if ($ex) {
4734 test_append_logfile($log_file, $ex);
4735 unlink($log_file);
4736
4737 die($ex);
4738 }
4739
4740 unlink($log_file);
4741 }
4742
4743 sub tls_list_ok_tls_required_by_ftpaccess_bug2178 {
4744 my $self = shift;
4745 my $tmpdir = $self->{tmpdir};
4746
4747 my $config_file = "$tmpdir/tls.conf";
4748 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
4749 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
4750
4751 my $log_file = test_get_logfile();
4752
4753 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
4754 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
4755
4756 my $user = 'proftpd';
4757 my $passwd = 'test';
4758 my $group = 'ftpd';
4759 my $home_dir = File::Spec->rel2abs($tmpdir);
4760 my $uid = 500;
4761 my $gid = 500;
4762
4763 # Make sure that, if we're running as root, that the home directory has
4764 # permissions/privs set for the account we create
4765 if ($< == 0) {
4766 unless (chmod(0755, $home_dir)) {
4767 die("Can't set perms on $home_dir to 0755: $!");
4768 }
4769
4770 unless (chown($uid, $gid, $home_dir)) {
4771 die("Can't set owner of $home_dir to $uid/$gid: $!");
4772 }
4773 }
4774
4775 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4776 '/bin/bash');
4777 auth_group_write($auth_group_file, $group, $gid, $user);
4778
4779 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4780 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
4781 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4782
4783 my $sub_dir = File::Spec->rel2abs("$home_dir/subdir");
4784 mkpath($sub_dir);
4785
4786 my $access_file = File::Spec->rel2abs("$sub_dir/.ftpaccess");
4787 if (open(my $fh, "> $access_file")) {
4788 print $fh "TLSRequired on\n";
4789 unless (close($fh)) {
4790 die("Can't write $access_file: $!");
4791 }
4792
4793 } else {
4794 die("Can't open $access_file: $!");
4795 }
4796
4797 my $config = {
4798 PidFile => $pid_file,
4799 ScoreboardFile => $scoreboard_file,
4800 SystemLog => $log_file,
4801
4802 AllowOverride => 'on',
4803 AuthUserFile => $auth_user_file,
4804 AuthGroupFile => $auth_group_file,
4805
4806 IfModules => {
4807 'mod_delay.c' => {
4808 DelayEngine => 'off',
4809 },
4810
4811 'mod_tls.c' => {
4812 TLSEngine => 'on',
4813 TLSLog => $log_file,
4814 TLSRequired => 'off',
4815 TLSRSACertificateFile => $server_cert,
4816 TLSCACertificateFile => $ca_cert,
4817 TLSOptions => 'NoSessionReuseRequired',
4818 },
4819 },
4820 };
4821
4822 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4823
4824 # Open pipes, for use between the parent and child processes. Specifically,
4825 # the child will indicate when it's done with its test by writing a message
4826 # to the parent.
4827 my ($rfh, $wfh);
4828 unless (pipe($rfh, $wfh)) {
4829 die("Can't open pipe: $!");
4830 }
4831
4832 require Net::FTPSSL;
4833
4834 my $ex;
4835
4836 # Fork child
4837 $self->handle_sigchld();
4838 defined(my $pid = fork()) or die("Can't fork: $!");
4839 if ($pid) {
4840 eval {
4841 # Give the server a chance to start up
4842 sleep(2);
4843
4844 my $client;
4845
4846 # IO::Socket::SSL options
4847 my $ssl_opts = {
4848 SSL_use_cert => 1,
4849 SSL_cert_file => $client_cert,
4850 SSL_key_file => $client_cert,
4851 SSL_ca_file => $ca_cert,
4852 };
4853
4854 $client = Net::FTPSSL->new('127.0.0.1',
4855 Croak => 1,
4856 DataProtLevel => 'P',
4857 Encryption => 'E',
4858 Port => $port,
4859 SSL_Client_Certificate => $ssl_opts,
4860 );
4861
4862 unless ($client->login($user, $passwd)) {
4863 die("Can't login: " . $client->last_message());
4864 }
4865
4866 $client->cwd('subdir');
4867 my $res = $client->list();
4868 if ($res) {
4869 die("LIST succeeded unexpectedly");
4870 }
4871
4872 my $resp_msg = $client->last_message();
4873 $client->quit();
4874
4875 my $expected = '226 Transfer complete';
4876 $self->assert($expected eq $resp_msg,
4877 test_msg("Expected '$expected', got '$resp_msg'"));
4878 };
4879
4880 if ($@) {
4881 $ex = $@;
4882 }
4883
4884 $wfh->print("done\n");
4885 $wfh->flush();
4886
4887 } else {
4888 eval { server_wait($config_file, $rfh) };
4889 if ($@) {
4890 warn($@);
4891 exit 1;
4892 }
4893
4894 exit 0;
4895 }
4896
4897 # Stop server
4898 server_stop($pid_file);
4899
4900 $self->assert_child_ok($pid);
4901
4902 if ($ex) {
4903 test_append_logfile($log_file, $ex);
4904 unlink($log_file);
4905
4906 die($ex);
4907 }
4908
4909 unlink($log_file);
4910 }
4911
4912 sub tls_incompatible_config_bug3247 {
4913 my $self = shift;
4914 my $tmpdir = $self->{tmpdir};
4915
4916 my $config_file = "$tmpdir/tls.conf";
4917 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
4918 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
4919
4920 my $log_file = test_get_logfile();
4921
4922 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4923 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
4924 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4925
4926 my $config = {
4927 PidFile => $pid_file,
4928 ScoreboardFile => $scoreboard_file,
4929 SystemLog => $log_file,
4930
4931 IfModules => {
4932 'mod_delay.c' => {
4933 DelayEngine => 'off',
4934 },
4935
4936 'mod_tls.c' => {
4937 TLSEngine => 'on',
4938 TLSLog => $log_file,
4939 TLSRequired => 'auth',
4940 TLSRSACertificateFile => $server_cert,
4941 TLSCACertificateFile => $ca_cert,
4942 TLSOptions => 'AllowPerUser',
4943 },
4944 },
4945 };
4946
4947 my ($port, $config_user, $config_group) = config_write($config_file, $config);
4948
4949 eval { server_start($config_file, $pid_file) };
4950 unless ($@) {
4951 test_append_logfile($log_file, "server started unexpectedly");
4952 unlink($log_file);
4953
4954 die("server started unexpectedly");
4955 }
4956
4957 unlink($log_file);
4958 }
4959
4960 sub tls_implicit_ssl_bug3266 {
4961 my $self = shift;
4962 my $tmpdir = $self->{tmpdir};
4963
4964 my $config_file = "$tmpdir/tls.conf";
4965 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
4966 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
4967
4968 my $log_file = test_get_logfile();
4969
4970 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
4971 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
4972
4973 my $user = 'proftpd';
4974 my $passwd = 'test';
4975 my $group = 'ftpd';
4976 my $home_dir = File::Spec->rel2abs($tmpdir);
4977 my $uid = 500;
4978 my $gid = 500;
4979
4980 # Make sure that, if we're running as root, that the home directory has
4981 # permissions/privs set for the account we create
4982 if ($< == 0) {
4983 unless (chmod(0755, $home_dir)) {
4984 die("Can't set perms on $home_dir to 0755: $!");
4985 }
4986
4987 unless (chown($uid, $gid, $home_dir)) {
4988 die("Can't set owner of $home_dir to $uid/$gid: $!");
4989 }
4990 }
4991
4992 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
4993 '/bin/bash');
4994 auth_group_write($auth_group_file, $group, $gid, $user);
4995
4996 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
4997 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
4998
4999 my $config = {
5000
5001 # The stupid Net::FTPSSL client requires port 990 when implicit
5002 # FTPS is used, regardless of the port we pass to the constructor.
5003 # (What kind of client API does not allow the port to be changed??)
5004 Port => 990,
5005
5006 PidFile => $pid_file,
5007 ScoreboardFile => $scoreboard_file,
5008 SystemLog => $log_file,
5009 TraceLog => $log_file,
5010 Trace => 'DEFAULT:10',
5011
5012 AuthUserFile => $auth_user_file,
5013 AuthGroupFile => $auth_group_file,
5014
5015 IfModules => {
5016 'mod_delay.c' => {
5017 DelayEngine => 'off',
5018 },
5019
5020 'mod_tls.c' => {
5021 TLSEngine => 'on',
5022 TLSLog => $log_file,
5023 TLSRequired => 'on',
5024 TLSOptions => 'UseImplicitSSL',
5025 TLSRSACertificateFile => $cert_file,
5026 TLSCACertificateFile => $ca_file,
5027 },
5028 },
5029 };
5030
5031 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5032
5033 # Open pipes, for use between the parent and child processes. Specifically,
5034 # the child will indicate when it's done with its test by writing a message
5035 # to the parent.
5036 my ($rfh, $wfh);
5037 unless (pipe($rfh, $wfh)) {
5038 die("Can't open pipe: $!");
5039 }
5040
5041 require Net::FTPSSL;
5042
5043 my $ex;
5044
5045 # Fork child
5046 $self->handle_sigchld();
5047 defined(my $pid = fork()) or die("Can't fork: $!");
5048 if ($pid) {
5049 eval {
5050 # Give the server a chance to start up
5051 sleep(2);
5052
5053 my $client_opts = {
5054 Encryption => 'I',
5055 Port => $port,
5056 };
5057
5058 if ($ENV{TEST_VERBOSE}) {
5059 $client_opts->{Debug} = 1;
5060 }
5061
5062 my $client = Net::FTPSSL->new('127.0.0.1', %$client_opts);
5063
5064 unless ($client) {
5065 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
5066 }
5067
5068 unless ($client->login($user, $passwd)) {
5069 die("Can't login: " . $client->last_message());
5070 }
5071 };
5072
5073 if ($@) {
5074 $ex = $@;
5075 }
5076
5077 $wfh->print("done\n");
5078 $wfh->flush();
5079
5080 } else {
5081 eval { server_wait($config_file, $rfh) };
5082 if ($@) {
5083 warn($@);
5084 exit 1;
5085 }
5086
5087 exit 0;
5088 }
5089
5090 # Stop server
5091 server_stop($pid_file);
5092
5093 $self->assert_child_ok($pid);
5094
5095 if ($ex) {
5096 test_append_logfile($log_file, $ex);
5097 unlink($log_file);
5098
5099 die($ex);
5100 }
5101
5102 unlink($log_file);
5103 }
5104
5105 sub tls_client_cert_verify_failed_embedded_nul_bug3275 {
5106 my $self = shift;
5107 my $tmpdir = $self->{tmpdir};
5108 my $setup = test_setup($tmpdir, 'tls');
5109
5110 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
5111 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-nul-subjaltname.pem');
5112
5113 # The cert/key with embedded NULs in the subjAltName field were obtained
5114 # from:
5115 #
5116 # http://people.redhat.com/thoger/certs-with-nuls/
5117
5118 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/cert-nul-subjaltname.pem');
5119 my $client_key = File::Spec->rel2abs('t/etc/modules/mod_tls/key-nul-subjaltname.pem');
5120
5121 my $config = {
5122 PidFile => $setup->{pid_file},
5123 ScoreboardFile => $setup->{scoreboard_file},
5124 SystemLog => $setup->{log_file},
5125 TraceLog => $setup->{log_file},
5126 Trace => 'tls:30',
5127
5128 AuthUserFile => $setup->{auth_user_file},
5129 AuthGroupFile => $setup->{auth_group_file},
5130
5131 IfModules => {
5132 'mod_delay.c' => {
5133 DelayEngine => 'off',
5134 },
5135
5136 'mod_tls.c' => {
5137 TLSEngine => 'on',
5138 TLSLog => $setup->{log_file},
5139 TLSRequired => 'on',
5140 TLSRSACertificateFile => $server_cert,
5141 TLSCACertificateFile => $ca_cert,
5142
5143 TLSVerifyClient => 'on',
5144
5145 # To trigger Bug#3275, we need to verify the subjAltName field in
5146 # the present cert, which means enabling DNS resolution
5147 TLSOptions => 'EnableDiags dNSNameRequired',
5148
5149 # We need to enable reverse DNS resolution as well, for this to work
5150 UseReverseDNS => 'on',
5151 },
5152 },
5153 };
5154
5155 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
5156 $config);
5157
5158 # Open pipes, for use between the parent and child processes. Specifically,
5159 # the child will indicate when it's done with its test by writing a message
5160 # to the parent.
5161 my ($rfh, $wfh);
5162 unless (pipe($rfh, $wfh)) {
5163 die("Can't open pipe: $!");
5164 }
5165
5166 require Net::FTPSSL;
5167
5168 my $ex;
5169
5170 # Fork child
5171 $self->handle_sigchld();
5172 defined(my $pid = fork()) or die("Can't fork: $!");
5173 if ($pid) {
5174 eval {
5175 # Give the server a chance to start up
5176 sleep(2);
5177
5178 # IO::Socket::SSL options
5179 my $ssl_opts = {
5180 SSL_use_cert => 1,
5181 SSL_ca_file => $ca_cert,
5182 SSL_cert_file => $client_cert,
5183 SSL_key_file => $client_key,
5184 SSL_verify_mode => SSL_VERIFY_NONE(),
5185 };
5186
5187 my $client = Net::FTPSSL->new('127.0.0.1',
5188 Croak => 1,
5189 Encryption => 'E',
5190 Port => $port,
5191 SSL_Client_Certificate => $ssl_opts,
5192 );
5193
5194 # Net::FTPSSL is rather stupid, and treats the initial 234 response
5195 # code (indicating that the SSL/TLS handshake should proceed) as
5196 # indicating success _of the handshake_.
5197 #
5198 # Thus if we want to test if the handshake succeeded, we have to
5199 # act as if it did succeed, then try to login (which should fail).
5200 # Sigh.
5201
5202 eval {
5203 unless ($client->login($setup->{user}, $setup->{passwd})) {
5204 die("Can't login: " . $client->last_message());
5205 }
5206 };
5207 unless ($@) {
5208 die("Login succeeded unexpectedly");
5209 }
5210 };
5211 if ($@) {
5212 $ex = $@;
5213 }
5214
5215 $wfh->print("done\n");
5216 $wfh->flush();
5217
5218 } else {
5219 eval { server_wait($setup->{config_file}, $rfh) };
5220 if ($@) {
5221 warn($@);
5222 exit 1;
5223 }
5224
5225 exit 0;
5226 }
5227
5228 # Stop server
5229 server_stop($setup->{pid_file});
5230 $self->assert_child_ok($pid);
5231
5232 unless ($ex) {
5233 test_cleanup($setup->{log_file}, "Test succeeded unexpectedly");
5234 }
5235
5236 # Not quite done yet. To make sure that this test did as expected, we
5237 # need to examine the log file, and look for the phrase 'spoof attempt'.
5238 # That indicates that mod_tls saw the embedded NUL.
5239 eval {
5240 if (open(my $fh, "< $setup->{log_file}")) {
5241 my $ok = 0;
5242
5243 while (my $line = <$fh>) {
5244 chomp($line);
5245
5246 if ($ENV{TEST_VERBOSE}) {
5247 print STDERR "# $line\n";
5248 }
5249
5250 if ($line =~ /spoof attempt/) {
5251 $ok = 1;
5252 last;
5253 }
5254 }
5255
5256 close($fh);
5257
5258 unless ($ok) {
5259 die("Expected TLSLog 'spoof attempt' not found as expected");
5260 }
5261
5262 } else {
5263 die("Can't read $setup->{log_file}: $!");
5264 }
5265 };
5266 if ($@) {
5267 $ex = $@;
5268 }
5269
5270 test_cleanup($setup->{log_file}, $ex);
5271 }
5272
5273 sub tls_opts_std_env_vars {
5274 my $self = shift;
5275 my $tmpdir = $self->{tmpdir};
5276 my $setup = test_setup($tmpdir, 'tls');
5277
5278 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5279
5280 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
5281 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
5282
5283 my $config = {
5284 PidFile => $setup->{pid_file},
5285 ScoreboardFile => $setup->{scoreboard_file},
5286 SystemLog => $setup->{log_file},
5287 TraceLog => $setup->{log_file},
5288 Trace => 'tls:20',
5289
5290 AuthUserFile => $setup->{auth_user_file},
5291 AuthGroupFile => $setup->{auth_group_file},
5292
5293 # Yes, this has a deliberately wrong variable for TLS_CLIENT_S_DN;
5294 # I use it to make sure that mod_log handles that particular formatting
5295 # as one would expect (i.e. replace it with an empty string).
5296 LogFormat => 'custom "FTPS=%{FTPS}e TLS_PROTOCOL=%{TLS_PROTOCOL}e TLS_SESSION_ID=%{TLS_SESSION_ID}e TLS_CIPHER=%{TLS_CIPHER}e TLS_LIBRARY_VERSION=%{TLS_LIBRARY_VERSION}e TLS_CLIENT_S_DN=\'%{env:TLS_CLIENT_S_DN}\'"',
5297 ExtendedLog => "$ext_log AUTH custom",
5298
5299 IfModules => {
5300 'mod_delay.c' => {
5301 DelayEngine => 'off',
5302 },
5303
5304 'mod_tls.c' => {
5305 TLSEngine => 'on',
5306 TLSLog => $setup->{log_file},
5307 TLSRequired => 'on',
5308 TLSRSACertificateFile => $cert_file,
5309 TLSCACertificateFile => $ca_file,
5310 TLSOptions => 'EnableDiags StdEnvVars',
5311
5312 # TLSv1.3 does not use session IDs
5313 TLSProtocol => 'TLSv1 TLSv1.1 TLSv1.2',
5314 },
5315 },
5316 };
5317
5318 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
5319 $config);
5320
5321 # Open pipes, for use between the parent and child processes. Specifically,
5322 # the child will indicate when it's done with its test by writing a message
5323 # to the parent.
5324 my ($rfh, $wfh);
5325 unless (pipe($rfh, $wfh)) {
5326 die("Can't open pipe: $!");
5327 }
5328
5329 require Net::FTPSSL;
5330
5331 my $ex;
5332
5333 # Fork child
5334 $self->handle_sigchld();
5335 defined(my $pid = fork()) or die("Can't fork: $!");
5336 if ($pid) {
5337 eval {
5338 # Give the server a chance to start up
5339 sleep(2);
5340
5341 my $client = Net::FTPSSL->new('127.0.0.1',
5342 Encryption => 'E',
5343 Port => $port,
5344 );
5345
5346 unless ($client) {
5347 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
5348 }
5349
5350 unless ($client->login($setup->{user}, $setup->{passwd})) {
5351 die("Can't login: " . $client->last_message());
5352 }
5353
5354 $client->quit();
5355 };
5356 if ($@) {
5357 $ex = $@;
5358 }
5359
5360 $wfh->print("done\n");
5361 $wfh->flush();
5362
5363 } else {
5364 eval { server_wait($setup->{config_file}, $rfh) };
5365 if ($@) {
5366 warn($@);
5367 exit 1;
5368 }
5369
5370 exit 0;
5371 }
5372
5373 # Stop server
5374 server_stop($setup->{pid_file});
5375 $self->assert_child_ok($pid);
5376
5377 test_cleanup($setup->{log_file}, $ex) if $ex;
5378
5379 # Open the ExtendedLog, and check for the expected environment variables
5380 eval {
5381 if (open(my $fh, "< $ext_log")) {
5382 my $ok = 0;
5383
5384 while (my $line = <$fh>) {
5385 chomp($line);
5386
5387 if ($ENV{TEST_VERBOSE}) {
5388 print STDERR "# $line\n";
5389 }
5390
5391 if ($line =~ /FTPS=(\d+) TLS_PROTOCOL=(\S+) TLS_SESSION_ID=(\S+) TLS_CIPHER=(\S+) TLS_LIBRARY_VERSION=(.*?) TLS_CLIENT_S_DN=''/) {
5392 my $ftps = $1;
5393 my $protocol = $2;
5394 my $sess_id = $3;
5395 my $cipher = $4;
5396 my $libversion = $5;
5397
5398 $self->assert($ftps eq '1',
5399 test_msg("Expected '1', got '$ftps'"));
5400 $self->assert(length($protocol) > 0,
5401 test_msg("Expected protocol, got '$protocol'"));
5402 $self->assert(length($sess_id) > 0,
5403 test_msg("Expected session ID, got '$sess_id'"));
5404 $self->assert(length($cipher) > 0,
5405 test_msg("Expected cipher, got '$cipher"));
5406 $self->assert(length($libversion) > 0,
5407 test_msg("Expected cipher, got '$libversion"));
5408
5409 $ok = 1;
5410 last;
5411
5412 } else {
5413 die("Mismatched ExtendedLog line '$line'");
5414 }
5415 }
5416
5417 close($fh);
5418
5419 unless ($ok) {
5420 die("Unexpected environment variable values in ExtendedLog");
5421 }
5422
5423 } else {
5424 die("Can't read $ext_log: $!");
5425 }
5426 };
5427 if ($@) {
5428 $ex = $@;
5429 }
5430
5431 test_cleanup($setup->{log_file}, $ex);
5432 }
5433
5434 sub tls_opts_std_env_vars_client_vars {
5435 my $self = shift;
5436 my $tmpdir = $self->{tmpdir};
5437
5438 my $config_file = "$tmpdir/tls.conf";
5439 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
5440 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
5441
5442 my $log_file = test_get_logfile();
5443
5444 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
5445 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
5446
5447 my $user = 'proftpd';
5448 my $passwd = 'test';
5449 my $group = 'ftpd';
5450 my $home_dir = File::Spec->rel2abs($tmpdir);
5451 my $uid = 500;
5452 my $gid = 500;
5453
5454 # Make sure that, if we're running as root, that the home directory has
5455 # permissions/privs set for the account we create
5456 if ($< == 0) {
5457 unless (chmod(0755, $home_dir)) {
5458 die("Can't set perms on $home_dir to 0755: $!");
5459 }
5460
5461 unless (chown($uid, $gid, $home_dir)) {
5462 die("Can't set owner of $home_dir to $uid/$gid: $!");
5463 }
5464 }
5465
5466 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5467 '/bin/bash');
5468 auth_group_write($auth_group_file, $group, $gid, $user);
5469
5470 my $ext_log = File::Spec->rel2abs("$tmpdir/custom.log");
5471
5472 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
5473 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
5474 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
5475
5476 my $config = {
5477 PidFile => $pid_file,
5478 ScoreboardFile => $scoreboard_file,
5479 SystemLog => $log_file,
5480
5481 AuthUserFile => $auth_user_file,
5482 AuthGroupFile => $auth_group_file,
5483
5484 LogFormat => 'custom "TLS_CLIENT_S_DN=\'%{TLS_CLIENT_S_DN}e\' TLS_CLIENT_I_DN=\'%{TLS_CLIENT_I_DN}e\'"',
5485 ExtendedLog => "$ext_log AUTH custom",
5486
5487 IfModules => {
5488 'mod_delay.c' => {
5489 DelayEngine => 'off',
5490 },
5491
5492 'mod_tls.c' => {
5493 TLSEngine => 'on',
5494 TLSLog => $log_file,
5495 TLSRequired => 'on',
5496 TLSRSACertificateFile => $cert_file,
5497 TLSCACertificateFile => $ca_file,
5498 TLSOptions => 'StdEnvVars',
5499 TLSVerifyClient => 'optional',
5500 },
5501 },
5502 };
5503
5504 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5505
5506 # Open pipes, for use between the parent and child processes. Specifically,
5507 # the child will indicate when it's done with its test by writing a message
5508 # to the parent.
5509 my ($rfh, $wfh);
5510 unless (pipe($rfh, $wfh)) {
5511 die("Can't open pipe: $!");
5512 }
5513
5514 require Net::FTPSSL;
5515
5516 my $ex;
5517
5518 # Fork child
5519 $self->handle_sigchld();
5520 defined(my $pid = fork()) or die("Can't fork: $!");
5521 if ($pid) {
5522 eval {
5523 # Give the server a chance to start up
5524 sleep(2);
5525
5526 # IO::Socket::SSL options
5527 my $ssl_opts = {
5528 SSL_use_cert => 1,
5529 SSL_cert_file => $client_cert,
5530 SSL_key_file => $client_cert,
5531 SSL_ca_file => $ca_file,
5532 };
5533
5534 my $client = Net::FTPSSL->new('127.0.0.1',
5535 Croak => 1,
5536 Encryption => 'E',
5537 Port => $port,
5538 SSL_Client_Certificate => $ssl_opts,
5539 );
5540
5541 unless ($client) {
5542 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
5543 }
5544
5545 unless ($client->login($user, $passwd)) {
5546 die("Can't login: " . $client->last_message());
5547 }
5548
5549 $client->quit();
5550 };
5551
5552 if ($@) {
5553 $ex = $@;
5554 }
5555
5556 $wfh->print("done\n");
5557 $wfh->flush();
5558
5559 } else {
5560 eval { server_wait($config_file, $rfh) };
5561 if ($@) {
5562 warn($@);
5563 exit 1;
5564 }
5565
5566 exit 0;
5567 }
5568
5569 # Stop server
5570 server_stop($pid_file);
5571
5572 $self->assert_child_ok($pid);
5573
5574 if ($ex) {
5575 die($ex);
5576 }
5577
5578 # Open the ExtendedLog, and check for the expected environment variables
5579 if (open(my $fh, "< $ext_log")) {
5580 my $ok = 0;
5581
5582 while (my $line = <$fh>) {
5583 chomp($line);
5584
5585 if ($line =~ /TLS_CLIENT_S_DN='(.*?)' TLS_CLIENT_I_DN='(.*?)'/) {
5586 my $subj_dn = $1;
5587 my $issuer_dn = $2;
5588
5589 $self->assert(length($subj_dn) > 0,
5590 test_msg("Expected subject DN, got '$subj_dn'"));
5591 $self->assert(length($issuer_dn) > 0,
5592 test_msg("Expected issuer DN, got '$issuer_dn'"));
5593
5594 $ok = 1;
5595 last;
5596
5597 } else {
5598 die("Mismatched ExtendedLog line '$line'");
5599 }
5600 }
5601
5602 close($fh);
5603
5604 unless ($ok) {
5605 die("Unexpected environment variable values in ExtendedLog");
5606 }
5607
5608 } else {
5609 die("Can't read $ext_log: $!");
5610 }
5611
5612 unlink($log_file);
5613 }
5614
5615 sub tls_opts_ipaddr_required_ipv4 {
5616 my $self = shift;
5617 my $tmpdir = $self->{tmpdir};
5618
5619 my $config_file = "$tmpdir/tls.conf";
5620 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
5621 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
5622
5623 my $log_file = test_get_logfile();
5624
5625 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
5626 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
5627
5628 my $user = 'proftpd';
5629 my $passwd = 'test';
5630 my $group = 'ftpd';
5631 my $home_dir = File::Spec->rel2abs($tmpdir);
5632 my $uid = 500;
5633 my $gid = 500;
5634
5635 # Make sure that, if we're running as root, that the home directory has
5636 # permissions/privs set for the account we create
5637 if ($< == 0) {
5638 unless (chmod(0755, $home_dir)) {
5639 die("Can't set perms on $home_dir to 0755: $!");
5640 }
5641
5642 unless (chown($uid, $gid, $home_dir)) {
5643 die("Can't set owner of $home_dir to $uid/$gid: $!");
5644 }
5645 }
5646
5647 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5648 '/bin/bash');
5649 auth_group_write($auth_group_file, $group, $gid, $user);
5650
5651 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
5652 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
5653 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
5654
5655 my $config = {
5656 PidFile => $pid_file,
5657 ScoreboardFile => $scoreboard_file,
5658 SystemLog => $log_file,
5659
5660 AuthUserFile => $auth_user_file,
5661 AuthGroupFile => $auth_group_file,
5662
5663 IfModules => {
5664 'mod_delay.c' => {
5665 DelayEngine => 'off',
5666 },
5667
5668 'mod_tls.c' => {
5669 TLSEngine => 'on',
5670 TLSLog => $log_file,
5671 TLSRequired => 'on',
5672 TLSRSACertificateFile => $cert_file,
5673 TLSCACertificateFile => $ca_file,
5674 TLSOptions => 'iPAddressRequired',
5675 TLSVerifyClient => 'on',
5676 },
5677 },
5678 };
5679
5680 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5681
5682 # Open pipes, for use between the parent and child processes. Specifically,
5683 # the child will indicate when it's done with its test by writing a message
5684 # to the parent.
5685 my ($rfh, $wfh);
5686 unless (pipe($rfh, $wfh)) {
5687 die("Can't open pipe: $!");
5688 }
5689
5690 require Net::FTPSSL;
5691
5692 my $ex;
5693
5694 # Fork child
5695 $self->handle_sigchld();
5696 defined(my $pid = fork()) or die("Can't fork: $!");
5697 if ($pid) {
5698 eval {
5699 # Give the server a chance to start up
5700 sleep(2);
5701
5702 # IO::Socket::SSL options
5703 my $ssl_opts = {
5704 SSL_use_cert => 1,
5705 SSL_cert_file => $client_cert,
5706 SSL_key_file => $client_cert,
5707 SSL_ca_file => $ca_file,
5708 };
5709
5710 my $client;
5711 eval {
5712 $client = Net::FTPSSL->new('127.0.0.1',
5713 Croak => 1,
5714 Encryption => 'E',
5715 Port => $port,
5716 );
5717 };
5718
5719 unless ($@) {
5720 die("Connection to server succeeded unexpectedly");
5721 }
5722
5723 $client = Net::FTPSSL->new('127.0.0.1',
5724 Croak => 1,
5725 Encryption => 'E',
5726 Port => $port,
5727 SSL_Client_Certificate => $ssl_opts,
5728 );
5729
5730 unless ($client->login($user, $passwd)) {
5731 die("Can't login: " . $client->last_message());
5732 }
5733
5734 $client->quit();
5735 };
5736
5737 if ($@) {
5738 $ex = $@;
5739 }
5740
5741 $wfh->print("done\n");
5742 $wfh->flush();
5743
5744 } else {
5745 eval { server_wait($config_file, $rfh) };
5746 if ($@) {
5747 warn($@);
5748 exit 1;
5749 }
5750
5751 exit 0;
5752 }
5753
5754 # Stop server
5755 server_stop($pid_file);
5756
5757 $self->assert_child_ok($pid);
5758
5759 if ($ex) {
5760 test_append_logfile($log_file, $ex);
5761 unlink($log_file);
5762
5763 die($ex);
5764 }
5765
5766 unlink($log_file);
5767 }
5768
5769 sub tls_opts_ipaddr_required_ipv6 {
5770 my $self = shift;
5771 my $tmpdir = $self->{tmpdir};
5772
5773 my $config_file = "$tmpdir/tls.conf";
5774 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
5775 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
5776
5777 my $log_file = test_get_logfile();
5778
5779 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
5780 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
5781
5782 my $user = 'proftpd';
5783 my $passwd = 'test';
5784 my $group = 'ftpd';
5785 my $home_dir = File::Spec->rel2abs($tmpdir);
5786 my $uid = 500;
5787 my $gid = 500;
5788
5789 # Make sure that, if we're running as root, that the home directory has
5790 # permissions/privs set for the account we create
5791 if ($< == 0) {
5792 unless (chmod(0755, $home_dir)) {
5793 die("Can't set perms on $home_dir to 0755: $!");
5794 }
5795
5796 unless (chown($uid, $gid, $home_dir)) {
5797 die("Can't set owner of $home_dir to $uid/$gid: $!");
5798 }
5799 }
5800
5801 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5802 '/bin/bash');
5803 auth_group_write($auth_group_file, $group, $gid, $user);
5804
5805 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ipv6-client-cert2.pem');
5806 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ipv6-server-cert2.pem');
5807 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ipv6-ca.pem');
5808
5809 my $config = {
5810 PidFile => $pid_file,
5811 ScoreboardFile => $scoreboard_file,
5812 SystemLog => $log_file,
5813 TraceLog => $log_file,
5814 Trace => 'DEFAULT:10',
5815
5816 AuthUserFile => $auth_user_file,
5817 AuthGroupFile => $auth_group_file,
5818
5819 IfModules => {
5820 'mod_delay.c' => {
5821 DelayEngine => 'off',
5822 },
5823
5824 'mod_tls.c' => {
5825 TLSEngine => 'on',
5826 TLSLog => $log_file,
5827 TLSRequired => 'on',
5828 TLSRSACertificateFile => $cert_file,
5829 TLSCACertificateFile => $ca_file,
5830 TLSOptions => 'iPAddressRequired',
5831 TLSVerifyClient => 'on',
5832 },
5833 },
5834 };
5835
5836 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5837
5838 # Open pipes, for use between the parent and child processes. Specifically,
5839 # the child will indicate when it's done with its test by writing a message
5840 # to the parent.
5841 my ($rfh, $wfh);
5842 unless (pipe($rfh, $wfh)) {
5843 die("Can't open pipe: $!");
5844 }
5845
5846 require Net::FTPSSL;
5847
5848 my $ex;
5849
5850 # Fork child
5851 $self->handle_sigchld();
5852 defined(my $pid = fork()) or die("Can't fork: $!");
5853 if ($pid) {
5854 eval {
5855 # Give the server a chance to start up
5856 sleep(2);
5857
5858 # IO::Socket::SSL options
5859 my $ssl_opts = {
5860 SSL_use_cert => 1,
5861 SSL_cert_file => $client_cert,
5862 SSL_key_file => $client_cert,
5863 SSL_ca_file => $ca_file,
5864 };
5865
5866 my $client;
5867 eval {
5868 $client = Net::FTPSSL->new('127.0.0.1',
5869 Croak => 1,
5870 Encryption => 'E',
5871 Port => $port,
5872 );
5873 };
5874
5875 unless ($@) {
5876 die("Connection to server succeeded unexpectedly");
5877 }
5878
5879 $client = Net::FTPSSL->new('127.0.0.1',
5880 Croak => 1,
5881 Encryption => 'E',
5882 Port => $port,
5883 SSL_Client_Certificate => $ssl_opts,
5884 );
5885
5886 unless ($client->login($user, $passwd)) {
5887 die("Can't login: " . $client->last_message());
5888 }
5889
5890 $client->quit();
5891 };
5892
5893 if ($@) {
5894 $ex = $@;
5895 }
5896
5897 $wfh->print("done\n");
5898 $wfh->flush();
5899
5900 } else {
5901 eval { server_wait($config_file, $rfh) };
5902 if ($@) {
5903 warn($@);
5904 exit 1;
5905 }
5906
5907 exit 0;
5908 }
5909
5910 # Stop server
5911 server_stop($pid_file);
5912
5913 $self->assert_child_ok($pid);
5914
5915 if ($ex) {
5916 test_append_logfile($log_file, $ex);
5917 unlink($log_file);
5918
5919 die($ex);
5920 }
5921
5922 unlink($log_file);
5923 }
5924
5925 sub tls_opts_allow_per_user_tlsrequired_on_anon_login_bug3325 {
5926 my $self = shift;
5927 my $tmpdir = $self->{tmpdir};
5928
5929 my $config_file = "$tmpdir/tls.conf";
5930 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
5931 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
5932
5933 my $log_file = test_get_logfile();
5934
5935 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
5936 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
5937
5938 my $user = 'proftpd';
5939 my $passwd = 'test';
5940 my $group = 'ftpd';
5941 my $home_dir = File::Spec->rel2abs($tmpdir);
5942 my $uid = 500;
5943 my $gid = 500;
5944
5945 # Make sure that, if we're running as root, that the home directory has
5946 # permissions/privs set for the account we create
5947 if ($< == 0) {
5948 unless (chmod(0755, $home_dir)) {
5949 die("Can't set perms on $home_dir to 0755: $!");
5950 }
5951
5952 unless (chown($uid, $gid, $home_dir)) {
5953 die("Can't set owner of $home_dir to $uid/$gid: $!");
5954 }
5955 }
5956
5957 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
5958 '/bin/bash');
5959 auth_group_write($auth_group_file, $group, $gid, $user);
5960
5961 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
5962 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
5963 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
5964
5965 my $config = {
5966 PidFile => $pid_file,
5967 ScoreboardFile => $scoreboard_file,
5968 SystemLog => $log_file,
5969
5970 AuthUserFile => $auth_user_file,
5971 AuthGroupFile => $auth_group_file,
5972
5973 IfModules => {
5974 'mod_delay.c' => {
5975 DelayEngine => 'off',
5976 },
5977
5978 'mod_tls.c' => {
5979 TLSEngine => 'on',
5980 TLSLog => $log_file,
5981 TLSRequired => 'on',
5982 TLSRSACertificateFile => $cert_file,
5983 TLSCACertificateFile => $ca_file,
5984 TLSOptions => 'AllowPerUser',
5985 },
5986 },
5987 };
5988
5989 my ($port, $config_user, $config_group) = config_write($config_file, $config);
5990
5991 my ($anon_user, $anon_group) = config_get_identity();
5992
5993 if (open(my $fh, ">> $config_file")) {
5994 print $fh <<EOC;
5995 <Anonymous $home_dir>
5996 User $anon_user
5997 Group $anon_group
5998 UserAlias anonymous $anon_user
5999 RequireValidShell off
6000 TLSRequired off
6001 </Anonymous>
6002 EOC
6003 unless (close($fh)) {
6004 die("Can't write $config_file: $!");
6005 }
6006
6007 } else {
6008 die("Can't open $config_file: $!");
6009 }
6010
6011 # Open pipes, for use between the parent and child processes. Specifically,
6012 # the child will indicate when it's done with its test by writing a message
6013 # to the parent.
6014 my ($rfh, $wfh);
6015 unless (pipe($rfh, $wfh)) {
6016 die("Can't open pipe: $!");
6017 }
6018
6019 require Net::FTPSSL;
6020
6021 my $ex;
6022
6023 # Fork child
6024 $self->handle_sigchld();
6025 defined(my $pid = fork()) or die("Can't fork: $!");
6026 if ($pid) {
6027 eval {
6028 # Give the server a chance to start up
6029 sleep(2);
6030
6031 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6032
6033 # We should be able to connect to the server without SSL, and login
6034 # anonymously without it.
6035 my ($resp_code, $resp_msg) = $client->login('anonymous', '[email protected]');
6036
6037 my $expected;
6038
6039 $expected = 230;
6040 $self->assert($expected == $resp_code,
6041 test_msg("Expected $expected, got $resp_code"));
6042
6043 $expected = 'Anonymous access granted, restrictions apply';
6044 $self->assert($expected eq $resp_msg,
6045 test_msg("Expected '$expected', got '$resp_msg'"));
6046
6047 $client->quit();
6048 };
6049
6050 if ($@) {
6051 $ex = $@;
6052 }
6053
6054 $wfh->print("done\n");
6055 $wfh->flush();
6056
6057 } else {
6058 eval { server_wait($config_file, $rfh) };
6059 if ($@) {
6060 warn($@);
6061 exit 1;
6062 }
6063
6064 exit 0;
6065 }
6066
6067 # Stop server
6068 server_stop($pid_file);
6069
6070 $self->assert_child_ok($pid);
6071
6072 if ($ex) {
6073 test_append_logfile($log_file, $ex);
6074 unlink($log_file);
6075
6076 die($ex);
6077 }
6078
6079 unlink($log_file);
6080 }
6081
6082 sub tls_opts_allow_per_user_tlsrequired_on_user_login_bug3325 {
6083 my $self = shift;
6084 my $tmpdir = $self->{tmpdir};
6085 my $setup = test_setup($tmpdir, 'tls');
6086
6087 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
6088 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6089 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6090
6091 my $config = {
6092 PidFile => $setup->{pid_file},
6093 ScoreboardFile => $setup->{scoreboard_file},
6094 SystemLog => $setup->{log_file},
6095
6096 AuthUserFile => $setup->{auth_user_file},
6097 AuthGroupFile => $setup->{auth_group_file},
6098 AuthOrder => 'mod_auth_file.c',
6099
6100 IfModules => {
6101 'mod_delay.c' => {
6102 DelayEngine => 'off',
6103 },
6104
6105 'mod_tls.c' => {
6106 TLSEngine => 'on',
6107 TLSLog => $setup->{log_file},
6108 TLSRequired => 'on',
6109 TLSRSACertificateFile => $cert_file,
6110 TLSCACertificateFile => $ca_file,
6111 TLSOptions => 'AllowPerUser',
6112 },
6113 },
6114 };
6115
6116 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6117 $config);
6118
6119 my ($anon_user, $anon_group) = config_get_identity();
6120
6121 if (open(my $fh, ">> $setup->{config_file}")) {
6122 print $fh <<EOC;
6123 <Anonymous $setup->{home_dir}>
6124 User $anon_user
6125 Group $anon_group
6126 UserAlias anonymous $anon_user
6127 RequireValidShell off
6128 TLSRequired off
6129 </Anonymous>
6130 EOC
6131 unless (close($fh)) {
6132 die("Can't write $setup->{config_file}: $!");
6133 }
6134
6135 } else {
6136 die("Can't open $setup->{config_file}: $!");
6137 }
6138
6139 # Open pipes, for use between the parent and child processes. Specifically,
6140 # the child will indicate when it's done with its test by writing a message
6141 # to the parent.
6142 my ($rfh, $wfh);
6143 unless (pipe($rfh, $wfh)) {
6144 die("Can't open pipe: $!");
6145 }
6146
6147 require Net::FTPSSL;
6148
6149 my $ex;
6150
6151 # Fork child
6152 $self->handle_sigchld();
6153 defined(my $pid = fork()) or die("Can't fork: $!");
6154 if ($pid) {
6155 eval {
6156 # Give the server a chance to start up
6157 sleep(2);
6158
6159 # With this config, we should not be able to login without SSL/TLS.
6160 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6161
6162 eval { $client->login($setup->{user}, $setup->{passwd}) };
6163 unless ($@) {
6164 die("Login succeeded unexpectedly");
6165 }
6166
6167 my $resp_code = $client->response_code();
6168 my $resp_msg = $client->response_msg();
6169
6170 my $expected = 530;
6171 $self->assert($expected == $resp_code,
6172 test_msg("Expected response code $expected, got $resp_code"));
6173
6174 $expected = 'Login incorrect.';
6175 $self->assert($expected eq $resp_msg,
6176 test_msg("Expected response message '$expected', got '$resp_msg'"));
6177
6178 # Note that we explicitly do not send a QUIT command, since it would fail
6179 # due to the TLS requirement, and the lack of a successful TLS handshake.
6180 };
6181 if ($@) {
6182 $ex = $@;
6183 }
6184
6185 $wfh->print("done\n");
6186 $wfh->flush();
6187
6188 } else {
6189 eval { server_wait($setup->{config_file}, $rfh) };
6190 if ($@) {
6191 warn($@);
6192 exit 1;
6193 }
6194
6195 exit 0;
6196 }
6197
6198 # Stop server
6199 server_stop($setup->{pid_file});
6200 $self->assert_child_ok($pid);
6201
6202 test_cleanup($setup->{log_file}, $ex);
6203 }
6204
6205 sub tls_opts_allow_per_user_tlsrequired_auth_user_login_bug3325 {
6206 my $self = shift;
6207 my $tmpdir = $self->{tmpdir};
6208
6209 my $config_file = "$tmpdir/tls.conf";
6210 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
6211 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
6212
6213 my $log_file = test_get_logfile();
6214
6215 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
6216 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
6217
6218 my $user = 'proftpd';
6219 my $passwd = 'test';
6220 my $group = 'ftpd';
6221 my $home_dir = File::Spec->rel2abs($tmpdir);
6222 my $uid = 500;
6223 my $gid = 500;
6224
6225 # Make sure that, if we're running as root, that the home directory has
6226 # permissions/privs set for the account we create
6227 if ($< == 0) {
6228 unless (chmod(0755, $home_dir)) {
6229 die("Can't set perms on $home_dir to 0755: $!");
6230 }
6231
6232 unless (chown($uid, $gid, $home_dir)) {
6233 die("Can't set owner of $home_dir to $uid/$gid: $!");
6234 }
6235 }
6236
6237 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6238 '/bin/bash');
6239 auth_group_write($auth_group_file, $group, $gid, $user);
6240
6241 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
6242 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6243 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6244
6245 my $config = {
6246 PidFile => $pid_file,
6247 ScoreboardFile => $scoreboard_file,
6248 SystemLog => $log_file,
6249
6250 AuthUserFile => $auth_user_file,
6251 AuthGroupFile => $auth_group_file,
6252
6253 IfModules => {
6254 'mod_delay.c' => {
6255 DelayEngine => 'off',
6256 },
6257
6258 'mod_tls.c' => {
6259 TLSEngine => 'on',
6260 TLSLog => $log_file,
6261 TLSRequired => 'auth',
6262 TLSRSACertificateFile => $cert_file,
6263 TLSCACertificateFile => $ca_file,
6264 TLSOptions => 'AllowPerUser',
6265 },
6266 },
6267 };
6268
6269 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6270
6271 my ($anon_user, $anon_group) = config_get_identity();
6272
6273 if (open(my $fh, ">> $config_file")) {
6274 print $fh <<EOC;
6275 <Anonymous $home_dir>
6276 User $anon_user
6277 Group $anon_group
6278 UserAlias anonymous $anon_user
6279 RequireValidShell off
6280 TLSRequired off
6281 </Anonymous>
6282 EOC
6283 unless (close($fh)) {
6284 die("Can't write $config_file: $!");
6285 }
6286
6287 } else {
6288 die("Can't open $config_file: $!");
6289 }
6290
6291 # Open pipes, for use between the parent and child processes. Specifically,
6292 # the child will indicate when it's done with its test by writing a message
6293 # to the parent.
6294 my ($rfh, $wfh);
6295 unless (pipe($rfh, $wfh)) {
6296 die("Can't open pipe: $!");
6297 }
6298
6299 require Net::FTPSSL;
6300
6301 my $ex;
6302
6303 # Fork child
6304 $self->handle_sigchld();
6305 defined(my $pid = fork()) or die("Can't fork: $!");
6306 if ($pid) {
6307 eval {
6308 # Give the server a chance to start up
6309 sleep(2);
6310
6311 # With this config, we should not be able to login without SSL/TLS
6312 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6313
6314 eval { $client->login($user, $passwd) };
6315 unless ($@) {
6316 die("Login succeeded unexpectedly");
6317 }
6318
6319 my $resp_code = $client->response_code();
6320 my $resp_msg = $client->response_msg();
6321
6322 my $expected;
6323
6324 $expected = 530;
6325 $self->assert($expected == $resp_code,
6326 test_msg("Expected $expected, got $resp_code"));
6327
6328 $expected = "Login incorrect.";
6329 $self->assert($expected eq $resp_msg,
6330 test_msg("Expected '$expected', got '$resp_msg'"));
6331 };
6332
6333 if ($@) {
6334 $ex = $@;
6335 }
6336
6337 $wfh->print("done\n");
6338 $wfh->flush();
6339
6340 } else {
6341 eval { server_wait($config_file, $rfh) };
6342 if ($@) {
6343 warn($@);
6344 exit 1;
6345 }
6346
6347 exit 0;
6348 }
6349
6350 # Stop server
6351 server_stop($pid_file);
6352
6353 $self->assert_child_ok($pid);
6354
6355 if ($ex) {
6356 test_append_logfile($log_file, $ex);
6357 unlink($log_file);
6358
6359 die($ex);
6360 }
6361
6362 unlink($log_file);
6363 }
6364
6365 sub tls_opts_allow_per_user_tlsrequired_off_ifsess_protocols_issue1679 {
6366 my $self = shift;
6367 my $tmpdir = $self->{tmpdir};
6368 my $setup = test_setup($tmpdir, 'tls');
6369
6370 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6371 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6372
6373 my $config = {
6374 PidFile => $setup->{pid_file},
6375 ScoreboardFile => $setup->{scoreboard_file},
6376 SystemLog => $setup->{log_file},
6377
6378 AuthUserFile => $setup->{auth_user_file},
6379 AuthGroupFile => $setup->{auth_group_file},
6380 AuthOrder => 'mod_auth_file.c',
6381
6382 Protocols => 'ftp ftps',
6383
6384 IfModules => {
6385 'mod_delay.c' => {
6386 DelayEngine => 'off',
6387 },
6388
6389 'mod_tls.c' => {
6390 TLSEngine => 'on',
6391 TLSLog => $setup->{log_file},
6392 TLSRequired => 'on',
6393 TLSRSACertificateFile => $cert_file,
6394 TLSCACertificateFile => $ca_file,
6395 TLSOptions => 'AllowPerUser',
6396 },
6397 },
6398 };
6399
6400 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6401 $config);
6402
6403 if (open(my $fh, ">> $setup->{config_file}")) {
6404 print $fh <<EOC;
6405 <IfUser $setup->{user}>
6406 TLSRequired off
6407 </IfUser>
6408 EOC
6409 unless (close($fh)) {
6410 die("Can't write $setup->{config_file}: $!");
6411 }
6412
6413 } else {
6414 die("Can't open $setup->{config_file}: $!");
6415 }
6416
6417 # Open pipes, for use between the parent and child processes. Specifically,
6418 # the child will indicate when it's done with its test by writing a message
6419 # to the parent.
6420 my ($rfh, $wfh);
6421 unless (pipe($rfh, $wfh)) {
6422 die("Can't open pipe: $!");
6423 }
6424
6425 require Net::FTPSSL;
6426
6427 my $ex;
6428
6429 # Fork child
6430 $self->handle_sigchld();
6431 defined(my $pid = fork()) or die("Can't fork: $!");
6432 if ($pid) {
6433 eval {
6434 # Give the server a chance to start up
6435 sleep(2);
6436
6437 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6438 $client->login($setup->{user}, $setup->{passwd});
6439
6440 my $resp_code = $client->response_code();
6441 my $resp_msg = $client->response_msg();
6442
6443 my $expected = 230;
6444 $self->assert($expected == $resp_code,
6445 test_msg("Expected response code $expected, got $resp_code"));
6446
6447 $expected = "User $setup->{user} logged in";
6448 $self->assert($expected eq $resp_msg,
6449 test_msg("Expected response message '$expected', got '$resp_msg'"));
6450 };
6451 if ($@) {
6452 $ex = $@;
6453 }
6454
6455 $wfh->print("done\n");
6456 $wfh->flush();
6457
6458 } else {
6459 eval { server_wait($setup->{config_file}, $rfh) };
6460 if ($@) {
6461 warn($@);
6462 exit 1;
6463 }
6464
6465 exit 0;
6466 }
6467
6468 # Stop server
6469 server_stop($setup->{pid_file});
6470 $self->assert_child_ok($pid);
6471
6472 test_cleanup($setup->{log_file}, $ex);
6473 }
6474
6475 sub tls_opts_allow_per_user_tlsrequired_on_ifsess_no_tls_issue1640 {
6476 my $self = shift;
6477 my $tmpdir = $self->{tmpdir};
6478 my $setup = test_setup($tmpdir, 'tls');
6479
6480 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6481 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6482
6483 my $config = {
6484 PidFile => $setup->{pid_file},
6485 ScoreboardFile => $setup->{scoreboard_file},
6486 SystemLog => $setup->{log_file},
6487
6488 AuthUserFile => $setup->{auth_user_file},
6489 AuthGroupFile => $setup->{auth_group_file},
6490 AuthOrder => 'mod_auth_file.c',
6491
6492 IfModules => {
6493 'mod_delay.c' => {
6494 DelayEngine => 'off',
6495 },
6496
6497 'mod_tls.c' => {
6498 TLSEngine => 'on',
6499 TLSLog => $setup->{log_file},
6500 TLSRequired => 'on',
6501 TLSRSACertificateFile => $cert_file,
6502 TLSCACertificateFile => $ca_file,
6503 TLSOptions => 'AllowPerUser',
6504 },
6505 },
6506 };
6507
6508 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6509 $config);
6510
6511 if (open(my $fh, ">> $setup->{config_file}")) {
6512 print $fh <<EOC;
6513 # This is required
6514 IfSessionOptions PerUnauthenticatedUser
6515
6516 <IfUser !$setup->{user}>
6517 TLSRequired off
6518 </IfUser>
6519 EOC
6520 unless (close($fh)) {
6521 die("Can't write $setup->{config_file}: $!");
6522 }
6523
6524 } else {
6525 die("Can't open $setup->{config_file}: $!");
6526 }
6527
6528 # Open pipes, for use between the parent and child processes. Specifically,
6529 # the child will indicate when it's done with its test by writing a message
6530 # to the parent.
6531 my ($rfh, $wfh);
6532 unless (pipe($rfh, $wfh)) {
6533 die("Can't open pipe: $!");
6534 }
6535
6536 require Net::FTPSSL;
6537
6538 my $ex;
6539
6540 # Fork child
6541 $self->handle_sigchld();
6542 defined(my $pid = fork()) or die("Can't fork: $!");
6543 if ($pid) {
6544 eval {
6545 # Give the server a chance to start up
6546 sleep(2);
6547
6548 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6549 eval { $client->user($setup->{user}) };
6550 unless ($@) {
6551 die("USER succeeded unexpectedly");
6552 }
6553
6554 my $resp_code = $client->response_code();
6555 my $resp_msg = $client->response_msg();
6556
6557 my $expected = 530;
6558 $self->assert($expected == $resp_code,
6559 test_msg("Expected response code $expected, got $resp_code"));
6560
6561 $expected = "Login incorrect.";
6562 $self->assert($expected eq $resp_msg,
6563 test_msg("Expected response message '$expected', got '$resp_msg'"));
6564 };
6565 if ($@) {
6566 $ex = $@;
6567 }
6568
6569 $wfh->print("done\n");
6570 $wfh->flush();
6571
6572 } else {
6573 eval { server_wait($setup->{config_file}, $rfh) };
6574 if ($@) {
6575 warn($@);
6576 exit 1;
6577 }
6578
6579 exit 0;
6580 }
6581
6582 # Stop server
6583 server_stop($setup->{pid_file});
6584 $self->assert_child_ok($pid);
6585
6586 eval {
6587 if (open(my $fh, "< $setup->{log_file}")) {
6588 my $ok = 1;
6589
6590 while (my $line = <$fh>) {
6591 chomp($line);
6592
6593 if ($ENV{TEST_VERBOSE}) {
6594 print STDERR "# $line\n";
6595 }
6596
6597 if ($line =~ /dispatching PRE_CMD.*PASS/) {
6598 $ok = 0;
6599 last;
6600 }
6601 }
6602 close($fh);
6603 $self->assert($ok, test_msg("Saw PASS command unexpectedly"));
6604
6605 } else {
6606 die("Can't read $setup->{log_file}: $!");
6607 }
6608 };
6609 if ($@) {
6610 $ex = $@ unless $ex;
6611 }
6612
6613 test_cleanup($setup->{log_file}, $ex);
6614 }
6615
6616 sub tls_opts_allow_per_user_tlsrequired_ctrl_user_login_bug3325 {
6617 my $self = shift;
6618 my $tmpdir = $self->{tmpdir};
6619
6620 my $config_file = "$tmpdir/tls.conf";
6621 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
6622 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
6623
6624 my $log_file = test_get_logfile();
6625
6626 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
6627 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
6628
6629 my $user = 'proftpd';
6630 my $passwd = 'test';
6631 my $group = 'ftpd';
6632 my $home_dir = File::Spec->rel2abs($tmpdir);
6633 my $uid = 500;
6634 my $gid = 500;
6635
6636 # Make sure that, if we're running as root, that the home directory has
6637 # permissions/privs set for the account we create
6638 if ($< == 0) {
6639 unless (chmod(0755, $home_dir)) {
6640 die("Can't set perms on $home_dir to 0755: $!");
6641 }
6642
6643 unless (chown($uid, $gid, $home_dir)) {
6644 die("Can't set owner of $home_dir to $uid/$gid: $!");
6645 }
6646 }
6647
6648 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6649 '/bin/bash');
6650 auth_group_write($auth_group_file, $group, $gid, $user);
6651
6652 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
6653 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6654 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6655
6656 my $config = {
6657 PidFile => $pid_file,
6658 ScoreboardFile => $scoreboard_file,
6659 SystemLog => $log_file,
6660
6661 AuthUserFile => $auth_user_file,
6662 AuthGroupFile => $auth_group_file,
6663
6664 IfModules => {
6665 'mod_delay.c' => {
6666 DelayEngine => 'off',
6667 },
6668
6669 'mod_tls.c' => {
6670 TLSEngine => 'on',
6671 TLSLog => $log_file,
6672 TLSRequired => 'ctrl',
6673 TLSRSACertificateFile => $cert_file,
6674 TLSCACertificateFile => $ca_file,
6675 TLSOptions => 'AllowPerUser',
6676 },
6677 },
6678 };
6679
6680 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6681
6682 my ($anon_user, $anon_group) = config_get_identity();
6683
6684 if (open(my $fh, ">> $config_file")) {
6685 print $fh <<EOC;
6686 <Anonymous $home_dir>
6687 User $anon_user
6688 Group $anon_group
6689 UserAlias anonymous $anon_user
6690 RequireValidShell off
6691 TLSRequired off
6692 </Anonymous>
6693 EOC
6694 unless (close($fh)) {
6695 die("Can't write $config_file: $!");
6696 }
6697
6698 } else {
6699 die("Can't open $config_file: $!");
6700 }
6701
6702 # Open pipes, for use between the parent and child processes. Specifically,
6703 # the child will indicate when it's done with its test by writing a message
6704 # to the parent.
6705 my ($rfh, $wfh);
6706 unless (pipe($rfh, $wfh)) {
6707 die("Can't open pipe: $!");
6708 }
6709
6710 require Net::FTPSSL;
6711
6712 my $ex;
6713
6714 # Fork child
6715 $self->handle_sigchld();
6716 defined(my $pid = fork()) or die("Can't fork: $!");
6717 if ($pid) {
6718 eval {
6719 # Give the server a chance to start up
6720 sleep(2);
6721
6722 # With this config, we should not be able to login without SSL/TLS
6723 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6724
6725 eval { $client->login($user, $passwd) };
6726 unless ($@) {
6727 die("Login succeeded unexpectedly");
6728 }
6729
6730 my $resp_code = $client->response_code();
6731 my $resp_msg = $client->response_msg();
6732
6733 my $expected;
6734
6735 $expected = 530;
6736 $self->assert($expected == $resp_code,
6737 test_msg("Expected $expected, got $resp_code"));
6738
6739 $expected = "Login incorrect.";
6740 $self->assert($expected eq $resp_msg,
6741 test_msg("Expected '$expected', got '$resp_msg'"));
6742 };
6743
6744 if ($@) {
6745 $ex = $@;
6746 }
6747
6748 $wfh->print("done\n");
6749 $wfh->flush();
6750
6751 } else {
6752 eval { server_wait($config_file, $rfh) };
6753 if ($@) {
6754 warn($@);
6755 exit 1;
6756 }
6757
6758 exit 0;
6759 }
6760
6761 # Stop server
6762 server_stop($pid_file);
6763
6764 $self->assert_child_ok($pid);
6765
6766 if ($ex) {
6767 test_append_logfile($log_file, $ex);
6768 unlink($log_file);
6769
6770 die($ex);
6771 }
6772
6773 unlink($log_file);
6774 }
6775
6776 sub tls_opts_allow_per_user_tlsrequired_data_user_login_bug3325 {
6777 my $self = shift;
6778 my $tmpdir = $self->{tmpdir};
6779
6780 my $config_file = "$tmpdir/tls.conf";
6781 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
6782 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
6783
6784 my $log_file = test_get_logfile();
6785
6786 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
6787 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
6788
6789 my $user = 'proftpd';
6790 my $passwd = 'test';
6791 my $group = 'ftpd';
6792 my $home_dir = File::Spec->rel2abs($tmpdir);
6793 my $uid = 500;
6794 my $gid = 500;
6795
6796 # Make sure that, if we're running as root, that the home directory has
6797 # permissions/privs set for the account we create
6798 if ($< == 0) {
6799 unless (chmod(0755, $home_dir)) {
6800 die("Can't set perms on $home_dir to 0755: $!");
6801 }
6802
6803 unless (chown($uid, $gid, $home_dir)) {
6804 die("Can't set owner of $home_dir to $uid/$gid: $!");
6805 }
6806 }
6807
6808 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
6809 '/bin/bash');
6810 auth_group_write($auth_group_file, $group, $gid, $user);
6811
6812 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
6813 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6814 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6815
6816 my $config = {
6817 PidFile => $pid_file,
6818 ScoreboardFile => $scoreboard_file,
6819 SystemLog => $log_file,
6820
6821 AuthUserFile => $auth_user_file,
6822 AuthGroupFile => $auth_group_file,
6823
6824 IfModules => {
6825 'mod_delay.c' => {
6826 DelayEngine => 'off',
6827 },
6828
6829 'mod_tls.c' => {
6830 TLSEngine => 'on',
6831 TLSLog => $log_file,
6832 TLSRequired => 'data',
6833 TLSRSACertificateFile => $cert_file,
6834 TLSCACertificateFile => $ca_file,
6835 TLSOptions => 'AllowPerUser',
6836 },
6837 },
6838 };
6839
6840 my ($port, $config_user, $config_group) = config_write($config_file, $config);
6841
6842 my ($anon_user, $anon_group) = config_get_identity();
6843
6844 if (open(my $fh, ">> $config_file")) {
6845 print $fh <<EOC;
6846 <Anonymous $home_dir>
6847 User $anon_user
6848 Group $anon_group
6849 UserAlias anonymous $anon_user
6850 RequireValidShell off
6851 TLSRequired off
6852 </Anonymous>
6853 EOC
6854 unless (close($fh)) {
6855 die("Can't write $config_file: $!");
6856 }
6857
6858 } else {
6859 die("Can't open $config_file: $!");
6860 }
6861
6862 # Open pipes, for use between the parent and child processes. Specifically,
6863 # the child will indicate when it's done with its test by writing a message
6864 # to the parent.
6865 my ($rfh, $wfh);
6866 unless (pipe($rfh, $wfh)) {
6867 die("Can't open pipe: $!");
6868 }
6869
6870 require Net::FTPSSL;
6871
6872 my $ex;
6873
6874 # Fork child
6875 $self->handle_sigchld();
6876 defined(my $pid = fork()) or die("Can't fork: $!");
6877 if ($pid) {
6878 eval {
6879 # Give the server a chance to start up
6880 sleep(2);
6881
6882 # With this config, we should not be able to login without SSL/TLS
6883 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
6884
6885 my ($resp_code, $resp_msg) = $client->login($user, $passwd);
6886
6887 my $expected;
6888
6889 $expected = 230;
6890 $self->assert($expected == $resp_code,
6891 test_msg("Expected $expected, got $resp_code"));
6892
6893 $expected = "User $user logged in";
6894 $self->assert($expected eq $resp_msg,
6895 test_msg("Expected '$expected', got '$resp_msg'"));
6896 };
6897
6898 if ($@) {
6899 $ex = $@;
6900 }
6901
6902 $wfh->print("done\n");
6903 $wfh->flush();
6904
6905 } else {
6906 eval { server_wait($config_file, $rfh) };
6907 if ($@) {
6908 warn($@);
6909 exit 1;
6910 }
6911
6912 exit 0;
6913 }
6914
6915 # Stop server
6916 server_stop($pid_file);
6917
6918 $self->assert_child_ok($pid);
6919
6920 if ($ex) {
6921 test_append_logfile($log_file, $ex);
6922 unlink($log_file);
6923
6924 die($ex);
6925 }
6926
6927 unlink($log_file);
6928 }
6929
6930 sub tls_opts_allow_per_user_tlsrequired_on_ifsess_login_bug3325 {
6931 my $self = shift;
6932 my $tmpdir = $self->{tmpdir};
6933 my $setup = test_setup($tmpdir, 'tls');
6934
6935 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
6936 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
6937 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
6938
6939 my $config = {
6940 PidFile => $setup->{pid_file},
6941 ScoreboardFile => $setup->{scoreboard_file},
6942 SystemLog => $setup->{log_file},
6943
6944 AuthUserFile => $setup->{auth_user_file},
6945 AuthGroupFile => $setup->{auth_group_file},
6946
6947 IfModules => {
6948 'mod_delay.c' => {
6949 DelayEngine => 'off',
6950 },
6951
6952 'mod_tls.c' => {
6953 TLSEngine => 'on',
6954 TLSLog => $setup->{log_file},
6955 TLSRequired => 'on',
6956 TLSRSACertificateFile => $cert_file,
6957 TLSCACertificateFile => $ca_file,
6958 TLSOptions => 'AllowPerUser',
6959 },
6960 },
6961 };
6962
6963 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
6964 $config);
6965
6966 my ($anon_user, $anon_group) = config_get_identity();
6967
6968 if (open(my $fh, ">> $setup->{config_file}")) {
6969 print $fh <<EOC;
6970 <IfModule mod_ifsession.c>
6971 <IfUser $setup->{user}>
6972 TLSRequired off
6973 </IfUser>
6974 </IfModule>
6975 EOC
6976 unless (close($fh)) {
6977 die("Can't write $setup->{config_file}: $!");
6978 }
6979
6980 } else {
6981 die("Can't open $setup->{config_file}: $!");
6982 }
6983
6984 # Open pipes, for use between the parent and child processes. Specifically,
6985 # the child will indicate when it's done with its test by writing a message
6986 # to the parent.
6987 my ($rfh, $wfh);
6988 unless (pipe($rfh, $wfh)) {
6989 die("Can't open pipe: $!");
6990 }
6991
6992 require Net::FTPSSL;
6993
6994 my $ex;
6995
6996 # Fork child
6997 $self->handle_sigchld();
6998 defined(my $pid = fork()) or die("Can't fork: $!");
6999 if ($pid) {
7000 eval {
7001 # Give the server a chance to start up
7002 sleep(2);
7003
7004 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
7005
7006 my ($resp_code, $resp_msg) = $client->login($setup->{user},
7007 $setup->{passwd});
7008 my $expected;
7009
7010 $expected = 230;
7011 $self->assert($expected == $resp_code,
7012 test_msg("Expected response code $expected, got $resp_code"));
7013
7014 $expected = "User $setup->{user} logged in";
7015 $self->assert($expected eq $resp_msg,
7016 test_msg("Expected response message '$expected', got '$resp_msg'"));
7017
7018 $client->quit();
7019 };
7020 if ($@) {
7021 $ex = $@;
7022 }
7023
7024 $wfh->print("done\n");
7025 $wfh->flush();
7026
7027 } else {
7028 eval { server_wait($setup->{config_file}, $rfh) };
7029 if ($@) {
7030 warn($@);
7031 exit 1;
7032 }
7033
7034 exit 0;
7035 }
7036
7037 # Stop server
7038 server_stop($setup->{pid_file});
7039 $self->assert_child_ok($pid);
7040
7041 test_cleanup($setup->{log_file}, $ex);
7042 }
7043
7044 sub tls_opts_allow_per_user_nosessionreuserequired_ifsess_login_issue1175 {
7045 my $self = shift;
7046 my $tmpdir = $self->{tmpdir};
7047 my $setup = test_setup($tmpdir, 'tls');
7048
7049 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
7050 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
7051
7052 my $config = {
7053 PidFile => $setup->{pid_file},
7054 ScoreboardFile => $setup->{scoreboard_file},
7055 SystemLog => $setup->{log_file},
7056
7057 AuthUserFile => $setup->{auth_user_file},
7058 AuthGroupFile => $setup->{auth_group_file},
7059
7060 IfModules => {
7061 'mod_delay.c' => {
7062 DelayEngine => 'off',
7063 },
7064
7065 'mod_tls.c' => {
7066 TLSEngine => 'on',
7067 TLSLog => $setup->{log_file},
7068 TLSRequired => 'on',
7069 TLSRSACertificateFile => $cert_file,
7070 TLSCACertificateFile => $ca_file,
7071 },
7072 },
7073 };
7074
7075 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
7076 $config);
7077
7078 my ($anon_user, $anon_group) = config_get_identity();
7079
7080 if (open(my $fh, ">> $setup->{config_file}")) {
7081 print $fh <<EOC;
7082 <IfModule mod_ifsession.c>
7083 <IfUser $setup->{user}>
7084 TLSOptions NoSessionReuseRequired
7085 </IfUser>
7086 </IfModule>
7087 EOC
7088 unless (close($fh)) {
7089 die("Can't write $setup->{config_file}: $!");
7090 }
7091
7092 } else {
7093 die("Can't open $setup->{config_file}: $!");
7094 }
7095
7096 # Open pipes, for use between the parent and child processes. Specifically,
7097 # the child will indicate when it's done with its test by writing a message
7098 # to the parent.
7099 my ($rfh, $wfh);
7100 unless (pipe($rfh, $wfh)) {
7101 die("Can't open pipe: $!");
7102 }
7103
7104 require Net::FTPSSL;
7105
7106 my $ex;
7107
7108 # Fork child
7109 $self->handle_sigchld();
7110 defined(my $pid = fork()) or die("Can't fork: $!");
7111 if ($pid) {
7112 eval {
7113 # Give the server a chance to start up
7114 sleep(2);
7115
7116 my $client = Net::FTPSSL->new('127.0.0.1',
7117 Encryption => 'E',
7118 Port => $port,
7119 Croak => 1,
7120 );
7121
7122 unless ($client->login($setup->{user}, $setup->{passwd})) {
7123 die("Can't login: " . $client->last_message());
7124 }
7125
7126 # Since we are NOT requiring SSL session reuse for data transfers,
7127 # and this client is not using SSL session resumption, I expect
7128 # this data transfer to succeed.
7129 my $res = $client->list('.');
7130 unless ($res) {
7131 die("LIST failed unexpectedly: " . $client->message());
7132 }
7133
7134 $client->quit();
7135 };
7136 if ($@) {
7137 $ex = $@;
7138 }
7139
7140 $wfh->print("done\n");
7141 $wfh->flush();
7142
7143 } else {
7144 eval { server_wait($setup->{config_file}, $rfh) };
7145 if ($@) {
7146 warn($@);
7147 exit 1;
7148 }
7149
7150 exit 0;
7151 }
7152
7153 # Stop server
7154 server_stop($setup->{pid_file});
7155 $self->assert_child_ok($pid);
7156
7157 test_cleanup($setup->{log_file}, $ex);
7158 }
7159
7160 sub tls_opts_allow_weak_security_issue1048 {
7161 my $self = shift;
7162 my $tmpdir = $self->{tmpdir};
7163 my $setup = test_setup($tmpdir, 'tls');
7164
7165 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/weak-cert.pem');
7166 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/weak-cert.pem');
7167
7168 my $config = {
7169 PidFile => $setup->{pid_file},
7170 ScoreboardFile => $setup->{scoreboard_file},
7171 SystemLog => $setup->{log_file},
7172 TraceLog => $setup->{log_file},
7173 Trace => 'tls:20',
7174
7175 AuthUserFile => $setup->{auth_user_file},
7176 AuthGroupFile => $setup->{auth_group_file},
7177
7178 IfModules => {
7179 'mod_delay.c' => {
7180 DelayEngine => 'off',
7181 },
7182
7183 'mod_tls.c' => {
7184 TLSEngine => 'on',
7185 TLSLog => $setup->{log_file},
7186 TLSRequired => 'on',
7187 TLSRSACertificateFile => $cert_file,
7188 TLSCACertificateFile => $ca_file,
7189 TLSOptions => 'AllowWeakSecurity EnableDiags',
7190 },
7191 },
7192 };
7193
7194 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
7195 $config);
7196
7197 # Open pipes, for use between the parent and child processes. Specifically,
7198 # the child will indicate when it's done with its test by writing a message
7199 # to the parent.
7200 my ($rfh, $wfh);
7201 unless (pipe($rfh, $wfh)) {
7202 die("Can't open pipe: $!");
7203 }
7204
7205 require Net::FTPSSL;
7206
7207 my $ex;
7208
7209 # Fork child
7210 $self->handle_sigchld();
7211 defined(my $pid = fork()) or die("Can't fork: $!");
7212 if ($pid) {
7213 eval {
7214 # Give the server a chance to start up
7215 sleep(2);
7216
7217 my $client = Net::FTPSSL->new('127.0.0.1',
7218 Encryption => 'E',
7219 Port => $port,
7220 );
7221
7222 unless ($client) {
7223 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
7224 }
7225
7226 unless ($client->login($setup->{user}, $setup->{passwd})) {
7227 die("Can't login: " . $client->last_message());
7228 }
7229
7230 $client->quit();
7231 };
7232 if ($@) {
7233 $ex = $@;
7234 }
7235
7236 $wfh->print("done\n");
7237 $wfh->flush();
7238
7239 } else {
7240 eval { server_wait($setup->{config_file}, $rfh) };
7241 if ($@) {
7242 warn($@);
7243 exit 1;
7244 }
7245
7246 exit 0;
7247 }
7248
7249 # Stop server
7250 server_stop($setup->{pid_file});
7251 $self->assert_child_ok($pid);
7252
7253 test_cleanup($setup->{log_file}, $ex);
7254 }
7255
7256 sub tls_rest_2gb_last_byte {
7257 my $self = shift;
7258 my $tmpdir = $self->{tmpdir};
7259
7260 my $config_file = "$tmpdir/tls.conf";
7261 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
7262 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
7263
7264 my $log_file = test_get_logfile();
7265
7266 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
7267 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
7268
7269 my $user = 'proftpd';
7270 my $passwd = 'test';
7271 my $group = 'ftpd';
7272 my $home_dir = File::Spec->rel2abs($tmpdir);
7273 my $uid = 500;
7274 my $gid = 500;
7275
7276 # Make sure that, if we're running as root, that the home directory has
7277 # permissions/privs set for the account we create
7278 if ($< == 0) {
7279 unless (chmod(0755, $home_dir)) {
7280 die("Can't set perms on $home_dir to 0755: $!");
7281 }
7282
7283 unless (chown($uid, $gid, $home_dir)) {
7284 die("Can't set owner of $home_dir to $uid/$gid: $!");
7285 }
7286 }
7287
7288 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7289 '/bin/bash');
7290 auth_group_write($auth_group_file, $group, $gid, $user);
7291
7292 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
7293 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
7294 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
7295
7296 # According to:
7297 #
7298 # http://trac.filezilla-project.org/ticket/4487
7299 #
7300 # FileZilla tests whether servers support resuming transfers over 2GB by
7301 # (IMHO stupidly) seeking to just before the last byte of the file on the
7302 # server, and expecting just a single byte.
7303 #
7304 # Make sure that proftpd does The Right Thing(tm) in a regression test for
7305 # this use case.
7306
7307 # Create a file that is 2GB plus 24 bytes.
7308 my $test_len = (2 ** 31) + 24;
7309 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
7310 if (open(my $fh, "> $test_file")) {
7311
7312 # Seek to the 2GB limit, then fill the rest with 'A'
7313 unless (seek($fh, (2 ** 31), 0)) {
7314 die("Can't seek to 2GB length: $!");
7315 }
7316
7317 print $fh "A" x 24;
7318
7319 unless (close($fh)) {
7320 die("Can't write $test_file: $!");
7321 }
7322
7323 } else {
7324 die("Can't open $test_file: $!");
7325 }
7326
7327 my $tmp_file = File::Spec->rel2abs("$tmpdir/test.tmp");
7328 my $tmp_fh;
7329 unless (open($tmp_fh, "> $tmp_file")) {
7330 die("Can't open $tmp_file: $!");
7331 }
7332
7333 my $config = {
7334 PidFile => $pid_file,
7335 ScoreboardFile => $scoreboard_file,
7336 SystemLog => $log_file,
7337
7338 AuthUserFile => $auth_user_file,
7339 AuthGroupFile => $auth_group_file,
7340
7341 IfModules => {
7342 'mod_delay.c' => {
7343 DelayEngine => 'off',
7344 },
7345
7346 'mod_tls.c' => {
7347 TLSEngine => 'on',
7348 TLSLog => $log_file,
7349 TLSRequired => 'on',
7350 TLSRSACertificateFile => $cert_file,
7351 TLSCACertificateFile => $ca_file,
7352 TLSOptions => 'NoSessionReuseRequired',
7353 },
7354 },
7355 };
7356
7357 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7358
7359 # Open pipes, for use between the parent and child processes. Specifically,
7360 # the child will indicate when it's done with its test by writing a message
7361 # to the parent.
7362 my ($rfh, $wfh);
7363 unless (pipe($rfh, $wfh)) {
7364 die("Can't open pipe: $!");
7365 }
7366
7367 require Net::FTPSSL;
7368
7369 my $ex;
7370
7371 # Fork child
7372 $self->handle_sigchld();
7373 defined(my $pid = fork()) or die("Can't fork: $!");
7374 if ($pid) {
7375 eval {
7376 # Give the server a chance to start up
7377 sleep(2);
7378
7379 my $client = Net::FTPSSL->new('127.0.0.1',
7380 Encryption => 'E',
7381 Port => $port,
7382 );
7383
7384 unless ($client) {
7385 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
7386 }
7387
7388 unless ($client->login($user, $passwd)) {
7389 die("Can't login: " . $client->last_message());
7390 }
7391
7392 unless ($client->binary()) {
7393 die("Can't set TYPE to binary: " . $client->last_message());
7394 }
7395
7396 my $rest_len = $test_len - 1;
7397
7398 my $res;
7399 if ($Net::FTPSSL::VERSION == 0.21) {
7400 # Note: The duplicated arguments here are to work around a bug in
7401 # Net::FTPSSL, version 0.21, in the quot() function.
7402 $res = $client->quot('REST', $rest_len, $rest_len);
7403
7404 } else {
7405 $res = $client->quot('REST', $rest_len);
7406 }
7407
7408 unless ($res) {
7409 die("Can't REST $rest_len: " . $client->last_message());
7410 }
7411
7412 my $resp_msg = $client->last_message();
7413 my $expected;
7414
7415 $expected = "350 Restarting at $rest_len. Send STORE or RETRIEVE to initiate transfer";
7416 $self->assert($expected eq $resp_msg,
7417 test_msg("Expected '$expected', got '$resp_msg'"));
7418
7419 unless ($client->get($test_file, $tmp_fh)) {
7420 die("Can't RETR $test_file: " . $client->last_message());
7421 }
7422
7423 $resp_msg = $client->last_message();
7424 $expected = "226 Transfer complete";
7425 $self->assert($expected eq $resp_msg,
7426 test_msg("Expected '$expected', got '$resp_msg'"));
7427
7428 close($tmp_fh);
7429
7430 my $buflen = (stat($tmp_file))[7];
7431 $expected = 1;
7432 $self->assert($expected == $buflen,
7433 test_msg("Expected $expected, got $buflen"));
7434 };
7435
7436 if ($@) {
7437 $ex = $@;
7438 }
7439
7440 $wfh->print("done\n");
7441 $wfh->flush();
7442
7443 } else {
7444 eval { server_wait($config_file, $rfh) };
7445 if ($@) {
7446 warn($@);
7447 exit 1;
7448 }
7449
7450 exit 0;
7451 }
7452
7453 # Stop server
7454 server_stop($pid_file);
7455
7456 $self->assert_child_ok($pid);
7457
7458 if ($ex) {
7459 test_append_logfile($log_file, $ex);
7460 unlink($log_file);
7461
7462 die($ex);
7463 }
7464
7465 unlink($log_file);
7466 }
7467
7468 sub tls_rest_4gb_last_byte {
7469 my $self = shift;
7470 my $tmpdir = $self->{tmpdir};
7471
7472 my $config_file = "$tmpdir/tls.conf";
7473 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
7474 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
7475
7476 my $log_file = test_get_logfile();
7477
7478 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
7479 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
7480
7481 my $user = 'proftpd';
7482 my $passwd = 'test';
7483 my $group = 'ftpd';
7484 my $home_dir = File::Spec->rel2abs($tmpdir);
7485 my $uid = 500;
7486 my $gid = 500;
7487
7488 # Make sure that, if we're running as root, that the home directory has
7489 # permissions/privs set for the account we create
7490 if ($< == 0) {
7491 unless (chmod(0755, $home_dir)) {
7492 die("Can't set perms on $home_dir to 0755: $!");
7493 }
7494
7495 unless (chown($uid, $gid, $home_dir)) {
7496 die("Can't set owner of $home_dir to $uid/$gid: $!");
7497 }
7498 }
7499
7500 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7501 '/bin/bash');
7502 auth_group_write($auth_group_file, $group, $gid, $user);
7503
7504 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
7505 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
7506 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
7507
7508 # According to:
7509 #
7510 # http://trac.filezilla-project.org/ticket/4487
7511 #
7512 # FileZilla tests whether servers support resuming transfers over 4GB by
7513 # (IMHO stupidly) seeking to just before the last byte of the file on the
7514 # server, and expecting just a single byte.
7515 #
7516 # Make sure that proftpd does The Right Thing(tm) in a regression test for
7517 # this use case.
7518
7519 # Create a file that is 4GB plus 24 bytes.
7520 my $test_len = (2 ** 32) + 24;
7521 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
7522 if (open(my $fh, "> $test_file")) {
7523
7524 # Seek to the 4GB limit, then fill the rest with 'A'
7525 unless (seek($fh, (2 ** 32), 0)) {
7526 die("Can't seek to 4GB length: $!");
7527 }
7528
7529 print $fh "A" x 24;
7530
7531 unless (close($fh)) {
7532 die("Can't write $test_file: $!");
7533 }
7534
7535 } else {
7536 die("Can't open $test_file: $!");
7537 }
7538
7539 my $tmp_file = File::Spec->rel2abs("$tmpdir/test.tmp");
7540 my $tmp_fh;
7541 unless (open($tmp_fh, "> $tmp_file")) {
7542 die("Can't open $tmp_file: $!");
7543 }
7544
7545 my $config = {
7546 PidFile => $pid_file,
7547 ScoreboardFile => $scoreboard_file,
7548 SystemLog => $log_file,
7549
7550 AuthUserFile => $auth_user_file,
7551 AuthGroupFile => $auth_group_file,
7552
7553 IfModules => {
7554 'mod_delay.c' => {
7555 DelayEngine => 'off',
7556 },
7557
7558 'mod_tls.c' => {
7559 TLSEngine => 'on',
7560 TLSLog => $log_file,
7561 TLSRequired => 'on',
7562 TLSRSACertificateFile => $cert_file,
7563 TLSCACertificateFile => $ca_file,
7564 TLSOptions => 'NoSessionReuseRequired',
7565 },
7566 },
7567 };
7568
7569 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7570
7571 # Open pipes, for use between the parent and child processes. Specifically,
7572 # the child will indicate when it's done with its test by writing a message
7573 # to the parent.
7574 my ($rfh, $wfh);
7575 unless (pipe($rfh, $wfh)) {
7576 die("Can't open pipe: $!");
7577 }
7578
7579 require Net::FTPSSL;
7580
7581 my $ex;
7582
7583 # Fork child
7584 $self->handle_sigchld();
7585 defined(my $pid = fork()) or die("Can't fork: $!");
7586 if ($pid) {
7587 eval {
7588 # Give the server a chance to start up
7589 sleep(2);
7590
7591 my $client = Net::FTPSSL->new('127.0.0.1',
7592 Encryption => 'E',
7593 Port => $port,
7594 );
7595
7596 unless ($client) {
7597 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
7598 }
7599
7600 unless ($client->login($user, $passwd)) {
7601 die("Can't login: " . $client->last_message());
7602 }
7603
7604 unless ($client->binary()) {
7605 die("Can't set TYPE to binary: " . $client->last_message());
7606 }
7607
7608 my $rest_len = $test_len - 1;
7609
7610 my $res;
7611 if ($Net::FTPSSL::VERSION == 0.21) {
7612 # Note: The duplicated arguments here are to work around a bug in
7613 # Net::FTPSSL, version 0.21, in the quot() function.
7614 $res = $client->quot('REST', $rest_len, $rest_len);
7615
7616 } else {
7617 $res = $client->quot('REST', $rest_len);
7618 }
7619
7620 unless ($res) {
7621 die("Can't REST $rest_len: " . $client->last_message());
7622 }
7623
7624 my $resp_msg = $client->last_message();
7625 my $expected;
7626
7627 $expected = "350 Restarting at $rest_len. Send STORE or RETRIEVE to initiate transfer";
7628 $self->assert($expected eq $resp_msg,
7629 test_msg("Expected '$expected', got '$resp_msg'"));
7630
7631 unless ($client->get($test_file, $tmp_fh)) {
7632 die("Can't RETR $test_file: " . $client->last_message());
7633 }
7634
7635 $resp_msg = $client->last_message();
7636 $expected = "226 Transfer complete";
7637 $self->assert($expected eq $resp_msg,
7638 test_msg("Expected '$expected', got '$resp_msg'"));
7639
7640 close($tmp_fh);
7641
7642 my $buflen = (stat($tmp_file))[7];
7643 $expected = 1;
7644 $self->assert($expected == $buflen,
7645 test_msg("Expected $expected, got $buflen"));
7646 };
7647
7648 if ($@) {
7649 $ex = $@;
7650 }
7651
7652 $wfh->print("done\n");
7653 $wfh->flush();
7654
7655 } else {
7656 eval { server_wait($config_file, $rfh) };
7657 if ($@) {
7658 warn($@);
7659 exit 1;
7660 }
7661
7662 exit 0;
7663 }
7664
7665 # Stop server
7666 server_stop($pid_file);
7667
7668 $self->assert_child_ok($pid);
7669
7670 if ($ex) {
7671 test_append_logfile($log_file, $ex);
7672 unlink($log_file);
7673
7674 die($ex);
7675 }
7676
7677 unlink($log_file);
7678 }
7679
7680 sub tls_stor_empty_file {
7681 my $self = shift;
7682 my $tmpdir = $self->{tmpdir};
7683
7684 my $config_file = "$tmpdir/tls.conf";
7685 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
7686 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
7687
7688 my $log_file = test_get_logfile();
7689
7690 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
7691 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
7692
7693 my $user = 'proftpd';
7694 my $passwd = 'test';
7695 my $group = 'ftpd';
7696 my $home_dir = File::Spec->rel2abs($tmpdir);
7697 my $uid = 500;
7698 my $gid = 500;
7699
7700 # Make sure that, if we're running as root, that the home directory has
7701 # permissions/privs set for the account we create
7702 if ($< == 0) {
7703 unless (chmod(0755, $home_dir)) {
7704 die("Can't set perms on $home_dir to 0755: $!");
7705 }
7706
7707 unless (chown($uid, $gid, $home_dir)) {
7708 die("Can't set owner of $home_dir to $uid/$gid: $!");
7709 }
7710 }
7711
7712 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7713 '/bin/bash');
7714 auth_group_write($auth_group_file, $group, $gid, $user);
7715
7716 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
7717 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
7718
7719 my $config = {
7720 PidFile => $pid_file,
7721 ScoreboardFile => $scoreboard_file,
7722 SystemLog => $log_file,
7723 TraceLog => $log_file,
7724 Trace => 'netio:20',
7725
7726 AuthUserFile => $auth_user_file,
7727 AuthGroupFile => $auth_group_file,
7728
7729 IfModules => {
7730 'mod_delay.c' => {
7731 DelayEngine => 'off',
7732 },
7733
7734 'mod_tls.c' => {
7735 TLSEngine => 'on',
7736 TLSLog => $log_file,
7737 TLSRequired => 'on',
7738 TLSRSACertificateFile => $cert_file,
7739 TLSCACertificateFile => $ca_file,
7740 TLSOptions => 'EnableDiags NoSessionReuseRequired',
7741 },
7742 },
7743 };
7744
7745 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7746
7747 my $empty_file = File::Spec->rel2abs("$tmpdir/empty.txt");
7748 if (open(my $fh, "> $empty_file")) {
7749 close($fh);
7750
7751 } else {
7752 die("Can't open $empty_file: $!");
7753 }
7754
7755 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
7756
7757 # Open pipes, for use between the parent and child processes. Specifically,
7758 # the child will indicate when it's done with its test by writing a message
7759 # to the parent.
7760 my ($rfh, $wfh);
7761 unless (pipe($rfh, $wfh)) {
7762 die("Can't open pipe: $!");
7763 }
7764
7765 require Net::FTPSSL;
7766
7767 my $ex;
7768
7769 # Fork child
7770 $self->handle_sigchld();
7771 defined(my $pid = fork()) or die("Can't fork: $!");
7772 if ($pid) {
7773 eval {
7774 # Give the server a chance to start up
7775 sleep(2);
7776
7777 my $client = Net::FTPSSL->new('127.0.0.1',
7778 Encryption => 'E',
7779 Port => $port,
7780 );
7781
7782 unless ($client) {
7783 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
7784 }
7785
7786 unless ($client->login($user, $passwd)) {
7787 die("Can't login: " . $client->last_message());
7788 }
7789
7790 unless ($client->binary()) {
7791 die("Can't set transfer mode to binary: " . $client->last_message());
7792 }
7793
7794 unless ($client->put($empty_file, 'test.txt')) {
7795 die("Can't upload '$empty_file' to 'test.txt': " .
7796 $client->last_message());
7797 }
7798
7799 $client->quit();
7800
7801 unless (-f $test_file) {
7802 die("File $test_file does not exist as expected");
7803 }
7804
7805 unless (-z $test_file) {
7806 die("File $test_file is not empty as expected");
7807 }
7808
7809 };
7810
7811 if ($@) {
7812 $ex = $@;
7813 }
7814
7815 $wfh->print("done\n");
7816 $wfh->flush();
7817
7818 } else {
7819 eval { server_wait($config_file, $rfh) };
7820 if ($@) {
7821 warn($@);
7822 exit 1;
7823 }
7824
7825 exit 0;
7826 }
7827
7828 # Stop server
7829 server_stop($pid_file);
7830
7831 $self->assert_child_ok($pid);
7832
7833 if ($ex) {
7834 test_append_logfile($log_file, $ex);
7835 unlink($log_file);
7836
7837 die($ex);
7838 }
7839
7840 unlink($log_file);
7841 }
7842
7843 sub tls_retr_empty_file {
7844 my $self = shift;
7845 my $tmpdir = $self->{tmpdir};
7846
7847 my $config_file = "$tmpdir/tls.conf";
7848 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
7849 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
7850
7851 my $log_file = test_get_logfile();
7852
7853 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
7854 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
7855
7856 my $user = 'proftpd';
7857 my $passwd = 'test';
7858 my $group = 'ftpd';
7859 my $home_dir = File::Spec->rel2abs($tmpdir);
7860 my $uid = 500;
7861 my $gid = 500;
7862
7863 # Make sure that, if we're running as root, that the home directory has
7864 # permissions/privs set for the account we create
7865 if ($< == 0) {
7866 unless (chmod(0755, $home_dir)) {
7867 die("Can't set perms on $home_dir to 0755: $!");
7868 }
7869
7870 unless (chown($uid, $gid, $home_dir)) {
7871 die("Can't set owner of $home_dir to $uid/$gid: $!");
7872 }
7873 }
7874
7875 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
7876 '/bin/bash');
7877 auth_group_write($auth_group_file, $group, $gid, $user);
7878
7879 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
7880 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
7881
7882 my $config = {
7883 PidFile => $pid_file,
7884 ScoreboardFile => $scoreboard_file,
7885 SystemLog => $log_file,
7886
7887 AuthUserFile => $auth_user_file,
7888 AuthGroupFile => $auth_group_file,
7889
7890 IfModules => {
7891 'mod_delay.c' => {
7892 DelayEngine => 'off',
7893 },
7894
7895 'mod_tls.c' => {
7896 TLSEngine => 'on',
7897 TLSLog => $log_file,
7898 TLSRequired => 'on',
7899 TLSRSACertificateFile => $cert_file,
7900 TLSCACertificateFile => $ca_file,
7901 TLSOptions => 'NoSessionReuseRequired',
7902 },
7903 },
7904 };
7905
7906 my ($port, $config_user, $config_group) = config_write($config_file, $config);
7907
7908 my $empty_file = File::Spec->rel2abs("$tmpdir/empty.txt");
7909 if (open(my $fh, "> $empty_file")) {
7910 close($fh);
7911
7912 } else {
7913 die("Can't open $empty_file: $!");
7914 }
7915
7916 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
7917
7918 # Open pipes, for use between the parent and child processes. Specifically,
7919 # the child will indicate when it's done with its test by writing a message
7920 # to the parent.
7921 my ($rfh, $wfh);
7922 unless (pipe($rfh, $wfh)) {
7923 die("Can't open pipe: $!");
7924 }
7925
7926 require Net::FTPSSL;
7927
7928 my $ex;
7929
7930 # Fork child
7931 $self->handle_sigchld();
7932 defined(my $pid = fork()) or die("Can't fork: $!");
7933 if ($pid) {
7934 eval {
7935 # Give the server a chance to start up
7936 sleep(2);
7937
7938 my $client = Net::FTPSSL->new('127.0.0.1',
7939 Encryption => 'E',
7940 Port => $port,
7941 );
7942
7943 unless ($client) {
7944 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
7945 }
7946
7947 unless ($client->login($user, $passwd)) {
7948 die("Can't login: " . $client->last_message());
7949 }
7950
7951 unless ($client->binary()) {
7952 die("Can't set transfer mode to binary: " . $client->last_message());
7953 }
7954
7955 unless ($client->get($empty_file, $test_file)) {
7956 die("Can't download '$empty_file' to '$test_file': " .
7957 $client->last_message());
7958 }
7959
7960 $client->quit();
7961
7962 unless (-f $test_file) {
7963 die("File $test_file does not exist as expected");
7964 }
7965
7966 unless (-z $test_file) {
7967 die("File $test_file is not empty as expected");
7968 }
7969
7970 };
7971
7972 if ($@) {
7973 $ex = $@;
7974 }
7975
7976 $wfh->print("done\n");
7977 $wfh->flush();
7978
7979 } else {
7980 eval { server_wait($config_file, $rfh) };
7981 if ($@) {
7982 warn($@);
7983 exit 1;
7984 }
7985
7986 exit 0;
7987 }
7988
7989 # Stop server
7990 server_stop($pid_file);
7991
7992 $self->assert_child_ok($pid);
7993
7994 if ($ex) {
7995 test_append_logfile($log_file, $ex);
7996 unlink($log_file);
7997
7998 die($ex);
7999 }
8000
8001 unlink($log_file);
8002 }
8003
8004 sub tls_required_on_feat_allowed_bug3420 {
8005 my $self = shift;
8006 my $tmpdir = $self->{tmpdir};
8007
8008 my $config_file = "$tmpdir/tls.conf";
8009 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
8010 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
8011
8012 my $log_file = test_get_logfile();
8013
8014 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
8015 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
8016
8017 my $user = 'proftpd';
8018 my $passwd = 'test';
8019 my $group = 'ftpd';
8020 my $home_dir = File::Spec->rel2abs($tmpdir);
8021 my $uid = 500;
8022 my $gid = 500;
8023
8024 # Make sure that, if we're running as root, that the home directory has
8025 # permissions/privs set for the account we create
8026 if ($< == 0) {
8027 unless (chmod(0755, $home_dir)) {
8028 die("Can't set perms on $home_dir to 0755: $!");
8029 }
8030
8031 unless (chown($uid, $gid, $home_dir)) {
8032 die("Can't set owner of $home_dir to $uid/$gid: $!");
8033 }
8034 }
8035
8036 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8037 '/bin/bash');
8038 auth_group_write($auth_group_file, $group, $gid, $user);
8039
8040 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8041 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8042
8043 my $config = {
8044 PidFile => $pid_file,
8045 ScoreboardFile => $scoreboard_file,
8046 SystemLog => $log_file,
8047
8048 AuthUserFile => $auth_user_file,
8049 AuthGroupFile => $auth_group_file,
8050
8051 IfModules => {
8052 'mod_delay.c' => {
8053 DelayEngine => 'off',
8054 },
8055
8056 'mod_tls.c' => {
8057 TLSEngine => 'on',
8058 TLSLog => $log_file,
8059 TLSRequired => 'on',
8060 TLSRSACertificateFile => $cert_file,
8061 TLSCACertificateFile => $ca_file,
8062 },
8063 },
8064 };
8065
8066 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8067
8068 # Open pipes, for use between the parent and child processes. Specifically,
8069 # the child will indicate when it's done with its test by writing a message
8070 # to the parent.
8071 my ($rfh, $wfh);
8072 unless (pipe($rfh, $wfh)) {
8073 die("Can't open pipe: $!");
8074 }
8075
8076 require Net::FTPSSL;
8077
8078 my $ex;
8079
8080 # Fork child
8081 $self->handle_sigchld();
8082 defined(my $pid = fork()) or die("Can't fork: $!");
8083 if ($pid) {
8084 eval {
8085 # Give the server a chance to start up
8086 sleep(2);
8087
8088 # We use a non-FTPS client here, to make sure that we can at least
8089 # get the FEAT data, as per Bug#3420.
8090
8091 my $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
8092 $client->feat();
8093
8094 my $resp_msgs = $client->response_msgs();
8095 my $count = scalar(@$resp_msgs);
8096 $self->assert($count > 0,
8097 test_msg("Expected > 0, got $count"));
8098 };
8099
8100 if ($@) {
8101 $ex = $@;
8102 }
8103
8104 $wfh->print("done\n");
8105 $wfh->flush();
8106
8107 } else {
8108 eval { server_wait($config_file, $rfh) };
8109 if ($@) {
8110 warn($@);
8111 exit 1;
8112 }
8113
8114 exit 0;
8115 }
8116
8117 # Stop server
8118 server_stop($pid_file);
8119
8120 $self->assert_child_ok($pid);
8121
8122 if ($ex) {
8123 test_append_logfile($log_file, $ex);
8124 unlink($log_file);
8125
8126 die($ex);
8127 }
8128
8129 unlink($log_file);
8130 }
8131
8132 sub tls_implicit_ssl_bug3437 {
8133 my $self = shift;
8134 my $tmpdir = $self->{tmpdir};
8135
8136 my $config_file = "$tmpdir/tls.conf";
8137 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
8138 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
8139
8140 my $log_file = test_get_logfile();
8141
8142 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
8143 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
8144
8145 my $user = 'proftpd';
8146 my $passwd = 'test';
8147 my $group = 'ftpd';
8148 my $home_dir = File::Spec->rel2abs($tmpdir);
8149 my $uid = 500;
8150 my $gid = 500;
8151
8152 # Make sure that, if we're running as root, that the home directory has
8153 # permissions/privs set for the account we create
8154 if ($< == 0) {
8155 unless (chmod(0755, $home_dir)) {
8156 die("Can't set perms on $home_dir to 0755: $!");
8157 }
8158
8159 unless (chown($uid, $gid, $home_dir)) {
8160 die("Can't set owner of $home_dir to $uid/$gid: $!");
8161 }
8162 }
8163
8164 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8165 '/bin/bash');
8166 auth_group_write($auth_group_file, $group, $gid, $user);
8167
8168 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8169 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8170
8171 my $config = {
8172
8173 # The stupid Net::FTPSSL client requires port 990 when implicit
8174 # FTPS is used, regardless of the port we pass to the constructor.
8175 # (What kind of client API does not allow the port to be changed??)
8176 Port => 990,
8177
8178 PidFile => $pid_file,
8179 ScoreboardFile => $scoreboard_file,
8180 SystemLog => $log_file,
8181 TraceLog => $log_file,
8182 Trace => 'DEFAULT:10',
8183
8184 AuthUserFile => $auth_user_file,
8185 AuthGroupFile => $auth_group_file,
8186
8187 IfModules => {
8188 'mod_delay.c' => {
8189 DelayEngine => 'off',
8190 },
8191
8192 'mod_tls.c' => {
8193 TLSEngine => 'on',
8194 TLSLog => $log_file,
8195 TLSRequired => 'off',
8196 TLSOptions => 'UseImplicitSSL',
8197 TLSRSACertificateFile => $cert_file,
8198 TLSCACertificateFile => $ca_file,
8199 },
8200 },
8201 };
8202
8203 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8204
8205 # Open pipes, for use between the parent and child processes. Specifically,
8206 # the child will indicate when it's done with its test by writing a message
8207 # to the parent.
8208 my ($rfh, $wfh);
8209 unless (pipe($rfh, $wfh)) {
8210 die("Can't open pipe: $!");
8211 }
8212
8213 require Net::FTPSSL;
8214
8215 my $ex;
8216
8217 # Fork child
8218 $self->handle_sigchld();
8219 defined(my $pid = fork()) or die("Can't fork: $!");
8220 if ($pid) {
8221 eval {
8222 # Give the server a chance to start up
8223 sleep(2);
8224
8225 my $client_opts = {
8226 Encryption => 'I',
8227 Port => $port,
8228 };
8229
8230 if ($ENV{TEST_VERBOSE}) {
8231 $client_opts->{Debug} = 1;
8232 }
8233
8234 my $client = Net::FTPSSL->new('127.0.0.1', %$client_opts);
8235
8236 unless ($client) {
8237 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
8238 }
8239
8240 unless ($client->login($user, $passwd)) {
8241 die("Can't login: " . $client->last_message());
8242 }
8243
8244 unless ($client->ccc('P')) {
8245 die("CCC failed: " . $client->last_message());
8246 }
8247
8248 $client->quit();
8249 };
8250
8251 if ($@) {
8252 $ex = $@;
8253 }
8254
8255 $wfh->print("done\n");
8256 $wfh->flush();
8257
8258 } else {
8259 eval { server_wait($config_file, $rfh) };
8260 if ($@) {
8261 warn($@);
8262 exit 1;
8263 }
8264
8265 exit 0;
8266 }
8267
8268 # Stop server
8269 server_stop($pid_file);
8270
8271 $self->assert_child_ok($pid);
8272
8273 if ($ex) {
8274 test_append_logfile($log_file, $ex);
8275 unlink($log_file);
8276
8277 die($ex);
8278 }
8279
8280 unlink($log_file);
8281 }
8282
8283 sub tls_ccc_list_bug3465 {
8284 my $self = shift;
8285 my $tmpdir = $self->{tmpdir};
8286
8287 my $config_file = "$tmpdir/tls.conf";
8288 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
8289 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
8290
8291 my $log_file = test_get_logfile();
8292
8293 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
8294 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
8295
8296 my $user = 'proftpd';
8297 my $passwd = 'test';
8298 my $group = 'ftpd';
8299 my $home_dir = File::Spec->rel2abs($tmpdir);
8300 my $uid = 500;
8301 my $gid = 500;
8302
8303 # Make sure that, if we're running as root, that the home directory has
8304 # permissions/privs set for the account we create
8305 if ($< == 0) {
8306 unless (chmod(0755, $home_dir)) {
8307 die("Can't set perms on $home_dir to 0755: $!");
8308 }
8309
8310 unless (chown($uid, $gid, $home_dir)) {
8311 die("Can't set owner of $home_dir to $uid/$gid: $!");
8312 }
8313 }
8314
8315 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8316 '/bin/bash');
8317 auth_group_write($auth_group_file, $group, $gid, $user);
8318
8319 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8320 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8321
8322 my $config = {
8323 PidFile => $pid_file,
8324 ScoreboardFile => $scoreboard_file,
8325 SystemLog => $log_file,
8326 TraceLog => $log_file,
8327 Trace => 'DEFAULT:10',
8328
8329 AuthUserFile => $auth_user_file,
8330 AuthGroupFile => $auth_group_file,
8331
8332 IfModules => {
8333 'mod_delay.c' => {
8334 DelayEngine => 'off',
8335 },
8336
8337 'mod_tls.c' => {
8338 TLSEngine => 'on',
8339 TLSLog => $log_file,
8340 TLSRequired => 'off',
8341 TLSOptions => 'NoSessionReuseRequired',
8342 TLSRSACertificateFile => $cert_file,
8343 TLSCACertificateFile => $ca_file,
8344 },
8345 },
8346 };
8347
8348 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8349
8350 # Open pipes, for use between the parent and child processes. Specifically,
8351 # the child will indicate when it's done with its test by writing a message
8352 # to the parent.
8353 my ($rfh, $wfh);
8354 unless (pipe($rfh, $wfh)) {
8355 die("Can't open pipe: $!");
8356 }
8357
8358 require Net::FTPSSL;
8359
8360 my $ex;
8361
8362 # Fork child
8363 $self->handle_sigchld();
8364 defined(my $pid = fork()) or die("Can't fork: $!");
8365 if ($pid) {
8366 eval {
8367 # Give the server a chance to start up
8368 sleep(2);
8369
8370 my $client_opts = {
8371 Encryption => 'E',
8372 Port => $port,
8373 };
8374
8375 if ($ENV{TEST_VERBOSE}) {
8376 $client_opts->{Debug} = 1;
8377 }
8378
8379 my $client = Net::FTPSSL->new('127.0.0.1', %$client_opts);
8380
8381 unless ($client) {
8382 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
8383 }
8384
8385 unless ($client->login($user, $passwd)) {
8386 die("Can't login: " . $client->last_message());
8387 }
8388
8389 unless ($client->ccc()) {
8390 die("CCC failed: " . $client->last_message());
8391 }
8392
8393 my $res = $client->list('.');
8394 unless ($res) {
8395 die("LIST failed: " . $client->message());
8396 }
8397
8398 $client->quit();
8399 };
8400
8401 if ($@) {
8402 $ex = $@;
8403 }
8404
8405 $wfh->print("done\n");
8406 $wfh->flush();
8407
8408 } else {
8409 eval { server_wait($config_file, $rfh) };
8410 if ($@) {
8411 warn($@);
8412 exit 1;
8413 }
8414
8415 exit 0;
8416 }
8417
8418 # Stop server
8419 server_stop($pid_file);
8420
8421 $self->assert_child_ok($pid);
8422
8423 if ($ex) {
8424 test_append_logfile($log_file, $ex);
8425 unlink($log_file);
8426
8427 die($ex);
8428 }
8429
8430 unlink($log_file);
8431 }
8432
8433 sub tls_ccc_before_login {
8434 my $self = shift;
8435 my $tmpdir = $self->{tmpdir};
8436 my $setup = test_setup($tmpdir, 'tls');
8437
8438 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8439 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8440
8441 my $config = {
8442 PidFile => $setup->{pid_file},
8443 ScoreboardFile => $setup->{scoreboard_file},
8444 SystemLog => $setup->{log_file},
8445 TraceLog => $setup->{log_file},
8446 Trace => 'DEFAULT:10 tls:20',
8447
8448 AuthUserFile => $setup->{auth_user_file},
8449 AuthGroupFile => $setup->{auth_group_file},
8450
8451 IfModules => {
8452 'mod_delay.c' => {
8453 DelayEngine => 'off',
8454 },
8455
8456 'mod_tls.c' => {
8457 TLSEngine => 'on',
8458 TLSLog => $setup->{log_file},
8459 TLSProtocol => 'TLSv1',
8460 TLSRequired => 'off',
8461 TLSOptions => 'NoSessionReuseRequired',
8462 TLSRSACertificateFile => $cert_file,
8463 TLSCACertificateFile => $ca_file,
8464 },
8465 },
8466 };
8467
8468 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
8469 $config);
8470
8471 # Open pipes, for use between the parent and child processes. Specifically,
8472 # the child will indicate when it's done with its test by writing a message
8473 # to the parent.
8474 my ($rfh, $wfh);
8475 unless (pipe($rfh, $wfh)) {
8476 die("Can't open pipe: $!");
8477 }
8478
8479 require Net::FTPSSL;
8480
8481 my $ex;
8482
8483 # Fork child
8484 $self->handle_sigchld();
8485 defined(my $pid = fork()) or die("Can't fork: $!");
8486 if ($pid) {
8487 eval {
8488 # Give the server a chance to start up
8489 sleep(2);
8490
8491 my $client_opts = {
8492 PeerHost => '127.0.0.1',
8493 PeerPort => $port,
8494 Proto => 'tcp',
8495 Type => SOCK_STREAM,
8496 Timeout => 10
8497 };
8498
8499 my $ssl_opts = {
8500 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
8501 };
8502
8503 my $client = IO::Socket::INET->new(%$client_opts);
8504 unless ($client) {
8505 die("Can't connect to 127.0.0.1:$port: $!");
8506 }
8507
8508 # Read the banner
8509 my $banner = <$client>;
8510 if ($ENV{TEST_VERBOSE}) {
8511 print STDOUT "# Received banner: $banner";
8512 }
8513
8514 # Send the AUTH command
8515 my $cmd = "AUTH TLS\r\n";
8516 if ($ENV{TEST_VERBOSE}) {
8517 print STDOUT "# Sending command: $cmd";
8518 }
8519 $client->print($cmd);
8520 $client->flush();
8521
8522 # Read the AUTH response
8523 my $resp = <$client>;
8524 if ($ENV{TEST_VERBOSE}) {
8525 print STDOUT "# Received response: $resp";
8526 }
8527
8528 my $expected = "234 AUTH TLS successful\r\n";
8529 unless ($expected eq $resp) {
8530 die("Expected response '$expected', got '$resp'");
8531 }
8532
8533 if ($ENV{TEST_VERBOSE}) {
8534 $IO::Socket::SSL::DEBUG = 3;
8535 }
8536
8537 my $res = IO::Socket::SSL->start_SSL($client, $ssl_opts);
8538 unless ($res) {
8539 croak("Failed SSL handshake: " . IO::Socket::SSL::errstr());
8540 }
8541
8542 $cmd = "CCC\r\n";
8543 if ($ENV{TEST_VERBOSE}) {
8544 print STDOUT "# Sending command: $cmd";
8545 }
8546 $client->print($cmd);
8547 $client->flush();
8548
8549 $resp = <$client>;
8550 if ($ENV{TEST_VERBOSE}) {
8551 print STDOUT "# Received response: $resp";
8552 }
8553
8554 $expected = "530 Please login with USER and PASS\r\n";
8555 unless ($expected eq $resp) {
8556 die("Expected response '$expected', got '$resp'");
8557 }
8558
8559 $res = $client->stop_SSL();
8560 unless ($res) {
8561 croak("Failed SSL shutdown: " . IO::Socket::SSL::errstr());
8562 }
8563
8564 $cmd = "QUIT\r\n";
8565 if ($ENV{TEST_VERBOSE}) {
8566 print STDOUT "# Sending command: $cmd";
8567 }
8568 $client->print($cmd);
8569 $client->flush();
8570
8571 $resp = <$client>;
8572 if ($ENV{TEST_VERBOSE}) {
8573 print STDOUT "# Received response: $resp";
8574 }
8575
8576 if ($resp) {
8577 die("Received response unexpectedly");
8578 }
8579
8580 $client->close();
8581 };
8582
8583 if ($@) {
8584 $ex = $@;
8585 }
8586
8587 $wfh->print("done\n");
8588 $wfh->flush();
8589
8590 } else {
8591 eval { server_wait($setup->{config_file}, $rfh) };
8592 if ($@) {
8593 warn($@);
8594 exit 1;
8595 }
8596
8597 exit 0;
8598 }
8599
8600 # Stop server
8601 server_stop($setup->{pid_file});
8602 $self->assert_child_ok($pid);
8603
8604 test_cleanup($setup->{log_file}, $ex);
8605 }
8606
8607 sub tls_opts_commonname_required_bug3512 {
8608 my $self = shift;
8609 my $tmpdir = $self->{tmpdir};
8610
8611 my $config_file = "$tmpdir/tls.conf";
8612 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
8613 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
8614
8615 my $log_file = test_get_logfile();
8616
8617 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
8618 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
8619
8620 my $user = 'proftpd';
8621 my $passwd = 'test';
8622 my $group = 'ftpd';
8623 my $home_dir = File::Spec->rel2abs($tmpdir);
8624 my $uid = 500;
8625 my $gid = 500;
8626
8627 # Make sure that, if we're running as root, that the home directory has
8628 # permissions/privs set for the account we create
8629 if ($< == 0) {
8630 unless (chmod(0755, $home_dir)) {
8631 die("Can't set perms on $home_dir to 0755: $!");
8632 }
8633
8634 unless (chown($uid, $gid, $home_dir)) {
8635 die("Can't set owner of $home_dir to $uid/$gid: $!");
8636 }
8637 }
8638
8639 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8640 '/bin/bash');
8641 auth_group_write($auth_group_file, $group, $gid, $user);
8642
8643 my $bad_client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
8644 my $good_client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert-localhost.pem');
8645
8646 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8647 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8648
8649 my $config = {
8650 PidFile => $pid_file,
8651 ScoreboardFile => $scoreboard_file,
8652 SystemLog => $log_file,
8653
8654 AuthUserFile => $auth_user_file,
8655 AuthGroupFile => $auth_group_file,
8656 UseReverseDNS => 'on',
8657
8658 IfModules => {
8659 'mod_delay.c' => {
8660 DelayEngine => 'off',
8661 },
8662
8663 'mod_tls.c' => {
8664 TLSEngine => 'on',
8665 TLSLog => $log_file,
8666 TLSRequired => 'on',
8667 TLSRSACertificateFile => $cert_file,
8668 TLSCACertificateFile => $ca_file,
8669 TLSOptions => 'CommonNameRequired',
8670 TLSVerifyClient => 'on',
8671 },
8672 },
8673 };
8674
8675 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8676
8677 # Open pipes, for use between the parent and child processes. Specifically,
8678 # the child will indicate when it's done with its test by writing a message
8679 # to the parent.
8680 my ($rfh, $wfh);
8681 unless (pipe($rfh, $wfh)) {
8682 die("Can't open pipe: $!");
8683 }
8684
8685 require Net::FTPSSL;
8686
8687 my $ex;
8688
8689 # Fork child
8690 $self->handle_sigchld();
8691 defined(my $pid = fork()) or die("Can't fork: $!");
8692 if ($pid) {
8693 eval {
8694 # Give the server a chance to start up
8695 sleep(2);
8696
8697 # IO::Socket::SSL options
8698 my $ssl_opts = {
8699 SSL_use_cert => 1,
8700 SSL_cert_file => $bad_client_cert,
8701 SSL_key_file => $bad_client_cert,
8702 SSL_ca_file => $ca_file,
8703 };
8704
8705 my $client;
8706 eval {
8707 $client = Net::FTPSSL->new('127.0.0.1',
8708 Croak => 1,
8709 Encryption => 'E',
8710 Port => $port,
8711 SSL_Client_Certificate => $ssl_opts,
8712 );
8713 };
8714
8715 unless ($@) {
8716 eval { $client->login($user, $passwd) };
8717 unless ($@) {
8718 die("Login succeeded unexpectedly");
8719 }
8720 }
8721
8722 $ssl_opts->{SSL_cert_file} = $good_client_cert;
8723 $ssl_opts->{SSL_key_file} = $good_client_cert;
8724
8725 $client = Net::FTPSSL->new('127.0.0.1',
8726 Croak => 1,
8727 Encryption => 'E',
8728 Port => $port,
8729 SSL_Client_Certificate => $ssl_opts,
8730 );
8731
8732 sleep(1);
8733
8734 unless ($client->login($user, $passwd)) {
8735 die("Can't login: " . $client->last_message());
8736 }
8737
8738 $client->quit();
8739 };
8740
8741 if ($@) {
8742 $ex = $@;
8743 }
8744
8745 $wfh->print("done\n");
8746 $wfh->flush();
8747
8748 } else {
8749 eval { server_wait($config_file, $rfh, 30) };
8750 if ($@) {
8751 warn($@);
8752 exit 1;
8753 }
8754
8755 exit 0;
8756 }
8757
8758 # Stop server
8759 server_stop($pid_file);
8760
8761 $self->assert_child_ok($pid);
8762
8763 if ($ex) {
8764 test_append_logfile($log_file, $ex);
8765 unlink($log_file);
8766
8767 die($ex);
8768 }
8769
8770 unlink($log_file);
8771 }
8772
8773 sub tls_opts_dns_name_required {
8774 my $self = shift;
8775 my $tmpdir = $self->{tmpdir};
8776
8777 my $config_file = "$tmpdir/tls.conf";
8778 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
8779 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
8780
8781 my $log_file = test_get_logfile();
8782
8783 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
8784 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
8785
8786 my $user = 'proftpd';
8787 my $passwd = 'test';
8788 my $group = 'ftpd';
8789 my $home_dir = File::Spec->rel2abs($tmpdir);
8790 my $uid = 500;
8791 my $gid = 500;
8792
8793 # Make sure that, if we're running as root, that the home directory has
8794 # permissions/privs set for the account we create
8795 if ($< == 0) {
8796 unless (chmod(0755, $home_dir)) {
8797 die("Can't set perms on $home_dir to 0755: $!");
8798 }
8799
8800 unless (chown($uid, $gid, $home_dir)) {
8801 die("Can't set owner of $home_dir to $uid/$gid: $!");
8802 }
8803 }
8804
8805 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8806 '/bin/bash');
8807 auth_group_write($auth_group_file, $group, $gid, $user);
8808
8809 my $bad_client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
8810 my $good_client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert-localhost.pem');
8811
8812 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8813 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8814
8815 my $config = {
8816 PidFile => $pid_file,
8817 ScoreboardFile => $scoreboard_file,
8818 SystemLog => $log_file,
8819
8820 AuthUserFile => $auth_user_file,
8821 AuthGroupFile => $auth_group_file,
8822 UseReverseDNS => 'on',
8823
8824 IfModules => {
8825 'mod_delay.c' => {
8826 DelayEngine => 'off',
8827 },
8828
8829 'mod_tls.c' => {
8830 TLSEngine => 'on',
8831 TLSLog => $log_file,
8832 TLSRequired => 'on',
8833 TLSRSACertificateFile => $cert_file,
8834 TLSCACertificateFile => $ca_file,
8835 TLSOptions => 'dNSNameRequired',
8836 TLSVerifyClient => 'on',
8837 },
8838 },
8839 };
8840
8841 my ($port, $config_user, $config_group) = config_write($config_file, $config);
8842
8843 # Open pipes, for use between the parent and child processes. Specifically,
8844 # the child will indicate when it's done with its test by writing a message
8845 # to the parent.
8846 my ($rfh, $wfh);
8847 unless (pipe($rfh, $wfh)) {
8848 die("Can't open pipe: $!");
8849 }
8850
8851 require Net::FTPSSL;
8852
8853 my $ex;
8854
8855 # Fork child
8856 $self->handle_sigchld();
8857 defined(my $pid = fork()) or die("Can't fork: $!");
8858 if ($pid) {
8859 eval {
8860 # Give the server a chance to start up
8861 sleep(2);
8862
8863 # IO::Socket::SSL options
8864 my $ssl_opts = {
8865 SSL_use_cert => 1,
8866 SSL_cert_file => $bad_client_cert,
8867 SSL_key_file => $bad_client_cert,
8868 SSL_ca_file => $ca_file,
8869 };
8870
8871 my $client;
8872 eval {
8873 $client = Net::FTPSSL->new('127.0.0.1',
8874 Croak => 1,
8875 Encryption => 'E',
8876 Port => $port,
8877 SSL_Client_Certificate => $ssl_opts,
8878 );
8879 };
8880
8881 unless ($@) {
8882 eval { $client->login($user, $passwd) };
8883 unless ($@) {
8884 die("Login succeeded unexpectedly");
8885 }
8886 }
8887
8888 $ssl_opts->{SSL_cert_file} = $good_client_cert;
8889 $ssl_opts->{SSL_key_file} = $good_client_cert;
8890
8891 $client = Net::FTPSSL->new('127.0.0.1',
8892 Croak => 1,
8893 Encryption => 'E',
8894 Port => $port,
8895 SSL_Client_Certificate => $ssl_opts,
8896 );
8897
8898 sleep(1);
8899
8900 unless ($client->login($user, $passwd)) {
8901 die("Can't login: " . $client->last_message());
8902 }
8903
8904 $client->quit();
8905 };
8906
8907 if ($@) {
8908 $ex = $@;
8909 }
8910
8911 $wfh->print("done\n");
8912 $wfh->flush();
8913
8914 } else {
8915 eval { server_wait($config_file, $rfh, 30) };
8916 if ($@) {
8917 warn($@);
8918 exit 1;
8919 }
8920
8921 exit 0;
8922 }
8923
8924 # Stop server
8925 server_stop($pid_file);
8926
8927 $self->assert_child_ok($pid);
8928
8929 if ($ex) {
8930 test_append_logfile($log_file, $ex);
8931 unlink($log_file);
8932
8933 die($ex);
8934 }
8935
8936 unlink($log_file);
8937 }
8938
8939 sub tls_opts_ip_addr_dns_name_cn_required {
8940 my $self = shift;
8941 my $tmpdir = $self->{tmpdir};
8942
8943 my $config_file = "$tmpdir/tls.conf";
8944 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
8945 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
8946
8947 my $log_file = test_get_logfile();
8948
8949 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
8950 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
8951
8952 my $user = 'proftpd';
8953 my $passwd = 'test';
8954 my $group = 'ftpd';
8955 my $home_dir = File::Spec->rel2abs($tmpdir);
8956 my $uid = 500;
8957 my $gid = 500;
8958
8959 # Make sure that, if we're running as root, that the home directory has
8960 # permissions/privs set for the account we create
8961 if ($< == 0) {
8962 unless (chmod(0755, $home_dir)) {
8963 die("Can't set perms on $home_dir to 0755: $!");
8964 }
8965
8966 unless (chown($uid, $gid, $home_dir)) {
8967 die("Can't set owner of $home_dir to $uid/$gid: $!");
8968 }
8969 }
8970
8971 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
8972 '/bin/bash');
8973 auth_group_write($auth_group_file, $group, $gid, $user);
8974
8975 my $bad_client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
8976 my $good_client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert-localhost.pem');
8977
8978 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
8979 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
8980
8981 my $config = {
8982 PidFile => $pid_file,
8983 ScoreboardFile => $scoreboard_file,
8984 SystemLog => $log_file,
8985
8986 AuthUserFile => $auth_user_file,
8987 AuthGroupFile => $auth_group_file,
8988 UseReverseDNS => 'on',
8989
8990 IfModules => {
8991 'mod_delay.c' => {
8992 DelayEngine => 'off',
8993 },
8994
8995 'mod_tls.c' => {
8996 TLSEngine => 'on',
8997 TLSLog => $log_file,
8998 TLSRequired => 'on',
8999 TLSRSACertificateFile => $cert_file,
9000 TLSCACertificateFile => $ca_file,
9001 TLSOptions => 'iPAddressRequired dNSNameRequired CommonNameRequired',
9002 TLSVerifyClient => 'on',
9003 },
9004 },
9005 };
9006
9007 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9008
9009 # Open pipes, for use between the parent and child processes. Specifically,
9010 # the child will indicate when it's done with its test by writing a message
9011 # to the parent.
9012 my ($rfh, $wfh);
9013 unless (pipe($rfh, $wfh)) {
9014 die("Can't open pipe: $!");
9015 }
9016
9017 require Net::FTPSSL;
9018
9019 my $ex;
9020
9021 # Fork child
9022 $self->handle_sigchld();
9023 defined(my $pid = fork()) or die("Can't fork: $!");
9024 if ($pid) {
9025 eval {
9026 # Give the server a chance to start up
9027 sleep(2);
9028
9029 # IO::Socket::SSL options
9030 my $ssl_opts = {
9031 SSL_use_cert => 1,
9032 SSL_cert_file => $bad_client_cert,
9033 SSL_key_file => $bad_client_cert,
9034 SSL_ca_file => $ca_file,
9035 };
9036
9037 my $client;
9038 eval {
9039 $client = Net::FTPSSL->new('127.0.0.1',
9040 Croak => 1,
9041 Encryption => 'E',
9042 Port => $port,
9043 SSL_Client_Certificate => $ssl_opts,
9044 );
9045 };
9046
9047 unless ($@) {
9048 eval { $client->login($user, $passwd) };
9049 unless ($@) {
9050 die("Login succeeded unexpectedly");
9051 }
9052 }
9053
9054 $ssl_opts->{SSL_cert_file} = $good_client_cert;
9055 $ssl_opts->{SSL_key_file} = $good_client_cert;
9056
9057 $client = Net::FTPSSL->new('127.0.0.1',
9058 Croak => 1,
9059 Encryption => 'E',
9060 Port => $port,
9061 SSL_Client_Certificate => $ssl_opts,
9062 );
9063
9064 sleep(1);
9065
9066 unless ($client->login($user, $passwd)) {
9067 die("Can't login: " . $client->last_message());
9068 }
9069
9070 $client->quit();
9071 };
9072
9073 if ($@) {
9074 $ex = $@;
9075 }
9076
9077 $wfh->print("done\n");
9078 $wfh->flush();
9079
9080 } else {
9081 eval { server_wait($config_file, $rfh, 30) };
9082 if ($@) {
9083 warn($@);
9084 exit 1;
9085 }
9086
9087 exit 0;
9088 }
9089
9090 # Stop server
9091 server_stop($pid_file);
9092
9093 $self->assert_child_ok($pid);
9094
9095 if ($ex) {
9096 test_append_logfile($log_file, $ex);
9097 unlink($log_file);
9098
9099 die($ex);
9100 }
9101
9102 unlink($log_file);
9103 }
9104
9105 sub tls_site_chmod_ok {
9106 my $self = shift;
9107 my $tmpdir = $self->{tmpdir};
9108
9109 my $config_file = "$tmpdir/tls.conf";
9110 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9111 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9112
9113 my $log_file = test_get_logfile();
9114
9115 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9116 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9117
9118 my $user = 'proftpd';
9119 my $passwd = 'test';
9120 my $group = 'ftpd';
9121 my $home_dir = File::Spec->rel2abs($tmpdir);
9122 my $uid = 500;
9123 my $gid = 500;
9124
9125 my $test_file = File::Spec->rel2abs("$tmpdir/test.txt");
9126 if (open(my $fh, "> $test_file")) {
9127 close($fh);
9128
9129 } else {
9130 die("Can't open $test_file: $!");
9131 }
9132
9133 # Make sure that, if we're running as root, that the home directory has
9134 # permissions/privs set for the account we create
9135 if ($< == 0) {
9136 unless (chmod(0755, $home_dir)) {
9137 die("Can't set perms on $home_dir to 0755: $!");
9138 }
9139
9140 unless (chown($uid, $gid, $home_dir, $test_file)) {
9141 die("Can't set owner of $home_dir to $uid/$gid: $!");
9142 }
9143 }
9144
9145 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9146 '/bin/bash');
9147 auth_group_write($auth_group_file, $group, $gid, $user);
9148
9149 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
9150 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
9151
9152 my $config = {
9153 PidFile => $pid_file,
9154 ScoreboardFile => $scoreboard_file,
9155 SystemLog => $log_file,
9156
9157 AuthUserFile => $auth_user_file,
9158 AuthGroupFile => $auth_group_file,
9159
9160 IfModules => {
9161 'mod_delay.c' => {
9162 DelayEngine => 'off',
9163 },
9164
9165 'mod_tls.c' => {
9166 TLSEngine => 'on',
9167 TLSLog => $log_file,
9168 TLSRequired => 'on',
9169 TLSRSACertificateFile => $cert_file,
9170 TLSCACertificateFile => $ca_file,
9171 },
9172 },
9173 };
9174
9175 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9176
9177 # Open pipes, for use between the parent and child processes. Specifically,
9178 # the child will indicate when it's done with its test by writing a message
9179 # to the parent.
9180 my ($rfh, $wfh);
9181 unless (pipe($rfh, $wfh)) {
9182 die("Can't open pipe: $!");
9183 }
9184
9185 require Net::FTPSSL;
9186
9187 my $ex;
9188
9189 # Fork child
9190 $self->handle_sigchld();
9191 defined(my $pid = fork()) or die("Can't fork: $!");
9192 if ($pid) {
9193 eval {
9194 # Give the server a chance to start up
9195 sleep(2);
9196
9197 my $client = Net::FTPSSL->new('127.0.0.1',
9198 Encryption => 'E',
9199 Port => $port,
9200 );
9201
9202 unless ($client) {
9203 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
9204 }
9205
9206 unless ($client->login($user, $passwd)) {
9207 die("Can't login: " . $client->last_message());
9208 }
9209
9210 unless ($client->site("CHMOD 777 test.txt")) {
9211 die("SITE CHMOD failed: " . $client->last_message());
9212 }
9213
9214 my $resp = $client->last_message();
9215
9216 my $expected;
9217
9218 $expected = '200 SITE CHMOD command successful';
9219 $self->assert($expected eq $resp,
9220 test_msg("Expected '$expected', got '$resp'"));
9221
9222 $client->quit();
9223
9224 my $perms = ((stat($test_file))[2] &07777);
9225
9226 $expected = 0777;
9227 $self->assert($expected == $perms,
9228 test_msg("Expected '$expected', got '$perms'"));
9229 };
9230
9231 if ($@) {
9232 $ex = $@;
9233 }
9234
9235 $wfh->print("done\n");
9236 $wfh->flush();
9237
9238 } else {
9239 eval { server_wait($config_file, $rfh) };
9240 if ($@) {
9241 warn($@);
9242 exit 1;
9243 }
9244
9245 exit 0;
9246 }
9247
9248 # Stop server
9249 server_stop($pid_file);
9250
9251 $self->assert_child_ok($pid);
9252
9253 if ($ex) {
9254 test_append_logfile($log_file, $ex);
9255 unlink($log_file);
9256
9257 die($ex);
9258 }
9259
9260 unlink($log_file);
9261 }
9262
9263 sub tls_default_tlsrequired {
9264 my $self = shift;
9265 my $tmpdir = $self->{tmpdir};
9266
9267 my $config_file = "$tmpdir/tls.conf";
9268 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9269 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9270
9271 my $log_file = test_get_logfile();
9272
9273 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9274 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9275
9276 my $user = 'proftpd';
9277 my $passwd = 'test';
9278 my $group = 'ftpd';
9279 my $home_dir = File::Spec->rel2abs($tmpdir);
9280 my $uid = 500;
9281 my $gid = 500;
9282
9283 # Make sure that, if we're running as root, that the home directory has
9284 # permissions/privs set for the account we create
9285 if ($< == 0) {
9286 unless (chmod(0755, $home_dir)) {
9287 die("Can't set perms on $home_dir to 0755: $!");
9288 }
9289
9290 unless (chown($uid, $gid, $home_dir)) {
9291 die("Can't set owner of $home_dir to $uid/$gid: $!");
9292 }
9293 }
9294
9295 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9296 '/bin/bash');
9297 auth_group_write($auth_group_file, $group, $gid, $user);
9298
9299 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
9300 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
9301
9302 my $config = {
9303 PidFile => $pid_file,
9304 ScoreboardFile => $scoreboard_file,
9305 SystemLog => $log_file,
9306
9307 AuthUserFile => $auth_user_file,
9308 AuthGroupFile => $auth_group_file,
9309
9310 IfModules => {
9311 'mod_delay.c' => {
9312 DelayEngine => 'off',
9313 },
9314
9315 'mod_tls.c' => {
9316 TLSEngine => 'on',
9317 TLSLog => $log_file,
9318 TLSRSACertificateFile => $cert_file,
9319 TLSCACertificateFile => $ca_file,
9320 },
9321 },
9322 };
9323
9324 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9325
9326 # Open pipes, for use between the parent and child processes. Specifically,
9327 # the child will indicate when it's done with its test by writing a message
9328 # to the parent.
9329 my ($rfh, $wfh);
9330 unless (pipe($rfh, $wfh)) {
9331 die("Can't open pipe: $!");
9332 }
9333
9334 require Net::FTPSSL;
9335
9336 my $ex;
9337
9338 # Fork child
9339 $self->handle_sigchld();
9340 defined(my $pid = fork()) or die("Can't fork: $!");
9341 if ($pid) {
9342 eval {
9343 # Give the server a chance to start up
9344 sleep(2);
9345
9346 # Login first with FTPS...
9347 my $client = Net::FTPSSL->new('127.0.0.1',
9348 Encryption => 'E',
9349 Port => $port,
9350 );
9351
9352 unless ($client) {
9353 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
9354 }
9355
9356 unless ($client->login($user, $passwd)) {
9357 die("Can't login: " . $client->last_message());
9358 }
9359
9360 $client->quit();
9361
9362 # Now log in using plain FTP
9363 $client = ProFTPD::TestSuite::FTP->new('127.0.0.1', $port);
9364 $client->login($user, $passwd);
9365 $client->quit();
9366 };
9367
9368 if ($@) {
9369 $ex = $@;
9370 }
9371
9372 $wfh->print("done\n");
9373 $wfh->flush();
9374
9375 } else {
9376 eval { server_wait($config_file, $rfh) };
9377 if ($@) {
9378 warn($@);
9379 exit 1;
9380 }
9381
9382 exit 0;
9383 }
9384
9385 # Stop server
9386 server_stop($pid_file);
9387
9388 $self->assert_child_ok($pid);
9389
9390 if ($ex) {
9391 test_append_logfile($log_file, $ex);
9392 unlink($log_file);
9393
9394 die($ex);
9395 }
9396
9397 unlink($log_file);
9398 }
9399
9400 sub tls_protocols_default {
9401 my $self = shift;
9402 my $tmpdir = $self->{tmpdir};
9403
9404 my $config_file = "$tmpdir/tls.conf";
9405 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9406 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9407
9408 my $log_file = test_get_logfile();
9409
9410 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9411 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9412
9413 my $user = 'proftpd';
9414 my $passwd = 'test';
9415 my $group = 'ftpd';
9416 my $home_dir = File::Spec->rel2abs($tmpdir);
9417 my $uid = 500;
9418 my $gid = 500;
9419
9420 # Make sure that, if we're running as root, that the home directory has
9421 # permissions/privs set for the account we create
9422 if ($< == 0) {
9423 unless (chmod(0755, $home_dir)) {
9424 die("Can't set perms on $home_dir to 0755: $!");
9425 }
9426
9427 unless (chown($uid, $gid, $home_dir)) {
9428 die("Can't set owner of $home_dir to $uid/$gid: $!");
9429 }
9430 }
9431
9432 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9433 '/bin/bash');
9434 auth_group_write($auth_group_file, $group, $gid, $user);
9435
9436 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
9437 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
9438
9439 my $config = {
9440 PidFile => $pid_file,
9441 ScoreboardFile => $scoreboard_file,
9442 SystemLog => $log_file,
9443
9444 AuthUserFile => $auth_user_file,
9445 AuthGroupFile => $auth_group_file,
9446
9447 IfModules => {
9448 'mod_delay.c' => {
9449 DelayEngine => 'off',
9450 },
9451
9452 'mod_tls.c' => {
9453 TLSEngine => 'on',
9454 TLSLog => $log_file,
9455 TLSRequired => 'on',
9456 TLSRSACertificateFile => $cert_file,
9457 TLSCACertificateFile => $ca_file,
9458 },
9459 },
9460 };
9461
9462 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9463
9464 # Open pipes, for use between the parent and child processes. Specifically,
9465 # the child will indicate when it's done with its test by writing a message
9466 # to the parent.
9467 my ($rfh, $wfh);
9468 unless (pipe($rfh, $wfh)) {
9469 die("Can't open pipe: $!");
9470 }
9471
9472 require Net::FTPSSL;
9473
9474 my $ex;
9475
9476 # Fork child
9477 $self->handle_sigchld();
9478 defined(my $pid = fork()) or die("Can't fork: $!");
9479 if ($pid) {
9480 eval {
9481 # Give the server a chance to start up
9482 sleep(2);
9483
9484 my $client = Net::FTPSSL->new('127.0.0.1',
9485 Encryption => 'E',
9486 Port => $port,
9487 );
9488
9489 unless ($client) {
9490 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
9491 }
9492
9493 unless ($client->login($user, $passwd)) {
9494 die("Can't login: " . $client->last_message());
9495 }
9496
9497 unless ($client->noop()) {
9498 die("NOOP failed: " . $client->last_message());
9499 }
9500
9501 $client->quit();
9502 };
9503
9504 if ($@) {
9505 $ex = $@;
9506 }
9507
9508 $wfh->print("done\n");
9509 $wfh->flush();
9510
9511 } else {
9512 eval { server_wait($config_file, $rfh) };
9513 if ($@) {
9514 warn($@);
9515 exit 1;
9516 }
9517
9518 exit 0;
9519 }
9520
9521 # Stop server
9522 server_stop($pid_file);
9523
9524 $self->assert_child_ok($pid);
9525
9526 if ($ex) {
9527 test_append_logfile($log_file, $ex);
9528 unlink($log_file);
9529
9530 die($ex);
9531 }
9532
9533 unlink($log_file);
9534 }
9535
9536 sub tls_protocols_with_ftps {
9537 my $self = shift;
9538 my $tmpdir = $self->{tmpdir};
9539
9540 my $config_file = "$tmpdir/tls.conf";
9541 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9542 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9543
9544 my $log_file = test_get_logfile();
9545
9546 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9547 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9548
9549 my $user = 'proftpd';
9550 my $passwd = 'test';
9551 my $group = 'ftpd';
9552 my $home_dir = File::Spec->rel2abs($tmpdir);
9553 my $uid = 500;
9554 my $gid = 500;
9555
9556 # Make sure that, if we're running as root, that the home directory has
9557 # permissions/privs set for the account we create
9558 if ($< == 0) {
9559 unless (chmod(0755, $home_dir)) {
9560 die("Can't set perms on $home_dir to 0755: $!");
9561 }
9562
9563 unless (chown($uid, $gid, $home_dir)) {
9564 die("Can't set owner of $home_dir to $uid/$gid: $!");
9565 }
9566 }
9567
9568 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9569 '/bin/bash');
9570 auth_group_write($auth_group_file, $group, $gid, $user);
9571
9572 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
9573 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
9574
9575 my $config = {
9576 PidFile => $pid_file,
9577 ScoreboardFile => $scoreboard_file,
9578 SystemLog => $log_file,
9579
9580 AuthUserFile => $auth_user_file,
9581 AuthGroupFile => $auth_group_file,
9582
9583 Protocols => 'ftps',
9584
9585 IfModules => {
9586 'mod_delay.c' => {
9587 DelayEngine => 'off',
9588 },
9589
9590 'mod_tls.c' => {
9591 TLSEngine => 'on',
9592 TLSLog => $log_file,
9593 TLSRequired => 'on',
9594 TLSRSACertificateFile => $cert_file,
9595 TLSCACertificateFile => $ca_file,
9596 },
9597 },
9598 };
9599
9600 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9601
9602 # Open pipes, for use between the parent and child processes. Specifically,
9603 # the child will indicate when it's done with its test by writing a message
9604 # to the parent.
9605 my ($rfh, $wfh);
9606 unless (pipe($rfh, $wfh)) {
9607 die("Can't open pipe: $!");
9608 }
9609
9610 require Net::FTPSSL;
9611
9612 my $ex;
9613
9614 # Fork child
9615 $self->handle_sigchld();
9616 defined(my $pid = fork()) or die("Can't fork: $!");
9617 if ($pid) {
9618 eval {
9619 # Give the server a chance to start up
9620 sleep(2);
9621
9622 my $client = Net::FTPSSL->new('127.0.0.1',
9623 Encryption => 'E',
9624 Port => $port,
9625 );
9626
9627 unless ($client) {
9628 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
9629 }
9630
9631 unless ($client->login($user, $passwd)) {
9632 die("Can't login: " . $client->last_message());
9633 }
9634
9635 unless ($client->noop()) {
9636 die("NOOP failed: " . $client->last_message());
9637 }
9638
9639 $client->quit();
9640 };
9641
9642 if ($@) {
9643 $ex = $@;
9644 }
9645
9646 $wfh->print("done\n");
9647 $wfh->flush();
9648
9649 } else {
9650 eval { server_wait($config_file, $rfh) };
9651 if ($@) {
9652 warn($@);
9653 exit 1;
9654 }
9655
9656 exit 0;
9657 }
9658
9659 # Stop server
9660 server_stop($pid_file);
9661
9662 $self->assert_child_ok($pid);
9663
9664 if ($ex) {
9665 test_append_logfile($log_file, $ex);
9666 unlink($log_file);
9667
9668 die($ex);
9669 }
9670
9671 unlink($log_file);
9672 }
9673
9674 sub tls_protocols_without_ftps {
9675 my $self = shift;
9676 my $tmpdir = $self->{tmpdir};
9677
9678 my $config_file = "$tmpdir/tls.conf";
9679 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9680 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9681
9682 my $log_file = test_get_logfile();
9683
9684 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9685 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9686
9687 my $user = 'proftpd';
9688 my $passwd = 'test';
9689 my $group = 'ftpd';
9690 my $home_dir = File::Spec->rel2abs($tmpdir);
9691 my $uid = 500;
9692 my $gid = 500;
9693
9694 # Make sure that, if we're running as root, that the home directory has
9695 # permissions/privs set for the account we create
9696 if ($< == 0) {
9697 unless (chmod(0755, $home_dir)) {
9698 die("Can't set perms on $home_dir to 0755: $!");
9699 }
9700
9701 unless (chown($uid, $gid, $home_dir)) {
9702 die("Can't set owner of $home_dir to $uid/$gid: $!");
9703 }
9704 }
9705
9706 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9707 '/bin/bash');
9708 auth_group_write($auth_group_file, $group, $gid, $user);
9709
9710 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
9711 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
9712
9713 my $config = {
9714 PidFile => $pid_file,
9715 ScoreboardFile => $scoreboard_file,
9716 SystemLog => $log_file,
9717
9718 AuthUserFile => $auth_user_file,
9719 AuthGroupFile => $auth_group_file,
9720
9721 Protocols => 'ftp',
9722
9723 IfModules => {
9724 'mod_delay.c' => {
9725 DelayEngine => 'off',
9726 },
9727
9728 'mod_tls.c' => {
9729 TLSEngine => 'on',
9730 TLSLog => $log_file,
9731 TLSRequired => 'on',
9732 TLSRSACertificateFile => $cert_file,
9733 TLSCACertificateFile => $ca_file,
9734 },
9735 },
9736 };
9737
9738 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9739
9740 # Open pipes, for use between the parent and child processes. Specifically,
9741 # the child will indicate when it's done with its test by writing a message
9742 # to the parent.
9743 my ($rfh, $wfh);
9744 unless (pipe($rfh, $wfh)) {
9745 die("Can't open pipe: $!");
9746 }
9747
9748 require Net::FTPSSL;
9749
9750 my $ex;
9751
9752 # Fork child
9753 $self->handle_sigchld();
9754 defined(my $pid = fork()) or die("Can't fork: $!");
9755 if ($pid) {
9756 eval {
9757 # Give the server a chance to start up
9758 sleep(2);
9759
9760 my $client = Net::FTPSSL->new('127.0.0.1',
9761 Encryption => 'E',
9762 Port => $port,
9763 );
9764
9765 unless ($client) {
9766 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
9767 }
9768
9769 if ($client->login($user, $passwd)) {
9770 die("Login succeeded unexpectedly");
9771 }
9772
9773 my $resp_msg = $client->last_message();
9774
9775 my $expected = '530 Login incorrect.';
9776 $self->assert($expected eq $resp_msg,
9777 test_msg("Expected '$expected', got '$resp_msg'"));
9778 };
9779
9780 if ($@) {
9781 $ex = $@;
9782 }
9783
9784 $wfh->print("done\n");
9785 $wfh->flush();
9786
9787 } else {
9788 eval { server_wait($config_file, $rfh) };
9789 if ($@) {
9790 warn($@);
9791 exit 1;
9792 }
9793
9794 exit 0;
9795 }
9796
9797 # Stop server
9798 server_stop($pid_file);
9799
9800 $self->assert_child_ok($pid);
9801
9802 if ($ex) {
9803 test_append_logfile($log_file, $ex);
9804 unlink($log_file);
9805
9806 die($ex);
9807 }
9808
9809 unlink($log_file);
9810 }
9811
9812 sub tls_ifsess_protocols_with_ftps {
9813 my $self = shift;
9814 my $tmpdir = $self->{tmpdir};
9815
9816 my $config_file = "$tmpdir/tls.conf";
9817 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9818 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9819
9820 my $log_file = test_get_logfile();
9821
9822 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9823 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9824
9825 my $user = 'proftpd';
9826 my $passwd = 'test';
9827 my $group = 'ftpd';
9828 my $home_dir = File::Spec->rel2abs($tmpdir);
9829 my $uid = 500;
9830 my $gid = 500;
9831
9832 # Make sure that, if we're running as root, that the home directory has
9833 # permissions/privs set for the account we create
9834 if ($< == 0) {
9835 unless (chmod(0755, $home_dir)) {
9836 die("Can't set perms on $home_dir to 0755: $!");
9837 }
9838
9839 unless (chown($uid, $gid, $home_dir)) {
9840 die("Can't set owner of $home_dir to $uid/$gid: $!");
9841 }
9842 }
9843
9844 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
9845 '/bin/bash');
9846 auth_group_write($auth_group_file, $group, $gid, $user);
9847
9848 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
9849 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
9850
9851 my $config = {
9852 PidFile => $pid_file,
9853 ScoreboardFile => $scoreboard_file,
9854 SystemLog => $log_file,
9855
9856 AuthUserFile => $auth_user_file,
9857 AuthGroupFile => $auth_group_file,
9858
9859 IfModules => {
9860 'mod_delay.c' => {
9861 DelayEngine => 'off',
9862 },
9863
9864 'mod_tls.c' => {
9865 TLSEngine => 'on',
9866 TLSLog => $log_file,
9867 TLSRequired => 'on',
9868 TLSRSACertificateFile => $cert_file,
9869 TLSCACertificateFile => $ca_file,
9870 },
9871 },
9872 };
9873
9874 my ($port, $config_user, $config_group) = config_write($config_file, $config);
9875
9876 if (open(my $fh, ">> $config_file")) {
9877 print $fh <<EOC;
9878
9879 <IfModule mod_ifsession.c>
9880 <IfUser foo>
9881 Protocols bar baz
9882 </IfUser>
9883
9884 <IfUser $user>
9885 Protocols ftps
9886 </IfUser>
9887 </IfModule>
9888 EOC
9889 unless (close($fh)) {
9890 die("Can't write $config_file: $!");
9891 }
9892
9893 } else {
9894 die("Can't open $config_file: $!");
9895 }
9896
9897 # Open pipes, for use between the parent and child processes. Specifically,
9898 # the child will indicate when it's done with its test by writing a message
9899 # to the parent.
9900 my ($rfh, $wfh);
9901 unless (pipe($rfh, $wfh)) {
9902 die("Can't open pipe: $!");
9903 }
9904
9905 require Net::FTPSSL;
9906
9907 my $ex;
9908
9909 # Fork child
9910 $self->handle_sigchld();
9911 defined(my $pid = fork()) or die("Can't fork: $!");
9912 if ($pid) {
9913 eval {
9914 # Give the server a chance to start up
9915 sleep(2);
9916
9917 my $client = Net::FTPSSL->new('127.0.0.1',
9918 Encryption => 'E',
9919 Port => $port,
9920 );
9921
9922 unless ($client) {
9923 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
9924 }
9925
9926 unless ($client->login($user, $passwd)) {
9927 die("Can't login: " . $client->last_message());
9928 }
9929
9930 unless ($client->noop()) {
9931 die("NOOP failed: " . $client->last_message());
9932 }
9933
9934 $client->quit();
9935 };
9936
9937 if ($@) {
9938 $ex = $@;
9939 }
9940
9941 $wfh->print("done\n");
9942 $wfh->flush();
9943
9944 } else {
9945 eval { server_wait($config_file, $rfh) };
9946 if ($@) {
9947 warn($@);
9948 exit 1;
9949 }
9950
9951 exit 0;
9952 }
9953
9954 # Stop server
9955 server_stop($pid_file);
9956
9957 $self->assert_child_ok($pid);
9958
9959 if ($ex) {
9960 test_append_logfile($log_file, $ex);
9961 unlink($log_file);
9962
9963 die($ex);
9964 }
9965
9966 unlink($log_file);
9967 }
9968
9969 sub tls_ifsess_protocols_without_ftps {
9970 my $self = shift;
9971 my $tmpdir = $self->{tmpdir};
9972
9973 my $config_file = "$tmpdir/tls.conf";
9974 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
9975 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
9976
9977 my $log_file = test_get_logfile();
9978
9979 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
9980 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
9981
9982 my $user = 'proftpd';
9983 my $passwd = 'test';
9984 my $group = 'ftpd';
9985 my $home_dir = File::Spec->rel2abs($tmpdir);
9986 my $uid = 500;
9987 my $gid = 500;
9988
9989 # Make sure that, if we're running as root, that the home directory has
9990 # permissions/privs set for the account we create
9991 if ($< == 0) {
9992 unless (chmod(0755, $home_dir)) {
9993 die("Can't set perms on $home_dir to 0755: $!");
9994 }
9995
9996 unless (chown($uid, $gid, $home_dir)) {
9997 die("Can't set owner of $home_dir to $uid/$gid: $!");
9998 }
9999 }
10000
10001 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10002 '/bin/bash');
10003 auth_group_write($auth_group_file, $group, $gid, $user);
10004
10005 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
10006 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10007
10008 my $config = {
10009 PidFile => $pid_file,
10010 ScoreboardFile => $scoreboard_file,
10011 SystemLog => $log_file,
10012
10013 AuthUserFile => $auth_user_file,
10014 AuthGroupFile => $auth_group_file,
10015
10016 IfModules => {
10017 'mod_delay.c' => {
10018 DelayEngine => 'off',
10019 },
10020
10021 'mod_tls.c' => {
10022 TLSEngine => 'on',
10023 TLSLog => $log_file,
10024 TLSRequired => 'on',
10025 TLSRSACertificateFile => $cert_file,
10026 TLSCACertificateFile => $ca_file,
10027 },
10028 },
10029 };
10030
10031 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10032
10033 if (open(my $fh, ">> $config_file")) {
10034 print $fh <<EOC;
10035
10036 <IfModule mod_ifsession.c>
10037 <IfUser foo>
10038 Protocols ftps
10039 </IfUser>
10040
10041 <IfUser $user>
10042 Protocols foo bar
10043 </IfUser>
10044 </IfModule>
10045 EOC
10046 unless (close($fh)) {
10047 die("Can't write $config_file: $!");
10048 }
10049
10050 } else {
10051 die("Can't open $config_file: $!");
10052 }
10053
10054 # Open pipes, for use between the parent and child processes. Specifically,
10055 # the child will indicate when it's done with its test by writing a message
10056 # to the parent.
10057 my ($rfh, $wfh);
10058 unless (pipe($rfh, $wfh)) {
10059 die("Can't open pipe: $!");
10060 }
10061
10062 require Net::FTPSSL;
10063
10064 my $ex;
10065
10066 # Fork child
10067 $self->handle_sigchld();
10068 defined(my $pid = fork()) or die("Can't fork: $!");
10069 if ($pid) {
10070 eval {
10071 # Give the server a chance to start up
10072 sleep(2);
10073
10074 my $client = Net::FTPSSL->new('127.0.0.1',
10075 Encryption => 'E',
10076 Port => $port,
10077 );
10078
10079 unless ($client) {
10080 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
10081 }
10082
10083 if ($client->login($user, $passwd)) {
10084 die("Login succeeded unexpectedly");
10085 }
10086
10087 my $resp_msg = $client->last_message();
10088
10089 my $expected = '530 Login incorrect.';
10090 $self->assert($expected eq $resp_msg,
10091 test_msg("Expected '$expected', got '$resp_msg'"));
10092 };
10093
10094 if ($@) {
10095 $ex = $@;
10096 }
10097
10098 $wfh->print("done\n");
10099 $wfh->flush();
10100
10101 } else {
10102 eval { server_wait($config_file, $rfh) };
10103 if ($@) {
10104 warn($@);
10105 exit 1;
10106 }
10107
10108 exit 0;
10109 }
10110
10111 # Stop server
10112 server_stop($pid_file);
10113
10114 $self->assert_child_ok($pid);
10115
10116 if ($ex) {
10117 test_append_logfile($log_file, $ex);
10118 unlink($log_file);
10119
10120 die($ex);
10121 }
10122
10123 unlink($log_file);
10124 }
10125
10126 sub tls_sess_cache_internal_bug3580 {
10127 my $self = shift;
10128 my $tmpdir = $self->{tmpdir};
10129
10130 my $config_file = "$tmpdir/tls.conf";
10131 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
10132 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
10133
10134 my $log_file = test_get_logfile();
10135
10136 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
10137 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
10138
10139 my $user = 'proftpd';
10140 my $passwd = 'test';
10141 my $group = 'ftpd';
10142 my $home_dir = File::Spec->rel2abs($tmpdir);
10143 my $uid = 500;
10144 my $gid = 500;
10145
10146 # Make sure that, if we're running as root, that the home directory has
10147 # permissions/privs set for the account we create
10148 if ($< == 0) {
10149 unless (chmod(0755, $home_dir)) {
10150 die("Can't set perms on $home_dir to 0755: $!");
10151 }
10152
10153 unless (chown($uid, $gid, $home_dir)) {
10154 die("Can't set owner of $home_dir to $uid/$gid: $!");
10155 }
10156 }
10157
10158 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10159 '/bin/bash');
10160 auth_group_write($auth_group_file, $group, $gid, $user);
10161
10162 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
10163 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10164
10165 my $config = {
10166 PidFile => $pid_file,
10167 ScoreboardFile => $scoreboard_file,
10168 SystemLog => $log_file,
10169
10170 AuthUserFile => $auth_user_file,
10171 AuthGroupFile => $auth_group_file,
10172
10173 IfModules => {
10174 'mod_delay.c' => {
10175 DelayEngine => 'off',
10176 },
10177
10178 'mod_tls.c' => {
10179 TLSEngine => 'on',
10180 TLSLog => $log_file,
10181 TLSRequired => 'on',
10182 TLSRSACertificateFile => $cert_file,
10183 TLSCACertificateFile => $ca_file,
10184
10185 TLSSessionCache => 'internal: 1800'
10186 },
10187 },
10188 };
10189
10190 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10191
10192 # Open pipes, for use between the parent and child processes. Specifically,
10193 # the child will indicate when it's done with its test by writing a message
10194 # to the parent.
10195 my ($rfh, $wfh);
10196 unless (pipe($rfh, $wfh)) {
10197 die("Can't open pipe: $!");
10198 }
10199
10200 require Net::FTPSSL;
10201
10202 my $ex;
10203
10204 # Fork child
10205 $self->handle_sigchld();
10206 defined(my $pid = fork()) or die("Can't fork: $!");
10207 if ($pid) {
10208 eval {
10209 # Give the server a chance to start up
10210 sleep(2);
10211
10212 my $client = Net::FTPSSL->new('127.0.0.1',
10213 Encryption => 'E',
10214 Port => $port,
10215 );
10216
10217 unless ($client) {
10218 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
10219 }
10220
10221 unless ($client->login($user, $passwd)) {
10222 die("Can't login: " . $client->last_message());
10223 }
10224 };
10225
10226 if ($@) {
10227 $ex = $@;
10228 }
10229
10230 $wfh->print("done\n");
10231 $wfh->flush();
10232
10233 } else {
10234 eval { server_wait($config_file, $rfh) };
10235 if ($@) {
10236 warn($@);
10237 exit 1;
10238 }
10239
10240 exit 0;
10241 }
10242
10243 # Stop server
10244 server_stop($pid_file);
10245
10246 $self->assert_child_ok($pid);
10247
10248 if ($ex) {
10249 test_append_logfile($log_file, $ex);
10250 unlink($log_file);
10251
10252 die($ex);
10253 }
10254
10255 unlink($log_file);
10256 }
10257
10258 sub tls_passphraseprovider_rsacertfile {
10259 my $self = shift;
10260 my $tmpdir = $self->{tmpdir};
10261 my $setup = test_setup($tmpdir, 'tls');
10262
10263 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert-passwd.pem');
10264 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10265 my $passphrase_provider = File::Spec->rel2abs('t/etc/modules/mod_tls/tls-get-passphrase.pl');
10266
10267 my $config = {
10268 PidFile => $setup->{pid_file},
10269 ScoreboardFile => $setup->{scoreboard_file},
10270 SystemLog => $setup->{log_file},
10271 TraceLog => $setup->{log_file},
10272 Trace => 'DEFAULT:20 tls:20',
10273
10274 AuthUserFile => $setup->{auth_user_file},
10275 AuthGroupFile => $setup->{auth_group_file},
10276
10277 IfModules => {
10278 'mod_delay.c' => {
10279 DelayEngine => 'off',
10280 },
10281
10282 'mod_tls.c' => {
10283 TLSEngine => 'on',
10284 TLSLog => $setup->{log_file},
10285 TLSRequired => 'on',
10286 TLSOptions => 'AllowWeakSecurity',
10287 TLSRSACertificateFile => $cert_file,
10288 TLSCACertificateFile => $ca_file,
10289
10290 TLSPassPhraseProvider => $passphrase_provider,
10291 },
10292 },
10293 };
10294
10295 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
10296 $config);
10297
10298 # Open pipes, for use between the parent and child processes. Specifically,
10299 # the child will indicate when it's done with its test by writing a message
10300 # to the parent.
10301 my ($rfh, $wfh);
10302 unless (pipe($rfh, $wfh)) {
10303 die("Can't open pipe: $!");
10304 }
10305
10306 require Net::FTPSSL;
10307
10308 my $ex;
10309
10310 # Fork child
10311 $self->handle_sigchld();
10312 defined(my $pid = fork()) or die("Can't fork: $!");
10313 if ($pid) {
10314 eval {
10315 # Give the server a chance to start up
10316 sleep(5);
10317
10318 my $client = Net::FTPSSL->new('127.0.0.1',
10319 Encryption => 'E',
10320 Port => $port,
10321 );
10322
10323 unless ($client) {
10324 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
10325 }
10326
10327 unless ($client->login($setup->{user}, $setup->{passwd})) {
10328 die("Can't login: " . $client->last_message());
10329 }
10330
10331 $client->quit();
10332 };
10333 if ($@) {
10334 $ex = $@;
10335 }
10336
10337 $wfh->print("done\n");
10338 $wfh->flush();
10339
10340 } else {
10341 eval { server_wait($setup->{config_file}, $rfh) };
10342 if ($@) {
10343 warn($@);
10344 exit 1;
10345 }
10346
10347 exit 0;
10348 }
10349
10350 # Stop server
10351 server_stop($setup->{pid_file});
10352 $self->assert_child_ok($pid);
10353
10354 test_cleanup($setup->{log_file}, $ex);
10355 }
10356
10357 sub tls_passphraseprovider_rsakeyfile_issue1179 {
10358 my $self = shift;
10359 my $tmpdir = $self->{tmpdir};
10360 my $setup = test_setup($tmpdir, 'tls');
10361
10362 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert-passwd.pem');
10363 my $key_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert-passwd.key');
10364 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10365 my $passphrase_provider = File::Spec->rel2abs('t/etc/modules/mod_tls/tls-get-passphrase.pl');
10366
10367 my $config = {
10368 PidFile => $setup->{pid_file},
10369 ScoreboardFile => $setup->{scoreboard_file},
10370 SystemLog => $setup->{log_file},
10371 TraceLog => $setup->{log_file},
10372 Trace => 'DEFAULT:20 tls:20',
10373
10374 AuthUserFile => $setup->{auth_user_file},
10375 AuthGroupFile => $setup->{auth_group_file},
10376
10377 IfModules => {
10378 'mod_delay.c' => {
10379 DelayEngine => 'off',
10380 },
10381
10382 'mod_tls.c' => {
10383 TLSEngine => 'on',
10384 TLSLog => $setup->{log_file},
10385 TLSRequired => 'on',
10386 TLSOptions => 'AllowWeakSecurity',
10387 TLSRSACertificateFile => $cert_file,
10388 TLSRSACertificateKeyFile => $key_file,
10389 TLSCACertificateFile => $ca_file,
10390
10391 TLSPassPhraseProvider => $passphrase_provider,
10392 },
10393 },
10394 };
10395
10396 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
10397 $config);
10398
10399 # Open pipes, for use between the parent and child processes. Specifically,
10400 # the child will indicate when it's done with its test by writing a message
10401 # to the parent.
10402 my ($rfh, $wfh);
10403 unless (pipe($rfh, $wfh)) {
10404 die("Can't open pipe: $!");
10405 }
10406
10407 require Net::FTPSSL;
10408
10409 my $ex;
10410
10411 # Fork child
10412 $self->handle_sigchld();
10413 defined(my $pid = fork()) or die("Can't fork: $!");
10414 if ($pid) {
10415 eval {
10416 # Give the server a chance to start up
10417 sleep(5);
10418
10419 my $client = Net::FTPSSL->new('127.0.0.1',
10420 Encryption => 'E',
10421 Port => $port,
10422 );
10423
10424 unless ($client) {
10425 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
10426 }
10427
10428 unless ($client->login($setup->{user}, $setup->{passwd})) {
10429 die("Can't login: " . $client->last_message());
10430 }
10431 };
10432 if ($@) {
10433 $ex = $@;
10434 }
10435
10436 $wfh->print("done\n");
10437 $wfh->flush();
10438
10439 } else {
10440 eval { server_wait($setup->{config_file}, $rfh) };
10441 if ($@) {
10442 warn($@);
10443 exit 1;
10444 }
10445
10446 exit 0;
10447 }
10448
10449 # Stop server
10450 server_stop($setup->{pid_file});
10451 $self->assert_child_ok($pid);
10452
10453 test_cleanup($setup->{log_file}, $ex);
10454 }
10455
10456 sub tls_verify_order_crl_bug3658 {
10457 my $self = shift;
10458 my $tmpdir = $self->{tmpdir};
10459
10460 my $config_file = "$tmpdir/tls.conf";
10461 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
10462 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
10463
10464 my $log_file = test_get_logfile();
10465
10466 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
10467 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
10468
10469 my $user = 'proftpd';
10470 my $passwd = 'test';
10471 my $group = 'ftpd';
10472 my $home_dir = File::Spec->rel2abs($tmpdir);
10473 my $uid = 500;
10474 my $gid = 500;
10475
10476 # Make sure that, if we're running as root, that the home directory has
10477 # permissions/privs set for the account we create
10478 if ($< == 0) {
10479 unless (chmod(0755, $home_dir)) {
10480 die("Can't set perms on $home_dir to 0755: $!");
10481 }
10482
10483 unless (chown($uid, $gid, $home_dir)) {
10484 die("Can't set owner of $home_dir to $uid/$gid: $!");
10485 }
10486 }
10487
10488 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10489 '/bin/bash');
10490 auth_group_write($auth_group_file, $group, $gid, $user);
10491
10492 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-server-cert.pem');
10493 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-client-cert.pem');
10494 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-ca.pem');
10495 my $crl_file = File::Spec->rel2abs('t/etc/modules/mod_tls/crl-ca-revoked.pem');
10496
10497 my $config = {
10498 PidFile => $pid_file,
10499 ScoreboardFile => $scoreboard_file,
10500 SystemLog => $log_file,
10501
10502 AuthUserFile => $auth_user_file,
10503 AuthGroupFile => $auth_group_file,
10504
10505 IfModules => {
10506 'mod_delay.c' => {
10507 DelayEngine => 'off',
10508 },
10509
10510 'mod_tls.c' => {
10511 TLSEngine => 'on',
10512 TLSLog => $log_file,
10513 TLSRequired => 'on',
10514 TLSRSACertificateFile => $server_cert,
10515 TLSCACertificateFile => $ca_cert,
10516
10517 # Verifying clients via CRLs only works when verification is
10518 # explicitly enabled.
10519 TLSCARevocationFile => $crl_file,
10520 TLSVerifyClient => 'on',
10521 TLSVerifyOrder => 'crl',
10522 },
10523 },
10524 };
10525
10526 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10527
10528 # Open pipes, for use between the parent and child processes. Specifically,
10529 # the child will indicate when it's done with its test by writing a message
10530 # to the parent.
10531 my ($rfh, $wfh);
10532 unless (pipe($rfh, $wfh)) {
10533 die("Can't open pipe: $!");
10534 }
10535
10536 require Net::FTPSSL;
10537
10538 my $ex;
10539
10540 # Fork child
10541 $self->handle_sigchld();
10542 defined(my $pid = fork()) or die("Can't fork: $!");
10543 if ($pid) {
10544 eval {
10545 # Give the server a chance to start up
10546 sleep(2);
10547
10548 my $client;
10549
10550 eval {
10551 # IO::Socket::SSL options
10552 my $ssl_opts = {
10553 SSL_use_cert => 1,
10554 SSL_cert_file => $client_cert,
10555 SSL_key_file => $client_cert,
10556 SSL_ca_file => $ca_cert,
10557 };
10558
10559 $client = Net::FTPSSL->new('127.0.0.1',
10560 Croak => 1,
10561 Encryption => 'E',
10562 Port => $port,
10563 SSL_Client_Certificate => $ssl_opts,
10564 );
10565 };
10566
10567 my $ex = $@;
10568 unless ($ex) {
10569 die("SSL connection succeeded unexpectedly");
10570 }
10571
10572 my $errstr = IO::Socket::SSL::errstr();
10573
10574 my $expected = 'certificate revoked';
10575 $self->assert(qr/$expected/, $errstr,
10576 test_msg("Expected '$expected', got '$errstr'"));
10577 };
10578
10579 if ($@) {
10580 $ex = $@;
10581 }
10582
10583 $wfh->print("done\n");
10584 $wfh->flush();
10585
10586 } else {
10587 eval { server_wait($config_file, $rfh) };
10588 if ($@) {
10589 warn($@);
10590 exit 1;
10591 }
10592
10593 exit 0;
10594 }
10595
10596 # Stop server
10597 server_stop($pid_file);
10598
10599 $self->assert_child_ok($pid);
10600
10601 if ($ex) {
10602 test_append_logfile($log_file, $ex);
10603 unlink($log_file);
10604
10605 die($ex);
10606 }
10607
10608 unlink($log_file);
10609 }
10610
10611 sub tls_verify_order_ocsp {
10612 my $self = shift;
10613 my $tmpdir = $self->{tmpdir};
10614
10615 my $config_file = "$tmpdir/tls.conf";
10616 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
10617 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
10618
10619 my $log_file = test_get_logfile();
10620
10621 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
10622 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
10623
10624 my $user = 'proftpd';
10625 my $passwd = 'test';
10626 my $group = 'ftpd';
10627 my $home_dir = File::Spec->rel2abs($tmpdir);
10628 my $uid = 500;
10629 my $gid = 500;
10630
10631 # Make sure that, if we're running as root, that the home directory has
10632 # permissions/privs set for the account we create
10633 if ($< == 0) {
10634 unless (chmod(0755, $home_dir)) {
10635 die("Can't set perms on $home_dir to 0755: $!");
10636 }
10637
10638 unless (chown($uid, $gid, $home_dir)) {
10639 die("Can't set owner of $home_dir to $uid/$gid: $!");
10640 }
10641 }
10642
10643 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10644 '/bin/bash');
10645 auth_group_write($auth_group_file, $group, $gid, $user);
10646
10647 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ocsp-server.pem');
10648 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ocsp-client.pem');
10649 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ocsp-ca.pem');
10650
10651 # XXX NOTE: Make sure the OCSP responder is running, at URL:
10652 #
10653 # http://localhost:7777
10654 #
10655 # since that is the OCSP URI baked into the OCSP client cert.
10656 #
10657 # To do this, go to the cert-tool/ directory, and run:
10658 #
10659 # openssl ocsp -index etc/cert-tool.index -CA ocsp-ca.pem \
10660 # -rsigner ocsp-ca.pem -url http://localhost:7777
10661
10662 my $config = {
10663 PidFile => $pid_file,
10664 ScoreboardFile => $scoreboard_file,
10665 SystemLog => $log_file,
10666
10667 AuthUserFile => $auth_user_file,
10668 AuthGroupFile => $auth_group_file,
10669
10670 IfModules => {
10671 'mod_delay.c' => {
10672 DelayEngine => 'off',
10673 },
10674
10675 'mod_tls.c' => {
10676 TLSEngine => 'on',
10677 TLSLog => $log_file,
10678 TLSRequired => 'on',
10679 TLSRSACertificateFile => $server_cert,
10680 TLSCACertificateFile => $ca_cert,
10681
10682 TLSOptions => 'EnableDiags',
10683
10684 # Verifying clients via OCSP only works when verification is
10685 # explicitly enabled.
10686 TLSVerifyClient => 'on',
10687
10688 TLSVerifyOrder => 'ocsp',
10689 },
10690 },
10691 };
10692
10693 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10694
10695 # Open pipes, for use between the parent and child processes. Specifically,
10696 # the child will indicate when it's done with its test by writing a message
10697 # to the parent.
10698 my ($rfh, $wfh);
10699 unless (pipe($rfh, $wfh)) {
10700 die("Can't open pipe: $!");
10701 }
10702
10703 require Net::FTPSSL;
10704
10705 my $ex;
10706
10707 # Fork child
10708 $self->handle_sigchld();
10709 defined(my $pid = fork()) or die("Can't fork: $!");
10710 if ($pid) {
10711 eval {
10712 # Give the server a chance to start up
10713 sleep(2);
10714
10715 my $client;
10716
10717 eval {
10718 # IO::Socket::SSL options
10719 my $ssl_opts = {
10720 SSL_use_cert => 1,
10721 SSL_cert_file => $client_cert,
10722 SSL_key_file => $client_cert,
10723 SSL_ca_file => $ca_cert,
10724 };
10725
10726 $client = Net::FTPSSL->new('127.0.0.1',
10727 Croak => 1,
10728 Encryption => 'E',
10729 Port => $port,
10730 SSL_Client_Certificate => $ssl_opts,
10731 );
10732 };
10733
10734 my $ex = $@;
10735 unless ($ex) {
10736 die("SSL connection succeeded unexpectedly");
10737 }
10738
10739 my $errstr = IO::Socket::SSL::errstr();
10740
10741 # In this case, since the CA which is needed to verify the OCSP
10742 # response has been revoked, the OCSP response can't be verified,
10743 # which results in a handshake failure.
10744 my $expected = 'handshake failure';
10745 $self->assert(qr/$expected/, $errstr,
10746 test_msg("Expected '$expected', got '$errstr'"));
10747 };
10748
10749 if ($@) {
10750 $ex = $@;
10751 }
10752
10753 $wfh->print("done\n");
10754 $wfh->flush();
10755
10756 } else {
10757 eval { server_wait($config_file, $rfh) };
10758 if ($@) {
10759 warn($@);
10760 exit 1;
10761 }
10762
10763 exit 0;
10764 }
10765
10766 # Stop server
10767 server_stop($pid_file);
10768
10769 $self->assert_child_ok($pid);
10770
10771 if ($ex) {
10772 test_append_logfile($log_file, $ex);
10773 unlink($log_file);
10774
10775 die($ex);
10776 }
10777
10778 unlink($log_file);
10779 }
10780
10781 sub tls_verify_order_ocsp_https {
10782 my $self = shift;
10783 my $tmpdir = $self->{tmpdir};
10784
10785 my $config_file = "$tmpdir/tls.conf";
10786 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
10787 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
10788
10789 my $log_file = test_get_logfile();
10790
10791 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
10792 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
10793
10794 my $user = 'proftpd';
10795 my $passwd = 'test';
10796 my $group = 'ftpd';
10797 my $home_dir = File::Spec->rel2abs($tmpdir);
10798 my $uid = 500;
10799 my $gid = 500;
10800
10801 # Make sure that, if we're running as root, that the home directory has
10802 # permissions/privs set for the account we create
10803 if ($< == 0) {
10804 unless (chmod(0755, $home_dir)) {
10805 die("Can't set perms on $home_dir to 0755: $!");
10806 }
10807
10808 unless (chown($uid, $gid, $home_dir)) {
10809 die("Can't set owner of $home_dir to $uid/$gid: $!");
10810 }
10811 }
10812
10813 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10814 '/bin/bash');
10815 auth_group_write($auth_group_file, $group, $gid, $user);
10816
10817 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ocsp-https-server.pem');
10818 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ocsp-https-client.pem');
10819 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ocsp-https-ca.pem');
10820
10821 # XXX NOTE: Make sure the OCSP responder is running, at URL:
10822 #
10823 # https://localhost:7777
10824 #
10825 # since that is the OCSP URI baked into the OCSP client cert.
10826 #
10827 # To do this, go to the cert-tool/ directory, and run:
10828 #
10829 # openssl ocsp -index etc/cert-tool.index -CA ocsp-https-ca.pem \
10830 # -rsigner ocsp-https-ca.pem -url https://localhost:7777
10831
10832 my $config = {
10833 PidFile => $pid_file,
10834 ScoreboardFile => $scoreboard_file,
10835 SystemLog => $log_file,
10836
10837 AuthUserFile => $auth_user_file,
10838 AuthGroupFile => $auth_group_file,
10839
10840 IfModules => {
10841 'mod_delay.c' => {
10842 DelayEngine => 'off',
10843 },
10844
10845 'mod_tls.c' => {
10846 TLSEngine => 'on',
10847 TLSLog => $log_file,
10848 TLSRequired => 'on',
10849 TLSRSACertificateFile => $server_cert,
10850 TLSCACertificateFile => $ca_cert,
10851
10852 TLSOptions => 'EnableDiags',
10853
10854 # Verifying clients via OCSP only works when verification is
10855 # explicitly enabled.
10856 TLSVerifyClient => 'on',
10857
10858 TLSVerifyOrder => 'ocsp',
10859 },
10860 },
10861 };
10862
10863 my ($port, $config_user, $config_group) = config_write($config_file, $config);
10864
10865 # Open pipes, for use between the parent and child processes. Specifically,
10866 # the child will indicate when it's done with its test by writing a message
10867 # to the parent.
10868 my ($rfh, $wfh);
10869 unless (pipe($rfh, $wfh)) {
10870 die("Can't open pipe: $!");
10871 }
10872
10873 require Net::FTPSSL;
10874
10875 my $ex;
10876
10877 # Fork child
10878 $self->handle_sigchld();
10879 defined(my $pid = fork()) or die("Can't fork: $!");
10880 if ($pid) {
10881 eval {
10882 # Give the server a chance to start up
10883 sleep(2);
10884
10885 my $client;
10886
10887 eval {
10888 # IO::Socket::SSL options
10889 my $ssl_opts = {
10890 SSL_use_cert => 1,
10891 SSL_cert_file => $client_cert,
10892 SSL_key_file => $client_cert,
10893 SSL_ca_file => $ca_cert,
10894 };
10895
10896 $client = Net::FTPSSL->new('127.0.0.1',
10897 Croak => 1,
10898 Encryption => 'E',
10899 Port => $port,
10900 SSL_Client_Certificate => $ssl_opts,
10901 );
10902 };
10903
10904 my $ex = $@;
10905 unless ($ex) {
10906 die("SSL connection succeeded unexpectedly");
10907 }
10908
10909 my $errstr = IO::Socket::SSL::errstr();
10910
10911 # In this case, since the CA which is needed to verify the OCSP
10912 # response has been revoked, the OCSP response can't be verified,
10913 # which results in a handshake failure.
10914 my $expected = 'handshake failure';
10915 $self->assert(qr/$expected/, $errstr,
10916 test_msg("Expected '$expected', got '$errstr'"));
10917 };
10918
10919 if ($@) {
10920 $ex = $@;
10921 }
10922
10923 $wfh->print("done\n");
10924 $wfh->flush();
10925
10926 } else {
10927 eval { server_wait($config_file, $rfh) };
10928 if ($@) {
10929 warn($@);
10930 exit 1;
10931 }
10932
10933 exit 0;
10934 }
10935
10936 # Stop server
10937 server_stop($pid_file);
10938
10939 $self->assert_child_ok($pid);
10940
10941 if ($ex) {
10942 test_append_logfile($log_file, $ex);
10943 unlink($log_file);
10944
10945 die($ex);
10946 }
10947
10948 unlink($log_file);
10949 }
10950
10951 sub tls_client_cert_verify_failed_selfsigned_cert_only_bug3742 {
10952 my $self = shift;
10953 my $tmpdir = $self->{tmpdir};
10954
10955 my $config_file = "$tmpdir/tls.conf";
10956 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
10957 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
10958
10959 my $log_file = test_get_logfile();
10960
10961 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
10962 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
10963
10964 my $user = 'proftpd';
10965 my $passwd = 'test';
10966 my $group = 'ftpd';
10967 my $home_dir = File::Spec->rel2abs($tmpdir);
10968 my $uid = 500;
10969 my $gid = 500;
10970
10971 # Make sure that, if we're running as root, that the home directory has
10972 # permissions/privs set for the account we create
10973 if ($< == 0) {
10974 unless (chmod(0755, $home_dir)) {
10975 die("Can't set perms on $home_dir to 0755: $!");
10976 }
10977
10978 unless (chown($uid, $gid, $home_dir)) {
10979 die("Can't set owner of $home_dir to $uid/$gid: $!");
10980 }
10981 }
10982
10983 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
10984 '/bin/bash');
10985 auth_group_write($auth_group_file, $group, $gid, $user);
10986
10987 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
10988 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
10989
10990 # Deliberately use the bug3742-ca.pem, which is self-signed CA cert, as the
10991 # client cert. And we deliberately use a different self-signed CA than
10992 # the one in ca-cert.pem, since that ca-cert.pem is also used by the
10993 # server.
10994 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/bug3742-ca.pem');
10995 my $client_key = File::Spec->rel2abs('t/etc/modules/mod_tls/bug3742-ca.pem');
10996
10997 my $config = {
10998 PidFile => $pid_file,
10999 ScoreboardFile => $scoreboard_file,
11000 SystemLog => $log_file,
11001
11002 AuthUserFile => $auth_user_file,
11003 AuthGroupFile => $auth_group_file,
11004
11005 IfModules => {
11006 'mod_delay.c' => {
11007 DelayEngine => 'off',
11008 },
11009
11010 'mod_tls.c' => {
11011 TLSEngine => 'on',
11012 TLSLog => $log_file,
11013 TLSRequired => 'on',
11014 TLSRSACertificateFile => $server_cert,
11015 TLSCACertificateFile => $ca_cert,
11016 TLSVerifyClient => 'on',
11017 },
11018 },
11019 };
11020
11021 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11022
11023 # Open pipes, for use between the parent and child processes. Specifically,
11024 # the child will indicate when it's done with its test by writing a message
11025 # to the parent.
11026 my ($rfh, $wfh);
11027 unless (pipe($rfh, $wfh)) {
11028 die("Can't open pipe: $!");
11029 }
11030
11031 require Net::FTPSSL;
11032
11033 my $ex;
11034
11035 # Fork child
11036 $self->handle_sigchld();
11037 defined(my $pid = fork()) or die("Can't fork: $!");
11038 if ($pid) {
11039 eval {
11040 # Give the server a chance to start up
11041 sleep(2);
11042
11043 my $client;
11044
11045 eval {
11046 # IO::Socket::SSL options
11047 my $ssl_opts = {
11048 SSL_use_cert => 1,
11049 SSL_cert_file => $client_cert,
11050 SSL_key_file => $client_key,
11051 SSL_ca_file => $ca_cert,
11052 };
11053
11054 eval {
11055 $client = Net::FTPSSL->new('127.0.0.1',
11056 Croak => 1,
11057 Encryption => 'E',
11058 Port => $port,
11059 SSL_Client_Certificate => $ssl_opts,
11060 );
11061 };
11062
11063 # This should die of an exception like:
11064 #
11065 # error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca
11066
11067 unless ($@) {
11068 die("Successfully connected to FTPS server unexpectedly");
11069 }
11070
11071 };
11072
11073 if ($@) {
11074 die($@);
11075 }
11076 };
11077
11078 if ($@) {
11079 $ex = $@;
11080 }
11081
11082 $wfh->print("done\n");
11083 $wfh->flush();
11084
11085 } else {
11086 eval { server_wait($config_file, $rfh) };
11087 if ($@) {
11088 warn($@);
11089 exit 1;
11090 }
11091
11092 exit 0;
11093 }
11094
11095 # Stop server
11096 server_stop($pid_file);
11097
11098 $self->assert_child_ok($pid);
11099
11100 if ($ex) {
11101 test_append_logfile($log_file, $ex);
11102 unlink($log_file);
11103
11104 die($ex);
11105 }
11106
11107 unlink($log_file);
11108 }
11109
11110 sub tls_client_cert_verify_failed_selfsigned_cert_in_chain_bug3742 {
11111 my $self = shift;
11112 my $tmpdir = $self->{tmpdir};
11113
11114 my $config_file = "$tmpdir/tls.conf";
11115 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
11116 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
11117
11118 my $log_file = test_get_logfile();
11119
11120 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
11121 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
11122
11123 my $user = 'proftpd';
11124 my $passwd = 'test';
11125 my $group = 'ftpd';
11126 my $home_dir = File::Spec->rel2abs($tmpdir);
11127 my $uid = 500;
11128 my $gid = 500;
11129
11130 # Make sure that, if we're running as root, that the home directory has
11131 # permissions/privs set for the account we create
11132 if ($< == 0) {
11133 unless (chmod(0755, $home_dir)) {
11134 die("Can't set perms on $home_dir to 0755: $!");
11135 }
11136
11137 unless (chown($uid, $gid, $home_dir)) {
11138 die("Can't set owner of $home_dir to $uid/$gid: $!");
11139 }
11140 }
11141
11142 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11143 '/bin/bash');
11144 auth_group_write($auth_group_file, $group, $gid, $user);
11145
11146 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
11147 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11148
11149 # To get the client to send a list of certs (including a self-signed CA)
11150 # to the server, we use a cert file which contains a list of certs
11151 # (including the client cert). Easy.
11152
11153 my $client_cert = File::Spec->rel2abs("$tmpdir/client-cert-chain.pem");
11154 if (open(my $outfh, "> $client_cert")) {
11155 # First the client cert
11156 my $cert = File::Spec->rel2abs('t/etc/modules/mod_tls/bug3742-client.pem');
11157
11158 if (open(my $infh, "< $cert")) {
11159 # Slurp in all of the data at once. Just easier that way.
11160 local $/;
11161
11162 my $data = <$infh>;
11163 close($infh);
11164
11165 print $outfh $data;
11166
11167 } else {
11168 die("Can't read $cert: $!");
11169 }
11170
11171 # Next the client CA
11172 $cert = File::Spec->rel2abs('t/etc/modules/mod_tls/bug3742-ca.pem');
11173
11174 if (open(my $infh, "< $cert")) {
11175 # Slurp in all of the data at once. Just easier that way.
11176 local $/;
11177
11178 my $data = <$infh>;
11179 close($infh);
11180
11181 print $outfh $data;
11182
11183 } else {
11184 die("Can't read $cert: $!");
11185 }
11186
11187 unless (close($outfh)) {
11188 die("Can't write $client_cert: $!");
11189 }
11190
11191 } else {
11192 die("Can't open $client_cert: $!");
11193 }
11194
11195 my $client_key = File::Spec->rel2abs('t/etc/modules/mod_tls/bug3742-client.pem');
11196
11197 my $config = {
11198 PidFile => $pid_file,
11199 ScoreboardFile => $scoreboard_file,
11200 SystemLog => $log_file,
11201
11202 AuthUserFile => $auth_user_file,
11203 AuthGroupFile => $auth_group_file,
11204
11205 IfModules => {
11206 'mod_delay.c' => {
11207 DelayEngine => 'off',
11208 },
11209
11210 'mod_tls.c' => {
11211 TLSEngine => 'on',
11212 TLSLog => $log_file,
11213 TLSRequired => 'on',
11214 TLSRSACertificateFile => $server_cert,
11215 TLSCACertificateFile => $ca_cert,
11216 TLSVerifyClient => 'on',
11217 },
11218 },
11219 };
11220
11221 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11222
11223 # Open pipes, for use between the parent and child processes. Specifically,
11224 # the child will indicate when it's done with its test by writing a message
11225 # to the parent.
11226 my ($rfh, $wfh);
11227 unless (pipe($rfh, $wfh)) {
11228 die("Can't open pipe: $!");
11229 }
11230
11231 require Net::FTPSSL;
11232
11233 my $ex;
11234
11235 # Fork child
11236 $self->handle_sigchld();
11237 defined(my $pid = fork()) or die("Can't fork: $!");
11238 if ($pid) {
11239 eval {
11240 # Give the server a chance to start up
11241 sleep(2);
11242
11243 my $client;
11244
11245 eval {
11246 # IO::Socket::SSL options
11247 my $ssl_opts = {
11248 SSL_use_cert => 1,
11249 SSL_cert_file => $client_cert,
11250 SSL_key_file => $client_key,
11251 };
11252
11253 eval {
11254 $client = Net::FTPSSL->new('127.0.0.1',
11255 Croak => 1,
11256 Encryption => 'E',
11257 Port => $port,
11258 SSL_Client_Certificate => $ssl_opts,
11259 );
11260 };
11261
11262 # This should die of an exception like:
11263 #
11264 # error:14094418:SSL routines:SSL3_READ_BYTES:tlsv1 alert unknown ca
11265
11266 unless ($@) {
11267 die("Successfully connected to FTPS server unexpectedly");
11268 }
11269
11270 };
11271
11272 if ($@) {
11273 die($@);
11274 }
11275 };
11276
11277 if ($@) {
11278 $ex = $@;
11279 }
11280
11281 $wfh->print("done\n");
11282 $wfh->flush();
11283
11284 } else {
11285 eval { server_wait($config_file, $rfh) };
11286 if ($@) {
11287 warn($@);
11288 exit 1;
11289 }
11290
11291 exit 0;
11292 }
11293
11294 # Stop server
11295 server_stop($pid_file);
11296
11297 $self->assert_child_ok($pid);
11298
11299 if ($ex) {
11300 test_append_logfile($log_file, $ex);
11301 unlink($log_file);
11302
11303 die($ex);
11304 }
11305
11306 unlink($log_file);
11307 }
11308
11309 sub tls_client_cert_verify_ok_server_selfsigned_cert_in_chain_bug3742 {
11310 my $self = shift;
11311 my $tmpdir = $self->{tmpdir};
11312 my $setup = test_setup($tmpdir, 'tls');
11313
11314 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
11315 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11316
11317 # To get the client to send a list of certs (including a self-signed CA)
11318 # to the server, we use a cert file which contains a list of certs
11319 # (including the client cert). Easy.
11320
11321 my $client_cert = File::Spec->rel2abs("$tmpdir/client-cert-chain.pem");
11322 if (open(my $outfh, "> $client_cert")) {
11323 # First the client cert
11324 my $cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
11325
11326 if (open(my $infh, "< $cert")) {
11327 # Slurp in all of the data at once. Just easier that way.
11328 local $/;
11329
11330 my $data = <$infh>;
11331 close($infh);
11332
11333 print $outfh $data;
11334
11335 } else {
11336 die("Can't read $cert: $!");
11337 }
11338
11339 # Next the client CA. This time, use the same CA that the server is
11340 # using (and trusting).
11341 $cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11342
11343 if (open(my $infh, "< $cert")) {
11344 # Slurp in all of the data at once. Just easier that way.
11345 local $/;
11346
11347 my $data = <$infh>;
11348 close($infh);
11349
11350 print $outfh $data;
11351
11352 } else {
11353 die("Can't read $cert: $!");
11354 }
11355
11356 unless (close($outfh)) {
11357 die("Can't write $client_cert: $!");
11358 }
11359
11360 } else {
11361 die("Can't open $client_cert: $!");
11362 }
11363
11364 my $client_key = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
11365
11366 my $config = {
11367 PidFile => $setup->{pid_file},
11368 ScoreboardFile => $setup->{scoreboard_file},
11369 SystemLog => $setup->{log_file},
11370
11371 AuthUserFile => $setup->{auth_user_file},
11372 AuthGroupFile => $setup->{auth_group_file},
11373
11374 IfModules => {
11375 'mod_delay.c' => {
11376 DelayEngine => 'off',
11377 },
11378
11379 'mod_tls.c' => {
11380 TLSEngine => 'on',
11381 TLSLog => $setup->{log_file},
11382 TLSOptions => 'EnableDiags',
11383 TLSRequired => 'on',
11384 TLSRSACertificateFile => $server_cert,
11385 TLSCACertificateFile => $ca_cert,
11386 TLSVerifyClient => 'on',
11387 },
11388 },
11389 };
11390
11391 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
11392 $config);
11393
11394 # Open pipes, for use between the parent and child processes. Specifically,
11395 # the child will indicate when it's done with its test by writing a message
11396 # to the parent.
11397 my ($rfh, $wfh);
11398 unless (pipe($rfh, $wfh)) {
11399 die("Can't open pipe: $!");
11400 }
11401
11402 require Net::FTPSSL;
11403
11404 my $ex;
11405
11406 # Fork child
11407 $self->handle_sigchld();
11408 defined(my $pid = fork()) or die("Can't fork: $!");
11409 if ($pid) {
11410 eval {
11411 # Give the server a chance to start up
11412 sleep(2);
11413
11414 my $client;
11415
11416 eval {
11417 # IO::Socket::SSL options
11418 my $ssl_opts = {
11419 SSL_use_cert => 1,
11420 SSL_cert_file => $client_cert,
11421 SSL_key_file => $client_key,
11422 SSL_ca_file => $ca_cert,
11423 };
11424
11425 $client = Net::FTPSSL->new('127.0.0.1',
11426 Croak => 1,
11427 Encryption => 'E',
11428 Port => $port,
11429 SSL_Client_Certificate => $ssl_opts,
11430 );
11431
11432 # If no exception was thrown at this point, we have succeeded.
11433 };
11434 if ($@) {
11435 die($@);
11436 }
11437 };
11438
11439 if ($@) {
11440 $ex = $@;
11441 }
11442
11443 $wfh->print("done\n");
11444 $wfh->flush();
11445
11446 } else {
11447 eval { server_wait($setup->{config_file}, $rfh) };
11448 if ($@) {
11449 warn($@);
11450 exit 1;
11451 }
11452
11453 exit 0;
11454 }
11455
11456 # Stop server
11457 server_stop($setup->{pid_file});
11458 $self->assert_child_ok($pid);
11459
11460 test_cleanup($setup->{log_file}, $ex);
11461 }
11462
11463 sub tls_opts_allow_dot_login_ok {
11464 my $self = shift;
11465 my $tmpdir = $self->{tmpdir};
11466 my $setup = test_setup($tmpdir, 'tls');
11467
11468 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
11469 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
11470 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11471
11472 my $tlslogin_file = File::Spec->rel2abs("$tmpdir/.tlslogin");
11473 unless (copy($client_cert, $tlslogin_file)) {
11474 die("Can't copy $client_cert to $tlslogin_file: $!");
11475 }
11476
11477 my $config = {
11478 PidFile => $setup->{pid_file},
11479 ScoreboardFile => $setup->{scoreboard_file},
11480 SystemLog => $setup->{log_file},
11481 TraceLog => $setup->{log_file},
11482 Trace => 'tls:30',
11483
11484 AuthUserFile => $setup->{auth_user_file},
11485 AuthGroupFile => $setup->{auth_group_file},
11486 AuthOrder => 'mod_auth_file.c',
11487
11488 IfModules => {
11489 'mod_delay.c' => {
11490 DelayEngine => 'off',
11491 },
11492
11493 'mod_tls.c' => {
11494 TLSEngine => 'on',
11495 TLSLog => $setup->{log_file},
11496 TLSRequired => 'on',
11497 TLSRSACertificateFile => $server_cert,
11498 TLSCACertificateFile => $ca_cert,
11499 TLSVerifyClient => 'optional',
11500 TLSOptions => 'AllowDotLogin',
11501 },
11502 },
11503 };
11504
11505 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
11506 $config);
11507
11508 # Open pipes, for use between the parent and child processes. Specifically,
11509 # the child will indicate when it's done with its test by writing a message
11510 # to the parent.
11511 my ($rfh, $wfh);
11512 unless (pipe($rfh, $wfh)) {
11513 die("Can't open pipe: $!");
11514 }
11515
11516 require Net::FTPSSL;
11517
11518 my $ex;
11519
11520 # Fork child
11521 $self->handle_sigchld();
11522 defined(my $pid = fork()) or die("Can't fork: $!");
11523 if ($pid) {
11524 eval {
11525 # Give the server a chance to start up
11526 sleep(2);
11527
11528 # IO::Socket::SSL options
11529 my $ssl_opts = {
11530 SSL_use_cert => 1,
11531 SSL_cert_file => $client_cert,
11532 SSL_key_file => $client_cert,
11533 SSL_ca_file => $ca_cert,
11534 };
11535
11536 my $client = Net::FTPSSL->new('127.0.0.1',
11537 Croak => 1,
11538 Encryption => 'E',
11539 Port => $port,
11540 SSL_Client_Certificate => $ssl_opts,
11541 );
11542
11543 unless ($client) {
11544 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
11545 }
11546
11547 unless ($client->_user($setup->{user})) {
11548 die("USER error: " . $client->last_message());
11549 }
11550
11551 my $expected = "232 User $setup->{user} logged in";
11552 my $resp = $client->last_message();
11553 $self->assert($expected eq $resp,
11554 test_msg("Expected response '$expected', got '$resp'"));
11555
11556 if ($client->_passwd()) {
11557 die("PASS succeeded unexpectedly");
11558 }
11559
11560 $expected = "503 You are already logged in";
11561 $resp = $client->last_message();
11562 $self->assert($expected eq $resp,
11563 test_msg("Expected response '$expected', got '$resp'"));
11564 };
11565 if ($@) {
11566 $ex = $@;
11567 }
11568
11569 $wfh->print("done\n");
11570 $wfh->flush();
11571
11572 } else {
11573 eval { server_wait($setup->{config_file}, $rfh) };
11574 if ($@) {
11575 warn($@);
11576 exit 1;
11577 }
11578
11579 exit 0;
11580 }
11581
11582 # Stop server
11583 server_stop($setup->{pid_file});
11584 $self->assert_child_ok($pid);
11585
11586 test_cleanup($setup->{log_file}, $ex);
11587 }
11588
11589 sub tls_opts_allow_dot_login_mismatch {
11590 my $self = shift;
11591 my $tmpdir = $self->{tmpdir};
11592 my $setup = test_setup($tmpdir, 'tls');
11593
11594 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
11595 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
11596 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11597
11598 my $tlslogin_file = File::Spec->rel2abs("$tmpdir/.tlslogin");
11599
11600 # Deliberately copy the wrong certificate into the .tlslogin file.
11601 unless (copy($server_cert, $tlslogin_file)) {
11602 die("Can't copy $server_cert to $tlslogin_file: $!");
11603 }
11604
11605 my $config = {
11606 PidFile => $setup->{pid_file},
11607 ScoreboardFile => $setup->{scoreboard_file},
11608 SystemLog => $setup->{log_file},
11609 TraceLog => $setup->{log_file},
11610 Trace => 'tls:30',
11611
11612 AuthUserFile => $setup->{auth_user_file},
11613 AuthGroupFile => $setup->{auth_group_file},
11614 AuthOrder => 'mod_auth_file.c',
11615
11616 IfModules => {
11617 'mod_delay.c' => {
11618 DelayEngine => 'off',
11619 },
11620
11621 'mod_tls.c' => {
11622 TLSEngine => 'on',
11623 TLSLog => $setup->{log_file},
11624 TLSRequired => 'on',
11625 TLSRSACertificateFile => $server_cert,
11626 TLSCACertificateFile => $ca_cert,
11627 TLSVerifyClient => 'optional',
11628 TLSOptions => 'AllowDotLogin',
11629 },
11630 },
11631 };
11632
11633 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
11634 $config);
11635
11636 # Open pipes, for use between the parent and child processes. Specifically,
11637 # the child will indicate when it's done with its test by writing a message
11638 # to the parent.
11639 my ($rfh, $wfh);
11640 unless (pipe($rfh, $wfh)) {
11641 die("Can't open pipe: $!");
11642 }
11643
11644 require Net::FTPSSL;
11645
11646 my $ex;
11647
11648 # Fork child
11649 $self->handle_sigchld();
11650 defined(my $pid = fork()) or die("Can't fork: $!");
11651 if ($pid) {
11652 eval {
11653 # Give the server a chance to start up
11654 sleep(2);
11655
11656 # IO::Socket::SSL options
11657 my $ssl_opts = {
11658 SSL_use_cert => 1,
11659 SSL_cert_file => $client_cert,
11660 SSL_key_file => $client_cert,
11661 SSL_ca_file => $ca_cert,
11662 };
11663
11664 my $client = Net::FTPSSL->new('127.0.0.1',
11665 Croak => 1,
11666 Encryption => 'E',
11667 Port => $port,
11668 SSL_Client_Certificate => $ssl_opts,
11669 );
11670
11671 unless ($client) {
11672 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
11673 }
11674
11675 unless ($client->_user($setup->{user})) {
11676 die("USER error: " . $client->last_message());
11677 }
11678
11679 my $expected = "331 Password required for $setup->{user}";
11680 my $resp = $client->last_message();
11681 $self->assert($expected eq $resp,
11682 test_msg("Expected response '$expected', got '$resp'"));
11683
11684 unless ($client->_passwd($setup->{passwd})) {
11685 die("PASS error: " . $client->last_message());
11686 }
11687
11688 $expected = "230 User $setup->{user} logged in";
11689 $resp = $client->last_message();
11690 $self->assert($expected eq $resp,
11691 test_msg("Expected response '$expected', got '$resp'"));
11692 };
11693 if ($@) {
11694 $ex = $@;
11695 }
11696
11697 $wfh->print("done\n");
11698 $wfh->flush();
11699
11700 } else {
11701 eval { server_wait($setup->{config_file}, $rfh) };
11702 if ($@) {
11703 warn($@);
11704 exit 1;
11705 }
11706
11707 exit 0;
11708 }
11709
11710 # Stop server
11711 server_stop($setup->{pid_file});
11712 $self->assert_child_ok($pid);
11713
11714 test_cleanup($setup->{log_file}, $ex);
11715 }
11716
11717 sub tls_opts_multiple_lines_bug3800 {
11718 my $self = shift;
11719 my $tmpdir = $self->{tmpdir};
11720
11721 my $config_file = "$tmpdir/tls.conf";
11722 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
11723 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
11724
11725 my $log_file = test_get_logfile();
11726
11727 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
11728 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
11729
11730 my $user = 'proftpd';
11731 my $passwd = 'test';
11732 my $group = 'ftpd';
11733 my $home_dir = File::Spec->rel2abs($tmpdir);
11734 my $uid = 500;
11735 my $gid = 500;
11736
11737 # Make sure that, if we're running as root, that the home directory has
11738 # permissions/privs set for the account we create
11739 if ($< == 0) {
11740 unless (chmod(0755, $home_dir)) {
11741 die("Can't set perms on $home_dir to 0755: $!");
11742 }
11743
11744 unless (chown($uid, $gid, $home_dir)) {
11745 die("Can't set owner of $home_dir to $uid/$gid: $!");
11746 }
11747 }
11748
11749 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11750 '/bin/bash');
11751 auth_group_write($auth_group_file, $group, $gid, $user);
11752
11753 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
11754 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11755
11756 my $config = {
11757 PidFile => $pid_file,
11758 ScoreboardFile => $scoreboard_file,
11759 SystemLog => $log_file,
11760
11761 AuthUserFile => $auth_user_file,
11762 AuthGroupFile => $auth_group_file,
11763
11764 IfModules => {
11765 'mod_delay.c' => {
11766 DelayEngine => 'off',
11767 },
11768
11769 'mod_tls.c' => [
11770 "TLSEngine on",
11771 "TLSLog $log_file",
11772 "TLSRequired on",
11773 "TLSRSACertificateFile $cert_file",
11774 "TLSCACertificateFile $ca_file",
11775
11776 "TLSOptions StdEnvVars",
11777 "TLSOptions NoSessionReuseRequired",
11778 ],
11779 },
11780 };
11781
11782 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11783
11784 # Open pipes, for use between the parent and child processes. Specifically,
11785 # the child will indicate when it's done with its test by writing a message
11786 # to the parent.
11787 my ($rfh, $wfh);
11788 unless (pipe($rfh, $wfh)) {
11789 die("Can't open pipe: $!");
11790 }
11791
11792 require Net::FTPSSL;
11793
11794 my $ex;
11795
11796 # Fork child
11797 $self->handle_sigchld();
11798 defined(my $pid = fork()) or die("Can't fork: $!");
11799 if ($pid) {
11800 eval {
11801 # Give the server a chance to start up
11802 sleep(2);
11803
11804 my $client = Net::FTPSSL->new('127.0.0.1',
11805 Encryption => 'E',
11806 Port => $port,
11807 Croak => 1,
11808 );
11809
11810 unless ($client->login($user, $passwd)) {
11811 die("Can't login: " . $client->last_message());
11812 }
11813
11814 # Since we are NOT requiring SSL session reuse for data transfers,
11815 # and this client is not using SSL session resumption, I expect
11816 # this data transfer to succeed.
11817 my $res = $client->list('.');
11818 unless ($res) {
11819 die("LIST failed unexpectedly: " . $client->message());
11820 }
11821 };
11822
11823 if ($@) {
11824 $ex = $@;
11825 }
11826
11827 $wfh->print("done\n");
11828 $wfh->flush();
11829
11830 } else {
11831 eval { server_wait($config_file, $rfh) };
11832 if ($@) {
11833 warn($@);
11834 exit 1;
11835 }
11836
11837 exit 0;
11838 }
11839
11840 # Stop server
11841 server_stop($pid_file);
11842
11843 $self->assert_child_ok($pid);
11844
11845 if ($ex) {
11846 test_append_logfile($log_file, $ex);
11847 unlink($log_file);
11848
11849 die($ex);
11850 }
11851
11852 unlink($log_file);
11853 }
11854
11855 sub tls_config_tlsmasqueradeaddress_bug3862 {
11856 my $self = shift;
11857 my $tmpdir = $self->{tmpdir};
11858
11859 my $config_file = "$tmpdir/tls.conf";
11860 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
11861 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
11862
11863 my $log_file = test_get_logfile();
11864
11865 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
11866 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
11867
11868 my $user = 'proftpd';
11869 my $passwd = 'test';
11870 my $group = 'ftpd';
11871 my $home_dir = File::Spec->rel2abs($tmpdir);
11872 my $uid = 500;
11873 my $gid = 500;
11874
11875 # Make sure that, if we're running as root, that the home directory has
11876 # permissions/privs set for the account we create
11877 if ($< == 0) {
11878 unless (chmod(0755, $home_dir)) {
11879 die("Can't set perms on $home_dir to 0755: $!");
11880 }
11881
11882 unless (chown($uid, $gid, $home_dir)) {
11883 die("Can't set owner of $home_dir to $uid/$gid: $!");
11884 }
11885 }
11886
11887 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
11888 '/bin/bash');
11889 auth_group_write($auth_group_file, $group, $gid, $user);
11890
11891 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
11892 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
11893
11894 my $masq_addr = '1.2.3.4';
11895
11896 my $config = {
11897 PidFile => $pid_file,
11898 ScoreboardFile => $scoreboard_file,
11899 SystemLog => $log_file,
11900
11901 AuthUserFile => $auth_user_file,
11902 AuthGroupFile => $auth_group_file,
11903
11904 IfModules => {
11905 'mod_delay.c' => {
11906 DelayEngine => 'off',
11907 },
11908
11909 'mod_tls.c' => [
11910 "TLSEngine on",
11911 "TLSLog $log_file",
11912 "TLSRequired on",
11913 "TLSRSACertificateFile $cert_file",
11914 "TLSCACertificateFile $ca_file",
11915
11916 "TLSMasqueradeAddress $masq_addr",
11917 ],
11918 },
11919 };
11920
11921 my ($port, $config_user, $config_group) = config_write($config_file, $config);
11922
11923 # Open pipes, for use between the parent and child processes. Specifically,
11924 # the child will indicate when it's done with its test by writing a message
11925 # to the parent.
11926 my ($rfh, $wfh);
11927 unless (pipe($rfh, $wfh)) {
11928 die("Can't open pipe: $!");
11929 }
11930
11931 require Net::FTPSSL;
11932
11933 my $ex;
11934
11935 # Fork child
11936 $self->handle_sigchld();
11937 defined(my $pid = fork()) or die("Can't fork: $!");
11938 if ($pid) {
11939 eval {
11940 # Give the server a chance to start up
11941 sleep(2);
11942
11943 my $client = Net::FTPSSL->new('127.0.0.1',
11944 Encryption => 'E',
11945 Port => $port,
11946 Croak => 1,
11947 );
11948
11949 unless ($client->login($user, $passwd)) {
11950 die("Can't login: " . $client->last_message());
11951 }
11952
11953 unless ($client->quot('PASV')) {
11954 die("Can't use PASV: " . $client->last_message());
11955 }
11956
11957 my $resp = $client->last_message();
11958
11959 if ($resp =~ /^227 Entering Passive Mode \((.*)?,\d+,\d+\)/) {
11960 my $resp_addr = $1;
11961
11962 my $expected = $masq_addr;
11963 $expected =~ s/\./,/g;
11964
11965 $self->assert($expected eq $resp_addr,
11966 test_msg("Expected PASV address '$expected', got '$resp_addr'"));
11967
11968 } else {
11969 die("PASV response '$resp' did not match expected pattern");
11970 }
11971
11972 $client->quit();
11973 };
11974
11975 if ($@) {
11976 $ex = $@;
11977 }
11978
11979 $wfh->print("done\n");
11980 $wfh->flush();
11981
11982 } else {
11983 eval { server_wait($config_file, $rfh) };
11984 if ($@) {
11985 warn($@);
11986 exit 1;
11987 }
11988
11989 exit 0;
11990 }
11991
11992 # Stop server
11993 server_stop($pid_file);
11994
11995 $self->assert_child_ok($pid);
11996
11997 if ($ex) {
11998 test_append_logfile($log_file, $ex);
11999 unlink($log_file);
12000
12001 die($ex);
12002 }
12003
12004 unlink($log_file);
12005 }
12006
12007 sub tls_config_tlsdhparamfile_bug3868 {
12008 my $self = shift;
12009 my $tmpdir = $self->{tmpdir};
12010
12011 my $config_file = "$tmpdir/tls.conf";
12012 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
12013 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
12014
12015 my $log_file = test_get_logfile();
12016
12017 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
12018 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
12019
12020 my $user = 'proftpd';
12021 my $passwd = 'test';
12022 my $group = 'ftpd';
12023 my $home_dir = File::Spec->rel2abs($tmpdir);
12024 my $uid = 500;
12025 my $gid = 500;
12026
12027 # Make sure that, if we're running as root, that the home directory has
12028 # permissions/privs set for the account we create
12029 if ($< == 0) {
12030 unless (chmod(0755, $home_dir)) {
12031 die("Can't set perms on $home_dir to 0755: $!");
12032 }
12033
12034 unless (chown($uid, $gid, $home_dir)) {
12035 die("Can't set owner of $home_dir to $uid/$gid: $!");
12036 }
12037 }
12038
12039 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
12040 '/bin/bash');
12041 auth_group_write($auth_group_file, $group, $gid, $user);
12042
12043 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12044 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12045 my $dhparam_file = File::Spec->rel2abs('t/etc/modules/mod_tls/dh1024.pem');
12046
12047 my $config = {
12048 PidFile => $pid_file,
12049 ScoreboardFile => $scoreboard_file,
12050 SystemLog => $log_file,
12051
12052 AuthUserFile => $auth_user_file,
12053 AuthGroupFile => $auth_group_file,
12054
12055 IfModules => {
12056 'mod_delay.c' => {
12057 DelayEngine => 'off',
12058 },
12059
12060 'mod_tls.c' => {
12061 TLSEngine => 'on',
12062 TLSLog => $log_file,
12063 TLSRequired => 'on',
12064 TLSRSACertificateFile => $cert_file,
12065 TLSCACertificateFile => $ca_file,
12066 TLSDHParamFile => $dhparam_file,
12067 },
12068 },
12069 };
12070
12071 my ($port, $config_user, $config_group) = config_write($config_file, $config);
12072
12073 # Open pipes, for use between the parent and child processes. Specifically,
12074 # the child will indicate when it's done with its test by writing a message
12075 # to the parent.
12076 my ($rfh, $wfh);
12077 unless (pipe($rfh, $wfh)) {
12078 die("Can't open pipe: $!");
12079 }
12080
12081 require Net::FTPSSL;
12082
12083 my $ex;
12084
12085 # Fork child
12086 $self->handle_sigchld();
12087 defined(my $pid = fork()) or die("Can't fork: $!");
12088 if ($pid) {
12089 eval {
12090 # Give the server a chance to start up
12091 sleep(2);
12092
12093 my $ssl_opts = {
12094 # Results in set_tmp_dh_callback() keylength of 1024 BITS
12095 SSL_cipher_list => 'DHE-RSA-AES256-SHA',
12096 SSL_ca_file => $ca_file,
12097 };
12098
12099 my $client = Net::FTPSSL->new('127.0.0.1',
12100 Encryption => 'E',
12101 Port => $port,
12102 SSL_Client_Certificate => $ssl_opts,
12103 );
12104
12105 unless ($client) {
12106 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
12107 }
12108
12109 unless ($client->login($user, $passwd)) {
12110 die("Can't login: " . $client->last_message());
12111 }
12112
12113 $client->quit();
12114 };
12115
12116 if ($@) {
12117 $ex = $@;
12118 }
12119
12120 $wfh->print("done\n");
12121 $wfh->flush();
12122
12123 } else {
12124 eval { server_wait($config_file, $rfh) };
12125 if ($@) {
12126 warn($@);
12127 exit 1;
12128 }
12129
12130 exit 0;
12131 }
12132
12133 # Stop server
12134 server_stop($pid_file);
12135
12136 $self->assert_child_ok($pid);
12137
12138 if ($ex) {
12139 test_append_logfile($log_file, $ex);
12140 unlink($log_file);
12141
12142 die($ex);
12143 }
12144
12145 unlink($log_file);
12146 }
12147
12148 sub tls_config_tlsciphersuite_bad_cipher {
12149 my $self = shift;
12150 my $tmpdir = $self->{tmpdir};
12151 my $setup = test_setup($tmpdir, 'tls');
12152
12153 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12154 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12155
12156 my $config = {
12157 PidFile => $setup->{pid_file},
12158 ScoreboardFile => $setup->{scoreboard_file},
12159 SystemLog => $setup->{log_file},
12160
12161 IfModules => {
12162 'mod_delay.c' => {
12163 DelayEngine => 'off',
12164 },
12165
12166 'mod_tls.c' => {
12167 TLSEngine => 'on',
12168 TLSLog => $setup->{log_file},
12169 TLSRSACertificateFile => $cert_file,
12170 TLSCACertificateFile => $ca_file,
12171 TLSCipherSuite => 'FOOBAR',
12172 },
12173 },
12174 };
12175
12176 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12177 $config);
12178
12179 my $ex;
12180
12181 # This should silently fail.
12182 server_start($setup->{config_file});
12183
12184 # This is where we detect the actual problem.
12185 eval { server_stop($setup->{pid_file}) };
12186 unless ($@) {
12187 $ex = "Server start with bad config unexpectedly";
12188 }
12189
12190 test_cleanup($setup->{log_file}, $ex);
12191 }
12192
12193 sub tls_config_tlscacertfile_bad_format {
12194 my $self = shift;
12195 my $tmpdir = $self->{tmpdir};
12196 my $setup = test_setup($tmpdir, 'tls');
12197
12198 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12199
12200 my $ca_file = File::Spec->rel2abs("$tmpdir/bad-ca.pem");
12201 if (open(my $fh, "> $ca_file")) {
12202 print $fh "foobar\n";
12203 unless (close($fh)) {
12204 die("Can't write $ca_file: $!");
12205 }
12206
12207 } else {
12208 die("Can't open $ca_file: $!");
12209 }
12210
12211 my $config = {
12212 PidFile => $setup->{pid_file},
12213 ScoreboardFile => $setup->{scoreboard_file},
12214 SystemLog => $setup->{log_file},
12215
12216 IfModules => {
12217 'mod_delay.c' => {
12218 DelayEngine => 'off',
12219 },
12220
12221 'mod_tls.c' => {
12222 TLSEngine => 'on',
12223 TLSLog => $setup->{log_file},
12224 TLSRSACertificateFile => $cert_file,
12225 TLSCACertificateFile => $ca_file,
12226 },
12227 },
12228 };
12229
12230 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12231 $config);
12232
12233 my $ex;
12234
12235 # This should silently fail.
12236 server_start($setup->{config_file});
12237
12238 # This is where we detect the actual problem.
12239 eval { server_stop($setup->{pid_file}) };
12240 unless ($@) {
12241 $ex = "Server start with bad config unexpectedly";
12242 }
12243
12244 test_cleanup($setup->{log_file}, $ex);
12245 }
12246
12247 sub tls_config_tlscarevocationfile_bad_format {
12248 my $self = shift;
12249 my $tmpdir = $self->{tmpdir};
12250 my $setup = test_setup($tmpdir, 'tls');
12251
12252 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12253 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12254
12255 my $crl_file = File::Spec->rel2abs("$tmpdir/bad-crl.pem");
12256 if (open(my $fh, "> $crl_file")) {
12257 print $fh "foobar\n";
12258 unless (close($fh)) {
12259 die("Can't write $crl_file: $!");
12260 }
12261
12262 } else {
12263 die("Can't open $crl_file: $!");
12264 }
12265
12266 my $config = {
12267 PidFile => $setup->{pid_file},
12268 ScoreboardFile => $setup->{scoreboard_file},
12269 SystemLog => $setup->{log_file},
12270
12271 IfModules => {
12272 'mod_delay.c' => {
12273 DelayEngine => 'off',
12274 },
12275
12276 'mod_tls.c' => {
12277 TLSEngine => 'on',
12278 TLSLog => $setup->{log_file},
12279 TLSRSACertificateFile => $cert_file,
12280 TLSCACertificateFile => $ca_file,
12281 TLSCARevocationFile => $crl_file,
12282 },
12283 },
12284 };
12285
12286 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12287 $config);
12288
12289 my $ex;
12290
12291 # This should silently fail.
12292 server_start($setup->{config_file});
12293
12294 # This is where we detect the actual problem.
12295 eval { server_stop($setup->{pid_file}) };
12296 unless ($@) {
12297 $ex = "Server start with bad config unexpectedly";
12298 }
12299
12300 test_cleanup($setup->{log_file}, $ex);
12301 }
12302
12303 sub tls_config_tlscertchainfile_bad_format {
12304 my $self = shift;
12305 my $tmpdir = $self->{tmpdir};
12306 my $setup = test_setup($tmpdir, 'tls');
12307
12308 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12309
12310 my $cert_chain_file = File::Spec->rel2abs("$tmpdir/cert-chain.pem");
12311 if (open(my $fh, "> $cert_chain_file")) {
12312 print $fh "FooBar\n";
12313 unless (close($fh)) {
12314 die("Can't write $cert_chain_file: $!");
12315 }
12316
12317 } else {
12318 die("Can't open $cert_chain_file: $!");
12319 }
12320
12321 my $config = {
12322 PidFile => $setup->{pid_file},
12323 ScoreboardFile => $setup->{scoreboard_file},
12324 SystemLog => $setup->{log_file},
12325
12326 IfModules => {
12327 'mod_delay.c' => {
12328 DelayEngine => 'off',
12329 },
12330
12331 'mod_tls.c' => {
12332 TLSEngine => 'on',
12333 TLSLog => $setup->{log_file},
12334 TLSRSACertificateFile => $cert_file,
12335 TLSCertificateChainFile => $cert_chain_file,
12336 },
12337 },
12338 };
12339
12340 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12341 $config);
12342
12343 my $ex;
12344
12345 # This should silently fail.
12346 server_start($setup->{config_file});
12347
12348 # This is where we detect the actual problem.
12349 eval { server_stop($setup->{pid_file}) };
12350 unless ($@) {
12351 $ex = "Server start with bad config unexpectedly";
12352 }
12353
12354 test_cleanup($setup->{log_file}, $ex);
12355 }
12356
12357 sub tls_config_tlsdsacertfile_bad_format {
12358 my $self = shift;
12359 my $tmpdir = $self->{tmpdir};
12360 my $setup = test_setup($tmpdir, 'tls');
12361
12362 my $cert_file = File::Spec->rel2abs("$tmpdir/bad-dsa.pem");
12363 if (open(my $fh, "> $cert_file")) {
12364 print $fh "FooBar\n";
12365 unless (close($fh)) {
12366 die("Can't write $cert_file: $!");
12367 }
12368
12369 } else {
12370 die("Can't open $cert_file: $!");
12371 }
12372
12373 my $config = {
12374 PidFile => $setup->{pid_file},
12375 ScoreboardFile => $setup->{scoreboard_file},
12376 SystemLog => $setup->{log_file},
12377
12378 IfModules => {
12379 'mod_delay.c' => {
12380 DelayEngine => 'off',
12381 },
12382
12383 'mod_tls.c' => {
12384 TLSEngine => 'on',
12385 TLSLog => $setup->{log_file},
12386 TLSDSACertificateFile => $cert_file,
12387 },
12388 },
12389 };
12390
12391 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12392 $config);
12393
12394 my $ex;
12395
12396 # This should silently fail.
12397 server_start($setup->{config_file});
12398
12399 # This is where we detect the actual problem.
12400 eval { server_stop($setup->{pid_file}) };
12401 unless ($@) {
12402 $ex = "Server start with bad config unexpectedly";
12403 }
12404
12405 test_cleanup($setup->{log_file}, $ex);
12406 }
12407
12408 sub tls_config_tlsdsacertfile_not_dsa {
12409 my $self = shift;
12410 my $tmpdir = $self->{tmpdir};
12411 my $setup = test_setup($tmpdir, 'tls');
12412
12413 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12414
12415 my $config = {
12416 PidFile => $setup->{pid_file},
12417 ScoreboardFile => $setup->{scoreboard_file},
12418 SystemLog => $setup->{log_file},
12419
12420 IfModules => {
12421 'mod_delay.c' => {
12422 DelayEngine => 'off',
12423 },
12424
12425 'mod_tls.c' => {
12426 TLSEngine => 'on',
12427 TLSLog => $setup->{log_file},
12428 TLSDSACertificateFile => $cert_file,
12429 },
12430 },
12431 };
12432
12433 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12434 $config);
12435
12436 my $ex;
12437
12438 # This should silently fail.
12439 server_start($setup->{config_file});
12440
12441 # This is where we detect the actual problem.
12442 eval { server_stop($setup->{pid_file}) };
12443 unless ($@) {
12444 $ex = "Server start with bad config unexpectedly";
12445 }
12446
12447 test_cleanup($setup->{log_file}, $ex);
12448 }
12449
12450 sub tls_config_tlsdsacertkeyfile_bad_format {
12451 my $self = shift;
12452 my $tmpdir = $self->{tmpdir};
12453 my $setup = test_setup($tmpdir, 'tls');
12454
12455 my $key_file = File::Spec->rel2abs('t/etc/modules/mod_tls/bad-key.pem');
12456 if (open(my $fh, "> $key_file")) {
12457 print $fh "FooBar\n";
12458 unless (close($fh)) {
12459 die("Can't write $key_file: $!");
12460 }
12461
12462 } else {
12463 die("Can't open $key_file: $!");
12464 }
12465
12466 my $config = {
12467 PidFile => $setup->{pid_file},
12468 ScoreboardFile => $setup->{scoreboard_file},
12469 SystemLog => $setup->{log_file},
12470
12471 IfModules => {
12472 'mod_delay.c' => {
12473 DelayEngine => 'off',
12474 },
12475
12476 'mod_tls.c' => {
12477 TLSEngine => 'on',
12478 TLSLog => $setup->{log_file},
12479 TLSDSACertificateKeyFile => $key_file,
12480 },
12481 },
12482 };
12483
12484 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12485 $config);
12486
12487 my $ex;
12488
12489 # This should silently fail.
12490 server_start($setup->{config_file});
12491
12492 # This is where we detect the actual problem.
12493 eval { server_stop($setup->{pid_file}) };
12494 unless ($@) {
12495 $ex = "Server start with bad config unexpectedly";
12496 }
12497
12498 test_cleanup($setup->{log_file}, $ex);
12499 }
12500
12501 sub tls_config_tlsrsacertkeyfile_passphrase {
12502 my $self = shift;
12503 my $tmpdir = $self->{tmpdir};
12504 my $setup = test_setup($tmpdir, 'tls');
12505
12506 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert-passwd.pem');
12507 my $key_file = $cert_file;
12508 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12509 my $passphrase_provider = File::Spec->rel2abs('t/etc/modules/mod_tls/tls-get-passphrase.pl');
12510
12511 my $config = {
12512 PidFile => $setup->{pid_file},
12513 ScoreboardFile => $setup->{scoreboard_file},
12514 SystemLog => $setup->{log_file},
12515
12516 IfModules => {
12517 'mod_delay.c' => {
12518 DelayEngine => 'off',
12519 },
12520
12521 'mod_tls.c' => {
12522 TLSEngine => 'on',
12523 TLSLog => $setup->{log_file},
12524 TLSRSACertificateFile => $cert_file,
12525 TLSRSACertificateKeyFile => $key_file,
12526 TLSPassPhraseProvider => $passphrase_provider,
12527 },
12528 },
12529 };
12530
12531 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
12532 $config);
12533
12534 my $ex;
12535
12536 # This should silently fail.
12537 server_start($setup->{config_file});
12538
12539 # This is where we detect the actual problem.
12540 eval { server_stop($setup->{pid_file}) };
12541 unless ($@) {
12542 $ex = "Server start with bad config unexpectedly";
12543 }
12544
12545 test_cleanup($setup->{log_file}, $ex);
12546 }
12547
12548 sub tls_session_cache_off_bug3869 {
12549 my $self = shift;
12550 my $tmpdir = $self->{tmpdir};
12551
12552 my $config_file = "$tmpdir/tls.conf";
12553 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
12554 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
12555
12556 my $log_file = test_get_logfile();
12557
12558 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
12559 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
12560
12561 my $user = 'proftpd';
12562 my $passwd = 'test';
12563 my $group = 'ftpd';
12564 my $home_dir = File::Spec->rel2abs($tmpdir);
12565 my $uid = 500;
12566 my $gid = 500;
12567
12568 # Make sure that, if we're running as root, that the home directory has
12569 # permissions/privs set for the account we create
12570 if ($< == 0) {
12571 unless (chmod(0755, $home_dir)) {
12572 die("Can't set perms on $home_dir to 0755: $!");
12573 }
12574
12575 unless (chown($uid, $gid, $home_dir)) {
12576 die("Can't set owner of $home_dir to $uid/$gid: $!");
12577 }
12578 }
12579
12580 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
12581 '/bin/bash');
12582 auth_group_write($auth_group_file, $group, $gid, $user);
12583
12584 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12585 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12586
12587 my $config = {
12588 PidFile => $pid_file,
12589 ScoreboardFile => $scoreboard_file,
12590 SystemLog => $log_file,
12591
12592 AuthUserFile => $auth_user_file,
12593 AuthGroupFile => $auth_group_file,
12594
12595 IfModules => {
12596 'mod_delay.c' => {
12597 DelayEngine => 'off',
12598 },
12599
12600 'mod_tls.c' => {
12601 TLSEngine => 'on',
12602 TLSLog => $log_file,
12603 TLSRequired => 'on',
12604 TLSRSACertificateFile => $cert_file,
12605 TLSCACertificateFile => $ca_file,
12606
12607 # By turning session caching off, the session reuse requirement
12608 # should be related.
12609 TLSSessionCache => 'off',
12610 },
12611 },
12612 };
12613
12614 my ($port, $config_user, $config_group) = config_write($config_file, $config);
12615
12616 # Open pipes, for use between the parent and child processes. Specifically,
12617 # the child will indicate when it's done with its test by writing a message
12618 # to the parent.
12619 my ($rfh, $wfh);
12620 unless (pipe($rfh, $wfh)) {
12621 die("Can't open pipe: $!");
12622 }
12623
12624 require Net::FTPSSL;
12625
12626 my $ex;
12627
12628 # Fork child
12629 $self->handle_sigchld();
12630 defined(my $pid = fork()) or die("Can't fork: $!");
12631 if ($pid) {
12632 eval {
12633 # Give the server a chance to start up
12634 sleep(2);
12635
12636 my $debug = 0;
12637 if ($ENV{TEST_VERBOSE}) {
12638 $debug = 2;
12639 }
12640
12641 my $client = Net::FTPSSL->new('127.0.0.1',
12642 Encryption => 'E',
12643 Port => $port,
12644 Croak => 1,
12645 Debug => $debug,
12646 );
12647
12648 unless ($client->login($user, $passwd)) {
12649 die("Can't login: " . $client->last_message());
12650 }
12651
12652 # Since we are NOT requiring SSL session reuse for data transfers,
12653 # and this client is not using SSL session resumption, I expect
12654 # this data transfer to succeed.
12655 my $res = $client->list('.');
12656 unless ($res) {
12657 die("LIST failed unexpectedly: " . $client->message());
12658 }
12659 };
12660
12661 if ($@) {
12662 $ex = $@;
12663 }
12664
12665 $wfh->print("done\n");
12666 $wfh->flush();
12667
12668 } else {
12669 eval { server_wait($config_file, $rfh) };
12670 if ($@) {
12671 warn($@);
12672 exit 1;
12673 }
12674
12675 exit 0;
12676 }
12677
12678 # Stop server
12679 server_stop($pid_file);
12680
12681 $self->assert_child_ok($pid);
12682
12683 if ($ex) {
12684 test_append_logfile($log_file, $ex);
12685 unlink($log_file);
12686
12687 die($ex);
12688 }
12689
12690 unlink($log_file);
12691 }
12692
12693 sub tls_limit_prot_bug3887 {
12694 my $self = shift;
12695 my $tmpdir = $self->{tmpdir};
12696
12697 my $config_file = "$tmpdir/tls.conf";
12698 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
12699 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
12700
12701 my $log_file = test_get_logfile();
12702
12703 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
12704 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
12705
12706 my $user = 'proftpd';
12707 my $passwd = 'test';
12708 my $group = 'ftpd';
12709 my $home_dir = File::Spec->rel2abs($tmpdir);
12710 my $uid = 500;
12711 my $gid = 500;
12712
12713 # Make sure that, if we're running as root, that the home directory has
12714 # permissions/privs set for the account we create
12715 if ($< == 0) {
12716 unless (chmod(0755, $home_dir)) {
12717 die("Can't set perms on $home_dir to 0755: $!");
12718 }
12719
12720 unless (chown($uid, $gid, $home_dir)) {
12721 die("Can't set owner of $home_dir to $uid/$gid: $!");
12722 }
12723 }
12724
12725 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
12726 '/bin/bash');
12727 auth_group_write($auth_group_file, $group, $gid, $user);
12728
12729 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12730 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
12731 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12732
12733 my $config = {
12734 PidFile => $pid_file,
12735 ScoreboardFile => $scoreboard_file,
12736 SystemLog => $log_file,
12737
12738 AuthUserFile => $auth_user_file,
12739 AuthGroupFile => $auth_group_file,
12740
12741 IfModules => {
12742 'mod_delay.c' => {
12743 DelayEngine => 'off',
12744 },
12745
12746 'mod_tls.c' => {
12747 TLSEngine => 'on',
12748 TLSLog => $log_file,
12749 TLSRequired => 'on',
12750 TLSRSACertificateFile => $server_cert,
12751 TLSCACertificateFile => $ca_cert,
12752 TLSOptions => 'NoSessionReuseRequired',
12753 },
12754 },
12755 };
12756
12757 my ($port, $config_user, $config_group) = config_write($config_file, $config);
12758
12759 if (open(my $fh, ">> $config_file")) {
12760 print $fh <<EOC;
12761 <Directory $home_dir>
12762 <Limit ALL>
12763 DenyAll
12764 </Limit>
12765
12766 <Limit LIST>
12767 AllowAll
12768 </Limit>
12769 </Directory>
12770 EOC
12771 unless (close($fh)) {
12772 die("Can't write $config_file: $!");
12773 }
12774
12775 } else {
12776 die("Can't open $config_file: $!");
12777 }
12778
12779 # Open pipes, for use between the parent and child processes. Specifically,
12780 # the child will indicate when it's done with its test by writing a message
12781 # to the parent.
12782 my ($rfh, $wfh);
12783 unless (pipe($rfh, $wfh)) {
12784 die("Can't open pipe: $!");
12785 }
12786
12787 require Net::FTPSSL;
12788
12789 my $ex;
12790
12791 # Fork child
12792 $self->handle_sigchld();
12793 defined(my $pid = fork()) or die("Can't fork: $!");
12794 if ($pid) {
12795 eval {
12796 # Give the server a chance to start up
12797 sleep(2);
12798
12799 my $client;
12800
12801 # IO::Socket::SSL options
12802 my $ssl_opts = {
12803 SSL_use_cert => 1,
12804 SSL_cert_file => $client_cert,
12805 SSL_key_file => $client_cert,
12806 SSL_ca_file => $ca_cert,
12807 };
12808
12809 my $debug = 0;
12810 if ($ENV{TEST_VERBOSE}) {
12811 $debug = 2;
12812 }
12813
12814 $client = Net::FTPSSL->new('127.0.0.1',
12815 Croak => 1,
12816 DataProtLevel => 'P',
12817 Encryption => 'E',
12818 Port => $port,
12819 Debug => $debug,
12820 SSL_Client_Certificate => $ssl_opts,
12821 );
12822
12823 unless ($client->login($user, $passwd)) {
12824 die("Can't login: " . $client->last_message());
12825 }
12826
12827 my $res;
12828 if ($Net::FTPSSL::VERSION == 0.21) {
12829 # Note: The duplicated arguments here are to work around a bug in
12830 # Net::FTPSSL, version 0.21, in the quot() function.
12831 $res = $client->quot('PROT', 'P', 'P');
12832
12833 } else {
12834 $res = $client->quot('PROT', 'P');
12835 }
12836
12837 unless ($res) {
12838 die("PROT failed unexpectedly: " . $client->last_message());
12839 }
12840
12841 $res = $client->list();
12842 unless ($res) {
12843 die("LIST failed unexpectedly: " . $client->last_message());
12844 }
12845
12846 my $resp_msg = $client->last_message();
12847 $client->quit();
12848
12849 my $expected = '226 Transfer complete';
12850 $self->assert($expected eq $resp_msg,
12851 test_msg("Expected '$expected', got '$resp_msg'"));
12852 };
12853
12854 if ($@) {
12855 $ex = $@;
12856 }
12857
12858 $wfh->print("done\n");
12859 $wfh->flush();
12860
12861 } else {
12862 eval { server_wait($config_file, $rfh) };
12863 if ($@) {
12864 warn($@);
12865 exit 1;
12866 }
12867
12868 exit 0;
12869 }
12870
12871 # Stop server
12872 server_stop($pid_file);
12873
12874 $self->assert_child_ok($pid);
12875
12876 if ($ex) {
12877 test_append_logfile($log_file, $ex);
12878 unlink($log_file);
12879
12880 die($ex);
12881 }
12882
12883 unlink($log_file);
12884 }
12885
12886 sub tls_config_tlsusername_bug3899 {
12887 my $self = shift;
12888 my $tmpdir = $self->{tmpdir};
12889
12890 my $config_file = "$tmpdir/tls.conf";
12891 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
12892 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
12893
12894 my $log_file = test_get_logfile();
12895
12896 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
12897 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
12898
12899 # Note: This name matches the CN of the client cert used, for purposes
12900 # of testing the TLSUserName directive.
12901 my $user = 'client-cert';
12902 my $passwd = 'test';
12903 my $group = 'ftpd';
12904 my $home_dir = File::Spec->rel2abs($tmpdir);
12905 my $uid = 500;
12906 my $gid = 500;
12907
12908 # Make sure that, if we're running as root, that the home directory has
12909 # permissions/privs set for the account we create
12910 if ($< == 0) {
12911 unless (chmod(0755, $home_dir)) {
12912 die("Can't set perms on $home_dir to 0755: $!");
12913 }
12914
12915 unless (chown($uid, $gid, $home_dir)) {
12916 die("Can't set owner of $home_dir to $uid/$gid: $!");
12917 }
12918 }
12919
12920 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
12921 '/bin/bash');
12922 auth_group_write($auth_group_file, $group, $gid, $user);
12923
12924 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
12925 my $client_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/client-cert.pem');
12926 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
12927
12928 my $config = {
12929 PidFile => $pid_file,
12930 ScoreboardFile => $scoreboard_file,
12931 SystemLog => $log_file,
12932
12933 AuthUserFile => $auth_user_file,
12934 AuthGroupFile => $auth_group_file,
12935
12936 IfModules => {
12937 'mod_delay.c' => {
12938 DelayEngine => 'off',
12939 },
12940
12941 'mod_tls.c' => {
12942 TLSEngine => 'on',
12943 TLSLog => $log_file,
12944 TLSRequired => 'on',
12945 TLSRSACertificateFile => $server_cert,
12946 TLSCACertificateFile => $ca_cert,
12947 TLSVerifyClient => 'optional',
12948
12949 TLSUserName => 'CommonName',
12950 },
12951 },
12952 };
12953
12954 my ($port, $config_user, $config_group) = config_write($config_file, $config);
12955
12956 # Open pipes, for use between the parent and child processes. Specifically,
12957 # the child will indicate when it's done with its test by writing a message
12958 # to the parent.
12959 my ($rfh, $wfh);
12960 unless (pipe($rfh, $wfh)) {
12961 die("Can't open pipe: $!");
12962 }
12963
12964 require Net::FTPSSL;
12965
12966 my $ex;
12967
12968 # Fork child
12969 $self->handle_sigchld();
12970 defined(my $pid = fork()) or die("Can't fork: $!");
12971 if ($pid) {
12972 eval {
12973 # Give the server a chance to start up
12974 sleep(2);
12975
12976 # IO::Socket::SSL options
12977 my $ssl_opts = {
12978 SSL_use_cert => 1,
12979 SSL_cert_file => $client_cert,
12980 SSL_key_file => $client_cert,
12981 SSL_ca_file => $ca_cert,
12982 };
12983
12984 my $client = Net::FTPSSL->new('127.0.0.1',
12985 Croak => 1,
12986 Encryption => 'E',
12987 Port => $port,
12988 SSL_Client_Certificate => $ssl_opts,
12989 );
12990
12991 unless ($client) {
12992 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
12993 }
12994
12995 unless ($client->_user($user)) {
12996 die("USER error: " . $client->last_message());
12997 }
12998
12999 my $expected = "232 User $user logged in";
13000 my $resp = $client->last_message();
13001 $self->assert($expected eq $resp,
13002 test_msg("Expected response '$expected', got '$resp'"));
13003 };
13004
13005 if ($@) {
13006 $ex = $@;
13007 }
13008
13009 $wfh->print("done\n");
13010 $wfh->flush();
13011
13012 } else {
13013 eval { server_wait($config_file, $rfh) };
13014 if ($@) {
13015 warn($@);
13016 exit 1;
13017 }
13018
13019 exit 0;
13020 }
13021
13022 # Stop server
13023 server_stop($pid_file);
13024
13025 $self->assert_child_ok($pid);
13026
13027 if ($ex) {
13028 test_append_logfile($log_file, $ex);
13029 unlink($log_file);
13030
13031 die($ex);
13032 }
13033
13034 unlink($log_file);
13035 }
13036
13037 sub tls_config_tlsrenegotiate_ctrl {
13038 my $self = shift;
13039 my $tmpdir = $self->{tmpdir};
13040 my $setup = test_setup($tmpdir, 'tls');
13041
13042 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
13043 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
13044
13045 # Number of seconds before renegotiating ctrl session
13046 my $ctrl_reneg = 3;
13047
13048 # Number of KB before renegotiating data session
13049 my $data_reneg = 1;
13050
13051 my $config = {
13052 PidFile => $setup->{pid_file},
13053 ScoreboardFile => $setup->{scoreboard_file},
13054 SystemLog => $setup->{log_file},
13055 TraceLog => $setup->{log_file},
13056 Trace => 'timer:20 tls:20',
13057
13058 AuthUserFile => $setup->{auth_user_file},
13059 AuthGroupFile => $setup->{auth_group_file},
13060
13061 IfModules => {
13062 'mod_delay.c' => {
13063 DelayEngine => 'off',
13064 },
13065
13066 'mod_tls.c' => {
13067 TLSEngine => 'on',
13068 TLSLog => $setup->{log_file},
13069 TLSOptions => 'AllowClientRenegotiations EnableDiags',
13070 TLSRequired => 'on',
13071 TLSRSACertificateFile => $server_cert,
13072 TLSCACertificateFile => $ca_cert,
13073
13074 TLSRenegotiate => "ctrl $ctrl_reneg data $data_reneg",
13075 },
13076 },
13077 };
13078
13079 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13080 $config);
13081
13082 # Open pipes, for use between the parent and child processes. Specifically,
13083 # the child will indicate when it's done with its test by writing a message
13084 # to the parent.
13085 my ($rfh, $wfh);
13086 unless (pipe($rfh, $wfh)) {
13087 die("Can't open pipe: $!");
13088 }
13089
13090 require Net::FTPSSL;
13091
13092 my $ex;
13093
13094 # Fork child
13095 $self->handle_sigchld();
13096 defined(my $pid = fork()) or die("Can't fork: $!");
13097 if ($pid) {
13098 eval {
13099 # Give the server a chance to start up
13100 sleep(2);
13101
13102 # Make sure we do not use TLSv1.3 here.
13103 my $ssl_opts = {
13104 SSL_version => 'TLSv1',
13105 };
13106
13107 my $client = Net::FTPSSL->new('127.0.0.1',
13108 Croak => 1,
13109 Encryption => 'E',
13110 Port => $port,
13111 SSL_Client_Certificate => $ssl_opts,
13112 );
13113
13114 unless ($client) {
13115 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
13116 }
13117
13118 unless ($client->login($setup->{user}, $setup->{passwd})) {
13119 die("Can't login: ", $client->last_message());
13120 }
13121
13122 # Sleep for longer than the ctrl renegotiation time, then use NOOP.
13123 if ($ENV{TEST_VERBOSE}) {
13124 print STDERR "# Sleeping for ", $ctrl_reneg, " secs\n";
13125 }
13126 sleep($ctrl_reneg + 1);
13127
13128 $client->quot('NOOP');
13129 $client->quit();
13130 };
13131 if ($@) {
13132 $ex = $@;
13133 }
13134
13135 $wfh->print("done\n");
13136 $wfh->flush();
13137
13138 } else {
13139 eval { server_wait($setup->{config_file}, $rfh) };
13140 if ($@) {
13141 warn($@);
13142 exit 1;
13143 }
13144
13145 exit 0;
13146 }
13147
13148 # Stop server
13149 server_stop($setup->{pid_file});
13150 $self->assert_child_ok($pid);
13151
13152 eval {
13153 if (open(my $fh, "< $setup->{log_file}")) {
13154 my $ok = 0;
13155
13156 while (my $line = <$fh>) {
13157 chomp($line);
13158
13159 if ($line =~ /SSL\/TLS sessions renegotiated: (\d+)/) {
13160 my $count = $1;
13161
13162 if ($ENV{TEST_VERBOSE}) {
13163 print STDERR "# $line\n";
13164 }
13165
13166 if ($count == 3) {
13167 $ok = 1;
13168 last;
13169 }
13170 }
13171 }
13172 close($fh);
13173
13174 $self->assert($ok,
13175 test_msg("Did not see expected number of session renegotiations"));
13176
13177 } else {
13178 die("Can't read $setup->{log_file}: $!");
13179 }
13180 };
13181 if ($@) {
13182 $ex = $@;
13183 }
13184
13185 test_cleanup($setup->{log_file}, $ex);
13186 }
13187
13188 sub tls_config_tlsrenegotiate_download {
13189 my $self = shift;
13190 my $tmpdir = $self->{tmpdir};
13191 my $setup = test_setup($tmpdir, 'tls');
13192
13193 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
13194 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
13195
13196 # Number of KB before renegotiating data session
13197 my $data_reneg = 32;
13198
13199 # Make a file large enough to trigger the renegotiation
13200 my $download_file = File::Spec->rel2abs("$tmpdir/download.dat");
13201 if (open(my $fh, "> $download_file")) {
13202 print $fh "AbCdEfGhIjKlMnOp" x 32768;
13203
13204 unless (close($fh)) {
13205 die("Can't write $download_file: $!");
13206 }
13207
13208 } else {
13209 die("Can't open $download_file: $!");
13210 }
13211
13212 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
13213
13214 # Number of seconds to perform the renegotiation
13215 my $reneg_timeout = 2;
13216
13217 my $config = {
13218 PidFile => $setup->{pid_file},
13219 ScoreboardFile => $setup->{scoreboard_file},
13220 SystemLog => $setup->{log_file},
13221 TraceLog => $setup->{log_file},
13222 Trace => 'timer:20 tls:20',
13223
13224 AuthUserFile => $setup->{auth_user_file},
13225 AuthGroupFile => $setup->{auth_group_file},
13226
13227 IfModules => {
13228 'mod_delay.c' => {
13229 DelayEngine => 'off',
13230 },
13231
13232 'mod_tls.c' => {
13233 TLSEngine => 'on',
13234 TLSLog => $setup->{log_file},
13235 TLSOptions => 'AllowClientRenegotiations EnableDiags NoSessionReuseRequired',
13236 TLSRequired => 'on',
13237 TLSRSACertificateFile => $server_cert,
13238 TLSCACertificateFile => $ca_cert,
13239
13240 TLSRenegotiate => "data $data_reneg timeout $reneg_timeout",
13241 },
13242 },
13243 };
13244
13245 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13246 $config);
13247
13248 # Open pipes, for use between the parent and child processes. Specifically,
13249 # the child will indicate when it's done with its test by writing a message
13250 # to the parent.
13251 my ($rfh, $wfh);
13252 unless (pipe($rfh, $wfh)) {
13253 die("Can't open pipe: $!");
13254 }
13255
13256 require Net::FTPSSL;
13257
13258 my $ex;
13259
13260 # Fork child
13261 $self->handle_sigchld();
13262 defined(my $pid = fork()) or die("Can't fork: $!");
13263 if ($pid) {
13264 eval {
13265 # Give the server a chance to start up
13266 sleep(2);
13267
13268 # Make sure we do not use TLSv1.3 here.
13269 my $ssl_opts = {
13270 SSL_version => 'TLSv1',
13271 };
13272
13273 my $client = Net::FTPSSL->new('127.0.0.1',
13274 Croak => 1,
13275 Encryption => 'E',
13276 Port => $port,
13277 SSL_Client_Certificate => $ssl_opts,
13278 );
13279
13280 unless ($client) {
13281 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
13282 }
13283
13284 unless ($client->login($setup->{user}, $setup->{passwd})) {
13285 die("Can't login: " . $client->last_message());
13286 }
13287
13288 unless ($client->binary()) {
13289 die("Can't set binary transfer mode: " . $client->last_message());
13290 }
13291
13292 unless ($client->get($download_file, $test_file)) {
13293 die("Can't download '$download_file' to '$test_file': " .
13294 $client->last_message());
13295 }
13296
13297 if ($ENV{TEST_VERBOSE}) {
13298 print STDERR "# Sleeping for ", $reneg_timeout + 1, " secs\n";
13299 }
13300
13301 # Allow the renegotiation timeout to fire
13302 sleep($reneg_timeout + 1);
13303
13304 $client->quot('NOOP');
13305 $client->quit();
13306 };
13307 if ($@) {
13308 $ex = $@;
13309 }
13310
13311 $wfh->print("done\n");
13312 $wfh->flush();
13313
13314 } else {
13315 eval { server_wait($setup->{config_file}, $rfh) };
13316 if ($@) {
13317 warn($@);
13318 exit 1;
13319 }
13320
13321 exit 0;
13322 }
13323
13324 # Stop server
13325 server_stop($setup->{pid_file});
13326 $self->assert_child_ok($pid);
13327
13328 eval {
13329 if (open(my $fh, "< $setup->{log_file}")) {
13330 my $ok = 0;
13331
13332 while (my $line = <$fh>) {
13333 chomp($line);
13334
13335 if ($line =~ /SSL\/TLS sessions renegotiated: (\d+)/) {
13336 my $count = $1;
13337
13338 if ($ENV{TEST_VERBOSE}) {
13339 print STDERR "# $line\n";
13340 }
13341
13342 if ($count >= 3) {
13343 $ok = 1;
13344 last;
13345 }
13346 }
13347 }
13348 close($fh);
13349
13350 $self->assert($ok,
13351 test_msg("Did not see expected number of session renegotiations"));
13352
13353 } else {
13354 die("Can't read $setup->{log_file}: $!");
13355 }
13356 };
13357 if ($@) {
13358 $ex = $@;
13359 }
13360
13361 test_cleanup($setup->{log_file}, $ex);
13362 }
13363
13364 sub tls_config_tlsrenegotiate_upload {
13365 my $self = shift;
13366 my $tmpdir = $self->{tmpdir};
13367 my $setup = test_setup($tmpdir, 'tls');
13368
13369 my $server_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
13370 my $ca_cert = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
13371
13372 # Number of KB before renegotiating data session
13373 my $data_reneg = 32;
13374
13375 # Make a file large enough to trigger the renegotiation
13376 my $test_file = File::Spec->rel2abs("$tmpdir/input.dat");
13377 if (open(my $fh, "> $test_file")) {
13378 print $fh "AbCdEfGhIjKlMnOp" x 8192;
13379
13380 unless (close($fh)) {
13381 die("Can't write $test_file: $!");
13382 }
13383
13384 } else {
13385 die("Can't open $test_file: $!");
13386 }
13387
13388 # Number of seconds to perform the renegotiation
13389 my $reneg_timeout = 2;
13390
13391 my $config = {
13392 PidFile => $setup->{pid_file},
13393 ScoreboardFile => $setup->{scoreboard_file},
13394 SystemLog => $setup->{log_file},
13395 TraceLog => $setup->{log_file},
13396 Trace => 'timer:20 tls:20',
13397
13398 AuthUserFile => $setup->{auth_user_file},
13399 AuthGroupFile => $setup->{auth_group_file},
13400
13401 IfModules => {
13402 'mod_delay.c' => {
13403 DelayEngine => 'off',
13404 },
13405
13406 'mod_tls.c' => {
13407 TLSEngine => 'on',
13408 TLSLog => $setup->{log_file},
13409 TLSOptions => 'AllowClientRenegotiations EnableDiags NoSessionReuseRequired',
13410 TLSRequired => 'on',
13411 TLSRSACertificateFile => $server_cert,
13412 TLSCACertificateFile => $ca_cert,
13413
13414 TLSRenegotiate => "data $data_reneg timeout $reneg_timeout",
13415 },
13416 },
13417 };
13418
13419 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
13420 $config);
13421
13422 # Open pipes, for use between the parent and child processes. Specifically,
13423 # the child will indicate when it's done with its test by writing a message
13424 # to the parent.
13425 my ($rfh, $wfh);
13426 unless (pipe($rfh, $wfh)) {
13427 die("Can't open pipe: $!");
13428 }
13429
13430 require Net::FTPSSL;
13431
13432 my $ex;
13433
13434 # Fork child
13435 $self->handle_sigchld();
13436 defined(my $pid = fork()) or die("Can't fork: $!");
13437 if ($pid) {
13438 eval {
13439 # Give the server a chance to start up
13440 sleep(2);
13441
13442 # Make sure we do not use TLSv1.3 here.
13443 my $ssl_opts = {
13444 SSL_version => 'TLSv1',
13445 };
13446
13447 my $client = Net::FTPSSL->new('127.0.0.1',
13448 Croak => 1,
13449 Encryption => 'E',
13450 Port => $port,
13451 SSL_Client_Certificate => $ssl_opts,
13452 );
13453
13454 unless ($client) {
13455 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
13456 }
13457
13458 unless ($client->login($setup->{user}, $setup->{passwd})) {
13459 die("Can't login: " . $client->last_message());
13460 }
13461
13462 unless ($client->put($test_file, 'test.dat')) {
13463 die("Can't upload '$test_file' to 'test.dat': " .
13464 $client->last_message());
13465 }
13466
13467 if ($ENV{TEST_VERBOSE}) {
13468 print STDERR "# Sleeping for ", $reneg_timeout + 1, " secs\n";
13469 }
13470
13471 # Allow the renegotiation timeout to fire
13472 sleep($reneg_timeout + 2);
13473
13474 $client->quot('NOOP');
13475 $client->quit();
13476 };
13477 if ($@) {
13478 $ex = $@;
13479 }
13480
13481 $wfh->print("done\n");
13482 $wfh->flush();
13483
13484 } else {
13485 eval { server_wait($setup->{config_file}, $rfh) };
13486 if ($@) {
13487 warn($@);
13488 exit 1;
13489 }
13490
13491 exit 0;
13492 }
13493
13494 # Stop server
13495 server_stop($setup->{pid_file});
13496 $self->assert_child_ok($pid);
13497
13498 eval {
13499 if (open(my $fh, "< $setup->{log_file}")) {
13500 my $ok = 0;
13501
13502 while (my $line = <$fh>) {
13503 chomp($line);
13504
13505 if ($line =~ /SSL\/TLS sessions renegotiated: (\d+)/) {
13506 my $count = $1;
13507
13508 if ($ENV{TEST_VERBOSE}) {
13509 print STDERR "# $line\n";
13510 }
13511
13512 if ($count >= 3) {
13513 $ok = 1;
13514 last;
13515 }
13516 }
13517 }
13518 close($fh);
13519
13520 $self->assert($ok,
13521 test_msg("Did not see expected number of session renegotiations"));
13522
13523 } else {
13524 die("Can't read $setup->{log_file}: $!");
13525 }
13526 };
13527 if ($@) {
13528 $ex = $@;
13529 }
13530
13531 test_cleanup($setup->{log_file}, $ex);
13532 }
13533
13534 sub tls_sscn_no_args_bug3955 {
13535 my $self = shift;
13536 my $tmpdir = $self->{tmpdir};
13537
13538 my $config_file = "$tmpdir/tls.conf";
13539 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
13540 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
13541
13542 my $log_file = test_get_logfile();
13543
13544 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
13545 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
13546
13547 my $user = 'proftpd';
13548 my $passwd = 'test';
13549 my $group = 'ftpd';
13550 my $home_dir = File::Spec->rel2abs($tmpdir);
13551 my $uid = 500;
13552 my $gid = 500;
13553
13554 # Make sure that, if we're running as root, that the home directory has
13555 # permissions/privs set for the account we create
13556 if ($< == 0) {
13557 unless (chmod(0755, $home_dir)) {
13558 die("Can't set perms on $home_dir to 0755: $!");
13559 }
13560
13561 unless (chown($uid, $gid, $home_dir)) {
13562 die("Can't set owner of $home_dir to $uid/$gid: $!");
13563 }
13564 }
13565
13566 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
13567 '/bin/bash');
13568 auth_group_write($auth_group_file, $group, $gid, $user);
13569
13570 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
13571 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
13572
13573 my $config = {
13574 PidFile => $pid_file,
13575 ScoreboardFile => $scoreboard_file,
13576 SystemLog => $log_file,
13577
13578 AuthUserFile => $auth_user_file,
13579 AuthGroupFile => $auth_group_file,
13580
13581 IfModules => {
13582 'mod_delay.c' => {
13583 DelayEngine => 'off',
13584 },
13585
13586 'mod_tls.c' => {
13587 TLSEngine => 'on',
13588 TLSLog => $log_file,
13589 TLSRequired => 'on',
13590 TLSRSACertificateFile => $cert_file,
13591 TLSCACertificateFile => $ca_file,
13592 },
13593 },
13594 };
13595
13596 my ($port, $config_user, $config_group) = config_write($config_file, $config);
13597
13598 # Open pipes, for use between the parent and child processes. Specifically,
13599 # the child will indicate when it's done with its test by writing a message
13600 # to the parent.
13601 my ($rfh, $wfh);
13602 unless (pipe($rfh, $wfh)) {
13603 die("Can't open pipe: $!");
13604 }
13605
13606 require Net::FTPSSL;
13607
13608 my $ex;
13609
13610 # Fork child
13611 $self->handle_sigchld();
13612 defined(my $pid = fork()) or die("Can't fork: $!");
13613 if ($pid) {
13614 eval {
13615 # Give the server a chance to start up
13616 sleep(2);
13617
13618 my $client = Net::FTPSSL->new('127.0.0.1',
13619 Encryption => 'E',
13620 Port => $port,
13621 );
13622
13623 unless ($client) {
13624 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
13625 }
13626
13627 unless ($client->login($user, $passwd)) {
13628 die("Can't login: " . $client->last_message());
13629 }
13630
13631 my $resp_code = $client->quot('SSCN');
13632 if ($resp_code != 2) {
13633 die("SSCN failed: " . $client->last_message());
13634 }
13635
13636 my $resp_msg = $client->last_message();
13637
13638 $client->quit();
13639
13640 my $expected = '200 SSCN:SERVER METHOD';
13641 $self->assert($expected eq $resp_msg,
13642 test_msg("Expected response message '$expected', got '$resp_msg'"));
13643 };
13644
13645 if ($@) {
13646 $ex = $@;
13647 }
13648
13649 $wfh->print("done\n");
13650 $wfh->flush();
13651
13652 } else {
13653 eval { server_wait($config_file, $rfh) };
13654 if ($@) {
13655 warn($@);
13656 exit 1;
13657 }
13658
13659 exit 0;
13660 }
13661
13662 # Stop server
13663 server_stop($pid_file);
13664
13665 $self->assert_child_ok($pid);
13666
13667 if ($ex) {
13668 test_append_logfile($log_file, $ex);
13669 unlink($log_file);
13670
13671 die($ex);
13672 }
13673
13674 unlink($log_file);
13675 }
13676
13677 sub tls_sscn_too_many_args_bug3955 {
13678 my $self = shift;
13679 my $tmpdir = $self->{tmpdir};
13680
13681 my $config_file = "$tmpdir/tls.conf";
13682 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
13683 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
13684
13685 my $log_file = test_get_logfile();
13686
13687 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
13688 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
13689
13690 my $user = 'proftpd';
13691 my $passwd = 'test';
13692 my $group = 'ftpd';
13693 my $home_dir = File::Spec->rel2abs($tmpdir);
13694 my $uid = 500;
13695 my $gid = 500;
13696
13697 # Make sure that, if we're running as root, that the home directory has
13698 # permissions/privs set for the account we create
13699 if ($< == 0) {
13700 unless (chmod(0755, $home_dir)) {
13701 die("Can't set perms on $home_dir to 0755: $!");
13702 }
13703
13704 unless (chown($uid, $gid, $home_dir)) {
13705 die("Can't set owner of $home_dir to $uid/$gid: $!");
13706 }
13707 }
13708
13709 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
13710 '/bin/bash');
13711 auth_group_write($auth_group_file, $group, $gid, $user);
13712
13713 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
13714 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
13715
13716 my $config = {
13717 PidFile => $pid_file,
13718 ScoreboardFile => $scoreboard_file,
13719 SystemLog => $log_file,
13720
13721 AuthUserFile => $auth_user_file,
13722 AuthGroupFile => $auth_group_file,
13723
13724 IfModules => {
13725 'mod_delay.c' => {
13726 DelayEngine => 'off',
13727 },
13728
13729 'mod_tls.c' => {
13730 TLSEngine => 'on',
13731 TLSLog => $log_file,
13732 TLSRequired => 'on',
13733 TLSRSACertificateFile => $cert_file,
13734 TLSCACertificateFile => $ca_file,
13735 },
13736 },
13737 };
13738
13739 my ($port, $config_user, $config_group) = config_write($config_file, $config);
13740
13741 # Open pipes, for use between the parent and child processes. Specifically,
13742 # the child will indicate when it's done with its test by writing a message
13743 # to the parent.
13744 my ($rfh, $wfh);
13745 unless (pipe($rfh, $wfh)) {
13746 die("Can't open pipe: $!");
13747 }
13748
13749 require Net::FTPSSL;
13750
13751 my $ex;
13752
13753 # Fork child
13754 $self->handle_sigchld();
13755 defined(my $pid = fork()) or die("Can't fork: $!");
13756 if ($pid) {
13757 eval {
13758 # Give the server a chance to start up
13759 sleep(2);
13760
13761 my $client = Net::FTPSSL->new('127.0.0.1',
13762 Encryption => 'E',
13763 Port => $port,
13764 );
13765
13766 unless ($client) {
13767 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
13768 }
13769
13770 unless ($client->login($user, $passwd)) {
13771 die("Can't login: " . $client->last_message());
13772 }
13773
13774 my $resp_code = $client->quot('SSCN', 'foo', 'bar', 'baz');
13775 if ($resp_code == 2) {
13776 die("SSCN succeeded unexpectedly");
13777 }
13778
13779 my $resp_msg = $client->last_message();
13780
13781 $client->quit();
13782
13783 my $expected = '504 SSCN: Invalid argument';
13784 $self->assert($expected eq $resp_msg,
13785 test_msg("Expected response message '$expected', got '$resp_msg'"));
13786 };
13787
13788 if ($@) {
13789 $ex = $@;
13790 }
13791
13792 $wfh->print("done\n");
13793 $wfh->flush();
13794
13795 } else {
13796 eval { server_wait($config_file, $rfh) };
13797 if ($@) {
13798 warn($@);
13799 exit 1;
13800 }
13801
13802 exit 0;
13803 }
13804
13805 # Stop server
13806 server_stop($pid_file);
13807
13808 $self->assert_child_ok($pid);
13809
13810 if ($ex) {
13811 test_append_logfile($log_file, $ex);
13812 unlink($log_file);
13813
13814 die($ex);
13815 }
13816
13817 unlink($log_file);
13818 }
13819
13820 sub tls_sscn_bad_arg_bug3955 {
13821 my $self = shift;
13822 my $tmpdir = $self->{tmpdir};
13823
13824 my $config_file = "$tmpdir/tls.conf";
13825 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
13826 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
13827
13828 my $log_file = test_get_logfile();
13829
13830 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
13831 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
13832
13833 my $user = 'proftpd';
13834 my $passwd = 'test';
13835 my $group = 'ftpd';
13836 my $home_dir = File::Spec->rel2abs($tmpdir);
13837 my $uid = 500;
13838 my $gid = 500;
13839
13840 # Make sure that, if we're running as root, that the home directory has
13841 # permissions/privs set for the account we create
13842 if ($< == 0) {
13843 unless (chmod(0755, $home_dir)) {
13844 die("Can't set perms on $home_dir to 0755: $!");
13845 }
13846
13847 unless (chown($uid, $gid, $home_dir)) {
13848 die("Can't set owner of $home_dir to $uid/$gid: $!");
13849 }
13850 }
13851
13852 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
13853 '/bin/bash');
13854 auth_group_write($auth_group_file, $group, $gid, $user);
13855
13856 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
13857 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
13858
13859 my $config = {
13860 PidFile => $pid_file,
13861 ScoreboardFile => $scoreboard_file,
13862 SystemLog => $log_file,
13863
13864 AuthUserFile => $auth_user_file,
13865 AuthGroupFile => $auth_group_file,
13866
13867 IfModules => {
13868 'mod_delay.c' => {
13869 DelayEngine => 'off',
13870 },
13871
13872 'mod_tls.c' => {
13873 TLSEngine => 'on',
13874 TLSLog => $log_file,
13875 TLSRequired => 'on',
13876 TLSRSACertificateFile => $cert_file,
13877 TLSCACertificateFile => $ca_file,
13878 },
13879 },
13880 };
13881
13882 my ($port, $config_user, $config_group) = config_write($config_file, $config);
13883
13884 # Open pipes, for use between the parent and child processes. Specifically,
13885 # the child will indicate when it's done with its test by writing a message
13886 # to the parent.
13887 my ($rfh, $wfh);
13888 unless (pipe($rfh, $wfh)) {
13889 die("Can't open pipe: $!");
13890 }
13891
13892 require Net::FTPSSL;
13893
13894 my $ex;
13895
13896 # Fork child
13897 $self->handle_sigchld();
13898 defined(my $pid = fork()) or die("Can't fork: $!");
13899 if ($pid) {
13900 eval {
13901 # Give the server a chance to start up
13902 sleep(2);
13903
13904 my $client = Net::FTPSSL->new('127.0.0.1',
13905 Encryption => 'E',
13906 Port => $port,
13907 );
13908
13909 unless ($client) {
13910 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
13911 }
13912
13913 unless ($client->login($user, $passwd)) {
13914 die("Can't login: " . $client->last_message());
13915 }
13916
13917 my $resp_code;
13918 if ($Net::FTPSSL::VERSION == 0.21) {
13919 # Note: The duplicated arguments here are to work around a bug in
13920 # Net::FTPSSL, version 0.21, in the quot() function.
13921 $resp_code = $client->quot('SSCN', 'true', 'true');
13922
13923 } else {
13924 $resp_code = $client->quot('SSCN', 'true');
13925 }
13926
13927 if ($resp_code == 2) {
13928 die("SSCN succeeded unexpectedly");
13929 }
13930
13931 my $resp_msg = $client->last_message();
13932
13933 $client->quit();
13934
13935 my $expected = '501 SSCN: Invalid argument';
13936 $self->assert($expected eq $resp_msg,
13937 test_msg("Expected response message '$expected', got '$resp_msg'"));
13938 };
13939
13940 if ($@) {
13941 $ex = $@;
13942 }
13943
13944 $wfh->print("done\n");
13945 $wfh->flush();
13946
13947 } else {
13948 eval { server_wait($config_file, $rfh) };
13949 if ($@) {
13950 warn($@);
13951 exit 1;
13952 }
13953
13954 exit 0;
13955 }
13956
13957 # Stop server
13958 server_stop($pid_file);
13959
13960 $self->assert_child_ok($pid);
13961
13962 if ($ex) {
13963 test_append_logfile($log_file, $ex);
13964 unlink($log_file);
13965
13966 die($ex);
13967 }
13968
13969 unlink($log_file);
13970 }
13971
13972 sub tls_sscn_toggle_bug3955 {
13973 my $self = shift;
13974 my $tmpdir = $self->{tmpdir};
13975
13976 my $config_file = "$tmpdir/tls.conf";
13977 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
13978 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
13979
13980 my $log_file = test_get_logfile();
13981
13982 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
13983 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
13984
13985 my $user = 'proftpd';
13986 my $passwd = 'test';
13987 my $group = 'ftpd';
13988 my $home_dir = File::Spec->rel2abs($tmpdir);
13989 my $uid = 500;
13990 my $gid = 500;
13991
13992 # Make sure that, if we're running as root, that the home directory has
13993 # permissions/privs set for the account we create
13994 if ($< == 0) {
13995 unless (chmod(0755, $home_dir)) {
13996 die("Can't set perms on $home_dir to 0755: $!");
13997 }
13998
13999 unless (chown($uid, $gid, $home_dir)) {
14000 die("Can't set owner of $home_dir to $uid/$gid: $!");
14001 }
14002 }
14003
14004 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
14005 '/bin/bash');
14006 auth_group_write($auth_group_file, $group, $gid, $user);
14007
14008 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
14009 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
14010
14011 my $config = {
14012 PidFile => $pid_file,
14013 ScoreboardFile => $scoreboard_file,
14014 SystemLog => $log_file,
14015
14016 AuthUserFile => $auth_user_file,
14017 AuthGroupFile => $auth_group_file,
14018
14019 IfModules => {
14020 'mod_delay.c' => {
14021 DelayEngine => 'off',
14022 },
14023
14024 'mod_tls.c' => {
14025 TLSEngine => 'on',
14026 TLSLog => $log_file,
14027 TLSRequired => 'on',
14028 TLSRSACertificateFile => $cert_file,
14029 TLSCACertificateFile => $ca_file,
14030 },
14031 },
14032 };
14033
14034 my ($port, $config_user, $config_group) = config_write($config_file, $config);
14035
14036 # Open pipes, for use between the parent and child processes. Specifically,
14037 # the child will indicate when it's done with its test by writing a message
14038 # to the parent.
14039 my ($rfh, $wfh);
14040 unless (pipe($rfh, $wfh)) {
14041 die("Can't open pipe: $!");
14042 }
14043
14044 require Net::FTPSSL;
14045
14046 my $ex;
14047
14048 # Fork child
14049 $self->handle_sigchld();
14050 defined(my $pid = fork()) or die("Can't fork: $!");
14051 if ($pid) {
14052 eval {
14053 # Give the server a chance to start up
14054 sleep(2);
14055
14056 my $client = Net::FTPSSL->new('127.0.0.1',
14057 Encryption => 'E',
14058 Port => $port,
14059 );
14060
14061 unless ($client) {
14062 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
14063 }
14064
14065 unless ($client->login($user, $passwd)) {
14066 die("Can't login: " . $client->last_message());
14067 }
14068
14069 my $resp_code;
14070 if ($Net::FTPSSL::VERSION == 0.21) {
14071 # Note: The duplicated arguments here are to work around a bug in
14072 # Net::FTPSSL, version 0.21, in the quot() function.
14073 $resp_code = $client->quot('SSCN', 'ON', 'ON');
14074
14075 } else {
14076 $resp_code = $client->quot('SSCN', 'ON');
14077 }
14078
14079 unless ($resp_code == 2) {
14080 die("SSCN failed: " . $client->last_message());
14081 }
14082
14083 my $resp_msg = $client->last_message();
14084
14085 my $expected = '200 SSCN:CLIENT METHOD';
14086 $self->assert($expected eq $resp_msg,
14087 test_msg("Expected response message '$expected', got '$resp_msg'"));
14088
14089 $resp_code = $client->quot('SSCN');
14090 unless ($resp_code == 2) {
14091 die("SSCN failed: " . $client->last_message());
14092 }
14093
14094 $resp_msg = $client->last_message();
14095
14096 $expected = '200 SSCN:CLIENT METHOD';
14097 $self->assert($expected eq $resp_msg,
14098 test_msg("Expected response message '$expected', got '$resp_msg'"));
14099
14100 if ($Net::FTPSSL::VERSION == 0.21) {
14101 # Note: The duplicated arguments here are to work around a bug in
14102 # Net::FTPSSL, version 0.21, in the quot() function.
14103 $resp_code = $client->quot('SSCN', 'OFF', 'OFF');
14104
14105 } else {
14106 $resp_code = $client->quot('SSCN', 'OFF');
14107 }
14108
14109 unless ($resp_code == 2) {
14110 die("SSCN failed: " . $client->last_message());
14111 }
14112
14113 $resp_msg = $client->last_message();
14114
14115 $expected = '200 SSCN:SERVER METHOD';
14116 $self->assert($expected eq $resp_msg,
14117 test_msg("Expected response message '$expected', got '$resp_msg'"));
14118
14119 $resp_code = $client->quot('SSCN');
14120 unless ($resp_code == 2) {
14121 die("SSCN failed: " . $client->last_message());
14122 }
14123
14124 $resp_msg = $client->last_message();
14125
14126 $expected = '200 SSCN:SERVER METHOD';
14127 $self->assert($expected eq $resp_msg,
14128 test_msg("Expected response message '$expected', got '$resp_msg'"));
14129
14130 $client->quit();
14131 };
14132
14133 if ($@) {
14134 $ex = $@;
14135 }
14136
14137 $wfh->print("done\n");
14138 $wfh->flush();
14139
14140 } else {
14141 eval { server_wait($config_file, $rfh) };
14142 if ($@) {
14143 warn($@);
14144 exit 1;
14145 }
14146
14147 exit 0;
14148 }
14149
14150 # Stop server
14151 server_stop($pid_file);
14152
14153 $self->assert_child_ok($pid);
14154
14155 if ($ex) {
14156 test_append_logfile($log_file, $ex);
14157 unlink($log_file);
14158
14159 die($ex);
14160 }
14161
14162 unlink($log_file);
14163 }
14164
14165 sub tls_config_limit_sscn_bug3955 {
14166 my $self = shift;
14167 my $tmpdir = $self->{tmpdir};
14168
14169 my $config_file = "$tmpdir/tls.conf";
14170 my $pid_file = File::Spec->rel2abs("$tmpdir/tls.pid");
14171 my $scoreboard_file = File::Spec->rel2abs("$tmpdir/tls.scoreboard");
14172
14173 my $log_file = test_get_logfile();
14174
14175 my $auth_user_file = File::Spec->rel2abs("$tmpdir/tls.passwd");
14176 my $auth_group_file = File::Spec->rel2abs("$tmpdir/tls.group");
14177
14178 my $user = 'proftpd';
14179 my $passwd = 'test';
14180 my $group = 'ftpd';
14181 my $home_dir = File::Spec->rel2abs($tmpdir);
14182 my $uid = 500;
14183 my $gid = 500;
14184
14185 # Make sure that, if we're running as root, that the home directory has
14186 # permissions/privs set for the account we create
14187 if ($< == 0) {
14188 unless (chmod(0755, $home_dir)) {
14189 die("Can't set perms on $home_dir to 0755: $!");
14190 }
14191
14192 unless (chown($uid, $gid, $home_dir)) {
14193 die("Can't set owner of $home_dir to $uid/$gid: $!");
14194 }
14195 }
14196
14197 auth_user_write($auth_user_file, $user, $passwd, $uid, $gid, $home_dir,
14198 '/bin/bash');
14199 auth_group_write($auth_group_file, $group, $gid, $user);
14200
14201 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
14202 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
14203
14204 my $config = {
14205 PidFile => $pid_file,
14206 ScoreboardFile => $scoreboard_file,
14207 SystemLog => $log_file,
14208
14209 AuthUserFile => $auth_user_file,
14210 AuthGroupFile => $auth_group_file,
14211
14212 IfModules => {
14213 'mod_delay.c' => {
14214 DelayEngine => 'off',
14215 },
14216
14217 'mod_tls.c' => {
14218 TLSEngine => 'on',
14219 TLSLog => $log_file,
14220 TLSRequired => 'on',
14221 TLSRSACertificateFile => $cert_file,
14222 TLSCACertificateFile => $ca_file,
14223 },
14224 },
14225
14226 Limit => {
14227 SSCN => {
14228 DenyAll => '',
14229 },
14230 },
14231 };
14232
14233 my ($port, $config_user, $config_group) = config_write($config_file, $config);
14234
14235 # Open pipes, for use between the parent and child processes. Specifically,
14236 # the child will indicate when it's done with its test by writing a message
14237 # to the parent.
14238 my ($rfh, $wfh);
14239 unless (pipe($rfh, $wfh)) {
14240 die("Can't open pipe: $!");
14241 }
14242
14243 require Net::FTPSSL;
14244
14245 my $ex;
14246
14247 # Fork child
14248 $self->handle_sigchld();
14249 defined(my $pid = fork()) or die("Can't fork: $!");
14250 if ($pid) {
14251 eval {
14252 # Give the server a chance to start up
14253 sleep(2);
14254
14255 my $client = Net::FTPSSL->new('127.0.0.1',
14256 Encryption => 'E',
14257 Port => $port,
14258 );
14259
14260 unless ($client) {
14261 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
14262 }
14263
14264 unless ($client->login($user, $passwd)) {
14265 die("Can't login: " . $client->last_message());
14266 }
14267
14268 my $resp_code;
14269 if ($Net::FTPSSL::VERSION == 0.21) {
14270 # Note: The duplicated arguments here are to work around a bug in
14271 # Net::FTPSSL, version 0.21, in the quot() function.
14272 $resp_code = $client->quot('SSCN', 'ON', 'ON');
14273
14274 } else {
14275 $resp_code = $client->quot('SSCN', 'ON');
14276 }
14277
14278 if ($resp_code == 2) {
14279 die("SSCN succeeded unexpectedly");
14280 }
14281
14282 my $resp_msg = $client->last_message();
14283
14284 $client->quit();
14285
14286 my $expected = '550 SSCN: Operation not permitted';
14287 $self->assert($expected eq $resp_msg,
14288 test_msg("Expected response message '$expected', got '$resp_msg'"));
14289 };
14290
14291 if ($@) {
14292 $ex = $@;
14293 }
14294
14295 $wfh->print("done\n");
14296 $wfh->flush();
14297
14298 } else {
14299 eval { server_wait($config_file, $rfh) };
14300 if ($@) {
14301 warn($@);
14302 exit 1;
14303 }
14304
14305 exit 0;
14306 }
14307
14308 # Stop server
14309 server_stop($pid_file);
14310
14311 $self->assert_child_ok($pid);
14312
14313 if ($ex) {
14314 test_append_logfile($log_file, $ex);
14315 unlink($log_file);
14316
14317 die($ex);
14318 }
14319
14320 unlink($log_file);
14321 }
14322
14323 sub tls_config_missing_certs {
14324 my $self = shift;
14325 my $tmpdir = $self->{tmpdir};
14326 my $setup = test_setup($tmpdir, 'tls');
14327
14328 my $config = {
14329 PidFile => $setup->{pid_file},
14330 ScoreboardFile => $setup->{scoreboard_file},
14331 SystemLog => $setup->{log_file},
14332 TraceLog => $setup->{log_file},
14333 Trace => 'tls:20',
14334
14335 AuthUserFile => $setup->{auth_user_file},
14336 AuthGroupFile => $setup->{auth_group_file},
14337
14338 IfModules => {
14339 'mod_delay.c' => {
14340 DelayEngine => 'off',
14341 },
14342
14343 'mod_tls.c' => {
14344 TLSEngine => 'on',
14345 TLSLog => $setup->{log_file},
14346 TLSRequired => 'on',
14347 TLSOptions => 'EnableDiags',
14348 },
14349 },
14350 };
14351
14352 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14353 $config);
14354
14355 # Open pipes, for use between the parent and child processes. Specifically,
14356 # the child will indicate when it's done with its test by writing a message
14357 # to the parent.
14358 my ($rfh, $wfh);
14359 unless (pipe($rfh, $wfh)) {
14360 die("Can't open pipe: $!");
14361 }
14362
14363 require Net::FTPSSL;
14364
14365 my $ex;
14366
14367 # Fork child
14368 $self->handle_sigchld();
14369 defined(my $pid = fork()) or die("Can't fork: $!");
14370 if ($pid) {
14371 eval {
14372 # Give the server a chance to start up
14373 sleep(2);
14374
14375 my $client = Net::FTPSSL->new('127.0.0.1',
14376 Encryption => 'E',
14377 Port => $port,
14378 );
14379
14380 if ($client) {
14381 die("Connected via AUTH TLS unexpectedly");
14382 }
14383
14384 my $errstr = IO::Socket::SSL::errstr();
14385 unless ($errstr) {
14386 $errstr = $Net::FTPSSL::ERRSTR;
14387 }
14388
14389 $self->assert(qr/^431/, $errstr, "Expected 431, got '$errstr'");
14390 };
14391
14392 if ($@) {
14393 $ex = $@;
14394 }
14395
14396 $wfh->print("done\n");
14397 $wfh->flush();
14398
14399 } else {
14400 eval { server_wait($setup->{config_file}, $rfh) };
14401 if ($@) {
14402 warn($@);
14403 exit 1;
14404 }
14405
14406 exit 0;
14407 }
14408
14409 # Stop server
14410 server_stop($setup->{pid_file});
14411 $self->assert_child_ok($pid);
14412
14413 test_cleanup($setup->{log_file}, $ex);
14414 }
14415
14416 sub starttls_ftp {
14417 my $port = shift;
14418 my $ssl_opts = shift;
14419
14420 my $client = IO::Socket::INET->new(
14421 PeerHost => '127.0.0.1',
14422 PeerPort => $port,
14423 Proto => 'tcp',
14424 Type => SOCK_STREAM,
14425 Timeout => 10
14426 );
14427 unless ($client) {
14428 croak("Can't connect to 127.0.0.1:$port: $!");
14429 }
14430
14431 # Read the banner
14432 my $banner = <$client>;
14433
14434 # Send the AUTH command
14435 my $cmd = "AUTH TLS\r\n";
14436 if ($ENV{TEST_VERBOSE}) {
14437 print STDOUT "# Sending command: $cmd";
14438 }
14439 $client->print($cmd);
14440 $client->flush();
14441
14442 # Read the AUTH response
14443 my $resp = <$client>;
14444 if ($ENV{TEST_VERBOSE}) {
14445 print STDOUT "# Received response: $resp";
14446 }
14447
14448 my $expected = "234 AUTH TLS successful\r\n";
14449 unless ($expected eq $resp) {
14450 croak(test_msg("Expected response '$expected', got '$resp'"));
14451 }
14452
14453 # Now perform the SSL handshake
14454 if ($ENV{TEST_VERBOSE}) {
14455 $IO::Socket::SSL::DEBUG = 3;
14456 }
14457
14458 my $res = IO::Socket::SSL->start_SSL($client, $ssl_opts);
14459 unless ($res) {
14460 croak("Failed SSL handshake: " . IO::Socket::SSL::errstr());
14461 }
14462
14463 $cmd = "QUIT\r\n";
14464 if ($ENV{TEST_VERBOSE}) {
14465 print STDOUT "# Sending command: $cmd";
14466 }
14467
14468 $client->print($cmd);
14469 $client->flush();
14470
14471 $resp = <$client>;
14472 if ($ENV{TEST_VERBOSE}) {
14473 print STDOUT "# Received response: $resp";
14474 }
14475
14476 $client->close();
14477 }
14478
14479 sub tls_stapling_on_bug4175 {
14480 my $self = shift;
14481 my $tmpdir = $self->{tmpdir};
14482 my $setup = test_setup($tmpdir, 'tls');
14483
14484 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
14485 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
14486
14487 my $config = {
14488 PidFile => $setup->{pid_file},
14489 ScoreboardFile => $setup->{scoreboard_file},
14490 SystemLog => $setup->{log_file},
14491 TraceLog => $setup->{log_file},
14492 Trace => 'tls:20',
14493
14494 AuthUserFile => $setup->{auth_user_file},
14495 AuthGroupFile => $setup->{auth_group_file},
14496
14497 IfModules => {
14498 'mod_delay.c' => {
14499 DelayEngine => 'off',
14500 },
14501
14502 'mod_tls.c' => {
14503 TLSEngine => 'on',
14504 TLSLog => $setup->{log_file},
14505 TLSRequired => 'on',
14506 TLSRSACertificateFile => $cert_file,
14507 TLSCACertificateFile => $ca_file,
14508 TLSOptions => 'EnableDiags',
14509 TLSStapling => 'on',
14510 },
14511 },
14512 };
14513
14514 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14515 $config);
14516
14517 # Open pipes, for use between the parent and child processes. Specifically,
14518 # the child will indicate when it's done with its test by writing a message
14519 # to the parent.
14520 my ($rfh, $wfh);
14521 unless (pipe($rfh, $wfh)) {
14522 die("Can't open pipe: $!");
14523 }
14524
14525 require IO::Socket::INET;
14526 require IO::Socket::SSL;
14527
14528 my $ex;
14529
14530 # Fork child
14531 $self->handle_sigchld();
14532 defined(my $pid = fork()) or die("Can't fork: $!");
14533 if ($pid) {
14534 eval {
14535 # Give the server a chance to start up
14536 sleep(2);
14537
14538 # Manually simulate the STARTTLS protocol
14539
14540 my $ssl_opts = {
14541 SSL_ocsp_mode => IO::Socket::SSL::SSL_OCSP_TRY_STAPLE(),
14542 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
14543 };
14544
14545 starttls_ftp($port, $ssl_opts);
14546 };
14547
14548 if ($@) {
14549 $ex = $@;
14550 }
14551
14552 $wfh->print("done\n");
14553 $wfh->flush();
14554
14555 } else {
14556 eval { server_wait($setup->{config_file}, $rfh) };
14557 if ($@) {
14558 warn($@);
14559 exit 1;
14560 }
14561
14562 exit 0;
14563 }
14564
14565 # Stop server
14566 server_stop($setup->{pid_file});
14567
14568 $self->assert_child_ok($pid);
14569
14570 test_cleanup($setup->{log_file}, $ex);
14571 }
14572
14573 sub tls_session_tickets_on_bug4176 {
14574 my $self = shift;
14575 my $tmpdir = $self->{tmpdir};
14576 my $setup = test_setup($tmpdir, 'tls');
14577
14578 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
14579 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
14580
14581 my $config = {
14582 PidFile => $setup->{pid_file},
14583 ScoreboardFile => $setup->{scoreboard_file},
14584 SystemLog => $setup->{log_file},
14585 TraceLog => $setup->{log_file},
14586 Trace => 'tls:20',
14587
14588 AuthUserFile => $setup->{auth_user_file},
14589 AuthGroupFile => $setup->{auth_group_file},
14590
14591 IfModules => {
14592 'mod_delay.c' => {
14593 DelayEngine => 'off',
14594 },
14595
14596 'mod_tls.c' => {
14597 TLSEngine => 'on',
14598 TLSLog => $setup->{log_file},
14599 TLSRequired => 'on',
14600 TLSRSACertificateFile => $cert_file,
14601 TLSCACertificateFile => $ca_file,
14602 TLSOptions => 'EnableDiags',
14603 TLSSessionTickets => 'on',
14604 TLSSessionTicketKeys => 'age 60sec count 2',
14605 },
14606 },
14607 };
14608
14609 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14610 $config);
14611
14612 # Open pipes, for use between the parent and child processes. Specifically,
14613 # the child will indicate when it's done with its test by writing a message
14614 # to the parent.
14615 my ($rfh, $wfh);
14616 unless (pipe($rfh, $wfh)) {
14617 die("Can't open pipe: $!");
14618 }
14619
14620 require IO::Socket::INET;
14621 require IO::Socket::SSL;
14622
14623 my $ex;
14624
14625 # Fork child
14626 $self->handle_sigchld();
14627 defined(my $pid = fork()) or die("Can't fork: $!");
14628 if ($pid) {
14629 eval {
14630 # Give the server a chance to start up
14631 sleep(2);
14632
14633 my $ssl_opts = {
14634 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
14635 };
14636
14637 # Manually simulate the STARTTLS protocol
14638
14639 starttls_ftp($port, $ssl_opts);
14640
14641 my $delay = 7;
14642 if ($delay > 0) {
14643 if ($ENV{TEST_VERBOSE}) {
14644 print STDOUT "# Delaying for $delay secs\n";
14645 }
14646
14647 sleep($delay);
14648 }
14649
14650 starttls_ftp($port, $ssl_opts);
14651 };
14652
14653 if ($@) {
14654 $ex = $@;
14655 }
14656
14657 $wfh->print("done\n");
14658 $wfh->flush();
14659
14660 } else {
14661 eval { server_wait($setup->{config_file}, $rfh, 30) };
14662 if ($@) {
14663 warn($@);
14664 exit 1;
14665 }
14666
14667 exit 0;
14668 }
14669
14670 # Stop server
14671 server_stop($setup->{pid_file});
14672
14673 $self->assert_child_ok($pid);
14674
14675 test_cleanup($setup->{log_file}, $ex);
14676 }
14677
14678 sub tls_restart_protected_certs_bug4260 {
14679 my $self = shift;
14680 my $tmpdir = $self->{tmpdir};
14681 my $setup = test_setup($tmpdir, 'tls');
14682
14683 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert-passwd.pem');
14684 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
14685 my $passphrase_provider = File::Spec->rel2abs('t/etc/modules/mod_tls/tls-get-passphrase-once.pl');
14686
14687 # Note: This lock file path MUST be kept in sync with the path used by
14688 # the TLSPassPhraseProvider script used in this test.
14689 my $lock_file = "/tmp/tls-passphrase.lock";
14690
14691 my $config = {
14692 PidFile => $setup->{pid_file},
14693 ScoreboardFile => $setup->{scoreboard_file},
14694 SystemLog => $setup->{log_file},
14695 TraceLog => $setup->{log_file},
14696 Trace => 'tls:20',
14697
14698 AuthUserFile => $setup->{auth_user_file},
14699 AuthGroupFile => $setup->{auth_group_file},
14700
14701 IfModules => {
14702 'mod_delay.c' => {
14703 DelayEngine => 'off',
14704 },
14705
14706 'mod_tls.c' => {
14707 TLSEngine => 'on',
14708 TLSLog => $setup->{log_file},
14709 TLSRSACertificateFile => $cert_file,
14710 TLSCACertificateFile => $ca_file,
14711
14712 TLSPassPhraseProvider => $passphrase_provider,
14713 },
14714 },
14715 };
14716
14717 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14718 $config);
14719
14720 my $ex;
14721
14722 # Start the server
14723 server_start($setup->{config_file});
14724 sleep(4);
14725
14726 # Restart the server
14727 server_restart($setup->{pid_file});
14728 sleep(4);
14729
14730 # Stop server
14731 unless (server_stop($setup->{pid_file})) {
14732 $ex = "Error stopping server";
14733 }
14734
14735 unlink($lock_file);
14736 test_cleanup($setup->{log_file}, $ex);
14737 }
14738
14739 sub tls_fxp_issue618 {
14740 my $self = shift;
14741 my $tmpdir = $self->{tmpdir};
14742 my $setup = test_setup($tmpdir, 'tls');
14743
14744 my $src_file = File::Spec->rel2abs("$tmpdir/src.txt");
14745 if (open(my $fh, "> $src_file")) {
14746 print $fh "Hello, FXP World!\n";
14747
14748 unless (close($fh)) {
14749 die("Can't write $src_file: $!");
14750 }
14751
14752 } else {
14753 die("Can't open $src_file: $!");
14754 }
14755
14756 my $dst_file = File::Spec->rel2abs("$tmpdir/dst.txt");
14757
14758 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
14759 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
14760
14761 # For this test, we will ask the servers to do FXP over TLS for the
14762 # data transfer, but NOT for the control connections. Net::FTPSSL does
14763 # not support FXP over TLS.
14764
14765 my $tls_opts = 'NoSessionReuseRequired';
14766 if ($ENV{TEST_VERBOSE}) {
14767 $tls_opts .= ' EnableDiags';
14768 }
14769
14770 my $timeout_idle = 15;
14771
14772 my $config = {
14773 PidFile => $setup->{pid_file},
14774 ScoreboardFile => $setup->{scoreboard_file},
14775 SystemLog => $setup->{log_file},
14776 TraceLog => $setup->{log_file},
14777 Trace => 'command:20 response:20 data:20 netio:20 tls:20',
14778
14779 AuthUserFile => $setup->{auth_user_file},
14780 AuthGroupFile => $setup->{auth_group_file},
14781
14782 AllowForeignAddress => 'on',
14783 AllowOverwrite => 'on',
14784 TimeoutIdle => $timeout_idle,
14785
14786 IfModules => {
14787 'mod_delay.c' => {
14788 DelayEngine => 'off',
14789 },
14790
14791 'mod_tls.c' => {
14792 TLSEngine => 'on',
14793 TLSLog => $setup->{log_file},
14794 TLSRequired => 'on',
14795 TLSRSACertificateFile => $cert_file,
14796 TLSCACertificateFile => $ca_file,
14797 TLSOptions => $tls_opts,
14798 TLSVerifyClient => 'off',
14799 TLSVerifyServer => 'off',
14800 },
14801 },
14802 };
14803
14804 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
14805 $config);
14806
14807 # Open pipes, for use between the parent and child processes. Specifically,
14808 # the child will indicate when it's done with its test by writing a message
14809 # to the parent.
14810 my ($rfh, $wfh);
14811 unless (pipe($rfh, $wfh)) {
14812 die("Can't open pipe: $!");
14813 }
14814
14815 my $ex;
14816
14817 # Fork child
14818 $self->handle_sigchld();
14819 defined(my $pid = fork()) or die("Can't fork: $!");
14820 if ($pid) {
14821 eval {
14822 # Allow server to start up
14823 sleep(2);
14824
14825 my $client_opts = {
14826 Encryption => 'E',
14827 Port => $port,
14828 };
14829
14830 if ($ENV{TEST_VERBOSE}) {
14831 $client_opts->{Debug} = 1;
14832 }
14833
14834 my $client1 = Net::FTPSSL->new('127.0.0.1', $client_opts);
14835 unless ($client1) {
14836 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
14837 }
14838
14839 unless ($client1->login($setup->{user}, $setup->{passwd})) {
14840 die("Can't login: " . $client1->last_message());
14841 }
14842
14843 my $client2 = Net::FTPSSL->new('127.0.0.1', $client_opts);
14844 unless ($client2) {
14845 die("Can't connect to FTPS server: " . IO::Socket::SSL::errstr());
14846 }
14847
14848 unless ($client2->login($setup->{user}, $setup->{passwd})) {
14849 die("Can't login: " . $client2->last_message());
14850 }
14851
14852 $client1->binary();
14853 $client2->binary();
14854
14855 my ($resp1, $resp2);
14856
14857 if ($Net::FTPSSL::VERSION == 0.21) {
14858 # Note: The duplicated arguments here are to work around a bug in
14859 # Net::FTPSSL, version 0.21, in the quot() function.
14860
14861 # One of the two servers needs to act as a client; use SSCN to indicate
14862 # this. The default SSCN value is to act as a server, thus the need
14863 # for an explicit SSCN command.
14864 $client1->quot('SSCN', 'ON', 'ON');
14865
14866 unless ($client1->quot('PROT', 'P', 'P')) {
14867 die("PROT P error: " . $client1->last_message());
14868 }
14869 unless ($client2->quot('PROT', 'P', 'P')) {
14870 die("PROT P error: " . $client2->last_message());
14871 }
14872
14873 # Get the PASV address from the first connection, and give it
14874 # to the second connection as a PORT command.
14875 unless ($client1->quot('PASV', '', '')) {
14876 die("PASV error: " . $client1->last_message());
14877 }
14878
14879 my $resp_msg = $client1->last_message();
14880 my $expected = 'Entering Passive Mode \(\d+,\d+,\d+,\d+,\d+,\d+\)';
14881 $self->assert(qr/$expected/, $resp_msg,
14882 "Expected response message '$expected', got '$resp_msg'");
14883
14884 # This will actually work, since both our connections are
14885 # from 127.0.0.1, which means we shouldn't run afoul of the
14886 # AllowForeignAddress limit.
14887 $resp_msg =~ /Entering Passive Mode \((\d+,\d+,\d+,\d+,\d+,\d+\))/;
14888 my $port_addr = $1;
14889
14890 unless ($client2->quot('PORT', $port_addr, $port_addr)) {
14891 die("PORT error: " . $client2->last_message());
14892 }
14893
14894 $resp_msg = $client2->last_message();
14895 $expected = 'PORT command successful';
14896 $self->assert(qr/$expected/, $resp_msg,
14897 "Expected response message '$expected', got '$resp_msg'");
14898
14899 # Note that we use command() here, not quot(), as the latter tries
14900 # to protect users from using data-transfer-causing commands like we
14901 # are doing.
14902 $resp1 = $client1->command('RETR', $src_file, $src_file);
14903 unless ($resp1) {
14904 die("Can't RETR $src_file: " . $client1->last_message());
14905 }
14906 $resp2 = $client2->command('STOR', $dst_file, $dst_file);
14907 unless ($resp2) {
14908 die("Can't STOR $dst_file: " . $client2->last_message());
14909 }
14910
14911 } else {
14912 # One of the two servers needs to act as a client; use SSCN to indicate
14913 # this. The default SSCN value is to act as a server, thus the need
14914 # for an explicit SSCN command.
14915 $client1->quot('SSCN', 'ON');
14916
14917 unless ($client1->quot('PROT', 'P')) {
14918 die("PROT P error: " . $client1->last_message());
14919 }
14920 unless ($client2->quot('PROT', 'P')) {
14921 die("PROT P error: " . $client2->last_message());
14922 }
14923
14924 # Get the PASV address from the first connection, and give it
14925 # to the second connection as a PORT command.
14926 unless ($client1->quot('PASV', '')) {
14927 die("PASV error: " . $client1->last_message());
14928 }
14929
14930 my $resp_msg = $client1->last_message();
14931 my $expected = 'Entering Passive Mode \(\d+,\d+,\d+,\d+,\d+,\d+\)';
14932 $self->assert(qr/$expected/, $resp_msg,
14933 "Expected response message '$expected', got '$resp_msg'");
14934
14935 # This will actually work, since both our connections are
14936 # from 127.0.0.1, which means we shouldn't run afoul of the
14937 # AllowForeignAddress limit.
14938 $resp_msg =~ /Entering Passive Mode \((\d+,\d+,\d+,\d+,\d+,\d+\))/;
14939 my $port_addr = $1;
14940
14941 unless ($client2->quot('PORT', $port_addr)) {
14942 die("PORT error: " . $client2->last_message());
14943 }
14944
14945 $resp_msg = $client2->last_message();
14946 $expected = 'PORT command successful';
14947 $self->assert(qr/$expected/, $resp_msg,
14948 "Expected response message '$expected', got '$resp_msg'");
14949
14950 # Note that we use command() here, not quot(), as the latter tries
14951 # to protect users from using data-transfer-causing commands like we
14952 # are doing.
14953 $resp1 = $client1->command('RETR', $src_file);
14954 unless ($resp1) {
14955 die("Can't RETR $src_file: " . $client1->last_message());
14956 }
14957 $resp2 = $client2->command('STOR', $dst_file);
14958 unless ($resp2) {
14959 die("Can't STOR $dst_file: " . $client2->last_message());
14960 }
14961 }
14962
14963 # First, we read the 150 responses, then the 226 responses.
14964 my $res1 = $resp1->response();
14965 my $res2 = $resp2->response();
14966
14967 if ($res1 eq '1') {
14968 $res1 = $resp1->response();
14969 }
14970 if ($res2 eq '1') {
14971 $res2 = $resp2->response();
14972 }
14973
14974 $client1->quit();
14975 $client2->quit();
14976
14977 $self->assert(-f $dst_file, "File $dst_file does not exist as expected");
14978 my $dst_size = -s $dst_file;
14979 my $expected = -s $src_file;
14980 $self->assert($expected == $dst_size,
14981 "Expected file size $expected, got $dst_size");
14982 };
14983 if ($@) {
14984 $ex = $@;
14985 }
14986
14987 $wfh->print("done\n");
14988 $wfh->flush();
14989
14990 } else {
14991 eval { server_wait($setup->{config_file}, $rfh, $timeout_idle + 5) };
14992 if ($@) {
14993 warn($@);
14994 exit 1;
14995 }
14996
14997 exit 0;
14998 }
14999
15000 # Stop server
15001 server_stop($setup->{pid_file});
15002 $self->assert_child_ok($pid);
15003
15004 test_cleanup($setup->{log_file}, $ex);
15005 }
15006
15007 sub tls_old_protocols_issue1273 {
15008 my $self = shift;
15009 my $tmpdir = $self->{tmpdir};
15010 my $setup = test_setup($tmpdir, 'tls');
15011
15012 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
15013 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
15014
15015 my $tls_opts = 'NoSessionReuseRequired UseImplicitSSL';
15016 if ($ENV{TEST_VERBOSE}) {
15017 $tls_opts .= ' EnableDiags';
15018 }
15019
15020 my $timeout_idle = 15;
15021
15022 my $config = {
15023 PidFile => $setup->{pid_file},
15024 ScoreboardFile => $setup->{scoreboard_file},
15025 SystemLog => $setup->{log_file},
15026 TraceLog => $setup->{log_file},
15027 Trace => 'command:20 response:20 data:20 netio:20 tls:20',
15028
15029 AuthUserFile => $setup->{auth_user_file},
15030 AuthGroupFile => $setup->{auth_group_file},
15031
15032 AllowForeignAddress => 'on',
15033 AllowOverwrite => 'on',
15034 TimeoutIdle => $timeout_idle,
15035
15036 IfModules => {
15037 'mod_delay.c' => {
15038 DelayEngine => 'off',
15039 },
15040
15041 'mod_tls.c' => {
15042 TLSEngine => 'on',
15043 TLSLog => $setup->{log_file},
15044 TLSProtocol => 'SSLv23',
15045 TLSRequired => 'on',
15046 TLSRSACertificateFile => $cert_file,
15047 TLSCACertificateFile => $ca_file,
15048 TLSOptions => $tls_opts,
15049 },
15050 },
15051 };
15052
15053 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15054 $config);
15055
15056 # Open pipes, for use between the parent and child processes. Specifically,
15057 # the child will indicate when it's done with its test by writing a message
15058 # to the parent.
15059 my ($rfh, $wfh);
15060 unless (pipe($rfh, $wfh)) {
15061 die("Can't open pipe: $!");
15062 }
15063
15064 my $ex;
15065
15066 # Fork child
15067 $self->handle_sigchld();
15068 defined(my $pid = fork()) or die("Can't fork: $!");
15069 if ($pid) {
15070 eval {
15071 sleep(2);
15072
15073 # We use an older OpenSSL version for the older protocols.
15074 # Allow server to start up
15075 my $openssl = '/Users/tj/local/openssl-0.9.8d/bin/openssl';
15076
15077 # Explicitly use SSLv3, which has been disabled by default in
15078 # OpenSSL-1.1.x; see:
15079 # https://github.com/openssl/openssl/issues/4989
15080
15081 my @cmd = (
15082 $openssl,
15083 's_client',
15084 '-connect',
15085 "127.0.0.1:$port",
15086 '-ssl3',
15087 );
15088
15089 my $tls_rh = IO::Handle->new();
15090 my $tls_wh = IO::Handle->new();
15091 my $tls_eh = IO::Handle->new();
15092
15093 $tls_wh->autoflush(1);
15094
15095 local $SIG{CHLD} = 'DEFAULT';
15096
15097 if ($ENV{TEST_VERBOSE}) {
15098 print STDERR "Executing: ", join(' ', @cmd), "\n";
15099 }
15100
15101 my $tls_pid = open3($tls_wh, $tls_rh, $tls_eh, @cmd);
15102 print $tls_wh "quit\n";
15103 waitpid($tls_pid, 0);
15104
15105 my ($res, $cipher_str, $err_str, $out_str);
15106 if ($? >> 8) {
15107 $err_str = join('', <$tls_eh>);
15108 $res = 0;
15109
15110 } else {
15111 my $output = [<$tls_rh>];
15112
15113 if ($ENV{TEST_VERBOSE}) {
15114 $out_str = join('', @$output);
15115 print STDERR "Stdout: $out_str\n";
15116
15117 $err_str = join('', <$tls_eh>);
15118 print STDERR "Stderr: $err_str\n";
15119 }
15120
15121 $res = 1;
15122 }
15123
15124 unless ($res) {
15125 die("Can't talk to server: $err_str");
15126 }
15127 };
15128 if ($@) {
15129 $ex = $@;
15130 }
15131
15132 $wfh->print("done\n");
15133 $wfh->flush();
15134
15135 } else {
15136 eval { server_wait($setup->{config_file}, $rfh, $timeout_idle + 5) };
15137 if ($@) {
15138 warn($@);
15139 exit 1;
15140 }
15141
15142 exit 0;
15143 }
15144
15145 # Stop server
15146 server_stop($setup->{pid_file});
15147 $self->assert_child_ok($pid);
15148 test_cleanup($setup->{log_file}, $ex) if $ex;
15149
15150 eval {
15151 if (open(my $fh, "< $setup->{log_file}")) {
15152 my $seen = 0;
15153
15154 while (my $line = <$fh>) {
15155 chomp($line);
15156
15157 if ($line =~ /OpenSSL.*?lacks support for client requested/) {
15158 $seen = 1;
15159 last;
15160 }
15161 }
15162
15163 close($fh);
15164
15165 $self->assert($seen, test_msg("Did not see expected log message"));
15166
15167 } else {
15168 die("Can't read $setup->{log_file}: $!");
15169 }
15170 };
15171 if ($@) {
15172 $ex = $@;
15173 }
15174
15175 test_cleanup($setup->{log_file}, $ex);
15176 }
15177
15178 sub tls_curl_download_largefile_renegotiate_bug4443 {
15179 my $self = shift;
15180 my $tmpdir = $self->{tmpdir};
15181 my $setup = test_setup($tmpdir, 'tls');
15182
15183 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
15184 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
15185
15186 # Create a file that is 1GB plus 24 bytes.
15187 my $test_len = (2 ** 30) + 24;
15188 my $test_file = File::Spec->rel2abs("$tmpdir/test.dat");
15189 if (open(my $fh, "> $test_file")) {
15190
15191 # Seek to the 1GB limit, then fill the rest with 'A'
15192 unless (seek($fh, (2 ** 30), 0)) {
15193 die("Can't seek to 1GB length: $!");
15194 }
15195
15196 print $fh "A" x 24;
15197
15198 unless (close($fh)) {
15199 die("Can't write $test_file: $!");
15200 }
15201
15202 } else {
15203 die("Can't open $test_file: $!");
15204 }
15205
15206 my $config = {
15207 PidFile => $setup->{pid_file},
15208 ScoreboardFile => $setup->{scoreboard_file},
15209 SystemLog => $setup->{log_file},
15210 TraceLog => $setup->{log_file},
15211 Trace => 'tls:20',
15212
15213 AuthUserFile => $setup->{auth_user_file},
15214 AuthGroupFile => $setup->{auth_group_file},
15215
15216 IfModules => {
15217 'mod_delay.c' => {
15218 DelayEngine => 'off',
15219 },
15220
15221 'mod_tls.c' => {
15222 TLSEngine => 'on',
15223 TLSLog => $setup->{log_file},
15224 TLSRequired => 'on',
15225 TLSRSACertificateFile => $cert_file,
15226 TLSCACertificateFile => $ca_file,
15227 TLSOptions => 'EnableDiags NoSessionReuseRequired',
15228 },
15229 },
15230 };
15231
15232 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15233 $config);
15234
15235 # Open pipes, for use between the parent and child processes. Specifically,
15236 # the child will indicate when it's done with its test by writing a message
15237 # to the parent.
15238 my ($rfh, $wfh);
15239 unless (pipe($rfh, $wfh)) {
15240 die("Can't open pipe: $!");
15241 }
15242
15243 my $ex;
15244
15245 # Fork child
15246 $self->handle_sigchld();
15247 defined(my $pid = fork()) or die("Can't fork: $!");
15248 if ($pid) {
15249 eval {
15250 # Give the server a chance to start up
15251 sleep(2);
15252
15253 my $curl = 'curl';
15254
15255 my $curl_cmd = [
15256 $curl,
15257 '-kvs',
15258 '-o',
15259 '/dev/null',
15260 '--user',
15261 "$setup->{user}:$setup->{passwd}",
15262 '--ftp-ssl',
15263 "ftp://127.0.0.1:$port/test.dat"
15264 ];
15265
15266 my $curl_rh = IO::Handle->new();
15267 my $curl_wh = IO::Handle->new();
15268 my $curl_eh = IO::Handle->new();
15269
15270 $curl_wh->autoflush(1);
15271
15272 local $SIG{CHLD} = 'DEFAULT';
15273
15274 # Give the server a chance to start up
15275 sleep(2);
15276
15277 if ($ENV{TEST_VERBOSE}) {
15278 print STDERR "Executing: ", join(' ', @$curl_cmd), "\n";
15279 }
15280
15281 my $curl_pid = open3($curl_wh, $curl_rh, $curl_eh, @$curl_cmd);
15282 waitpid($curl_pid, 0);
15283 my $exit_status = $?;
15284
15285 my ($res, $errstr);
15286 if ($exit_status >> 8 == 0) {
15287 $errstr = join('', <$curl_eh>);
15288 $res = 0;
15289
15290 } else {
15291 $errstr = join('', <$curl_eh>);
15292 if ($ENV{TEST_VERBOSE}) {
15293 print STDERR "Stderr: $errstr\n";
15294 }
15295
15296 $res = 1;
15297 }
15298
15299 unless ($res == 0) {
15300 die("Can't download from FTPS server: $errstr");
15301 }
15302 };
15303 if ($@) {
15304 $ex = $@;
15305 }
15306
15307 $wfh->print("done\n");
15308 $wfh->flush();
15309
15310 } else {
15311 eval { server_wait($setup->{config_file}, $rfh, 60) };
15312 if ($@) {
15313 warn($@);
15314 exit 1;
15315 }
15316
15317 exit 0;
15318 }
15319
15320 # Stop server
15321 server_stop($setup->{pid_file});
15322 $self->assert_child_ok($pid);
15323
15324 test_cleanup($setup->{log_file}, $ex);
15325 }
15326
15327 sub tls_useimplicitssl_tcp_connect_only {
15328 my $self = shift;
15329 my $tmpdir = $self->{tmpdir};
15330 my $setup = test_setup($tmpdir, 'tls');
15331
15332 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
15333 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
15334
15335 my $config = {
15336 PidFile => $setup->{pid_file},
15337 ScoreboardFile => $setup->{scoreboard_file},
15338 SystemLog => $setup->{log_file},
15339 TraceLog => $setup->{log_file},
15340 Trace => 'tls:20',
15341
15342 AuthUserFile => $setup->{auth_user_file},
15343 AuthGroupFile => $setup->{auth_group_file},
15344
15345 IfModules => {
15346 'mod_delay.c' => {
15347 DelayEngine => 'off',
15348 },
15349
15350 'mod_tls.c' => {
15351 TLSEngine => 'on',
15352 TLSLog => $setup->{log_file},
15353 TLSRequired => 'off',
15354 TLSOptions => 'EnableDiags UseImplicitSSL',
15355 TLSRSACertificateFile => $cert_file,
15356 TLSCACertificateFile => $ca_file,
15357 TLSVerifyClient => 'off',
15358 },
15359 },
15360 };
15361
15362 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15363 $config);
15364
15365 # Open pipes, for use between the parent and child processes. Specifically,
15366 # the child will indicate when it's done with its test by writing a message
15367 # to the parent.
15368 my ($rfh, $wfh);
15369 unless (pipe($rfh, $wfh)) {
15370 die("Can't open pipe: $!");
15371 }
15372
15373 my $ex;
15374
15375 # Fork child
15376 $self->handle_sigchld();
15377 defined(my $pid = fork()) or die("Can't fork: $!");
15378 if ($pid) {
15379 eval {
15380 # Give the server a chance to start up
15381 sleep(2);
15382
15383 my $tcp_opts = {
15384 PeerAddr => '127.0.0.1',
15385 PeerPort => $port,
15386 Proto => 'tcp',
15387 Timeout => 2,
15388 };
15389
15390 my $client = IO::Socket::INET->new(%$tcp_opts);
15391 unless ($client) {
15392 die("Can't connect to FTPS server: $!");
15393 }
15394
15395 sleep(1);
15396 $client->close();
15397 };
15398 if ($@) {
15399 $ex = $@;
15400 }
15401
15402 $wfh->print("done\n");
15403 $wfh->flush();
15404
15405 } else {
15406 eval { server_wait($setup->{config_file}, $rfh) };
15407 if ($@) {
15408 warn($@);
15409 exit 1;
15410 }
15411
15412 exit 0;
15413 }
15414
15415 # Stop server
15416 server_stop($setup->{pid_file});
15417 $self->assert_child_ok($pid);
15418
15419 eval {
15420 if (open(my $fh, "< $setup->{log_file}")) {
15421 my $ok = 1;
15422
15423 while (my $line = <$fh>) {
15424 chomp($line);
15425
15426 if ($ENV{TEST_VERBOSE}) {
15427 print STDERR "# $line\n";
15428 }
15429
15430 if ($line =~ /mod_tls\.c: error initializing session/) {
15431 $ok = 0;
15432 last;
15433 }
15434 }
15435
15436 close($fh);
15437
15438 $self->assert($ok, test_msg("Saw undesirable log message unexpectedly"));
15439
15440 } else {
15441 die("Can't read $setup->{log_file}: $!");
15442 }
15443 };
15444 if ($@) {
15445 $ex = $@;
15446 }
15447
15448 test_cleanup($setup->{log_file}, $ex);
15449 }
15450
15451 sub tls_explicit_plaintext_fallback_issue192 {
15452 my $self = shift;
15453 my $tmpdir = $self->{tmpdir};
15454 my $setup = test_setup($tmpdir, 'tls');
15455
15456 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
15457 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
15458
15459 # To force a TLS handshake failure, we'll configure the client to use a
15460 # protocol version (e.g. TLSv1) that the server won't support.
15461
15462 my $config = {
15463 PidFile => $setup->{pid_file},
15464 ScoreboardFile => $setup->{scoreboard_file},
15465 SystemLog => $setup->{log_file},
15466 TraceLog => $setup->{log_file},
15467 Trace => 'binding:20 command:20 response:20 tls:20',
15468
15469 AuthUserFile => $setup->{auth_user_file},
15470 AuthGroupFile => $setup->{auth_group_file},
15471 AuthOrder => 'mod_auth_file.c',
15472
15473 IfModules => {
15474 'mod_delay.c' => {
15475 DelayEngine => 'off',
15476 },
15477
15478 'mod_tls.c' => {
15479 TLSEngine => 'on',
15480 TLSLog => $setup->{log_file},
15481 TLSRequired => 'on',
15482 TLSRSACertificateFile => $cert_file,
15483 TLSCACertificateFile => $ca_file,
15484 TLSProtocol => 'TLSv1.1 TLSv1.2',
15485 TLSOptions => 'EnableDiags',
15486 },
15487 },
15488 };
15489
15490 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15491 $config);
15492
15493 # Open pipes, for use between the parent and child processes. Specifically,
15494 # the child will indicate when it's done with its test by writing a message
15495 # to the parent.
15496 my ($rfh, $wfh);
15497 unless (pipe($rfh, $wfh)) {
15498 die("Can't open pipe: $!");
15499 }
15500
15501 require Net::FTPSSL;
15502
15503 my $ex;
15504
15505 # Ignore SIGPIPE (generated when writing to a closed TCP socket).
15506 local $SIG{PIPE} = sub { };
15507
15508 # Fork child
15509 $self->handle_sigchld();
15510 defined(my $pid = fork()) or die("Can't fork: $!");
15511 if ($pid) {
15512 eval {
15513 # Give the server a chance to start up
15514 sleep(2);
15515
15516 # Note that we cannot use Net::FTPSSL here, as it makes assumptions which
15517 # complicate the testing of this use case. Thus we do it manually.
15518
15519 my $client = IO::Socket::INET->new(
15520 PeerHost => '127.0.0.1',
15521 PeerPort => $port,
15522 Proto => 'tcp',
15523 Type => SOCK_STREAM,
15524 Timeout => 10
15525 );
15526 unless ($client) {
15527 croak("Can't connect to 127.0.0.1:$port: $!");
15528 }
15529
15530 # Read the banner
15531 my $banner = <$client>;
15532 if ($ENV{TEST_VERBOSE}) {
15533 print STDOUT "# Received banner: $banner\n";
15534 }
15535
15536 # Send the AUTH command
15537 my $cmd = "AUTH TLS\r\n";
15538 if ($ENV{TEST_VERBOSE}) {
15539 print STDOUT "# Sending command: $cmd";
15540 }
15541
15542 $client->print($cmd);
15543 $client->flush();
15544
15545 # Read the AUTH response
15546 my $resp = <$client>;
15547 if ($ENV{TEST_VERBOSE}) {
15548 print STDOUT "# Received response: $resp\n";
15549 }
15550
15551 my $expected = "234 AUTH TLS successful\r\n";
15552 unless ($expected eq $resp) {
15553 croak("Expected response '$expected', got '$resp'");
15554 }
15555
15556 # Now perform the SSL handshake
15557 if ($ENV{TEST_VERBOSE}) {
15558 $IO::Socket::SSL::DEBUG = 3;
15559 }
15560
15561 my $ssl_opts = {
15562 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
15563 };
15564
15565 my $res = IO::Socket::SSL->start_SSL($client, $ssl_opts);
15566 if ($res) {
15567 croak("TLS handshake succeeded unexpectedly");
15568 }
15569
15570 # Due to mod_tls implementation, where we close the ctrl connection on
15571 # TLS handshake failure (to avoid any plaintext fallback issues, as some
15572 # security scanners/tools like to nag about), we should expect to read
15573 # an async 421 response here. It may take a little while for the buffers
15574 # to flush, so add a little delay to allow for that time.
15575 sleep(1);
15576
15577 $cmd = "FEAT\r\n";
15578 if ($ENV{TEST_VERBOSE}) {
15579 print STDOUT "# Sending command: $cmd";
15580 }
15581
15582 $client->print($cmd);
15583 $client->flush();
15584
15585 # Read the FEAT response
15586 my $resp = <$client>;
15587 if ($ENV{TEST_VERBOSE}) {
15588 print STDOUT "# Received response: $resp\n";
15589 }
15590
15591 my $expected = "421 TLS handshake failed\r\n";
15592 unless ($expected eq $resp) {
15593 croak("Expected response '$expected', got '$resp'");
15594 }
15595
15596 $client->close();
15597 };
15598 if ($@) {
15599 $ex = $@;
15600 }
15601
15602 $wfh->print("done\n");
15603 $wfh->flush();
15604
15605 } else {
15606 eval { server_wait($setup->{config_file}, $rfh) };
15607 if ($@) {
15608 warn($@);
15609 exit 1;
15610 }
15611
15612 exit 0;
15613 }
15614
15615 # Stop server
15616 server_stop($setup->{pid_file});
15617 $self->assert_child_ok($pid);
15618
15619 test_cleanup($setup->{log_file}, $ex);
15620 }
15621
15622 sub tls_implicit_plaintext_fallback_issue192 {
15623 my $self = shift;
15624 my $tmpdir = $self->{tmpdir};
15625 my $setup = test_setup($tmpdir, 'tls');
15626
15627 my $cert_file = File::Spec->rel2abs('t/etc/modules/mod_tls/server-cert.pem');
15628 my $ca_file = File::Spec->rel2abs('t/etc/modules/mod_tls/ca-cert.pem');
15629
15630 # To force a TLS handshake failure, we'll configure the client to use a
15631 # protocol version (e.g. TLSv1) that the server won't support.
15632
15633 my $config = {
15634 PidFile => $setup->{pid_file},
15635 ScoreboardFile => $setup->{scoreboard_file},
15636 SystemLog => $setup->{log_file},
15637 TraceLog => $setup->{log_file},
15638 Trace => 'binding:20 command:20 response:20 tls:20',
15639
15640 AuthUserFile => $setup->{auth_user_file},
15641 AuthGroupFile => $setup->{auth_group_file},
15642 AuthOrder => 'mod_auth_file.c',
15643
15644 IfModules => {
15645 'mod_delay.c' => {
15646 DelayEngine => 'off',
15647 },
15648
15649 'mod_tls.c' => {
15650 TLSEngine => 'on',
15651 TLSLog => $setup->{log_file},
15652 TLSRequired => 'on',
15653 TLSRSACertificateFile => $cert_file,
15654 TLSCACertificateFile => $ca_file,
15655 TLSProtocol => 'TLSv1.1 TLSv1.2',
15656 TLSOptions => 'EnableDiags UseImplicitSSL',
15657 },
15658 },
15659 };
15660
15661 my ($port, $config_user, $config_group) = config_write($setup->{config_file},
15662 $config);
15663
15664 # Open pipes, for use between the parent and child processes. Specifically,
15665 # the child will indicate when it's done with its test by writing a message
15666 # to the parent.
15667 my ($rfh, $wfh);
15668 unless (pipe($rfh, $wfh)) {
15669 die("Can't open pipe: $!");
15670 }
15671
15672 require Net::FTPSSL;
15673
15674 my $ex;
15675
15676 # Ignore SIGPIPE (generated when writing to a closed TCP socket).
15677 local $SIG{PIPE} = sub { };
15678
15679 # Fork child
15680 $self->handle_sigchld();
15681 defined(my $pid = fork()) or die("Can't fork: $!");
15682 if ($pid) {
15683 eval {
15684 # Give the server a chance to start up
15685 sleep(2);
15686
15687 # Note that we cannot use Net::FTPSSL here, as it makes assumptions which
15688 # complicate the testing of this use case. Thus we do it manually.
15689
15690 my $client = IO::Socket::INET->new(
15691 PeerHost => '127.0.0.1',
15692 PeerPort => $port,
15693 Proto => 'tcp',
15694 Type => SOCK_STREAM,
15695 Timeout => 10
15696 );
15697 unless ($client) {
15698 croak("Can't connect to 127.0.0.1:$port: $!");
15699 }
15700
15701 # Now perform the SSL handshake
15702 if ($ENV{TEST_VERBOSE}) {
15703 $IO::Socket::SSL::DEBUG = 3;
15704 }
15705
15706 my $ssl_opts = {
15707 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(),
15708 };
15709
15710 my $res = IO::Socket::SSL->start_SSL($client, $ssl_opts);
15711 if ($res) {
15712 croak("TLS handshake succeeded unexpectedly");
15713 }
15714
15715 # Due to mod_tls implementation, where we close the ctrl connection on
15716 # TLS handshake failure (to avoid any plaintext fallback issues, as some
15717 # security scanners/tools like to nag about), we should expect to read
15718 # an async 421 response here. It may take a little while for the buffers
15719 # to flush, so add a little delay to allow for that time.
15720 sleep(1);
15721
15722 my $cmd = "FEAT\r\n";
15723 if ($ENV{TEST_VERBOSE}) {
15724 print STDOUT "# Sending command: $cmd";
15725 }
15726
15727 $client->print($cmd);
15728 $client->flush();
15729
15730 # Read the FEAT response
15731 my $resp = <$client>;
15732 if ($ENV{TEST_VERBOSE}) {
15733 print STDOUT "# Received response: $resp\n";
15734 }
15735
15736 my $expected = "421 TLS handshake failed\r\n";
15737 unless ($expected eq $resp) {
15738 croak("Expected response '$expected', got '$resp'");
15739 }
15740
15741 $client->close();
15742 };
15743 if ($@) {
15744 $ex = $@;
15745 }
15746
15747 $wfh->print("done\n");
15748 $wfh->flush();
15749
15750 } else {
15751 eval { server_wait($setup->{config_file}, $rfh) };
15752 if ($@) {
15753 warn($@);
15754 exit 1;
15755 }
15756
15757 exit 0;
15758 }
15759
15760 # Stop server
15761 server_stop($setup->{pid_file});
15762 $self->assert_child_ok($pid);
15763
15764 test_cleanup($setup->{log_file}, $ex);
15765 }
15766
15767 1;