Fix in ssltest is no-ssl2 configured
[openssl.git] / ssl / ssltest.c
index c77dc86673b48c12d7b2fd4d102f263d74391034..26ff634ea3c8b2dcb477a6f4cce368a3dff9563b 100644 (file)
@@ -229,6 +229,9 @@ static void sv_usage(void)
        {
        fprintf(stderr,"usage: ssltest [args ...]\n");
        fprintf(stderr,"\n");
+#ifdef OPENSSL_FIPS
+       fprintf(stderr,"-F             - run test in FIPS mode\n");
+#endif
        fprintf(stderr," -server_auth  - check server certificate\n");
        fprintf(stderr," -client_auth  - do client authentication\n");
        fprintf(stderr," -proxy        - allow proxy certificates\n");
@@ -410,7 +413,7 @@ int main(int argc, char *argv[])
        long bytes=256L;
 #ifndef OPENSSL_NO_DH
        DH *dh;
-       int dhe1024 = 0, dhe1024dsa = 0;
+       int dhe1024 = 1, dhe1024dsa = 0;
 #endif
 #ifndef OPENSSL_NO_ECDH
        EC_KEY *ecdh = NULL;
@@ -420,9 +423,14 @@ int main(int argc, char *argv[])
        int print_time = 0;
        clock_t s_time = 0, c_time = 0;
        int comp = 0;
+#ifndef OPENSSL_NO_COMP
        COMP_METHOD *cm = NULL;
+#endif
        STACK_OF(SSL_COMP) *ssl_comp_methods = NULL;
        int test_cipherlist = 0;
+#ifdef OPENSSL_FIPS
+       int fips_mode=0;
+#endif
 
        verbose = 0;
        debug = 0;
@@ -454,7 +462,16 @@ int main(int argc, char *argv[])
 
        while (argc >= 1)
                {
-               if      (strcmp(*argv,"-server_auth") == 0)
+               if(!strcmp(*argv,"-F"))
+                       {
+#ifdef OPENSSL_FIPS
+                       fips_mode=1;
+#else
+                       fprintf(stderr,"not compiled with FIPS support, so exitting without running.\n");
+                       EXIT(0);
+#endif
+                       }
+               else if (strcmp(*argv,"-server_auth") == 0)
                        server_auth=1;
                else if (strcmp(*argv,"-client_auth") == 0)
                        client_auth=1;
@@ -636,6 +653,20 @@ bad:
                EXIT(1);
                }
 
+#ifdef OPENSSL_FIPS
+       if(fips_mode)
+               {
+               if(!FIPS_mode_set(1))
+                       {
+                       ERR_load_crypto_strings();
+                       ERR_print_errors(BIO_new_fp(stderr,BIO_NOCLOSE));
+                       EXIT(1);
+                       }
+               else
+                       fprintf(stderr,"*** IN FIPS MODE ***\n");
+               }
+#endif
+
        if (print_time)
                {
                if (!bio_pair)
@@ -652,6 +683,7 @@ bad:
        SSL_library_init();
        SSL_load_error_strings();
 
+#ifndef OPENSSL_NO_COMP
        if (comp == COMP_ZLIB) cm = COMP_zlib();
        if (comp == COMP_RLE) cm = COMP_rle();
        if (cm != NULL)
@@ -688,6 +720,7 @@ bad:
                        fprintf(stderr, "  %d: %s\n", c->id, c->name);
                        }
        }
+#endif
 
 #if !defined(OPENSSL_NO_SSL2) && !defined(OPENSSL_NO_SSL3)
        if (ssl2)
@@ -702,7 +735,13 @@ bad:
                meth=SSLv23_method();
 #else
 #ifdef OPENSSL_NO_SSL2
-       meth=SSLv3_method();
+       if (tls1)
+               meth=TLSv1_method();
+       else
+       if (ssl3)
+               meth=SSLv3_method();
+       else
+               meth=SSLv23_method();
 #else
        meth=SSLv2_method();
 #endif
@@ -1318,7 +1357,6 @@ int doit(SSL *s_ssl, SSL *c_ssl, long count)
        BIO *c_bio=NULL;
        BIO *s_bio=NULL;
        int c_r,c_w,s_r,s_w;
-       int c_want,s_want;
        int i,j;
        int done=0;
        int c_write,s_write;
@@ -1353,8 +1391,6 @@ int doit(SSL *s_ssl, SSL *c_ssl, long count)
 
        c_r=0; s_r=1;
        c_w=1; s_w=0;
-       c_want=W_WRITE;
-       s_want=0;
        c_write=1,s_write=0;
 
        /* We can always do writes */
@@ -2055,20 +2091,12 @@ static int MS_CALLBACK app_verify_callback(X509_STORE_CTX *ctx, void *arg)
                }
 
 #ifndef OPENSSL_NO_X509_VERIFY
-# ifdef OPENSSL_FIPS
-       if(s->version == TLS1_VERSION)
-               FIPS_allow_md5(1);
-# endif
        ok = X509_verify_cert(ctx);
-# ifdef OPENSSL_FIPS
-       if(s->version == TLS1_VERSION)
-               FIPS_allow_md5(0);
-# endif
 #endif
 
        if (cb_arg->proxy_auth)
                {
-               if (ok)
+               if (ok > 0)
                        {
                        const char *cond_end = NULL;
 
@@ -2230,6 +2258,7 @@ static DH *get_dh1024dsa()
        dh->length = 160;
        return(dh);
        }
+#endif
 
 static int do_test_cipherlist(void)
        {
@@ -2237,6 +2266,7 @@ static int do_test_cipherlist(void)
        const SSL_METHOD *meth;
        SSL_CIPHER *ci, *tci = NULL;
 
+#ifndef OPENSSL_NO_SSL2
        fprintf(stderr, "testing SSLv2 cipher list order: ");
        meth = SSLv2_method();
        while ((ci = meth->get_cipher(i++)) != NULL)
@@ -2250,7 +2280,8 @@ static int do_test_cipherlist(void)
                tci = ci;
                }
        fprintf(stderr, "ok\n");
-
+#endif
+#ifndef OPENSSL_NO_SSL3
        fprintf(stderr, "testing SSLv3 cipher list order: ");
        meth = SSLv3_method();
        tci = NULL;
@@ -2265,7 +2296,8 @@ static int do_test_cipherlist(void)
                tci = ci;
                }
        fprintf(stderr, "ok\n");
-
+#endif
+#ifndef OPENSSL_NO_TLS1
        fprintf(stderr, "testing TLSv1 cipher list order: ");
        meth = TLSv1_method();
        tci = NULL;
@@ -2280,7 +2312,7 @@ static int do_test_cipherlist(void)
                tci = ci;
                }
        fprintf(stderr, "ok\n");
+#endif
 
        return 1;
        }
-#endif