DRI/Protocol/EPP/Extensions/VeriSign/TwoFactorAuth.pm

filter: Statementstmt 9.9% 13 / 131 Branchbran 0.0% 0 / 80 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 28.5% 4 / 14 Podpod 0.0% 0 / 5 totaltotal 6.8% 17 / 250 CC 48 SCAR 46.9
CC
48
Cov
6%
domain_update_generate
240.0
_generate_tokendata
110.0
_generate_token
90.0
CRAP 109.2
« DRI/Protocol/EPP/Extensions/AT/ATResult.pm ↑ Summary DRI/Protocol/EPP/Extensions/EURid/Registrar.pm »
1 ## Domain Registry Interface, VeriSign Two Factor Auth EPP extension
2 ##
3 ## Copyright (c) 2012,2018-2019 Patrick Mevzek <netdri@dotandco.com>. All rights reserved.
4 ##
5 ## This file is part of Net::DRI
6 ##
7 ## Net::DRI is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## See the LICENSE file that comes with this distribution for more details.
13 ####################################################################################################
14  
15 package Net::DRI::Protocol::EPP::Extensions::VeriSign::TwoFactorAuth;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 ####################################################################################################
24  
25 sub register_commands
26 0 ▶{
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my ($class,$version)=@_;
28 0 return { 'authsession' => { create => [ \&auth_create_generate, \&auth_create_parse ] },
29 'domain' => { update => [ \&domain_update_generate, undef ] }, ## other domain operations ?
30 };
31 }
32  
33 sub setup
34 0 ▶{
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($class,$po,$version)=@_;
36 0 $po->ns({ 'authExt' => 'http://www.verisign.com/epp/authExt-1.0',
37 'authSession' => 'http://www.verisign.com/epp/authSession-1.0',
38 });
39 0 return;
40 }
41  
42 ####################################################################################################
43  
44 sub _check_credentials
45 0 ▶{
Subroutine _check_credentials: not called CC=4 SCAR=30.0
46 0 my ($ra)=@_;
47  
48 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "credentials" must be an array reference') unless ref $ra eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $ra eq "ARRAY" 0 0 0
49 0 foreach my $c (@$ra)
50 {
51 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Credentials must each be an XML token from 1 to 255 characters long, not '.$c) unless Net::DRI::Util::xml_is_token($c,1,255);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($c, 1, 255) 0 0 0
52 }
53 0 return;
54 }
55  
56 sub _generate_svcotpcreds
57 0 ▶{
Subroutine _generate_svcotpcreds: not called CC=6 SCAR=37.4
58 0 my ($rp)=@_;
59  
60 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "service_provider" is mandatory') unless Net::DRI::Util::has_key($rp,'service_provider');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "service_provider") 0 0 0
61 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "otp" is mandatory') unless Net::DRI::Util::has_key($rp,'otp');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "otp") 0 0 0
62 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "credentials" is mandatory') unless Net::DRI::Util::has_key($rp,'credentials');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "credentials") 0 0 0
63 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "service_provider" must be an XML token from 3 to 10 characters long') unless Net::DRI::Util::xml_is_token($rp->{service_provider},3,10);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($rp->{"service_provider"}, 3, 10) 0 0 0
64 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "otp" must be an XML token from 5 to 20 characters long') unless Net::DRI::Util::xml_is_token($rp->{otp},5,20);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($rp->{"otp"}, 5, 20) 0 0 0
65 0 _check_credentials($rp->{credentials});
66  
67 0 my @n;
68 0 push @n,['authSession:serviceProvider',$rp->{service_provider}];
69 0 push @n,['authSession:otp',$rp->{otp}];
70 0 push @n,['authSession:credentialList',map { ['authSession:credentialId',$_] } @{$rp->{credentials}}];
71 0 return @n;
72 }
73  
74 sub _generate_token
75 0 ▶{
Subroutine _generate_token: not called CC=9 SCAR=45.0
76 0 my ($rp)=@_;
77  
78 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "service_provider" is mandatory') unless Net::DRI::Util::has_key($rp,'service_provider');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "service_provider") 0 0 0
79 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "credential" is mandatory') unless Net::DRI::Util::has_key($rp,'credential');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "credential") 0 0 0
80 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "crDate" is mandatory') unless Net::DRI::Util::has_key($rp,'crDate');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "crDate") 0 0 0
81 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "exDate" is mandatory') unless Net::DRI::Util::has_key($rp,'exDate');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "exDate") 0 0 0
82 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "service_provider" must be an XML token from 3 to 10 characters long') unless Net::DRI::Util::xml_is_token($rp->{service_provider},3,10);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($rp->{"service_provider"}, 3, 10) 0 0 0
83 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "credential" must be an XML token from 1 to 255 characters long') unless Net::DRI::Util::xml_is_token($rp->{credential},1,255);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($rp->{"credential"}, 1, 255) 0 0 0
84 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "crDate" must be a DateTime object') unless Net::DRI::Util::check_isa($rp->{crDate},'DateTime');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::check_isa($rp->{"crDate"}, "DateTime") 0 0 0
85 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "exDate" must be a DateTime object') unless Net::DRI::Util::check_isa($rp->{exDate},'DateTime');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::check_isa($rp->{"exDate"}, "DateTime") 0 0 0
86  
87 0 my @n;
88 0 push @n,['authSession:serviceProvider',$rp->{service_provider}];
89 0 push @n,['authSession:credentialId',$rp->{credential}];
90 0 push @n,['authSession:crDate',Net::DRI::Util::dto2zstring($rp->{crDate})];
91 0 push @n,['authSession:exDate',Net::DRI::Util::dto2zstring($rp->{exDate})];
92 0 return @n;
93 }
94  
95 sub auth_create_generate
96 0 ▶{
Subroutine auth_create_generate: not called CC=1 SCAR=6.9
Pod undocumented
97 0 my ($epp,$rp)=@_;
98 0 my $mes=$epp->message();
99  
100 0 my @n;
101 0 push @n,_generate_svcotpcreds($rp);
102  
103 0 $mes->command('create','authSession:create', $mes->nsattrs('authSession'));
104 0 $mes->command_body(\@n);
105 0 return;
106 }
107  
108 sub auth_create_parse
109 0 ▶{
Subroutine auth_create_parse: not called CC=9 SCAR=45.0
Pod undocumented
110 0 my ($po,$otype,$oaction,$oname,$rinfo)=@_;
111 0 my $mes=$po->message();
112 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
113  
114 0 my $data=$mes->get_response('authSession','creData');
115 0 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
116  
117 0 my %d;
118 0 foreach my $el (Net::DRI::Util::xml_list_children($data))
119 {
120 0 my ($name,$c)=@$el;
121 0 ▶ if ($name eq 'token')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'token') { } 0 0 0
elsif ($name eq 'signature') { } 0 0 0
122 {
123 0 foreach my $subel (Net::DRI::Util::xml_list_children($c))
124 {
125 0 my ($subname,$subc)=@$subel;
126 0 ▶ if ($subname=~m/^(serviceProvider|credentialId)$/)
Branch: 2 branches
BranchTrueFalseTotal
if ($subname =~ /^(serviceProvider|credentialId)$/) { } 0 0 0
elsif ($subname =~ /^(crDate|exDate)$/) { } 0 0 0
127 {
128 0 $d{Net::DRI::Util::remcam($1)}=$subc->textContent();
129 } elsif ($subname=~m/^(crDate|exDate)$/)
130 {
131 0 $d{$1}=$po->parse_iso8601($subc->textContent());
132 }
133 }
134 } elsif ($name eq 'signature')
135 {
136 0 $d{signature}=$c->textContent();
137 }
138 }
139  
140 0 $rinfo->{auth}->{$d{credential_id}}=\%d;
141 0 return;
142 }
143  
144 sub _generate_tokendata
145 0 ▶{
Subroutine _generate_tokendata: not called CC=10 SCAR=47.0
146 0 my ($rp)=@_;
147  
148 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "token_provider" is mandatory') unless Net::DRI::Util::has_key($rp,'token_provider');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "token_provider") 0 0 0
149 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Either key "token" or "generic_token" is mandatory') unless Net::DRI::Util::has_key($rp,'token') xor Net::DRI::Util::has_key($rp,'generic_token');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "token") xor Net::DRI::Util::has_key($rp, "generic_token") 0 0 0
Condition0%0/4
Net::DRI::Util::has_key($rp, "token") xor Net::DRI::Util::has_key($rp, "generic_token")
l&&rl&&!r!l&&r!l&&!r
0000
MC/DC0%0/2
Net::DRI::Util::has_key($rp, "token") xor Net::DRI::Util::has_key($rp, "generic_token")
Net::DRI::Util::has_key($rp, "token") Net::DRI::Util::has_key($rp, "generic_token")
Truth table0%0/4
A xor B
A= Net::DRI::Util::has_key($rp, "token")B= Net::DRI::Util::has_key($rp, "generic_token")
ABresult
110
101
011
000
150 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Key "signature" is mandatory') unless Net::DRI::Util::has_key($rp,'signature');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "signature") 0 0 0
151 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "token_provider" must be an XML token from 3 to 10 characters long') unless Net::DRI::Util::xml_is_token($rp->{token_provider},3,10);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($rp->{"token_provider"}, 3, 10) 0 0 0
152  
153 0 my @n;
154 0 push @n,['authExt:tokenProvider',$rp->{token_provider}];
155 0 ▶ if (Net::DRI::Util::has_key($rp,'generic_token'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rp, "generic_token")) 0 0 0
156 {
157 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "generic_token" must be an XML string') unless Net::DRI::Util::is_string($rp->{generic_token});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::is_string($rp->{"generic_token"}) 0 0 0
158 0 push @n,['authExt:genericToken',$rp->{generic_token}];
159 }
160 0 ▶ if (Net::DRI::Util::has_key($rp,'token'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rp, "token")) 0 0 0
161 {
162 0 push @n,['authExt:token',_generate_token($rp->{token})];
163 }
164  
165 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "signature" must be an XML base64binary content') unless Net::DRI::Util::verify_base64($rp->{signature});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_base64($rp->{"signature"}) 0 0 0
166 0 push @n,['authExt:signature',$rp->{signature}];
167  
168 0 return ['authExt:tokenData',@n];
169 }
170  
171 sub _generate_otpdata
172 0 ▶{
Subroutine _generate_otpdata: not called CC=1 SCAR=6.9
173 0 my ($rp)=@_;
174 0 return ['authSession:otpData',_generate_svcotpcreds($rp)];
175 }
176  
177 sub domain_update_generate
178 0 ▶{
Subroutine domain_update_generate: not called CC=15 SCAR=54.8
Pod undocumented
179 0 my ($epp,$dom,$toc,$rp)=@_;
180  
181 0 ▶ return unless Net::DRI::Util::has_key($rp,'auth') && ref $rp->{auth} eq 'HASH' && grep { Net::DRI::Util::has_key($rp->{auth},$_); } qw/validate bind unbind/;
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rp, "auth") and ref $rp->{"auth"} eq "HASH" and grep {Net::DRI::Util::has_key($rp->{"auth"}, $_);} "validate", "bind", "unbind" 0 0 0
Condition0%0/6
Net::DRI::Util::has_key($rp, "auth") and ref $rp->{"auth"} eq "HASH" and grep {Net::DRI::Util::has_key($rp->{"auth"}, $_);} "validate", "bind", "unbind"
!ll&&!rl&&r
000
Net::DRI::Util::has_key($rp, "auth") and ref $rp->{"auth"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
Net::DRI::Util::has_key($rp, "auth") and ref $rp->{"auth"} eq "HASH" and grep {Net::DRI::Util::has_key($rp->{"auth"}, $_);} "validate", "bind", "unbind"
Net::DRI::Util::has_key($rp, "auth") ref $rp->{"auth"} eq "HASH" grep {Net::DRI::Util::has_key($rp->{"auth"}, $_);} "validate", "bind", "unbind"
Truth table0%0/4
A and B and C
A= Net::DRI::Util::has_key($rp, "auth")B= ref $rp->{"auth"} eq "HASH"C= grep {Net::DRI::Util::has_key($rp->{"auth"}, $_);} "validate", "bind", "unbind"
ABCresult
0XX0
10X0
1100
1111
182  
183 0 my @n;
184  
185 0 ▶ if (Net::DRI::Util::has_key($rp->{auth},'validate'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rp->{"auth"}, "validate")) 0 0 0
186 {
187 0 my @d;
188  
189 0 ▶ if (Net::DRI::Util::has_key($rp->{auth}->{validate},'token_provider'))
Branch: 2 branches
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rp->{'auth'}{'validate'}, 'token_provider')) { } 0 0 0
elsif (Net::DRI::Util::has_key($rp->{'auth'}{'validate'}, 'service_provider')) { } 0 0 0
190 {
191 0 push @d,_generate_tokendata($rp->{auth}->{validate});
192 } elsif (Net::DRI::Util::has_key($rp->{auth}->{validate},'service_provider'))
193 {
194 0 push @d,_generate_otpdata($rp->{auth}->{validate});
195 } else
196 {
197 0 Net::DRI::Exception::usererr_insufficient_parameters('Key "validate" needs either a "service_provider" or a "token_provider" key');
198 }
199 0 push @n,['authExt:validate',@d];
200 }
201  
202 0 ▶ if (Net::DRI::Util::has_key($rp->{auth},'bind'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rp->{"auth"}, "bind")) 0 0 0
203 {
204 0 ▶ my @data=ref $rp->{auth}->{bind} eq 'ARRAY' ? @{$rp->{auth}->{bind}} : ($rp->{auth}->{bind});
Branch: 1 branch
BranchTrueFalseTotal
ref $rp->{'auth'}{'bind'} eq 'ARRAY' ? : 0 0 0
205 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Value for key "bind" must be a refhash or a refarray of refhashes') if grep { ref $_ ne 'HASH' } @data;
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_ ne "HASH";} @data 0 0 0
206 0 my $istoken=scalar grep { exists $_->{token_provider} } @data;
207 0 my $isotp=scalar grep { exists $_->{service_provider} } @data;
208 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('For key "bind" values must be refarray of refhashes with key "token_provider" or "service_provider", not both') if ($istoken && $isotp);
Branch: 1 branch
BranchTrueFalseTotal
if $istoken and $isotp 0 0 0
Condition0%0/3
$istoken and $isotp
!ll&&!rl&&r
000
MC/DC0%0/2
$istoken and $isotp
$istoken $isotp
Truth table0%0/3
A and B
A= $istokenB= $isotp
ABresult
0X0
100
111
209  
210 0 my @d;
211 0 ▶ if ($istoken)
Branch: 2 branches
BranchTrueFalseTotal
if ($istoken) { } 0 0 0
elsif ($isotp) { } 0 0 0
212 {
213 0 push @d,['authExt:tokenDataList',map { _generate_tokendata($_) } @data ];
214 } elsif ($isotp)
215 {
216 0 push @d,['authExt:otpDataList',map { _generate_otpdata($_) } @data ];
217 } else
218 {
219 0 Net::DRI::Exception::usererr_insufficient_parameters('For key "bind" values must be refarray of refhashes with either key "token_provider" or "service_provider"');
220 }
221 0 push @n,['authExt:bind',@d];
222 }
223  
224 0 ▶ if (Net::DRI::Util::has_key($rp->{auth},'unbind'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rp->{"auth"}, "unbind")) 0 0 0
225 {
226 0 my @d;
227 0 _check_credentials($rp->{auth}->{unbind});
228 0 push @d,map { ['authSession:credentialId',$_] } @{$rp->{auth}->{unbind}};
229 0 push @n,['authExt:unbind',@d];
230 }
231  
232 0 $epp->message()->command_extension(['authExt', 'authSession'], ['authActions', @n]);
233 0 return;
234 }
235  
236 ####################################################################################################
237 1 1;
238  
239 __END__
« DRI/Protocol/EPP/Extensions/AT/ATResult.pm ↑ Summary DRI/Protocol/EPP/Extensions/EURid/Registrar.pm »