apps/s_client.c:1451: error: INTEGER_OVERFLOW_L1
  (0 - 1):unsigned64 by call to `SSL_new`.
Showing all 24 steps of the trace


apps/s_client.c:1437:3: Call
1435.   		SSL_CTX_set_srp_cb_arg(ctx,&srp_arg);
1436.   		SSL_CTX_set_srp_client_pwd_callback(ctx, ssl_give_srp_client_pwd_cb);
1437.   		SSL_CTX_set_srp_strength(ctx, srp_arg.strength);
          ^
1438.   		if (c_msg || c_debug || srp_arg.amp == 0)
1439.   			SSL_CTX_set_srp_verify_param_callback(ctx, ssl_srp_verify_param_cb);

ssl/tls_srp.c:482:9: Call
  480.   int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength)
  481.   	{
  482.   	return tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH, strength,
                 ^
  483.   			     NULL);
  484.   	}

ssl/s3_lib.c:3751:12: Call
    3749.   			return 0;
    3750.   			}
    3751.   		if ((new=DHparams_dup(dh)) == NULL)
                       ^
    3752.   			{
    3753.   			SSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);

crypto/dh/dh_ameth.c:523:8: Call
      521.   	{
      522.   	DH *ret;
      523.   	ret = DH_new();
                    ^
      524.   	if (!ret)
      525.   		return NULL;

crypto/dh/dh_lib.c:104:9: Call
        102.   DH *DH_new(void)
        103.   	{
        104.   	return DH_new_method(NULL);
                       ^
        105.   	}
        106.   

crypto/dh/dh_lib.c:131:17: Call
          129.   		}
          130.   	else
          131.   		ret->engine = ENGINE_get_default_DH();
                                 ^
          132.   	if(ret->engine)
          133.   		{

crypto/engine/tb_dh.c:104:9: Call
            102.   ENGINE *ENGINE_get_default_DH(void)
            103.   	{
            104.   	return engine_table_select(&dh_table, dummy_nid);
                           ^
            105.   	}
            106.   

crypto/engine/eng_table.c:261:6: Call
              259.   	/* Check again inside the lock otherwise we could race against cleanup
              260.   	 * operations. But don't worry about a fprintf(stderr). */
              261.   	if(!int_table_check(table, 0)) goto end;
                          ^
              262.   	tmplate.nid = nid;
              263.   	fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);

crypto/engine/eng_table.c:122:11: Call
                120.   	if(*t) return 1;
                121.   	if(!create) return 0;
                122.   	if((lh = lh_ENGINE_PILE_new()) == NULL)
                                 ^
                123.   		return 0;
                124.   	*t = (ENGINE_TABLE *)lh;

crypto/lhash/lhash.c:133:2: Assignment
                  131.   	ret->up_load=UP_LOAD;
                  132.   	ret->down_load=DOWN_LOAD;
                  133.   	ret->num_items=0;
                          ^
                  134.   
                  135.   	ret->num_expands=0;

apps/s_client.c:1451:6: Call
1449.   #endif
1450.   
1451.   	con=SSL_new(ctx);
             ^
1452.   	if (sess_in)
1453.   		{

ssl/ssl_lib.c:275:1: Parameter `ctx->sessions->num_items`
  273.   	}
  274.   
  275. > SSL *SSL_new(SSL_CTX *ctx)
  276.   	{
  277.   	SSL *s;

ssl/ssl_lib.c:408:2: Call
  406.   	s->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;
  407.   
  408.   	SSL_clear(s);
          ^
  409.   
  410.   	CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);

ssl/ssl_lib.c:185:1: Parameter `s->ctx->sessions->num_items`
    183.   	};
    184.   
    185. > int SSL_clear(SSL *s)
    186.   	{
    187.   

ssl/ssl_lib.c:194:6: Call
    192.   		}
    193.   
    194.   	if (ssl_clear_bad_session(s))
                ^
    195.   		{
    196.   		SSL_SESSION_free(s->session);

ssl/ssl_sess.c:982:1: Parameter `s->ctx->sessions->num_items`
      980.   	}
      981.   
      982. > int ssl_clear_bad_session(SSL *s)
      983.   	{
      984.   	if (	(s->session != NULL) &&

ssl/ssl_sess.c:988:3: Call
      986.   		!(SSL_in_init(s) || SSL_in_before(s)))
      987.   		{
      988.   		SSL_CTX_remove_session(s->ctx,s->session);
               ^
      989.   		return(1);
      990.   		}

ssl/ssl_sess.c:677:1: Parameter `ctx->sessions->num_items`
        675.   	}
        676.   
        677. > int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
        678.   {
        679.   	return remove_session_lock(ctx, c, 1);

ssl/ssl_sess.c:679:9: Call
        677.   int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
        678.   {
        679.   	return remove_session_lock(ctx, c, 1);
                       ^
        680.   }
        681.   

ssl/ssl_sess.c:682:1: Parameter `ctx->sessions->num_items`
          680.   }
          681.   
          682. > static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
          683.   	{
          684.   	SSL_SESSION *r;

ssl/ssl_sess.c:693:6: Call
          691.   			{
          692.   			ret=1;
          693.   			r=lh_SSL_SESSION_delete(ctx->sessions,c);
                      ^
          694.   			SSL_SESSION_list_remove(ctx,c);
          695.   			}

crypto/lhash/lhash.c:217:1: <LHS trace>
215.   	}
216.   
217. > void *lh_delete(_LHASH *lh, const void *data)
218.   	{
219.   	unsigned long hash;

crypto/lhash/lhash.c:217:1: Parameter `lh->num_items`
            215.   	}
            216.   
            217. > void *lh_delete(_LHASH *lh, const void *data)
            218.   	{
            219.   	unsigned long hash;

crypto/lhash/lhash.c:240:2: Binary operation: (0 - 1):unsigned64 by call to `SSL_new` 
            238.   		}
            239.   
            240.   	lh->num_items--;
                    ^
            241.   	if ((lh->num_nodes > MIN_NODES) &&
            242.   		(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))

