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
17 int print_info(gnutls_session_t session)
20 gnutls_credentials_type_t cred;
21 gnutls_kx_algorithm_t kx;
26 /* print the key exchange's algorithm name
28 kx = gnutls_kx_get(session);
29 tmp = gnutls_kx_get_name(kx);
30 printf("- Key Exchange: %s\n", tmp);
32 /* Check the authentication type used and switch
35 cred = gnutls_auth_get_type(session);
38 printf("- TLS/IA session\n");
44 printf("- SRP session with username %s\n",
45 gnutls_srp_server_get_username(session));
50 /* This returns NULL in server side.
52 if (gnutls_psk_client_get_hint(session) != NULL)
53 printf("- PSK authentication. PSK hint '%s'\n",
54 gnutls_psk_client_get_hint(session));
55 /* This returns NULL in client side.
57 if (gnutls_psk_server_get_username(session) != NULL)
58 printf("- PSK authentication. Connected as '%s'\n",
59 gnutls_psk_server_get_username(session));
61 if (kx == GNUTLS_KX_ECDHE_PSK)
63 else if (kx == GNUTLS_KX_DHE_PSK)
67 case GNUTLS_CRD_ANON: /* anonymous authentication */
69 printf("- Anonymous authentication.\n");
70 if (kx == GNUTLS_KX_ANON_ECDH)
72 else if (kx == GNUTLS_KX_ANON_DH)
76 case GNUTLS_CRD_CERTIFICATE: /* certificate authentication */
78 /* Check if we have been using ephemeral Diffie-Hellman.
80 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
82 else if (kx == GNUTLS_KX_ECDHE_RSA
83 || kx == GNUTLS_KX_ECDHE_ECDSA)
86 /* if the certificate list is available, then
87 * print some information about it.
89 print_x509_certificate_info(session);
94 printf("- Ephemeral ECDH using curve %s\n",
95 gnutls_ecc_curve_get_name(gnutls_ecc_curve_get
98 printf("- Ephemeral DH using prime of %d bits\n",
99 gnutls_dh_get_prime_bits(session));
101 /* print the protocol's name (ie TLS 1.0)
104 gnutls_protocol_get_name(gnutls_protocol_get_version(session));
105 printf("- Protocol: %s\n", tmp);
107 /* print the certificate type of the peer.
111 gnutls_certificate_type_get_name(gnutls_certificate_type_get
114 printf("- Certificate Type: %s\n", tmp);
116 /* print the compression algorithm (if any)
118 tmp = gnutls_compression_get_name(gnutls_compression_get(session));
119 printf("- Compression: %s\n", tmp);
121 /* print the name of the cipher used.
124 tmp = gnutls_cipher_get_name(gnutls_cipher_get(session));
125 printf("- Cipher: %s\n", tmp);
127 /* Print the MAC algorithms name.
130 tmp = gnutls_mac_get_name(gnutls_mac_get(session));
131 printf("- MAC: %s\n", tmp);