1 /* Written by Matt Caswell for the OpenSSL Project */
2 /* ====================================================================
3 * Copyright (c) 2016 The OpenSSL Project. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
31 * 6. Redistributions of any form whatsoever must retain the following
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
57 #include <openssl/bio.h>
58 #include <openssl/ssl.h>
59 #include <openssl/err.h>
62 #define TOTAL_NUM_TESTS 2
63 #define TEST_SSL_CTX 0
68 SSL_CONF_CTX *confctx;
72 static int checksslv2(int test, int sslv2)
75 if (test == TEST_SSL_CTX) {
76 options = SSL_CTX_get_options(ctx);
78 options = SSL_get_options(ssl);
80 return ((options & SSL_OP_NO_SSLv2) == 0) ^ (sslv2 == SSLV2OFF);
83 int main(int argc, char *argv[])
90 SSL_load_error_strings();
92 err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
94 CRYPTO_malloc_debug_init();
95 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
96 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
99 confctx = SSL_CONF_CTX_new();
100 ctx = SSL_CTX_new(SSLv23_method());
102 if (confctx == NULL || ctx == NULL)
105 SSL_CONF_CTX_set_flags(confctx, SSL_CONF_FLAG_FILE
106 | SSL_CONF_FLAG_CLIENT
107 | SSL_CONF_FLAG_SERVER);
110 * For each test set up an SSL_CTX and SSL and see whether SSLv2 is enabled
111 * as expected after various SSL_CONF_cmd("Protocol", ...) calls.
113 for (currtest = 0; currtest < TOTAL_NUM_TESTS; currtest++) {
114 BIO_printf(err, "SSLv2 CONF Test number %d\n", currtest);
115 if (currtest == TEST_SSL_CTX)
116 SSL_CONF_CTX_set_ssl_ctx(confctx, ctx);
118 SSL_CONF_CTX_set_ssl(confctx, ssl);
120 /* SSLv2 should be off by default */
121 if (!checksslv2(currtest, SSLV2OFF)) {
122 BIO_printf(err, "SSLv2 CONF Test: Off by default test FAIL\n");
126 if (SSL_CONF_cmd(confctx, "Protocol", "ALL") != 2
127 || !SSL_CONF_CTX_finish(confctx)) {
128 BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
132 /* Should still be off even after ALL Protocols on */
133 if (!checksslv2(currtest, SSLV2OFF)) {
134 BIO_printf(err, "SSLv2 CONF Test: Off after config #1 FAIL\n");
138 if (SSL_CONF_cmd(confctx, "Protocol", "SSLv2") != 2
139 || !SSL_CONF_CTX_finish(confctx)) {
140 BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
144 /* Should still be off even if explicitly asked for */
145 if (!checksslv2(currtest, SSLV2OFF)) {
146 BIO_printf(err, "SSLv2 CONF Test: Off after config #2 FAIL\n");
150 if (SSL_CONF_cmd(confctx, "Protocol", "-SSLv2") != 2
151 || !SSL_CONF_CTX_finish(confctx)) {
152 BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");;
156 if (!checksslv2(currtest, SSLV2OFF)) {
157 BIO_printf(err, "SSLv2 CONF Test: Off after config #3 FAIL\n");
161 if (currtest == TEST_SSL_CTX)
162 SSL_CTX_clear_options(ctx, SSL_OP_NO_SSLv2);
164 SSL_clear_options(ssl, SSL_OP_NO_SSLv2);
166 if (!checksslv2(currtest, SSLV2ON)) {
167 BIO_printf(err, "SSLv2 CONF Test: On after clear FAIL\n");
171 if (SSL_CONF_cmd(confctx, "Protocol", "ALL") != 2
172 || !SSL_CONF_CTX_finish(confctx)) {
173 BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
177 /* Option has been cleared and config says have SSLv2 so should be on */
178 if (!checksslv2(currtest, SSLV2ON)) {
179 BIO_printf(err, "SSLv2 CONF Test: On after config #1 FAIL\n");
183 if (SSL_CONF_cmd(confctx, "Protocol", "SSLv2") != 2
184 || !SSL_CONF_CTX_finish(confctx)) {
185 BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
189 /* Option has been cleared and config says have SSLv2 so should be on */
190 if (!checksslv2(currtest, SSLV2ON)) {
191 BIO_printf(err, "SSLv2 CONF Test: On after config #2 FAIL\n");
195 if (SSL_CONF_cmd(confctx, "Protocol", "-SSLv2") != 2
196 || !SSL_CONF_CTX_finish(confctx)) {
197 BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
201 /* Option has been cleared but config says no SSLv2 so should be off */
202 if (!checksslv2(currtest, SSLV2OFF)) {
203 BIO_printf(err, "SSLv2 CONF Test: Off after config #4 FAIL\n");
214 SSL_CONF_CTX_free(confctx);
217 printf("SSLv2 CONF test: FAILED (Test %d)\n", currtest);
218 ERR_print_errors(err);
220 printf("SSLv2 CONF test: PASSED\n");
224 ERR_remove_thread_state(NULL);
226 CRYPTO_cleanup_all_ex_data();
227 CRYPTO_mem_leaks(err);
230 return testresult ? EXIT_SUCCESS : EXIT_FAILURE;