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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
* Copyright (c) 2015 Joel Sing <jsing@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <openssl/ssl.h>
#include <err.h>
#include <stdio.h>
#include <string.h>
static int
get_put_test(const char *name, const SSL_METHOD *method)
{
STACK_OF(SSL_CIPHER) *ciphers;
const SSL_CIPHER *cipher;
unsigned char buf[2];
SSL_CTX *ssl_ctx = NULL;
SSL *ssl = NULL;
int ret = 1;
int i, len;
if ((len = method->put_cipher_by_char(NULL, NULL)) != 2) {
fprintf(stderr,
"%s: put_cipher_by_char() returned len %i (want 2)\n",
name, len);
return (1);
}
if ((ssl_ctx = SSL_CTX_new(method)) == NULL) {
fprintf(stderr, "%s: SSL_CTX_new() returned NULL\n", name);
goto failure;
}
if ((ssl = SSL_new(ssl_ctx)) == NULL) {
fprintf(stderr, "%s: SSL_new() returned NULL\n", name);
goto failure;
}
if ((ciphers = SSL_get_ciphers(ssl)) == NULL) {
fprintf(stderr, "%s: no ciphers\n", name);
goto failure;
}
for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
cipher = sk_SSL_CIPHER_value(ciphers, i);
if ((len = method->put_cipher_by_char(cipher, buf)) != 2) {
fprintf(stderr,
"%s: put_cipher_by_char() returned len %i for %s "
"(want 2)\n",
name, len, SSL_CIPHER_get_name(cipher));
goto failure;
}
if ((cipher = method->get_cipher_by_char(buf)) == NULL) {
fprintf(stderr,
"%s: get_cipher_by_char() returned NULL for %s\n",
name, SSL_CIPHER_get_name(cipher));
goto failure;
}
}
ret = 0;
failure:
SSL_CTX_free(ssl_ctx);
SSL_free(ssl);
return (ret);
}
static int
cipher_get_put_tests(void)
{
int failed = 0;
failed |= get_put_test("SSLv23", SSLv23_method());
failed |= get_put_test("SSLv23_client", SSLv23_client_method());
failed |= get_put_test("SSLv23_server", SSLv23_server_method());
failed |= get_put_test("SSLv3", SSLv3_method());
failed |= get_put_test("SSLv3_client", SSLv3_client_method());
failed |= get_put_test("SSLv3_server", SSLv3_server_method());
failed |= get_put_test("TLSv1", TLSv1_method());
failed |= get_put_test("TLSv1_client", TLSv1_client_method());
failed |= get_put_test("TLSv1_server", TLSv1_server_method());
failed |= get_put_test("TLSv1_1", TLSv1_1_method());
failed |= get_put_test("TLSv1_1_client", TLSv1_1_client_method());
failed |= get_put_test("TLSv1_1_server", TLSv1_1_server_method());
failed |= get_put_test("TLSv1_2", TLSv1_2_method());
failed |= get_put_test("TLSv1_2_client", TLSv1_2_client_method());
failed |= get_put_test("TLSv1_2_server", TLSv1_2_server_method());
failed |= get_put_test("DTLSv1", DTLSv1_method());
failed |= get_put_test("DTLSv1_client", DTLSv1_client_method());
failed |= get_put_test("DTLSv1_server", DTLSv1_server_method());
return failed;
}
int
main(int argc, char **argv)
{
SSL_library_init();
return cipher_get_put_tests();
}
|