| 1 | package Net::EPP::MITMProxy; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: A generic EPP proxy server framework. | ||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use IO::Socket::SSL; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mozilla::CA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Net::EPP::Protocol; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Socket6; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use SUPER; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use base qw(Net::Server::PreFork); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use feature qw(state); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use vars qw($OPT_KEY $HELLO); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use bytes; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | my $OPT_KEY = __PACKAGE__.'::opts'; | |||||||||||||||||||||||||||
| 17 | 1 | my $HELLO = '<epp xmlns="urn:ietf:params:xml:ns:epp-1.0"><hello/></epp>'; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | $self->{$OPT_KEY} = { | ||||||||||||||||||||||||||||
| 24 | remote_server => delete($args{remote_server}), | ||||||||||||||||||||||||||||
| 25 | remote_port => delete($args{remote_port}) || 700, | ||||||||||||||||||||||||||||
| 26 | remote_key => delete($args{remote_key}), | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | remote_cert => delete($args{remote_cert}), | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'remote_port'} || 700
MC/DC0%0/1
delete $args{'remote_port'} || 700
delete $args{'remote_port'}
Truth table0%0/2
A
A= delete $args{'remote_port'}
| |||||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | super; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub process_request { | ||||||||||||||||||||||||||
|
Subroutine
process_request: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | 0 | my ($self, $client) = @_; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $server = $self->connect_to_remote_server; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | return unless ($server); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | my $frame = $self->get_frame($server); | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (!$frame) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | $self->log(0, 'error getting <greeting> from remote server'); | |||||||||||||||||||||||||||
| 42 | 0 | return; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $self->send_frame($client, $self->rewrite_response($frame, $HELLO)); | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | while (1) { | |||||||||||||||||||||||||||
| 48 | 0 | my $command = $self->get_frame($client); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (!$command) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $self->log(0, 'error getting command frame from client'); | |||||||||||||||||||||||||||
| 52 | 0 | last; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->send_frame($server, $self->rewrite_command($command)); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $response = $self->get_frame($server); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if (!$response) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | $self->log(0, 'error getting response frame from remote server'); | |||||||||||||||||||||||||||
| 61 | 0 | last; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | $self->send_frame($client, $self->rewrite_response($response, $command)); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub connect_to_remote_server { | ||||||||||||||||||||||||||
|
Subroutine
connect_to_remote_server: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | my %args = ( | ||||||||||||||||||||||||||||
| 74 | PeerHost => $self->{$OPT_KEY}->{remote_server}, | ||||||||||||||||||||||||||||
| 75 | PeerPort => $self->{$OPT_KEY}->{remote_port}, | ||||||||||||||||||||||||||||
| 76 | 0 | SSL_verify_mode => SSL_VERIFY_PEER, | |||||||||||||||||||||||||||
| 77 | SSL_ca_file => Mozilla::CA::SSL_ca_file(), | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | if ($self->{$OPT_KEY}->{remote_key} && $self->{$OPT_KEY}->{remote_cert}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{$OPT_KEY}{"remote_key"} and $self->{$OPT_KEY}{"remote_cert"}
MC/DC0%0/2
$self->{$OPT_KEY}{"remote_key"} and $self->{$OPT_KEY}{"remote_cert"}
$self->{$OPT_KEY}{"remote_key"}
$self->{$OPT_KEY}{"remote_cert"}
Truth table0%0/3
A and B
A= $self->{$OPT_KEY}{"remote_key"}B= $self->{$OPT_KEY}{"remote_cert"}
| |||||||||||||||||||||||||||||
| 81 | 0 | $args{SSL_key_file} = $self->{$OPT_KEY}->{remote_key}; | |||||||||||||||||||||||||||
| 82 | 0 | $args{SSL_cert_file} = $self->{$OPT_KEY}->{remote_cert}; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | my $server = IO::Socket::SSL->new(%args); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if (!$server) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | $self->log(0, sprintf( | ||||||||||||||||||||||||||||
| 89 | 'connection to [%s]:%u failed (error=%s, SSL error=%s)', | ||||||||||||||||||||||||||||
| 90 | $self->{$OPT_KEY}->{remote_server}, | ||||||||||||||||||||||||||||
| 91 | $self->{$OPT_KEY}->{remote_port}, | ||||||||||||||||||||||||||||
| 92 | 0 | $!, | |||||||||||||||||||||||||||
| 93 | $SSL_ERROR | ||||||||||||||||||||||||||||
| 94 | )); | ||||||||||||||||||||||||||||
| 95 | 0 | return; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | return $server; | |||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | ▶ | sub get_frame { | ||||||||||||||||||||||||||
|
Subroutine
get_frame: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 102 | 0 | my ($self, $socket) = @_; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | return Net::EPP::Protocol->get_frame($socket); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub send_frame { | ||||||||||||||||||||||||||
|
Subroutine
send_frame: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | return Net::EPP::Protocol->send_frame(@_); | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub rewrite_command { | ||||||||||||||||||||||||||
|
Subroutine
rewrite_command: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my ($self, $command_xml) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return $command_xml; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub rewrite_response { | ||||||||||||||||||||||||||
|
Subroutine
rewrite_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 0 | my ($self, $response_xml, $command_xml) = @_; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 0 | return $response_xml; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | 1; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | __END__ | ||||||||||||||||||||||||||||