void *lh_delete(_LHASH *lh, const void *data)
	{
	unsigned long hash;
	LHASH_NODE *nn,**rn;
	void *ret;
	lh->error=0;
	rn=getrn(lh,data,&hash);
	if (*rn == NULL)
		{
		lh->num_no_delete++;
		return(NULL);
		}
	else
		{
		nn= *rn;
		*rn=nn->next;
		ret=nn->data;
		OPENSSL_free(nn);
		lh->num_delete++;
		}
	lh->num_items--;
	if ((lh->num_nodes > MIN_NODES) &&
		(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
		contract(lh);
	return(ret);
	}
['int MAIN(int argc, char **argv)\n\t{\n\tint build_chain = 0;\n\tSSL *con=NULL;\n#ifndef OPENSSL_NO_KRB5\n\tKSSL_CTX *kctx;\n#endif\n\tint s,k,width,state=0;\n\tchar *cbuf=NULL,*sbuf=NULL,*mbuf=NULL;\n\tint cbuf_len,cbuf_off;\n\tint sbuf_len,sbuf_off;\n\tfd_set readfds,writefds;\n\tshort port=PORT;\n\tint full_log=1;\n\tchar *host=SSL_HOST_NAME;\n\tchar *xmpphost = NULL;\n\tchar *cert_file=NULL,*key_file=NULL,*chain_file=NULL;\n\tint cert_format = FORMAT_PEM, key_format = FORMAT_PEM;\n\tchar *passarg = NULL, *pass = NULL;\n\tX509 *cert = NULL;\n\tEVP_PKEY *key = NULL;\n\tSTACK_OF(X509) *chain = NULL;\n\tchar *CApath=NULL,*CAfile=NULL;\n\tchar *chCApath=NULL,*chCAfile=NULL;\n\tchar *vfyCApath=NULL,*vfyCAfile=NULL;\n\tint reconnect=0,badop=0,verify=SSL_VERIFY_NONE;\n\tint crlf=0;\n\tint write_tty,read_tty,write_ssl,read_ssl,tty_on,ssl_pending;\n\tSSL_CTX *ctx=NULL;\n\tint ret=1,in_init=1,i,nbio_test=0;\n\tint starttls_proto = PROTO_OFF;\n\tint prexit = 0;\n\tX509_VERIFY_PARAM *vpm = NULL;\n\tint badarg = 0;\n\tconst SSL_METHOD *meth=NULL;\n\tint socket_type=SOCK_STREAM;\n\tBIO *sbio;\n\tchar *inrand=NULL;\n\tint mbuf_len=0;\n\tstruct timeval timeout, *timeoutp;\n#ifndef OPENSSL_NO_ENGINE\n\tchar *engine_id=NULL;\n\tchar *ssl_client_engine_id=NULL;\n\tENGINE *ssl_client_engine=NULL;\n#endif\n\tENGINE *e=NULL;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)\n\tstruct timeval tv;\n#if defined(OPENSSL_SYS_BEOS_R5)\n\tint stdin_set = 0;\n#endif\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n\tchar *servername = NULL;\n        tlsextctx tlsextcbp =\n        {NULL,0};\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\tconst char *next_proto_neg_in = NULL;\n# endif\n\tconst char *alpn_in = NULL;\n# define MAX_SI_TYPES 100\n\tunsigned short serverinfo_types[MAX_SI_TYPES];\n\tint serverinfo_types_count = 0;\n#endif\n\tchar *sess_in = NULL;\n\tchar *sess_out = NULL;\n\tstruct sockaddr peer;\n\tint peerlen = sizeof(peer);\n\tint enable_timeouts = 0 ;\n\tlong socket_mtu = 0;\n#ifndef OPENSSL_NO_JPAKE\nstatic char *jpake_secret = NULL;\n#define no_jpake !jpake_secret\n#else\n#define no_jpake 1\n#endif\n#ifndef OPENSSL_NO_SRP\n\tchar * srppass = NULL;\n\tint srp_lateuser = 0;\n\tSRP_ARG srp_arg = {NULL,NULL,0,0,0,1024};\n#endif\n\tSSL_EXCERT *exc = NULL;\n\tSSL_CONF_CTX *cctx = NULL;\n\tSTACK_OF(OPENSSL_STRING) *ssl_args = NULL;\n\tchar *crl_file = NULL;\n\tint crl_format = FORMAT_PEM;\n\tint crl_download = 0;\n\tSTACK_OF(X509_CRL) *crls = NULL;\n\tint sdebug = 0;\n\tmeth=SSLv23_client_method();\n\tapps_startup();\n\tc_Pause=0;\n\tc_quiet=0;\n\tc_ign_eof=0;\n\tc_debug=0;\n\tc_msg=0;\n\tc_showcerts=0;\n\tif (bio_err == NULL)\n\t\tbio_err=BIO_new_fp(stderr,BIO_NOCLOSE);\n\tif (!load_config(bio_err, NULL))\n\t\tgoto end;\n\tcctx = SSL_CONF_CTX_new();\n\tif (!cctx)\n\t\tgoto end;\n\tSSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CLIENT);\n\tSSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CMDLINE);\n\tif (\t((cbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n\t\t((sbuf=OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n\t\t((mbuf=OPENSSL_malloc(BUFSIZZ)) == NULL))\n\t\t{\n\t\tBIO_printf(bio_err,"out of memory\\n");\n\t\tgoto end;\n\t\t}\n\tverify_depth=0;\n\tverify_error=X509_V_OK;\n#ifdef FIONBIO\n\tc_nbio=0;\n#endif\n\targc--;\n\targv++;\n\twhile (argc >= 1)\n\t\t{\n\t\tif\t(strcmp(*argv,"-host") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\thost= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-port") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tport=atoi(*(++argv));\n\t\t\tif (port == 0) goto bad;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-connect") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tif (!extract_host_port(*(++argv),&host,NULL,&port))\n\t\t\t\tgoto bad;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-xmpphost") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\txmpphost= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-verify") == 0)\n\t\t\t{\n\t\t\tverify=SSL_VERIFY_PEER;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tverify_depth=atoi(*(++argv));\n\t\t\tif (!c_quiet)\n\t\t\t\tBIO_printf(bio_err,"verify depth is %d\\n",verify_depth);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-cert") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcert_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CRL") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcrl_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-crl_download") == 0)\n\t\t\tcrl_download = 1;\n\t\telse if\t(strcmp(*argv,"-sess_out") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsess_out = *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-sess_in") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsess_in = *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-certform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcert_format = str2fmt(*(++argv));\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CRLform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tcrl_format = str2fmt(*(++argv));\n\t\t\t}\n\t\telse if (args_verify(&argv, &argc, &badarg, bio_err, &vpm))\n\t\t\t{\n\t\t\tif (badarg)\n\t\t\t\tgoto bad;\n\t\t\tcontinue;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-verify_return_error") == 0)\n\t\t\tverify_return_error = 1;\n\t\telse if (strcmp(*argv,"-verify_quiet") == 0)\n\t\t\tverify_quiet = 1;\n\t\telse if (strcmp(*argv,"-brief") == 0)\n\t\t\t{\n\t\t\tc_brief = 1;\n\t\t\tverify_quiet = 1;\n\t\t\tc_quiet = 1;\n\t\t\t}\n\t\telse if (args_excert(&argv, &argc, &badarg, bio_err, &exc))\n\t\t\t{\n\t\t\tif (badarg)\n\t\t\t\tgoto bad;\n\t\t\tcontinue;\n\t\t\t}\n\t\telse if (args_ssl(&argv, &argc, cctx, &badarg, bio_err, &ssl_args))\n\t\t\t{\n\t\t\tif (badarg)\n\t\t\t\tgoto bad;\n\t\t\tcontinue;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-prexit") == 0)\n\t\t\tprexit=1;\n\t\telse if\t(strcmp(*argv,"-crlf") == 0)\n\t\t\tcrlf=1;\n\t\telse if\t(strcmp(*argv,"-quiet") == 0)\n\t\t\t{\n\t\t\tc_quiet=1;\n\t\t\tc_ign_eof=1;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-ign_eof") == 0)\n\t\t\tc_ign_eof=1;\n\t\telse if\t(strcmp(*argv,"-no_ign_eof") == 0)\n\t\t\tc_ign_eof=0;\n\t\telse if\t(strcmp(*argv,"-pause") == 0)\n\t\t\tc_Pause=1;\n\t\telse if\t(strcmp(*argv,"-debug") == 0)\n\t\t\tc_debug=1;\n#ifndef OPENSSL_NO_TLSEXT\n\t\telse if\t(strcmp(*argv,"-tlsextdebug") == 0)\n\t\t\tc_tlsextdebug=1;\n\t\telse if\t(strcmp(*argv,"-status") == 0)\n\t\t\tc_status_req=1;\n\t\telse if\t(strcmp(*argv,"-auth") == 0)\n\t\t\tc_auth = 1;\n\t\telse if\t(strcmp(*argv,"-auth_require_reneg") == 0)\n\t\t\tc_auth_require_reneg = 1;\n#endif\n#ifdef WATT32\n\t\telse if (strcmp(*argv,"-wdebug") == 0)\n\t\t\tdbug_init();\n#endif\n\t\telse if\t(strcmp(*argv,"-msg") == 0)\n\t\t\tc_msg=1;\n\t\telse if\t(strcmp(*argv,"-msgfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tbio_c_msg = BIO_new_file(*(++argv), "w");\n\t\t\t}\n#ifndef OPENSSL_NO_SSL_TRACE\n\t\telse if\t(strcmp(*argv,"-trace") == 0)\n\t\t\tc_msg=2;\n#endif\n\t\telse if\t(strcmp(*argv,"-security_debug") == 0)\n\t\t\t{ sdebug=1; }\n\t\telse if\t(strcmp(*argv,"-security_debug_verbose") == 0)\n\t\t\t{ sdebug=2; }\n\t\telse if\t(strcmp(*argv,"-showcerts") == 0)\n\t\t\tc_showcerts=1;\n\t\telse if\t(strcmp(*argv,"-nbio_test") == 0)\n\t\t\tnbio_test=1;\n\t\telse if\t(strcmp(*argv,"-state") == 0)\n\t\t\tstate=1;\n#ifndef OPENSSL_NO_PSK\n                else if (strcmp(*argv,"-psk_identity") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpsk_identity=*(++argv);\n\t\t\t}\n                else if (strcmp(*argv,"-psk") == 0)\n\t\t\t{\n                        size_t j;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpsk_key=*(++argv);\n\t\t\tfor (j = 0; j < strlen(psk_key); j++)\n                                {\n                                if (isxdigit((unsigned char)psk_key[j]))\n                                        continue;\n                                BIO_printf(bio_err,"Not a hex number \'%s\'\\n",*argv);\n                                goto bad;\n                                }\n\t\t\t}\n#endif\n#ifndef OPENSSL_NO_SRP\n\t\telse if (strcmp(*argv,"-srpuser") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsrp_arg.srplogin= *(++argv);\n\t\t\tmeth=TLSv1_client_method();\n\t\t\t}\n\t\telse if (strcmp(*argv,"-srppass") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsrppass= *(++argv);\n\t\t\tmeth=TLSv1_client_method();\n\t\t\t}\n\t\telse if (strcmp(*argv,"-srp_strength") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsrp_arg.strength=atoi(*(++argv));\n\t\t\tBIO_printf(bio_err,"SRP minimal length for N is %d\\n",srp_arg.strength);\n\t\t\tmeth=TLSv1_client_method();\n\t\t\t}\n\t\telse if (strcmp(*argv,"-srp_lateuser") == 0)\n\t\t\t{\n\t\t\tsrp_lateuser= 1;\n\t\t\tmeth=TLSv1_client_method();\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-srp_moregroups") == 0)\n\t\t\t{\n\t\t\tsrp_arg.amp=1;\n\t\t\tmeth=TLSv1_client_method();\n\t\t\t}\n#endif\n#ifndef OPENSSL_NO_SSL2\n\t\telse if\t(strcmp(*argv,"-ssl2") == 0)\n\t\t\tmeth=SSLv2_client_method();\n#endif\n#ifndef OPENSSL_NO_SSL3\n\t\telse if\t(strcmp(*argv,"-ssl3") == 0)\n\t\t\tmeth=SSLv3_client_method();\n#endif\n#ifndef OPENSSL_NO_TLS1\n\t\telse if\t(strcmp(*argv,"-tls1_2") == 0)\n\t\t\tmeth=TLSv1_2_client_method();\n\t\telse if\t(strcmp(*argv,"-tls1_1") == 0)\n\t\t\tmeth=TLSv1_1_client_method();\n\t\telse if\t(strcmp(*argv,"-tls1") == 0)\n\t\t\tmeth=TLSv1_client_method();\n#endif\n#ifndef OPENSSL_NO_DTLS1\n\t\telse if\t(strcmp(*argv,"-dtls") == 0)\n\t\t\t{\n\t\t\tmeth=DTLS_client_method();\n\t\t\tsocket_type=SOCK_DGRAM;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-dtls1") == 0)\n\t\t\t{\n\t\t\tmeth=DTLSv1_client_method();\n\t\t\tsocket_type=SOCK_DGRAM;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-dtls1_2") == 0)\n\t\t\t{\n\t\t\tmeth=DTLSv1_2_client_method();\n\t\t\tsocket_type=SOCK_DGRAM;\n\t\t\t}\n\t\telse if (strcmp(*argv,"-timeout") == 0)\n\t\t\tenable_timeouts=1;\n\t\telse if (strcmp(*argv,"-mtu") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsocket_mtu = atol(*(++argv));\n\t\t\t}\n#endif\n\t\telse if\t(strcmp(*argv,"-keyform") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkey_format = str2fmt(*(++argv));\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-pass") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tpassarg = *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-cert_chain") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tchain_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-key") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkey_file= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-reconnect") == 0)\n\t\t\t{\n\t\t\treconnect=5;\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-CApath") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCApath= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-chainCApath") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tchCApath= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-verifyCApath") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tvfyCApath= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-build_chain") == 0)\n\t\t\tbuild_chain = 1;\n\t\telse if\t(strcmp(*argv,"-CAfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tCAfile= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-chainCAfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tchCAfile= *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-verifyCAfile") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tvfyCAfile= *(++argv);\n\t\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\t\telse if (strcmp(*argv,"-nextprotoneg") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tnext_proto_neg_in = *(++argv);\n\t\t\t}\n# endif\n\t\telse if (strcmp(*argv,"-alpn") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\talpn_in = *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-serverinfo") == 0)\n\t\t\t{\n\t\t\tchar *c;\n\t\t\tint start = 0;\n\t\t\tint len;\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tc = *(++argv);\n\t\t\tserverinfo_types_count = 0;\n\t\t\tlen = strlen(c);\n\t\t\tfor (i = 0; i <= len; ++i)\n\t\t\t\t{\n\t\t\t\tif (i == len || c[i] == \',\')\n\t\t\t\t\t{\n\t\t\t\t\tserverinfo_types[serverinfo_types_count]\n\t\t\t\t\t    = atoi(c+start);\n\t\t\t\t\tserverinfo_types_count++;\n\t\t\t\t\tstart = i+1;\n\t\t\t\t\t}\n\t\t\t\tif (serverinfo_types_count == MAX_SI_TYPES)\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n#endif\n#ifdef FIONBIO\n\t\telse if (strcmp(*argv,"-nbio") == 0)\n\t\t\t{ c_nbio=1; }\n#endif\n\t\telse if\t(strcmp(*argv,"-starttls") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\t++argv;\n\t\t\tif (strcmp(*argv,"smtp") == 0)\n\t\t\t\tstarttls_proto = PROTO_SMTP;\n\t\t\telse if (strcmp(*argv,"pop3") == 0)\n\t\t\t\tstarttls_proto = PROTO_POP3;\n\t\t\telse if (strcmp(*argv,"imap") == 0)\n\t\t\t\tstarttls_proto = PROTO_IMAP;\n\t\t\telse if (strcmp(*argv,"ftp") == 0)\n\t\t\t\tstarttls_proto = PROTO_FTP;\n\t\t\telse if (strcmp(*argv, "xmpp") == 0)\n\t\t\t\tstarttls_proto = PROTO_XMPP;\n\t\t\telse\n\t\t\t\tgoto bad;\n\t\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\t\telse if\t(strcmp(*argv,"-engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tengine_id = *(++argv);\n\t\t\t}\n\t\telse if\t(strcmp(*argv,"-ssl_client_engine") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tssl_client_engine_id = *(++argv);\n\t\t\t}\n#endif\n\t\telse if (strcmp(*argv,"-rand") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tinrand= *(++argv);\n\t\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\t\telse if (strcmp(*argv,"-servername") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tservername= *(++argv);\n\t\t\t}\n#endif\n#ifndef OPENSSL_NO_JPAKE\n\t\telse if (strcmp(*argv,"-jpake") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tjpake_secret = *++argv;\n\t\t\t}\n#endif\n\t\telse if (strcmp(*argv,"-use_srtp") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tsrtp_profiles = *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keymatexport") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeymatexportlabel= *(++argv);\n\t\t\t}\n\t\telse if (strcmp(*argv,"-keymatexportlen") == 0)\n\t\t\t{\n\t\t\tif (--argc < 1) goto bad;\n\t\t\tkeymatexportlen=atoi(*(++argv));\n\t\t\tif (keymatexportlen == 0) goto bad;\n\t\t\t}\n                else\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"unknown option %s\\n",*argv);\n\t\t\tbadop=1;\n\t\t\tbreak;\n\t\t\t}\n\t\targc--;\n\t\targv++;\n\t\t}\n\tif (badop)\n\t\t{\nbad:\n\t\tsc_usage();\n\t\tgoto end;\n\t\t}\n#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)\n\tif (jpake_secret)\n\t\t{\n\t\tif (psk_key)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t   "Can\'t use JPAKE and PSK together\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tpsk_identity = "JPAKE";\n\t\t}\n#endif\n\tOpenSSL_add_ssl_algorithms();\n\tSSL_load_error_strings();\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n\tnext_proto.status = -1;\n\tif (next_proto_neg_in)\n\t\t{\n\t\tnext_proto.data = next_protos_parse(&next_proto.len, next_proto_neg_in);\n\t\tif (next_proto.data == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error parsing -nextprotoneg argument\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\telse\n\t\tnext_proto.data = NULL;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n        e = setup_engine(bio_err, engine_id, 1);\n\tif (ssl_client_engine_id)\n\t\t{\n\t\tssl_client_engine = ENGINE_by_id(ssl_client_engine_id);\n\t\tif (!ssl_client_engine)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t\t"Error getting client auth engine\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n\tif (!app_passwd(bio_err, passarg, NULL, &pass, NULL))\n\t\t{\n\t\tBIO_printf(bio_err, "Error getting password\\n");\n\t\tgoto end;\n\t\t}\n\tif (key_file == NULL)\n\t\tkey_file = cert_file;\n\tif (key_file)\n\t\t{\n\t\tkey = load_key(bio_err, key_file, key_format, 0, pass, e,\n\t\t\t       "client certificate private key file");\n\t\tif (!key)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (cert_file)\n\t\t{\n\t\tcert = load_cert(bio_err,cert_file,cert_format,\n\t\t\t\tNULL, e, "client certificate file");\n\t\tif (!cert)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (chain_file)\n\t\t{\n\t\tchain = load_certs(bio_err, chain_file,FORMAT_PEM,\n\t\t\t\t\tNULL, e, "client certificate chain");\n\t\tif (!chain)\n\t\t\tgoto end;\n\t\t}\n\tif (crl_file)\n\t\t{\n\t\tX509_CRL *crl;\n\t\tcrl = load_crl(crl_file, crl_format);\n\t\tif (!crl)\n\t\t\t{\n\t\t\tBIO_puts(bio_err, "Error loading CRL\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tcrls = sk_X509_CRL_new_null();\n\t\tif (!crls || !sk_X509_CRL_push(crls, crl))\n\t\t\t{\n\t\t\tBIO_puts(bio_err, "Error adding CRL\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tX509_CRL_free(crl);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n\tif (!load_excert(&exc, bio_err))\n\t\tgoto end;\n\tif (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL\n\t\t&& !RAND_status())\n\t\t{\n\t\tBIO_printf(bio_err,"warning, not much extra random data, consider using the -rand option\\n");\n\t\t}\n\tif (inrand != NULL)\n\t\tBIO_printf(bio_err,"%ld semi-random bytes loaded\\n",\n\t\t\tapp_RAND_load_files(inrand));\n\tif (bio_c_out == NULL)\n\t\t{\n\t\tif (c_quiet && !c_debug)\n\t\t\t{\n\t\t\tbio_c_out=BIO_new(BIO_s_null());\n\t\t\tif (c_msg && !bio_c_msg)\n\t\t\t\tbio_c_msg=BIO_new_fp(stdout,BIO_NOCLOSE);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (bio_c_out == NULL)\n\t\t\t\tbio_c_out=BIO_new_fp(stdout,BIO_NOCLOSE);\n\t\t\t}\n\t\t}\n#ifndef OPENSSL_NO_SRP\n\tif(!app_passwd(bio_err, srppass, NULL, &srp_arg.srppassin, NULL))\n\t\t{\n\t\tBIO_printf(bio_err, "Error getting password\\n");\n\t\tgoto end;\n\t\t}\n#endif\n\tctx=SSL_CTX_new(meth);\n\tif (ctx == NULL)\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (sdebug)\n\t\tssl_ctx_security_debug(ctx, bio_err, sdebug);\n\tif (vpm)\n\t\tSSL_CTX_set1_param(ctx, vpm);\n\tif (!args_ssl_call(ctx, bio_err, cctx, ssl_args, 1, no_jpake))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n\tif (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile,\n\t\t\t\t\t\tcrls, crl_download))\n\t\t{\n\t\tBIO_printf(bio_err, "Error loading store locations\\n");\n\t\tERR_print_errors(bio_err);\n\t\tgoto end;\n\t\t}\n#ifndef OPENSSL_NO_ENGINE\n\tif (ssl_client_engine)\n\t\t{\n\t\tif (!SSL_CTX_set_client_cert_engine(ctx, ssl_client_engine))\n\t\t\t{\n\t\t\tBIO_puts(bio_err, "Error setting client auth engine\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tENGINE_free(ssl_client_engine);\n\t\t\tgoto end;\n\t\t\t}\n\t\tENGINE_free(ssl_client_engine);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_PSK\n#ifdef OPENSSL_NO_JPAKE\n\tif (psk_key != NULL)\n#else\n\tif (psk_key != NULL || jpake_secret)\n#endif\n\t\t{\n\t\tif (c_debug)\n\t\t\tBIO_printf(bio_c_out, "PSK key given or JPAKE in use, setting client callback\\n");\n\t\tSSL_CTX_set_psk_client_callback(ctx, psk_client_cb);\n\t\t}\n\tif (srtp_profiles != NULL)\n\t\tSSL_CTX_set_tlsext_use_srtp(ctx, srtp_profiles);\n#endif\n\tif (exc) ssl_ctx_set_excert(ctx, exc);\n\tif (socket_type == SOCK_DGRAM) SSL_CTX_set_read_ahead(ctx, 1);\n#if !defined(OPENSSL_NO_TLSEXT)\n# if !defined(OPENSSL_NO_NEXTPROTONEG)\n\tif (next_proto.data)\n\t\tSSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &next_proto);\n# endif\n\tif (alpn_in)\n\t\t{\n\t\tunsigned short alpn_len;\n\t\tunsigned char *alpn = next_protos_parse(&alpn_len, alpn_in);\n\t\tif (alpn == NULL)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Error parsing -alpn argument\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tSSL_CTX_set_alpn_protos(ctx, alpn, alpn_len);\n\t\tOPENSSL_free(alpn);\n\t\t}\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n\t\tif (serverinfo_types_count)\n\t\t\t{\n\t\t\tfor (i = 0; i < serverinfo_types_count; i++)\n\t\t\t\t{\n\t\t\t\tSSL_CTX_set_custom_cli_ext(ctx,\n\t\t\t\t\t\t\t   serverinfo_types[i],\n\t\t\t\t\t\t\t   NULL,\n\t\t\t\t\t\t\t   serverinfo_cli_cb,\n\t\t\t\t\t\t\t   NULL);\n\t\t\t\t}\n\t\t\t}\n#endif\n\tif (state) SSL_CTX_set_info_callback(ctx,apps_ssl_info_callback);\n#if 0\n\telse\n\t\tSSL_CTX_set_cipher_list(ctx,getenv("SSL_CIPHER"));\n#endif\n\tSSL_CTX_set_verify(ctx,verify,verify_callback);\n\tif ((!SSL_CTX_load_verify_locations(ctx,CAfile,CApath)) ||\n\t\t(!SSL_CTX_set_default_verify_paths(ctx)))\n\t\t{\n\t\tERR_print_errors(bio_err);\n\t\t}\n\tssl_ctx_add_crls(ctx, crls, crl_download);\n\tif (!set_cert_key_stuff(ctx,cert,key,chain,build_chain))\n\t\tgoto end;\n#ifndef OPENSSL_NO_TLSEXT\n\tif (servername != NULL)\n\t\t{\n\t\ttlsextcbp.biodebug = bio_err;\n\t\tSSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);\n\t\tSSL_CTX_set_tlsext_servername_arg(ctx, &tlsextcbp);\n\t\t}\n#ifndef OPENSSL_NO_SRP\n        if (srp_arg.srplogin)\n\t\t{\n\t\tif (!srp_lateuser && !SSL_CTX_set_srp_username(ctx, srp_arg.srplogin))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Unable to set SRP username\\n");\n\t\t\tgoto end;\n\t\t\t}\n\t\tsrp_arg.msg = c_msg;\n\t\tsrp_arg.debug = c_debug ;\n\t\tSSL_CTX_set_srp_cb_arg(ctx,&srp_arg);\n\t\tSSL_CTX_set_srp_client_pwd_callback(ctx, ssl_give_srp_client_pwd_cb);\n\t\tSSL_CTX_set_srp_strength(ctx, srp_arg.strength);\n\t\tif (c_msg || c_debug || srp_arg.amp == 0)\n\t\t\tSSL_CTX_set_srp_verify_param_callback(ctx, ssl_srp_verify_param_cb);\n\t\t}\n#endif\n\tif (c_auth)\n\t\t{\n\t\tSSL_CTX_set_custom_cli_ext(ctx, TLSEXT_TYPE_client_authz, authz_tlsext_generate_cb, authz_tlsext_cb, bio_err);\n\t\tSSL_CTX_set_custom_cli_ext(ctx, TLSEXT_TYPE_server_authz, authz_tlsext_generate_cb, authz_tlsext_cb, bio_err);\n\t\tSSL_CTX_set_cli_supp_data(ctx, TLSEXT_SUPPLEMENTALDATATYPE_authz_data, suppdata_cb, auth_suppdata_generate_cb, bio_err);\n\t\t}\n#endif\n\tcon=SSL_new(ctx);\n\tif (sess_in)\n\t\t{\n\t\tSSL_SESSION *sess;\n\t\tBIO *stmp = BIO_new_file(sess_in, "r");\n\t\tif (!stmp)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Can\'t open session file %s\\n",\n\t\t\t\t\t\tsess_in);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tsess = PEM_read_bio_SSL_SESSION(stmp, NULL, 0, NULL);\n\t\tBIO_free(stmp);\n\t\tif (!sess)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "Can\'t open session file %s\\n",\n\t\t\t\t\t\tsess_in);\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\tSSL_set_session(con, sess);\n\t\tSSL_SESSION_free(sess);\n\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\tif (servername != NULL)\n\t\t{\n\t\tif (!SSL_set_tlsext_host_name(con,servername))\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"Unable to set TLS servername extension.\\n");\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n#ifndef OPENSSL_NO_KRB5\n\tif (con  &&  (kctx = kssl_ctx_new()) != NULL)\n                {\n\t\tSSL_set0_kssl_ctx(con, kctx);\n                kssl_ctx_setstring(kctx, KSSL_SERVER, host);\n\t\t}\n#endif\n#if 0\n#ifdef TLSEXT_TYPE_opaque_prf_input\n\tSSL_set_tlsext_opaque_prf_input(con, "Test client", 11);\n#endif\n#endif\nre_start:\n\tif (init_client(&s,host,port,socket_type) == 0)\n\t\t{\n\t\tBIO_printf(bio_err,"connect:errno=%d\\n",get_last_socket_error());\n\t\tSHUTDOWN(s);\n\t\tgoto end;\n\t\t}\n\tBIO_printf(bio_c_out,"CONNECTED(%08X)\\n",s);\n#ifdef FIONBIO\n\tif (c_nbio)\n\t\t{\n\t\tunsigned long l=1;\n\t\tBIO_printf(bio_c_out,"turning on non blocking io\\n");\n\t\tif (BIO_socket_ioctl(s,FIONBIO,&l) < 0)\n\t\t\t{\n\t\t\tERR_print_errors(bio_err);\n\t\t\tgoto end;\n\t\t\t}\n\t\t}\n#endif\n\tif (c_Pause & 0x01) SSL_set_debug(con, 1);\n\tif (socket_type == SOCK_DGRAM)\n\t\t{\n\t\tsbio=BIO_new_dgram(s,BIO_NOCLOSE);\n\t\tif (getsockname(s, &peer, (void *)&peerlen) < 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err, "getsockname:errno=%d\\n",\n\t\t\t\tget_last_socket_error());\n\t\t\tSHUTDOWN(s);\n\t\t\tgoto end;\n\t\t\t}\n\t\t(void)BIO_ctrl_set_connected(sbio, 1, &peer);\n\t\tif (enable_timeouts)\n\t\t\t{\n\t\t\ttimeout.tv_sec = 0;\n\t\t\ttimeout.tv_usec = DGRAM_RCV_TIMEOUT;\n\t\t\tBIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n\t\t\ttimeout.tv_sec = 0;\n\t\t\ttimeout.tv_usec = DGRAM_SND_TIMEOUT;\n\t\t\tBIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n\t\t\t}\n\t\tif (socket_mtu > 28)\n\t\t\t{\n\t\t\tSSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n\t\t\tSSL_set_mtu(con, socket_mtu - 28);\n\t\t\t}\n\t\telse\n\t\t\tBIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n\t\t}\n\telse\n\t\tsbio=BIO_new_socket(s,BIO_NOCLOSE);\n\tif (nbio_test)\n\t\t{\n\t\tBIO *test;\n\t\ttest=BIO_new(BIO_f_nbio_test());\n\t\tsbio=BIO_push(test,sbio);\n\t\t}\n\tif (c_debug)\n\t\t{\n\t\tSSL_set_debug(con, 1);\n\t\tBIO_set_callback(sbio,bio_dump_callback);\n\t\tBIO_set_callback_arg(sbio,(char *)bio_c_out);\n\t\t}\n\tif (c_msg)\n\t\t{\n#ifndef OPENSSL_NO_SSL_TRACE\n\t\tif (c_msg == 2)\n\t\t\tSSL_set_msg_callback(con, SSL_trace);\n\t\telse\n#endif\n\t\t\tSSL_set_msg_callback(con, msg_cb);\n\t\tSSL_set_msg_callback_arg(con, bio_c_msg ? bio_c_msg : bio_c_out);\n\t\t}\n#ifndef OPENSSL_NO_TLSEXT\n\tif (c_tlsextdebug)\n\t\t{\n\t\tSSL_set_tlsext_debug_callback(con, tlsext_cb);\n\t\tSSL_set_tlsext_debug_arg(con, bio_c_out);\n\t\t}\n\tif (c_status_req)\n\t\t{\n\t\tSSL_set_tlsext_status_type(con, TLSEXT_STATUSTYPE_ocsp);\n\t\tSSL_CTX_set_tlsext_status_cb(ctx, ocsp_resp_cb);\n\t\tSSL_CTX_set_tlsext_status_arg(ctx, bio_c_out);\n#if 0\n{\nSTACK_OF(OCSP_RESPID) *ids = sk_OCSP_RESPID_new_null();\nOCSP_RESPID *id = OCSP_RESPID_new();\nid->value.byKey = ASN1_OCTET_STRING_new();\nid->type = V_OCSP_RESPID_KEY;\nASN1_STRING_set(id->value.byKey, "Hello World", -1);\nsk_OCSP_RESPID_push(ids, id);\nSSL_set_tlsext_status_ids(con, ids);\n}\n#endif\n\t\t}\n#endif\n#ifndef OPENSSL_NO_JPAKE\n\tif (jpake_secret)\n\t\tjpake_client_auth(bio_c_out, sbio, jpake_secret);\n#endif\n\tSSL_set_bio(con,sbio,sbio);\n\tSSL_set_connect_state(con);\n\twidth=SSL_get_fd(con)+1;\n\tread_tty=1;\n\twrite_tty=0;\n\ttty_on=0;\n\tread_ssl=1;\n\twrite_ssl=1;\n\tcbuf_len=0;\n\tcbuf_off=0;\n\tsbuf_len=0;\n\tsbuf_off=0;\n\tif (starttls_proto == PROTO_SMTP)\n\t\t{\n\t\tint foundit=0;\n\t\tBIO *fbio = BIO_new(BIO_f_buffer());\n\t\tBIO_push(fbio, sbio);\n\t\tdo\n\t\t\t{\n\t\t\tmbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);\n\t\t\t}\n\t\twhile (mbuf_len>3 && mbuf[3]==\'-\');\n\t\tBIO_printf(fbio,"EHLO openssl.client.net\\r\\n");\n\t\t(void)BIO_flush(fbio);\n\t\tdo\n\t\t\t{\n\t\t\tmbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);\n\t\t\tif (strstr(mbuf,"STARTTLS"))\n\t\t\t\tfoundit=1;\n\t\t\t}\n\t\twhile (mbuf_len>3 && mbuf[3]==\'-\');\n\t\t(void)BIO_flush(fbio);\n\t\tBIO_pop(fbio);\n\t\tBIO_free(fbio);\n\t\tif (!foundit)\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t   "didn\'t found starttls in server response,"\n\t\t\t\t   " try anyway...\\n");\n\t\tBIO_printf(sbio,"STARTTLS\\r\\n");\n\t\tBIO_read(sbio,sbuf,BUFSIZZ);\n\t\t}\n\telse if (starttls_proto == PROTO_POP3)\n\t\t{\n\t\tBIO_read(sbio,mbuf,BUFSIZZ);\n\t\tBIO_printf(sbio,"STLS\\r\\n");\n\t\tBIO_read(sbio,sbuf,BUFSIZZ);\n\t\t}\n\telse if (starttls_proto == PROTO_IMAP)\n\t\t{\n\t\tint foundit=0;\n\t\tBIO *fbio = BIO_new(BIO_f_buffer());\n\t\tBIO_push(fbio, sbio);\n\t\tBIO_gets(fbio,mbuf,BUFSIZZ);\n\t\tBIO_printf(fbio,". CAPABILITY\\r\\n");\n\t\t(void)BIO_flush(fbio);\n\t\tdo\n\t\t\t{\n\t\t\tmbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);\n\t\t\tif (strstr(mbuf,"STARTTLS"))\n\t\t\t\tfoundit=1;\n\t\t\t}\n\t\twhile (mbuf_len>3 && mbuf[0]!=\'.\');\n\t\t(void)BIO_flush(fbio);\n\t\tBIO_pop(fbio);\n\t\tBIO_free(fbio);\n\t\tif (!foundit)\n\t\t\tBIO_printf(bio_err,\n\t\t\t\t   "didn\'t found STARTTLS in server response,"\n\t\t\t\t   " try anyway...\\n");\n\t\tBIO_printf(sbio,". STARTTLS\\r\\n");\n\t\tBIO_read(sbio,sbuf,BUFSIZZ);\n\t\t}\n\telse if (starttls_proto == PROTO_FTP)\n\t\t{\n\t\tBIO *fbio = BIO_new(BIO_f_buffer());\n\t\tBIO_push(fbio, sbio);\n\t\tdo\n\t\t\t{\n\t\t\tmbuf_len = BIO_gets(fbio,mbuf,BUFSIZZ);\n\t\t\t}\n\t\twhile (mbuf_len>3 && mbuf[3]==\'-\');\n\t\t(void)BIO_flush(fbio);\n\t\tBIO_pop(fbio);\n\t\tBIO_free(fbio);\n\t\tBIO_printf(sbio,"AUTH TLS\\r\\n");\n\t\tBIO_read(sbio,sbuf,BUFSIZZ);\n\t\t}\n\tif (starttls_proto == PROTO_XMPP)\n\t\t{\n\t\tint seen = 0;\n\t\tBIO_printf(sbio,"<stream:stream "\n\t\t    "xmlns:stream=\'http://etherx.jabber.org/streams\' "\n\t\t    "xmlns=\'jabber:client\' to=\'%s\' version=\'1.0\'>", xmpphost ?\n\t\t\t   xmpphost : host);\n\t\tseen = BIO_read(sbio,mbuf,BUFSIZZ);\n\t\tmbuf[seen] = 0;\n\t\twhile (!strstr(mbuf, "<starttls xmlns=\'urn:ietf:params:xml:ns:xmpp-tls\'") &&\n\t\t\t\t!strstr(mbuf, "<starttls xmlns=\\"urn:ietf:params:xml:ns:xmpp-tls\\""))\n\t\t\t{\n\t\t\tseen = BIO_read(sbio,mbuf,BUFSIZZ);\n\t\t\tif (seen <= 0)\n\t\t\t\tgoto shut;\n\t\t\tmbuf[seen] = 0;\n\t\t\t}\n\t\tBIO_printf(sbio, "<starttls xmlns=\'urn:ietf:params:xml:ns:xmpp-tls\'/>");\n\t\tseen = BIO_read(sbio,sbuf,BUFSIZZ);\n\t\tsbuf[seen] = 0;\n\t\tif (!strstr(sbuf, "<proceed"))\n\t\t\tgoto shut;\n\t\tmbuf[0] = 0;\n\t\t}\n\tfor (;;)\n\t\t{\n\t\tFD_ZERO(&readfds);\n\t\tFD_ZERO(&writefds);\n\t\tif ((SSL_version(con) == DTLS1_VERSION) &&\n\t\t\tDTLSv1_get_timeout(con, &timeout))\n\t\t\ttimeoutp = &timeout;\n\t\telse\n\t\t\ttimeoutp = NULL;\n\t\tif (SSL_in_init(con) && !SSL_total_renegotiations(con))\n\t\t\t{\n\t\t\tin_init=1;\n\t\t\ttty_on=0;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\ttty_on=1;\n\t\t\tif (in_init)\n\t\t\t\t{\n\t\t\t\tin_init=0;\n#if 0\n#ifndef OPENSSL_NO_TLSEXT\n\t\t\t\tif (servername != NULL && !SSL_session_reused(con))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_c_out,"Server did %sacknowledge servername extension.\\n",tlsextcbp.ack?"":"not ");\n\t\t\t\t\t}\n#endif\n#endif\n\t\t\t\tif (sess_out)\n\t\t\t\t\t{\n\t\t\t\t\tBIO *stmp = BIO_new_file(sess_out, "w");\n\t\t\t\t\tif (stmp)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tPEM_write_bio_SSL_SESSION(stmp, SSL_get_session(con));\n\t\t\t\t\t\tBIO_free(stmp);\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\tBIO_printf(bio_err, "Error writing session file %s\\n", sess_out);\n\t\t\t\t\t}\n\t\t\t\tif (c_brief)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_puts(bio_err,\n\t\t\t\t\t\t"CONNECTION ESTABLISHED\\n");\n\t\t\t\t\tprint_ssl_summary(bio_err, con);\n\t\t\t\t\t}\n\t\t\t\tif (generated_supp_data)\n\t\t\t\t\t{\n\t\t\t\t\tOPENSSL_free(generated_supp_data);\n\t\t\t\t\tgenerated_supp_data = NULL;\n\t\t\t\t\t}\n\t\t\t\tprint_stuff(bio_c_out,con,full_log);\n\t\t\t\tif (full_log > 0) full_log--;\n\t\t\t\tif (starttls_proto)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"%s",mbuf);\n\t\t\t\t\tstarttls_proto = PROTO_OFF;\n\t\t\t\t\t}\n\t\t\t\tif (reconnect)\n\t\t\t\t\t{\n\t\t\t\t\treconnect--;\n\t\t\t\t\tBIO_printf(bio_c_out,"drop connection and then reconnect\\n");\n\t\t\t\t\tSSL_shutdown(con);\n\t\t\t\t\tSSL_set_connect_state(con);\n\t\t\t\t\tSHUTDOWN(SSL_get_fd(con));\n\t\t\t\t\tgoto re_start;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\tssl_pending = read_ssl && SSL_pending(con);\n\t\tif (!ssl_pending)\n\t\t\t{\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE) && !defined (OPENSSL_SYS_BEOS_R5)\n\t\t\tif (tty_on)\n\t\t\t\t{\n\t\t\t\tif (read_tty)  openssl_fdset(fileno(stdin),&readfds);\n\t\t\t\tif (write_tty) openssl_fdset(fileno(stdout),&writefds);\n\t\t\t\t}\n\t\t\tif (read_ssl)\n\t\t\t\topenssl_fdset(SSL_get_fd(con),&readfds);\n\t\t\tif (write_ssl)\n\t\t\t\topenssl_fdset(SSL_get_fd(con),&writefds);\n#else\n\t\t\tif(!tty_on || !write_tty) {\n\t\t\t\tif (read_ssl)\n\t\t\t\t\topenssl_fdset(SSL_get_fd(con),&readfds);\n\t\t\t\tif (write_ssl)\n\t\t\t\t\topenssl_fdset(SSL_get_fd(con),&writefds);\n\t\t\t}\n#endif\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n\t\t\ti=0;\n\t\t\tif(!write_tty) {\n\t\t\t\tif(read_tty) {\n\t\t\t\t\ttv.tv_sec = 1;\n\t\t\t\t\ttv.tv_usec = 0;\n\t\t\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t\t NULL,&tv);\n#if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)\n\t\t\t\t\tif(!i && (!_kbhit() || !read_tty) ) continue;\n#else\n\t\t\t\t\tif(!i && (!((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0))) || !read_tty) ) continue;\n#endif\n\t\t\t\t} else \ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t NULL,timeoutp);\n\t\t\t}\n#elif defined(OPENSSL_SYS_NETWARE)\n\t\t\tif(!write_tty) {\n\t\t\t\tif(read_tty) {\n\t\t\t\t\ttv.tv_sec = 1;\n\t\t\t\t\ttv.tv_usec = 0;\n\t\t\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t\tNULL,&tv);\n\t\t\t\t} else \ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\tNULL,timeoutp);\n\t\t\t}\n#elif defined(OPENSSL_SYS_BEOS_R5)\n\t\t\ti=0;\n\t\t\tstdin_set = 0;\n\t\t\t(void)fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);\n\t\t\tif(!write_tty) {\n\t\t\t\tif(read_tty) {\n\t\t\t\t\ttv.tv_sec = 1;\n\t\t\t\t\ttv.tv_usec = 0;\n\t\t\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t\t NULL,&tv);\n\t\t\t\t\tif (read(fileno(stdin), sbuf, 0) >= 0)\n\t\t\t\t\t\tstdin_set = 1;\n\t\t\t\t\tif (!i && (stdin_set != 1 || !read_tty))\n\t\t\t\t\t\tcontinue;\n\t\t\t\t} else \ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t\t NULL,timeoutp);\n\t\t\t}\n\t\t\t(void)fcntl(fileno(stdin), F_SETFL, 0);\n#else\n\t\t\ti=select(width,(void *)&readfds,(void *)&writefds,\n\t\t\t\t NULL,timeoutp);\n#endif\n\t\t\tif ( i < 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"bad select %d\\n",\n\t\t\t\tget_last_socket_error());\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n\t\tif ((SSL_version(con) == DTLS1_VERSION) && DTLSv1_handle_timeout(con) > 0)\n\t\t\t{\n\t\t\tBIO_printf(bio_err,"TIMEOUT occurred\\n");\n\t\t\t}\n\t\tif (!ssl_pending && FD_ISSET(SSL_get_fd(con),&writefds))\n\t\t\t{\n\t\t\tk=SSL_write(con,&(cbuf[cbuf_off]),\n\t\t\t\t(unsigned int)cbuf_len);\n\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t{\n\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\tcbuf_off+=k;\n\t\t\t\tcbuf_len-=k;\n\t\t\t\tif (k <= 0) goto end;\n\t\t\t\tif (cbuf_len <= 0)\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=0;\n\t\t\t\t\twrite_ssl=1;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tBIO_printf(bio_c_out,"write W BLOCK\\n");\n\t\t\t\twrite_ssl=1;\n\t\t\t\tread_tty=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tBIO_printf(bio_c_out,"write R BLOCK\\n");\n\t\t\t\twrite_tty=0;\n\t\t\t\tread_ssl=1;\n\t\t\t\twrite_ssl=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\tBIO_printf(bio_c_out,"write X BLOCK\\n");\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\tif (cbuf_len != 0)\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_c_out,"shutdown\\n");\n\t\t\t\t\tret = 0;\n\t\t\t\t\tgoto shut;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tif ((k != 0) || (cbuf_len != 0))\n\t\t\t\t\t{\n\t\t\t\t\tBIO_printf(bio_err,"write:errno=%d\\n",\n\t\t\t\t\t\tget_last_socket_error());\n\t\t\t\t\tgoto shut;\n\t\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\tread_tty=1;\n\t\t\t\t\twrite_ssl=0;\n\t\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE) || defined(OPENSSL_SYS_BEOS_R5)\n\t\telse if (!ssl_pending && write_tty)\n#else\n\t\telse if (!ssl_pending && FD_ISSET(fileno(stdout),&writefds))\n#endif\n\t\t\t{\n#ifdef CHARSET_EBCDIC\n\t\t\tascii2ebcdic(&(sbuf[sbuf_off]),&(sbuf[sbuf_off]),sbuf_len);\n#endif\n\t\t\ti=raw_write_stdout(&(sbuf[sbuf_off]),sbuf_len);\n\t\t\tif (i <= 0)\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_c_out,"DONE\\n");\n\t\t\t\tret = 0;\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\tsbuf_len-=i;;\n\t\t\tsbuf_off+=i;\n\t\t\tif (sbuf_len <= 0)\n\t\t\t\t{\n\t\t\t\tread_ssl=1;\n\t\t\t\twrite_tty=0;\n\t\t\t\t}\n\t\t\t}\n\t\telse if (ssl_pending || FD_ISSET(SSL_get_fd(con),&readfds))\n\t\t\t{\n#ifdef RENEG\n{ static int iiii; if (++iiii == 52) { SSL_renegotiate(con); iiii=0; } }\n#endif\n#if 1\n\t\t\tk=SSL_read(con,sbuf,1024   );\n#else\n\t\t\tk=SSL_read(con,sbuf,16);\n{ char zbuf[10240];\nprintf("read=%d pending=%d peek=%d\\n",k,SSL_pending(con),SSL_peek(con,zbuf,10240));\n}\n#endif\n\t\t\tswitch (SSL_get_error(con,k))\n\t\t\t\t{\n\t\t\tcase SSL_ERROR_NONE:\n\t\t\t\tif (k <= 0)\n\t\t\t\t\tgoto end;\n\t\t\t\tsbuf_off=0;\n\t\t\t\tsbuf_len=k;\n\t\t\t\tread_ssl=0;\n\t\t\t\twrite_tty=1;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_WRITE:\n\t\t\t\tBIO_printf(bio_c_out,"read W BLOCK\\n");\n\t\t\t\twrite_ssl=1;\n\t\t\t\tread_tty=0;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_READ:\n\t\t\t\tBIO_printf(bio_c_out,"read R BLOCK\\n");\n\t\t\t\twrite_tty=0;\n\t\t\t\tread_ssl=1;\n\t\t\t\tif ((read_tty == 0) && (write_ssl == 0))\n\t\t\t\t\twrite_ssl=1;\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_WANT_X509_LOOKUP:\n\t\t\t\tBIO_printf(bio_c_out,"read X BLOCK\\n");\n\t\t\t\tbreak;\n\t\t\tcase SSL_ERROR_SYSCALL:\n\t\t\t\tret=get_last_socket_error();\n\t\t\t\tif (c_brief)\n\t\t\t\t\tBIO_puts(bio_err, "CONNECTION CLOSED BY SERVER\\n");\n\t\t\t\telse\n\t\t\t\t\tBIO_printf(bio_err,"read:errno=%d\\n",ret);\n\t\t\t\tgoto shut;\n\t\t\tcase SSL_ERROR_ZERO_RETURN:\n\t\t\t\tBIO_printf(bio_c_out,"closed\\n");\n\t\t\t\tret=0;\n\t\t\t\tgoto shut;\n\t\t\tcase SSL_ERROR_SSL:\n\t\t\t\tERR_print_errors(bio_err);\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\t}\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n#if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)\n\t\telse if (_kbhit())\n#else\n\t\telse if ((_kbhit()) || (WAIT_OBJECT_0 == WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))\n#endif\n#elif defined (OPENSSL_SYS_NETWARE)\n\t\telse if (_kbhit())\n#elif defined(OPENSSL_SYS_BEOS_R5)\n\t\telse if (stdin_set)\n#else\n\t\telse if (FD_ISSET(fileno(stdin),&readfds))\n#endif\n\t\t\t{\n\t\t\tif (crlf)\n\t\t\t\t{\n\t\t\t\tint j, lf_num;\n\t\t\t\ti=raw_read_stdin(cbuf,BUFSIZZ/2);\n\t\t\t\tlf_num = 0;\n\t\t\t\tfor (j = 0; j < i; j++)\n\t\t\t\t\tif (cbuf[j] == \'\\n\')\n\t\t\t\t\t\tlf_num++;\n\t\t\t\tfor (j = i-1; j >= 0; j--)\n\t\t\t\t\t{\n\t\t\t\t\tcbuf[j+lf_num] = cbuf[j];\n\t\t\t\t\tif (cbuf[j] == \'\\n\')\n\t\t\t\t\t\t{\n\t\t\t\t\t\tlf_num--;\n\t\t\t\t\t\ti++;\n\t\t\t\t\t\tcbuf[j+lf_num] = \'\\r\';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tassert(lf_num == 0);\n\t\t\t\t}\n\t\t\telse\n\t\t\t\ti=raw_read_stdin(cbuf,BUFSIZZ);\n\t\t\tif ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == \'Q\')))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"DONE\\n");\n\t\t\t\tret=0;\n\t\t\t\tgoto shut;\n\t\t\t\t}\n\t\t\tif ((!c_ign_eof) && (cbuf[0] == \'R\'))\n\t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"RENEGOTIATING\\n");\n\t\t\t\tSSL_renegotiate(con);\n\t\t\t\tcbuf_len=0;\n\t\t\t\t}\n#ifndef OPENSSL_NO_HEARTBEATS\n\t\t\telse if ((!c_ign_eof) && (cbuf[0] == \'B\'))\n \t\t\t\t{\n\t\t\t\tBIO_printf(bio_err,"HEARTBEATING\\n");\n\t\t\t\tSSL_heartbeat(con);\n\t\t\t\tcbuf_len=0;\n\t\t\t\t}\n#endif\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tcbuf_len=i;\n\t\t\t\tcbuf_off=0;\n#ifdef CHARSET_EBCDIC\n\t\t\t\tebcdic2ascii(cbuf, cbuf, i);\n#endif\n\t\t\t\t}\n\t\t\twrite_ssl=1;\n\t\t\tread_tty=0;\n\t\t\t}\n\t\t}\n\tret=0;\nshut:\n\tif (in_init)\n\t\tprint_stuff(bio_c_out,con,full_log);\n\tSSL_shutdown(con);\n\tSHUTDOWN(SSL_get_fd(con));\nend:\n\tif (con != NULL)\n\t\t{\n\t\tif (prexit != 0)\n\t\t\tprint_stuff(bio_c_out,con,1);\n\t\tSSL_free(con);\n\t\t}\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n\tif (next_proto.data)\n\t\tOPENSSL_free(next_proto.data);\n#endif\n\tif (ctx != NULL) SSL_CTX_free(ctx);\n\tif (cert)\n\t\tX509_free(cert);\n\tif (crls)\n\t\tsk_X509_CRL_pop_free(crls, X509_CRL_free);\n\tif (key)\n\t\tEVP_PKEY_free(key);\n\tif (chain)\n\t\tsk_X509_pop_free(chain, X509_free);\n\tif (pass)\n\t\tOPENSSL_free(pass);\n\tif (vpm)\n\t\tX509_VERIFY_PARAM_free(vpm);\n\tssl_excert_free(exc);\n\tif (ssl_args)\n\t\tsk_OPENSSL_STRING_free(ssl_args);\n\tif (cctx)\n\t\tSSL_CONF_CTX_free(cctx);\n#ifndef OPENSSL_NO_JPAKE\n\tif (jpake_secret && psk_key)\n\t\tOPENSSL_free(psk_key);\n#endif\n\tif (cbuf != NULL) { OPENSSL_cleanse(cbuf,BUFSIZZ); OPENSSL_free(cbuf); }\n\tif (sbuf != NULL) { OPENSSL_cleanse(sbuf,BUFSIZZ); OPENSSL_free(sbuf); }\n\tif (mbuf != NULL) { OPENSSL_cleanse(mbuf,BUFSIZZ); OPENSSL_free(mbuf); }\n\tif (bio_c_out != NULL)\n\t\t{\n\t\tBIO_free(bio_c_out);\n\t\tbio_c_out=NULL;\n\t\t}\n\tif (bio_c_msg != NULL)\n\t\t{\n\t\tBIO_free(bio_c_msg);\n\t\tbio_c_msg=NULL;\n\t\t}\n\tapps_shutdown();\n\tOPENSSL_EXIT(ret);\n\t}', 'int SSL_CTX_set_srp_strength(SSL_CTX *ctx, int strength)\n\t{\n\treturn tls1_ctx_ctrl(ctx, SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH, strength,\n\t\t\t     NULL);\n\t}', 'long ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)\n\t{\n\tCERT *cert;\n\tcert=ctx->cert;\n\tswitch (cmd)\n\t\t{\n#ifndef OPENSSL_NO_RSA\n\tcase SSL_CTRL_NEED_TMP_RSA:\n\t\tif (\t(cert->rsa_tmp == NULL) &&\n\t\t\t((cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||\n\t\t\t (EVP_PKEY_size(cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > (512/8)))\n\t\t\t)\n\t\t\treturn(1);\n\t\telse\n\t\t\treturn(0);\n\tcase SSL_CTRL_SET_TMP_RSA:\n\t\t{\n\t\tRSA *rsa;\n\t\tint i;\n\t\trsa=(RSA *)parg;\n\t\ti=1;\n\t\tif (rsa == NULL)\n\t\t\ti=0;\n\t\telse\n\t\t\t{\n\t\t\tif ((rsa=RSAPrivateKey_dup(rsa)) == NULL)\n\t\t\t\ti=0;\n\t\t\t}\n\t\tif (!i)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_RSA_LIB);\n\t\t\treturn(0);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (cert->rsa_tmp != NULL)\n\t\t\t\tRSA_free(cert->rsa_tmp);\n\t\t\tcert->rsa_tmp=rsa;\n\t\t\treturn(1);\n\t\t\t}\n\t\t}\n\tcase SSL_CTRL_SET_TMP_RSA_CB:\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn(0);\n\t\t}\n\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_DH\n\tcase SSL_CTRL_SET_TMP_DH:\n\t\t{\n\t\tDH *new=NULL,*dh;\n\t\tdh=(DH *)parg;\n\t\tif (!ssl_ctx_security(ctx, SSL_SECOP_TMP_DH,\n\t\t\t\t\t\tDH_security_bits(dh), 0, dh))\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_DH_KEY_TOO_SMALL);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif ((new=DHparams_dup(dh)) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif (!(ctx->options & SSL_OP_SINGLE_DH_USE))\n\t\t\t{\n\t\t\tif (!DH_generate_key(new))\n\t\t\t\t{\n\t\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_DH_LIB);\n\t\t\t\tDH_free(new);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\tif (cert->dh_tmp != NULL)\n\t\t\tDH_free(cert->dh_tmp);\n\t\tcert->dh_tmp=new;\n\t\treturn 1;\n\t\t}\n\tcase SSL_CTRL_SET_TMP_DH_CB:\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn(0);\n\t\t}\n\t\tbreak;\n\tcase SSL_CTRL_SET_DH_AUTO:\n\t\tctx->cert->dh_tmp_auto = larg;\n\t\treturn 1;\n#endif\n#ifndef OPENSSL_NO_ECDH\n\tcase SSL_CTRL_SET_TMP_ECDH:\n\t\t{\n\t\tEC_KEY *ecdh = NULL;\n\t\tif (parg == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB);\n\t\t\treturn 0;\n\t\t\t}\n\t\tecdh = EC_KEY_dup((EC_KEY *)parg);\n\t\tif (ecdh == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_EC_LIB);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif (!(ctx->options & SSL_OP_SINGLE_ECDH_USE))\n\t\t\t{\n\t\t\tif (!EC_KEY_generate_key(ecdh))\n\t\t\t\t{\n\t\t\t\tEC_KEY_free(ecdh);\n\t\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL,ERR_R_ECDH_LIB);\n\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t}\n\t\tif (cert->ecdh_tmp != NULL)\n\t\t\t{\n\t\t\tEC_KEY_free(cert->ecdh_tmp);\n\t\t\t}\n\t\tcert->ecdh_tmp = ecdh;\n\t\treturn 1;\n\t\t}\n\tcase SSL_CTRL_SET_TMP_ECDH_CB:\n\t\t{\n\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n\t\treturn(0);\n\t\t}\n\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n\tcase SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG:\n\t\tctx->tlsext_servername_arg=parg;\n\t\tbreak;\n\tcase SSL_CTRL_SET_TLSEXT_TICKET_KEYS:\n\tcase SSL_CTRL_GET_TLSEXT_TICKET_KEYS:\n\t\t{\n\t\tunsigned char *keys = parg;\n\t\tif (!keys)\n\t\t\treturn 48;\n\t\tif (larg != 48)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_TICKET_KEYS_LENGTH);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif (cmd == SSL_CTRL_SET_TLSEXT_TICKET_KEYS)\n\t\t\t{\n\t\t\tmemcpy(ctx->tlsext_tick_key_name, keys, 16);\n\t\t\tmemcpy(ctx->tlsext_tick_hmac_key, keys + 16, 16);\n\t\t\tmemcpy(ctx->tlsext_tick_aes_key, keys + 32, 16);\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tmemcpy(keys, ctx->tlsext_tick_key_name, 16);\n\t\t\tmemcpy(keys + 16, ctx->tlsext_tick_hmac_key, 16);\n\t\t\tmemcpy(keys + 32, ctx->tlsext_tick_aes_key, 16);\n\t\t\t}\n\t\treturn 1;\n\t\t}\n#ifdef TLSEXT_TYPE_opaque_prf_input\n\tcase SSL_CTRL_SET_TLSEXT_OPAQUE_PRF_INPUT_CB_ARG:\n\t\tctx->tlsext_opaque_prf_input_callback_arg = parg;\n\t\treturn 1;\n#endif\n\tcase SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG:\n\t\tctx->tlsext_status_arg=parg;\n\t\treturn 1;\n\t\tbreak;\n#ifndef OPENSSL_NO_SRP\n\tcase SSL_CTRL_SET_TLS_EXT_SRP_USERNAME:\n\t\tctx->srp_ctx.srp_Mask|=SSL_kSRP;\n\t\tif (ctx->srp_ctx.login != NULL)\n\t\t\tOPENSSL_free(ctx->srp_ctx.login);\n\t\tctx->srp_ctx.login = NULL;\n\t\tif (parg == NULL)\n\t\t\tbreak;\n\t\tif (strlen((const char *)parg) > 255 || strlen((const char *)parg) < 1)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, SSL_R_INVALID_SRP_USERNAME);\n\t\t\treturn 0;\n\t\t\t}\n\t\tif ((ctx->srp_ctx.login = BUF_strdup((char *)parg)) == NULL)\n\t\t\t{\n\t\t\tSSLerr(SSL_F_SSL3_CTX_CTRL, ERR_R_INTERNAL_ERROR);\n\t\t\treturn 0;\n\t\t\t}\n\t\tbreak;\n\tcase SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD:\n\t\tctx->srp_ctx.SRP_give_srp_client_pwd_callback=srp_password_from_info_cb;\n\t\tctx->srp_ctx.info=parg;\n\t\tbreak;\n\tcase SSL_CTRL_SET_SRP_ARG:\n\t\tctx->srp_ctx.srp_Mask|=SSL_kSRP;\n\t\tctx->srp_ctx.SRP_cb_arg=parg;\n\t\tbreak;\n\tcase SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH:\n\t\tctx->srp_ctx.strength=larg;\n\t\tbreak;\n#endif\n#ifndef OPENSSL_NO_EC\n\tcase SSL_CTRL_SET_CURVES:\n\t\treturn tls1_set_curves(&ctx->tlsext_ellipticcurvelist,\n\t\t\t\t\t&ctx->tlsext_ellipticcurvelist_length,\n\t\t\t\t\t\t\t\tparg, larg);\n\tcase SSL_CTRL_SET_CURVES_LIST:\n\t\treturn tls1_set_curves_list(&ctx->tlsext_ellipticcurvelist,\n\t\t\t\t\t&ctx->tlsext_ellipticcurvelist_length,\n\t\t\t\t\t\t\t\tparg);\n\tcase SSL_CTRL_SET_ECDH_AUTO:\n\t\tctx->cert->ecdh_tmp_auto = larg;\n\t\treturn 1;\n#endif\n\tcase SSL_CTRL_SET_SIGALGS:\n\t\treturn tls1_set_sigalgs(ctx->cert, parg, larg, 0);\n\tcase SSL_CTRL_SET_SIGALGS_LIST:\n\t\treturn tls1_set_sigalgs_list(ctx->cert, parg, 0);\n\tcase SSL_CTRL_SET_CLIENT_SIGALGS:\n\t\treturn tls1_set_sigalgs(ctx->cert, parg, larg, 1);\n\tcase SSL_CTRL_SET_CLIENT_SIGALGS_LIST:\n\t\treturn tls1_set_sigalgs_list(ctx->cert, parg, 1);\n\tcase SSL_CTRL_SET_CLIENT_CERT_TYPES:\n\t\treturn ssl3_set_req_cert_type(ctx->cert, parg, larg);\n\tcase SSL_CTRL_BUILD_CERT_CHAIN:\n\t\treturn ssl_build_cert_chain(NULL, ctx, larg);\n\tcase SSL_CTRL_SET_VERIFY_CERT_STORE:\n\t\treturn ssl_cert_set_cert_store(ctx->cert, parg, 0, larg);\n\tcase SSL_CTRL_SET_CHAIN_CERT_STORE:\n\t\treturn ssl_cert_set_cert_store(ctx->cert, parg, 1, larg);\n#endif\n\tcase SSL_CTRL_EXTRA_CHAIN_CERT:\n\t\tif (ctx->extra_certs == NULL)\n\t\t\t{\n\t\t\tif ((ctx->extra_certs=sk_X509_new_null()) == NULL)\n\t\t\t\treturn(0);\n\t\t\t}\n\t\tsk_X509_push(ctx->extra_certs,(X509 *)parg);\n\t\tbreak;\n\tcase SSL_CTRL_GET_EXTRA_CHAIN_CERTS:\n\t\tif (ctx->extra_certs == NULL && larg == 0)\n\t\t\t*(STACK_OF(X509) **)parg =  ctx->cert->key->chain;\n\t\telse\n\t\t\t*(STACK_OF(X509) **)parg =  ctx->extra_certs;\n\t\tbreak;\n\tcase SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS:\n\t\tif (ctx->extra_certs)\n\t\t\t{\n\t\t\tsk_X509_pop_free(ctx->extra_certs, X509_free);\n\t\t\tctx->extra_certs = NULL;\n\t\t\t}\n\t\tbreak;\n\tcase SSL_CTRL_CHAIN:\n\t\tif (larg)\n\t\t\treturn ssl_cert_set1_chain(NULL, ctx,\n\t\t\t\t\t\t(STACK_OF (X509) *)parg);\n\t\telse\n\t\t\treturn ssl_cert_set0_chain(NULL, ctx,\n\t\t\t\t\t\t(STACK_OF (X509) *)parg);\n\tcase SSL_CTRL_CHAIN_CERT:\n\t\tif (larg)\n\t\t\treturn ssl_cert_add1_chain_cert(NULL, ctx, (X509 *)parg);\n\t\telse\n\t\t\treturn ssl_cert_add0_chain_cert(NULL, ctx, (X509 *)parg);\n\tcase SSL_CTRL_GET_CHAIN_CERTS:\n\t\t*(STACK_OF(X509) **)parg = ctx->cert->key->chain;\n\t\tbreak;\n\tcase SSL_CTRL_SELECT_CURRENT_CERT:\n\t\treturn ssl_cert_select_current(ctx->cert, (X509 *)parg);\n\tcase SSL_CTRL_SET_CURRENT_CERT:\n\t\treturn ssl_cert_set_current(ctx->cert, larg);\n\tdefault:\n\t\treturn(0);\n\t\t}\n\treturn(1);\n\t}', 'DH *DHparams_dup(DH *dh)\n\t{\n\tDH *ret;\n\tret = DH_new();\n\tif (!ret)\n\t\treturn NULL;\n\tif (!int_dh_param_copy(ret, dh, -1))\n\t\t{\n\t\tDH_free(ret);\n\t\treturn NULL;\n\t\t}\n\treturn ret;\n\t}', 'DH *DH_new(void)\n\t{\n\treturn DH_new_method(NULL);\n\t}', 'DH *DH_new_method(ENGINE *engine)\n\t{\n\tDH *ret;\n\tret=(DH *)OPENSSL_malloc(sizeof(DH));\n\tif (ret == NULL)\n\t\t{\n\t\tDHerr(DH_F_DH_NEW_METHOD,ERR_R_MALLOC_FAILURE);\n\t\treturn(NULL);\n\t\t}\n\tret->meth = DH_get_default_method();\n#ifndef OPENSSL_NO_ENGINE\n\tif (engine)\n\t\t{\n\t\tif (!ENGINE_init(engine))\n\t\t\t{\n\t\t\tDHerr(DH_F_DH_NEW_METHOD, ERR_R_ENGINE_LIB);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\tret->engine = engine;\n\t\t}\n\telse\n\t\tret->engine = ENGINE_get_default_DH();\n\tif(ret->engine)\n\t\t{\n\t\tret->meth = ENGINE_get_DH(ret->engine);\n\t\tif(!ret->meth)\n\t\t\t{\n\t\t\tDHerr(DH_F_DH_NEW_METHOD,ERR_R_ENGINE_LIB);\n\t\t\tENGINE_finish(ret->engine);\n\t\t\tOPENSSL_free(ret);\n\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n#endif\n\tret->pad=0;\n\tret->version=0;\n\tret->p=NULL;\n\tret->g=NULL;\n\tret->length=0;\n\tret->pub_key=NULL;\n\tret->priv_key=NULL;\n\tret->q=NULL;\n\tret->j=NULL;\n\tret->seed = NULL;\n\tret->seedlen = 0;\n\tret->counter = NULL;\n\tret->method_mont_p=NULL;\n\tret->references = 1;\n\tret->flags=ret->meth->flags;\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);\n\tif ((ret->meth->init != NULL) && !ret->meth->init(ret))\n\t\t{\n#ifndef OPENSSL_NO_ENGINE\n\t\tif (ret->engine)\n\t\t\tENGINE_finish(ret->engine);\n#endif\n\t\tCRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data);\n\t\tOPENSSL_free(ret);\n\t\tret=NULL;\n\t\t}\n\treturn(ret);\n\t}', 'ENGINE *ENGINE_get_default_DH(void)\n\t{\n\treturn engine_table_select(&dh_table, dummy_nid);\n\t}', 'ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)\n#else\nENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l)\n#endif\n\t{\n\tENGINE *ret = NULL;\n\tENGINE_PILE tmplate, *fnd=NULL;\n\tint initres, loop = 0;\n\tif(!(*table))\n\t\t{\n#ifdef ENGINE_TABLE_DEBUG\n\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing "\n\t\t\t"registered!\\n", f, l, nid);\n#endif\n\t\treturn NULL;\n\t\t}\n\tERR_set_mark();\n\tCRYPTO_w_lock(CRYPTO_LOCK_ENGINE);\n\tif(!int_table_check(table, 0)) goto end;\n\ttmplate.nid = nid;\n\tfnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate);\n\tif(!fnd) goto end;\n\tif(fnd->funct && engine_unlocked_init(fnd->funct))\n\t\t{\n#ifdef ENGINE_TABLE_DEBUG\n\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n\t\t\t"ENGINE \'%s\' cached\\n", f, l, nid, fnd->funct->id);\n#endif\n\t\tret = fnd->funct;\n\t\tgoto end;\n\t\t}\n\tif(fnd->uptodate)\n\t\t{\n\t\tret = fnd->funct;\n\t\tgoto end;\n\t\t}\ntrynext:\n\tret = sk_ENGINE_value(fnd->sk, loop++);\n\tif(!ret)\n\t\t{\n#ifdef ENGINE_TABLE_DEBUG\n\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "\n\t\t\t\t"registered implementations would initialise\\n",\n\t\t\t\tf, l, nid);\n#endif\n\t\tgoto end;\n\t\t}\n\tif((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))\n\t\tinitres = engine_unlocked_init(ret);\n\telse\n\t\tinitres = 0;\n\tif(initres)\n\t\t{\n\t\tif((fnd->funct != ret) && engine_unlocked_init(ret))\n\t\t\t{\n\t\t\tif(fnd->funct)\n\t\t\t\tengine_unlocked_finish(fnd->funct, 0);\n\t\t\tfnd->funct = ret;\n#ifdef ENGINE_TABLE_DEBUG\n\t\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "\n\t\t\t\t"setting default to \'%s\'\\n", f, l, nid, ret->id);\n#endif\n\t\t\t}\n#ifdef ENGINE_TABLE_DEBUG\n\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using "\n\t\t\t\t"newly initialised \'%s\'\\n", f, l, nid, ret->id);\n#endif\n\t\tgoto end;\n\t\t}\n\tgoto trynext;\nend:\n\tif(fnd) fnd->uptodate = 1;\n#ifdef ENGINE_TABLE_DEBUG\n\tif(ret)\n\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n\t\t\t\t"ENGINE \'%s\'\\n", f, l, nid, ret->id);\n\telse\n\t\tfprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "\n\t\t\t\t"\'no matching ENGINE\'\\n", f, l, nid);\n#endif\n\tCRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);\n\tERR_pop_to_mark();\n\treturn ret;\n\t}', 'static int int_table_check(ENGINE_TABLE **t, int create)\n\t{\n\tLHASH_OF(ENGINE_PILE) *lh;\n\tif(*t) return 1;\n\tif(!create) return 0;\n\tif((lh = lh_ENGINE_PILE_new()) == NULL)\n\t\treturn 0;\n\t*t = (ENGINE_TABLE *)lh;\n\treturn 1;\n\t}', '_LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)\n\t{\n\t_LHASH *ret;\n\tint i;\n\tif ((ret=OPENSSL_malloc(sizeof(_LHASH))) == NULL)\n\t\tgoto err0;\n\tif ((ret->b=OPENSSL_malloc(sizeof(LHASH_NODE *)*MIN_NODES)) == NULL)\n\t\tgoto err1;\n\tfor (i=0; i<MIN_NODES; i++)\n\t\tret->b[i]=NULL;\n\tret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);\n\tret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);\n\tret->num_nodes=MIN_NODES/2;\n\tret->num_alloc_nodes=MIN_NODES;\n\tret->p=0;\n\tret->pmax=MIN_NODES/2;\n\tret->up_load=UP_LOAD;\n\tret->down_load=DOWN_LOAD;\n\tret->num_items=0;\n\tret->num_expands=0;\n\tret->num_expand_reallocs=0;\n\tret->num_contracts=0;\n\tret->num_contract_reallocs=0;\n\tret->num_hash_calls=0;\n\tret->num_comp_calls=0;\n\tret->num_insert=0;\n\tret->num_replace=0;\n\tret->num_delete=0;\n\tret->num_no_delete=0;\n\tret->num_retrieve=0;\n\tret->num_retrieve_miss=0;\n\tret->num_hash_comps=0;\n\tret->error=0;\n\treturn(ret);\nerr1:\n\tOPENSSL_free(ret);\nerr0:\n\treturn(NULL);\n\t}', 'SSL *SSL_new(SSL_CTX *ctx)\n\t{\n\tSSL *s;\n\tif (ctx == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_NULL_SSL_CTX);\n\t\treturn(NULL);\n\t\t}\n\tif (ctx->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_NEW,SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);\n\t\treturn(NULL);\n\t\t}\n\ts=(SSL *)OPENSSL_malloc(sizeof(SSL));\n\tif (s == NULL) goto err;\n\tmemset(s,0,sizeof(SSL));\n#ifndef\tOPENSSL_NO_KRB5\n\ts->kssl_ctx = kssl_ctx_new();\n#endif\n\ts->options=ctx->options;\n\ts->mode=ctx->mode;\n\ts->max_cert_list=ctx->max_cert_list;\n\tif (ctx->cert != NULL)\n\t\t{\n\t\ts->cert = ssl_cert_dup(ctx->cert);\n\t\tif (s->cert == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\ts->cert=NULL;\n\ts->read_ahead=ctx->read_ahead;\n\ts->msg_callback=ctx->msg_callback;\n\ts->msg_callback_arg=ctx->msg_callback_arg;\n\ts->verify_mode=ctx->verify_mode;\n\ts->not_resumable_session_cb=ctx->not_resumable_session_cb;\n#if 0\n\ts->verify_depth=ctx->verify_depth;\n#endif\n\ts->sid_ctx_length=ctx->sid_ctx_length;\n\tOPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);\n\tmemcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx));\n\ts->verify_callback=ctx->default_verify_callback;\n\ts->generate_session_id=ctx->generate_session_id;\n\ts->param = X509_VERIFY_PARAM_new();\n\tif (!s->param)\n\t\tgoto err;\n\tX509_VERIFY_PARAM_inherit(s->param, ctx->param);\n#if 0\n\ts->purpose = ctx->purpose;\n\ts->trust = ctx->trust;\n#endif\n\ts->quiet_shutdown=ctx->quiet_shutdown;\n\ts->max_send_fragment = ctx->max_send_fragment;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->ctx=ctx;\n#ifndef OPENSSL_NO_TLSEXT\n\ts->tlsext_debug_cb = 0;\n\ts->tlsext_debug_arg = NULL;\n\ts->tlsext_ticket_expected = 0;\n\ts->tlsext_status_type = -1;\n\ts->tlsext_status_expected = 0;\n\ts->tlsext_ocsp_ids = NULL;\n\ts->tlsext_ocsp_exts = NULL;\n\ts->tlsext_ocsp_resp = NULL;\n\ts->tlsext_ocsp_resplen = -1;\n\tCRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX);\n\ts->initial_ctx=ctx;\n#ifndef OPENSSL_NO_EC\n\tif (ctx->tlsext_ecpointformatlist)\n\t\t{\n\t\ts->tlsext_ecpointformatlist =\n\t\t\tBUF_memdup(ctx->tlsext_ecpointformatlist,\n\t\t\t\t\tctx->tlsext_ecpointformatlist_length);\n\t\tif (!s->tlsext_ecpointformatlist)\n\t\t\tgoto err;\n\t\ts->tlsext_ecpointformatlist_length =\n\t\t\t\t\tctx->tlsext_ecpointformatlist_length;\n\t\t}\n\tif (ctx->tlsext_ellipticcurvelist)\n\t\t{\n\t\ts->tlsext_ellipticcurvelist =\n\t\t\tBUF_memdup(ctx->tlsext_ellipticcurvelist,\n\t\t\t\t\tctx->tlsext_ellipticcurvelist_length);\n\t\tif (!s->tlsext_ellipticcurvelist)\n\t\t\tgoto err;\n\t\ts->tlsext_ellipticcurvelist_length =\n\t\t\t\t\tctx->tlsext_ellipticcurvelist_length;\n\t\t}\n#endif\n# ifndef OPENSSL_NO_NEXTPROTONEG\n\ts->next_proto_negotiated = NULL;\n# endif\n\tif (s->ctx->alpn_client_proto_list)\n\t\t{\n\t\ts->alpn_client_proto_list =\n\t\t\tOPENSSL_malloc(s->ctx->alpn_client_proto_list_len);\n\t\tif (s->alpn_client_proto_list == NULL)\n\t\t\tgoto err;\n\t\tmemcpy(s->alpn_client_proto_list, s->ctx->alpn_client_proto_list,\n\t\t       s->ctx->alpn_client_proto_list_len);\n\t\ts->alpn_client_proto_list_len = s->ctx->alpn_client_proto_list_len;\n\t\t}\n#endif\n\ts->verify_result=X509_V_OK;\n\ts->method=ctx->method;\n\tif (!s->method->ssl_new(s))\n\t\tgoto err;\n\ts->references=1;\n\ts->server=(ctx->method->ssl_accept == ssl_undefined_function)?0:1;\n\tSSL_clear(s);\n\tCRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);\n#ifndef OPENSSL_NO_PSK\n\ts->psk_client_callback=ctx->psk_client_callback;\n\ts->psk_server_callback=ctx->psk_server_callback;\n#endif\n\treturn(s);\nerr:\n\tif (s != NULL)\n\t\t{\n\t\tif (s->cert != NULL)\n\t\t\tssl_cert_free(s->cert);\n\t\tif (s->ctx != NULL)\n\t\t\tSSL_CTX_free(s->ctx);\n\t\tOPENSSL_free(s);\n\t\t}\n\tSSLerr(SSL_F_SSL_NEW,ERR_R_MALLOC_FAILURE);\n\treturn(NULL);\n\t}', 'int SSL_clear(SSL *s)\n\t{\n\tif (s->method == NULL)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,SSL_R_NO_METHOD_SPECIFIED);\n\t\treturn(0);\n\t\t}\n\tif (ssl_clear_bad_session(s))\n\t\t{\n\t\tSSL_SESSION_free(s->session);\n\t\ts->session=NULL;\n\t\t}\n\ts->error=0;\n\ts->hit=0;\n\ts->shutdown=0;\n#if 0\n\tif (s->renegotiate) return(1);\n#else\n\tif (s->renegotiate)\n\t\t{\n\t\tSSLerr(SSL_F_SSL_CLEAR,ERR_R_INTERNAL_ERROR);\n\t\treturn 0;\n\t\t}\n#endif\n\ts->type=0;\n\ts->state=SSL_ST_BEFORE|((s->server)?SSL_ST_ACCEPT:SSL_ST_CONNECT);\n\ts->version=s->method->version;\n\ts->client_version=s->version;\n\ts->rwstate=SSL_NOTHING;\n\ts->rstate=SSL_ST_READ_HEADER;\n#if 0\n\ts->read_ahead=s->ctx->read_ahead;\n#endif\n\tif (s->init_buf != NULL)\n\t\t{\n\t\tBUF_MEM_free(s->init_buf);\n\t\ts->init_buf=NULL;\n\t\t}\n\tssl_clear_cipher_ctx(s);\n\tssl_clear_hash_ctx(&s->read_hash);\n\tssl_clear_hash_ctx(&s->write_hash);\n\ts->first_packet=0;\n#if 1\n\tif (!s->in_handshake && (s->session == NULL) && (s->method != s->ctx->method))\n\t\t{\n\t\ts->method->ssl_free(s);\n\t\ts->method=s->ctx->method;\n\t\tif (!s->method->ssl_new(s))\n\t\t\treturn(0);\n\t\t}\n\telse\n#endif\n\t\ts->method->ssl_clear(s);\n\treturn(1);\n\t}', 'int ssl_clear_bad_session(SSL *s)\n\t{\n\tif (\t(s->session != NULL) &&\n\t\t!(s->shutdown & SSL_SENT_SHUTDOWN) &&\n\t\t!(SSL_in_init(s) || SSL_in_before(s)))\n\t\t{\n\t\tSSL_CTX_remove_session(s->ctx,s->session);\n\t\treturn(1);\n\t\t}\n\telse\n\t\treturn(0);\n\t}', 'int SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)\n{\n\treturn remove_session_lock(ctx, c, 1);\n}', 'static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)\n\t{\n\tSSL_SESSION *r;\n\tint ret=0;\n\tif ((c != NULL) && (c->session_id_length != 0))\n\t\t{\n\t\tif(lck) CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);\n\t\tif ((r = lh_SSL_SESSION_retrieve(ctx->sessions,c)) == c)\n\t\t\t{\n\t\t\tret=1;\n\t\t\tr=lh_SSL_SESSION_delete(ctx->sessions,c);\n\t\t\tSSL_SESSION_list_remove(ctx,c);\n\t\t\t}\n\t\tif(lck) CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);\n\t\tif (ret)\n\t\t\t{\n\t\t\tr->not_resumable=1;\n\t\t\tif (ctx->remove_session_cb != NULL)\n\t\t\t\tctx->remove_session_cb(ctx,r);\n\t\t\tSSL_SESSION_free(r);\n\t\t\t}\n\t\t}\n\telse\n\t\tret=0;\n\treturn(ret);\n\t}', 'void *lh_delete(_LHASH *lh, const void *data)\n\t{\n\tunsigned long hash;\n\tLHASH_NODE *nn,**rn;\n\tvoid *ret;\n\tlh->error=0;\n\trn=getrn(lh,data,&hash);\n\tif (*rn == NULL)\n\t\t{\n\t\tlh->num_no_delete++;\n\t\treturn(NULL);\n\t\t}\n\telse\n\t\t{\n\t\tnn= *rn;\n\t\t*rn=nn->next;\n\t\tret=nn->data;\n\t\tOPENSSL_free(nn);\n\t\tlh->num_delete++;\n\t\t}\n\tlh->num_items--;\n\tif ((lh->num_nodes > MIN_NODES) &&\n\t\t(lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))\n\t\tcontract(lh);\n\treturn(ret);\n\t}']