| 1 | package Net::SSH::Any::Test::Backend::Dropbear_Daemon; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::SSH::Any; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::SSH::Any::Constants qw(SSHA_BACKEND_ERROR); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use parent 'Net::SSH::Any::Test::Backend::_Daemon'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub _validate_backend_opts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_backend_opts: called CC=5 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my $tssh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | $tssh->SUPER::_validate_backend_opts or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # dropbear and dbclient are resolved here so that they can be used | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # as friends by any other commands | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my $opts = $tssh->{current_opts}; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | ▶ | $tssh->_be_find_cmd('dropbear') // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$tssh->_be_find_cmd("dropbear") // (return)
MC/DC0%0/1
$tssh->_be_find_cmd("dropbear") // (return)
$tssh->_be_find_cmd("dropbear")
Truth table50%1/2
A
A= $tssh->_be_find_cmd("dropbear")
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | $tssh->_be_find_cmd('dropbearconvert') // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$tssh->_be_find_cmd("dropbearconvert") // (return)
MC/DC0%0/1
$tssh->_be_find_cmd("dropbearconvert") // (return)
$tssh->_be_find_cmd("dropbearconvert")
Truth table0%0/2
A
A= $tssh->_be_find_cmd("dropbearconvert")
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $tssh->_be_find_cmd('dropbearkey') // return; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$tssh->_be_find_cmd("dropbearkey") // (return)
MC/DC0%0/1
$tssh->_be_find_cmd("dropbearkey") // (return)
$tssh->_be_find_cmd("dropbearkey")
Truth table0%0/2
A
A= $tssh->_be_find_cmd("dropbearkey")
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my $key_type = 'rsa'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | sub _extract_publickey_from_log { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_publickey_from_log: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | my ($tssh, $log, $pubkey_path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if (open my($in), '<', $log) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | while (<$in>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (/^ssh-$key_type\s+/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if (open my($out), '>', $pubkey_path) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | print $out $_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | close $out and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $tssh->_set_error(SSHA_BACKEND_ERROR, "unable to extract publickey from dropbearkey log"); | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub _create_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_key: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($tssh, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | -f "$path.dbk" and -f "$path.pub" and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-f "$path.dbk" and -f "$path.pub"
MC/DC0%0/2
-f "$path.dbk" and -f "$path.pub"
-f "$path.dbk"
-f "$path.pub"
Truth table0%0/3
A and B
A= -f "$path.dbk"B= -f "$path.pub"
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $tmppath = join('.', $path, $$, int(rand(9999999))); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | my $log_fn = $tssh->_log_fn('dropbearkey'); | |||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($tssh->_run_cmd({stdout_file => $log_fn}, 'dropbearkey', -t => $key_type, -s => 1024, -f => "$tmppath.dbk") and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath) and $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath)
MC/DC0%0/3
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk") and $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath) and $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
$tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk")
$tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath)
$tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
Truth table0%0/4
A and B and C
A= $tssh->_run_cmd({"stdout_file", $log_fn}, "dropbearkey", "-t", $key_type, "-s", 1024, "-f", "$tmppath.dbk")B= $tssh->_run_cmd({}, "dropbearconvert", "dropbear", "openssh", "$tmppath.dbk", $tmppath)C= $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | $tssh->_run_cmd({}, 'dropbearconvert', 'dropbear', 'openssh', "$tmppath.dbk", $tmppath) and | ||||||||||||||||||||||||||||||||||||||||||
| 53 | $tssh->_extract_publickey_from_log($log_fn, "$tmppath.pub")) { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | unlink $path; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | unlink "$path.pub"; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | unlink "$path.dbk"; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | chmod 0644, "$tmppath.pub"; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (rename $tmppath, $path and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
rename $tmppath, $path and rename "$tmppath.pub", "$path.pub" and rename "$tmppath.dbk", "$path.dbk"
rename $tmppath, $path and rename "$tmppath.pub", "$path.pub"
MC/DC0%0/3
rename $tmppath, $path and rename "$tmppath.pub", "$path.pub" and rename "$tmppath.dbk", "$path.dbk"
rename $tmppath, $path
rename "$tmppath.pub", "$path.pub"
rename "$tmppath.dbk", "$path.dbk"
Truth table0%0/4
A and B and C
A= rename $tmppath, $pathB= rename "$tmppath.pub", "$path.pub"C= rename "$tmppath.dbk", "$path.dbk"
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | rename "$tmppath.pub", "$path.pub" and | ||||||||||||||||||||||||||||||||||||||||||
| 60 | rename "$tmppath.dbk", "$path.dbk") { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $tssh->_log("key generated $path"); | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $tssh->_or_set_error(SSHA_BACKEND_ERROR, "key generation failed"); | |||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub _be_find_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_be_find_cmd: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | my $tssh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 1 | ▶ | my $find_opts = (ref($_[0]) ? shift : {}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | my ($name, $friend, $app, $default) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | my $opts = $tssh->{current_opts}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | $tssh->SUPER::_be_find_cmd($find_opts, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | $name, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | $friend // $opts->{local_dropbear_cmd}, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | ▶ | $app // { POSIX => 'Dropbear', MSWin => 'Cygwin' }, | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$friend // $opts->{"local_dropbear_cmd"}
$app // {"POSIX", "Dropbear", "MSWin", "Cygwin"}
MC/DC0%0/2
$friend // $opts->{"local_dropbear_cmd"}
$friend
$opts->{"local_dropbear_cmd"}
MC/DC0%0/1
$app // {"POSIX", "Dropbear", "MSWin", "Cygwin"}
$app
Truth table33%1/3
A // B
A= $friendB= $opts->{"local_dropbear_cmd"}
Truth table50%1/2
A
A= $app
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | $default); | ||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _start_and_check { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_start_and_check: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $tssh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $tssh->_create_all_keys or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $opts = $tssh->{current_opts}; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $tssh->{daemon_proc} = $tssh->_run_cmd({async => 1}, | |||||||||||||||||||||||||||||||||||||||||
| 88 | 'dropbear', '-E', '-s', | ||||||||||||||||||||||||||||||||||||||||||
| 89 | -r => "$opts->{host_key_path}.dbk", | ||||||||||||||||||||||||||||||||||||||||||
| 90 | -U => "$opts->{user_key_path}.pub", | ||||||||||||||||||||||||||||||||||||||||||
| 91 | -p => "localhost:$opts->{port}", | ||||||||||||||||||||||||||||||||||||||||||
| 92 | -P => $tssh->_backend_wfile('dropbear.pid')); | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | $tssh->_check_daemon_and_set_uri and return 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $tssh->_stop; | |||||||||||||||||||||||||||||||||||||||||
| 96 | () | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub _daemon_name { 'dropbear' } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_daemon_name: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||