Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

SSL suport, take 3 #47

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
4 participants
Contributor

ap commented May 31, 2012

Cleaned up version of the patch from #45.

und3f commented May 31, 2012

Your patch is broken. I receive error for any ssl request.

2012/05/31-22:59:33 CONNECT SSLEAY Peer: "[127.0.0.1]:40874" Local: "[127.0.0.1]:5000"
[3301] Read error: Resource temporarily unavailable
[3301] Closing connection

Net::Server creates non-blocking sockets for SSLeay proto. In this mode you have to wait till socket will be ready or ignore EAGAIN and EINTR errors.
und3f/Net-Server@5aa4145#L1R120

I don't know why it uses non-blocking sockets. You could also try to change socket mode to blocking.

Owner

miyagawa commented May 31, 2012

I like that simplicity of the patch and that it uses Net::Server 2's built-in. Let me know once this works cleanly and I will get it merged down.

Contributor

ap commented May 31, 2012

It’ll be a few days, but I’ll take a look as soon as I can.

I'm also getting the issue und3f is getting, looking forward to this patch! SSL would be great!

Using https://github.com/und3f/Net-Server master i get a different issue, when start the server I get:
Binding to SSLEAY port 5000 on host *

However all requests are handled by HTTP not SSL

Even more bizzarly the psgi enviroment shows https - yet it is defiantly not using ssl

$VAR1 = {
'psgi.multiprocess' => 1,
'SCRIPT_NAME' => '',
'SERVER_NAME' => '192.168.60.241',
'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
'PATH_INFO' => '/psgi',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8',
'REQUEST_METHOD' => 'GET',
'psgi.multithread' => '',
'HTTP_ACCEPT_CHARSET' => 'ISO-8859-1,utf-8;q=0.7,_;q=0.3',
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Iron/19.0.1100.0 Chrome/19.0.1100.0 Safari/536.5',
'QUERY_STRING' => '',
'SERVER_PORT' => 5000,
'psgix.input.buffered' => 1,
'HTTP_COOKIE' => 'session_debuger=2VflFfC7ipFOzu636c5lHhklI; session_default=A1dEf9l7QFJ6thRAp8HyCVqHH',
'HTTP_ACCEPT_LANGUAGE' => 'en-US,en;q=0.8',
'REMOTE_ADDR' => '31.221.34.167',
'SERVER_PROTOCOL' => 'HTTP/1.1',
'psgi.streaming' => 1,
'REQUEST_URI' => '/psgi',
'psgi.errors' => *::STDERR,
'psgi.version' => [
1,
1
],
'psgi.nonblocking' => '',
'psgix.io' => bless( _Symbol::GEN203, 'Net::Server::Proto::SSLEAY' ),
'psgi.url_scheme' => 'https',
'REMOTE_HOST' => '192.168.1.10',
'psgi.run_once' => '',
'psgix.harakiri' => 1,
'HTTP_HOST' => '192.168.60.241:5000',
'psgi.input' => *{'Starman::Server::$io'}
};

when connecting to the server with https i get these out of the server:
2012/07/30-13:45:28 CONNECT TCP Peer: "192.168.1.10:55373" Local: "192.168.60.241:5000"
[6268] Read 88 bytes: do {
require MIME::Base64;
MIME::Base64::decode("FgMAAFMBAABPAwBQFoK2sD4KNQ0pYcB0Iam+BsPbxFZQUXnDYAcZ3F7+FgAAKAD/AIgAhwA5ADgAhAA1AEUARAAzADIAlgBBAAUABAAvABYAE/7/AAoBAA==");
}
[6268] Client connection timed out
[6268] Closing connectio

Ok after much bodgery I managed to get this to work - but its a complete mess and I've mange to break http compatibility.

My knowledge of POSIX is limited, and I'm not certain I can get this to an acceptable place myself.

I'll describe here what I have found so that miyagawa/ap/und3f might understand better than I do.

sysread/syswrite calls in Starman/Server.pm are not using the sysread/syswrite implemented in Net/Server/Proto/SSLEAY.pm
I bodge fixed it by calling directly on the socket, ie: $self->{server}->{client}->sysread(my $buf, CHUNKSIZE)

like this however $buf isn't passed to the method as a reference, so I changed that to:
I bodge fixed it by calling directly on the socket, ie: $self->{server}->{client}->sysread($buf, CHUNKSIZE)

On top of this the read seems to be non-blocking, so I replaced the die with a next when the read was 0 length.

I suspect that the main problems here are a) the overloaded sysread/syswrite calls are not being used. b) the socket is nonblocking and the code expects a blocking socket from Net/Server/Proto/SSLEAY.pm.

This can all be coded around in Starman, but I suspect the implementation problem is actually in Net::Server.

Advice and help appreciated.

OK I take that back - there is something even worse at work here. With the above changes It works on my small Hello World test app, but its just falls apart with larger requests, loading only a small part of each request. loading a large image for example gets only the first 30KB~ and then stops.

I'll have to leave this for people who know what they are doing!

@ap ap closed this Jul 20, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment