DBus/Authn/Mechanism/DBUS_COOKIE_SHA1.pm

filter: Statementstmt 83.8% 52 / 62 Branchbran 33.3% 2 / 6 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 3 totaltotal 73.4% 69 / 94 SCAR 18.8
CC
6
Cov
75%
_getpw
6.0
new
3.9
_authn_respond_data
2.9
CRAP 6.5
« DBus/Authn/Mechanism/DBUS_COOKIE_SHA1/Pieces.pm ↑ Summary DBus/Connect.pm »
1 package Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1;
2  
3 # https://dbus.freedesktop.org/doc/dbus-specification.html#auth-mechanisms-sha
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use parent qw( Protocol::DBus::Authn::Mechanism );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 4 my $sha_module;
15  
16 4 ▶use constant must_send_initial => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 use constant {
19 4 DEBUG => 0,
20 4 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 sub new {
23 1 ▶ my ($class) = @_;
Subroutine new: called CC=3 SCAR=13.6
Pod undocumented
24  
25 1 local $@;
26  
27 1 ▶ if ( eval { require Digest::SHA1; 1 } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Digest::SHA1; 1 } }) { } 1 0 1
elsif (eval { do { require Digest::SHA; 1 } }) { } 0 0 0
28 1 $sha_module = 'Digest::SHA1';
29 }
30 0 elsif ( eval { require Digest::SHA; 1 } ) {
31 0 $sha_module = 'Digest::SHA';
32 }
33 else {
34 0 die "No SHA module available!";
35 }
36  
37 1 return $class->SUPER::new( @_[ 1 .. $#_ ] );
38 }
39  
40 sub INITIAL_RESPONSE {
41 1 ▶ my ($self) = @_;
Subroutine INITIAL_RESPONSE: called CC=1 SCAR=0.0
Pod undocumented
42  
43 1 return unpack( 'H*', ($self->_getpw())[0] );
44 }
45  
46 sub AFTER_AUTH {
47 1 ▶ my ($self) = @_;
Subroutine AFTER_AUTH: called CC=1 SCAR=0.0
Pod undocumented
48  
49 return (
50 [ 1 => sub {
51 1 ▶ _consume_data($self, @_);
Subroutine __ANON__: called CC=1 SCAR=0.0
52 1 } ],
53 [ 0 => \&_authn_respond_data ],
54 );
55 }
56  
57 sub _getpw {
58 0 ▶ my ($self) = @_;
Subroutine _getpw: not called CC=2 SCAR=17.9
59  
60 0 ▶ $self->{'_pw'} ||= [ getpwuid $> ];
Condition0%0/2
$self->{"_pw"} ||= [getpwuid $>]
l!l
00
MC/DC0%0/1
$self->{"_pw"} ||= [getpwuid $>]
$self->{"_pw"}
Truth table0%0/2
A
A= $self->{"_pw"}
Aresult
11
00
61  
62 0 return @{ $self->{'_pw'} };
63 }
64  
65 sub _consume_data {
66 1 ▶ my ($self, $authn, $line) = @_;
Subroutine _consume_data: called CC=2 SCAR=7.0
67  
68 1 ▶ if (0 != index($line, 'DATA ')) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 != index($line, "DATA ")) 0 1 1
69 0 die "Invalid line: [$line]";
70 }
71  
72 1 substr( $line, 0, 5, q<> );
73  
74 1 my ($ck_ctx, $ck_id, $sr_challenge) = split m< >, pack( 'H*', $line );
75  
76 1 if (DEBUG()) {
77 print STDERR (
78 "AUTHN/SHA1 context: $ck_ctx$/",
79 "AUTHN/SHA1 cookie ID: $ck_id$/",
80 "AUTHN/SHA1 server challenge: $sr_challenge$/",
81 );
82 }
83  
84 1 my $cookie = $self->_get_cookie($ck_ctx, $ck_id);
85  
86 1 my $cl_challenge = _create_challenge();
87  
88 1 my $str = join(
89 ':',
90 $sr_challenge,
91 $cl_challenge,
92 $cookie,
93 );
94  
95 1 my $str_digest = _sha1_hex($str);
96  
97 1 if (DEBUG()) {
98 print STDERR (
99 "AUTHN/SHA1 cookie: $cookie$/",
100 "AUTHN/SHA1 client challenge: $ck_id$/",
101 "AUTHN/SHA1 string: $str$/",
102 );
103 }
104  
105 1 $authn->{'_sha1_response'} = unpack 'H*', "$cl_challenge $str_digest";
106  
107 1 return;
108 }
109  
110 sub _authn_respond_data {
111 return (
112 'DATA',
113 1 ▶ $_[0]->{'_sha1_response'} || do {
Subroutine _authn_respond_data: called CC=2 SCAR=10.5
Condition33%1/3
$_[0]{'_sha1_response'} || do { die 'No SHA1 DATA response set!' }
l!l&&r!l&&!r
100
MC/DC0%0/2
$_[0]{'_sha1_response'} || do { die 'No SHA1 DATA response set!' }
$_[0]{'_sha1_response'} do { die 'No SHA1 DATA response set!' }
Truth table33%1/3
A || B
A= $_[0]{'_sha1_response'}B= do { die 'No SHA1 DATA response set!' }
ABresult
1X1
011
000
114 0 die "No SHA1 DATA response set!";
115 },
116 );
117 }
118  
119 4 *_sha1_hex = \&Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces::sha1_hex;
120  
121 4 *_create_challenge = \&Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces::create_challenge;
122  
123 sub _get_cookie {
124 1 ▶ my ($self, $ck_ctx, $ck_id) = @_;
Subroutine _get_cookie: called CC=1 SCAR=0.0
125  
126 1 return Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces::get_cookie(
127 ($self->_getpw())[7],
128 $ck_ctx,
129 $ck_id,
130 );
131 }
132  
133 4 1;
« DBus/Authn/Mechanism/DBUS_COOKIE_SHA1/Pieces.pm ↑ Summary DBus/Connect.pm »