-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssl_check_chain
executable file
·717 lines (595 loc) · 24.5 KB
/
ssl_check_chain
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
#!/usr/bin/perl
use warnings;
use strict;
my $copyright = << 'COPYRIGHT';
Copyright (C) 2021-2022 Timothe Litt <litt at acm.org>
Use --man for license information.
COPYRIGHT
our $VERSION = '$Id$';
# License is in the POD at the end of this file.
use Config( qw/%Config/ );
use Cwd( qw/realpath/ );
use Date::Parse;
use Errno( qw/EAGAIN/ );
use Fcntl( qw/:seek/ );
use File::Basename;
use File::Spec;
use File::Temp;
use Getopt::Long( qw/:config bundling/ );
use POSIX( qw/strftime/ );
use Text::Abbrev;
my @signo;
defined $Config{sig_name} and @signo = ( split( ' ', $Config{sig_name} ) );
my $ostype = eval { require Perl::OSType; return Perl::OSType::os_type() } || 'Unix';
my $havepss;
my $tmpdir = File::Spec->tmpdir || '.';
my $CAcerts = '';
# Environment variables that specify trusted CA locations
my %calocs = ( -CAfile => [qw/SSL_CERT_FILE CURL_CA_BUNDLE/],
-CApath => [qw/SSL_CERT_DIR/],
);
for my $opt ( keys %calocs ) {
my $vars = $calocs{$opt};
foreach my $var ( @$vars ) {
if( my $val = $ENV{$var} ) {
$CAcerts .= " $opt $val ";
last;
}
}
}
# s_client supported list of starttls protocols => standard port
#<<<
my %starttls = (
"xmpp-server" => 5269, "postgres" => 5432, "xmpp" => 5222, "sieve" => 2000,
"mysql" => 3306, "pop3" => 110, "imap" => 143, "irc" => 194,
"nntp" => 119, "ldap" => 389, "ftp" => 21, "lmtp" => 24,
"smtp" => 25,
);
#>>>
my %starttlsAbbrev = abbrev( keys %starttls );
# Duplicate / @loop detection
my( %atfiles, %hosts );
# Option values => OpenSSL options
my %tlsver = ( '1.1' => '-tls1_1', '1.2' => '-tls1_2', '1.3' => '-tls1_3', );
# Option values
my( $cafile, $cadir, $debug, $warn, $help, $man, $version, $starttls, $timeout,
$tlsver,
$type );
# Execute command & print unexpected errors
sub docmd {
my( $cmd ) = join( '', @_ );
printf( ">> %s", $cmd ) if( $debug );
my $r = qx($cmd);
if( $? != 0 ) {
if( $? == -1 ) {
printf STDERR ( "failed to execute %s: $!\n", $cmd );
} elsif( $? & 127 ) {
printf STDERR (
"%s died with signal %s (%d), %s coredump\n", $cmd,
( $signo[ $? & 127 ] || '??' ), ( $? & 127 ),
( $? & 128 ) ? 'with' : 'without' );
} elsif( $_[1] ne 'verify' ) {
printf STDERR ( "%s exited with value %d\n", $cmd, $? >> 8 );
}
return "$r";
}
return $r;
}
# Compute a time difference and return an approximate text representation
sub pdelta {
my( $date, $now ) = @_;
my $day = 24 * 60 * 60;
my $delta = $date - $now;
my $d2g = int( ( abs( $delta ) ) / $day );
if( $d2g == 0 ) {
return "today";
}
$d2g = int( ( abs( $delta ) + ( $day - 1 ) ) / $day );
my $text = "in %d days%s, on %s";
if( $delta < 0 ) {
$text = "%d days%s ago, on %s";
$delta = -$delta;
}
my $y2g = "";
if( $d2g > 366 ) {
$y2g = sprintf( " (%.2f years)", $d2g / 365 );
}
return sprintf( $text, $d2g, $y2g,
strftime( '%a %d-%b-%Y at %T %Z', localtime( $date ) ) );
}
# Produce a string describing where something was specified
sub atloc {
my( $at, $atl ) = @_;
return sprintf( "in %s at line %u", $at, $atl )
if( $at );
return "in command arguments";
}
# Expand tildes in file names and return the realpath
sub tildename {
my( $filename, $at, $atl ) = @_;
if( $filename =~ s,^~([^/]*)/,, ) {
if( $ostype eq 'Unix' ) {
my $user = length $1 ? $1 : getlogin();
my $dir = ( getpwnam( $user ) )[7];
die( sprintf(
"~%s/%s: %s has no home directory, specified %s\n", $1, $filename,
$user,
atloc( $at, $atl ) ) )
unless( $dir );
$filename = File::Spec->catfile( $dir, $filename );
}
}
return realpath( $filename );
}
# Read a PEM file and make sure it contains at least one certificate
sub readfile {
my( $name, $header, $at, $atl ) = @_;
$$header = 1;
$name = tildename( $name, $at, $atl );
unless( defined $name ) {
printf STDERR (
"Skipping unresolvable filename %s, specified %s\n", $_[0],
atloc( $at, $atl ) )
if( $warn );
return;
}
if( ( my $prev = $hosts{"$name:FILE"} ) ) {
printf STDERR (
"Skipping duplicate certificate file %s %s, previously specified in %s\n",
$name, atloc( $at, $atl ), $prev )
if( $warn );
$hosts{"$name:FILE"} = atloc( $at, $atl );
return;
}
$hosts{"$name:FILE"} = atloc( $at, $atl );
printf( "open: $name\n" ) if( $debug );
if( open( my $fh, '<', $name ) ) {
my $chain = '';
while( <$fh> ) {
$chain .= $_;
}
close( $fh );
unless( $chain =~ /^-{2,8}BEGIN (?:TRUSTED )?CERTIFICATE/m ) {
die( sprintf(
"No certificates found in %s, specified %s\n", $name,
atloc( $at, $atl ) ) );
}
( my $haskey ) = $chain =~ /^-{2,8}BEGIN (RSA|EC) PRIVATE KEY/m;
return ( $chain, $haskey );
}
die( sprintf( "open: %s: %s %s\n", $name, $!, atloc( $at, $atl ) ) );
}
# Process an indirect file, which contains hosts, files, and/or more indirection
sub atfile {
my( $host, $fn, $header, $first, $at, $atl ) = @_;
$fn = tildename( $fn, $at, $atl );
die( sprintf("Unresolvable \@filename %s, specified %s\n", $_[1], atloc( $at, $atl )
) )
unless( defined $fn );
if( $atfiles{$fn} ) {
printf STDERR (
"Skipping redundant use of %s => %s %s. The previous use was %s\n",
$host, $fn, atloc( $at, $atl ), $atfiles{$fn} )
if( $warn );
$atfiles{$fn} = atloc( $at, $atl );
return;
}
$atfiles{$fn} = atloc( $at, $atl );
printf( "open: $fn\n" ) if( $debug );
if( open( my $fh, '<', $fn ) ) {
while( <$fh> ) {
chomp $_;
s/^\s*//;
s/\s*$//;
next if( /^(?:#.*)?$/ );
printf( "%s:%u: %s\n", $fn, $., $_ ) if( $debug );
$$header = 1;
checkhost( $_, $header, $first, $fn, $. );
}
close( $fh );
} else {
die( sprintf( "open: %s: %s %s\n", $fn, $!, atloc( $at, $atl ) ) );
}
return;
}
# Run the checks on each argument - indirect, host, or file
sub checkhost {
my( $host, $header, $first, $at, $atl ) = @_;
return atfile( $host, $1, $header, $first, $at, $atl ) if( $host =~ /^@(.*)$/ );
my $text = '';
my( $port, $chain, $haskey );
if( $host =~ m,^[/.~], || $host =~ m,/, ) {
$port = 'FILE';
$host =~ s/:FILE$//;
( $chain, $haskey ) = readfile( $host, $header, $at, $atl );
return unless( $chain );
} elsif( ( my $name, $port, my $pn ) =
$host =~ m,^(\[[[:xdigit:]:]\]|.*?):(?:([[:digit:]]+)|([[:alnum:].*_-]+))$, )
{
if( $pn ) {
$port = getservbyname( $pn, 'tcp' );
if( $port ) {
$host = "$name:$port";
} elsif( $pn =~ /^FILE$/ ) {
$port = $pn;
( $chain, $haskey ) = readfile( $name, $header, $at, $atl );
return unless( $chain );
} else {
die( sprintf(
"\"%s\" is not a known port name for %s, specified %s, see /etc/services\n",
$pn, $name, atloc( $at, $atl ) ) );
}
}
} elsif( $starttls =~ /^-starttls (.*)$/ && ( $port = $starttls{$1} ) ) {
$host .= ":$port";
} else {
$port = 443;
$host .= ":$port";
}
if( $port ne 'FILE' ) {
if( ( my $prev = $hosts{$host} ) ) {
printf STDERR (
"Skipping duplicate host \"%s\" %s, previously specified %s\n", $host,
atloc( $at, $atl ), $prev
)
if( $warn );
$hosts{$host} = atloc( $at, $atl );
return;
}
$hosts{$host} = atloc( $at, $atl );
}
unless( defined $chain ) {
my $cmd =
"openssl s_client $CAcerts $starttls -showcerts $tlsver $type -connect $host";
printf STDERR ( ">> %s\n", $cmd ) if( $debug );
my( $cpid, $waitpid );
eval {
my( $saveout, $saveerr );
open( $saveout, ">&STDOUT" );
open( $saveerr, ">&STDERR" );
$chain = File::Temp->new( DIR => $tmpdir, TEMPLATE => "checkchain-XXXXXX",
SUFFIX => '.txt', UNLINK => 1 );
open( STDOUT, ">&" . fileno( $chain ) ) or die( "open1: $!\n" );
open( STDERR, ">&" . fileno( $chain ) ) or die( "open2: $!\n" );
local $SIG{ALRM} = sub { kill 'KILL', $cpid; die( "timeout!\n" ) };
#<<<
FORK:{
if( $cpid = fork ) {
close( STDOUT );
open( STDOUT, ">&" . fileno( $saveout ) );
close( $saveout );
close( STDERR );
open( STDERR, ">&" . fileno( $saveerr ) );
close( $saveerr );
last;
} elsif( defined $cpid ) {
close( STDIN );
open( STDIN, '<', '/dev/null' ) or die( "open3: $!\n" );
exec $cmd or die( "exec: $!\n" );
} elsif( $! == EAGAIN ) {
sleep 3;
redo FORK;
} else {
die( "Can't fork: $!\n" );
}
}
#>>>
alarm( $timeout );
( $waitpid = waitpid( $cpid, 0 ) ) == $cpid or die( "waitpid: $!\n" );
alarm( 0 );
};
alarm( 0 );
waitpid( $cpid, 0 ) if( $cpid && !$waitpid );
if( $@ ) {
undef $chain;
die( "$@" ) unless( $@ eq "timeout!\n" );
printf STDERR ( "Unable to connect to $host (timeout)\n" );
return;
} else {
seek( $chain, 0, SEEK_SET );
local $/;
$chain = <$chain>;
}
unless( defined $chain && length $chain ) {
printf STDERR ( "Unable to connect to $host\n" );
return;
}
if( $chain =~ /\balert handshake failure\b/ || $? ) {
if( $debug ) {
print STDERR ( $chain ) if( $chain );
if( $? ) {
if( $? == -1 ) {
printf STDERR ( "failed to execute %s: $!\n", $cmd );
} elsif( $? & 127 ) {
printf STDERR (
"%s died with signal %s (%d), %s coredump\n", $cmd,
( $signo[ $? & 127 ] || '??' ), ( $? & 127 ),
( $? & 128 ) ? 'with' : 'without' );
} else {
printf STDERR ( "%s exited with value %d\n", $cmd, $? >> 8 );
}
}
}
printf STDERR ( "TLS connection to %s was not successful\n", $host );
return;
}
return unless( $chain );
}
my @chain = $chain =~ /(^-{2,8}BEGIN (?:TRUSTED )?CERTIFICATE.*?^-{2,8}END.*?\n)/msg;
if( @chain ) {
my %cert;
my $now = time;
my $untrusted = '';
for( my $i = 0; $i < @chain; ++$i ) {
my $file = File::Temp->new(
DIR => $tmpdir, TEMPLATE => "checkchain-$i-XXXXXX",
SUFFIX => '.pem', UNLINK => 1 );
$cert{$i}{file} = $file;
print $file ( $chain[$i] );
$file->flush;
my $state = docmd(
"openssl ", "x509",
" -noout -text -in ", "$file\n" );
$cert{$i}{subject} = $1 if( $state =~ /^\s*Subject:\s*(.*?)$/m );
$cert{$i}{issuer} = $1 if( $state =~ /^\s*Issuer:\s*(.*?)$/m );
$cert{$i}{start} = str2time( $1, 'GMT' )
if( $state =~ /^\s*Not Before\s*:\s*(.*?)$/m );
$cert{$i}{end} = str2time( $1, 'GMT' )
if( $state =~ /^\s*Not After\s*:\s*(.*?)$/m );
$cert{$i}{key} = uc $1
if( $state =~
/^\s*Public Key Algorithm\s*:\s*(?:id-)?(.*?)(?:PublicKey|Encryption)?$/m
);
$cert{$i}{klen} = $1 if( $state =~ /^\s*(?:RSA )?Public-Key\s*:\s*(.*?)$/m );
$untrusted .= sprintf( " -untrusted %s", "$file" ) if( $i > 0 );
}
for( my $i = 0; $i < @chain; ++$i ) {
$text .= "\n" if( $i > 0 );
$text .= sprintf( "Contains private %s key\n\n", $haskey )
if( $i == 0 && $haskey );
$text .= sprintf(
"[%u] Subject: %s\n Issuer : %s\n", $i, $cert{$i}{subject},
$cert{$i}{issuer} );
$text .= sprintf( " Type : %s %s\n", $cert{$i}{key}, $cert{$i}{klen} );
if( $now < $cert{$i}{start} || $now > $cert{$i}{end} ) {
$text .= " Certificate is NOT valid at this time\n";
}
if( $now < $cert{$i}{start} ) {
$text .= sprintf(
" Certificate is not yet valid, will be %s\n",
pdelta( $cert{$i}{start}, $now ) );
} else {
$text .= sprintf(
" Certificate became valid %s\n",
pdelta( $cert{$i}{start}, $now ) );
}
if( $now > $cert{$i}{end} ) {
$text .= sprintf(
" Certificate expired %s\n",
pdelta( $cert{$i}{end}, $now ) );
} else {
$text .= sprintf(
" Certificate expires %s\n",
pdelta( $cert{$i}{end}, $now ) );
}
my $state = docmd(
"openssl ", "verify", " $CAcerts $untrusted ", $cert{$i}{file},
" 2>&1\n" );
chomp $state;
if( my( $subj, $err, $depth, $text ) =
$state =~
/\A(.*?)\nerror ([[:digit:]]+) at ([[:digit:]]+) depth lookup: (.*?)$/m )
{
if( $subj eq $cert{$i}{issuer} ) {
$state =
"Failed to verify issuer's certificate:\n $subj\n SSL error: $err : \"$text\" at depth $depth";
}
}
$state =~ s,$tmpdir/.*?\.pem: ,,g;
$state = "Verify result: " . $state;
$state =~ s/^/ /gm;
$text .= $state . "\n";
}
} else {
$text = $chain;
}
if( $$header ) {
$text =~ s/^/ /mg;
$header = '';
if( $$first ) {
$$first = 0;
} else {
$header = "\n";
}
$header .= sprintf( "%s\n%s\n", $host, '-' x length( $host ) );
$text = $header . $text;
}
print( $text );
}
# Main program - Process command line options
GetOptions(
"CAfile|C=s" => \$cafile,
"CApath|CAdir=s" => \$cadir,
"debug|d!" => \$debug,
"starttls|s=s" => \$starttls,
"timeout=i" => \$timeout,
"tlsversion|t=s" => \$tlsver,
"type|c=s" => \$type,
"warnings!" => \$warn,
'help|?|h' => \$help,
'man' => \$man,
'version' => \$version,
) or die( "Command line error, --help for usage\n" );
if( $help || $man ) {
eval {
no warnings 'once';
$Pod::Usage::Formatter = 'Pod::Text::Termcap';
require Pod::Usage;
} or
die( "Install Pod::Usage or use 'perldoc $0'\n" );
Pod::Usage::pod2usage( 1 ) if( $help );
Pod::Usage::pod2usage( -exitval => 0, -verbose => 2 ) if( $man );
}
if( $version ) {
printf( "%s version %s\n%s", basename( $0 ),
join( '-', ( $VERSION =~ /([[:xdigit:]]{4})/g )[ -4 .. -1 ] ), $copyright );
exit;
}
$warn = 1 unless( defined $warn );
# Default and/or convert option values for use
if( defined $cafile || defined $cadir ) {
$CAcerts = '';
$CAcerts .= " -CAfile $cafile"
if( defined $cafile );
$CAcerts .= " -CApath $cadir"
if( defined $cadir );
}
if( defined $starttls ) {
my $fullnm = $starttlsAbbrev{ lc $starttls };
die "Unsupported STARTTLS protocol: \"$starttls\"\n" unless( $fullnm );
$starttls = $fullnm;
$starttls = "-starttls $starttls";
} else {
$starttls = '';
}
if( defined $timeout ) {
$timeout = abs( $timeout ) || 2;
} else {
$timeout = 120;
}
if( defined $tlsver ) {
die "Unsupported TLS version\n" unless( ( $tlsver = $tlsver{$tlsver} ) );
} else {
$tlsver = '';
}
if( defined $type ) {
$type = lc $type;
my $cs;
if( $type =~ /^ec(?:dsa)?$/ ) {
$cs = 'ECDSA+SHA1:ECDSA+SHA224:ECDSA+SHA384:ECDSA+SHA256:ECDSA+SHA512';
} elsif( $type eq 'rsa' ) {
unless( defined $havepss ) {
my $pkalgs = docmd( 'openssl ', 'list -public-key-algorithms' );
$havepss = $pkalgs =~ /^\s*PEM\sstring:\s*RSA-PSS\b/m;
}
if( $tlsver =~ /1_[3-9]$/ ) {
die( sprintf( "TLS 1.3 doesn't support '%s' certificates\n", uc $type ) );
}
$cs =
$havepss
? 'RSA-PSS+SHA512:RSA-PSS+SHA384:RSA-PSS+SHA256:RSA+SHA512:RSA+SHA256:RSA+SHA384:RSA+SHA224:RSA+SHA1'
: 'RSA+SHA512:RSA+SHA256:RSA+SHA384:RSA+SHA224:RSA+SHA1';
}
$type = "-sigalgs '$cs'";
} else {
$type = '';
}
# Finally, process each command line argument (or complain if none)
unless( @ARGV >= 1 ) {
eval { require Pod::Usage; } or die( "See " . basename( $0 ) . " --help\n" );
Pod::Usage::pod2usage( 1 );
}
my $first = 1;
my $header = @ARGV > 1 || grep { /^@/ } @ARGV;
foreach my $host ( @ARGV ) {
checkhost( $host, \$header, \$first );
}
exit
__END__
=pod
=head1 SSL_CHECK_CHAIN
ssl_check_chain - check the certificate chain for hosts
=head1 SYNOPSIS
ssl_check_chain [options] [host[:port] ...] [file:FILE] [@file...]
Options:
--CAfile=file Specify bundle file of trusted CA certificates for verification
--CApath=dir Specify a hashed directory containing trusted CA certificates for verification.
--starttls=proto Specify that STARTTLS should be used in the connection.
--timeout=secs Specify timeout for TLS connections
--tlsversion=ver Specify the version TLS to connect with
--type=type Specify the certificate type desired from the server
--[no-]warnings Display or suppress warnings
--help brief help message
--man full documentation
=head1 OPTIONS
The short options take the same argument as the corresponding long options, and are provided
for compatibility with F<ssl_info>
=over 8
=item B<--CAfile>=I<file> B<-C>
Specify a file containing one or more trusted CA certificates to verify the host's certificate chain.
If not specified, the environment variables SSL_CERT_FILE and CURL_CA_BUNDLE will be tried, and if neither of them is set, OpenSSL's default will be used.
=item B<--CApath>=I<file> B<--CAdir>=I<file>
Specify a directory containing hashed links to one or more trusted CA certificates to verify the host's certificate chain.
If not specified, the environment variable SSL_CERT_DIR will be tried. If it is not set, OpenSSL's default will be used.
=item B<--starttls>=I<protocol> B<-s>
Specifies that STARTTLS is required to make the TLS connection.
I<protocol> is one of the following: "smtp", "pop3", "imap", "ftp", "xmpp",
"xmpp-server", "irc", "postgres", "mysql", "lmtp", "nntp", "sieve", or "ldap"
=item B<--timeout>=I<secs> I<@file>
Speciries the maximum amount of time that I<ssl_check_chain> will wait for a TLS connection.
The default is 120 seconds.
=item B<--tlsversion>=I<version>
Specify the TLS protocol version to use: 1.1, 1.2, or 1.3.
=item B<--type>=I<type> B<-c>
Specify that an I<ec> (I<ecdsa>) or I<rsa> certificate is desired.
=item B<--[no-]warnings>
Controls whether warning messages are displayed. The default is B<--warnings>.
Warnings include duplicated files and hosts, which are skipped, and other recoverable conditions.
=item B<--help>
Print a brief help message and exits.
=item B<--man>
Prints the manual page and exits.
=back
When options require keyword values, the keyword may be abbreviated providing that the abbreviation is unique.
=head1 DESCRIPTION
B<ssl_check_chain> will connect to each host specified and obtain its certificate and any intermediate certificate chain.
Port can be numeric, or a service name (e.g. from /etc/services).
If a port is not specified: if --starttls is specified, the default port for the STARTTLS protocol is used, otherwise 443 (https) is assumed.
If the port is specified as I<FILE>, B<ssl_check_chain> will open the specified file and process it as if the certificates were received from a server.
The certificate chain must be in PEM format. If a filename begins with '.', '/', or '~', or if it contains a '/', the I<:FILE> is inferred, since
no DNS hostname or IP address can have those forms.
If an argument is of the form I<@file>, the file is processed as a list of arguments, one per line, in any of the forms described previously.
I<@file>s can be nested, but attempting to process the same file more than once is an error. In an I<@file>, blank lines and lines beginning with I<#> are ignored.
I<FILE> and I<@file> names support tilde expansion, but not wildcards.
The validity dates of each certificate returned will be verified, as will its chain.
To request the desired certificate from dual-certificate servers, you can specify B<--type>=I<ec> or B<--type>=I<rsa>.
This is done by providing a list of acceptable signature algorithms; the connecion will fail if the server doesn't have a matching certificate.
You can also specify B<--tlsversion>=I<1.1>, B<--tlsversion>=I<1.2>, or B<--tlsversion>=I<1.3> to select the protocol version.
Each certificate is analyzed in the order received from the server or contained in the file, which should be from leaf (the server) toward the root (trusted CA).
The trust root is not sent by the server, but is located by OpenSSL via -CAfile or -CApath.
Any date or verification errors will be reported.
Note that if a trusted (root) certificate has expired, only the root name is available.
This automates the manual process of determining where and why a certificate chain is broken.
=head1 BUGS
Report any bugs, feature requests and/or patches on the issue tracker,
located at F<https://github.com/tlhackque/certtools/issues>. In the
event that the project moves, contact the author directly.
=head1 AUTHOR
Timothe Litt E<lt>litt@acm.orgE<gt>
=head1 COPYRIGHT and LICENSE
Copyright (c) 2021 Timothe Litt
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of the author shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from the author.
Any modifications to this software must be clearly documented by and
attributed to their author, who is responsible for their effects.
Bug reports, suggestions and patches are welcomed by the original author.
=head1 SEE ALSO
I<openssl(1)> I<ssl_info>
I<POD version $Id$>
=cut