DEV: sslkeylogger: handle file opening error

Prevent a Lua error if output file cannot be opened when logging SSL
keys. Report a warning instead with the error description.
This commit is contained in:
Amaury Denoyelle 2023-10-03 15:05:56 +02:00
parent b019636cd7
commit e1e6fbb3fd
1 changed files with 9 additions and 5 deletions

View File

@ -28,14 +28,18 @@ local function sslkeylog(txn, filename)
-- ensure that a key is written only once by using a session variable -- ensure that a key is written only once by using a session variable
if not txn:get_var('sess.sslkeylogdone') then if not txn:get_var('sess.sslkeylogdone') then
file = io.open(filename, 'a') local file, err = io.open(filename, 'a')
if file then
for fieldname, fetch in pairs(fields) do for fieldname, fetch in pairs(fields) do
if fetch() then if fetch() then
file:write(string.format('%s %s %s\n', fieldname, client_random, fetch())) file:write(string.format('%s %s %s\n', fieldname, client_random, fetch()))
end end
end end
file:close() file:close()
else
core.Warning("Cannot open SSL log file: " .. err .. ".")
end
txn:set_var('sess.sslkeylogdone', true) txn:set_var('sess.sslkeylogdone', true)
end end
end end