if (verbose) fprintf(stdout, " done\n"); }
dh=get_dh1024dsa(); } else if (dhe1024) dh=get_dh1024();
int main(int argc, char *argv[])	{	char *CApath=NULL,*CAfile=NULL;	int badop=0;	int bio_pair=0;	int force=0;	int tls1=0,ssl2=0,ssl3=0,ret=1;	int client_auth=0;	int server_auth=0,i;	char *server_cert=TEST_SERVER_CERT;	char *client_cert=TEST_CLIENT_CERT;	SSL_CTX *s_ctx=NULL;	SSL_CTX *c_ctx=NULL;	SSL_METHOD *meth=NULL;	SSL *c_ssl,*s_ssl;	int number=1,reuse=0;	long bytes=1L;	SSL_CIPHER *ciph;	int dhe1024 = 0, no_dhe = 0;#ifndef NO_DH	DH *dh;#endif	verbose = 0;	debug = 0;	cipher = 0;		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);	argc--;	argv++;	while (argc >= 1)		{		if	(strcmp(*argv,"-server_auth") == 0)			server_auth=1;		else if	(strcmp(*argv,"-client_auth") == 0)			client_auth=1;		else if	(strcmp(*argv,"-v") == 0)			verbose=1;		else if	(strcmp(*argv,"-d") == 0)			debug=1;		else if	(strcmp(*argv,"-reuse") == 0)			reuse=1;		else if	(strcmp(*argv,"-dhe1024") == 0)			dhe1024=1;		else if	(strcmp(*argv,"-no_dhe") == 0)			no_dhe=1;		else if	(strcmp(*argv,"-ssl2") == 0)			ssl2=1;		else if	(strcmp(*argv,"-tls1") == 0)			tls1=1;		else if	(strcmp(*argv,"-ssl3") == 0)			ssl3=1;		else if	(strncmp(*argv,"-num",4) == 0)			{			if (--argc < 1) goto bad;			number= atoi(*(++argv));			if (number == 0) number=1;			}		else if	(strcmp(*argv,"-bytes") == 0)			{			if (--argc < 1) goto bad;			bytes= atol(*(++argv));			if (bytes == 0L) bytes=1L;			i=strlen(argv[0]);			if (argv[0][i-1] == 'k') bytes*=1024L;			if (argv[0][i-1] == 'm') bytes*=1024L*1024L;			}		else if	(strcmp(*argv,"-cert") == 0)			{			if (--argc < 1) goto bad;			server_cert= *(++argv);			}		else if	(strcmp(*argv,"-s_cert") == 0)			{			if (--argc < 1) goto bad;			server_cert= *(++argv);			}		else if	(strcmp(*argv,"-c_cert") == 0)			{			if (--argc < 1) goto bad;			client_cert= *(++argv);			}		else if	(strcmp(*argv,"-cipher") == 0)			{			if (--argc < 1) goto bad;			cipher= *(++argv);			}		else if	(strcmp(*argv,"-CApath") == 0)			{			if (--argc < 1) goto bad;			CApath= *(++argv);			}		else if	(strcmp(*argv,"-CAfile") == 0)			{			if (--argc < 1) goto bad;			CAfile= *(++argv);			}		else if	(strcmp(*argv,"-bio_pair") == 0)			{			bio_pair = 1;			}		else if	(strcmp(*argv,"-f") == 0)			{			force = 1;			}		else			{			fprintf(stderr,"unknown option %s\n",*argv);			badop=1;			break;			}		argc--;		argv++;		}	if (badop)		{bad:		sv_usage();		goto end;		}	if (!ssl2 && !ssl3 && !tls1 && number > 1 && !reuse && !force)		{		fprintf(stderr, "This case cannot work.  Use -f switch to perform "			"the test anyway\n"			"(and -d to see what happens, "			"and -bio_pair to really make it happen :-)\n"			"or add one of -ssl2, -ssl3, -tls1, -reuse to "			"avoid protocol mismatch.\n");		exit(1);		}/*	if (cipher == NULL) cipher=getenv("SSL_CIPHER"); */	SSL_library_init();	SSL_load_error_strings();#if !defined(NO_SSL2) && !defined(NO_SSL3)	if (ssl2)		meth=SSLv2_method();	else 	if (tls1)		meth=TLSv1_method();	else	if (ssl3)		meth=SSLv3_method();	else		meth=SSLv23_method();#else#ifdef NO_SSL2	meth=SSLv3_method();#else	meth=SSLv2_method();#endif#endif	c_ctx=SSL_CTX_new(meth);	s_ctx=SSL_CTX_new(meth);	if ((c_ctx == NULL) || (s_ctx == NULL))		{		ERR_print_errors(bio_err);		goto end;		}	if (cipher != NULL)		{		SSL_CTX_set_cipher_list(c_ctx,cipher);		SSL_CTX_set_cipher_list(s_ctx,cipher);		}#ifndef NO_DH	if (!no_dhe)		{# ifndef NO_DSA		if (dhe1024) 			{			DSA *dsa;			unsigned char seed[20];						if (verbose)				{				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, dsa_cb, bio_err);			dh = DSA_dup_DH(dsa);				DSA_free(dsa);			/* important: SSL_OP_SINGLE_DH_USE to avoid small subgroup attacks */			SSL_CTX_set_options(s_ctx, SSL_OP_SINGLE_DH_USE);						if (verbose)				fprintf(stdout, " done\n");			}		else# endif			dh=get_dh512();		SSL_CTX_set_tmp_dh(s_ctx,dh);		DH_free(dh);		}#endif#ifndef NO_RSA	SSL_CTX_set_tmp_rsa_callback(s_ctx,tmp_rsa_cb);#endif	if (!SSL_CTX_use_certificate_file(s_ctx,server_cert,SSL_FILETYPE_PEM))		{		ERR_print_errors(bio_err);		}	else if (!SSL_CTX_use_PrivateKey_file(s_ctx,server_cert,		SSL_FILETYPE_PEM))		{		ERR_print_errors(bio_err);		goto end;		}	if (client_auth)		{		SSL_CTX_use_certificate_file(c_ctx,client_cert,			SSL_FILETYPE_PEM);		SSL_CTX_use_PrivateKey_file(c_ctx,client_cert,			SSL_FILETYPE_PEM);		}	if (	(!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||		(!SSL_CTX_set_default_verify_paths(s_ctx)) ||		(!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||		(!SSL_CTX_set_default_verify_paths(c_ctx)))		{		/* fprintf(stderr,"SSL_load_verify_locations\n"); */		ERR_print_errors(bio_err);		/* goto end; */		}	if (client_auth)		{		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)		{		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);	for (i=0; i<number; i++)		{		if (!reuse) SSL_set_session(c_ssl,NULL);		if (bio_pair)			ret=doit_biopair(s_ssl,c_ssl,bytes);		else			ret=doit(s_ssl,c_ssl,bytes);		}	if (!verbose)		{		ciph=SSL_get_current_cipher(c_ssl);		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))		BIO_printf(bio_stdout, "%d handshakes of %ld bytes done\n",number,bytes);	SSL_free(s_ssl);	SSL_free(c_ssl);end:	if (s_ctx != NULL) SSL_CTX_free(s_ctx);	if (c_ctx != NULL) SSL_CTX_free(c_ctx);	if (bio_stdout != NULL) BIO_free(bio_stdout);	ERR_free_strings();	ERR_remove_state(0);	EVP_cleanup();	CRYPTO_mem_leaks(bio_err);	if (bio_err != NULL) BIO_free(bio_err);	EXIT(ret);	}