From: Simon Ruderich Date: Sat, 10 Aug 2013 13:51:39 +0000 (+0200) Subject: Display TLS session information in level DEBUG2. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=988acc79a2e88342edf375f886cfd6cf098e4c9e;p=tlsproxy%2Ftlsproxy.git Display TLS session information in level DEBUG2. --- diff --git a/src/connection.c b/src/connection.c index 3056aa7..a473873 100644 --- a/src/connection.c +++ b/src/connection.c @@ -28,6 +28,8 @@ #include #include +#include + /* Maximum length of a HTTP request line. Longer request lines are aborted * with an error. The standard doesn't specify a maximum line length but this @@ -84,6 +86,8 @@ static int connect_to_host(const char *hostname, const char *port); static int parse_request(const char *buffer, char *host, char *port, int *version_minor); +static void log_session_information(gnutls_session_t session); + void handle_connection(int client_socket) { int server_socket; @@ -253,6 +257,10 @@ void handle_connection(int client_socket) { LOG(DEBUG1, "server TLS handshake finished"); + if (global_log_level >= LOG_DEBUG2_LEVEL) { + log_session_information(server_session); + } + /* Make sure the server certificate is valid and known. */ if (verify_tls_connection(server_session, host) != 0) { LOG(ERROR, "server certificate validation failed!"); @@ -296,6 +304,10 @@ void handle_connection(int client_socket) { LOG(DEBUG1, "client TLS handshake finished"); + if (global_log_level >= LOG_DEBUG2_LEVEL) { + log_session_information(client_session); + } + /* Tell the client that the verification failed. Shouldn't be necessary as * the client should terminate the connection because he received the * invalid certificate but better be sure. */ @@ -886,3 +898,71 @@ static int parse_request(const char *request, char *host, char *port, return 0; } + + +static void log_session_information(gnutls_session_t session) { + /* From doc/examples/ex-session-info.c of GnuTLS 3.2.3's tarball and + * modified, thanks. */ + + const char *tmp; + gnutls_credentials_type_t cred; + gnutls_kx_algorithm_t kx; + int dhe, ecdh; + + dhe = 0; + ecdh = 0; + + /* Key exchange algorithm. */ + kx = gnutls_kx_get(session); + LOG(DEBUG2, "- key exchange: %s", gnutls_kx_get_name(kx)); + + /* Authentication type. */ + cred = gnutls_auth_get_type(session); + switch (cred) { + case GNUTLS_CRD_CERTIFICATE: + if (kx == GNUTLS_KX_DHE_RSA + || kx == GNUTLS_KX_DHE_DSS) { + dhe = 1; +#ifdef GNUTLS_KX_ECDHE_RSA + } else if (kx == GNUTLS_KX_ECDHE_RSA + || kx == GNUTLS_KX_ECDHE_ECDSA) { + ecdh = 1; +#endif + } + break; + + case GNUTLS_CRD_IA: + case GNUTLS_CRD_SRP: + case GNUTLS_CRD_PSK: + case GNUTLS_CRD_ANON: + /* This shouldn't occur. */ + LOG(WARNING, "unexpected authentication method: %d", cred); + break; + } + + /* Information about key exchange. */ + if (dhe) { + LOG(DEBUG2, "- ephemeral DH using prime of %d bits", + gnutls_dh_get_prime_bits(session)); + } else if (ecdh) { +#ifdef GNUTLS_KX_ECDHE_RSA + LOG(DEBUG2, "- ephemeral ECDH using curve %s", + gnutls_ecc_curve_get_name(gnutls_ecc_curve_get(session))); +#endif + } + + tmp = gnutls_protocol_get_name(gnutls_protocol_get_version(session)); + LOG(DEBUG2, "- protocol: %s", tmp); /* e.g. TLS 1.0 */ + + tmp = gnutls_certificate_type_get_name(gnutls_certificate_type_get(session)); + LOG(DEBUG2, "- certificate type: %s", tmp); + + tmp = gnutls_compression_get_name(gnutls_compression_get(session)); + LOG(DEBUG2, "- compression: %s", tmp); + + tmp = gnutls_cipher_get_name(gnutls_cipher_get(session)); + LOG(DEBUG2, "- cipher: %s", tmp); + + tmp = gnutls_mac_get_name(gnutls_mac_get(session)); + LOG(DEBUG2, "- MAC: %s", tmp); +}