123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- #include <stdlib.h>
- #include <openssl/bio.h>
- #include <openssl/ssl.h>
- #include <openssl/err.h>
- #define TOTAL_NUM_TESTS 2
- #define TEST_SSL_CTX 0
- #define SSLV2ON 1
- #define SSLV2OFF 0
- SSL_CONF_CTX *confctx;
- SSL_CTX *ctx;
- SSL *ssl;
- static int checksslv2(int test, int sslv2)
- {
- int options;
- if (test == TEST_SSL_CTX) {
- options = SSL_CTX_get_options(ctx);
- } else {
- options = SSL_get_options(ssl);
- }
- return ((options & SSL_OP_NO_SSLv2) == 0) ^ (sslv2 == SSLV2OFF);
- }
- int main(int argc, char *argv[])
- {
- BIO *err;
- int testresult = 0;
- int currtest;
- SSL_library_init();
- SSL_load_error_strings();
- err = BIO_new_fp(stderr, BIO_NOCLOSE | BIO_FP_TEXT);
- CRYPTO_malloc_debug_init();
- CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
- CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
- confctx = SSL_CONF_CTX_new();
- ctx = SSL_CTX_new(SSLv23_method());
- ssl = SSL_new(ctx);
- if (confctx == NULL || ctx == NULL)
- goto end;
- SSL_CONF_CTX_set_flags(confctx, SSL_CONF_FLAG_FILE
- | SSL_CONF_FLAG_CLIENT
- | SSL_CONF_FLAG_SERVER);
-
- for (currtest = 0; currtest < TOTAL_NUM_TESTS; currtest++) {
- BIO_printf(err, "SSLv2 CONF Test number %d\n", currtest);
- if (currtest == TEST_SSL_CTX)
- SSL_CONF_CTX_set_ssl_ctx(confctx, ctx);
- else
- SSL_CONF_CTX_set_ssl(confctx, ssl);
-
- if (!checksslv2(currtest, SSLV2OFF)) {
- BIO_printf(err, "SSLv2 CONF Test: Off by default test FAIL\n");
- goto end;
- }
- if (SSL_CONF_cmd(confctx, "Protocol", "ALL") != 2
- || !SSL_CONF_CTX_finish(confctx)) {
- BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
- goto end;
- }
-
- if (!checksslv2(currtest, SSLV2OFF)) {
- BIO_printf(err, "SSLv2 CONF Test: Off after config #1 FAIL\n");
- goto end;
- }
- if (SSL_CONF_cmd(confctx, "Protocol", "SSLv2") != 2
- || !SSL_CONF_CTX_finish(confctx)) {
- BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
- goto end;
- }
-
- if (!checksslv2(currtest, SSLV2OFF)) {
- BIO_printf(err, "SSLv2 CONF Test: Off after config #2 FAIL\n");
- goto end;
- }
- if (SSL_CONF_cmd(confctx, "Protocol", "-SSLv2") != 2
- || !SSL_CONF_CTX_finish(confctx)) {
- BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");;
- goto end;
- }
- if (!checksslv2(currtest, SSLV2OFF)) {
- BIO_printf(err, "SSLv2 CONF Test: Off after config #3 FAIL\n");
- goto end;
- }
- if (currtest == TEST_SSL_CTX)
- SSL_CTX_clear_options(ctx, SSL_OP_NO_SSLv2);
- else
- SSL_clear_options(ssl, SSL_OP_NO_SSLv2);
- if (!checksslv2(currtest, SSLV2ON)) {
- BIO_printf(err, "SSLv2 CONF Test: On after clear FAIL\n");
- goto end;
- }
- if (SSL_CONF_cmd(confctx, "Protocol", "ALL") != 2
- || !SSL_CONF_CTX_finish(confctx)) {
- BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
- goto end;
- }
-
- if (!checksslv2(currtest, SSLV2ON)) {
- BIO_printf(err, "SSLv2 CONF Test: On after config #1 FAIL\n");
- goto end;
- }
- if (SSL_CONF_cmd(confctx, "Protocol", "SSLv2") != 2
- || !SSL_CONF_CTX_finish(confctx)) {
- BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
- goto end;
- }
-
- if (!checksslv2(currtest, SSLV2ON)) {
- BIO_printf(err, "SSLv2 CONF Test: On after config #2 FAIL\n");
- goto end;
- }
- if (SSL_CONF_cmd(confctx, "Protocol", "-SSLv2") != 2
- || !SSL_CONF_CTX_finish(confctx)) {
- BIO_printf(err, "SSLv2 CONF Test: SSL_CONF command FAIL\n");
- goto end;
- }
-
- if (!checksslv2(currtest, SSLV2OFF)) {
- BIO_printf(err, "SSLv2 CONF Test: Off after config #4 FAIL\n");
- goto end;
- }
- }
- testresult = 1;
- end:
- SSL_free(ssl);
- SSL_CTX_free(ctx);
- SSL_CONF_CTX_free(confctx);
- if (!testresult) {
- printf("SSLv2 CONF test: FAILED (Test %d)\n", currtest);
- ERR_print_errors(err);
- } else {
- printf("SSLv2 CONF test: PASSED\n");
- }
- ERR_free_strings();
- ERR_remove_thread_state(NULL);
- EVP_cleanup();
- CRYPTO_cleanup_all_ex_data();
- CRYPTO_mem_leaks(err);
- BIO_free(err);
- return testresult ? EXIT_SUCCESS : EXIT_FAILURE;
- }
|