summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@gnutls.org>2013-03-12 18:23:49 +0100
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2013-03-12 18:23:49 +0100
commita9a3a26ac27d2b003c4d245d32b59c92aa5ded35 (patch)
tree6bc1f3afb25a0bb423967045a2e7bc40251db167
parentba1a0fae3371baccaa24aed1f5fcdc12f6df82e1 (diff)
downloadgnutls-a9a3a26ac27d2b003c4d245d32b59c92aa5ded35.tar.gz
Added gnutls_session_get_desc()
-rw-r--r--NEWS1
-rw-r--r--doc/examples/ex-cert-select-pkcs11.c6
-rw-r--r--doc/examples/ex-cert-select.c6
-rw-r--r--doc/examples/ex-client-anon.c6
-rw-r--r--doc/examples/ex-client-dtls.c6
-rw-r--r--doc/examples/ex-client-psk.c6
-rw-r--r--doc/examples/ex-client-srp.c6
-rw-r--r--doc/examples/ex-client-x509.c6
-rw-r--r--lib/gnutls_int.h2
-rw-r--r--lib/gnutls_ui.c68
-rw-r--r--lib/includes/gnutls/gnutls.h.in1
-rw-r--r--lib/libgnutls.map1
-rw-r--r--src/common.c5
13 files changed, 111 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index c51ba998bb..d692d31e1f 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,7 @@ gnutls_x509_crq_get_dn2: Added
gnutls_x509_trust_list_remove_trust_mem: Added
gnutls_x509_trust_list_remove_trust_file: Added
gnutls_x509_trust_list_remove_cas: Added
+gnutls_session_get_desc: Added
* Version 3.1.9 (released 2013-02-27)
diff --git a/doc/examples/ex-cert-select-pkcs11.c b/doc/examples/ex-cert-select-pkcs11.c
index a437a51507..fb902be891 100644
--- a/doc/examples/ex-cert-select-pkcs11.c
+++ b/doc/examples/ex-cert-select-pkcs11.c
@@ -128,7 +128,11 @@ main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/doc/examples/ex-cert-select.c b/doc/examples/ex-cert-select.c
index b4ec2b1605..6e12a8d3a1 100644
--- a/doc/examples/ex-cert-select.c
+++ b/doc/examples/ex-cert-select.c
@@ -143,7 +143,11 @@ main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/doc/examples/ex-client-anon.c b/doc/examples/ex-client-anon.c
index 3d4d3afa08..4cb804e65d 100644
--- a/doc/examples/ex-client-anon.c
+++ b/doc/examples/ex-client-anon.c
@@ -70,7 +70,11 @@ main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/doc/examples/ex-client-dtls.c b/doc/examples/ex-client-dtls.c
index 026cb7d082..9b8fd98c21 100644
--- a/doc/examples/ex-client-dtls.c
+++ b/doc/examples/ex-client-dtls.c
@@ -87,7 +87,11 @@ main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/doc/examples/ex-client-psk.c b/doc/examples/ex-client-psk.c
index 4ebff50dcd..60da53e66b 100644
--- a/doc/examples/ex-client-psk.c
+++ b/doc/examples/ex-client-psk.c
@@ -80,7 +80,11 @@ main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/doc/examples/ex-client-srp.c b/doc/examples/ex-client-srp.c
index 7b4989608c..e828eb8eaa 100644
--- a/doc/examples/ex-client-srp.c
+++ b/doc/examples/ex-client-srp.c
@@ -77,7 +77,11 @@ main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/doc/examples/ex-client-x509.c b/doc/examples/ex-client-x509.c
index acd6593d47..bf8ae6bbef 100644
--- a/doc/examples/ex-client-x509.c
+++ b/doc/examples/ex-client-x509.c
@@ -96,7 +96,11 @@ int main (void)
}
else
{
- printf ("- Handshake was completed\n");
+ char* desc;
+
+ desc = gnutls_session_get_desc(session);
+ printf ("- Session info: %s\n", desc);
+ gnutls_free(desc);
}
gnutls_record_send (session, MSG, strlen (MSG));
diff --git a/lib/gnutls_int.h b/lib/gnutls_int.h
index 8c58b4abd1..305ecefcd7 100644
--- a/lib/gnutls_int.h
+++ b/lib/gnutls_int.h
@@ -536,7 +536,7 @@ typedef struct
/* FIXME: The following are not saved in the session storage
* for session resumption.
*/
-
+
/* Used by extensions that enable supplemental data: Which ones
* do that? Do they belong in security parameters?
*/
diff --git a/lib/gnutls_ui.c b/lib/gnutls_ui.c
index e8b12c3797..d4cce95e07 100644
--- a/lib/gnutls_ui.c
+++ b/lib/gnutls_ui.c
@@ -836,5 +836,71 @@ gnutls_certificate_set_rsa_export_params (gnutls_certificate_credentials_t
{
res->rsa_params = rsa_params;
}
-
#endif
+
+#define DESC_SIZE 64
+
+/**
+ * gnutls_session_get_desc:
+ * @session: is a gnutls session
+ *
+ * This function returns a string describing the current session.
+ * The string is null terminated and allocated using gnutls_malloc().
+ *
+ * Returns: a description of the protocols and algorithms in the current session.
+ *
+ * Since: 3.1.10
+ **/
+char *
+gnutls_session_get_desc (gnutls_session_t session)
+{
+ gnutls_kx_algorithm_t kx;
+ unsigned type;
+ char kx_name[32];
+ char proto_name[32];
+ const char* curve_name = NULL;
+ unsigned dh_bits = 0;
+ char* desc;
+
+ kx = session->security_parameters.kx_algorithm;
+
+ if (kx == GNUTLS_KX_ANON_ECDH || kx == GNUTLS_KX_ECDHE_PSK ||
+ kx == GNUTLS_KX_ECDHE_RSA || kx == GNUTLS_KX_ECDHE_ECDSA)
+ {
+ curve_name = gnutls_ecc_curve_get_name(gnutls_ecc_curve_get(session));
+ }
+ else if (kx == GNUTLS_KX_ANON_DH || kx == GNUTLS_KX_DHE_PSK ||
+ kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
+ {
+ dh_bits = gnutls_dh_get_prime_bits (session);
+ }
+
+ if (curve_name != NULL)
+ snprintf(kx_name, sizeof(kx_name), "%s-%s", gnutls_kx_get_name(kx), curve_name);
+ else if (dh_bits != 0)
+ snprintf(kx_name, sizeof(kx_name), "%s-%u", gnutls_kx_get_name(kx), dh_bits);
+ else
+ snprintf(kx_name, sizeof(kx_name), "%s", gnutls_kx_get_name(kx));
+
+ type = gnutls_certificate_type_get (session);
+ if (type == GNUTLS_CRT_X509)
+ snprintf(proto_name, sizeof(proto_name), "%s-PKIX", gnutls_protocol_get_name(_gnutls_protocol_get_version(session)));
+ else
+ snprintf(proto_name, sizeof(proto_name), "%s-%s", gnutls_protocol_get_name(_gnutls_protocol_get_version(session)),
+ gnutls_certificate_type_get_name(type));
+
+ gnutls_protocol_get_name(_gnutls_protocol_get_version (session)),
+
+ desc = gnutls_malloc(DESC_SIZE);
+ if (desc == NULL)
+ return NULL;
+
+ snprintf(desc, DESC_SIZE,
+ "(%s)-(%s)-(%s)-(%s)",
+ proto_name,
+ kx_name,
+ gnutls_cipher_get_name (gnutls_cipher_get (session)),
+ gnutls_mac_get_name (gnutls_mac_get (session)));
+
+ return desc;
+}
diff --git a/lib/includes/gnutls/gnutls.h.in b/lib/includes/gnutls/gnutls.h.in
index 872e4fdca0..851d397ae3 100644
--- a/lib/includes/gnutls/gnutls.h.in
+++ b/lib/includes/gnutls/gnutls.h.in
@@ -1090,6 +1090,7 @@ gnutls_ecc_curve_t gnutls_ecc_curve_get(gnutls_session_t session);
gnutls_datum_t * data);
void gnutls_session_get_random (gnutls_session_t session, gnutls_datum_t* client,
gnutls_datum_t* server);
+ char * gnutls_session_get_desc (gnutls_session_t session);
int gnutls_session_set_premaster (gnutls_session_t session, unsigned int entity,
gnutls_protocol_t version,
diff --git a/lib/libgnutls.map b/lib/libgnutls.map
index 3a793a1521..a762d189aa 100644
--- a/lib/libgnutls.map
+++ b/lib/libgnutls.map
@@ -900,6 +900,7 @@ GNUTLS_3_1_0 {
gnutls_x509_trust_list_remove_trust_mem;
gnutls_x509_trust_list_remove_trust_file;
gnutls_x509_trust_list_remove_cas;
+ gnutls_session_get_desc;
} GNUTLS_3_0_0;
GNUTLS_PRIVATE {
diff --git a/src/common.c b/src/common.c
index 6a6ede25cf..8663fc7753 100644
--- a/src/common.c
+++ b/src/common.c
@@ -457,8 +457,13 @@ print_info (gnutls_session_t session, int verbose, int print_cert)
unsigned char session_id[33];
size_t session_id_size = sizeof (session_id);
gnutls_srtp_profile_t srtp_profile;
+ char *desc;
int rc;
+ desc = gnutls_session_get_desc(session);
+ printf ("- Description: %s\n", desc);
+ gnutls_free(desc);
+
/* print session ID */
gnutls_session_get_id (session, session_id, &session_id_size);
printf ("- Session ID: %s\n",