2 * Copyright (C) 2004-2012 Free Software Foundation, Inc.
4 * Author: Simon Josefsson
6 * This file is part of GnuTLS.
8 * GnuTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GnuTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
35 # include <netinet/in.h>
36 # include <sys/socket.h>
39 # include <windows.h> /* for Sleep */
43 #include <gnutls/gnutls.h>
44 #include <gnutls/crypto.h>
50 int break_on_error = 0;
53 "-----BEGIN DH PARAMETERS-----\n"
54 "MIGGAoGAtkxw2jlsVCsrfLqxrN+IrF/3W8vVFvDzYbLmxi2GQv9s/PQGWP1d9i22\n"
55 "P2DprfcJknWt7KhCI1SaYseOQIIIAYP78CfyIpGScW/vS8khrw0rlQiyeCvQgF3O\n"
56 "GeGOEywcw+oQT4SmFOD7H0smJe2CNyjYpexBXQ/A0mbTF9QKm1cCAQU=\n"
57 "-----END DH PARAMETERS-----\n";
59 void fail(const char *format, ...)
64 va_start(arg_ptr, format);
65 vsnprintf(str, sizeof(str), format, arg_ptr);
72 void sec_sleep(int sec)
81 ret = nanosleep(&ts, NULL);
82 } while (ret == -1 && errno == EINTR);
88 } while (ret == -1 && errno == EINTR);
92 void success(const char *format, ...)
97 va_start(arg_ptr, format);
98 vsnprintf(str, sizeof(str), format, arg_ptr);
103 void escapeprint(const char *str, size_t len)
107 printf(" (length %d bytes):\n\t", (int) len);
108 for (i = 0; i < len; i++) {
109 if (((str[i] & 0xFF) >= 'A' && (str[i] & 0xFF) <= 'Z') ||
110 ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') ||
111 ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9')
112 || (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.')
113 printf("%c", (str[i] & 0xFF));
115 printf("\\x%02X", (str[i] & 0xFF));
116 if ((i + 1) % 16 == 0 && (i + 1) < len)
122 void hexprint(const void *_str, size_t len)
125 const char *str = _str;
128 for (i = 0; i < len; i++) {
129 printf("%02x ", (str[i] & 0xFF));
130 if ((i + 1) % 8 == 0)
132 if ((i + 1) % 16 == 0 && i + 1 < len)
138 void binprint(const void *_str, size_t len)
141 const char *str = _str;
144 for (i = 0; i < len; i++) {
145 printf("%d%d%d%d%d%d%d%d ",
146 (str[i] & 0xFF) & 0x80 ? 1 : 0,
147 (str[i] & 0xFF) & 0x40 ? 1 : 0,
148 (str[i] & 0xFF) & 0x20 ? 1 : 0,
149 (str[i] & 0xFF) & 0x10 ? 1 : 0,
150 (str[i] & 0xFF) & 0x08 ? 1 : 0,
151 (str[i] & 0xFF) & 0x04 ? 1 : 0,
152 (str[i] & 0xFF) & 0x02 ? 1 : 0,
153 (str[i] & 0xFF) & 0x01 ? 1 : 0);
154 if ((i + 1) % 3 == 0)
156 if ((i + 1) % 6 == 0 && i + 1 < len)
162 int main(int argc, char *argv[])
165 if (strcmp(argv[argc - 1], "-v") == 0 ||
166 strcmp(argv[argc - 1], "--verbose") == 0)
168 else if (strcmp(argv[argc - 1], "-b") == 0 ||
169 strcmp(argv[argc - 1], "--break-on-error") == 0)
171 else if (strcmp(argv[argc - 1], "-h") == 0 ||
172 strcmp(argv[argc - 1], "-?") == 0 ||
173 strcmp(argv[argc - 1], "--help") == 0) {
175 ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n",
183 if (debug || error_count > 0)
184 printf("Self test `%s' finished with %d errors\n", argv[0],
187 return error_count ? 1 : 0;
191 char file[TMPNAME_SIZE];
192 struct tmp_file_st *next;
195 static struct tmp_file_st *temp_files = (void*)-1;
197 static void append(const char *file)
199 struct tmp_file_st *p;
201 if (temp_files == (void*)-1)
204 p = calloc(1, sizeof(*p));
207 strcpy(p->file, file);
208 p->next = temp_files;
212 char *get_tmpname(char s[TMPNAME_SIZE])
214 unsigned char rnd[6];
215 static char _s[TMPNAME_SIZE];
220 ret = gnutls_rnd(GNUTLS_RND_NONCE, rnd, sizeof(rnd));
224 path = getenv("builddir");
233 snprintf(p, TMPNAME_SIZE, "%s/tmpfile-%02x%02x%02x%02x%02x%02x.tmp", path, (unsigned)rnd[0], (unsigned)rnd[1],
234 (unsigned)rnd[2], (unsigned)rnd[3], (unsigned)rnd[4], (unsigned)rnd[5]);
241 void track_temp_files(void)
246 void delete_temp_files(void)
248 struct tmp_file_st *p = temp_files;
249 struct tmp_file_st *next;