GnuTLS: Implement tls_get_cipher()

Provide OpenSSL-style name for the negotiated cipher suite.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2017-12-28 17:41:20 +02:00
parent 5791d2117c
commit 5d292fcfbd

View file

@ -1538,8 +1538,35 @@ int tls_get_version(void *ssl_ctx, struct tls_connection *conn,
int tls_get_cipher(void *ssl_ctx, struct tls_connection *conn,
char *buf, size_t buflen)
{
/* TODO */
buf[0] = '\0';
gnutls_cipher_algorithm_t cipher;
gnutls_kx_algorithm_t kx;
gnutls_mac_algorithm_t mac;
const char *kx_str, *cipher_str, *mac_str;
int res;
cipher = gnutls_cipher_get(conn->session);
cipher_str = gnutls_cipher_get_name(cipher);
if (!cipher_str)
cipher_str = "";
kx = gnutls_kx_get(conn->session);
kx_str = gnutls_kx_get_name(kx);
if (!kx_str)
kx_str = "";
mac = gnutls_mac_get(conn->session);
mac_str = gnutls_mac_get_name(mac);
if (!mac_str)
mac_str = "";
if (kx == GNUTLS_KX_RSA)
res = os_snprintf(buf, buflen, "%s-%s", cipher_str, mac_str);
else
res = os_snprintf(buf, buflen, "%s-%s-%s",
kx_str, cipher_str, mac_str);
if (os_snprintf_error(buflen, res))
return -1;
return 0;
}