blib/lib/Langertha/Holmgang/Sim/Linux/Pki.pm

filter: Statementstmt 84.4% 528 / 625 Branchbran 51.7% 212 / 410 Conditioncond 38.4% 131 / 341 MC/DCmcdc 8.2% 15 / 181 Subroutinesub 89.4% 51 / 57 Podpod 100% 13 / 13 totaltotal 58.3% 950 / 1627 CC 366 SCAR 52.1
CC
366
Cov
63%
_x509
684.5
_s_client
530.5
_x509_text
132.0
CRAP 183.8
« blib/lib/Langertha/Holmgang/ToolSchema.pm ↑ Summary blib/lib/Langertha/Holmgang/Shell/Filter.pm »
1 package Langertha::Holmgang::Sim::Linux::Pki;
2 # ABSTRACT: Certificates and keys as data: openssl, update-ca-certificates, verification in the client
3  
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Digest::SHA ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use MIME::Base64 ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Time::Local ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 our $VERSION = '0.001';
14  
15  
16 4 my $JSON = JSON::MaybeXS->new( utf8 => 1, canonical => 1 );
17  
18 0 ▶sub _L { require Langertha::Holmgang::Sim::Linux; return 'Langertha::Holmgang::Sim::Linux' }
Subroutine _L: not called CC=1 SCAR=6.9
19 57 ▶sub _text { my ( $dev, $p ) = @_; return Langertha::Holmgang::Sim::Linux::_file_text( $dev, $p ) }
Subroutine _text: called CC=1 SCAR=0.0
20  
21 0 ▶sub _gap { _L(); no warnings 'once'; push @Langertha::Holmgang::Sim::Linux::GAPS, join ' ', @_; return ( '', 0 ) }
Subroutine BEGIN: called CC=1 SCAR=1.2
Subroutine _gap: not called CC=1 SCAR=1.2
22  
23 # --- PEM ------------------------------------------------------------------------
24  
25 4 my %LABEL = ( cert => 'CERTIFICATE', key => 'PRIVATE KEY', enckey => 'ENCRYPTED PRIVATE KEY',
26 csr => 'CERTIFICATE REQUEST', pub => 'PUBLIC KEY', p7 => 'PKCS7' );
27  
28  
29 17 ▶sub pem {
Subroutine pem: called CC=2 SCAR=6.9
Pod documented
30 17 my ( $kind, $id ) = @_;
31 17 ▶ my $tag = $kind eq 'enckey' ? 'key' : $kind;
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'enckey' ? : 1 16 17
32 17 my $b = MIME::Base64::encode_base64( "cai-sim-$tag:$id", '' );
33 17 $b =~ s/(.{64})/$1\n/g;
34 17 $b =~ s/\n\z//;
35 17 return "-----BEGIN $LABEL{$kind}-----\n$b\n-----END $LABEL{$kind}-----\n";
36 }
37  
38  
39 57 ▶sub blocks {
Subroutine blocks: called CC=7 SCAR=19.8
Pod documented
40 57 my ($t) = @_;
41 57 my @b;
42 57 ▶ while ( ( $t // '' ) =~ /-----BEGIN ([A-Z0-9 ]+)-----\s*\n(.*?)\n?-----END \1-----/sg ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($t // "") =~ /-----BEGIN ([A-Z0-9 ]+)-----\s*\n(.*?)\n?-----END \1-----/gs) 64 57 121
Condition50%1/2
$t // ""
l!l
1210
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
43 64 my ( $label, $body ) = ( $1, $2 );
44 64 my %rev = reverse %LABEL;
45 64 ▶ my $kind = $rev{$label} // 'other';
Condition50%1/2
$rev{$label} // "other"
l!l
640
MC/DC0%0/1
$rev{$label} // "other"
$rev{$label}
Truth table50%1/2
A
A= $rev{$label}
Aresult
11
00
46 64 ( my $b64 = $body ) =~ s/\s+//g;
47 64 my $raw = MIME::Base64::decode_base64($b64);
48 64 my $block = "-----BEGIN $label-----\n$body\n-----END $label-----\n";
49 64 ▶ if ( $raw =~ /\Acai-sim-(cert|key|csr|pub|p7):(.+)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raw =~ /\Acai-sim-(cert|key|csr|pub|p7):(.+)\z/s) 64 0 64
50 64 my ( $tag, $id ) = ( $1, $2 );
51 64 ▶ my $want = $kind eq 'enckey' ? 'key' : $kind;
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'enckey' ? : 6 58 64
52 64 ▶ if ( $tag eq $want ) { push @b, { kind => $kind, id => $id, text => $block }; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq $want) 64 0 64
53 }
54 0 push @b, { kind => 'bad', label => $label, text => $block };
55 }
56 57 return @b;
57 }
58  
59 # --- Katalog --------------------------------------------------------------------
60  
61  
62 340 ▶sub catalog {
Subroutine catalog: called CC=9 SCAR=22.0
Pod documented
63 340 my ($state) = @_;
64 340 my %c = ( certs => {}, keys => {}, now => undef );
65 340 ▶ for my $h ( sort keys %{ $state || {} } ) {
Condition50%1/2
$state || {}
l!l
3400
MC/DC0%0/1
$state || {}
$state
Truth table50%1/2
A
A= $state
Aresult
11
00
66 878 ▶ my $p = ref $state->{$h} eq 'HASH' ? $state->{$h}{pki} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $$state{$h} eq 'HASH' ? : 878 0 878
67 878 ▶ next unless ref $p eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $p eq "HASH" 594 284 878
68 284 ▶ %{ $c{certs} } = ( %{ $c{certs} }, %{ $p->{certs} || {} } );
Condition100%2/2
$$p{'certs'} || {}
l!l
142142
MC/DC100%1/1
$$p{'certs'} || {}
$$p{'certs'}
Truth table100%2/2
A
A= $$p{'certs'}
Aresult
11
00
69 284 ▶ %{ $c{keys} } = ( %{ $c{keys} }, %{ $p->{keys} || {} } );
Condition100%2/2
$$p{'keys'} || {}
l!l
142142
MC/DC100%1/1
$$p{'keys'} || {}
$$p{'keys'}
Truth table100%2/2
A
A= $$p{'keys'}
Aresult
11
00
70 284 ▶ $c{now} //= $p->{now};
Condition66%2/3
$c{"now"} //= $$p{"now"}
l!l&&r!l&&!r
0142142
MC/DC50%1/2
$c{"now"} //= $$p{"now"}
$c{"now"} $$p{"now"}
Truth table66%2/3
A //= B
A= $c{"now"}B= $$p{"now"}
ABresult
1X1
011
000
71 }
72 340 ▶ $c{now} //= '2026-10-24T08:00:00Z';
Condition100%2/2
$c{"now"} //= "2026-10-24T08:00:00Z"
l!l
142198
MC/DC100%1/1
$c{"now"} //= "2026-10-24T08:00:00Z"
$c{"now"}
Truth table100%2/2
A
A= $c{"now"}
Aresult
11
00
73 340 return \%c;
74 }
75  
76 315 ▶sub _epoch {
Subroutine _epoch: called CC=6 SCAR=20.9
77 315 my ($t) = @_;
78 315 ▶ my ( $y, $m, $d, $H, $M, $S ) = ( $t // '' ) =~ /\A(\d{4})-(\d\d)-(\d\d)(?:[T ](\d\d):(\d\d)(?::(\d\d))?)?/ or return 0;
Branch: 1 branch
BranchTrueFalseTotal
() = ($t // "") =~ /\A(\d{4})-(\d\d)-(\d\d)(?:[T ](\d\d):(\d\d)(?::(\d\d))?)?/ or return 0 315 0 315
Condition50%1/2
$t // ""
l!l
3150
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
79 315 ▶ return Time::Local::timegm( $S // 0, $M // 0, $H // 0, $d, $m - 1, $y );
Condition50%3/6
$S // 0
l!l
3150
$M // 0
l!l
3150
$H // 0
l!l
3150
MC/DC0%0/1
$S // 0
$S
MC/DC0%0/1
$M // 0
$M
MC/DC0%0/1
$H // 0
$H
Truth table50%1/2
A
A= $S
Aresult
11
00
Truth table50%1/2
A
A= $M
Aresult
11
00
Truth table50%1/2
A
A= $H
Aresult
11
00
80 }
81  
82 4 my @MON = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
83  
84 78 ▶sub _odate {
Subroutine _odate: called CC=1 SCAR=0.0
85 78 my ($t) = @_;
86 78 my @g = gmtime( _epoch($t) );
87 78 return sprintf( '%s %2d %02d:%02d:%02d %d GMT', $MON[ $g[4] ], $g[3], $g[2], $g[1], $g[0], $g[5] + 1900 );
88 }
89  
90 2 ▶sub _iso { my ($e) = @_; my @g = gmtime($e); return sprintf( '%04d-%02d-%02dT%02d:%02d:%02dZ', $g[5] + 1900, $g[4] + 1, @g[ 3, 2, 1, 0 ] ) }
Subroutine _iso: called CC=1 SCAR=0.0
91  
92  
93 18 ▶sub dn {
Subroutine dn: called CC=3 SCAR=11.3
Pod documented
94 18 my ($s) = @_;
95 18 ▶ return join ', ', map { my ( $k, $v ) = split /\s*=\s*/, $_, 2; "$k = " . ( $v // '' ) } grep {length} split /\s*,\s*(?=[A-Za-z]+\s*=)/, $s // '';
Condition50%2/4
$v // ""
l!l
400
$s // ""
l!l
180
MC/DC0%0/1
$v // ""
$v
MC/DC0%0/1
$s // ""
$s
Truth table50%1/2
A
A= $v
Aresult
11
00
Truth table50%1/2
A
A= $s
Aresult
11
00
96 }
97  
98 0 ▶sub _cn { my ($s) = @_; return ( $s // '' ) =~ /(?:\A|,)\s*CN\s*=\s*([^,]+)/ ? $1 : undef }
Subroutine _cn: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
($s // '') =~ /(?:\A|,)\s*CN\s*=\s*([^,]+)/ ? : 0 0 0
Condition0%0/2
$s // ""
l!l
00
MC/DC0%0/1
$s // ""
$s
Truth table0%0/2
A
A= $s
Aresult
11
00
99  
100 4 ▶sub _hex { my ( $id, $n, $sep ) = @_; my $h = uc Digest::SHA::sha512_hex("cai-sim:$id"); $h = substr( $h x 4, 0, $n ); return $sep ? join( ':', $h =~ /(..)/g ) : $h }
Subroutine _hex: called CC=2 SCAR=7.0
Branch: 1 branch
BranchTrueFalseTotal
$sep ? : 0 4 4
101  
102  
103 4 ▶sub modulus { my ($key) = @_; return _hex( "mod:$key", 256 ) }
Subroutine modulus: called CC=1 SCAR=0.0
Pod documented
104  
105 # --- Pruefung -------------------------------------------------------------------
106  
107 4 our %ERR = (
108 2 => 'unable to get issuer certificate', 9 => 'certificate is not yet valid', 10 => 'certificate has expired', 18 => 'self-signed certificate',
109 19 => 'self-signed certificate in certificate chain', 20 => 'unable to get local issuer certificate',
110 21 => 'unable to verify the first certificate', 24 => 'invalid CA certificate',
111 );
112  
113  
114 36 ▶sub verify_chain {
Subroutine verify_chain: called CC=19 SCAR=32.5
Pod documented
115 36 my ( $cat, $leaf, $inter, $trust ) = @_;
116 36 my $now = _epoch( $cat->{now} );
117 36 ▶ my %trust = map { $_ => 1 } @{ $trust || [] };
Condition50%1/2
$trust || []
l!l
360
MC/DC0%0/1
$trust || []
$trust
Truth table50%1/2
A
A= $trust
Aresult
11
00
118 36 ▶ my %inter = map { $_ => 1 } @{ $inter || [] };
Condition50%1/2
$inter || []
l!l
360
MC/DC0%0/1
$inter || []
$inter
Truth table50%1/2
A
A= $inter
Aresult
11
00
119 36 my ( $cur, $depth, $from_trust, %seen ) = ( $leaf, 0, 0 );
120 36 while (1) {
121 50 ▶ my $c = $cat->{certs}{$cur} or return { code => 20, depth => $depth, cert => $cur };
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$cat{"certs"}{$cur} or return {"code", 20, "depth", $depth, "cert", $cur} 50 0 50
122 50 ▶ return { code => 10, depth => $depth, cert => $cur } if _epoch( $c->{not_after} ) && $now > _epoch( $c->{not_after} );
Branch: 1 branch
BranchTrueFalseTotal
if _epoch($$c{"not_after"}) and $now > _epoch($$c{"not_after"}) 1 49 50
Condition66%2/3
_epoch($$c{"not_after"}) and $now > _epoch($$c{"not_after"})
!ll&&!rl&&r
0491
MC/DC50%1/2
_epoch($$c{"not_after"}) and $now > _epoch($$c{"not_after"})
_epoch($$c{"not_after"}) $now > _epoch($$c{"not_after"})
Truth table66%2/3
A and B
A= _epoch($$c{"not_after"})B= $now > _epoch($$c{"not_after"})
ABresult
0X0
100
111
123 49 ▶ return { code => 9, depth => $depth, cert => $cur } if _epoch( $c->{not_before} ) && $now < _epoch( $c->{not_before} );
Branch: 1 branch
BranchTrueFalseTotal
if _epoch($$c{"not_before"}) and $now < _epoch($$c{"not_before"}) 0 49 49
Condition33%1/3
_epoch($$c{"not_before"}) and $now < _epoch($$c{"not_before"})
!ll&&!rl&&r
0490
MC/DC0%0/2
_epoch($$c{"not_before"}) and $now < _epoch($$c{"not_before"})
_epoch($$c{"not_before"}) $now < _epoch($$c{"not_before"})
Truth table33%1/3
A and B
A= _epoch($$c{"not_before"})B= $now < _epoch($$c{"not_before"})
ABresult
0X0
100
111
124 49 ▶ my $iss = $c->{issuer} // $cur;
Condition33%1/3
$$c{"issuer"} // $cur
l!l&&r!l&&!r
4900
MC/DC0%0/2
$$c{"issuer"} // $cur
$$c{"issuer"} $cur
Truth table33%1/3
A // B
A= $$c{"issuer"}B= $cur
ABresult
1X1
011
000
125 49 ▶ if ( $iss eq $cur ) { # selbst signiert: Anker nur, wenn vertraut
Branch: 1 branch
BranchTrueFalseTotal
if ($iss eq $cur) 8 41 49
126 8 ▶ return undef if $trust{$cur};
Branch: 1 branch
BranchTrueFalseTotal
if $trust{$cur} 8 0 8
127 0 ▶ return { code => $depth ? 19 : 18, depth => $depth, cert => $cur };
Branch: 1 branch
BranchTrueFalseTotal
$depth ? : 0 0 0
128 }
129 41 ▶ my $have = $trust{$iss} || $inter{$iss};
Condition100%3/3
$trust{$iss} || $inter{$iss}
l!l&&r!l&&!r
9527
MC/DC100%2/2
$trust{$iss} || $inter{$iss}
$trust{$iss} $inter{$iss}
Truth table100%3/3
A || B
A= $trust{$iss}B= $inter{$iss}
ABresult
1X1
011
000
130 41 ▶ return { code => $from_trust ? 2 : 20, depth => $depth, cert => $cur } unless $have && !$seen{$iss}++;
Branch: 2 branches
BranchTrueFalseTotal
unless $have and not $seen{$iss}++ 27 14 41
$from_trust ? : 1 26 27
Condition66%2/3
$have and not $seen{$iss}++
!ll&&!rl&&r
27014
MC/DC50%1/2
$have and not $seen{$iss}++
$have not $seen{$iss}++
Truth table66%2/3
A and not(B)
A= $haveB= not $seen{$iss}++
ABresult
0X0
100
111
131 14 my $ic = $cat->{certs}{$iss};
132 14 ▶ return { code => 24, depth => $depth + 1, cert => $iss } if $ic && !$ic->{ca};
Branch: 1 branch
BranchTrueFalseTotal
if $ic and not $$ic{"ca"} 0 14 14
Condition33%1/3
$ic and not $$ic{"ca"}
!ll&&!rl&&r
0140
MC/DC0%0/2
$ic and not $$ic{"ca"}
$ic not $$ic{"ca"}
Truth table33%1/3
A and not(B)
A= $icB= not $$ic{"ca"}
ABresult
0X0
100
111
133 14 ▶ ( $cur, $depth, $from_trust ) = ( $iss, $depth + 1, $trust{$iss} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$trust{$iss} ? : 9 5 14
134 }
135 }
136  
137  
138 7 ▶sub name_matches {
Subroutine name_matches: called CC=7 SCAR=22.0
Pod documented
139 7 my ( $c, $name ) = @_;
140 7 $name = lc $name;
141 7 ▶ my @n = @{ $c->{sans} || [] };
Condition50%1/2
$$c{'sans'} || []
l!l
70
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table50%1/2
A
A= $$c{'sans'}
Aresult
11
00
142 0 ▶ @n = grep {defined} _cn( $c->{subject} ) unless @n;
Branch: 1 branch
BranchTrueFalseTotal
unless @n 0 7 7
143 7 for my $s (@n) {
144 7 ( my $x = lc $s ) =~ s/\A(?:DNS|IP(?: Address)?):\s*//i;
145 7 ▶ return 1 if $x eq $name;
Branch: 1 branch
BranchTrueFalseTotal
if $x eq $name 6 1 7
146 0 ▶ if ( $x =~ /\A\*\.(.+)\z/ ) { my $d = $1; return 1 if $name =~ /\A[^.]+\.\Q$d\E\z/ }
Branch: 2 branches
BranchTrueFalseTotal
if ($x =~ /\A\*\.(.+)\z/) 0 1 1
if $name =~ /\A[^.]+\.\Q$d\E\z/ 0 0 0
147 }
148 1 return 0;
149 }
150  
151  
152 # Vertrauensspeicher eines Geraets (Client): trusted + installed, dazu von Hand
153 # an das Buendel /etc/ssl/certs/ca-certificates.crt Angehaengtes (wie echt,
154 # bis zum naechsten update-ca-certificates)
155 36 ▶sub trust_of {
Subroutine trust_of: called CC=5 SCAR=16.2
Pod documented
156 36 my ($dev) = @_;
157 36 ▶ my $p = ref $dev->{pki} eq 'HASH' ? $dev->{pki} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $$dev{'pki'} eq 'HASH' ? : 36 0 36
158 36 my $b = _text( $dev, '/etc/ssl/certs/ca-certificates.crt' );
159 36 ▶ return [ @{ $p->{trusted} || [] }, @{ $p->{installed} || [] }, defined $b ? _cert_ids($b) : () ];
Branch: 1 branch
BranchTrueFalseTotal
defined $b ? : 0 36 36
Condition100%4/4
$$p{'trusted'} || []
l!l
351
$$p{'installed'} || []
l!l
432
MC/DC100%1/1
$$p{'trusted'} || []
$$p{'trusted'}
MC/DC100%1/1
$$p{'installed'} || []
$$p{'installed'}
Truth table100%2/2
A
A= $$p{'trusted'}
Aresult
11
00
Truth table100%2/2
A
A= $$p{'installed'}
Aresult
11
00
160 }
161  
162 6 ▶sub _cert_ids { my ($t) = @_; return map { $_->{id} } grep { $_->{kind} eq 'cert' } blocks($t) }
Subroutine _cert_ids: called CC=1 SCAR=0.0
163  
164  
165 34 ▶sub client_verify {
Subroutine client_verify: called CC=10 SCAR=23.5
Pod documented
166 34 my ( $state, $from, $tls, $req ) = @_;
167 34 my $cat = catalog($state);
168 34 ▶ my $dev = $state->{$from} || {};
Condition50%1/2
$$state{$from} || {}
l!l
340
MC/DC0%0/1
$$state{$from} || {}
$$state{$from}
Truth table50%1/2
A
A= $$state{$from}
Aresult
11
00
169 34 ▶ my @chain = @{ $tls->{chain} || [] };
Condition50%1/2
$$tls{'chain'} || []
l!l
340
MC/DC0%0/1
$$tls{'chain'} || []
$$tls{'chain'}
Truth table50%1/2
A
A= $$tls{'chain'}
Aresult
11
00
170 34 ▶ return [ 35, '(35) OpenSSL/3.0.15: error:0A000410:SSL routines::sslv3 alert handshake failure' ] unless @chain;
Branch: 1 branch
BranchTrueFalseTotal
unless @chain 0 34 34
171 34 my $trust = trust_of($dev);
172 34 ▶ if ( defined $req->{cacert} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$req{"cacert"}) 1 33 34
173 1 my $t = _text( $dev, $req->{cacert} );
174 1 ▶ return [ 77, "(77) error setting certificate file: $req->{cacert}" ] unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
175 1 $trust = [ _cert_ids($t) ];
176 }
177 34 ▶ if ( my $e = verify_chain( $cat, $chain[0], [ @chain[ 1 .. $#chain ] ], $trust ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $e = verify_chain($cat, $chain[0], [@chain[1 .. $#chain]], $trust)) 27 7 34
178 27 return [ 60, "(60) SSL certificate problem: $ERR{ $e->{code} }" ];
179 }
180 7 ▶ my $host = $req->{host} // '';
Condition50%1/2
$$req{"host"} // ""
l!l
70
MC/DC0%0/1
$$req{"host"} // ""
$$req{"host"}
Truth table50%1/2
A
A= $$req{"host"}
Aresult
11
00
181 7 ▶ my $leaf = $cat->{certs}{ $chain[0] } || {};
Condition50%1/2
$$cat{'certs'}{$chain[0]} || {}
l!l
70
MC/DC0%0/1
$$cat{'certs'}{$chain[0]} || {}
$$cat{'certs'}{$chain[0]}
Truth table50%1/2
A
A= $$cat{'certs'}{$chain[0]}
Aresult
11
00
182 7 ▶ return [ 60, "(60) SSL: no alternative certificate subject name matches target host name '$host'" ]
Branch: 1 branch
BranchTrueFalseTotal
unless name_matches($leaf, $host) 1 6 7
183 unless name_matches( $leaf, $host );
184 6 return undef;
185 }
186  
187  
188 36 ▶sub tls_lines {
Subroutine tls_lines: called CC=10 SCAR=28.5
Pod documented
189 36 my ( $state, $tls ) = @_;
190 36 my $cat = catalog($state);
191 36 ▶ my $c = $cat->{certs}{ ( $tls->{chain} || [] )->[0] // '' } or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$cat{"certs"}{($$tls{"chain"} || [])->[0] // ""} or return () 36 0 36
Condition50%2/4
($$tls{"chain"} || [])->[0] // ""
l!l
360
$$tls{'chain'} || []
l!l
360
MC/DC0%0/1
($$tls{"chain"} || [])->[0] // ""
$$tls{'chain'}
Truth table50%1/2
A
A= $$tls{'chain'}
Aresult
11
00
192 return ( "* SSL connection using $tls->{protocol} / " . ( $tls->{protocol} eq 'TLSv1.3' ? 'TLS_AES_256_GCM_SHA384' : 'ECDHE-RSA-AES256-GCM-SHA384' ),
193 '* Server certificate:', '* subject: ' . ( $c->{subject} // '' ) =~ s/,\s*/; /gr,
194 '* start date: ' . _odate( $c->{not_before} ), '* expire date: ' . _odate( $c->{not_after} ),
195 36 ▶ '* subjectAltName: ' . join( ', ', @{ $c->{sans} || [] } ),
Condition44%4/9
$$c{'sans'} || []
l!l
360
($$cat{"certs"}{$$c{"issuer"} // ""}{"subject"} // $$c{"issuer"}) // ""
l!l
360
$$cat{"certs"}{$$c{"issuer"} // ""}{"subject"} // $$c{"issuer"}
l!l&&r!l&&!r
3600
$$c{"issuer"} // ""
l!l
360
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
MC/DC0%0/2
($$cat{"certs"}{$$c{"issuer"} // ""}{"subject"} // $$c{"issuer"}) // ""
$$cat{"certs"}{$$c{"issuer"} // ""}{"subject"} $$c{"issuer"}
MC/DC0%0/1
$$c{"issuer"} // ""
$$c{"issuer"}
Truth table50%1/2
A
A= $$c{'sans'}
Aresult
11
00
Truth table33%1/3
A // B
A= $$cat{"certs"}{$$c{"issuer"} // ""}{"subject"}B= $$c{"issuer"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$c{"issuer"}
Aresult
11
00
196 36 ▶ '* issuer: ' . ( $cat->{certs}{ $c->{issuer} // '' }{subject} // $c->{issuer} // '' ) =~ s/,\s*/; /gr );
Branch: 1 branch
BranchTrueFalseTotal
$$tls{'protocol'} eq 'TLSv1.3' ? : 36 0 36
Condition50%1/2
$$c{"subject"} // ""
l!l
360
MC/DC0%0/1
$$c{"subject"} // ""
$$c{"subject"}
Truth table50%1/2
A
A= $$c{"subject"}
Aresult
11
00
197 }
198  
199 # --- openssl --------------------------------------------------------------------
200  
201 19 ▶sub _opts {
Subroutine _opts: called CC=8 SCAR=20.9
202 19 my ( $av, %spec ) = @_; # spec: name => 1 (Wert folgt) | 0 (Schalter)
203 19 my ( %o, @rest );
204 19 my @a = @$av;
205 19 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 61 19 80
206 61 my $x = shift @a;
207 61 ▶ if ( $x =~ /\A--?([\w.:-]+)\z/ && exists $spec{$1} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A--?([\w.:-]+)\z/ and exists $spec{$1}) 60 1 61
Condition66%2/3
$x =~ /\A--?([\w.:-]+)\z/ and exists $spec{$1}
!ll&&!rl&&r
1060
MC/DC50%1/2
$x =~ /\A--?([\w.:-]+)\z/ and exists $spec{$1}
$x =~ /\A--?([\w.:-]+)\z/ exists $spec{$1}
Truth table66%2/3
A and B
A= $x =~ /\A--?([\w.:-]+)\z/B= exists $spec{$1}
ABresult
0X0
100
111
208 60 my $k = $1;
209 60 ▶ if ( $spec{$k} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($spec{$k}) { } 33 27 60
210 33 ▶ return ( undef, "$k: Option requires an argument" ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 33 33
211 33 my $v = shift @a;
212 33 ▶ if ( $spec{$k} == 2 ) { push @{ $o{$k} }, $v }
Branch: 1 branch
BranchTrueFalseTotal
if ($spec{$k} == 2) { } 2 31 33
213 31 else { $o{$k} = $v }
214 }
215 27 else { $o{$k} = 1; push @{ $o{_order} }, $k }
216 60 next;
217 }
218 0 ▶ if ( $x =~ /\A-/ ) { return ( undef, "Unknown option or message digest: " . substr( $x, 1 ) ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($x =~ /\A-/) 0 1 1
219 1 push @rest, $x;
220 }
221 19 $o{_rest} = \@rest;
222 19 return ( \%o );
223 }
224  
225 0 ▶sub _usage { my ( $cmd, $msg ) = @_; return ( "$cmd: $msg\n$cmd: Use -help for summary.", 0 ) }
Subroutine _usage: not called CC=1 SCAR=6.9
226  
227  
228 21 ▶sub openssl {
Subroutine openssl: called CC=5 SCAR=18.4
Pod documented
229 21 my ( $dev, $av, $ctx, $stdin ) = @_;
230 21 my @a = @$av;
231 21 ▶ my $sub = shift(@a) // return _gap('openssl (interaktiv)');
Condition50%1/2
shift @a // (return _gap("openssl (interaktiv)"))
l!l
210
MC/DC0%0/1
shift @a // (return _gap("openssl (interaktiv)"))
shift @a
Truth table50%1/2
A
A= shift @a
Aresult
11
00
232 21 ▶ my $state = $ctx->{state} || { $ctx->{host} => $dev };
Condition50%1/2
$$ctx{'state'} || {$$ctx{'host'}, $dev}
l!l
210
MC/DC0%0/1
$$ctx{'state'} || {$$ctx{'host'}, $dev}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
Aresult
11
00
233 my %f = (
234 x509 => \&_x509, rsa => \&_pkey, pkey => \&_pkey, verify => \&_verify, s_client => \&_s_client,
235 crl2pkcs7 => \&_crl2pkcs7, pkcs7 => \&_pkcs7, req => \&_req, dgst => \&_dgst, sha256 => \&_dgst,
236 0 ▶ sha1 => \&_dgst, md5 => \&_dgst, version => sub { ( 'OpenSSL 3.0.15 3 Sep 2024 (Library: OpenSSL 3.0.15 3 Sep 2024)', 1 ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
237 21 );
238 21 ▶ my $fn = $f{$sub} or return $sub =~ /\A(?:genrsa|genpkey|ecparam|pkcs12|ca|x509v3|storeutl|ocsp|rand|enc|base64|list|s_server|speed)\z/
Branch: 2 branches
BranchTrueFalseTotal
my $fn = $f{$sub} or return $sub =~ /\A(?:genrsa|genpkey|ecparam|pkcs12|ca|x509v3|storeutl|ocsp|rand|enc|base64|list|s_server|speed)\z/ ? _gap("openssl", $sub, @a) : (qq[Invalid command '${sub}'; type "help" for a list.], 0) 21 0 21
$sub =~ /\A(?:genrsa|genpkey|ecparam|pkcs12|ca|x509v3|storeutl|ocsp|rand|enc|base64|list|s_server|speed)\z/ ? : 0 0 0
239 ? _gap( 'openssl', $sub, @a )
240 : ( "Invalid command '$sub'; type \"help\" for a list.", 0 );
241 21 return $fn->( $dev, \@a, $ctx, $stdin, $state, $sub );
242 }
243  
244 13 ▶sub _read_in {
Subroutine _read_in: called CC=4 SCAR=14.0
245 13 my ( $dev, $o, $stdin, $what ) = @_;
246 13 ▶ if ( defined $o->{in} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"in"}) 12 1 13
247 12 my $t = _text( $dev, $o->{in} );
248 12 ▶ return ( undef, "Could not open file or uri for loading $what from $o->{in}: No such file or directory" ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 12 12
249 12 return ($t);
250 }
251 1 ▶ return ( $stdin // '' );
Condition50%1/2
$stdin // ""
l!l
10
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
252 }
253  
254 6 ▶sub _x509 {
Subroutine _x509: called CC=55 SCAR=65.3
255 6 my ( $dev, $av, $ctx, $stdin, $state ) = @_;
256 6 my ( $o, $e ) = _opts( $av, in => 1, inform => 1, outform => 1, out => 1, checkend => 1, ext => 1, noout => 0, subject => 0,
257 issuer => 0, dates => 0, startdate => 0, enddate => 0, serial => 0, fingerprint => 0, sha256 => 0, sha1 => 0,
258 md5 => 0, text => 0, modulus => 0, pubkey => 0, subject_hash => 0, issuer_hash => 0, nameopt => 1, purpose => 0,
259 email => 0, hash => 0, ocsp_uri => 0 );
260 6 ▶ return _usage( 'x509', $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 6 6
261 6 my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'certificate' );
262 6 ▶ return ( $err, 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 6 6
263 6 ▶ my ($b) = grep { $_->{kind} eq 'cert' || $_->{kind} eq 'bad' } blocks($t);
Condition33%1/3
$$_{'kind'} eq 'cert' || $$_{'kind'} eq 'bad'
l!l&&r!l&&!r
600
MC/DC0%0/2
$$_{'kind'} eq 'cert' || $$_{'kind'} eq 'bad'
$$_{'kind'} eq 'cert' $$_{'kind'} eq 'bad'
Truth table33%1/3
A || B
A= $$_{'kind'} eq 'cert'B= $$_{'kind'} eq 'bad'
ABresult
1X1
011
000
264 6 my $cat = catalog($state);
265 6 ▶ my $c = $b && $b->{kind} eq 'cert' ? $cat->{certs}{ $b->{id} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$b && $$b{'kind'} eq 'cert' ? : 6 0 6
Condition33%1/3
$b and $$b{"kind"} eq "cert"
!ll&&!rl&&r
006
MC/DC0%0/2
$b and $$b{"kind"} eq "cert"
$b $$b{"kind"} eq "cert"
Truth table33%1/3
A and B
A= $bB= $$b{"kind"} eq "cert"
ABresult
0X0
100
111
266 6 ▶ return ( 'Could not read certificate from ' . ( $o->{in} // '<stdin>' ) . "\nUnable to load certificate", 0 ) unless $c;
Branch: 1 branch
BranchTrueFalseTotal
unless $c 0 6 6
Condition0%0/2
$$o{"in"} // "<stdin>"
l!l
00
MC/DC0%0/1
$$o{"in"} // "<stdin>"
$$o{"in"}
Truth table0%0/2
A
A= $$o{"in"}
Aresult
11
00
267 6 my $id = $b->{id};
268 6 my @out;
269 6 ▶ my $alg = $o->{sha256} ? 'sha256' : $o->{md5} ? 'md5' : 'sha1';
Branch: 2 branches
BranchTrueFalseTotal
$$o{'sha256'} ? : 0 6 6
$$o{'md5'} ? : 0 6 6
270 6 ▶ for my $k ( @{ $o->{_order} || [] } ) {
Condition50%1/2
$$o{'_order'} || []
l!l
60
MC/DC0%0/1
$$o{'_order'} || []
$$o{'_order'}
Truth table50%1/2
A
A= $$o{'_order'}
Aresult
11
00
271 13 ▶ if ( $k eq 'subject' ) { push @out, 'subject=' . dn( $c->{subject} ) }
Branch: 14 branches
BranchTrueFalseTotal
if ($k eq 'subject') { } 2 11 13
elsif ($k eq 'issuer') { } 1 10 11
elsif ($k eq 'dates') { } 0 10 10
elsif ($k eq 'startdate') { } 0 10 10
elsif ($k eq 'enddate') { } 2 8 10
elsif ($k eq 'serial') { } 0 8 8
elsif ($k eq 'fingerprint') { } 0 8 8
elsif ($k eq 'modulus') { } 2 6 8
elsif ($k eq 'pubkey') { } 0 6 6
elsif ($k eq 'subject_hash' or $k eq 'hash') { } 0 6 6
elsif ($k eq 'issuer_hash') { } 0 6 6
elsif ($k eq 'text') { } 0 6 6
elsif ($k eq 'purpose') { } 0 6 6
elsif ($k eq 'ocsp_uri') { } 0 6 6
272 1 ▶ elsif ( $k eq 'issuer' ) { push @out, 'issuer=' . dn( ( $cat->{certs}{ $c->{issuer} // '' } || $c )->{subject} ) }
Condition40%2/5
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
l!l&&r!l&&!r
100
$$c{"issuer"} // ""
l!l
10
MC/DC0%0/2
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
$$cat{'certs'}{$$c{'issuer'} // ''} $c
MC/DC0%0/1
$$c{"issuer"} // ""
$$c{"issuer"}
Truth table33%1/3
A || B
A= $$cat{'certs'}{$$c{'issuer'} // ''}B= $c
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$c{"issuer"}
Aresult
11
00
273 0 elsif ( $k eq 'dates' ) { push @out, 'notBefore=' . _odate( $c->{not_before} ), 'notAfter=' . _odate( $c->{not_after} ) }
274 0 elsif ( $k eq 'startdate' ) { push @out, 'notBefore=' . _odate( $c->{not_before} ) }
275 2 elsif ( $k eq 'enddate' ) { push @out, 'notAfter=' . _odate( $c->{not_after} ) }
276 0 ▶ elsif ( $k eq 'serial' ) { push @out, 'serial=' . ( $c->{serial} // _hex( "serial:$id", 32 ) ) }
Condition0%0/3
$$c{"serial"} // _hex("serial:$id", 32)
l!l&&r!l&&!r
000
MC/DC0%0/2
$$c{"serial"} // _hex("serial:$id", 32)
$$c{"serial"} _hex("serial:$id", 32)
Truth table0%0/3
A // B
A= $$c{"serial"}B= _hex("serial:$id", 32)
ABresult
1X1
011
000
277 elsif ( $k eq 'fingerprint' ) {
278 0 ▶ push @out, uc($alg) . ' Fingerprint=' . _hex( "fp-$alg:$id", $alg eq 'sha256' ? 64 : $alg eq 'md5' ? 32 : 40, 1 );
Branch: 2 branches
BranchTrueFalseTotal
$alg eq 'sha256' ? : 0 0 0
$alg eq 'md5' ? : 0 0 0
279 }
280 2 ▶ elsif ( $k eq 'modulus' ) { push @out, 'Modulus=' . modulus( $c->{key} // $id ) }
Condition33%1/3
$$c{"key"} // $id
l!l&&r!l&&!r
200
MC/DC0%0/2
$$c{"key"} // $id
$$c{"key"} $id
Truth table33%1/3
A // B
A= $$c{"key"}B= $id
ABresult
1X1
011
000
281 0 ▶ elsif ( $k eq 'pubkey' ) { push @out, pem( pub => $c->{key} // $id ) =~ s/\n\z//r }
Condition0%0/3
$$c{"key"} // $id
l!l&&r!l&&!r
000
MC/DC0%0/2
$$c{"key"} // $id
$$c{"key"} $id
Truth table0%0/3
A // B
A= $$c{"key"}B= $id
ABresult
1X1
011
000
282 0 ▶ elsif ( $k eq 'subject_hash' || $k eq 'hash' ) { push @out, lc _hex( "sh:" . ( $c->{subject} // '' ), 8 ) }
Condition20%1/5
$k eq "subject_hash" or $k eq "hash"
l!l&&r!l&&!r
006
$$c{"subject"} // ""
l!l
00
MC/DC0%0/2
$k eq "subject_hash" or $k eq "hash"
$k eq "subject_hash" $k eq "hash"
MC/DC0%0/1
$$c{"subject"} // ""
$$c{"subject"}
Truth table33%1/3
A or B
A= $k eq "subject_hash"B= $k eq "hash"
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$c{"subject"}
Aresult
11
00
283 0 ▶ elsif ( $k eq 'issuer_hash' ) { push @out, lc _hex( "sh:" . ( ( $cat->{certs}{ $c->{issuer} // '' } || $c )->{subject} // '' ), 8 ) }
Condition0%0/7
($$cat{"certs"}{$$c{"issuer"} // ""} || $c)->{"subject"} // ""
l!l
00
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
l!l&&r!l&&!r
000
$$c{"issuer"} // ""
l!l
00
MC/DC0%0/2
($$cat{"certs"}{$$c{"issuer"} // ""} || $c)->{"subject"} // ""
$$cat{'certs'}{$$c{'issuer'} // ''} $c
MC/DC0%0/1
$$c{"issuer"} // ""
$$c{"issuer"}
Truth table0%0/3
A || B
A= $$cat{'certs'}{$$c{'issuer'} // ''}B= $c
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$c{"issuer"}
Aresult
11
00
284 0 elsif ( $k eq 'text' ) { push @out, _x509_text( $cat, $id, $c ) }
285 0 ▶ elsif ( $k eq 'purpose' ) { push @out, 'Certificate purposes:', 'SSL client : Yes', 'SSL server : ' . ( $c->{ca} ? 'No' : 'Yes' ) }
Branch: 1 branch
BranchTrueFalseTotal
$$c{'ca'} ? : 0 0 0
286 0 elsif ( $k eq 'ocsp_uri' ) { push @out, 'http://ocsp.example.net' }
287 }
288 6 ▶ if ( defined $o->{ext} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"ext"}) 0 6 6
289 0 for my $x ( split /,/, $o->{ext} ) {
290 0 ▶ if ( $x eq 'subjectAltName' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x eq 'subjectAltName') { } 0 0 0
elsif ($x eq 'basicConstraints') { } 0 0 0
291 0 ▶ push @out, 'X509v3 Subject Alternative Name: ', ' ' . join( ', ', map { /\A(?:DNS|IP)/ ? $_ : "DNS:$_" } @{ $c->{sans} || [] } )
Branch: 1 branch
BranchTrueFalseTotal
/\A(?:DNS|IP)/ ? : 0 0 0
Condition0%0/2
$$c{'sans'} || []
l!l
00
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table0%0/2
A
A= $$c{'sans'}
Aresult
11
00
292 0 ▶ if @{ $c->{sans} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @{$$c{"sans"} or [];} 0 0 0
Condition0%0/2
$$c{'sans'} || []
l!l
00
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table0%0/2
A
A= $$c{'sans'}
Aresult
11
00
293 }
294 0 ▶ elsif ( $x eq 'basicConstraints' ) { push @out, 'X509v3 Basic Constraints: critical', ' CA:' . ( $c->{ca} ? 'TRUE' : 'FALSE' ) }
Branch: 1 branch
BranchTrueFalseTotal
$$c{'ca'} ? : 0 0 0
295 0 else { push @out, "No extensions matched with -ext $x" if 0 }
296 }
297 }
298 6 my $ok = 1;
299 6 ▶ if ( defined $o->{checkend} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"checkend"}) 1 5 6
300 1 ▶ my $exp = _epoch( $c->{not_after} ) <= _epoch( $cat->{now} ) + ( $o->{checkend} =~ /\A\d+\z/ ? $o->{checkend} : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$$o{'checkend'} =~ /\A\d+\z/ ? : 1 0 1
301 1 ▶ push @out, $exp ? 'Certificate will expire' : 'Certificate will not expire';
Branch: 1 branch
BranchTrueFalseTotal
$exp ? : 0 1 1
302 1 ▶ $ok = $exp ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$exp ? : 0 1 1
303 }
304 6 ▶ if ( !$o->{noout} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$o{"noout"}) 0 6 6
305 0 ▶ if ( defined $o->{out} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{'out'}) { } 0 0 0
306 0 my ( $we, $wok ) = Langertha::Holmgang::Sim::Linux::_write_path( $dev, $o->{out}, pem( cert => $id ), 0, $ctx );
307 0 ▶ return ( $we, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 0 0
308 }
309 0 else { push @out, pem( cert => $id ) =~ s/\n\z//r }
310 }
311 6 return ( join( "\n", @out ), $ok );
312 }
313  
314 0 ▶sub _x509_text {
Subroutine _x509_text: not called CC=11 SCAR=48.8
315 0 my ( $cat, $id, $c ) = @_;
316 0 ▶ my $iss = ( $cat->{certs}{ $c->{issuer} // '' } || $c )->{subject};
Condition0%0/5
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
l!l&&r!l&&!r
000
$$c{"issuer"} // ""
l!l
00
MC/DC0%0/2
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
$$cat{'certs'}{$$c{'issuer'} // ''} $c
MC/DC0%0/1
$$c{"issuer"} // ""
$$c{"issuer"}
Truth table0%0/3
A || B
A= $$cat{'certs'}{$$c{'issuer'} // ''}B= $c
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$c{"issuer"}
Aresult
11
00
317 0 ▶ my $bits = ( $cat->{keys}{ $c->{key} // '' } || {} )->{bits} // 2048;
Condition0%0/6
($$cat{"keys"}{$$c{"key"} // ""} || {})->{"bits"} // 2048
l!l
00
$$cat{'keys'}{$$c{'key'} // ''} || {}
l!l
00
$$c{"key"} // ""
l!l
00
MC/DC0%0/1
($$cat{"keys"}{$$c{"key"} // ""} || {})->{"bits"} // 2048
$$cat{'keys'}{$$c{'key'} // ''}
MC/DC0%0/1
$$c{"key"} // ""
$$c{"key"}
Truth table0%0/2
A
A= $$cat{'keys'}{$$c{'key'} // ''}
Aresult
11
00
Truth table0%0/2
A
A= $$c{"key"}
Aresult
11
00
318 my @l = ( 'Certificate:', ' Data:', ' Version: 3 (0x2)', ' Serial Number:',
319 ' ' . lc join( ':', ( $c->{serial} // _hex( "serial:$id", 32 ) ) =~ /(..)/g ),
320 ' Signature Algorithm: sha256WithRSAEncryption', ' Issuer: ' . dn($iss), ' Validity',
321 ' Not Before: ' . _odate( $c->{not_before} ), ' Not After : ' . _odate( $c->{not_after} ),
322 ' Subject: ' . dn( $c->{subject} ), ' Subject Public Key Info:',
323 ' Public Key Algorithm: rsaEncryption', " Public-Key: ($bits bit)",
324 ' X509v3 extensions:', ' X509v3 Basic Constraints: critical',
325 0 ▶ ' CA:' . ( $c->{ca} ? 'TRUE' : 'FALSE' ) );
Branch: 1 branch
BranchTrueFalseTotal
$$c{'ca'} ? : 0 0 0
Condition0%0/3
$$c{"serial"} // _hex("serial:$id", 32)
l!l&&r!l&&!r
000
MC/DC0%0/2
$$c{"serial"} // _hex("serial:$id", 32)
$$c{"serial"} _hex("serial:$id", 32)
Truth table0%0/3
A // B
A= $$c{"serial"}B= _hex("serial:$id", 32)
ABresult
1X1
011
000
326 push @l, ' X509v3 Subject Alternative Name: ',
327 0 ▶ ' ' . join( ', ', map { /\A(?:DNS|IP)/ ? $_ : "DNS:$_" } @{ $c->{sans} } ) if @{ $c->{sans} || [] };
Branch: 2 branches
BranchTrueFalseTotal
if @{$$c{"sans"} or [];} 0 0 0
/\A(?:DNS|IP)/ ? : 0 0 0
Condition0%0/2
$$c{'sans'} || []
l!l
00
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table0%0/2
A
A= $$c{'sans'}
Aresult
11
00
328 0 push @l, ' Signature Algorithm: sha256WithRSAEncryption';
329 0 return @l;
330 }
331  
332 # Passphrase aus -passin
333 3 ▶sub _pass {
Subroutine _pass: called CC=6 SCAR=27.6
334 3 my ( $dev, $spec ) = @_;
335 3 ▶ return undef unless defined $spec;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spec 1 2 3
336 2 ▶ return $1 if $spec =~ /\Apass:(.*)\z/s;
Branch: 1 branch
BranchTrueFalseTotal
if $spec =~ /\Apass:(.*)\z/s 2 0 2
337 0 ▶ if ( $spec =~ /\Afile:(.+)\z/ ) { my $t = _text( $dev, $1 ); return defined $t ? ( split /\n/, $t )[0] // '' : undef }
Branch: 2 branches
BranchTrueFalseTotal
if ($spec =~ /\Afile:(.+)\z/) 0 0 0
defined $t ? : 0 0 0
Condition0%0/2
(split(/\n/, $t, 0))[0] // ""
l!l
00
MC/DC0%0/1
(split(/\n/, $t, 0))[0] // ""
(split(/\n/, $t, 0))[0]
Truth table0%0/2
A
A= (split(/\n/, $t, 0))[0]
Aresult
11
00
338 0 return undef;
339 }
340  
341 # Schluessel aus Text: ( key-id, fehler )
342 7 ▶sub _load_key {
Subroutine _load_key: called CC=8 SCAR=21.3
343 7 my ( $cat, $dev, $t, $passin, $path ) = @_;
344 7 ▶ my ($b) = grep { $_->{kind} eq 'key' || $_->{kind} eq 'enckey' } blocks($t);
Condition66%2/3
$$_{'kind'} eq 'key' || $$_{'kind'} eq 'enckey'
l!l&&r!l&&!r
430
MC/DC0%0/2
$$_{'kind'} eq 'key' || $$_{'kind'} eq 'enckey'
$$_{'kind'} eq 'key' $$_{'kind'} eq 'enckey'
Truth table66%2/3
A || B
A= $$_{'kind'} eq 'key'B= $$_{'kind'} eq 'enckey'
ABresult
1X1
011
000
345 7 ▶ return ( undef, "Could not read private key from $path" ) unless $b && $cat->{keys}{ $b->{id} };
Branch: 1 branch
BranchTrueFalseTotal
unless $b and $$cat{"keys"}{$$b{"id"}} 0 7 7
Condition33%1/3
$b and $$cat{"keys"}{$$b{"id"}}
!ll&&!rl&&r
007
MC/DC0%0/2
$b and $$cat{"keys"}{$$b{"id"}}
$b $$cat{"keys"}{$$b{"id"}}
Truth table33%1/3
A and B
A= $bB= $$cat{"keys"}{$$b{"id"}}
ABresult
0X0
100
111
346 7 ▶ if ( $b->{kind} eq 'enckey' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$b{"kind"} eq "enckey") 3 4 7
347 3 ▶ my $want = $cat->{keys}{ $b->{id} }{passphrase} // '';
Condition50%1/2
$$cat{"keys"}{$$b{"id"}}{"passphrase"} // ""
l!l
30
MC/DC0%0/1
$$cat{"keys"}{$$b{"id"}}{"passphrase"} // ""
$$cat{"keys"}{$$b{"id"}}{"passphrase"}
Truth table50%1/2
A
A= $$cat{"keys"}{$$b{"id"}}{"passphrase"}
Aresult
11
00
348 3 my $p = _pass( $dev, $passin );
349 3 ▶ return ( undef, "Enter pass phrase for $path:\nCould not read private key from $path" ) unless defined $p;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 1 2 3
350 2 ▶ return ( undef, "Could not read private key from $path" ) unless $p eq $want;
Branch: 1 branch
BranchTrueFalseTotal
unless $p eq $want 1 1 2
351 }
352 5 return ( $b->{id} );
353 }
354  
355 5 ▶sub _pkey {
Subroutine _pkey: called CC=22 SCAR=40.1
356 5 my ( $dev, $av, $ctx, $stdin, $state, $cmd ) = @_;
357 5 my ( $o, $e ) = _opts( $av, in => 1, out => 1, passin => 1, passout => 1, inform => 1, outform => 1, noout => 0,
358 modulus => 0, check => 0, text => 0, pubout => 0, pubin => 0, aes256 => 0, des3 => 0, traditional => 0 );
359 5 ▶ return _usage( $cmd, $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 5 5
360 5 my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'private key' );
361 5 ▶ return ( $err, 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 5 5
362 5 my $cat = catalog($state);
363 5 ▶ my $path = $o->{in} // '<stdin>';
Condition50%1/2
$$o{"in"} // "<stdin>"
l!l
50
MC/DC0%0/1
$$o{"in"} // "<stdin>"
$$o{"in"}
Truth table50%1/2
A
A= $$o{"in"}
Aresult
11
00
364 5 ▶ if ( $o->{pubin} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"pubin"}) 0 5 5
365 0 my ($b) = grep { $_->{kind} eq 'pub' } blocks($t);
366 0 ▶ return ( "Could not read public key from $path", 0 ) unless $b;
Branch: 1 branch
BranchTrueFalseTotal
unless $b 0 0 0
367 0 ▶ return ( join( "\n", $o->{modulus} ? 'Modulus=' . modulus( $b->{id} ) : (), $o->{noout} ? () : pem( pub => $b->{id} ) =~ s/\n\z//r ), 1 );
Branch: 2 branches
BranchTrueFalseTotal
$$o{'modulus'} ? : 0 0 0
$$o{'noout'} ? : 0 0 0
368 }
369 5 my ( $id, $kerr ) = _load_key( $cat, $dev, $t, $o->{passin}, $path );
370 5 ▶ return ( $kerr, 0 ) unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 2 3 5
371 3 ▶ my $k = $cat->{keys}{$id} || {};
Condition50%1/2
$$cat{'keys'}{$id} || {}
l!l
30
MC/DC0%0/1
$$cat{'keys'}{$id} || {}
$$cat{'keys'}{$id}
Truth table50%1/2
A
A= $$cat{'keys'}{$id}
Aresult
11
00
372 3 my @out;
373 3 ▶ push @out, 'Modulus=' . modulus($id) if $o->{modulus};
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"modulus"} 2 1 3
374 3 ▶ push @out, $cmd eq 'rsa' ? 'RSA key ok' : 'Key is valid' if $o->{check};
Branch: 2 branches
BranchTrueFalseTotal
if $$o{"check"} 0 3 3
$cmd eq 'rsa' ? : 0 0 0
375 3 ▶ push @out, 'Private-Key: (' . ( $k->{bits} // 2048 ) . ' bit, 2 primes)', 'modulus:', ' ' . lc( substr( modulus($id), 0, 48 ) =~ s/(..)(?=.)/$1:/gr ) . ':...' if $o->{text};
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"text"} 0 3 3
Condition0%0/2
$$k{"bits"} // 2048
l!l
00
MC/DC0%0/1
$$k{"bits"} // 2048
$$k{"bits"}
Truth table0%0/2
A
A= $$k{"bits"}
Aresult
11
00
376 3 ▶ if ( !$o->{noout} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$o{"noout"}) 1 2 3
377 1 ▶ my $text = $o->{pubout} ? pem( pub => $id ) : pem( ( $o->{aes256} || $o->{des3} ) ? 'enckey' : 'key', $id );
Branch: 2 branches
BranchTrueFalseTotal
$$o{'pubout'} ? : 0 1 1
$$o{'aes256'} || $$o{'des3'} ? : 0 1 1
Condition33%1/3
$$o{"aes256"} or $$o{"des3"}
l!l&&r!l&&!r
001
MC/DC0%0/2
$$o{"aes256"} or $$o{"des3"}
$$o{"aes256"} $$o{"des3"}
Truth table33%1/3
A or B
A= $$o{"aes256"}B= $$o{"des3"}
ABresult
1X1
011
000
378 1 ▶ if ( defined $o->{out} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{'out'}) { } 1 0 1
379 1 my ( $we, $wok ) = _write_key( $dev, $o->{out}, $text, $ctx, !$o->{pubout} );
380 1 ▶ return ( $we, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 1 1
381 1 ▶ push @out, 'writing RSA key' if $cmd eq 'rsa';
Branch: 1 branch
BranchTrueFalseTotal
if $cmd eq "rsa" 1 0 1
382 }
383 0 else { push @out, 'writing RSA key' x !!( $cmd eq 'rsa' ), $text =~ s/\n\z//r }
384 }
385 3 return ( join( "\n", grep {length} @out ), 1 );
386 }
387  
388 # Private Schluessel schreibt OpenSSL 3 neu mit 0600 (bio_open_owner)
389 2 ▶sub _write_key {
Subroutine _write_key: called CC=4 SCAR=15.5
390 2 my ( $dev, $path, $text, $ctx, $private ) = @_;
391 2 my $new = !Langertha::Holmgang::Sim::Linux::_file_entry( $dev, $path );
392 2 my ( $e, $ok ) = Langertha::Holmgang::Sim::Linux::_write_path( $dev, $path, $text, 0, $ctx );
393 2 ▶ return ( $e, $ok ) unless $ok && $private && $new;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok and $private and $new 0 2 2
Condition33%2/6
$ok and $private and $new
!ll&&!rl&&r
002
$ok and $private
!ll&&!rl&&r
002
MC/DC0%0/3
$ok and $private and $new
$ok $private $new
Truth table25%1/4
A and B and C
A= $okB= $privateC= $new
ABCresult
0XX0
10X0
1100
1111
394 2 $dev->{files}{$path} = { content => $text, owner => 'root', group => 'root', mode => '0600' };
395 2 return ( $e, $ok );
396 }
397  
398 1 ▶sub _verify {
Subroutine _verify: called CC=17 SCAR=36.3
399 1 my ( $dev, $av, $ctx, $stdin, $state ) = @_;
400 1 my ( $o, $e ) = _opts( $av, CAfile => 1, untrusted => 2, CApath => 1, purpose => 1, verbose => 0, show_chain => 0,
401 no_check_time => 0, partial_chain => 0, verify_hostname => 1, x509_strict => 0, 'no-CAfile' => 0, 'no-CApath' => 0 );
402 1 ▶ return _usage( 'verify', $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 1 1
403 1 my $cat = catalog($state);
404 1 my $trust = trust_of($dev);
405 1 ▶ if ( defined $o->{CAfile} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"CAfile"}) 1 0 1
406 1 ▶ my $t = _text( $dev, $o->{CAfile} ) // return ( "Error loading file $o->{CAfile}", 0 );
Condition50%1/2
_text($dev, $$o{"CAfile"}) // (return qq[Error loading file $$o{"CAfile"}], 0)
l!l
10
MC/DC0%0/1
_text($dev, $$o{"CAfile"}) // (return qq[Error loading file $$o{"CAfile"}], 0)
_text($dev, $$o{"CAfile"})
Truth table50%1/2
A
A= _text($dev, $$o{"CAfile"})
Aresult
11
00
407 1 ▶ $trust = [ $o->{'no-CAfile'} ? () : (), _cert_ids($t) ];
Branch: 1 branch
BranchTrueFalseTotal
$$o{'no-CAfile'} ? : 0 1 1
408 }
409 0 ▶ my @inter = map { my $t = _text( $dev, $_ ); defined $t ? _cert_ids($t) : () } @{ $o->{untrusted} || [] };
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 0 0 0
Condition50%1/2
$$o{'untrusted'} || []
l!l
01
MC/DC0%0/1
$$o{'untrusted'} || []
$$o{'untrusted'}
Truth table50%1/2
A
A= $$o{'untrusted'}
Aresult
11
00
410 1 my @files = @{ $o->{_rest} };
411 1 ▶ @files = ('stdin') unless @files;
Branch: 1 branch
BranchTrueFalseTotal
unless @files 0 1 1
412 1 my @out;
413 1 my $ok = 1;
414 1 for my $f (@files) {
415 1 ▶ my $t = $f eq 'stdin' ? $stdin // '' : _text( $dev, $f );
Branch: 1 branch
BranchTrueFalseTotal
$f eq 'stdin' ? : 0 1 1
Condition0%0/2
$stdin // ""
l!l
00
MC/DC0%0/1
$stdin // ""
$stdin
Truth table0%0/2
A
A= $stdin
Aresult
11
00
416 0 ▶ if ( !defined $t ) { push @out, "Could not open file or uri for loading certificate from $f: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 1 1
417 1 my ($id) = _cert_ids($t);
418 0 ▶ if ( !defined $id || !$cat->{certs}{$id} ) { push @out, "Could not read certificate from $f", 'Unable to load certificate'; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id and $$cat{"certs"}{$id}) 0 1 1
Condition33%1/3
defined $id and $$cat{"certs"}{$id}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $id and $$cat{"certs"}{$id}
defined $id $$cat{"certs"}{$id}
Truth table33%1/3
A and B
A= defined $idB= $$cat{"certs"}{$id}
ABresult
0X0
100
111
419 1 ▶ if ( my $r = verify_chain( $cat, $id, \@inter, $trust ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $r = verify_chain($cat, $id, \@inter, $trust)) { } 1 0 1
420 1 ▶ my $c = $cat->{certs}{ $r->{cert} } || {};
Condition50%1/2
$$cat{'certs'}{$$r{'cert'}} || {}
l!l
10
MC/DC0%0/1
$$cat{'certs'}{$$r{'cert'}} || {}
$$cat{'certs'}{$$r{'cert'}}
Truth table50%1/2
A
A= $$cat{'certs'}{$$r{'cert'}}
Aresult
11
00
421 1 ▶ push @out, dn( $c->{subject} // '' ), "error $r->{code} at $r->{depth} depth lookup: $ERR{ $r->{code} }", "error $f: verification failed";
Condition50%1/2
$$c{"subject"} // ""
l!l
10
MC/DC0%0/1
$$c{"subject"} // ""
$$c{"subject"}
Truth table50%1/2
A
A= $$c{"subject"}
Aresult
11
00
422 1 $ok = 0;
423 }
424 0 else { push @out, "$f: OK" }
425 }
426 1 return ( join( "\n", @out ), $ok );
427 }
428  
429 1 ▶sub _s_client {
Subroutine _s_client: called CC=55 SCAR=62.7
430 1 my ( $dev, $av, $ctx, $stdin, $state ) = @_;
431 1 my ( $o, $e ) = _opts( $av, connect => 1, servername => 1, CAfile => 1, cert => 1, key => 1, showcerts => 0, brief => 0,
432 tls1 => 0, tls1_1 => 0, tls1_2 => 0, tls1_3 => 0, quiet => 0, verify_return_error => 0, verify => 1, state => 0,
433 debug => 0, status => 0, crlf => 0, ign_eof => 0, no_ign_eof => 0, alpn => 1, noservername => 0, verify_hostname => 1,
434 starttls => 1, prexit => 0, msg => 0 );
435 1 ▶ return _usage( 's_client', $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 1 1
436 1 ▶ my $c = $o->{connect} // $o->{_rest}[0] // 'localhost:443';
Condition40%2/5
($$o{"connect"} // $$o{"_rest"}[0]) // "localhost:443"
l!l
10
$$o{"connect"} // $$o{"_rest"}[0]
l!l&&r!l&&!r
100
MC/DC0%0/2
($$o{"connect"} // $$o{"_rest"}[0]) // "localhost:443"
$$o{"connect"} $$o{"_rest"}[0]
Truth table33%1/3
A // B
A= $$o{"connect"}B= $$o{"_rest"}[0]
ABresult
1X1
011
000
437 1 my ( $host, $port ) = $c =~ /\A\[?([^\]]+?)\]?(?::(\d+))?\z/;
438 1 ▶ $port //= 443;
Condition50%1/2
$port //= 443
l!l
10
MC/DC0%0/1
$port //= 443
$port
Truth table50%1/2
A
A= $port
Aresult
11
00
439 0 my ($ver) = map { { tls1 => 'TLSv1', tls1_1 => 'TLSv1.1', tls1_2 => 'TLSv1.2', tls1_3 => 'TLSv1.3' }->{$_} } grep { $o->{$_} } qw( tls1 tls1_1 tls1_2 tls1_3 );
440 1 require Langertha::Holmgang::Sim::Linux::Http;
441 1 ▶ my $sni = $o->{noservername} ? undef : $o->{servername} // ( $host =~ /\A[\d.]+\z/ ? undef : $host );
Branch: 2 branches
BranchTrueFalseTotal
$$o{'noservername'} ? : 0 1 1
$host =~ /\A[\d.]+\z/ ? : 0 0 0
Condition33%1/3
$$o{"servername"} // ($host =~ /\A[\d.]+\z/ ? undef : $host)
l!l&&r!l&&!r
100
MC/DC0%0/2
$$o{"servername"} // ($host =~ /\A[\d.]+\z/ ? undef : $host)
$$o{"servername"} ($host =~ /\A[\d.]+\z/ ? undef : $host)
Truth table33%1/3
A // B
A= $$o{"servername"}B= ($host =~ /\A[\d.]+\z/ ? undef : $host)
ABresult
1X1
011
000
442 my $res = Langertha::Holmgang::Sim::Linux::Http::request( $state, $ctx->{host}, {
443 url => "https://$host:$port/", method => 'HEAD', insecure => 1, tls_version => $ver,
444 headers => { host => $sni // $host }, ( defined $sni ? ( sni => $sni ) : () ),
445 1 ▶ ( defined $o->{cert} ? ( cert => $o->{cert}, key => $o->{key} // $o->{cert} ) : () ),
Branch: 2 branches
BranchTrueFalseTotal
defined $sni ? : 1 0 1
defined $$o{'cert'} ? : 0 1 1
Condition16%1/6
$sni // $host
l!l&&r!l&&!r
100
$$o{"key"} // $$o{"cert"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$sni // $host
$sni $host
MC/DC0%0/2
$$o{"key"} // $$o{"cert"}
$$o{"key"} $$o{"cert"}
Truth table33%1/3
A // B
A= $sniB= $host
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $$o{"key"}B= $$o{"cert"}
ABresult
1X1
011
000
446 } );
447 1 ▶ if ( defined $res->{error} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$res{"error"}) 0 1 1
448 return ( "40F7B3E1B17F0000:error:8000006F:system library:BIO_connect:Connection refused:../crypto/bio/bio_sock2.c:114:calling connect()\nconnect:errno=111", 1 )
449 0 ▶ if ( $res->{code} // 0 ) == 7;
Branch: 1 branch
BranchTrueFalseTotal
if ($$res{"code"} // 0) == 7 0 0 0
Condition0%0/2
$$res{"code"} // 0
l!l
00
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
Aresult
11
00
450 return ( "40F7B3E1B17F0000:error:10080002:BIO routines:BIO_lookup_ex:system lib:../crypto/bio/bio_sock.c:457:\nconnect:errno=0", 1 )
451 0 ▶ if ( $res->{code} // 0 ) == 6;
Branch: 1 branch
BranchTrueFalseTotal
if ($$res{"code"} // 0) == 6 0 0 0
Condition0%0/2
$$res{"code"} // 0
l!l
00
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
Aresult
11
00
452 return ( "CONNECTED(00000003)\n40F7B3E1B17F0000:error:0A00010B:SSL routines:ssl3_get_record:wrong version number:../ssl/record/ssl3_record.c:354:\n---\nno peer certificate available\n---", 1 )
453 0 ▶ if ( $res->{code} // 0 ) == 35 && $res->{error} =~ /wrong version/;
Branch: 1 branch
BranchTrueFalseTotal
if ($$res{"code"} // 0) == 35 and $$res{"error"} =~ /wrong version/ 0 0 0
Condition0%0/5
($$res{"code"} // 0) == 35 and $$res{"error"} =~ /wrong version/
!ll&&!rl&&r
000
$$res{"code"} // 0
l!l
00
MC/DC0%0/2
($$res{"code"} // 0) == 35 and $$res{"error"} =~ /wrong version/
$$res{"code"} $$res{"error"} =~ /wrong version/
Truth table0%0/3
A and B
A= $$res{"code"}B= $$res{"error"} =~ /wrong version/
ABresult
0X0
100
111
454 return ( "CONNECTED(00000003)\n40F7B3E1B17F0000:error:0A00042E:SSL routines:ssl3_read_bytes:tlsv1 alert protocol version:../ssl/record/rec_layer_s3.c:1584:SSL alert number 70\n---\nno peer certificate available\n---\nNo client certificate CA names sent\n---", 1 )
455 0 ▶ if ( $res->{code} // 0 ) == 35;
Branch: 1 branch
BranchTrueFalseTotal
if ($$res{"code"} // 0) == 35 0 0 0
Condition0%0/2
$$res{"code"} // 0
l!l
00
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
Aresult
11
00
456 0 return ( "CONNECTED(00000003)\n$res->{error}", 1 );
457 }
458 1 ▶ my $tls = $res->{tls} or return ( 'CONNECTED(00000003)', 1 );
Branch: 1 branch
BranchTrueFalseTotal
my $tls = $$res{"tls"} or return "CONNECTED(00000003)", 1 1 0 1
459 1 my $cat = catalog($state);
460 1 ▶ my @chain = @{ $tls->{chain} || [] };
Condition50%1/2
$$tls{'chain'} || []
l!l
10
MC/DC0%0/1
$$tls{'chain'} || []
$$tls{'chain'}
Truth table50%1/2
A
A= $$tls{'chain'}
Aresult
11
00
461 1 my $trust = trust_of($dev);
462 0 ▶ if ( defined $o->{CAfile} ) { my $t = _text( $dev, $o->{CAfile} ); $trust = [ defined $t ? _cert_ids($t) : () ] }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $$o{"CAfile"}) 0 1 1
defined $t ? : 0 0 0
463 1 ▶ my $r = @chain ? verify_chain( $cat, $chain[0], [ @chain[ 1 .. $#chain ] ], $trust ) : { code => 20, depth => 0 };
Branch: 1 branch
BranchTrueFalseTotal
@chain ? : 1 0 1
464 1 my @l = ('CONNECTED(00000003)');
465 1 ▶ my $subj = sub { dn( ( $cat->{certs}{ $_[0] } || {} )->{subject} ) };
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition50%1/2
$$cat{'certs'}{$_[0]} || {}
l!l
60
MC/DC0%0/1
$$cat{'certs'}{$_[0]} || {}
$$cat{'certs'}{$_[0]}
Truth table50%1/2
A
A= $$cat{'certs'}{$_[0]}
Aresult
11
00
466 1 ▶ my $issu = sub { my $x = $cat->{certs}{ $_[0] } || {}; dn( ( $cat->{certs}{ $x->{issuer} // '' } || {} )->{subject} // $x->{issuer} ) };
Subroutine __ANON__: called CC=5 SCAR=19.2
Condition44%4/9
$$cat{'certs'}{$_[0]} || {}
l!l
30
($$cat{"certs"}{$$x{"issuer"} // ""} || {})->{"subject"} // $$x{"issuer"}
l!l&&r!l&&!r
300
$$cat{'certs'}{$$x{'issuer'} // ''} || {}
l!l
30
$$x{"issuer"} // ""
l!l
30
MC/DC0%0/1
$$cat{'certs'}{$_[0]} || {}
$$cat{'certs'}{$_[0]}
MC/DC0%0/2
($$cat{"certs"}{$$x{"issuer"} // ""} || {})->{"subject"} // $$x{"issuer"}
$$cat{'certs'}{$$x{'issuer'} // ''} $$x{"issuer"}
MC/DC0%0/1
$$x{"issuer"} // ""
$$x{"issuer"}
Truth table50%1/2
A
A= $$cat{'certs'}{$_[0]}
Aresult
11
00
Truth table33%1/3
A // B
A= $$cat{'certs'}{$$x{'issuer'} // ''}B= $$x{"issuer"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$x{"issuer"}
Aresult
11
00
467 1 ▶ if ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 1 1
468 0 ▶ for ( my $d = $r->{depth}; $d >= 0; $d-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d >= 0) 0 0 0
469 0 ▶ my $id = $chain[$d] // $r->{cert};
Condition0%0/3
$chain[$d] // $$r{"cert"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$chain[$d] // $$r{"cert"}
$chain[$d] $$r{"cert"}
Truth table0%0/3
A // B
A= $chain[$d]B= $$r{"cert"}
ABresult
1X1
011
000
470 0 push @l, "depth=$d " . $subj->($id);
471 0 ▶ push @l, "verify error:num=$r->{code}:$ERR{$r->{code}}" if $d == $r->{depth};
Branch: 1 branch
BranchTrueFalseTotal
if $d == $$r{"depth"} 0 0 0
472 0 ▶ push @l, 'verify error:num=21:unable to verify the first certificate' if $d == 0 && $r->{code} == 20 && $r->{depth} == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $d == 0 and $$r{"code"} == 20 and $$r{"depth"} == 0 0 0 0
Condition0%0/6
$d == 0 and $$r{"code"} == 20 and $$r{"depth"} == 0
!ll&&!rl&&r
000
$d == 0 and $$r{"code"} == 20
!ll&&!rl&&r
000
MC/DC0%0/3
$d == 0 and $$r{"code"} == 20 and $$r{"depth"} == 0
$d == 0 $$r{"code"} == 20 $$r{"depth"} == 0
Truth table0%0/4
A and B and C
A= $d == 0B= $$r{"code"} == 20C= $$r{"depth"} == 0
ABCresult
0XX0
10X0
1100
1111
473 0 push @l, 'verify return:1';
474 }
475 }
476 else {
477 1 my $n = $#chain;
478 1 ▶ for ( my $d = $n + 1; $d >= 0; $d-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d >= 0) 3 1 4
479 3 ▶ my $id = $d <= $n ? $chain[$d] : ( $cat->{certs}{ $chain[$n] } || {} )->{issuer};
Branch: 1 branch
BranchTrueFalseTotal
$d <= $n ? : 2 1 3
Condition50%1/2
$$cat{'certs'}{$chain[$n]} || {}
l!l
10
MC/DC0%0/1
$$cat{'certs'}{$chain[$n]} || {}
$$cat{'certs'}{$chain[$n]}
Truth table50%1/2
A
A= $$cat{'certs'}{$chain[$n]}
Aresult
11
00
480 3 ▶ next unless defined $id && $cat->{certs}{$id};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id and $$cat{"certs"}{$id} 0 3 3
Condition33%1/3
defined $id and $$cat{"certs"}{$id}
!ll&&!rl&&r
003
MC/DC0%0/2
defined $id and $$cat{"certs"}{$id}
defined $id $$cat{"certs"}{$id}
Truth table33%1/3
A and B
A= defined $idB= $$cat{"certs"}{$id}
ABresult
0X0
100
111
481 3 ▶ next if $d == $n + 1 && $id eq $chain[$n];
Branch: 1 branch
BranchTrueFalseTotal
if $d == $n + 1 and $id eq $chain[$n] 0 3 3
Condition66%2/3
$d == $n + 1 and $id eq $chain[$n]
!ll&&!rl&&r
210
MC/DC0%0/2
$d == $n + 1 and $id eq $chain[$n]
$d == $n + 1 $id eq $chain[$n]
Truth table66%2/3
A and B
A= $d == $n + 1B= $id eq $chain[$n]
ABresult
0X0
100
111
482 3 push @l, "depth=$d " . $subj->($id), 'verify return:1';
483 }
484 }
485 1 push @l, '---', 'Certificate chain';
486 1 for my $i ( 0 .. $#chain ) {
487 2 ▶ my $x = $cat->{certs}{ $chain[$i] } || {};
Condition50%1/2
$$cat{'certs'}{$chain[$i]} || {}
l!l
20
MC/DC0%0/1
$$cat{'certs'}{$chain[$i]} || {}
$$cat{'certs'}{$chain[$i]}
Truth table50%1/2
A
A= $$cat{'certs'}{$chain[$i]}
Aresult
11
00
488 push @l, " $i s:" . $subj->( $chain[$i] ), ' i:' . $issu->( $chain[$i] ),
489 ' a:PKEY: rsaEncryption, ' . ( ( $cat->{keys}{ $x->{key} // '' } || {} )->{bits} // 2048 ) . ' (bit); sigalg: RSA-SHA256',
490 2 ▶ ' v:NotBefore: ' . _odate( $x->{not_before} ) . '; NotAfter: ' . _odate( $x->{not_after} );
Condition66%4/6
($$cat{"keys"}{$$x{"key"} // ""} || {})->{"bits"} // 2048
l!l
11
$$cat{'keys'}{$$x{'key'} // ''} || {}
l!l
20
$$x{"key"} // ""
l!l
20
MC/DC0%0/1
($$cat{"keys"}{$$x{"key"} // ""} || {})->{"bits"} // 2048
$$cat{'keys'}{$$x{'key'} // ''}
MC/DC0%0/1
$$x{"key"} // ""
$$x{"key"}
Truth table50%1/2
A
A= $$cat{'keys'}{$$x{'key'} // ''}
Aresult
11
00
Truth table50%1/2
A
A= $$x{"key"}
Aresult
11
00
491 2 ▶ push @l, pem( cert => $chain[$i] ) =~ s/\n\z//r if $o->{showcerts};
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"showcerts"} 0 2 2
492 }
493 1 push @l, '---', 'Server certificate';
494 1 ▶ push @l, pem( cert => $chain[0] ) =~ s/\n\z//r unless $o->{showcerts};
Branch: 1 branch
BranchTrueFalseTotal
unless $$o{"showcerts"} 1 0 1
495 1 push @l, 'subject=' . $subj->( $chain[0] ), 'issuer=' . $issu->( $chain[0] ), '---';
496 0 ▶ push @l, $tls->{client_ca} ? ( 'Acceptable client certificate CA names', map { $subj->($_) } @{ $tls->{client_ca} } ) : 'No client certificate CA names sent';
Branch: 1 branch
BranchTrueFalseTotal
$$tls{'client_ca'} ? : 0 1 1
497 1 ▶ my $code = $r ? ( $r->{code} == 20 && $r->{depth} == 0 ? 21 : $r->{code} ) : 0;
Branch: 2 branches
BranchTrueFalseTotal
$r ? : 0 1 1
$$r{'code'} == 20 && $$r{'depth'} == 0 ? : 0 0 0
Condition0%0/3
$$r{"code"} == 20 and $$r{"depth"} == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$$r{"code"} == 20 and $$r{"depth"} == 0
$$r{"code"} == 20 $$r{"depth"} == 0
Truth table0%0/3
A and B
A= $$r{"code"} == 20B= $$r{"depth"} == 0
ABresult
0X0
100
111
498 1 ▶ my $msg = $r ? $ERR{$code} : 'ok';
Branch: 1 branch
BranchTrueFalseTotal
$r ? : 0 1 1
499 push @l, '---', 'SSL handshake has read 4352 bytes and written 393 bytes',
500 $r ? "Verification error: $msg" : 'Verification: OK', '---',
501 1 ▶ "New, $tls->{protocol}, Cipher is " . ( $tls->{protocol} eq 'TLSv1.3' ? 'TLS_AES_256_GCM_SHA384' : 'ECDHE-RSA-AES256-GCM-SHA384' ),
Branch: 2 branches
BranchTrueFalseTotal
$r ? : 0 1 1
$$tls{'protocol'} eq 'TLSv1.3' ? : 1 0 1
502 'Server public key is 2048 bit', 'Secure Renegotiation IS NOT supported', 'Compression: NONE', 'Expansion: NONE',
503 'No ALPN negotiated', 'Early data was not sent', "Verify return code: $code ($msg)", '---', 'DONE';
504 1 return ( join( "\n", @l ), 1 );
505 }
506  
507 1 ▶sub _crl2pkcs7 {
Subroutine _crl2pkcs7: called CC=5 SCAR=16.4
508 1 my ( $dev, $av, $ctx, $stdin, $state ) = @_;
509 1 my ( $o, $e ) = _opts( $av, nocrl => 0, certfile => 2, out => 1, outform => 1, in => 1 );
510 1 ▶ return _usage( 'crl2pkcs7', $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 1 1
511 1 my @ids;
512 1 ▶ for my $f ( @{ $o->{certfile} || [] } ) {
Condition50%1/2
$$o{'certfile'} || []
l!l
10
MC/DC0%0/1
$$o{'certfile'} || []
$$o{'certfile'}
Truth table50%1/2
A
A= $$o{'certfile'}
Aresult
11
00
513 1 ▶ my $t = _text( $dev, $f ) // return ( "Could not open file or uri for loading certificates from $f: No such file or directory", 0 );
Condition50%1/2
_text($dev, $f) // (return "Could not open file or uri for loading certificates from ${f}: No such file or directory", 0)
l!l
10
MC/DC0%0/1
_text($dev, $f) // (return "Could not open file or uri for loading certificates from ${f}: No such file or directory", 0)
_text($dev, $f)
Truth table50%1/2
A
A= _text($dev, $f)
Aresult
11
00
514 1 push @ids, _cert_ids($t);
515 }
516 1 my $p = pem( p7 => join( ',', @ids ) );
517 1 return ( $p =~ s/\n\z//r, 1 );
518 }
519  
520 1 ▶sub _pkcs7 {
Subroutine _pkcs7: called CC=12 SCAR=28.5
521 1 my ( $dev, $av, $ctx, $stdin, $state ) = @_;
522 1 my ( $o, $e ) = _opts( $av, in => 1, inform => 1, print_certs => 0, noout => 0, text => 0, print => 0 );
523 1 ▶ return _usage( 'pkcs7', $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 1 1
524 1 my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'PKCS7' );
525 1 ▶ return ( $err, 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
526 1 my ($b) = grep { $_->{kind} eq 'p7' } blocks($t);
527 1 ▶ return ( 'Could not read PKCS7 from ' . ( $o->{in} // '<stdin>' ) . "\nUnable to load PKCS7 object", 0 ) unless $b;
Branch: 1 branch
BranchTrueFalseTotal
unless $b 0 1 1
Condition0%0/2
$$o{"in"} // "<stdin>"
l!l
00
MC/DC0%0/1
$$o{"in"} // "<stdin>"
$$o{"in"}
Truth table0%0/2
A
A= $$o{"in"}
Aresult
11
00
528 1 my $cat = catalog($state);
529 1 my @l;
530 1 for my $id ( split /,/, $b->{id} ) {
531 2 ▶ my $c = $cat->{certs}{$id} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $c = $$cat{"certs"}{$id} or next 2 0 2
532 2 ▶ push @l, 'subject=' . dn( $c->{subject} ), 'issuer=' . dn( ( $cat->{certs}{ $c->{issuer} // '' } || $c )->{subject} );
Condition40%2/5
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
l!l&&r!l&&!r
200
$$c{"issuer"} // ""
l!l
20
MC/DC0%0/2
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
$$cat{'certs'}{$$c{'issuer'} // ''} $c
MC/DC0%0/1
$$c{"issuer"} // ""
$$c{"issuer"}
Truth table33%1/3
A || B
A= $$cat{'certs'}{$$c{'issuer'} // ''}B= $c
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$c{"issuer"}
Aresult
11
00
533 2 ▶ push @l, pem( cert => $id ) =~ s/\n\z//r unless $o->{noout};
Branch: 1 branch
BranchTrueFalseTotal
unless $$o{"noout"} 0 2 2
534 2 push @l, '';
535 }
536 1 ▶ pop @l if @l && $l[-1] eq '';
Branch: 1 branch
BranchTrueFalseTotal
if @l and $l[-1] eq "" 1 0 1
Condition33%1/3
@l and $l[-1] eq ""
!ll&&!rl&&r
001
MC/DC0%0/2
@l and $l[-1] eq ""
@l $l[-1] eq ""
Truth table33%1/3
A and B
A= @lB= $l[-1] eq ""
ABresult
0X0
100
111
537 1 return ( join( "\n", @l ), 1 );
538 }
539  
540 2 ▶sub _dgst {
Subroutine _dgst: called CC=14 SCAR=33.2
541 2 my ( $dev, $av, $ctx, $stdin, $state, $cmd ) = @_;
542 2 my @a = @$av;
543 2 ▶ my $alg = $cmd eq 'dgst' ? 'sha256' : $cmd;
Branch: 1 branch
BranchTrueFalseTotal
$cmd eq 'dgst' ? : 0 2 2
544 2 my @files;
545 0 ▶ for (@a) { if (/\A-(sha256|sha1|md5|sha512)\z/) { $alg = $1 } elsif ( !/\A-/ ) { push @files, $_ } }
Branch: 2 branches
BranchTrueFalseTotal
if (/\A-(sha256|sha1|md5|sha512)\z/) { } 0 0 0
elsif (not /\A-/) { } 0 0 0
546 2 my @out;
547 2 ▶ for my $f ( @files ? @files : (undef) ) {
Branch: 1 branch
BranchTrueFalseTotal
@files ? : 0 2 2
548 2 ▶ my $t = defined $f ? _text( $dev, $f ) : $stdin // '';
Branch: 1 branch
BranchTrueFalseTotal
defined $f ? : 0 2 2
Condition50%1/2
$stdin // ""
l!l
20
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
Aresult
11
00
549 2 ▶ return ( "Can't open \"$f\" for reading, No such file or directory", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 2 2
550 2 ▶ my $h = $alg eq 'md5' ? do { require Digest::MD5; Digest::MD5::md5_hex($t) } : Digest::SHA->can("${alg}_hex")->( _enc_bytes($t) );
Branch: 1 branch
BranchTrueFalseTotal
$alg eq 'md5' ? : 2 0 2
551 2 ▶ push @out, uc( $alg eq 'sha256' ? 'SHA2-256' : $alg eq 'sha512' ? 'SHA2-512' : $alg ) . '(' . ( $f // 'stdin' ) . ")= $h";
Branch: 2 branches
BranchTrueFalseTotal
$alg eq 'sha256' ? : 0 2 2
$alg eq 'sha512' ? : 0 2 2
Condition50%1/2
$f // "stdin"
l!l
02
MC/DC0%0/1
$f // "stdin"
$f
Truth table50%1/2
A
A= $f
Aresult
11
00
552 }
553 2 return ( join( "\n", @out ), 1 );
554 }
555  
556 1 ▶sub _enc_bytes { my ($t) = @_; utf8::encode($t) if utf8::is_utf8($t); return $t }
Subroutine _enc_bytes: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($t) 0 1 1
557  
558 # --- req (CSR, selbst signiert) -------------------------------------------------
559  
560 3 ▶sub _subj {
Subroutine _subj: called CC=3 SCAR=11.0
561 3 my ($s) = @_;
562 3 ▶ return undef unless defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 1 2 3
563 2 $s =~ s{\A/}{};
564 2 my @p = grep {length} split m{(?<!\\)/}, $s;
565 2 ▶ return join ',', map { my ( $k, $v ) = split /=/, $_, 2; "$k=" . ( $v // '' ) } @p;
Condition50%1/2
$v // ""
l!l
20
MC/DC0%0/1
$v // ""
$v
Truth table50%1/2
A
A= $v
Aresult
11
00
566 }
567  
568 1 ▶sub _sans_from {
Subroutine _sans_from: called CC=2 SCAR=7.0
569 1 my ($v) = @_;
570 1 ▶ return () unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 1 1
571 1 $v =~ s/\A\s*subjectAltName\s*=\s*//;
572 1 return map { s/\A\s+|\s+\z//gr } grep {/\S/} split /,/, $v;
573 }
574  
575 # openssl.cnf: [req] distinguished_name, req_extensions, x509_extensions, prompt
576 1 ▶sub _cnf {
Subroutine _cnf: called CC=6 SCAR=18.1
577 1 my ($t) = @_;
578 1 my ( %s, $cur );
579 1 $cur = '';
580 1 ▶ for my $l ( split /\n/, $t // '' ) {
Condition50%1/2
$t // ""
l!l
10
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
Aresult
11
00
581 11 $l =~ s/#.*//;
582 11 ▶ next unless $l =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $l =~ /\S/ 0 11 11
583 11 ▶ if ( $l =~ /^\s*\[\s*([^\]\s]+)\s*\]/ ) { $cur = $1; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($l =~ /^\s*\[\s*([^\]\s]+)\s*\]/) 4 7 11
584 7 ▶ my ( $k, $v ) = $l =~ /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ or next;
Branch: 1 branch
BranchTrueFalseTotal
() = $l =~ /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ or next 7 0 7
585 7 push @{ $s{$cur} }, [ $k, $v ];
586 }
587 1 return \%s;
588 }
589  
590 0 ▶sub _cnf_get { my ( $c, $sec, $k ) = @_; for ( @{ $c->{$sec} || [] } ) { return $_->[1] if $_->[0] eq $k } return undef }
Subroutine _cnf_get: called CC=4 SCAR=14.3
Branch: 1 branch
BranchTrueFalseTotal
if $$_[0] eq $k 4 3 7
Condition50%1/2
$$c{$sec} || []
l!l
40
MC/DC0%0/1
$$c{$sec} || []
$$c{$sec}
Truth table50%1/2
A
A= $$c{$sec}
Aresult
11
00
591  
592 1 ▶sub _cnf_sans {
Subroutine _cnf_sans: called CC=4 SCAR=14.8
593 1 my ( $c, $sec ) = @_;
594 1 ▶ my $v = _cnf_get( $c, $sec, 'subjectAltName' ) // return ();
Condition50%1/2
_cnf_get($c, $sec, "subjectAltName") // (return ())
l!l
10
MC/DC0%0/1
_cnf_get($c, $sec, "subjectAltName") // (return ())
_cnf_get($c, $sec, "subjectAltName")
Truth table50%1/2
A
A= _cnf_get($c, $sec, "subjectAltName")
Aresult
11
00
595 1 ▶ if ( $v =~ /\A\@(\S+)\z/ ) { return map { my ( $t, undef ) = split /\./, $_->[0]; "$t:$_->[1]" } @{ $c->{$1} || [] } }
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ /\A\@(\S+)\z/) 1 0 1
Condition50%1/2
$$c{$1} || []
l!l
10
MC/DC0%0/1
$$c{$1} || []
$$c{$1}
Truth table50%1/2
A
A= $$c{$1}
Aresult
11
00
596 0 return _sans_from($v);
597 }
598  
599 3 ▶sub _canon_csr {
Subroutine _canon_csr: called CC=4 SCAR=13.9
600 3 my (%c) = @_;
601 3 my %seen;
602 3 ▶ my @sans = sort grep { !$seen{$_}++ } map { /\A(?:DNS|IP|email|URI):/ ? $_ : "DNS:$_" } @{ $c{sans} || [] };
Branch: 1 branch
BranchTrueFalseTotal
/\A(?:DNS|IP|email|URI):/ ? : 4 2 6
Condition50%1/2
$c{'sans'} || []
l!l
30
MC/DC0%0/1
$c{'sans'} || []
$c{'sans'}
Truth table50%1/2
A
A= $c{'sans'}
Aresult
11
00
603 3 ▶ my %dn = map { my ( $k, $v ) = split /=/, $_, 2; ( $k => $v ) } grep {length} split /,(?=[A-Za-z]+=)/, $c{subject} // '';
Condition50%1/2
$c{"subject"} // ""
l!l
30
MC/DC0%0/1
$c{"subject"} // ""
$c{"subject"}
Truth table50%1/2
A
A= $c{"subject"}
Aresult
11
00
604 3 return $JSON->encode( { subject => \%dn, sans => \@sans, key => $c{key} } );
605 }
606  
607 3 ▶sub _csr_pem { my ($json) = @_; my $b = MIME::Base64::encode_base64( "cai-sim-csr:$json", '' ); $b =~ s/(.{64})/$1\n/g; $b =~ s/\n\z//; return "-----BEGIN CERTIFICATE REQUEST-----\n$b\n-----END CERTIFICATE REQUEST-----\n" }
Subroutine _csr_pem: called CC=1 SCAR=0.0
608  
609  
610 1 ▶sub csr_pem_for { my (%c) = @_; return _csr_pem( _canon_csr(%c) ) }
Subroutine csr_pem_for: called CC=1 SCAR=0.0
Pod documented
611  
612 1 ▶sub _dn_from_hash { my ($h) = @_; my @o = qw( C ST L O OU CN emailAddress ); my %k = map { $_ => 1 } @o; return join ',', map {"$_=$h->{$_}"} ( grep { exists $h->{$_} } @o ), sort grep { !$k{$_} } keys %$h }
Subroutine _dn_from_hash: called CC=1 SCAR=0.0
613  
614 4 ▶sub _req {
Subroutine _req: called CC=49 SCAR=46.4
615 4 my ( $dev, $av, $ctx, $stdin, $state ) = @_;
616 4 my ( $o, $e ) = _opts( $av, new => 0, x509 => 0, key => 1, newkey => 1, nodes => 0, noenc => 0, keyout => 1, out => 1,
617 in => 1, subj => 1, addext => 2, config => 1, reqexts => 1, extensions => 1, days => 1, sha256 => 0, sha384 => 0,
618 noout => 0, text => 0, subject => 0, verify => 0, passin => 1, passout => 1, batch => 0, utf8 => 0, set_serial => 1 );
619 4 ▶ return _usage( 'req', $e ) unless $o;
Branch: 1 branch
BranchTrueFalseTotal
unless $o 0 4 4
620 4 my $cat = catalog($state);
621 4 ▶ my $p = $dev->{pki} //= {};
Condition50%1/2
$$dev{"pki"} //= {}
l!l
40
MC/DC0%0/1
$$dev{"pki"} //= {}
$$dev{"pki"}
Truth table50%1/2
A
A= $$dev{"pki"}
Aresult
11
00
622 4 ▶ if ( !$o->{new} && !$o->{x509} ) { # CSR lesen
Branch: 1 branch
BranchTrueFalseTotal
unless ($$o{"new"} or $$o{"x509"}) 1 3 4
Condition100%3/3
$$o{"new"} or $$o{"x509"}
l!l&&r!l&&!r
211
MC/DC100%2/2
$$o{"new"} or $$o{"x509"}
$$o{"new"} $$o{"x509"}
Truth table100%3/3
A or B
A= $$o{"new"}B= $$o{"x509"}
ABresult
1X1
011
000
623 1 my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'certificate request' );
624 1 ▶ return ( $err, 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
625 1 my ($b) = grep { $_->{kind} eq 'csr' } blocks($t);
626 1 ▶ return ( 'Unable to load X509 request', 0 ) unless $b;
Branch: 1 branch
BranchTrueFalseTotal
unless $b 0 1 1
627 1 ▶ my $c = eval { $JSON->decode( _enc_bytes( $b->{id} ) ) } or return ( 'Unable to load X509 request', 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $c = eval { do { $JSON->decode(_enc_bytes($$b{"id"})) } } or return "Unable to load X509 request", 0 1 0 1
628 1 my @l;
629 1 ▶ push @l, 'Certificate request self-signature verify OK' if $o->{verify};
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"verify"} 0 1 1
630 1 ▶ push @l, 'subject=' . dn( _dn_from_hash( $c->{subject} ) ) if $o->{subject};
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"subject"} 0 1 1
631 push @l, 'Certificate Request:', ' Data:', ' Version: 1 (0x0)', ' Subject: ' . dn( _dn_from_hash( $c->{subject} ) ),
632 ' Subject Public Key Info:', ' Public Key Algorithm: rsaEncryption',
633 ' Public-Key: (' . ( ( $cat->{keys}{ $c->{key} // '' } || {} )->{bits} // 2048 ) . ' bit)',
634 ' Attributes:', ' Requested Extensions:',
635 1 ( @{ $c->{sans} } ? ( ' X509v3 Subject Alternative Name: ', ' ' . join( ', ', @{ $c->{sans} } ) ) : () ),
636 1 ▶ ' Signature Algorithm: sha256WithRSAEncryption' if $o->{text};
Branch: 2 branches
BranchTrueFalseTotal
if $$o{"text"} 1 0 1
@{$$c{'sans'};} ? : 1 0 1
Condition50%3/6
($$cat{"keys"}{$$c{"key"} // ""} || {})->{"bits"} // 2048
l!l
10
$$cat{'keys'}{$$c{'key'} // ''} || {}
l!l
10
$$c{"key"} // ""
l!l
10
MC/DC0%0/1
($$cat{"keys"}{$$c{"key"} // ""} || {})->{"bits"} // 2048
$$cat{'keys'}{$$c{'key'} // ''}
MC/DC0%0/1
$$c{"key"} // ""
$$c{"key"}
Truth table50%1/2
A
A= $$cat{'keys'}{$$c{'key'} // ''}
Aresult
11
00
Truth table50%1/2
A
A= $$c{"key"}
Aresult
11
00
637 1 ▶ push @l, $b->{text} =~ s/\n\z//r unless $o->{noout};
Branch: 1 branch
BranchTrueFalseTotal
unless $$o{"noout"} 0 1 1
638 1 return ( join( "\n", @l ), 1 );
639 }
640 # Schluessel
641 3 my $key;
642 3 ▶ if ( defined $o->{key} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $$o{'key'}) { } 2 1 3
elsif (defined $$o{'newkey'}) { } 1 0 1
643 2 ▶ my $t = _text( $dev, $o->{key} ) // return ( "Could not open file or uri for loading private key from $o->{key}: No such file or directory", 0 );
Condition50%1/2
_text($dev, $$o{"key"}) // (return qq[Could not open file or uri for loading private key from $$o{"key"}: No such file or directory], 0)
l!l
20
MC/DC0%0/1
_text($dev, $$o{"key"}) // (return qq[Could not open file or uri for loading private key from $$o{"key"}: No such file or directory], 0)
_text($dev, $$o{"key"})
Truth table50%1/2
A
A= _text($dev, $$o{"key"})
Aresult
11
00
644 2 ( $key, my $kerr ) = _load_key( $cat, $dev, $t, $o->{passin}, $o->{key} );
645 2 ▶ return ( $kerr, 0 ) unless defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 2 2
646 }
647 elsif ( defined $o->{newkey} ) {
648 1 ▶ my ($bits) = $o->{newkey} =~ /\Arsa:(\d+)\z/ or return _gap( 'openssl req -newkey', $o->{newkey} );
Branch: 1 branch
BranchTrueFalseTotal
my($bits) = $$o{"newkey"} =~ /\Arsa:(\d+)\z/ or return _gap("openssl req -newkey", $$o{"newkey"}) 1 0 1
649 1 ▶ my $n = 1 + scalar grep {/\Agen-key-/} keys %{ $p->{keys} || {} };
Condition50%1/2
$$p{'keys'} || {}
l!l
10
MC/DC0%0/1
$$p{'keys'} || {}
$$p{'keys'}
Truth table50%1/2
A
A= $$p{'keys'}
Aresult
11
00
650 1 $key = "gen-key-$n";
651 1 $p->{keys}{$key} = { bits => 0 + $bits };
652 1 ▶ return _gap('openssl req -newkey ohne -nodes (Passphrase interaktiv)') unless $o->{nodes} || $o->{noenc} || defined $o->{passout};
Branch: 1 branch
BranchTrueFalseTotal
unless $$o{"nodes"} or $$o{"noenc"} or defined $$o{"passout"} 0 1 1
Condition33%2/6
$$o{"nodes"} or $$o{"noenc"} or defined $$o{"passout"}
l!l&&r!l&&!r
100
$$o{"nodes"} or $$o{"noenc"}
l!l&&r!l&&!r
100
MC/DC0%0/3
$$o{"nodes"} or $$o{"noenc"} or defined $$o{"passout"}
$$o{"nodes"} $$o{"noenc"} defined $$o{"passout"}
Truth table25%1/4
A or B or C
A= $$o{"nodes"}B= $$o{"noenc"}C= defined $$o{"passout"}
ABCresult
1XX1
01X1
0011
0000
653 1 ▶ my $kout = $o->{keyout} // 'privkey.pem';
Condition50%1/2
$$o{"keyout"} // "privkey.pem"
l!l
10
MC/DC0%0/1
$$o{"keyout"} // "privkey.pem"
$$o{"keyout"}
Truth table50%1/2
A
A= $$o{"keyout"}
Aresult
11
00
654 1 ▶ $kout = "/root/$kout" unless $kout =~ m{\A/};
Branch: 1 branch
BranchTrueFalseTotal
unless $kout =~ m[\A/] 0 1 1
655 1 my ( $we, $wok ) = _write_key( $dev, $kout, pem( key => $key ), $ctx, 1 );
656 1 ▶ return ( $we, 0 ) unless $wok;
Branch: 1 branch
BranchTrueFalseTotal
unless $wok 0 1 1
657 }
658 0 else { return _gap('openssl req ohne -key/-newkey') }
659 # Subjekt und Namen
660 3 ▶ my $cnf = defined $o->{config} ? _cnf( _text( $dev, $o->{config} ) // return ( "Can't open \"$o->{config}\" for reading, No such file or directory", 0 ) ) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $$o{'config'} ? : 1 2 3
Condition50%1/2
_text($dev, $$o{"config"}) // (return qq[Can't open "$$o{"config"}" for reading, No such file or directory], 0)
l!l
10
MC/DC0%0/1
_text($dev, $$o{"config"}) // (return qq[Can't open "$$o{"config"}" for reading, No such file or directory], 0)
_text($dev, $$o{"config"})
Truth table50%1/2
A
A= _text($dev, $$o{"config"})
Aresult
11
00
661 3 my $subject = _subj( $o->{subj} );
662 3 ▶ if ( !defined $subject && defined $o->{config} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $subject and defined $$o{"config"}) 1 2 3
Condition66%2/3
not defined $subject and defined $$o{"config"}
!ll&&!rl&&r
201
MC/DC50%1/2
not defined $subject and defined $$o{"config"}
not defined $subject defined $$o{"config"}
Truth table66%2/3
not(A) and B
A= not defined $subjectB= defined $$o{"config"}
ABresult
0X0
100
111
663 1 my $dsec = _cnf_get( $cnf, 'req', 'distinguished_name' );
664 1 ▶ if ( defined $dsec && ( _cnf_get( $cnf, 'req', 'prompt' ) // '' ) eq 'no' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dsec and (_cnf_get($cnf, "req", "prompt") // "") eq "no") 1 0 1
Condition40%2/5
defined $dsec and (_cnf_get($cnf, "req", "prompt") // "") eq "no"
!ll&&!rl&&r
001
_cnf_get($cnf, "req", "prompt") // ""
l!l
10
MC/DC0%0/2
defined $dsec and (_cnf_get($cnf, "req", "prompt") // "") eq "no"
defined $dsec _cnf_get($cnf, "req", "prompt")
Truth table33%1/3
A and B
A= defined $dsecB= _cnf_get($cnf, "req", "prompt")
ABresult
0X0
100
111
665 1 ▶ $subject = join ',', map {"$_->[0]=$_->[1]"} @{ $cnf->{$dsec} || [] };
Condition50%1/2
$$cnf{$dsec} || []
l!l
10
MC/DC0%0/1
$$cnf{$dsec} || []
$$cnf{$dsec}
Truth table50%1/2
A
A= $$cnf{$dsec}
Aresult
11
00
666 }
667 }
668 3 ▶ return _gap('openssl req (interaktive Abfrage des Subjekts)') unless defined $subject;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subject 0 3 3
669 3 ▶ my @sans = map { _sans_from($_) } grep {/\A\s*subjectAltName\s*=/} @{ $o->{addext} || [] };
Condition100%2/2
$$o{'addext'} || []
l!l
12
MC/DC100%1/1
$$o{'addext'} || []
$$o{'addext'}
Truth table100%2/2
A
A= $$o{'addext'}
Aresult
11
00
670 3 ▶ if ( defined $o->{config} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$o{"config"}) 1 2 3
671 1 ▶ my $xsec = $o->{x509} ? ( $o->{extensions} // _cnf_get( $cnf, 'req', 'x509_extensions' ) ) : ( $o->{reqexts} // _cnf_get( $cnf, 'req', 'req_extensions' ) );
Branch: 1 branch
BranchTrueFalseTotal
$$o{'x509'} ? : 0 1 1
Condition16%1/6
$$o{"extensions"} // _cnf_get($cnf, "req", "x509_extensions")
l!l&&r!l&&!r
000
$$o{"reqexts"} // _cnf_get($cnf, "req", "req_extensions")
l!l&&r!l&&!r
010
MC/DC0%0/2
$$o{"extensions"} // _cnf_get($cnf, "req", "x509_extensions")
$$o{"extensions"} _cnf_get($cnf, "req", "x509_extensions")
MC/DC0%0/2
$$o{"reqexts"} // _cnf_get($cnf, "req", "req_extensions")
$$o{"reqexts"} _cnf_get($cnf, "req", "req_extensions")
Truth table0%0/3
A // B
A= $$o{"extensions"}B= _cnf_get($cnf, "req", "x509_extensions")
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $$o{"reqexts"}B= _cnf_get($cnf, "req", "req_extensions")
ABresult
1X1
011
000
672 1 ▶ push @sans, _cnf_sans( $cnf, $xsec ) if defined $xsec;
Branch: 1 branch
BranchTrueFalseTotal
if defined $xsec 1 0 1
673 }
674 3 my $out = $o->{out};
675 3 ▶ if ( $o->{x509} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$o{"x509"}) 1 2 3
676 1 ▶ my $n = 1 + scalar grep {/\Agen-cert-/} keys %{ $p->{certs} || {} };
Condition50%1/2
$$p{'certs'} || {}
l!l
10
MC/DC0%0/1
$$p{'certs'} || {}
$$p{'certs'}
Truth table50%1/2
A
A= $$p{'certs'}
Aresult
11
00
677 1 my $id = "gen-cert-$n";
678 1 my $now = _epoch( $cat->{now} );
679 1 my %seen;
680 0 ▶ $p->{certs}{$id} = { subject => $subject, sans => [ grep { !$seen{$_}++ } map { s/\ADNS://r } @sans ], issuer => $id, ca => 1, key => $key,
Branch: 1 branch
BranchTrueFalseTotal
$$o{'days'} && $$o{'days'} =~ /\A\d+\z/ ? : 1 0 1
Condition33%1/3
$$o{"days"} and $$o{"days"} =~ /\A\d+\z/
!ll&&!rl&&r
001
MC/DC0%0/2
$$o{"days"} and $$o{"days"} =~ /\A\d+\z/
$$o{"days"} $$o{"days"} =~ /\A\d+\z/
Truth table33%1/3
A and B
A= $$o{"days"}B= $$o{"days"} =~ /\A\d+\z/
ABresult
0X0
100
111
681 1 not_before => _iso($now), not_after => _iso( $now + 86400 * ( $o->{days} && $o->{days} =~ /\A\d+\z/ ? $o->{days} : 30 ) ) };
682 1 my $text = pem( cert => $id );
683 1 ▶ return ( $text =~ s/\n\z//r, 1 ) unless defined $out;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 0 1 1
684 1 my ( $we, $wok ) = Langertha::Holmgang::Sim::Linux::_write_path( $dev, $out, $text, 0, $ctx );
685 1 return ( $we, $wok );
686 }
687 2 my $text = _csr_pem( _canon_csr( subject => $subject, sans => \@sans, key => $key ) );
688 2 ▶ return ( $text =~ s/\n\z//r, 1 ) unless defined $out;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out 0 2 2
689 2 my ( $we, $wok ) = Langertha::Holmgang::Sim::Linux::_write_path( $dev, $out, $text, 0, $ctx );
690 2 return ( $we, $wok );
691 }
692  
693 # --- update-ca-certificates -----------------------------------------------------
694  
695  
696 4 ▶sub update_ca_certificates {
Subroutine update_ca_certificates: called CC=12 SCAR=29.8
Pod documented
697 4 my ( $dev, $av, $ctx ) = @_;
698 4 ▶ my $p = $dev->{pki} //= {};
Condition50%1/2
$$dev{"pki"} //= {}
l!l
40
MC/DC0%0/1
$$dev{"pki"} //= {}
$$dev{"pki"}
Truth table50%1/2
A
A= $$dev{"pki"}
Aresult
11
00
699 4 ▶ my @old = @{ $p->{installed} || [] };
Condition50%1/2
$$p{'installed'} || []
l!l
04
MC/DC0%0/1
$$p{'installed'} || []
$$p{'installed'}
Truth table50%1/2
A
A= $$p{'installed'}
Aresult
11
00
700 4 my @new;
701 4 for my $f ( Langertha::Holmgang::Sim::Linux::_under( $dev, '/usr/local/share/ca-certificates' ) ) {
702 6 ▶ next unless $f =~ /\.crt\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /\.crt\z/ 4 2 6
703 2 ▶ push @new, _cert_ids( _text( $dev, $f ) // '' );
Condition50%1/2
_text($dev, $f) // ""
l!l
20
MC/DC0%0/1
_text($dev, $f) // ""
_text($dev, $f)
Truth table50%1/2
A
A= _text($dev, $f)
Aresult
11
00
704 }
705 0 my %o = map { $_ => 1 } @old;
706 4 my %n = map { $_ => 1 } @new;
707 4 my $add = grep { !$o{$_} } keys %n;
708 0 my $rem = grep { !$n{$_} } keys %o;
709 4 my @sorted = sort keys %n;
710 4 ▶ if ( join( ',', @sorted ) ne join( ',', sort @old ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (join(",", @sorted) ne join(",", sort(@old))) 2 2 4
711 2 ▶ if (@sorted) { $p->{installed} = \@sorted }
Branch: 1 branch
BranchTrueFalseTotal
if (@sorted) { } 2 0 2
712 0 else { delete $p->{installed} }
713 }
714 # das Buendel wird neu geschrieben: von Hand Angehaengtes faellt heraus
715 4 my $bundle = '/etc/ssl/certs/ca-certificates.crt';
716 4 ▶ if ( Langertha::Holmgang::Sim::Linux::_file_entry( $dev, $bundle ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Langertha::Holmgang::Sim::Linux::_file_entry($dev, $bundle)) 0 4 4
717 0 ▶ my $t = join '', map { pem( cert => $_ ) } @{ $p->{trusted} || [] }, @sorted;
Condition0%0/2
$$p{'trusted'} || []
l!l
00
MC/DC0%0/1
$$p{'trusted'} || []
$$p{'trusted'}
Truth table0%0/2
A
A= $$p{'trusted'}
Aresult
11
00
718 0 ▶ Langertha::Holmgang::Sim::Linux::_file_set( $dev, $bundle, $t ) if $t ne ( _text( $dev, $bundle ) // '' );
Branch: 1 branch
BranchTrueFalseTotal
if $t ne (_text($dev, $bundle) // "") 0 0 0
Condition0%0/2
_text($dev, $bundle) // ""
l!l
00
MC/DC0%0/1
_text($dev, $bundle) // ""
_text($dev, $bundle)
Truth table0%0/2
A
A= _text($dev, $bundle)
Aresult
11
00
719 }
720 4 return ( "Updating certificates in /etc/ssl/certs...\n$add added, $rem removed; done.\nRunning hooks in /etc/ca-certificates/update.d...\ndone.", 1 );
721 }
722  
723 4 1;
724  
725 __END__
« blib/lib/Langertha/Holmgang/ToolSchema.pm ↑ Summary blib/lib/Langertha/Holmgang/Shell/Filter.pm »