Skip to content

Commit 058f257

Browse files
committed
tlshd: Show ingress certificate on successful handshake
As a debugging aid and for auditing, emit a one-line summary of incoming certificate(s) after a successful handshake. Server-side only. Signed-off-by: Chuck Lever <[email protected]>
1 parent d3d5c3a commit 058f257

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/tlshd/server.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,28 @@ static void tlshd_tls13_server_x509_handshake(struct tlshd_handshake_parms *parm
273273

274274
tlshd_start_tls_handshake(session, parms);
275275

276+
if (tlshd_debug &&
277+
gnutls_certificate_type_get(session) == GNUTLS_CRT_X509) {
278+
const gnutls_datum_t *peercerts;
279+
unsigned int i, num_certs = 0;
280+
281+
peercerts = gnutls_certificate_get_peers(session, &num_certs);
282+
for (i = 0; i < num_certs; i++) {
283+
gnutls_x509_crt_t cert;
284+
gnutls_datum_t cinfo;
285+
286+
gnutls_x509_crt_init(&cert);
287+
gnutls_x509_crt_import(cert, &peercerts[i],
288+
GNUTLS_X509_FMT_DER);
289+
if (gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_ONELINE,
290+
&cinfo) == 0) {
291+
tlshd_log_debug("Peer certificate: %s", cinfo.data);
292+
gnutls_free(cinfo.data);
293+
}
294+
gnutls_x509_crt_deinit(cert);
295+
}
296+
}
297+
276298
gnutls_deinit(session);
277299

278300
out_free_creds:

0 commit comments

Comments
 (0)