Skip to content

Commit cbc41c2

Browse files
committed
log ssl keys using a Lua script
Add a Lua script to log SSL keys to decipher traffic in an output file. This is available through a http-request action. To execute only once per connection a session variable is used. To be able to use SSL keys fetch the setting tune.ssl.keylog must be activated in haproxy configuration. The output file is specified as a parameter to the http-request action. It is set to /logs/keys.log which is the path inspected by the interop. This will allow to support on the interop several tests which rely on traffic deciphering even if the client do not log SSL keys. For the moment, only mvfst seems to be in this case.
1 parent bd29288 commit cbc41c2

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ COPY --from=builder-ssl \
4949
/usr/local/lib/libssl.so* /usr/local/lib/libcrypto.so* /usr/local/lib/
5050
COPY --from=builder /usr/local/sbin/haproxy /usr/local/sbin/
5151
COPY quic.cfg lighttpd.cfg /
52+
COPY sslkeylogger.lua /
5253

5354
COPY run_endpoint.sh .
5455
RUN chmod +x run_endpoint.sh

quic.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
global
22
cluster-secret what-a-secret!
33

4+
tune.ssl.keylog on
5+
lua-load sslkeylogger.lua
6+
47
expose-experimental-directives
58
trace quic sink stderr
69
trace quic level developer
@@ -22,6 +25,9 @@ defaults
2225
frontend fe
2326
bind quic4@:443 proto quic ssl allow-0rtt crt /tmp/cert.pem alpn hq-interop,h3 "${HAP_EXTRA_ARGS}"
2427
bind quic6@:443 proto quic ssl allow-0rtt crt /tmp/cert.pem alpn hq-interop,h3 "${HAP_EXTRA_ARGS}"
28+
29+
http-request lua.sslkeylog /logs/keys.log
30+
2531
use_backend be
2632

2733
backend be

sslkeylogger.lua

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
local function sslkeylog(txn, filename)
2+
local fields = {
3+
CLIENT_EARLY_TRAFFIC_SECRET = function() return txn.f:ssl_fc_client_early_traffic_secret() end,
4+
CLIENT_HANDSHAKE_TRAFFIC_SECRET = function() return txn.f:ssl_fc_client_handshake_traffic_secret() end,
5+
SERVER_HANDSHAKE_TRAFFIC_SECRET = function() return txn.f:ssl_fc_server_handshake_traffic_secret() end,
6+
CLIENT_TRAFFIC_SECRET_0 = function() return txn.f:ssl_fc_client_traffic_secret_0() end,
7+
SERVER_TRAFFIC_SECRET_0 = function() return txn.f:ssl_fc_server_traffic_secret_0() end,
8+
EXPORTER_SECRET = function() return txn.f:ssl_fc_exporter_secret() end,
9+
EARLY_EXPORTER_SECRET = function() return txn.f:ssl_fc_early_exporter_secret() end
10+
}
11+
12+
local client_random = txn.c:hex(txn.f:ssl_fc_client_random())
13+
14+
if not txn:get_var('sess.sslkeylogdone') then
15+
file = io.open(filename, 'a')
16+
for fieldname, fetch in pairs(fields) do
17+
if fetch() then
18+
file:write(string.format('%s %s %s\n', fieldname, client_random, fetch()))
19+
end
20+
end
21+
22+
file:close()
23+
txn:set_var('sess.sslkeylogdone', true)
24+
end
25+
end
26+
27+
core.register_action('sslkeylog', { 'http-req' }, sslkeylog, 1)

0 commit comments

Comments
 (0)