Software /
code /
prosody
Comparison
net/server_event.lua @ 12802:4a8740e01813
Merge 0.12->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 12 Dec 2022 07:10:54 +0100 |
parent | 12542:5ec9d6913162 |
child | 12974:ba409c67353b |
comparison
equal
deleted
inserted
replaced
12801:ebd6b4d8bf04 | 12802:4a8740e01813 |
---|---|
45 local s_sub = string.sub | 45 local s_sub = string.sub |
46 | 46 |
47 local coroutine_wrap = coroutine.wrap | 47 local coroutine_wrap = coroutine.wrap |
48 local coroutine_yield = coroutine.yield | 48 local coroutine_yield = coroutine.yield |
49 | 49 |
50 local has_luasec, ssl = pcall ( require , "ssl" ) | 50 local has_luasec = pcall ( require , "ssl" ) |
51 local socket = require "socket" | 51 local socket = require "socket" |
52 local levent = require "luaevent.core" | 52 local levent = require "luaevent.core" |
53 local inet = require "util.net"; | 53 local inet = require "util.net"; |
54 local inet_pton = inet.pton; | 54 local inet_pton = inet.pton; |
55 local sslconfig = require "util.sslconfig"; | |
56 local tls_impl = require "net.tls_luasec"; | |
55 | 57 |
56 local socket_gettime = socket.gettime | 58 local socket_gettime = socket.gettime |
57 | 59 |
58 local log = require ("util.logger").init("socket") | 60 local log = require ("util.logger").init("socket") |
59 | 61 |
151 local _ | 153 local _ |
152 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! | 154 _ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks! |
153 _ = self.eventwrite and self.eventwrite:close( ) | 155 _ = self.eventwrite and self.eventwrite:close( ) |
154 self.eventread, self.eventwrite = nil, nil | 156 self.eventread, self.eventwrite = nil, nil |
155 local err | 157 local err |
156 self.conn, err = ssl.wrap( self.conn, self._sslctx ) | 158 self.conn, err = self._sslctx:wrap(self.conn) |
157 if err then | 159 if err then |
158 self.fatalerror = err | 160 self.fatalerror = err |
159 self.conn = nil -- cannot be used anymore | 161 self.conn = nil -- cannot be used anymore |
160 if call_onconnect then | 162 if call_onconnect then |
161 self.ondisconnect = nil -- don't call this when client isn't really connected | 163 self.ondisconnect = nil -- don't call this when client isn't really connected |
166 end | 168 end |
167 | 169 |
168 if self.conn.sni then | 170 if self.conn.sni then |
169 if self.servername then | 171 if self.servername then |
170 self.conn:sni(self.servername); | 172 self.conn:sni(self.servername); |
171 elseif self._server and type(self._server.hosts) == "table" and next(self._server.hosts) ~= nil then | 173 elseif next(self._sslctx._sni_contexts) ~= nil then |
172 self.conn:sni(self._server.hosts, true); | 174 self.conn:sni(self._sslctx._sni_contexts, true); |
173 end | 175 end |
174 end | 176 end |
175 | 177 |
176 self.conn:settimeout( 0 ) -- set non blocking | 178 self.conn:settimeout( 0 ) -- set non blocking |
177 local handshakecallback = coroutine_wrap(function( event ) | 179 local handshakecallback = coroutine_wrap(function( event ) |
270 end | 272 end |
271 end | 273 end |
272 | 274 |
273 function interface_mt:pause() | 275 function interface_mt:pause() |
274 return self:_lock(self.nointerface, true, self.nowriting); | 276 return self:_lock(self.nointerface, true, self.nowriting); |
277 end | |
278 | |
279 function interface_mt:sslctx() | |
280 return self._sslctx | |
281 end | |
282 | |
283 function interface_mt:ssl_info() | |
284 local sock = self.conn; | |
285 if not sock.info then return nil, "not-implemented"; end | |
286 return sock:info(); | |
287 end | |
288 | |
289 function interface_mt:ssl_peercertificate() | |
290 local sock = self.conn; | |
291 if not sock.getpeercertificate then return nil, "not-implemented"; end | |
292 return sock:getpeercertificate(); | |
293 end | |
294 | |
295 function interface_mt:ssl_peerverification() | |
296 local sock = self.conn; | |
297 if not sock.getpeerverification then return nil, { { "Chain verification not supported" } }; end | |
298 return sock:getpeerverification(); | |
299 end | |
300 | |
301 function interface_mt:ssl_peerfinished() | |
302 local sock = self.conn; | |
303 if not sock.getpeerfinished then return nil, "not-implemented"; end | |
304 return sock:getpeerfinished(); | |
275 end | 305 end |
276 | 306 |
277 function interface_mt:resume() | 307 function interface_mt:resume() |
278 self:_lock(self.nointerface, false, self.nowriting); | 308 self:_lock(self.nointerface, false, self.nowriting); |
279 if self.readcallback and not self.eventread then | 309 if self.readcallback and not self.eventread then |
922 get_backend = get_backend, | 952 get_backend = get_backend, |
923 hook_signal = hook_signal, | 953 hook_signal = hook_signal, |
924 add_task = add_task, | 954 add_task = add_task, |
925 watchfd = watchfd, | 955 watchfd = watchfd, |
926 | 956 |
957 tls_builder = function(basedir) | |
958 return sslconfig._new(tls_impl.new_context, basedir) | |
959 end, | |
960 | |
927 __NAME = SCRIPT_NAME, | 961 __NAME = SCRIPT_NAME, |
928 __DATE = LAST_MODIFIED, | 962 __DATE = LAST_MODIFIED, |
929 __AUTHOR = SCRIPT_AUTHOR, | 963 __AUTHOR = SCRIPT_AUTHOR, |
930 __VERSION = SCRIPT_VERSION, | 964 __VERSION = SCRIPT_VERSION, |
931 | 965 |