| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$t // ""
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$rev{$label} // "other"
$rev{$label}
Truth table50%1/2
A
A= $rev{$label}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 64 | my ( $tag, $id ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 64 | ▶ | my $want = $kind eq 'enckey' ? 'key' : $kind; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 64 | ▶ | if ( $tag eq $want ) { push @b, { kind => $kind, id => $id, text => $block }; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || {}
MC/DC0%0/1
$state || {}
$state
Truth table50%1/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 878 | ▶ | my $p = ref $state->{$h} eq 'HASH' ? $state->{$h}{pki} : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 878 | ▶ | next unless ref $p eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 284 | ▶ | %{ $c{certs} } = ( %{ $c{certs} }, %{ $p->{certs} || {} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$p{'certs'} || {}
MC/DC100%1/1
$$p{'certs'} || {}
$$p{'certs'}
Truth table100%2/2
A
A= $$p{'certs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 284 | ▶ | %{ $c{keys} } = ( %{ $c{keys} }, %{ $p->{keys} || {} } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$p{'keys'} || {}
MC/DC100%1/1
$$p{'keys'} || {}
$$p{'keys'}
Truth table100%2/2
A
A= $$p{'keys'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 284 | ▶ | $c{now} //= $p->{now}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$c{"now"} //= $$p{"now"}
MC/DC50%1/2
$c{"now"} //= $$p{"now"}
$c{"now"}
$$p{"now"}
Truth table66%2/3
A //= B
A= $c{"now"}B= $$p{"now"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 340 | ▶ | $c{now} //= '2026-10-24T08:00:00Z'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$c{"now"} //= "2026-10-24T08:00:00Z"
MC/DC100%1/1
$c{"now"} //= "2026-10-24T08:00:00Z"
$c{"now"}
Truth table100%2/2
A
A= $c{"now"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$t // ""
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 315 | ▶ | return Time::Local::timegm( $S // 0, $M // 0, $H // 0, $d, $m - 1, $y ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
$S // 0
$M // 0
$H // 0
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
Truth table50%1/2
A
A= $M
Truth table50%1/2
A
A= $H
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 // ""
$s // ""
MC/DC0%0/1
$v // ""
$v
MC/DC0%0/1
$s // ""
$s
Truth table50%1/2
A
A= $v
Truth table50%1/2
A
A= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$s // ""
MC/DC0%0/1
$s // ""
$s
Truth table0%0/2
A
A= $s
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || []
MC/DC0%0/1
$trust || []
$trust
Truth table50%1/2
A
A= $trust
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 36 | ▶ | my %inter = map { $_ => 1 } @{ $inter || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$inter || []
MC/DC0%0/1
$inter || []
$inter
Truth table50%1/2
A
A= $inter
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 50 | ▶ | return { code => 10, depth => $depth, cert => $cur } if _epoch( $c->{not_after} ) && $now > _epoch( $c->{not_after} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
_epoch($$c{"not_after"}) and $now > _epoch($$c{"not_after"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 49 | ▶ | return { code => 9, depth => $depth, cert => $cur } if _epoch( $c->{not_before} ) && $now < _epoch( $c->{not_before} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
_epoch($$c{"not_before"}) and $now < _epoch($$c{"not_before"})
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 49 | ▶ | my $iss = $c->{issuer} // $cur; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$c{"issuer"} // $cur
MC/DC0%0/2
$$c{"issuer"} // $cur
$$c{"issuer"}
$cur
Truth table33%1/3
A // B
A= $$c{"issuer"}B= $cur
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 49 | ▶ | if ( $iss eq $cur ) { # selbst signiert: Anker nur, wenn vertraut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | return undef if $trust{$cur}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | return { code => $depth ? 19 : 18, depth => $depth, cert => $cur }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 41 | ▶ | my $have = $trust{$iss} || $inter{$iss}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$trust{$iss} || $inter{$iss}
MC/DC100%2/2
$trust{$iss} || $inter{$iss}
$trust{$iss}
$inter{$iss}
Truth table100%3/3
A || B
A= $trust{$iss}B= $inter{$iss}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 41 | ▶ | return { code => $from_trust ? 2 : 20, depth => $depth, cert => $cur } unless $have && !$seen{$iss}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$have and not $seen{$iss}++
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}++
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 14 | my $ic = $cat->{certs}{$iss}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 14 | ▶ | return { code => 24, depth => $depth + 1, cert => $iss } if $ic && !$ic->{ca}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ic and not $$ic{"ca"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 14 | ▶ | ( $cur, $depth, $from_trust ) = ( $iss, $depth + 1, $trust{$iss} ? 1 : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table50%1/2
A
A= $$c{'sans'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | @n = grep {defined} _cn( $c->{subject} ) unless @n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ( $x =~ /\A\*\.(.+)\z/ ) { my $d = $1; return 1 if $name =~ /\A[^.]+\.\Q$d\E\z/ } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%4/4
$$p{'trusted'} || []
$$p{'installed'} || []
MC/DC100%1/1
$$p{'trusted'} || []
$$p{'trusted'}
MC/DC100%1/1
$$p{'installed'} || []
$$p{'installed'}
Truth table100%2/2
A
A= $$p{'trusted'}
Truth table100%2/2
A
A= $$p{'installed'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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} || {}
MC/DC0%0/1
$$state{$from} || {}
$$state{$from}
Truth table50%1/2
A
A= $$state{$from}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 34 | ▶ | my @chain = @{ $tls->{chain} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$tls{'chain'} || []
MC/DC0%0/1
$$tls{'chain'} || []
$$tls{'chain'}
Truth table50%1/2
A
A= $$tls{'chain'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 34 | ▶ | return [ 35, '(35) OpenSSL/3.0.15: error:0A000410:SSL routines::sslv3 alert handshake failure' ] unless @chain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 34 | my $trust = trust_of($dev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 34 | ▶ | if ( defined $req->{cacert} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $trust = [ _cert_ids($t) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 34 | ▶ | if ( my $e = verify_chain( $cat, $chain[0], [ @chain[ 1 .. $#chain ] ], $trust ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 27 | return [ 60, "(60) SSL certificate problem: $ERR{ $e->{code} }" ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 7 | ▶ | my $host = $req->{host} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$req{"host"} // ""
MC/DC0%0/1
$$req{"host"} // ""
$$req{"host"}
Truth table50%1/2
A
A= $$req{"host"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 7 | ▶ | my $leaf = $cat->{certs}{ $chain[0] } || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$cat{'certs'}{$chain[0]} || {}
MC/DC0%0/1
$$cat{'certs'}{$chain[0]} || {}
$$cat{'certs'}{$chain[0]}
Truth table50%1/2
A
A= $$cat{'certs'}{$chain[0]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 7 | ▶ | return [ 60, "(60) SSL: no alternative certificate subject name matches target host name '$host'" ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%2/4
($$tls{"chain"} || [])->[0] // ""
$$tls{'chain'} || []
MC/DC0%0/1
($$tls{"chain"} || [])->[0] // ""
$$tls{'chain'}
Truth table50%1/2
A
A= $$tls{'chain'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'} || []
($$cat{"certs"}{$$c{"issuer"} // ""}{"subject"} // $$c{"issuer"}) // ""
$$cat{"certs"}{$$c{"issuer"} // ""}{"subject"} // $$c{"issuer"}
$$c{"issuer"} // ""
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'}
Truth table33%1/3
A // B
A= $$cat{"certs"}{$$c{"issuer"} // ""}{"subject"}B= $$c{"issuer"}
Truth table50%1/2
A
A= $$c{"issuer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 36 | ▶ | '* issuer: ' . ( $cat->{certs}{ $c->{issuer} // '' }{subject} // $c->{issuer} // '' ) =~ s/,\s*/; /gr ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$c{"subject"} // ""
MC/DC0%0/1
$$c{"subject"} // ""
$$c{"subject"}
Truth table50%1/2
A
A= $$c{"subject"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 61 | my $x = shift @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 61 | ▶ | if ( $x =~ /\A--?([\w.:-]+)\z/ && exists $spec{$1} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$x =~ /\A--?([\w.:-]+)\z/ and exists $spec{$1}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 60 | my $k = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 60 | ▶ | if ( $spec{$k} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 33 | ▶ | return ( undef, "$k: Option requires an argument" ) unless @a; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 33 | my $v = shift @a; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 33 | ▶ | if ( $spec{$k} == 2 ) { push @{ $o{$k} }, $v } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)"))
MC/DC0%0/1
shift @a // (return _gap("openssl (interaktiv)"))
shift @a
Truth table50%1/2
A
A= shift @a
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 21 | ▶ | my $state = $ctx->{state} || { $ctx->{host} => $dev }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$ctx{'state'} || {$$ctx{'host'}, $dev}
MC/DC0%0/1
$$ctx{'state'} || {$$ctx{'host'}, $dev}
$$ctx{'state'}
Truth table50%1/2
A
A= $$ctx{'state'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 12 | return ($t); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 1 | ▶ | return ( $stdin // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$stdin // ""
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 6 | my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'certificate' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 6 | ▶ | return ( $err, 0 ) unless defined $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | ▶ | my ($b) = grep { $_->{kind} eq 'cert' || $_->{kind} eq 'bad' } blocks($t); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$_{'kind'} eq 'cert' || $$_{'kind'} eq 'bad'
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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 6 | my $cat = catalog($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 6 | ▶ | my $c = $b && $b->{kind} eq 'cert' ? $cat->{certs}{ $b->{id} } : undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$b and $$b{"kind"} eq "cert"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 6 | ▶ | return ( 'Could not read certificate from ' . ( $o->{in} // '<stdin>' ) . "\nUnable to load certificate", 0 ) unless $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$$o{"in"} // "<stdin>"
MC/DC0%0/1
$$o{"in"} // "<stdin>"
$$o{"in"}
Truth table0%0/2
A
A= $$o{"in"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 6 | my $id = $b->{id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 6 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 6 | ▶ | my $alg = $o->{sha256} ? 'sha256' : $o->{md5} ? 'md5' : 'sha1'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 6 | ▶ | for my $k ( @{ $o->{_order} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$o{'_order'} || []
MC/DC0%0/1
$$o{'_order'} || []
$$o{'_order'}
Truth table50%1/2
A
A= $$o{'_order'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 13 | ▶ | if ( $k eq 'subject' ) { push @out, 'subject=' . dn( $c->{subject} ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 14 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1 | ▶ | elsif ( $k eq 'issuer' ) { push @out, 'issuer=' . dn( ( $cat->{certs}{ $c->{issuer} // '' } || $c )->{subject} ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
$$c{"issuer"} // ""
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
Truth table50%1/2
A
A= $$c{"issuer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | elsif ( $k eq 'modulus' ) { push @out, 'Modulus=' . modulus( $c->{key} // $id ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$$c{"key"} // $id
MC/DC0%0/2
$$c{"key"} // $id
$$c{"key"}
$id
Truth table33%1/3
A // B
A= $$c{"key"}B= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | ▶ | elsif ( $k eq 'pubkey' ) { push @out, pem( pub => $c->{key} // $id ) =~ s/\n\z//r } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$$c{"key"} // $id
MC/DC0%0/2
$$c{"key"} // $id
$$c{"key"}
$id
Truth table0%0/3
A // B
A= $$c{"key"}B= $id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"
$$c{"subject"} // ""
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"
Truth table0%0/2
A
A= $$c{"subject"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
$$c{"issuer"} // ""
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
Truth table0%0/2
A
A= $$c{"issuer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | elsif ( $k eq 'ocsp_uri' ) { push @out, 'http://ocsp.example.net' } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 6 | ▶ | if ( defined $o->{ext} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | for my $x ( split /,/, $o->{ext} ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | if ( $x eq 'subjectAltName' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | push @out, 'X509v3 Subject Alternative Name: ', ' ' . join( ', ', map { /\A(?:DNS|IP)/ ? $_ : "DNS:$_" } @{ $c->{sans} || [] } ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$$c{'sans'} || []
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table0%0/2
A
A= $$c{'sans'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if @{ $c->{sans} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$$c{'sans'} || []
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table0%0/2
A
A= $$c{'sans'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | elsif ( $x eq 'basicConstraints' ) { push @out, 'X509v3 Basic Constraints: critical', ' CA:' . ( $c->{ca} ? 'TRUE' : 'FALSE' ) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | my $exp = _epoch( $c->{not_after} ) <= _epoch( $cat->{now} ) + ( $o->{checkend} =~ /\A\d+\z/ ? $o->{checkend} : 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | ▶ | push @out, $exp ? 'Certificate will expire' : 'Certificate will not expire'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | $ok = $exp ? 0 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 6 | ▶ | if ( !$o->{noout} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if ( defined $o->{out} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
$$c{"issuer"} // ""
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
Truth table0%0/2
A
A= $$c{"issuer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | ▶ | my $bits = ( $cat->{keys}{ $c->{key} // '' } || {} )->{bits} // 2048; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
($$cat{"keys"}{$$c{"key"} // ""} || {})->{"bits"} // 2048
$$cat{'keys'}{$$c{'key'} // ''} || {}
$$c{"key"} // ""
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'} // ''}
Truth table0%0/2
A
A= $$c{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$$c{"serial"} // _hex("serial:$id", 32)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | push @l, ' X509v3 Subject Alternative Name: ', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | ' ' . join( ', ', map { /\A(?:DNS|IP)/ ? $_ : "DNS:$_" } @{ $c->{sans} } ) if @{ $c->{sans} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
$$c{'sans'} || []
MC/DC0%0/1
$$c{'sans'} || []
$$c{'sans'}
Truth table0%0/2
A
A= $$c{'sans'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 2 | ▶ | return $1 if $spec =~ /\Apass:(.*)\z/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if ( $spec =~ /\Afile:(.+)\z/ ) { my $t = _text( $dev, $1 ); return defined $t ? ( split /\n/, $t )[0] // '' : undef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/2
(split(/\n/, $t, 0))[0] // ""
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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'
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'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 7 | ▶ | return ( undef, "Could not read private key from $path" ) unless $b && $cat->{keys}{ $b->{id} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$b and $$cat{"keys"}{$$b{"id"}}
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"}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | ▶ | if ( $b->{kind} eq 'enckey' ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | ▶ | my $want = $cat->{keys}{ $b->{id} }{passphrase} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$cat{"keys"}{$$b{"id"}}{"passphrase"} // ""
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 2 | ▶ | return ( undef, "Could not read private key from $path" ) unless $p eq $want; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 5 | my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'private key' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 5 | ▶ | return ( $err, 0 ) unless defined $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 5 | my $cat = catalog($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 5 | ▶ | my $path = $o->{in} // '<stdin>'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$o{"in"} // "<stdin>"
MC/DC0%0/1
$$o{"in"} // "<stdin>"
$$o{"in"}
Truth table50%1/2
A
A= $$o{"in"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 5 | ▶ | if ( $o->{pubin} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 3 | ▶ | my $k = $cat->{keys}{$id} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$cat{'keys'}{$id} || {}
MC/DC0%0/1
$$cat{'keys'}{$id} || {}
$$cat{'keys'}{$id}
Truth table50%1/2
A
A= $$cat{'keys'}{$id}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 3 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 3 | ▶ | push @out, 'Modulus=' . modulus($id) if $o->{modulus}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 3 | ▶ | push @out, $cmd eq 'rsa' ? 'RSA key ok' : 'Key is valid' if $o->{check}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$$k{"bits"} // 2048
MC/DC0%0/1
$$k{"bits"} // 2048
$$k{"bits"}
Truth table0%0/2
A
A= $$k{"bits"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 3 | ▶ | if ( !$o->{noout} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 1 | ▶ | my $text = $o->{pubout} ? pem( pub => $id ) : pem( ( $o->{aes256} || $o->{des3} ) ? 'enckey' : 'key', $id ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$$o{"aes256"} or $$o{"des3"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 1 | ▶ | if ( defined $o->{out} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | my ( $we, $wok ) = _write_key( $dev, $o->{out}, $text, $ctx, !$o->{pubout} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | ▶ | return ( $we, 0 ) unless $wok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | push @out, 'writing RSA key' if $cmd eq 'rsa'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$ok and $private and $new
$ok and $private
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | my $cat = catalog($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | my $trust = trust_of($dev); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 1 | ▶ | if ( defined $o->{CAfile} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | ▶ | $trust = [ $o->{'no-CAfile'} ? () : (), _cert_ids($t) ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | my @inter = map { my $t = _text( $dev, $_ ); defined $t ? _cert_ids($t) : () } @{ $o->{untrusted} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$o{'untrusted'} || []
MC/DC0%0/1
$$o{'untrusted'} || []
$$o{'untrusted'}
Truth table50%1/2
A
A= $$o{'untrusted'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | my @files = @{ $o->{_rest} }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | @files = ('stdin') unless @files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$stdin // ""
MC/DC0%0/1
$stdin // ""
$stdin
Truth table0%0/2
A
A= $stdin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $id and $$cat{"certs"}{$id}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1 | ▶ | if ( my $r = verify_chain( $cat, $id, \@inter, $trust ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | ▶ | my $c = $cat->{certs}{ $r->{cert} } || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$cat{'certs'}{$$r{'cert'}} || {}
MC/DC0%0/1
$$cat{'certs'}{$$r{'cert'}} || {}
$$cat{'certs'}{$$r{'cert'}}
Truth table50%1/2
A
A= $$cat{'certs'}{$$r{'cert'}}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
MC/DC0%0/1
$$c{"subject"} // ""
$$c{"subject"}
Truth table50%1/2
A
A= $$c{"subject"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 1 | ▶ | my $c = $o->{connect} // $o->{_rest}[0] // 'localhost:443'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
($$o{"connect"} // $$o{"_rest"}[0]) // "localhost:443"
$$o{"connect"} // $$o{"_rest"}[0]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | my ( $host, $port ) = $c =~ /\A\[?([^\]]+?)\]?(?::(\d+))?\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | $port //= 443; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$port //= 443
MC/DC0%0/1
$port //= 443
$port
Truth table50%1/2
A
A= $port
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$$o{"servername"} // ($host =~ /\A[\d.]+\z/ ? undef : $host)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$sni // $host
$$o{"key"} // $$o{"cert"}
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
Truth table0%0/3
A // B
A= $$o{"key"}B= $$o{"cert"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 1 | ▶ | if ( defined $res->{error} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$$res{"code"} // 0
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$$res{"code"} // 0
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/5
($$res{"code"} // 0) == 35 and $$res{"error"} =~ /wrong version/
$$res{"code"} // 0
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$$res{"code"} // 0
MC/DC0%0/1
$$res{"code"} // 0
$$res{"code"}
Truth table0%0/2
A
A= $$res{"code"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | return ( "CONNECTED(00000003)\n$res->{error}", 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 1 | ▶ | my $tls = $res->{tls} or return ( 'CONNECTED(00000003)', 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | my $cat = catalog($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | my @chain = @{ $tls->{chain} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$tls{'chain'} || []
MC/DC0%0/1
$$tls{'chain'} || []
$$tls{'chain'}
Truth table50%1/2
A
A= $$tls{'chain'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | ▶ | my $r = @chain ? verify_chain( $cat, $chain[0], [ @chain[ 1 .. $#chain ] ], $trust ) : { code => 20, depth => 0 }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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]} || {}
MC/DC0%0/1
$$cat{'certs'}{$_[0]} || {}
$$cat{'certs'}{$_[0]}
Truth table50%1/2
A
A= $$cat{'certs'}{$_[0]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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]} || {}
($$cat{"certs"}{$$x{"issuer"} // ""} || {})->{"subject"} // $$x{"issuer"}
$$cat{'certs'}{$$x{'issuer'} // ''} || {}
$$x{"issuer"} // ""
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]}
Truth table33%1/3
A // B
A= $$cat{'certs'}{$$x{'issuer'} // ''}B= $$x{"issuer"}
Truth table50%1/2
A
A= $$x{"issuer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | ▶ | if ($r) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | for ( my $d = $r->{depth}; $d >= 0; $d-- ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | my $id = $chain[$d] // $r->{cert}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$chain[$d] // $$r{"cert"}
MC/DC0%0/2
$chain[$d] // $$r{"cert"}
$chain[$d]
$$r{"cert"}
Truth table0%0/3
A // B
A= $chain[$d]B= $$r{"cert"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$d == 0 and $$r{"code"} == 20 and $$r{"depth"} == 0
$d == 0 and $$r{"code"} == 20
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 3 | ▶ | my $id = $d <= $n ? $chain[$d] : ( $cat->{certs}{ $chain[$n] } || {} )->{issuer}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$cat{'certs'}{$chain[$n]} || {}
MC/DC0%0/1
$$cat{'certs'}{$chain[$n]} || {}
$$cat{'certs'}{$chain[$n]}
Truth table50%1/2
A
A= $$cat{'certs'}{$chain[$n]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 3 | ▶ | next unless defined $id && $cat->{certs}{$id}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $id and $$cat{"certs"}{$id}
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}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | ▶ | next if $d == $n + 1 && $id eq $chain[$n]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$d == $n + 1 and $id eq $chain[$n]
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]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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]} || {}
MC/DC0%0/1
$$cat{'certs'}{$chain[$i]} || {}
$$cat{'certs'}{$chain[$i]}
Truth table50%1/2
A
A= $$cat{'certs'}{$chain[$i]}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
$$cat{'keys'}{$$x{'key'} // ''} || {}
$$x{"key"} // ""
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'} // ''}
Truth table50%1/2
A
A= $$x{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 2 | ▶ | push @l, pem( cert => $chain[$i] ) =~ s/\n\z//r if $o->{showcerts}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 1 | ▶ | my $code = $r ? ( $r->{code} == 20 && $r->{depth} == 0 ? 21 : $r->{code} ) : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$$r{"code"} == 20 and $$r{"depth"} == 0
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | ▶ | my $msg = $r ? $ERR{$code} : 'ok'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | my @ids; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | ▶ | for my $f ( @{ $o->{certfile} || [] } ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$o{'certfile'} || []
MC/DC0%0/1
$$o{'certfile'} || []
$$o{'certfile'}
Truth table50%1/2
A
A= $$o{'certfile'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 1 | my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'PKCS7' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 1 | ▶ | return ( $err, 0 ) unless defined $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/2
$$o{"in"} // "<stdin>"
MC/DC0%0/1
$$o{"in"} // "<stdin>"
$$o{"in"}
Truth table0%0/2
A
A= $$o{"in"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 2 | ▶ | push @l, 'subject=' . dn( $c->{subject} ), 'issuer=' . dn( ( $cat->{certs}{ $c->{issuer} // '' } || $c )->{subject} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$$cat{'certs'}{$$c{'issuer'} // ''} || $c
$$c{"issuer"} // ""
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
Truth table50%1/2
A
A= $$c{"issuer"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 2 | ▶ | push @l, pem( cert => $id ) =~ s/\n\z//r unless $o->{noout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 2 | push @l, ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 1 | ▶ | pop @l if @l && $l[-1] eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@l and $l[-1] eq ""
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 ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 2 | my @files; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | ▶ | for (@a) { if (/\A-(sha256|sha1|md5|sha512)\z/) { $alg = $1 } elsif ( !/\A-/ ) { push @files, $_ } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | my @out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | ▶ | for my $f ( @files ? @files : (undef) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 2 | ▶ | my $t = defined $f ? _text( $dev, $f ) : $stdin // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$stdin // ""
MC/DC0%0/1
$stdin // ""
$stdin
Truth table50%1/2
A
A= $stdin
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 2 | ▶ | return ( "Can't open \"$f\" for reading, No such file or directory", 0 ) unless defined $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | ▶ | push @out, uc( $alg eq 'sha256' ? 'SHA2-256' : $alg eq 'sha512' ? 'SHA2-512' : $alg ) . '(' . ( $f // 'stdin' ) . ")= $h"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$f // "stdin"
MC/DC0%0/1
$f // "stdin"
$f
Truth table50%1/2
A
A= $f
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 // ""
MC/DC0%0/1
$v // ""
$v
Truth table50%1/2
A
A= $v
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 // ""
MC/DC0%0/1
$t // ""
$t
Truth table50%1/2
A
A= $t
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 11 | $l =~ s/#.*//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 11 | ▶ | next unless $l =~ /\S/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 11 | ▶ | if ( $l =~ /^\s*\[\s*([^\]\s]+)\s*\]/ ) { $cur = $1; next } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 7 | ▶ | my ( $k, $v ) = $l =~ /^\s*([^=]+?)\s*=\s*(.*?)\s*$/ or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$$c{$sec} || []
MC/DC0%0/1
$$c{$sec} || []
$$c{$sec}
Truth table50%1/2
A
A= $$c{$sec}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 ())
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | if ( $v =~ /\A\@(\S+)\z/ ) { return map { my ( $t, undef ) = split /\./, $_->[0]; "$t:$_->[1]" } @{ $c->{$1} || [] } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$$c{$1} || []
MC/DC0%0/1
$$c{$1} || []
$$c{$1}
Truth table50%1/2
A
A= $$c{$1}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
$c{'sans'} || []
MC/DC0%0/1
$c{'sans'} || []
$c{'sans'}
Truth table50%1/2
A
A= $c{'sans'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} // ""
MC/DC0%0/1
$c{"subject"} // ""
$c{"subject"}
Truth table50%1/2
A
A= $c{"subject"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 4 | my $cat = catalog($state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 4 | ▶ | my $p = $dev->{pki} //= {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$dev{"pki"} //= {}
MC/DC0%0/1
$$dev{"pki"} //= {}
$$dev{"pki"}
Truth table50%1/2
A
A= $$dev{"pki"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 4 | ▶ | if ( !$o->{new} && !$o->{x509} ) { # CSR lesen | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$$o{"new"} or $$o{"x509"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | my ( $t, $err ) = _read_in( $dev, $o, $stdin, 'certificate request' ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 1 | ▶ | return ( $err, 0 ) unless defined $t; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | my ($b) = grep { $_->{kind} eq 'csr' } blocks($t); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 1 | ▶ | return ( 'Unable to load X509 request', 0 ) unless $b; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | ▶ | my $c = eval { $JSON->decode( _enc_bytes( $b->{id} ) ) } or return ( 'Unable to load X509 request', 0 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 1 | my @l; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | ▶ | push @l, 'Certificate request self-signature verify OK' if $o->{verify}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 1 | ▶ | push @l, 'subject=' . dn( _dn_from_hash( $c->{subject} ) ) if $o->{subject}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%3/6
($$cat{"keys"}{$$c{"key"} // ""} || {})->{"bits"} // 2048
$$cat{'keys'}{$$c{'key'} // ''} || {}
$$c{"key"} // ""
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'} // ''}
Truth table50%1/2
A
A= $$c{"key"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 1 | ▶ | push @l, $b->{text} =~ s/\n\z//r unless $o->{noout}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 1 | return ( join( "\n", @l ), 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | # Schluessel | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 3 | my $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 3 | ▶ | if ( defined $o->{key} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | ▶ | my $n = 1 + scalar grep {/\Agen-key-/} keys %{ $p->{keys} || {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$p{'keys'} || {}
MC/DC0%0/1
$$p{'keys'} || {}
$$p{'keys'}
Truth table50%1/2
A
A= $$p{'keys'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
$$o{"nodes"} or $$o{"noenc"} or defined $$o{"passout"}
$$o{"nodes"} or $$o{"noenc"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | ▶ | my $kout = $o->{keyout} // 'privkey.pem'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$o{"keyout"} // "privkey.pem"
MC/DC0%0/1
$$o{"keyout"} // "privkey.pem"
$$o{"keyout"}
Truth table50%1/2
A
A= $$o{"keyout"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 1 | ▶ | $kout = "/root/$kout" unless $kout =~ m{\A/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 1 | my ( $we, $wok ) = _write_key( $dev, $kout, pem( key => $key ), $ctx, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | ▶ | return ( $we, 0 ) unless $wok; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition50%1/2
_text($dev, $$o{"config"}) // (return qq[Can't open "$$o{"config"}" for reading, No such file or directory], 0)
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"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 3 | my $subject = _subj( $o->{subj} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 3 | ▶ | if ( !defined $subject && defined $o->{config} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $subject and defined $$o{"config"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition40%2/5
defined $dsec and (_cnf_get($cnf, "req", "prompt") // "") eq "no"
_cnf_get($cnf, "req", "prompt") // ""
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 1 | ▶ | $subject = join ',', map {"$_->[0]=$_->[1]"} @{ $cnf->{$dsec} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$cnf{$dsec} || []
MC/DC0%0/1
$$cnf{$dsec} || []
$$cnf{$dsec}
Truth table50%1/2
A
A= $$cnf{$dsec}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 3 | ▶ | return _gap('openssl req (interaktive Abfrage des Subjekts)') unless defined $subject; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 3 | ▶ | my @sans = map { _sans_from($_) } grep {/\A\s*subjectAltName\s*=/} @{ $o->{addext} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$o{'addext'} || []
MC/DC100%1/1
$$o{'addext'} || []
$$o{'addext'}
Truth table100%2/2
A
A= $$o{'addext'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 3 | ▶ | if ( defined $o->{config} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition16%1/6
$$o{"extensions"} // _cnf_get($cnf, "req", "x509_extensions")
$$o{"reqexts"} // _cnf_get($cnf, "req", "req_extensions")
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")
Truth table33%1/3
A // B
A= $$o{"reqexts"}B= _cnf_get($cnf, "req", "req_extensions")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 1 | ▶ | push @sans, _cnf_sans( $cnf, $xsec ) if defined $xsec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 3 | my $out = $o->{out}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 3 | ▶ | if ( $o->{x509} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 1 | ▶ | my $n = 1 + scalar grep {/\Agen-cert-/} keys %{ $p->{certs} || {} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$p{'certs'} || {}
MC/DC0%0/1
$$p{'certs'} || {}
$$p{'certs'}
Truth table50%1/2
A
A= $$p{'certs'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
$$o{"days"} and $$o{"days"} =~ /\A\d+\z/
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/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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"} //= {}
MC/DC0%0/1
$$dev{"pki"} //= {}
$$dev{"pki"}
Truth table50%1/2
A
A= $$dev{"pki"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 4 | ▶ | my @old = @{ $p->{installed} || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$p{'installed'} || []
MC/DC0%0/1
$$p{'installed'} || []
$$p{'installed'}
Truth table50%1/2
A
A= $$p{'installed'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 2 | ▶ | push @new, _cert_ids( _text( $dev, $f ) // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
_text($dev, $f) // ""
MC/DC0%0/1
_text($dev, $f) // ""
_text($dev, $f)
Truth table50%1/2
A
A= _text($dev, $f)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 2 | ▶ | if (@sorted) { $p->{installed} = \@sorted } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 0 | ▶ | my $t = join '', map { pem( cert => $_ ) } @{ $p->{trusted} || [] }, @sorted; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$$p{'trusted'} || []
MC/DC0%0/1
$$p{'trusted'} || []
$$p{'trusted'}
Truth table0%0/2
A
A= $$p{'trusted'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | ▶ | Langertha::Holmgang::Sim::Linux::_file_set( $dev, $bundle, $t ) if $t ne ( _text( $dev, $bundle ) // '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
_text($dev, $bundle) // ""
MC/DC0%0/1
_text($dev, $bundle) // ""
_text($dev, $bundle)
Truth table0%0/2
A
A= _text($dev, $bundle)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||