gnutls_ecc_curve_t str_to_curve(const char *str) { unsigned num = 0; const gnutls_ecc_curve_t *list, *p; list = gnutls_ecc_curve_list(); p = list; while(*p != 0) { if (strcasecmp(str, gnutls_ecc_curve_get_name(*p)) == 0) return *p; p++; num++; } fprintf(stderr, "Unsupported curve: %s\nAvailable curves:\n", str); if (num == 0) printf("none\n"); p = list; while(*p != 0) { fprintf(stderr, "\t- %s\n", gnutls_ecc_curve_get_name(*p)); p++; } exit(1); }
/* initialize curves caches */ int ecc_wmnaf_cache_init (void) { int j, err; gnutls_ecc_curve_cache_entry_t *ret; const gnutls_ecc_curve_t *p; ret = (gnutls_ecc_curve_cache_entry_t *) malloc (MAX_ALGOS * sizeof (gnutls_ecc_curve_cache_entry_t)); if (ret == NULL) return GNUTLS_E_MEMORY_ERROR; /* get supported curves' ids */ p = gnutls_ecc_curve_list (); for (j = 0; *p; ++p, ++j) { if ((err = _ecc_wmnaf_cache_entry_init (ret + *p - 1, *p)) != 0) goto done; } /* nullify last cache entry id */ ret[j].id = GNUTLS_ECC_CURVE_INVALID; err = GNUTLS_E_SUCCESS; ecc_wmnaf_cache = ret; done: if (err) { int i; for (i = 0; i < j; ++i) { _ecc_wmnaf_cache_entry_free (ret + i); } free (ret); ecc_wmnaf_cache = NULL; } return err; }
void print_list (const char *priorities, int verbose) { size_t i; int ret; unsigned int idx; const char *name; const char *err; unsigned char id[2]; gnutls_kx_algorithm_t kx; gnutls_cipher_algorithm_t cipher; gnutls_mac_algorithm_t mac; gnutls_protocol_t version; gnutls_priority_t pcache; const unsigned int *list; if (priorities != NULL) { printf ("Cipher suites for %s\n", priorities); ret = gnutls_priority_init (&pcache, priorities, &err); if (ret < 0) { fprintf (stderr, "Syntax error at: %s\n", err); exit (1); } for (i = 0;; i++) { ret = gnutls_priority_get_cipher_suite_index (pcache, i, &idx); if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) break; if (ret == GNUTLS_E_UNKNOWN_CIPHER_SUITE) continue; name = gnutls_cipher_suite_info (idx, id, NULL, NULL, NULL, &version); if (name != NULL) printf ("%-50s\t0x%02x, 0x%02x\t%s\n", name, (unsigned char) id[0], (unsigned char) id[1], gnutls_protocol_get_name (version)); } printf("\n"); { ret = gnutls_priority_certificate_type_list (pcache, &list); printf ("Certificate types: "); if (ret == 0) printf("none\n"); for (i = 0; i < (unsigned)ret; i++) { printf ("CTYPE-%s", gnutls_certificate_type_get_name (list[i])); if (i+1!=(unsigned)ret) printf (", "); else printf ("\n"); } } { ret = gnutls_priority_protocol_list (pcache, &list); printf ("Protocols: "); if (ret == 0) printf("none\n"); for (i = 0; i < (unsigned)ret; i++) { printf ("VERS-%s", gnutls_protocol_get_name (list[i])); if (i+1!=(unsigned)ret) printf (", "); else printf ("\n"); } } { ret = gnutls_priority_compression_list (pcache, &list); printf ("Compression: "); if (ret == 0) printf("none\n"); for (i = 0; i < (unsigned)ret; i++) { printf ("COMP-%s", gnutls_compression_get_name (list[i])); if (i+1!=(unsigned)ret) printf (", "); else printf ("\n"); } } { ret = gnutls_priority_ecc_curve_list (pcache, &list); printf ("Elliptic curves: "); if (ret == 0) printf("none\n"); for (i = 0; i < (unsigned)ret; i++) { printf ("CURVE-%s", gnutls_ecc_curve_get_name (list[i])); if (i+1!=(unsigned)ret) printf (", "); else printf ("\n"); } } { ret = gnutls_priority_sign_list (pcache, &list); printf ("PK-signatures: "); if (ret == 0) printf("none\n"); for (i = 0; i < (unsigned)ret; i++) { printf ("SIGN-%s", gnutls_sign_algorithm_get_name (list[i])); if (i+1!=(unsigned)ret) printf (", "); else printf ("\n"); } } return; } printf ("Cipher suites:\n"); for (i = 0; (name = gnutls_cipher_suite_info (i, id, &kx, &cipher, &mac, &version)); i++) { printf ("%-50s\t0x%02x, 0x%02x\t%s\n", name, (unsigned char) id[0], (unsigned char) id[1], gnutls_protocol_get_name (version)); if (verbose) printf ("\tKey exchange: %s\n\tCipher: %s\n\tMAC: %s\n\n", gnutls_kx_get_name (kx), gnutls_cipher_get_name (cipher), gnutls_mac_get_name (mac)); } printf("\n"); { const gnutls_certificate_type_t *p = gnutls_certificate_type_list (); printf ("Certificate types: "); for (; *p; p++) { printf ("CTYPE-%s", gnutls_certificate_type_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_protocol_t *p = gnutls_protocol_list (); printf ("Protocols: "); for (; *p; p++) { printf ("VERS-%s", gnutls_protocol_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_cipher_algorithm_t *p = gnutls_cipher_list (); printf ("Ciphers: "); for (; *p; p++) { printf ("%s", gnutls_cipher_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_mac_algorithm_t *p = gnutls_mac_list (); printf ("MACs: "); for (; *p; p++) { printf ("%s", gnutls_mac_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_kx_algorithm_t *p = gnutls_kx_list (); printf ("Key exchange algorithms: "); for (; *p; p++) { printf ("%s", gnutls_kx_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_compression_method_t *p = gnutls_compression_list (); printf ("Compression: "); for (; *p; p++) { printf ("COMP-%s", gnutls_compression_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_ecc_curve_t *p = gnutls_ecc_curve_list (); printf ("Elliptic curves: "); for (; *p; p++) { printf ("CURVE-%s", gnutls_ecc_curve_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_pk_algorithm_t *p = gnutls_pk_list (); printf ("Public Key Systems: "); for (; *p; p++) { printf ("%s", gnutls_pk_algorithm_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } { const gnutls_sign_algorithm_t *p = gnutls_sign_list (); printf ("PK-signatures: "); for (; *p; p++) { printf ("SIGN-%s", gnutls_sign_algorithm_get_name (*p)); if (*(p + 1)) printf (", "); else printf ("\n"); } } }
static void main_texinfo (void) { { size_t i; const char *name; char id[2]; gnutls_kx_algorithm_t kx; gnutls_cipher_algorithm_t cipher; gnutls_mac_algorithm_t mac; gnutls_protocol_t version; printf ("@heading Ciphersuites\n"); printf ("@multitable @columnfractions .60 .20 .20\n"); printf("@headitem Ciphersuite name @tab TLS ID @tab Since\n"); for (i = 0; (name = gnutls_cipher_suite_info (i, id, &kx, &cipher, &mac, &version)); i++) { printf ("@item %s\n@tab 0x%02X 0x%02X\n@tab %s\n", escape_texi_string(name, buffer, sizeof(buffer)), (unsigned char) id[0], (unsigned char) id[1], gnutls_protocol_get_name (version)); } printf ("@end multitable\n"); } { const gnutls_certificate_type_t *p = gnutls_certificate_type_list (); printf ("\n\n@heading Certificate types\n"); printf ("@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_certificate_type_get_name (*p)); } printf ("@end table\n"); } { const gnutls_protocol_t *p = gnutls_protocol_list (); printf ("\n@heading Protocols\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_protocol_get_name (*p)); } printf ("@end table\n"); } { const gnutls_cipher_algorithm_t *p = gnutls_cipher_list (); printf ("\n@heading Ciphers\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_cipher_get_name (*p)); } printf ("@end table\n"); } { const gnutls_mac_algorithm_t *p = gnutls_mac_list (); printf ("\n@heading MAC algorithms\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_mac_get_name (*p)); } printf ("@end table\n"); } { const gnutls_kx_algorithm_t *p = gnutls_kx_list (); printf ("\n@heading Key exchange methods\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_kx_get_name (*p)); } printf ("@end table\n"); } { const gnutls_pk_algorithm_t *p = gnutls_pk_list (); printf ("\n@heading Public key algorithms\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_pk_get_name (*p)); } printf ("@end table\n"); } { const gnutls_sign_algorithm_t *p = gnutls_sign_list (); printf ("\n@heading Public key signature algorithms\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_sign_get_name (*p)); } printf ("@end table\n"); } { const gnutls_ecc_curve_t *p = gnutls_ecc_curve_list (); printf ("\n@heading Elliptic curves\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_ecc_curve_get_name (*p)); } printf ("@end table\n"); } { const gnutls_compression_method_t *p = gnutls_compression_list (); printf ("\n@heading Compression methods\n@table @code\n"); for (; *p; p++) { printf ("@item %s\n", gnutls_compression_get_name (*p)); } printf ("@end table\n"); } }