DRI/Protocol/EPP/Connection.pm

filter: Statementstmt 46.4% 26 / 56 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 0.0% 0 / 5 totaltotal 40.0% 34 / 85 CC 7 SCAR 24.0
CC
7
Cov
38%
read_data
30.0
read_fragments
12.0
transport_default
2.0
CRAP 11.0
« DRI/Protocol/BookMyName/WS/Message.pm ↑ Summary DRI/DRD/CentralNic.pm »
1 ## Domain Registry Interface, EPP Connection handling
2 ##
3 ## Copyright (c) 2005-2013,2016 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::Connection;
16  
17 5 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 5 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use Net::DRI::Data::Raw;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use Net::DRI::Protocol::ResultStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 ▶use Net::SSLeay;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 =pod
28  
29 =head1 NAME
30  
31 Net::DRI::Protocol::EPP::Connection - EPP over TCP/TLS Connection Handling (RFC5734) for Net::DRI
32  
33 =head1 DESCRIPTION
34  
35 Please see the README file for details.
36  
37 =head1 SUPPORT
38  
39 For now, support questions should be sent to:
40  
41 E<lt>netdri@dotandco.comE<gt>
42  
43 Please also see the SUPPORT file in the distribution.
44  
45 =head1 SEE ALSO
46  
47 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
48  
49 =head1 AUTHOR
50  
51 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
52  
53 =head1 COPYRIGHT
54  
55 Copyright (c) 2005-2013,2016 Patrick Mevzek <netdri@dotandco.com>.
56 All rights reserved.
57  
58 This program is free software; you can redistribute it and/or modify
59 it under the terms of the GNU General Public License as published by
60 the Free Software Foundation; either version 2 of the License, or
61 (at your option) any later version.
62  
63 See the LICENSE file that comes with this distribution for more details.
64  
65 =cut
66  
67 ####################################################################################################
68  
69 sub read_fragments
70 0 ▶{
Subroutine read_fragments: not called CC=3 SCAR=24.8
Pod undocumented
71 0 my ($sock,$length)=@_;
72 0 my $data='';
73 0 ▶ while($length > 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($length > 0) 0 0 0
74 {
75 0 my $new;
76 0 my $read=$sock->sysread($new,$length);
77 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Error reading socket','en')) unless $read;
Branch: 1 branch
BranchTrueFalseTotal
unless $read 0 0 0
78 0 $length-=$read;
79 0 $data.=$new;
80 }
81 0 return $data;
82 }
83  
84 sub read_data
85 0 ▶{
Subroutine read_data: not called CC=5 SCAR=34.0
Pod undocumented
86 0 my ($class,$to,$sock)=@_;
87 0 my $header=read_fragments($sock,4); ## first 4 bytes are the packed length
88 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Unable to read frame length','en')) unless length $header;
Branch: 1 branch
BranchTrueFalseTotal
unless length $header 0 0 0
89 0 my $length=unpack('N',$header)-4; ## Length of the XML frame
90 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Unable to decode frame length','en')) unless $length > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $length > 0 0 0 0
91 0 my $frame=Net::DRI::Util::decode_utf8(read_fragments($sock,$length));
92 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','<empty message from server>','en')) unless length $frame;
Branch: 1 branch
BranchTrueFalseTotal
unless length $frame 0 0 0
93 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Got unexpected EPP message: '.$frame,'en')) unless $frame=~m!</(?:[^:]+:)?epp>\s*$!s;
Branch: 1 branch
BranchTrueFalseTotal
unless $frame =~ m[</(?:[^:]+:)?epp>\s*$]s 0 0 0
94 0 return Net::DRI::Data::Raw->new_from_xmlstring($frame);
95 }
96  
97 sub write_message
98 1 ▶{
Subroutine write_message: called CC=1 SCAR=0.0
Pod undocumented
99 1 my ($self,$to,$msg)=@_;
100  
101 1 my $m=Net::DRI::Util::encode_utf8($msg);
102 1 my $l=pack('N',4+length($m)); ## RFC 4934 §4
103 1 return $l.$m; ## We do not support EPP "0.4" at all (which lacks length before data)
104 }
105  
106 sub transport_default
107 0 ▶{
Subroutine transport_default: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my ($self,$tname)=@_;
109 0 return (defer => 0, socktype => 'ssl', ssl_version => 'TLSv1', remote_port => 700);
110 }
111  
112 # SSL_verify_callback
113 # If you want to verify certificates yourself, you can pass a sub reference along with this parameter to do so. When the
114 # callback is called, it will be passed: 1) a true/false value that indicates what OpenSSL thinks of the certificate, 2)
115 # a C-style memory address of the certificate store, 3) a string containing the certificate's issuer attributes and owner
116 # attributes, and 4) a string containing any errors encountered (0 if no errors). The function should return 1 or 0,
117 # depending on whether it thinks the certificate is valid or invalid. The default is to let OpenSSL do all of the busy
118 # work.
119 ##
120 ## (seems to be called twice)
121 ##
122 ## See also IO::Socket::SSL verify_hostname()
123  
124 ## TODO: implement TLS checkings as defined in RFC5734 §9 (test that $po->name() eq 'EPP' !)
125 sub tls_verifications
126 0 ▶{
Subroutine tls_verifications: not called CC=1 SCAR=6.9
Pod undocumented
127 0 my ($to,$status,$store,$certowner,$errors)=@_;
128  
129 ## From internals of IO::Socket::SSL :
130 0 my $cert=Net::SSLeay::X509_STORE_CTX_get_current_cert($store);
131 0 my $issuer= Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert));
132 0 my $subject=Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert));
133  
134 0 print STDERR "TODO WIP\n";
135 0 print STDERR "ISSUER=$issuer\n";
136 0 print STDERR "SUBJECT=$subject\n";
137 0 print STDERR "STATUS=$status\n";
138 0 print STDERR "ERRORS=$errors\n"; ## self signed certificate is considered an error
139  
140 0 return 1; ## 1 if certificate is valid, 0 otherwise
141 }
142  
143 ####################################################################################################
144 5 1;
« DRI/Protocol/BookMyName/WS/Message.pm ↑ Summary DRI/DRD/CentralNic.pm »