tests: updated the suite to account for the removal of DSA by default
[gnutls:gnutls.git] / tests / priorities.c
1 /*
2  * Copyright (C) 2012 Free Software Foundation, Inc.
3  * Copyright (C) 2012-2015 Nikos Mavrogiannopoulos
4  *
5  * Author: Nikos Mavrogiannopoulos
6  *
7  * This file is part of GnuTLS.
8  *
9  * GnuTLS is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * GnuTLS is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with GnuTLS; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <gnutls/gnutls.h>
32
33 #include "utils.h"
34
35 #ifdef ENABLE_FIPS140
36 void doit(void)
37 {
38         exit(77);
39 }
40
41 #else
42
43 static void
44 try_prio(const char *prio, unsigned expected_cs, unsigned expected_ciphers, unsigned line)
45 {
46         int ret;
47         gnutls_priority_t p;
48         const char *err;
49         const unsigned int *t;
50         unsigned i, si, count = 0;
51
52         /* this must be called once in the program
53          */
54         global_init();
55
56         ret = gnutls_priority_init(&p, prio, &err);
57         if (ret < 0) {
58                 fprintf(stderr, "error: %s: %s\n", gnutls_strerror(ret),
59                         err);
60                 exit(1);
61         }
62
63         for (i = 0;; i++) {
64                 ret = gnutls_priority_get_cipher_suite_index(p, i, &si);
65                 if (ret == GNUTLS_E_UNKNOWN_CIPHER_SUITE)
66                         continue;
67                 else if (ret == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE)
68                         break;
69                 else if (ret == 0) {
70                         count++;
71                         /* fprintf(stderr, "%s\n", gnutls_cipher_suite_info(si, NULL, NULL, NULL, NULL, NULL)); */
72                 }
73
74         }
75
76         ret = gnutls_priority_cipher_list(p, &t);
77         if ((unsigned) ret != expected_ciphers) {
78 #if 0
79                 for (i = 0; i < ret; i++)
80                         fprintf(stderr, "%s\n",
81                                 gnutls_cipher_get_name(t[i]));
82 #endif
83                 fail("%s:%d: expected %d ciphers, found %d\n", prio, line, expected_ciphers,
84                      ret);
85                 exit(1);
86         }
87
88         gnutls_priority_deinit(p);
89
90         /* fprintf(stderr, "count: %d\n", count); */
91
92         if (debug)
93                 success("finished: %s\n", prio);
94
95         if (count != expected_cs) {
96                 fail("%s:%d: expected %d ciphersuites, found %d\n", prio, line, expected_cs,
97                      count);
98                 exit(1);
99         }
100 }
101
102 void doit(void)
103 {
104         const int normal = 54;
105         const int null = 5;
106         const int sec128 = 50;
107
108         try_prio("NORMAL", normal, 11, __LINE__);
109         try_prio("NORMAL:-MAC-ALL:+MD5:+MAC-ALL", normal, 11, __LINE__);
110         try_prio("NORMAL:+CIPHER-ALL", normal, 11, __LINE__);   /* all (except null) */
111         try_prio("NORMAL:-CIPHER-ALL:+NULL", null, 1, __LINE__);        /* null */
112         try_prio("NORMAL:-CIPHER-ALL:+NULL:+CIPHER-ALL", normal + null, 12, __LINE__);  /* should be null + all */
113         try_prio("NORMAL:-CIPHER-ALL:+NULL:+CIPHER-ALL:-CIPHER-ALL:+AES-128-CBC", 8, 1, __LINE__);      /* should be null + all */
114         try_prio("PERFORMANCE", normal, 11, __LINE__);
115         try_prio("SECURE256", 19, 5, __LINE__);
116         try_prio("SECURE128", sec128, 10, __LINE__);
117         try_prio("SECURE128:+SECURE256", sec128, 10, __LINE__); /* should be the same as SECURE128 */
118         try_prio("SECURE128:+SECURE256:+NORMAL", normal, 11, __LINE__); /* should be the same as NORMAL */
119         try_prio("SUITEB192", 1, 1, __LINE__);
120 }
121
122 #endif