blib/lib/Net/SSH/Perl/Auth/ChallengeResponse.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 82 SCAR 40.3
CC
7
Cov
0%
authenticate
42.0
enabled
6.0
new
2.0
CRAP 56.0
1 package Net::SSH::Perl::Auth::ChallengeResponse;
2 use strict;
3 use warnings;
4  
5 use Net::SSH::Perl::Constants qw(
6 SSH_CMSG_AUTH_TIS
7 SSH_SMSG_AUTH_TIS_CHALLENGE
8 SSH_CMSG_AUTH_TIS_RESPONSE
9 SSH_SMSG_SUCCESS
10 SSH_SMSG_FAILURE );
11  
12 use Net::SSH::Perl::Packet;
13 use Net::SSH::Perl::Util qw( _read_passphrase );
14 use Net::SSH::Perl::Auth;
15 use base qw( Net::SSH::Perl::Auth );
16  
17 use Scalar::Util qw(weaken);
18  
19 sub new {
20 my $class = shift;
21 my $ssh = shift;
22 my $auth = bless { ssh => $ssh }, $class;
23 weaken $auth->{ssh};
24 $auth->enabled( $ssh->config->get('auth_ch_res') );
25 $auth;
26 }
27  
28 sub enabled {
29 my $auth = shift;
30 $auth->{enabled} = shift if @_;
31 $auth->{enabled};
32 }
33  
34 sub authenticate {
35 my $auth = shift;
36 my $ssh = $auth->{ssh};
37 $ssh->debug("Password authentication is disabled by the client."), return
38 unless $auth->enabled;
39  
40 $ssh->debug("Doing challenge response authentication.");
41 for (1..$ssh->config->get('number_of_password_prompts')) {
42 my $packet = $ssh->packet_start(SSH_CMSG_AUTH_TIS);
43 $packet->send;
44  
45 $packet = Net::SSH::Perl::Packet->read($ssh);
46 my $type = $packet->type;
47 $ssh->fatal_disconnect("Protocol error in AUTH_TIS")
48 unless $type == SSH_SMSG_FAILURE ||
49 $type == SSH_SMSG_AUTH_TIS_CHALLENGE;
50  
51 $ssh->debug("No challenge presented."), return
52 unless $type == SSH_SMSG_AUTH_TIS_CHALLENGE;
53  
54 my $challenge = $packet->get_str;
55 my $response = _read_passphrase($challenge);
56 $packet = $ssh->packet_start(SSH_CMSG_AUTH_TIS_RESPONSE);
57 $packet->put_str($response);
58 $packet->send;
59  
60 $packet = Net::SSH::Perl::Packet->read($ssh);
61 return 1 if $packet->type == SSH_SMSG_SUCCESS;
62  
63 $ssh->fatal_disconnect("Protocol error to AUTH_TIS response")
64 unless $packet->type == SSH_SMSG_FAILURE;
65 }
66  
67 return 0;
68 }
69  
70 1;