Report progress as in dsatest.c when creating a DHE key.
[openssl.git] / ssl / ssltest.c
index 7d3c31dfaef618e9de0472b4c2a4177f614165ff..d655bbbd841cbfa0f6ee941ecac2492c4a583385 100644 (file)
 #include <openssl/x509.h>
 #include <openssl/ssl.h>
 #include <openssl/err.h>
+#include <openssl/rand.h>
 #ifdef WINDOWS
 #include "../crypto/bio/bss_file.c"
 #endif
 
-#if defined(NO_RSA) && !defined(NO_SSL2)
-#define NO_SSL2
-#endif
-
 #ifdef VMS
 #  define TEST_SERVER_CERT "SYS$DISK:[-.APPS]SERVER.PEM"
 #  define TEST_CLIENT_CERT "SYS$DISK:[-.APPS]CLIENT.PEM"
@@ -93,6 +90,10 @@ static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export,int keylength);
 #ifndef NO_DH
 static DH *get_dh512(void);
 #endif
+#ifndef NO_DSA
+static void MS_CALLBACK dsa_cb(int p, int n, void *arg);
+#endif
+
 static BIO *bio_err=NULL;
 static BIO *bio_stdout=NULL;
 
@@ -106,6 +107,7 @@ static int s_nbio=0;
 #endif
 #endif
 
+static const char rnd_seed[] = "string to make the random number generator think it has entropy";
 
 int doit_biopair(SSL *s_ssl,SSL *c_ssl,long bytes);
 int doit(SSL *s_ssl,SSL *c_ssl,long bytes);
@@ -173,6 +175,8 @@ int main(int argc, char *argv[])
        
        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
 
+       RAND_seed(rnd_seed, sizeof rnd_seed);
+
        bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
        bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
 
@@ -330,12 +334,12 @@ bad:
                        
                        if (verbose)
                                {
-                               fprintf(stdout, "Creating 1024 bit DHE parameters ...");
-                               fflush(stdout);
+                               BIO_printf(bio_err, "Creating 1024 bit DHE parameters\n");
+                               BIO_flush(bio_err);
                                }
                        
                        memcpy(seed, "Random String no. 12", 20);
-                       dsa = DSA_generate_parameters(1024, seed, 20, NULL, NULL, 0, NULL);
+                       dsa = DSA_generate_parameters(1024, seed, 20, NULL, NULL, dsa_cb, bio_err);
                        dh = DSA_dup_DH(dsa);   
                        DSA_free(dsa);
                        /* important: SSL_OP_SINGLE_DH_USE to avoid small subgroup attacks */
@@ -387,17 +391,22 @@ bad:
 
        if (client_auth)
                {
-               fprintf(stderr,"client authentication\n");
+               BIO_printf(bio_err,"client authentication\n");
                SSL_CTX_set_verify(s_ctx,
                        SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
                        verify_callback);
                }
        if (server_auth)
                {
-               fprintf(stderr,"server authentication\n");
+               BIO_printf(bio_err,"server authentication\n");
                SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
                        verify_callback);
                }
+       
+       {
+               int session_id_context = 0;
+               SSL_CTX_set_session_id_context(s_ctx, (void *)&session_id_context, sizeof session_id_context);
+       }
 
        c_ssl=SSL_new(c_ctx);
        s_ssl=SSL_new(s_ctx);
@@ -414,13 +423,13 @@ bad:
        if (!verbose)
                {
                ciph=SSL_get_current_cipher(c_ssl);
-               fprintf(stdout,"Protocol %s, cipher %s, %s\n",
+               BIO_printf(bio_stdout,"Protocol %s, cipher %s, %s\n",
                        SSL_get_version(c_ssl),
                        SSL_CIPHER_get_version(ciph),
                        SSL_CIPHER_get_name(ciph));
                }
        if ((number > 1) || (bytes > 1L))
-               printf("%d handshakes of %ld bytes done\n",number,bytes);
+               BIO_printf(bio_stdout, "%d handshakes of %ld bytes done\n",number,bytes);
 
        SSL_free(s_ssl);
        SSL_free(c_ssl);
@@ -500,7 +509,7 @@ int doit_biopair(SSL *s_ssl, SSL *c_ssl, long count)
                 * BIO_ctrl_pending(bio)              number of bytes we can read now
                 * BIO_ctrl_get_read_request(bio)     number of bytes needed to fulfil
                 *                                      other side's read attempt
-                * BIO_ctrl_get_write_gurantee(bio)   number of bytes we can write now
+                * BIO_ctrl_get_write_guarantee(bio)   number of bytes we can write now
                 *
                 * ..._read_request is never more than ..._write_guarantee;
                 * it depends on the application which one you should use.
@@ -1181,3 +1190,24 @@ static RSA MS_CALLBACK *tmp_rsa_cb(SSL *s, int is_export, int keylength)
        return(rsa_tmp);
        }
 #endif
+
+#ifndef NO_DSA
+static void MS_CALLBACK dsa_cb(int p, int n, void *arg)
+       {
+       char c='*';
+       static int ok=0,num=0;
+
+       if (p == 0) { c='.'; num++; };
+       if (p == 1) c='+';
+       if (p == 2) { c='*'; ok++; }
+       if (p == 3) c='\n';
+       BIO_write(arg,&c,1);
+       (void)BIO_flush(arg);
+
+       if (!ok && (p == 0) && (num > 1))
+               {
+               BIO_printf((BIO *)arg,"error in dsatest\n");
+               exit(1);
+               }
+       }
+#endif