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
;
27 /* print the key exchange's algorithm name
29 kx
= gnutls_kx_get (session
);
30 tmp
= gnutls_kx_get_name (kx
);
31 printf ("- Key Exchange: %s\n", tmp
);
33 /* Check the authentication type used and switch
36 cred
= gnutls_auth_get_type (session
);
40 printf ("- TLS/IA session\n");
46 printf ("- SRP session with username %s\n",
47 gnutls_srp_server_get_username (session
));
52 /* This returns NULL in server side.
54 if (gnutls_psk_client_get_hint (session
) != NULL
)
55 printf ("- PSK authentication. PSK hint '%s'\n",
56 gnutls_psk_client_get_hint (session
));
57 /* This returns NULL in client side.
59 if (gnutls_psk_server_get_username (session
) != NULL
)
60 printf ("- PSK authentication. Connected as '%s'\n",
61 gnutls_psk_server_get_username (session
));
63 if (kx
== GNUTLS_KX_ECDHE_PSK
)
65 else if (kx
== GNUTLS_KX_DHE_PSK
)
69 case GNUTLS_CRD_ANON
: /* anonymous authentication */
71 printf ("- Anonymous authentication.\n");
72 if (kx
== GNUTLS_KX_ANON_ECDH
)
74 else if (kx
== GNUTLS_KX_ANON_DH
)
78 case GNUTLS_CRD_CERTIFICATE
: /* certificate authentication */
80 /* Check if we have been using ephemeral Diffie-Hellman.
82 if (kx
== GNUTLS_KX_DHE_RSA
|| kx
== GNUTLS_KX_DHE_DSS
)
84 else if (kx
== GNUTLS_KX_ECDHE_RSA
|| kx
== GNUTLS_KX_ECDHE_ECDSA
)
87 /* if the certificate list is available, then
88 * print some information about it.
90 print_x509_certificate_info (session
);
95 printf ("- Ephemeral ECDH using curve %s\n",
96 gnutls_ecc_curve_get_name (gnutls_ecc_curve_get (session
)));
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)
103 tmp
= gnutls_protocol_get_name (gnutls_protocol_get_version (session
));
104 printf ("- Protocol: %s\n", tmp
);
106 /* print the certificate type of the peer.
110 gnutls_certificate_type_get_name (gnutls_certificate_type_get (session
));
112 printf ("- Certificate Type: %s\n", tmp
);
114 /* print the compression algorithm (if any)
116 tmp
= gnutls_compression_get_name (gnutls_compression_get (session
));
117 printf ("- Compression: %s\n", tmp
);
119 /* print the name of the cipher used.
122 tmp
= gnutls_cipher_get_name (gnutls_cipher_get (session
));
123 printf ("- Cipher: %s\n", tmp
);
125 /* Print the MAC algorithms name.
128 tmp
= gnutls_mac_get_name (gnutls_mac_get (session
));
129 printf ("- MAC: %s\n", tmp
);