texinfo documentation is similar to the printed manual.
[gnutls.git] / src / common.c
blob48f56bdcc75e5ad94379b2b260b3dff64a931bb9
1 /*
2 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
3 * Author: Nikos Mavrogiannopoulos
5 * This file is part of GnuTLS.
7 * GnuTLS is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * GnuTLS is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <config.h>
23 /* Work around problem reported in
24 <http://permalink.gmane.org/gmane.comp.lib.gnulib.bugs/15755>.*/
25 #if GETTIMEOFDAY_CLOBBERS_LOCALTIME
26 #undef localtime
27 #endif
29 #include <getpass.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <gnutls/gnutls.h>
35 #include <gnutls/x509.h>
36 #include <gnutls/openpgp.h>
37 #include <time.h>
38 #include <common.h>
40 #define SU(x) (x!=NULL?x:"Unknown")
42 extern int verbose;
44 const char str_unknown[] = "(unknown)";
46 /* Hex encodes the given data.
48 const char *
49 raw_to_string (const unsigned char *raw, size_t raw_size)
51 static char buf[1024];
52 size_t i;
53 if (raw_size == 0)
54 return NULL;
56 if (raw_size * 3 + 1 >= sizeof (buf))
57 return NULL;
59 for (i = 0; i < raw_size; i++)
61 sprintf (&(buf[i * 3]), "%02X%s", raw[i],
62 (i == raw_size - 1) ? "" : ":");
64 buf[sizeof (buf) - 1] = '\0';
66 return buf;
69 static void
70 print_x509_info_compact (gnutls_session_t session)
72 gnutls_x509_crt_t crt;
73 const gnutls_datum_t *cert_list;
74 unsigned int cert_list_size = 0;
75 int ret;
76 gnutls_datum_t cinfo;
78 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
79 if (cert_list_size == 0)
81 fprintf (stderr, "No certificates found!\n");
82 return;
85 gnutls_x509_crt_init (&crt);
86 ret =
87 gnutls_x509_crt_import (crt, &cert_list[0],
88 GNUTLS_X509_FMT_DER);
89 if (ret < 0)
91 fprintf (stderr, "Decoding error: %s\n",
92 gnutls_strerror (ret));
93 return;
96 ret =
97 gnutls_x509_crt_print (crt, GNUTLS_CRT_PRINT_COMPACT, &cinfo);
98 if (ret == 0)
100 printf ("- X.509 cert: %s\n", cinfo.data);
101 gnutls_free (cinfo.data);
104 gnutls_x509_crt_deinit (crt);
107 static void
108 print_x509_info (gnutls_session_t session, int flag, int print_cert)
110 gnutls_x509_crt_t crt;
111 const gnutls_datum_t *cert_list;
112 unsigned int cert_list_size = 0, j;
113 int ret;
115 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
116 if (cert_list_size == 0)
118 fprintf (stderr, "No certificates found!\n");
119 return;
122 printf ("- Certificate type: X.509\n");
123 printf ("- Got a certificate list of %d certificates.\n",
124 cert_list_size);
126 for (j = 0; j < cert_list_size; j++)
128 gnutls_datum_t cinfo;
130 gnutls_x509_crt_init (&crt);
131 ret =
132 gnutls_x509_crt_import (crt, &cert_list[j],
133 GNUTLS_X509_FMT_DER);
134 if (ret < 0)
136 fprintf (stderr, "Decoding error: %s\n",
137 gnutls_strerror (ret));
138 return;
141 printf ("- Certificate[%d] info:\n - ", j);
143 ret =
144 gnutls_x509_crt_print (crt, flag, &cinfo);
145 if (ret == 0)
147 printf ("%s\n", cinfo.data);
148 gnutls_free (cinfo.data);
151 if (print_cert)
153 size_t size = 0;
154 char *p = NULL;
156 ret =
157 gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM, p,
158 &size);
159 if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
161 p = malloc (size);
162 if (!p)
164 fprintf (stderr, "gnutls_malloc\n");
165 exit (1);
168 ret =
169 gnutls_x509_crt_export (crt, GNUTLS_X509_FMT_PEM,
170 p, &size);
172 if (ret < 0)
174 fprintf (stderr, "Encoding error: %s\n",
175 gnutls_strerror (ret));
176 return;
179 fputs ("\n", stdout);
180 fputs (p, stdout);
181 fputs ("\n", stdout);
183 gnutls_free (p);
186 gnutls_x509_crt_deinit (crt);
190 /* returns true or false, depending on whether the hostname
191 * matches to certificate */
192 static int
193 verify_x509_hostname (gnutls_session_t session, const char *hostname)
195 gnutls_x509_crt_t crt;
196 const gnutls_datum_t *cert_list;
197 unsigned int cert_list_size = 0;
198 int ret;
200 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
201 if (cert_list_size == 0)
203 fprintf (stderr, "No certificates found!\n");
204 return 0;
207 gnutls_x509_crt_init (&crt);
208 ret =
209 gnutls_x509_crt_import (crt, &cert_list[0],
210 GNUTLS_X509_FMT_DER);
211 if (ret < 0)
213 fprintf (stderr, "Decoding error: %s\n",
214 gnutls_strerror (ret));
215 return 0;
218 /* Check the hostname of the first certificate if it matches
219 * the name of the host we connected to.
221 if (hostname != NULL)
223 if (gnutls_x509_crt_check_hostname (crt, hostname) == 0)
225 printf
226 ("- The hostname in the certificate does NOT match '%s'\n",
227 hostname);
228 ret = 0;
230 else
232 printf ("- The hostname in the certificate matches '%s'.\n",
233 hostname);
234 ret = 1;
238 gnutls_x509_crt_deinit (crt);
240 return ret;
243 #ifdef ENABLE_OPENPGP
244 /* returns true or false, depending on whether the hostname
245 * matches to certificate */
246 static int
247 verify_openpgp_hostname (gnutls_session_t session, const char *hostname)
249 gnutls_openpgp_crt_t crt;
250 const gnutls_datum_t *cert_list;
251 unsigned int cert_list_size = 0;
252 int ret;
254 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
255 if (cert_list_size == 0)
257 fprintf (stderr, "No certificates found!\n");
258 return 0;
261 gnutls_openpgp_crt_init (&crt);
262 ret =
263 gnutls_openpgp_crt_import (crt, &cert_list[0],
264 GNUTLS_OPENPGP_FMT_RAW);
265 if (ret < 0)
267 fprintf (stderr, "Decoding error: %s\n",
268 gnutls_strerror (ret));
269 return 0;
272 /* Check the hostname of the first certificate if it matches
273 * the name of the host we connected to.
275 if (gnutls_openpgp_crt_check_hostname (crt, hostname) == 0)
277 printf
278 ("- The hostname in the certificate does NOT match '%s'\n",
279 hostname);
280 ret = 0;
282 else
284 printf ("- The hostname in the certificate matches '%s'.\n",
285 hostname);
286 ret = 1;
289 gnutls_openpgp_crt_deinit (crt);
291 return ret;
294 static void
295 print_openpgp_info_compact (gnutls_session_t session)
298 gnutls_openpgp_crt_t crt;
299 const gnutls_datum_t *cert_list;
300 unsigned int cert_list_size = 0;
301 int ret;
303 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
305 if (cert_list_size > 0)
307 gnutls_datum_t cinfo;
309 gnutls_openpgp_crt_init (&crt);
310 ret = gnutls_openpgp_crt_import (crt, &cert_list[0],
311 GNUTLS_OPENPGP_FMT_RAW);
312 if (ret < 0)
314 fprintf (stderr, "Decoding error: %s\n",
315 gnutls_strerror (ret));
316 return;
319 ret =
320 gnutls_openpgp_crt_print (crt, GNUTLS_CRT_PRINT_COMPACT, &cinfo);
321 if (ret == 0)
323 printf ("- OpenPGP cert: %s\n", cinfo.data);
324 gnutls_free (cinfo.data);
327 gnutls_openpgp_crt_deinit (crt);
331 static void
332 print_openpgp_info (gnutls_session_t session, int flag, int print_cert)
335 gnutls_openpgp_crt_t crt;
336 const gnutls_datum_t *cert_list;
337 unsigned int cert_list_size = 0;
338 int ret;
340 printf ("- Certificate type: OpenPGP\n");
342 cert_list = gnutls_certificate_get_peers (session, &cert_list_size);
344 if (cert_list_size > 0)
346 gnutls_datum_t cinfo;
348 gnutls_openpgp_crt_init (&crt);
349 ret = gnutls_openpgp_crt_import (crt, &cert_list[0],
350 GNUTLS_OPENPGP_FMT_RAW);
351 if (ret < 0)
353 fprintf (stderr, "Decoding error: %s\n",
354 gnutls_strerror (ret));
355 return;
358 ret =
359 gnutls_openpgp_crt_print (crt, flag, &cinfo);
360 if (ret == 0)
362 printf ("- %s\n", cinfo.data);
363 gnutls_free (cinfo.data);
366 if (print_cert)
368 size_t size = 0;
369 char *p = NULL;
371 ret =
372 gnutls_openpgp_crt_export (crt,
373 GNUTLS_OPENPGP_FMT_BASE64,
374 p, &size);
375 if (ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
377 p = malloc (size);
378 if (!p)
380 fprintf (stderr, "gnutls_malloc\n");
381 exit (1);
384 ret =
385 gnutls_openpgp_crt_export (crt,
386 GNUTLS_OPENPGP_FMT_BASE64,
387 p, &size);
389 if (ret < 0)
391 fprintf (stderr, "Encoding error: %s\n",
392 gnutls_strerror (ret));
393 return;
396 fputs (p, stdout);
397 fputs ("\n", stdout);
399 gnutls_free (p);
402 gnutls_openpgp_crt_deinit (crt);
406 #endif
408 /* returns false (0) if not verified, or true (1) otherwise
411 cert_verify (gnutls_session_t session, const char* hostname)
413 int rc;
414 unsigned int status = 0;
415 int type;
417 rc = gnutls_certificate_verify_peers2 (session, &status);
418 if (rc == GNUTLS_E_NO_CERTIFICATE_FOUND)
420 printf ("- Peer did not send any certificate.\n");
421 return 0;
424 if (rc < 0)
426 printf ("- Could not verify certificate (err: %s)\n",
427 gnutls_strerror (rc));
428 return 0;
431 type = gnutls_certificate_type_get (session);
432 if (type == GNUTLS_CRT_X509)
435 if (status & GNUTLS_CERT_REVOKED)
436 printf ("- Peer's certificate chain revoked\n");
437 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
438 printf ("- Peer's certificate issuer is unknown\n");
439 if (status & GNUTLS_CERT_SIGNER_NOT_CA)
440 printf ("- Peer's certificate issuer is not a CA\n");
441 if (status & GNUTLS_CERT_INSECURE_ALGORITHM)
442 printf
443 ("- Peer's certificate chain uses insecure algorithm\n");
444 if (status & GNUTLS_CERT_NOT_ACTIVATED)
445 printf
446 ("- Peer's certificate chain uses not yet valid certificate\n");
447 if (status & GNUTLS_CERT_EXPIRED)
448 printf
449 ("- Peer's certificate chain uses expired certificate\n");
450 if (status & GNUTLS_CERT_INVALID)
451 printf ("- Peer's certificate is NOT trusted\n");
452 else
453 printf ("- Peer's certificate is trusted\n");
455 rc = verify_x509_hostname (session, hostname);
456 if (rc == 0) status |= GNUTLS_CERT_INVALID;
458 else if (type == GNUTLS_CRT_OPENPGP)
460 if (status & GNUTLS_CERT_INVALID)
461 printf ("- Peer's key is invalid\n");
462 else
463 printf ("- Peer's key is valid\n");
464 if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
465 printf ("- Could not find a signer of the peer's key\n");
467 rc = verify_openpgp_hostname (session, hostname);
468 if (rc == 0) status |= GNUTLS_CERT_INVALID;
470 else
472 fprintf(stderr, "Unknown certificate type\n");
473 status |= GNUTLS_CERT_INVALID;
476 if (status)
477 return 0;
479 return 1;
482 static void
483 print_dh_info (gnutls_session_t session, const char *str, int print)
485 printf ("- %sDiffie-Hellman parameters\n", str);
486 printf (" - Using prime: %d bits\n",
487 gnutls_dh_get_prime_bits (session));
488 printf (" - Secret key: %d bits\n",
489 gnutls_dh_get_secret_bits (session));
490 printf (" - Peer's public key: %d bits\n",
491 gnutls_dh_get_peers_public_bits (session));
493 if (print)
495 int ret;
496 gnutls_datum_t raw_gen = { NULL, 0 };
497 gnutls_datum_t raw_prime = { NULL, 0 };
498 gnutls_dh_params_t dh_params = NULL;
499 unsigned char *params_data = NULL;
500 size_t params_data_size = 0;
502 ret = gnutls_dh_get_group (session, &raw_gen, &raw_prime);
503 if (ret)
505 fprintf (stderr, "gnutls_dh_get_group %d\n", ret);
506 goto out;
509 ret = gnutls_dh_params_init (&dh_params);
510 if (ret)
512 fprintf (stderr, "gnutls_dh_params_init %d\n", ret);
513 goto out;
516 ret =
517 gnutls_dh_params_import_raw (dh_params, &raw_prime,
518 &raw_gen);
519 if (ret)
521 fprintf (stderr, "gnutls_dh_params_import_raw %d\n", ret);
522 goto out;
525 ret = gnutls_dh_params_export_pkcs3 (dh_params,
526 GNUTLS_X509_FMT_PEM,
527 params_data,
528 &params_data_size);
529 if (ret != GNUTLS_E_SHORT_MEMORY_BUFFER)
531 fprintf (stderr, "gnutls_dh_params_export_pkcs3 %d\n",
532 ret);
533 goto out;
536 params_data = gnutls_malloc (params_data_size);
537 if (!params_data)
539 fprintf (stderr, "gnutls_malloc %d\n", ret);
540 goto out;
543 ret = gnutls_dh_params_export_pkcs3 (dh_params,
544 GNUTLS_X509_FMT_PEM,
545 params_data,
546 &params_data_size);
547 if (ret)
549 fprintf (stderr, "gnutls_dh_params_export_pkcs3-2 %d\n",
550 ret);
551 goto out;
554 printf (" - PKCS#3 format:\n\n%.*s\n", (int) params_data_size,
555 params_data);
557 out:
558 gnutls_free (params_data);
559 gnutls_free (raw_prime.data);
560 gnutls_free (raw_gen.data);
561 gnutls_dh_params_deinit (dh_params);
565 static void
566 print_ecdh_info (gnutls_session_t session, const char *str)
568 int curve;
570 printf ("- %sEC Diffie-Hellman parameters\n", str);
572 curve = gnutls_ecc_curve_get (session);
574 printf (" - Using curve: %s\n", gnutls_ecc_curve_get_name (curve));
575 printf (" - Curve size: %d bits\n",
576 gnutls_ecc_curve_get_size (curve) * 8);
581 print_info (gnutls_session_t session, int print_cert)
583 const char *tmp;
584 gnutls_credentials_type_t cred;
585 gnutls_kx_algorithm_t kx;
586 unsigned char session_id[33];
587 size_t session_id_size = sizeof (session_id);
589 /* print session ID */
590 gnutls_session_get_id (session, session_id, &session_id_size);
591 printf ("- Session ID: %s\n",
592 raw_to_string (session_id, session_id_size));
594 /* print the key exchange's algorithm name
596 kx = gnutls_kx_get (session);
598 cred = gnutls_auth_get_type (session);
599 switch (cred)
601 #ifdef ENABLE_ANON
602 case GNUTLS_CRD_ANON:
603 if (kx == GNUTLS_KX_ANON_ECDH)
604 print_ecdh_info (session, "Anonymous ");
605 else
606 print_dh_info (session, "Anonymous ", verbose);
607 break;
608 #endif
609 #ifdef ENABLE_SRP
610 case GNUTLS_CRD_SRP:
611 /* This should be only called in server
612 * side.
614 if (gnutls_srp_server_get_username (session) != NULL)
615 printf ("- SRP authentication. Connected as '%s'\n",
616 gnutls_srp_server_get_username (session));
617 break;
618 #endif
619 #ifdef ENABLE_PSK
620 case GNUTLS_CRD_PSK:
621 /* This returns NULL in server side.
623 if (gnutls_psk_client_get_hint (session) != NULL)
624 printf ("- PSK authentication. PSK hint '%s'\n",
625 gnutls_psk_client_get_hint (session));
626 /* This returns NULL in client side.
628 if (gnutls_psk_server_get_username (session) != NULL)
629 printf ("- PSK authentication. Connected as '%s'\n",
630 gnutls_psk_server_get_username (session));
631 if (kx == GNUTLS_KX_DHE_PSK)
632 print_dh_info (session, "Ephemeral ", verbose);
633 if (kx == GNUTLS_KX_ECDHE_PSK)
634 print_ecdh_info (session, "Ephemeral ");
635 break;
636 #endif
637 case GNUTLS_CRD_IA:
638 printf ("- TLS/IA authentication\n");
639 break;
640 case GNUTLS_CRD_CERTIFICATE:
642 char dns[256];
643 size_t dns_size = sizeof (dns);
644 unsigned int type;
646 /* This fails in client side */
647 if (gnutls_server_name_get
648 (session, dns, &dns_size, &type, 0) == 0)
650 printf ("- Given server name[%d]: %s\n", type, dns);
654 print_cert_info (session,
655 verbose?GNUTLS_CRT_PRINT_FULL:GNUTLS_CRT_PRINT_COMPACT,
656 print_cert);
658 if (kx == GNUTLS_KX_DHE_RSA || kx == GNUTLS_KX_DHE_DSS)
659 print_dh_info (session, "Ephemeral ", verbose);
660 else if (kx == GNUTLS_KX_ECDHE_RSA
661 || kx == GNUTLS_KX_ECDHE_ECDSA)
662 print_ecdh_info (session, "Ephemeral ");
665 tmp =
666 SU (gnutls_protocol_get_name
667 (gnutls_protocol_get_version (session)));
668 printf ("- Version: %s\n", tmp);
670 tmp = SU (gnutls_kx_get_name (kx));
671 printf ("- Key Exchange: %s\n", tmp);
673 tmp = SU (gnutls_cipher_get_name (gnutls_cipher_get (session)));
674 printf ("- Cipher: %s\n", tmp);
676 tmp = SU (gnutls_mac_get_name (gnutls_mac_get (session)));
677 printf ("- MAC: %s\n", tmp);
679 tmp =
680 SU (gnutls_compression_get_name
681 (gnutls_compression_get (session)));
682 printf ("- Compression: %s\n", tmp);
684 if (verbose)
686 gnutls_datum_t cb;
687 int rc;
689 rc = gnutls_session_channel_binding (session,
690 GNUTLS_CB_TLS_UNIQUE, &cb);
691 if (rc)
692 fprintf (stderr, "Channel binding error: %s\n",
693 gnutls_strerror (rc));
694 else
696 size_t i;
698 printf ("- Channel binding 'tls-unique': ");
699 for (i = 0; i < cb.size; i++)
700 printf ("%02x", cb.data[i]);
701 printf ("\n");
705 /* Warning: Do not print anything more here. The 'Compression:'
706 output MUST be the last non-verbose output. This is used by
707 Emacs starttls.el code. */
709 fflush (stdout);
711 return 0;
714 void
715 print_cert_info (gnutls_session_t session, int flag, int print_cert)
718 if (gnutls_certificate_client_get_request_status (session) != 0)
719 printf ("- Server has requested a certificate.\n");
721 switch (gnutls_certificate_type_get (session))
723 case GNUTLS_CRT_X509:
724 print_x509_info (session, flag, print_cert);
725 break;
726 #ifdef ENABLE_OPENPGP
727 case GNUTLS_CRT_OPENPGP:
728 print_openpgp_info (session, flag, print_cert);
729 break;
730 #endif
731 default:
732 printf ("Unknown type\n");
733 break;
737 void
738 print_cert_info_compact (gnutls_session_t session)
741 if (gnutls_certificate_client_get_request_status (session) != 0)
742 printf ("- Server has requested a certificate.\n");
744 switch (gnutls_certificate_type_get (session))
746 case GNUTLS_CRT_X509:
747 print_x509_info_compact (session);
748 break;
749 #ifdef ENABLE_OPENPGP
750 case GNUTLS_CRT_OPENPGP:
751 print_openpgp_info_compact (session);
752 break;
753 #endif
754 default:
755 printf ("Unknown type\n");
756 break;
760 void
761 print_list (const char *priorities, int verbose)
763 size_t i;
764 int ret;
765 unsigned int idx;
766 const char *name;
767 const char *err;
768 unsigned char id[2];
769 gnutls_kx_algorithm_t kx;
770 gnutls_cipher_algorithm_t cipher;
771 gnutls_mac_algorithm_t mac;
772 gnutls_protocol_t version;
773 gnutls_priority_t pcache;
774 const unsigned int *list;
776 if (priorities != NULL)
778 printf ("Cipher suites for %s\n", priorities);
780 ret = gnutls_priority_init (&pcache, priorities, &err);
781 if (ret < 0)
783 fprintf (stderr, "Syntax error at: %s\n", err);
784 exit (1);
787 for (i = 0;; i++)
789 ret =
790 gnutls_priority_get_cipher_suite_index (pcache, i,
791 &idx);
792 if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
793 break;
794 if (ret == GNUTLS_E_UNKNOWN_CIPHER_SUITE)
795 continue;
797 name =
798 gnutls_cipher_suite_info (idx, id, NULL, NULL, NULL,
799 &version);
801 if (name != NULL)
802 printf ("%-50s\t0x%02x, 0x%02x\t%s\n",
803 name, (unsigned char) id[0],
804 (unsigned char) id[1],
805 gnutls_protocol_get_name (version));
808 printf("\n");
810 ret = gnutls_priority_certificate_type_list (pcache, &list);
812 printf ("Certificate types: ");
813 if (ret == 0) printf("none\n");
814 for (i = 0; i < (unsigned)ret; i++)
816 printf ("CTYPE-%s",
817 gnutls_certificate_type_get_name (list[i]));
818 if (i+1!=(unsigned)ret)
819 printf (", ");
820 else
821 printf ("\n");
826 ret = gnutls_priority_protocol_list (pcache, &list);
828 printf ("Protocols: ");
829 if (ret == 0) printf("none\n");
830 for (i = 0; i < (unsigned)ret; i++)
832 printf ("VERS-%s", gnutls_protocol_get_name (list[i]));
833 if (i+1!=(unsigned)ret)
834 printf (", ");
835 else
836 printf ("\n");
841 ret = gnutls_priority_compression_list (pcache, &list);
843 printf ("Compression: ");
844 if (ret == 0) printf("none\n");
845 for (i = 0; i < (unsigned)ret; i++)
847 printf ("COMP-%s",
848 gnutls_compression_get_name (list[i]));
849 if (i+1!=(unsigned)ret)
850 printf (", ");
851 else
852 printf ("\n");
857 ret = gnutls_priority_ecc_curve_list (pcache, &list);
859 printf ("Elliptic curves: ");
860 if (ret == 0) printf("none\n");
861 for (i = 0; i < (unsigned)ret; i++)
863 printf ("CURVE-%s",
864 gnutls_ecc_curve_get_name (list[i]));
865 if (i+1!=(unsigned)ret)
866 printf (", ");
867 else
868 printf ("\n");
873 ret = gnutls_priority_sign_list (pcache, &list);
875 printf ("PK-signatures: ");
876 if (ret == 0) printf("none\n");
877 for (i = 0; i < (unsigned)ret; i++)
879 printf ("SIGN-%s",
880 gnutls_sign_algorithm_get_name (list[i]));
881 if (i+1!=(unsigned)ret)
882 printf (", ");
883 else
884 printf ("\n");
888 return;
891 printf ("Cipher suites:\n");
892 for (i = 0; (name = gnutls_cipher_suite_info
893 (i, id, &kx, &cipher, &mac, &version)); i++)
895 printf ("%-50s\t0x%02x, 0x%02x\t%s\n",
896 name,
897 (unsigned char) id[0], (unsigned char) id[1],
898 gnutls_protocol_get_name (version));
899 if (verbose)
900 printf ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n",
901 gnutls_kx_get_name (kx),
902 gnutls_cipher_get_name (cipher),
903 gnutls_mac_get_name (mac));
906 printf("\n");
908 const gnutls_certificate_type_t *p =
909 gnutls_certificate_type_list ();
911 printf ("Certificate types: ");
912 for (; *p; p++)
914 printf ("CTYPE-%s", gnutls_certificate_type_get_name (*p));
915 if (*(p + 1))
916 printf (", ");
917 else
918 printf ("\n");
923 const gnutls_protocol_t *p = gnutls_protocol_list ();
925 printf ("Protocols: ");
926 for (; *p; p++)
928 printf ("VERS-%s", gnutls_protocol_get_name (*p));
929 if (*(p + 1))
930 printf (", ");
931 else
932 printf ("\n");
937 const gnutls_cipher_algorithm_t *p = gnutls_cipher_list ();
939 printf ("Ciphers: ");
940 for (; *p; p++)
942 printf ("%s", gnutls_cipher_get_name (*p));
943 if (*(p + 1))
944 printf (", ");
945 else
946 printf ("\n");
951 const gnutls_mac_algorithm_t *p = gnutls_mac_list ();
953 printf ("MACs: ");
954 for (; *p; p++)
956 printf ("%s", gnutls_mac_get_name (*p));
957 if (*(p + 1))
958 printf (", ");
959 else
960 printf ("\n");
965 const gnutls_kx_algorithm_t *p = gnutls_kx_list ();
967 printf ("Key exchange algorithms: ");
968 for (; *p; p++)
970 printf ("%s", gnutls_kx_get_name (*p));
971 if (*(p + 1))
972 printf (", ");
973 else
974 printf ("\n");
979 const gnutls_compression_method_t *p = gnutls_compression_list ();
981 printf ("Compression: ");
982 for (; *p; p++)
984 printf ("COMP-%s", gnutls_compression_get_name (*p));
985 if (*(p + 1))
986 printf (", ");
987 else
988 printf ("\n");
993 const gnutls_ecc_curve_t *p = gnutls_ecc_curve_list ();
995 printf ("Elliptic curves: ");
996 for (; *p; p++)
998 printf ("CURVE-%s", gnutls_ecc_curve_get_name (*p));
999 if (*(p + 1))
1000 printf (", ");
1001 else
1002 printf ("\n");
1007 const gnutls_pk_algorithm_t *p = gnutls_pk_list ();
1009 printf ("Public Key Systems: ");
1010 for (; *p; p++)
1012 printf ("%s", gnutls_pk_algorithm_get_name (*p));
1013 if (*(p + 1))
1014 printf (", ");
1015 else
1016 printf ("\n");
1021 const gnutls_sign_algorithm_t *p = gnutls_sign_list ();
1023 printf ("PK-signatures: ");
1024 for (; *p; p++)
1026 printf ("SIGN-%s", gnutls_sign_algorithm_get_name (*p));
1027 if (*(p + 1))
1028 printf (", ");
1029 else
1030 printf ("\n");
1035 int check_command(gnutls_session_t session, const char* str)
1037 int len = strlen(str);
1039 if (len > 2 && str[0] == str[1] && str[0] == '*')
1041 if (strncmp(str, "**REHANDSHAKE**",
1042 sizeof ("**REHANDSHAKE**") - 1) == 0)
1044 fprintf (stderr, "*** Sending rehandshake request\n");
1045 gnutls_rehandshake (session);
1046 return 1;
1049 return 0;