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 CC 6 SCAR 8.0
CC
6
Cov
75%
_getpw
6.0
new
3.9
_authn_respond_data
2.9
CRAP 2.2
« DBus/X/Rejected.pm ↑ Summary DBus.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 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use parent qw( Protocol::DBus::Authn::Mechanism );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 5 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 my $sha_module;
15  
16 5 ▶use constant must_send_initial => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 DEBUG => 0,
20 5 };
21  
22 2 ▶sub new {
Subroutine new: called CC=3 SCAR=13.6
Pod undocumented
23 2 my ($class) = @_;
24  
25 2 local $@;
26  
27 2 ▶ if ( eval { require Digest::SHA1; 1 } ) {
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { require Digest::SHA1; 1 } }) { } 2 0 2
elsif (eval { do { require Digest::SHA; 1 } }) { } 0 0 0
28 2 $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 2 return $class->SUPER::new( @_[ 1 .. $#_ ] );
38 }
39  
40 2 ▶sub INITIAL_RESPONSE {
Subroutine INITIAL_RESPONSE: called CC=1 SCAR=0.0
Pod undocumented
41 2 my ($self) = @_;
42  
43 2 return unpack( 'H*', ($self->_getpw())[0] );
44 }
45  
46 2 ▶sub AFTER_AUTH {
Subroutine AFTER_AUTH: called CC=1 SCAR=0.0
Pod undocumented
47 2 my ($self) = @_;
48  
49 return (
50 2 ▶ [ 1 => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
51 2 _consume_data($self, @_);
52 2 } ],
53 [ 0 => \&_authn_respond_data ],
54 );
55 }
56  
57 0 ▶sub _getpw {
Subroutine _getpw: not called CC=2 SCAR=17.9
58 0 my ($self) = @_;
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 2 ▶sub _consume_data {
Subroutine _consume_data: called CC=2 SCAR=7.0
66 2 my ($self, $authn, $line) = @_;
67  
68 2 ▶ if (0 != index($line, 'DATA ')) {
Branch: 1 branch
BranchTrueFalseTotal
if (0 != index($line, "DATA ")) 0 2 2
69 0 die "Invalid line: [$line]";
70 }
71  
72 2 substr( $line, 0, 5, q<> );
73  
74 2 my ($ck_ctx, $ck_id, $sr_challenge) = split m< >, pack( 'H*', $line );
75  
76 2 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 2 my $cookie = $self->_get_cookie($ck_ctx, $ck_id);
85  
86 2 my $cl_challenge = _create_challenge();
87  
88 2 my $str = join(
89 ':',
90 $sr_challenge,
91 $cl_challenge,
92 $cookie,
93 );
94  
95 2 my $str_digest = _sha1_hex($str);
96  
97 2 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 2 $authn->{'_sha1_response'} = unpack 'H*', "$cl_challenge $str_digest";
106  
107 2 return;
108 }
109  
110 2 ▶sub _authn_respond_data {
Subroutine _authn_respond_data: called CC=2 SCAR=10.5
111 return (
112 'DATA',
113 2 ▶ $_[0]->{'_sha1_response'} || do {
Condition33%1/3
$_[0]{'_sha1_response'} || do { die 'No SHA1 DATA response set!' }
l!l&&r!l&&!r
200
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 5 *_sha1_hex = \&Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces::sha1_hex;
120  
121 5 *_create_challenge = \&Protocol::DBus::Authn::Mechanism::DBUS_COOKIE_SHA1::Pieces::create_challenge;
122  
123 2 ▶sub _get_cookie {
Subroutine _get_cookie: called CC=1 SCAR=0.0
124 2 my ($self, $ck_ctx, $ck_id) = @_;
125  
126 2 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 5 1;
« DBus/X/Rejected.pm ↑ Summary DBus.pm »