Diff

plugins/mod_s2s/mod_s2s.lua @ 5423:4acc1598f391

mod_s2s: Add COMPAT cahin verification code for older LuaSec versions
author Kim Alvefur <zash@zash.se>
date Thu, 04 Apr 2013 19:21:47 +0200
parent 5408:767ecb0091a6
child 5454:5f69fddf6fb9
line wrap: on
line diff
--- a/plugins/mod_s2s/mod_s2s.lua	Wed Apr 03 15:48:49 2013 +0200
+++ b/plugins/mod_s2s/mod_s2s.lua	Thu Apr 04 19:21:47 2013 +0200
@@ -15,6 +15,7 @@
 local tostring, type = tostring, type;
 local t_insert = table.insert;
 local xpcall, traceback = xpcall, debug.traceback;
+local NULL = {};
 
 local add_task = require "util.timer".add_task;
 local st = require "util.stanza";
@@ -226,11 +227,19 @@
 	end
 
 	if cert then
-		local chain_valid, errors = conn:getpeerverification()
+		local chain_valid, errors;
+		if conn.getpeerverification then
+			chain_valid, errors = conn:getpeerverification();
+		elseif conn.getpeerchainvalid then -- COMPAT mw/luasec-hg
+			chain_valid, errors = conn:getpeerchainvalid();
+			errors = (not chain_valid) and { { errors } } or nil;
+		else
+			chain_valid, errors = false, { { "Chain verification not supported by this version of LuaSec" } };
+		end
 		-- Is there any interest in printing out all/the number of errors here?
 		if not chain_valid then
 			(session.log or log)("debug", "certificate chain validation result: invalid");
-			for depth, t in ipairs(errors) do
+			for depth, t in ipairs(errors or NULL) do
 				(session.log or log)("debug", "certificate error(s) at depth %d: %s", depth-1, table.concat(t, ", "))
 			end
 			session.cert_chain_status = "invalid";