From 390df4ca2e4098a6235f19b95b3df7a5a43aaeb9 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 12 Jul 2009 15:18:53 +0100 Subject: net.server: Don't continue with socket initialisation if SSL handshake failed, fixes nil socket traceback --- net/server.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/server.lua b/net/server.lua index 9418d388..78f79b56 100644 --- a/net/server.lua +++ b/net/server.lua @@ -546,7 +546,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport socket:settimeout( 0 ) handler.readbuffer = handshake handler.sendbuffer = handshake - handshake( socket ) -- do handshake + if not handshake( socket ) then -- do handshake + return nil, nil, "ssl handshake failed"; + end else -- We're not automatically doing SSL, so we're not secure (yet) ssl = false -- cgit v1.2.3 From 9b42931a189ae66889607923f42c0938e23e2fa3 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 12 Jul 2009 15:20:43 +0100 Subject: net.httpserver: Add helper function to set up HTTP server according to given config options --- net/httpserver.lua | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/net/httpserver.lua b/net/httpserver.lua index d159202e..77cc5b98 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -17,7 +17,7 @@ local listener; local t_insert, t_concat = table.insert, table.concat; local s_match, s_gmatch = string.match, string.gmatch; -local tonumber, tostring, pairs = tonumber, tostring, pairs; +local tonumber, tostring, pairs, ipairs, type = tonumber, tostring, pairs, ipairs, type; local urlencode = function (s) return s and (s:gsub("%W", function (c) return string.format("%%%02x", c:byte()); end)); end @@ -250,6 +250,26 @@ function new(params) end end +function new_from_config(ports, handle_request) + for _, options in ipairs(ports) do + local port, base, ssl, interface = 5280, "http-bind", false, nil; + if type(options) == "number" then + port = options; + elseif type(options) == "table" then + port, base, ssl, interface = options.port or 5280, options.path or "http-bind", options.ssl or false, options.interface; + elseif type(options) == "string" then + base = options; + end + + if ssl then + ssl.mode = "server"; + ssl.protocol = "sslv23"; + end + + new{ port = port, base = base, handler = handle_request, ssl = ssl, type = (ssl and "ssl") or "tcp" } + end +end + _M.request_reader = request_reader; _M.send_response = send_response; _M.urlencode = urlencode; -- cgit v1.2.3 From ca69ee89225e918759e02fd7e36a04eb27900b11 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 12 Jul 2009 15:21:10 +0100 Subject: mod_bosh: Use new httpserver helper to initialise ports --- plugins/mod_bosh.lua | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/plugins/mod_bosh.lua b/plugins/mod_bosh.lua index b07238bd..ccf08ec4 100644 --- a/plugins/mod_bosh.lua +++ b/plugins/mod_bosh.lua @@ -276,16 +276,6 @@ function on_timer() end local ports = config.get(module.host, "core", "bosh_ports") or { 5280 }; -for _, options in ipairs(ports) do - local port, base, ssl, interface = 5280, "http-bind", false, nil; - if type(options) == "number" then - port = options; - elseif type(options) == "table" then - port, base, ssl, interface = options.port or 5280, options.path or "http-bind", options.ssl or false, options.interface; - elseif type(options) == "string" then - base = options; - end - httpserver.new{ port = port, base = base, handler = handle_request, ssl = ssl } -end +httpserver.new_from_config(ports, handle_request); server.addtimer(on_timer); -- cgit v1.2.3 From 4117259212afab1c15f98eaeffb8c442cfa54c8c Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 12 Jul 2009 15:22:37 +0100 Subject: mod_httpserver: Use new httpserver helper to initialise ports --- plugins/mod_httpserver.lua | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 98a3a36e..0f1d991c 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -28,14 +28,4 @@ local function handle_request(method, body, request) end local ports = config.get(module.host, "core", "http_ports") or { 5280 }; -for _, options in ipairs(ports) do - local port, base, ssl, interface = 5280, "files", false, nil; - if type(options) == "number" then - port = options; - elseif type(options) == "table" then - port, base, ssl, interface = options.port or 5280, options.path or "files", options.ssl or false, options.interface; - elseif type(options) == "string" then - base = options; - end - httpserver.new{ port = port, base = base, handler = handle_request, ssl = ssl } -end +httpserver.new_from_config(ports, handle_request); -- cgit v1.2.3