aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2009-02-27 18:40:17 +0000
committerMatthew Wild <mwild1@gmail.com>2009-02-27 18:40:17 +0000
commitc2b54ca16026643838440922fa966cea576f42d2 (patch)
tree2ec344987da52b5cdb31bc936253301bb27df423 /net
parent2a5e41bed0c75505a5367e87c7c6e48220443434 (diff)
downloadprosody-c2b54ca16026643838440922fa966cea576f42d2.tar.gz
prosody-c2b54ca16026643838440922fa966cea576f42d2.zip
net.server: Some fixes for SSL/TLS handshake handling
Diffstat (limited to 'net')
-rw-r--r--net/server.lua15
1 files changed, 11 insertions, 4 deletions
diff --git a/net/server.lua b/net/server.lua
index cea2ada3..aacadacc 100644
--- a/net/server.lua
+++ b/net/server.lua
@@ -480,16 +480,19 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
if sslctx then -- ssl?
ssl = true
local wrote
+ local read
local handshake = coroutine_wrap( function( client ) -- create handshake coroutine
local err
for i = 1, 10 do -- 10 handshake attemps
+ _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
+ _readlistlen = ( read and removesocket( _readlist, socket, _readlistlen ) ) or _readlistlen
+ read, wrote = nil, nil
_, err = client:dohandshake( )
if not err then
--out_put( "server.lua: ssl handshake done" )
- _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions
handler.sendbuffer = _sendbuffer
- --return dispatch( handler )
+ -- return dispatch( handler )
return true
else
out_put( "server.lua: error during ssl handshake: ", err )
@@ -497,6 +500,10 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
_sendlistlen = _sendlistlen + 1
_sendlist[ _sendlistlen ] = client
wrote = true
+ elseif err == "wantread" and not read then
+ _readlistlen = _readlistlen + 1
+ _readlist [ _readlistlen ] = client
+ read = true
end
--coroutine_yield( handler, nil, err ) -- handshake not finished
coroutine_yield( )
@@ -558,8 +565,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport
handler.starttls = nil
needtls = nil
- handler.receivedata = handler.handshake
- handler.dispatchdata = handler.handshake
+ handler.readbuffer = handshake
+ handler.sendbuffer = handshake
handshake( socket ) -- do handshake
end
handler.readbuffer = _readbuffer