summaryrefslogtreecommitdiff
path: root/doc/tex/ex3.tex
blob: 6aca20fbb9063cf1291179c47602d1c23dd0ab0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
\begin{verbatim}

#define PRINTX(x,y) if (y[0]!=0) printf(" -   %s %s\n", x, y)
#define PRINT_DN(X) PRINTX( "CN:", X->common_name); \
	PRINTX( "OU:", X->organizational_unit_name); \
	PRINTX( "O:", X->organization); \
	PRINTX( "L:", X->locality_name); \
	PRINTX( "S:", X->state_or_province_name); \
	PRINTX( "C:", X->country); \
	PRINTX( "SAN:", gnutls_x509pki_client_get_subject_alt_name(x509_info))

int print_info(GNUTLS_STATE state)
{
   const char *tmp;
   const X509PKI_CLIENT_AUTH_INFO *x509_info;
   const gnutls_DN* dn;

   /* print the key exchange's algorithm name
    */
   tmp = gnutls_kx_get_name(gnutls_get_current_kx(state));
   printf("- Key Exchange: %s\n", tmp);

   /* in case of X509 PKI
    */
   if (gnutls_get_auth_info_type(state) == GNUTLS_X509PKI) {
      x509_info = gnutls_get_auth_info(state);
      if (x509_info != NULL) {
         switch ( gnutls_x509pki_client_get_peer_certificate_status(x509_info)) {
         case GNUTLS_CERT_NOT_TRUSTED:
            printf("- Peer's X509 Certificate was NOT verified\n");
            break;
         case GNUTLS_CERT_EXPIRED:
            printf("- Peer's X509 Certificate was verified but is expired\n");
            break;
         case GNUTLS_CERT_TRUSTED:
            printf("- Peer's X509 Certificate was verified\n");
            break;
         case GNUTLS_CERT_INVALID:
         default:
            printf("- Peer's X509 Certificate was invalid\n");
            break;

         }
         printf(" - Certificate info:\n");
         printf(" - Certificate version: #%d\n", gnutls_x509pki_client_get_peer_certificate_version(x509_info));

         dn = gnutls_x509pki_client_get_peer_dn( x509_info);
         PRINT_DN(dn);

         printf(" - Certificate Issuer's info:\n");
         dn = gnutls_x509pki_client_get_issuer_dn( x509_info);
         PRINT_DN(dn);
      }
   }

   tmp = gnutls_version_get_name(gnutls_get_current_version(state));
   printf("- Version: %s\n", tmp);

   tmp = gnutls_compression_get_name(gnutls_get_current_compression_method(state));
   printf("- Compression: %s\n", tmp);

   tmp = gnutls_cipher_get_name(gnutls_get_current_cipher(state));
   printf("- Cipher: %s\n", tmp);

   tmp = gnutls_mac_get_name(gnutls_get_current_mac_algorithm(state));
   printf("- MAC: %s\n", tmp);

   return 0;
}

\end{verbatim}