1 /* This example code is placed in the public domain. */
9 #include <gnutls/gnutls.h>
10 #include <gnutls/x509.h>
14 /* This function will print some details of the
18 print_info (gnutls_session_t session)
21 gnutls_credentials_type_t cred;
22 gnutls_kx_algorithm_t kx;
24 /* print the key exchange's algorithm name
26 kx = gnutls_kx_get (session);
27 tmp = gnutls_kx_get_name (kx);
28 printf ("- Key Exchange: %s\n", tmp);
30 /* Check the authentication type used and switch
33 cred = gnutls_auth_get_type (session);
37 printf ("- TLS/IA session\n");
43 printf ("- SRP session with username %s\n",
44 gnutls_srp_server_get_username (session));
49 /* This returns NULL in server side.
51 if (gnutls_psk_client_get_hint (session) != NULL)
52 printf ("- PSK authentication. PSK hint '%s'\n",
53 gnutls_psk_client_get_hint (session));
54 /* This returns NULL in client side.
56 if (gnutls_psk_server_get_username (session) != NULL)
57 printf ("- PSK authentication. Connected as '%s'\n",
58 gnutls_psk_server_get_username (session));
61 case GNUTLS_CRD_ANON: /* anonymous authentication */
63 printf ("- Anonymous DH using prime of %d bits\n",
64 gnutls_dh_get_prime_bits (session));
67 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */
69 /* Check if we have been using ephemeral Diffie-Hellman.
71 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
73 printf ("\n- Ephemeral DH using prime of %d bits\n",
74 gnutls_dh_get_prime_bits (session));
77 /* if the certificate list is available, then
78 * print some information about it.
80 print_x509_certificate_info (session);
84 /* print the protocol's name (ie TLS 1.0)
86 tmp = gnutls_protocol_get_name (gnutls_protocol_get_version (session));
87 printf ("- Protocol: %s\n", tmp);
89 /* print the certificate type of the peer.
93 gnutls_certificate_type_get_name (gnutls_certificate_type_get (session));
95 printf ("- Certificate Type: %s\n", tmp);
97 /* print the compression algorithm (if any)
99 tmp = gnutls_compression_get_name (gnutls_compression_get (session));
100 printf ("- Compression: %s\n", tmp);
102 /* print the name of the cipher used.
105 tmp = gnutls_cipher_get_name (gnutls_cipher_get (session));
106 printf ("- Cipher: %s\n", tmp);
108 /* Print the MAC algorithms name.
111 tmp = gnutls_mac_get_name (gnutls_mac_get (session));
112 printf ("- MAC: %s\n", tmp);