Package list libpoe-component-sslify-perl / 95ea76e
initial commit for hook work Apocalypse 10 years ago
2 changed file(s) with 40 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
2727 # die_if_ssl_error won't die on non-blocking errors. We don't need to call connect()
2828 # again, because OpenSSL I/O functions (read, write, ...) can handle that entirely
2929 # by self (it's needed to connect() once to determine connection type).
30 my $resp = Net::SSLeay::connect( $ssl ) or die_if_ssl_error( 'ssl connect' );
31
30 my $res = Net::SSLeay::connect( $ssl ) or die_if_ssl_error( 'ssl connect' );
31 warn "Net::SSLeay::connect(TIEHANDLE) -> $res";
3232 my $self = bless {
3333 'ssl' => $ssl,
3434 'ctx' => $ctx,
3535 'socket' => $socket,
3636 'fileno' => $fileno,
3737 'client' => 1,
38 'status' => $res,
3839 }, $class;
3940
4041 return $self;
1818 # die_if_ssl_error won't die on non-blocking errors. We don't need to call accept()
1919 # again, because OpenSSL I/O functions (read, write, ...) can handle that entirely
2020 # by self (it's needed to accept() once to determine connection type).
21 my $err = Net::SSLeay::accept( $ssl ) and die_if_ssl_error( 'ssl accept' );
22
21 my $res = Net::SSLeay::accept( $ssl ) and die_if_ssl_error( 'ssl accept' );
22 warn "Net::SSLeay::accept(TIEHANDLE) -> $res";
2323 my $self = bless {
2424 'ssl' => $ssl,
2525 'ctx' => $ctx,
2626 'socket' => $socket,
2727 'fileno' => $fileno,
28 'status' => $res,
2829 }, $class;
2930
3031 return $self;
32 }
33
34 sub _check_status {
35 my $self = shift;
36 my $method = shift;
37
38 # Okay, is negotiation done?
39 # http://www.openssl.org/docs/ssl/SSL_connect.html#RETURN_VALUES
40 if ( $self->{'status'} == -1 ) {
41 # client or server?
42 my $res;
43 if ( exists $self->{'client'} ) {
44 $res = Net::SSLeay::connect( $self->{'ssl'} );
45 warn "Net::SSLeay::connect($method) -> $res";
46 } else {
47 $res = Net::SSLeay::accept( $self->{'ssl'} );
48 warn "Net::SSLeay::accept($method) -> $res";
49 }
50
51 if ( $res == 0 ) {
52 # TODO error?
53 } elsif ( $res == 1 ) {
54 $self->{'status'} = 1;
55
56 # TODO call the hook function for successful connect
57 warn "CALLING HOOK FUNCTION for " . ( exists $self->{'client'} ? 'CLIENT' : 'SERVER' );
58 }
59 }
3160 }
3261
3362 # Read something from the socket
3766
3867 # Get the pointers to buffer, length, and the offset
3968 my( $buf, $len, $offset ) = \( @_ );
69
70 # Check connection status
71 $self->_check_status( 'READ' );
4072
4173 # If we have no offset, replace the buffer with some input
4274 if ( ! defined $$offset ) {
74106 sub WRITE {
75107 # Get ourself + buffer + length + offset to write
76108 my( $self, $buf, $len, $offset ) = @_;
109
110 # Check connection status
111 $self->_check_status( 'WRITE' );
77112
78113 # If we have nothing to offset, then start from the beginning
79114 if ( ! defined $offset ) {