| 1 | ## Domain Registry Interface, Login Security Extension Mapping for EPP | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ## | ||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Copyright (c) 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::LoginSecurity; | ||||||||||||||||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use feature 'state'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Net::DRI::Exception; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use Net::DRI::Util; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | #################################################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my $trigger_password = '[LOGIN-SECURITY]'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | sub register_commands | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_commands: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my ($class, $version)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | state $rsession = { 'session' => { 'login' => [ \&login, \&parse ]} }; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | return $rsession; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | sub setup | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my ($class, $po, $version)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | state $ns = { 'loginSec' => 'urn:ietf:params:xml:ns:epp:loginSec-1.0' }; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | $po->ns($ns); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Patch core login | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # (this is bad and should not be needed if we would be able to register_commands at specific time of run) | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $core_login = $po->{commands_by_class}{'Net::DRI::Protocol::EPP::Core::Session'}{session}{login}[0]; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | my $new_login = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my ($po, $login, $password, $rdata) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $ns = $po->ns(); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (defined $ns && exists $ns->{loginSec} && grep { $_ eq $ns->{loginSec} } @{$po->default_parameters()->{server}->{extensions_selected}}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $ns and exists $ns->{"loginSec"} and grep {$_ eq $ns->{"loginSec"};} @{$po->default_parameters->{"server"}{"extensions_selected"};}
defined $ns and exists $ns->{"loginSec"}
MC/DC0%0/3
defined $ns and exists $ns->{"loginSec"} and grep {$_ eq $ns->{"loginSec"};} @{$po->default_parameters->{"server"}{"extensions_selected"};}
defined $ns
exists $ns->{"loginSec"}
grep {$_ eq $ns->{"loginSec"};} @{$po->default_parameters->{"server"}{"extensions_selected"};}
Truth table0%0/4
A and B and C
A= defined $nsB= exists $ns->{"loginSec"}C= grep {$_ eq $ns->{"loginSec"};} @{$po->default_parameters->{"server"}{"extensions_selected"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if ($password eq $trigger_password) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | Net::DRI::Exception::usererr_invalid_parameters(sprintf('password can not be "%s"', $trigger_password)); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if (length($password) > 16) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | $rdata->{login_security} = { password => $password }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $password = $trigger_password; # ยง3.2 | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if (Net::DRI::Util::has_key($rdata, 'client_newpassword') and length($rdata->{client_newpassword}) > 16) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
Net::DRI::Util::has_key($rdata, "client_newpassword") and length $rdata->{"client_newpassword"} > 16
MC/DC0%0/2
Net::DRI::Util::has_key($rdata, "client_newpassword") and length $rdata->{"client_newpassword"} > 16
Net::DRI::Util::has_key($rdata, "client_newpassword")
length $rdata->{"client_newpassword"} > 16
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($rdata, "client_newpassword")B= length $rdata->{"client_newpassword"} > 16
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $rdata->{login_security}->{client_newpassword} = $rdata->{client_newpassword}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $rdata->{client_newpassword} = $trigger_password; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return $core_login->($po, $login, $password, $rdata); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $po->{commands_by_class}{'Net::DRI::Protocol::EPP::Core::Session'}{session}{login} = [ $new_login, undef ]; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub implements { return 'https://tools.ietf.org/html/draft-ietf-regext-login-security-03'; } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
implements: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | sub login | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
login: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my ($po, $login, $password, $rdata)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | return unless Net::DRI::Util::has_key($rdata, 'login_security'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my ($long_password, $long_new_password)=@{$rdata->{login_security}}{qw/password client_newpassword/}; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | delete $rdata->{login_security}; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | my $agent = { | |||||||||||||||||||||||||||||||||||||||||
| 87 | app => sprintf('Net::DRI/%s (%s)', $Net::DRI::VERSION, $po->nameversion()), | ||||||||||||||||||||||||||||||||||||||||||
| 88 | tech => sprintf('perl/%vd XML::LibXML/%s', $^V, $XML::LibXML::VERSION), | ||||||||||||||||||||||||||||||||||||||||||
| 89 | os => $^O, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if (Net::DRI::Util::has_key($rdata, 'client_agent') && ref $rdata->{'client_agent'} eq 'HASH') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
Net::DRI::Util::has_key($rdata, "client_agent") and ref $rdata->{"client_agent"} eq "HASH"
MC/DC0%0/2
Net::DRI::Util::has_key($rdata, "client_agent") and ref $rdata->{"client_agent"} eq "HASH"
Net::DRI::Util::has_key($rdata, "client_agent")
ref $rdata->{"client_agent"} eq "HASH"
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($rdata, "client_agent")B= ref $rdata->{"client_agent"} eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | foreach my $t (qw/app tech os/) | |||||||||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | $agent->{$t} = $rdata->{client_agent}->{$t} if exists $rdata->{client_agent}->{$t}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my @agent = map { [$_, $agent->{$_}] } grep { defined $agent->{$_} } qw/app tech os/; | |||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my @nodes; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | push @nodes, ['userAgent', @agent] if @agent; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if (defined $long_password) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters('password') unless Net::DRI::Util::xml_is_token($long_password, 6); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | push @nodes, ['pw', $long_password]; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (defined $long_new_password) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters('client_newpassword') unless Net::DRI::Util::xml_is_token($long_new_password, 6); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | push @nodes, ['newPW', $long_new_password]; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | $po->message()->command_extension('loginSec', ['loginSec', @nodes]); | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | sub parse | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my ($po, $otype, $oaction, $oname, $rinfo)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | my $mes=$po->message(); | |||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # This needs to be parsed for both success and error cases | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $data = $mes->get_extension('loginSec','loginSecData'); | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return unless defined $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my %events = (warning => [], error => []); | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | foreach my $el (Net::DRI::Util::xml_list_children($data)) | |||||||||||||||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | my ($name, $node)=@$el; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | next unless $name eq 'event'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my %event = (type => $node->getAttribute('type'), # mandatory | |||||||||||||||||||||||||||||||||||||||||
| 138 | lang => 'en'); # optional, default value | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | foreach my $attr (qw/name exDate value duration lang/) | |||||||||||||||||||||||||||||||||||||||||
| 140 | { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | next unless $node->hasAttribute($attr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $event{$attr eq 'name' ? 'subtype' : $attr} = $node->getAttribute($attr); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $content = $node->textContent(); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $content =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $content =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $event{description} = $content if $content ne ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | push @{$events{$node->getAttribute('level')}}, \%event; | |||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $rinfo->{session}->{login_security} = \%events; | |||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | #################################################################################################### | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||||||||||||||||