apps/s_client.c:1445: error: UNINITIALIZED_VALUE
  The value read from s was never initialized.
Showing all 1 steps of the trace


apps/s_client.c:1445:13: 
1443.           unsigned long l = 1;
1444.           BIO_printf(bio_c_out, "turning on non blocking io\n");
1445. >         if (BIO_socket_ioctl(s, FIONBIO, &l) < 0) {
1446.               ERR_print_errors(bio_err);
1447.               goto end;

int MAIN(int argc, char **argv)
{
    int build_chain = 0;
    SSL *con = NULL;
#ifndef OPENSSL_NO_KRB5
    KSSL_CTX *kctx;
#endif
    int s, k, width, state = 0;
    char *cbuf = NULL, *sbuf = NULL, *mbuf = NULL;
    int cbuf_len, cbuf_off;
    int sbuf_len, sbuf_off;
    fd_set readfds, writefds;
    short port = PORT;
    int full_log = 1;
    char *host = SSL_HOST_NAME;
    const char *unix_path = NULL;
    char *xmpphost = NULL;
    char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;
    int cert_format = FORMAT_PEM, key_format = FORMAT_PEM;
    char *passarg = NULL, *pass = NULL;
    X509 *cert = NULL;
    EVP_PKEY *key = NULL;
    STACK_OF(X509) *chain = NULL;
    char *CApath = NULL, *CAfile = NULL;
    char *chCApath = NULL, *chCAfile = NULL;
    char *vfyCApath = NULL, *vfyCAfile = NULL;
    int reconnect = 0, badop = 0, verify = SSL_VERIFY_NONE;
    int crlf = 0;
    int write_tty, read_tty, write_ssl, read_ssl, tty_on, ssl_pending;
    SSL_CTX *ctx = NULL;
    int ret = 1, in_init = 1, i, nbio_test = 0;
    int starttls_proto = PROTO_OFF;
    int prexit = 0;
    X509_VERIFY_PARAM *vpm = NULL;
    int badarg = 0;
    const SSL_METHOD *meth = NULL;
    int socket_type = SOCK_STREAM;
    BIO *sbio;
    char *inrand = NULL;
    int mbuf_len = 0;
    struct timeval timeout, *timeoutp;
#ifndef OPENSSL_NO_ENGINE
    char *engine_id = NULL;
    char *ssl_client_engine_id = NULL;
    ENGINE *ssl_client_engine = NULL;
#endif
    ENGINE *e = NULL;
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
    struct timeval tv;
#endif
#ifndef OPENSSL_NO_TLSEXT
    char *servername = NULL;
    tlsextctx tlsextcbp = { NULL, 0 };
# ifndef OPENSSL_NO_NEXTPROTONEG
    const char *next_proto_neg_in = NULL;
# endif
    const char *alpn_in = NULL;
# define MAX_SI_TYPES 100
    unsigned short serverinfo_types[MAX_SI_TYPES];
    int serverinfo_types_count = 0;
#endif
    char *sess_in = NULL;
    char *sess_out = NULL;
    struct sockaddr peer;
    int peerlen = sizeof(peer);
    int fallback_scsv = 0;
    int enable_timeouts = 0;
    long socket_mtu = 0;
#ifndef OPENSSL_NO_JPAKE
    static char *jpake_secret = NULL;
# define no_jpake !jpake_secret
#else
# define no_jpake 1
#endif
#ifndef OPENSSL_NO_SRP
    char *srppass = NULL;
    int srp_lateuser = 0;
    SRP_ARG srp_arg = { NULL, NULL, 0, 0, 0, 1024 };
#endif
    SSL_EXCERT *exc = NULL;
    SSL_CONF_CTX *cctx = NULL;
    STACK_OF(OPENSSL_STRING) *ssl_args = NULL;
    char *crl_file = NULL;
    int crl_format = FORMAT_PEM;
    int crl_download = 0;
    STACK_OF(X509_CRL) *crls = NULL;
    int sdebug = 0;
    meth = SSLv23_client_method();
    apps_startup();
    c_Pause = 0;
    c_quiet = 0;
    c_ign_eof = 0;
    c_debug = 0;
    c_msg = 0;
    c_showcerts = 0;
    if (bio_err == NULL)
        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
    if (!load_config(bio_err, NULL))
        goto end;
    cctx = SSL_CONF_CTX_new();
    if (!cctx)
        goto end;
    SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CLIENT);
    SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CMDLINE);
    if (((cbuf = OPENSSL_malloc(BUFSIZZ)) == NULL) ||
        ((sbuf = OPENSSL_malloc(BUFSIZZ)) == NULL) ||
        ((mbuf = OPENSSL_malloc(BUFSIZZ)) == NULL)) {
        BIO_printf(bio_err, "out of memory\n");
        goto end;
    }
    verify_depth = 0;
    verify_error = X509_V_OK;
#ifdef FIONBIO
    c_nbio = 0;
#endif
    argc--;
    argv++;
    while (argc >= 1) {
        if (strcmp(*argv, "-host") == 0) {
            if (--argc < 1)
                goto bad;
            host = *(++argv);
        } else if (strcmp(*argv, "-port") == 0) {
            if (--argc < 1)
                goto bad;
            port = atoi(*(++argv));
            if (port == 0)
                goto bad;
        } else if (strcmp(*argv, "-connect") == 0) {
            if (--argc < 1)
                goto bad;
            if (!extract_host_port(*(++argv), &host, NULL, &port))
                goto bad;
        } else if (strcmp(*argv, "-unix") == 0) {
            if (--argc < 1)
                goto bad;
            unix_path = *(++argv);
        } else if (strcmp(*argv, "-xmpphost") == 0) {
            if (--argc < 1)
                goto bad;
            xmpphost = *(++argv);
        } else if (strcmp(*argv, "-verify") == 0) {
            verify = SSL_VERIFY_PEER;
            if (--argc < 1)
                goto bad;
            verify_depth = atoi(*(++argv));
            if (!c_quiet)
                BIO_printf(bio_err, "verify depth is %d\n", verify_depth);
        } else if (strcmp(*argv, "-cert") == 0) {
            if (--argc < 1)
                goto bad;
            cert_file = *(++argv);
        } else if (strcmp(*argv, "-CRL") == 0) {
            if (--argc < 1)
                goto bad;
            crl_file = *(++argv);
        } else if (strcmp(*argv, "-crl_download") == 0)
            crl_download = 1;
        else if (strcmp(*argv, "-sess_out") == 0) {
            if (--argc < 1)
                goto bad;
            sess_out = *(++argv);
        } else if (strcmp(*argv, "-sess_in") == 0) {
            if (--argc < 1)
                goto bad;
            sess_in = *(++argv);
        } else if (strcmp(*argv, "-certform") == 0) {
            if (--argc < 1)
                goto bad;
            cert_format = str2fmt(*(++argv));
        } else if (strcmp(*argv, "-CRLform") == 0) {
            if (--argc < 1)
                goto bad;
            crl_format = str2fmt(*(++argv));
        } else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm)) {
            if (badarg)
                goto bad;
            continue;
        } else if (strcmp(*argv, "-verify_return_error") == 0)
            verify_return_error = 1;
        else if (strcmp(*argv, "-verify_quiet") == 0)
            verify_quiet = 1;
        else if (strcmp(*argv, "-brief") == 0) {
            c_brief = 1;
            verify_quiet = 1;
            c_quiet = 1;
        } else if (args_excert(&argv, &argc, &badarg, bio_err, &exc)) {
            if (badarg)
                goto bad;
            continue;
        } else if (args_ssl(&argv, &argc, cctx, &badarg, bio_err, &ssl_args)) {
            if (badarg)
                goto bad;
            continue;
        } else if (strcmp(*argv, "-prexit") == 0)
            prexit = 1;
        else if (strcmp(*argv, "-crlf") == 0)
            crlf = 1;
        else if (strcmp(*argv, "-quiet") == 0) {
            c_quiet = 1;
            c_ign_eof = 1;
        } else if (strcmp(*argv, "-ign_eof") == 0)
            c_ign_eof = 1;
        else if (strcmp(*argv, "-no_ign_eof") == 0)
            c_ign_eof = 0;
        else if (strcmp(*argv, "-pause") == 0)
            c_Pause = 1;
        else if (strcmp(*argv, "-debug") == 0)
            c_debug = 1;
#ifndef OPENSSL_NO_TLSEXT
        else if (strcmp(*argv, "-tlsextdebug") == 0)
            c_tlsextdebug = 1;
        else if (strcmp(*argv, "-status") == 0)
            c_status_req = 1;
#endif
#ifdef WATT32
        else if (strcmp(*argv, "-wdebug") == 0)
            dbug_init();
#endif
        else if (strcmp(*argv, "-msg") == 0)
            c_msg = 1;
        else if (strcmp(*argv, "-msgfile") == 0) {
            if (--argc < 1)
                goto bad;
            bio_c_msg = BIO_new_file(*(++argv), "w");
        }
#ifndef OPENSSL_NO_SSL_TRACE
        else if (strcmp(*argv, "-trace") == 0)
            c_msg = 2;
#endif
        else if (strcmp(*argv, "-security_debug") == 0) {
            sdebug = 1;
        } else if (strcmp(*argv, "-security_debug_verbose") == 0) {
            sdebug = 2;
        } else if (strcmp(*argv, "-showcerts") == 0)
            c_showcerts = 1;
        else if (strcmp(*argv, "-nbio_test") == 0)
            nbio_test = 1;
        else if (strcmp(*argv, "-state") == 0)
            state = 1;
#ifndef OPENSSL_NO_PSK
        else if (strcmp(*argv, "-psk_identity") == 0) {
            if (--argc < 1)
                goto bad;
            psk_identity = *(++argv);
        } else if (strcmp(*argv, "-psk") == 0) {
            size_t j;
            if (--argc < 1)
                goto bad;
            psk_key = *(++argv);
            for (j = 0; j < strlen(psk_key); j++) {
                if (isxdigit((unsigned char)psk_key[j]))
                    continue;
                BIO_printf(bio_err, "Not a hex number '%s'\n", *argv);
                goto bad;
            }
        }
#endif
#ifndef OPENSSL_NO_SRP
        else if (strcmp(*argv, "-srpuser") == 0) {
            if (--argc < 1)
                goto bad;
            srp_arg.srplogin = *(++argv);
            meth = TLSv1_client_method();
        } else if (strcmp(*argv, "-srppass") == 0) {
            if (--argc < 1)
                goto bad;
            srppass = *(++argv);
            meth = TLSv1_client_method();
        } else if (strcmp(*argv, "-srp_strength") == 0) {
            if (--argc < 1)
                goto bad;
            srp_arg.strength = atoi(*(++argv));
            BIO_printf(bio_err, "SRP minimal length for N is %d\n",
                       srp_arg.strength);
            meth = TLSv1_client_method();
        } else if (strcmp(*argv, "-srp_lateuser") == 0) {
            srp_lateuser = 1;
            meth = TLSv1_client_method();
        } else if (strcmp(*argv, "-srp_moregroups") == 0) {
            srp_arg.amp = 1;
            meth = TLSv1_client_method();
        }
#endif
#ifndef OPENSSL_NO_SSL3_METHOD
        else if (strcmp(*argv, "-ssl3") == 0)
            meth = SSLv3_client_method();
#endif
#ifndef OPENSSL_NO_TLS1
        else if (strcmp(*argv, "-tls1_2") == 0)
            meth = TLSv1_2_client_method();
        else if (strcmp(*argv, "-tls1_1") == 0)
            meth = TLSv1_1_client_method();
        else if (strcmp(*argv, "-tls1") == 0)
            meth = TLSv1_client_method();
#endif
#ifndef OPENSSL_NO_DTLS1
        else if (strcmp(*argv, "-dtls") == 0) {
            meth = DTLS_client_method();
            socket_type = SOCK_DGRAM;
        } else if (strcmp(*argv, "-dtls1") == 0) {
            meth = DTLSv1_client_method();
            socket_type = SOCK_DGRAM;
        } else if (strcmp(*argv, "-dtls1_2") == 0) {
            meth = DTLSv1_2_client_method();
            socket_type = SOCK_DGRAM;
        } else if (strcmp(*argv, "-timeout") == 0)
            enable_timeouts = 1;
        else if (strcmp(*argv, "-mtu") == 0) {
            if (--argc < 1)
                goto bad;
            socket_mtu = atol(*(++argv));
        }
#endif
        else if (strcmp(*argv, "-fallback_scsv") == 0) {
            fallback_scsv = 1;
        } else if (strcmp(*argv, "-keyform") == 0) {
            if (--argc < 1)
                goto bad;
            key_format = str2fmt(*(++argv));
        } else if (strcmp(*argv, "-pass") == 0) {
            if (--argc < 1)
                goto bad;
            passarg = *(++argv);
        } else if (strcmp(*argv, "-cert_chain") == 0) {
            if (--argc < 1)
                goto bad;
            chain_file = *(++argv);
        } else if (strcmp(*argv, "-key") == 0) {
            if (--argc < 1)
                goto bad;
            key_file = *(++argv);
        } else if (strcmp(*argv, "-reconnect") == 0) {
            reconnect = 5;
        } else if (strcmp(*argv, "-CApath") == 0) {
            if (--argc < 1)
                goto bad;
            CApath = *(++argv);
        } else if (strcmp(*argv, "-chainCApath") == 0) {
            if (--argc < 1)
                goto bad;
            chCApath = *(++argv);
        } else if (strcmp(*argv, "-verifyCApath") == 0) {
            if (--argc < 1)
                goto bad;
            vfyCApath = *(++argv);
        } else if (strcmp(*argv, "-build_chain") == 0)
            build_chain = 1;
        else if (strcmp(*argv, "-CAfile") == 0) {
            if (--argc < 1)
                goto bad;
            CAfile = *(++argv);
        } else if (strcmp(*argv, "-chainCAfile") == 0) {
            if (--argc < 1)
                goto bad;
            chCAfile = *(++argv);
        } else if (strcmp(*argv, "-verifyCAfile") == 0) {
            if (--argc < 1)
                goto bad;
            vfyCAfile = *(++argv);
        }
#ifndef OPENSSL_NO_TLSEXT
# ifndef OPENSSL_NO_NEXTPROTONEG
        else if (strcmp(*argv, "-nextprotoneg") == 0) {
            if (--argc < 1)
                goto bad;
            next_proto_neg_in = *(++argv);
        }
# endif
        else if (strcmp(*argv, "-alpn") == 0) {
            if (--argc < 1)
                goto bad;
            alpn_in = *(++argv);
        } else if (strcmp(*argv, "-serverinfo") == 0) {
            char *c;
            int start = 0;
            int len;
            if (--argc < 1)
                goto bad;
            c = *(++argv);
            serverinfo_types_count = 0;
            len = strlen(c);
            for (i = 0; i <= len; ++i) {
                if (i == len || c[i] == ',') {
                    serverinfo_types[serverinfo_types_count]
                        = atoi(c + start);
                    serverinfo_types_count++;
                    start = i + 1;
                }
                if (serverinfo_types_count == MAX_SI_TYPES)
                    break;
            }
        }
#endif
#ifdef FIONBIO
        else if (strcmp(*argv, "-nbio") == 0) {
            c_nbio = 1;
        }
#endif
        else if (strcmp(*argv, "-starttls") == 0) {
            if (--argc < 1)
                goto bad;
            ++argv;
            if (strcmp(*argv, "smtp") == 0)
                starttls_proto = PROTO_SMTP;
            else if (strcmp(*argv, "pop3") == 0)
                starttls_proto = PROTO_POP3;
            else if (strcmp(*argv, "imap") == 0)
                starttls_proto = PROTO_IMAP;
            else if (strcmp(*argv, "ftp") == 0)
                starttls_proto = PROTO_FTP;
            else if (strcmp(*argv, "xmpp") == 0)
                starttls_proto = PROTO_XMPP;
            else
                goto bad;
        }
#ifndef OPENSSL_NO_ENGINE
        else if (strcmp(*argv, "-engine") == 0) {
            if (--argc < 1)
                goto bad;
            engine_id = *(++argv);
        } else if (strcmp(*argv, "-ssl_client_engine") == 0) {
            if (--argc < 1)
                goto bad;
            ssl_client_engine_id = *(++argv);
        }
#endif
        else if (strcmp(*argv, "-rand") == 0) {
            if (--argc < 1)
                goto bad;
            inrand = *(++argv);
        }
#ifndef OPENSSL_NO_TLSEXT
        else if (strcmp(*argv, "-servername") == 0) {
            if (--argc < 1)
                goto bad;
            servername = *(++argv);
        }
#endif
#ifndef OPENSSL_NO_JPAKE
        else if (strcmp(*argv, "-jpake") == 0) {
            if (--argc < 1)
                goto bad;
            jpake_secret = *++argv;
        }
#endif
#ifndef OPENSSL_NO_SRTP
        else if (strcmp(*argv, "-use_srtp") == 0) {
            if (--argc < 1)
                goto bad;
            srtp_profiles = *(++argv);
        }
#endif
        else if (strcmp(*argv, "-keymatexport") == 0) {
            if (--argc < 1)
                goto bad;
            keymatexportlabel = *(++argv);
        } else if (strcmp(*argv, "-keymatexportlen") == 0) {
            if (--argc < 1)
                goto bad;
            keymatexportlen = atoi(*(++argv));
            if (keymatexportlen == 0)
                goto bad;
        } else {
            BIO_printf(bio_err, "unknown option %s\n", *argv);
            badop = 1;
            break;
        }
        argc--;
        argv++;
    }
    if (badop) {
 bad:
        sc_usage();
        goto end;
    }
    if (unix_path && (socket_type != SOCK_STREAM)) {
        BIO_printf(bio_err,
                   "Can't use unix sockets and datagrams together\n");
        goto end;
    }
#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)
    if (jpake_secret) {
        if (psk_key) {
            BIO_printf(bio_err, "Can't use JPAKE and PSK together\n");
            goto end;
        }
        psk_identity = "JPAKE";
    }
#endif
    OpenSSL_add_ssl_algorithms();
    SSL_load_error_strings();
#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
    next_proto.status = -1;
    if (next_proto_neg_in) {
        next_proto.data =
            next_protos_parse(&next_proto.len, next_proto_neg_in);
        if (next_proto.data == NULL) {
            BIO_printf(bio_err, "Error parsing -nextprotoneg argument\n");
            goto end;
        }
    } else
        next_proto.data = NULL;
#endif
#ifndef OPENSSL_NO_ENGINE
    e = setup_engine(bio_err, engine_id, 1);
    if (ssl_client_engine_id) {
        ssl_client_engine = ENGINE_by_id(ssl_client_engine_id);
        if (!ssl_client_engine) {
            BIO_printf(bio_err, "Error getting client auth engine\n");
            goto end;
        }
    }
#endif
    if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) {
        BIO_printf(bio_err, "Error getting password\n");
        goto end;
    }
    if (key_file == NULL)
        key_file = cert_file;
    if (key_file) {
        key = load_key(bio_err, key_file, key_format, 0, pass, e,
                       "client certificate private key file");
        if (!key) {
            ERR_print_errors(bio_err);
            goto end;
        }
    }
    if (cert_file) {
        cert = load_cert(bio_err, cert_file, cert_format,
                         NULL, e, "client certificate file");
        if (!cert) {
            ERR_print_errors(bio_err);
            goto end;
        }
    }
    if (chain_file) {
        chain = load_certs(bio_err, chain_file, FORMAT_PEM,
                           NULL, e, "client certificate chain");
        if (!chain)
            goto end;
    }
    if (crl_file) {
        X509_CRL *crl;
        crl = load_crl(crl_file, crl_format);
        if (!crl) {
            BIO_puts(bio_err, "Error loading CRL\n");
            ERR_print_errors(bio_err);
            goto end;
        }
        crls = sk_X509_CRL_new_null();
        if (!crls || !sk_X509_CRL_push(crls, crl)) {
            BIO_puts(bio_err, "Error adding CRL\n");
            ERR_print_errors(bio_err);
            X509_CRL_free(crl);
            goto end;
        }
    }
    if (!load_excert(&exc, bio_err))
        goto end;
    if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL
        && !RAND_status()) {
        BIO_printf(bio_err,
                   "warning, not much extra random data, consider using the -rand option\n");
    }
    if (inrand != NULL)
        BIO_printf(bio_err, "%ld semi-random bytes loaded\n",
                   app_RAND_load_files(inrand));
    if (bio_c_out == NULL) {
        if (c_quiet && !c_debug) {
            bio_c_out = BIO_new(BIO_s_null());
            if (c_msg && !bio_c_msg)
                bio_c_msg = BIO_new_fp(stdout, BIO_NOCLOSE);
        } else {
            if (bio_c_out == NULL)
                bio_c_out = BIO_new_fp(stdout, BIO_NOCLOSE);
        }
    }
#ifndef OPENSSL_NO_SRP
    if (!app_passwd(bio_err, srppass, NULL, &srp_arg.srppassin, NULL)) {
        BIO_printf(bio_err, "Error getting password\n");
        goto end;
    }
#endif
    ctx = SSL_CTX_new(meth);
    if (ctx == NULL) {
        ERR_print_errors(bio_err);
        goto end;
    }
    if (sdebug)
        ssl_ctx_security_debug(ctx, bio_err, sdebug);
    if (vpm)
        SSL_CTX_set1_param(ctx, vpm);
    if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, 1, no_jpake)) {
        ERR_print_errors(bio_err);
        goto end;
    }
    if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile,
                         crls, crl_download)) {
        BIO_printf(bio_err, "Error loading store locations\n");
        ERR_print_errors(bio_err);
        goto end;
    }
#ifndef OPENSSL_NO_ENGINE
    if (ssl_client_engine) {
        if (!SSL_CTX_set_client_cert_engine(ctx, ssl_client_engine)) {
            BIO_puts(bio_err, "Error setting client auth engine\n");
            ERR_print_errors(bio_err);
            ENGINE_free(ssl_client_engine);
            goto end;
        }
        ENGINE_free(ssl_client_engine);
    }
#endif
#ifndef OPENSSL_NO_PSK
# ifdef OPENSSL_NO_JPAKE
    if (psk_key != NULL)
# else
    if (psk_key != NULL || jpake_secret)
# endif
    {
        if (c_debug)
            BIO_printf(bio_c_out,
                       "PSK key given or JPAKE in use, setting client callback\n");
        SSL_CTX_set_psk_client_callback(ctx, psk_client_cb);
    }
#endif
#ifndef OPENSSL_NO_SRTP
    if (srtp_profiles != NULL)
        SSL_CTX_set_tlsext_use_srtp(ctx, srtp_profiles);
#endif
    if (exc)
        ssl_ctx_set_excert(ctx, exc);
    if (socket_type == SOCK_DGRAM)
        SSL_CTX_set_read_ahead(ctx, 1);
#if !defined(OPENSSL_NO_TLSEXT)
# if !defined(OPENSSL_NO_NEXTPROTONEG)
    if (next_proto.data)
        SSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &next_proto);
# endif
    if (alpn_in) {
        unsigned short alpn_len;
        unsigned char *alpn = next_protos_parse(&alpn_len, alpn_in);
        if (alpn == NULL) {
            BIO_printf(bio_err, "Error parsing -alpn argument\n");
            goto end;
        }
        SSL_CTX_set_alpn_protos(ctx, alpn, alpn_len);
        OPENSSL_free(alpn);
    }
#endif
#ifndef OPENSSL_NO_TLSEXT
    for (i = 0; i < serverinfo_types_count; i++) {
        SSL_CTX_add_client_custom_ext(ctx,
                                      serverinfo_types[i],
                                      NULL, NULL, NULL,
                                      serverinfo_cli_parse_cb, NULL);
    }
#endif
    if (state)
        SSL_CTX_set_info_callback(ctx, apps_ssl_info_callback);
#if 0
    else
        SSL_CTX_set_cipher_list(ctx, getenv("SSL_CIPHER"));
#endif
    SSL_CTX_set_verify(ctx, verify, verify_callback);
    if ((!SSL_CTX_load_verify_locations(ctx, CAfile, CApath)) ||
        (!SSL_CTX_set_default_verify_paths(ctx))) {
        ERR_print_errors(bio_err);
    }
    ssl_ctx_add_crls(ctx, crls, crl_download);
    if (!set_cert_key_stuff(ctx, cert, key, chain, build_chain))
        goto end;
#ifndef OPENSSL_NO_TLSEXT
    if (servername != NULL) {
        tlsextcbp.biodebug = bio_err;
        SSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);
        SSL_CTX_set_tlsext_servername_arg(ctx, &tlsextcbp);
    }
# ifndef OPENSSL_NO_SRP
    if (srp_arg.srplogin) {
        if (!srp_lateuser && !SSL_CTX_set_srp_username(ctx, srp_arg.srplogin)) {
            BIO_printf(bio_err, "Unable to set SRP username\n");
            goto end;
        }
        srp_arg.msg = c_msg;
        srp_arg.debug = c_debug;
        SSL_CTX_set_srp_cb_arg(ctx, &srp_arg);
        SSL_CTX_set_srp_client_pwd_callback(ctx, ssl_give_srp_client_pwd_cb);
        SSL_CTX_set_srp_strength(ctx, srp_arg.strength);
        if (c_msg || c_debug || srp_arg.amp == 0)
            SSL_CTX_set_srp_verify_param_callback(ctx,
                                                  ssl_srp_verify_param_cb);
    }
# endif
#endif
    con = SSL_new(ctx);
    if (sess_in) {
        SSL_SESSION *sess;
        BIO *stmp = BIO_new_file(sess_in, "r");
        if (!stmp) {
            BIO_printf(bio_err, "Can't open session file %s\n", sess_in);
            ERR_print_errors(bio_err);
            goto end;
        }
        sess = PEM_read_bio_SSL_SESSION(stmp, NULL, 0, NULL);
        BIO_free(stmp);
        if (!sess) {
            BIO_printf(bio_err, "Can't open session file %s\n", sess_in);
            ERR_print_errors(bio_err);
            goto end;
        }
        SSL_set_session(con, sess);
        SSL_SESSION_free(sess);
    }
    if (fallback_scsv)
        SSL_set_mode(con, SSL_MODE_SEND_FALLBACK_SCSV);
#ifndef OPENSSL_NO_TLSEXT
    if (servername != NULL) {
        if (!SSL_set_tlsext_host_name(con, servername)) {
            BIO_printf(bio_err, "Unable to set TLS servername extension.\n");
            ERR_print_errors(bio_err);
            goto end;
        }
    }
#endif
#ifndef OPENSSL_NO_KRB5
    if (con && (kctx = kssl_ctx_new()) != NULL) {
        SSL_set0_kssl_ctx(con, kctx);
        kssl_ctx_setstring(kctx, KSSL_SERVER, host);
    }
#endif
#if 0
# ifdef TLSEXT_TYPE_opaque_prf_input
    SSL_set_tlsext_opaque_prf_input(con, "Test client", 11);
# endif
#endif
 re_start:
#ifdef NO_SYS_UN_H
    if (init_client(&s, host, port, socket_type) == 0)
#else
    if ((!unix_path && (init_client(&s, host, port, socket_type) == 0)) ||
        (unix_path && (init_client_unix(&s, unix_path) == 0)))
#endif
    {
        BIO_printf(bio_err, "connect:errno=%d\n", get_last_socket_error());
        SHUTDOWN(s);
        goto end;
    }
    BIO_printf(bio_c_out, "CONNECTED(%08X)\n", s);
#ifdef FIONBIO
    if (c_nbio) {
        unsigned long l = 1;
        BIO_printf(bio_c_out, "turning on non blocking io\n");
        if (BIO_socket_ioctl(s, FIONBIO, &l) < 0) {
            ERR_print_errors(bio_err);
            goto end;
        }
    }
#endif
    if (c_Pause & 0x01)
        SSL_set_debug(con, 1);
    if (socket_type == SOCK_DGRAM) {
        sbio = BIO_new_dgram(s, BIO_NOCLOSE);
        if (getsockname(s, &peer, (void *)&peerlen) < 0) {
            BIO_printf(bio_err, "getsockname:errno=%d\n",
                       get_last_socket_error());
            SHUTDOWN(s);
            goto end;
        }
        (void)BIO_ctrl_set_connected(sbio, 1, &peer);
        if (enable_timeouts) {
            timeout.tv_sec = 0;
            timeout.tv_usec = DGRAM_RCV_TIMEOUT;
            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);
            timeout.tv_sec = 0;
            timeout.tv_usec = DGRAM_SND_TIMEOUT;
            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);
        }
        if (socket_mtu) {
            if (socket_mtu < DTLS_get_link_min_mtu(con)) {
                BIO_printf(bio_err, "MTU too small. Must be at least %ld\n",
                           DTLS_get_link_min_mtu(con));
                BIO_free(sbio);
                goto shut;
            }
            SSL_set_options(con, SSL_OP_NO_QUERY_MTU);
            if (!DTLS_set_link_mtu(con, socket_mtu)) {
                BIO_printf(bio_err, "Failed to set MTU\n");
                BIO_free(sbio);
                goto shut;
            }
        } else
            BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);
    } else
        sbio = BIO_new_socket(s, BIO_NOCLOSE);
    if (nbio_test) {
        BIO *test;
        test = BIO_new(BIO_f_nbio_test());
        sbio = BIO_push(test, sbio);
    }
    if (c_debug) {
        SSL_set_debug(con, 1);
        BIO_set_callback(sbio, bio_dump_callback);
        BIO_set_callback_arg(sbio, (char *)bio_c_out);
    }
    if (c_msg) {
#ifndef OPENSSL_NO_SSL_TRACE
        if (c_msg == 2)
            SSL_set_msg_callback(con, SSL_trace);
        else
#endif
            SSL_set_msg_callback(con, msg_cb);
        SSL_set_msg_callback_arg(con, bio_c_msg ? bio_c_msg : bio_c_out);
    }
#ifndef OPENSSL_NO_TLSEXT
    if (c_tlsextdebug) {
        SSL_set_tlsext_debug_callback(con, tlsext_cb);
        SSL_set_tlsext_debug_arg(con, bio_c_out);
    }
    if (c_status_req) {
        SSL_set_tlsext_status_type(con, TLSEXT_STATUSTYPE_ocsp);
        SSL_CTX_set_tlsext_status_cb(ctx, ocsp_resp_cb);
        SSL_CTX_set_tlsext_status_arg(ctx, bio_c_out);
# if 0
        {
            STACK_OF(OCSP_RESPID) *ids = sk_OCSP_RESPID_new_null();
            OCSP_RESPID *id = OCSP_RESPID_new();
            id->value.byKey = ASN1_OCTET_STRING_new();
            id->type = V_OCSP_RESPID_KEY;
            ASN1_STRING_set(id->value.byKey, "Hello World", -1);
            sk_OCSP_RESPID_push(ids, id);
            SSL_set_tlsext_status_ids(con, ids);
        }
# endif
    }
#endif
#ifndef OPENSSL_NO_JPAKE
    if (jpake_secret)
        jpake_client_auth(bio_c_out, sbio, jpake_secret);
#endif
    SSL_set_bio(con, sbio, sbio);
    SSL_set_connect_state(con);
    width = SSL_get_fd(con) + 1;
    read_tty = 1;
    write_tty = 0;
    tty_on = 0;
    read_ssl = 1;
    write_ssl = 1;
    cbuf_len = 0;
    cbuf_off = 0;
    sbuf_len = 0;
    sbuf_off = 0;
    if (starttls_proto == PROTO_SMTP) {
        int foundit = 0;
        BIO *fbio = BIO_new(BIO_f_buffer());
        BIO_push(fbio, sbio);
        do {
            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);
        }
        while (mbuf_len > 3 && mbuf[3] == '-');
        BIO_printf(fbio, "EHLO openssl.client.net\r\n");
        (void)BIO_flush(fbio);
        do {
            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);
            if (strstr(mbuf, "STARTTLS"))
                foundit = 1;
        }
        while (mbuf_len > 3 && mbuf[3] == '-');
        (void)BIO_flush(fbio);
        BIO_pop(fbio);
        BIO_free(fbio);
        if (!foundit)
            BIO_printf(bio_err,
                       "didn't found starttls in server response,"
                       " try anyway...\n");
        BIO_printf(sbio, "STARTTLS\r\n");
        BIO_read(sbio, sbuf, BUFSIZZ);
    } else if (starttls_proto == PROTO_POP3) {
        BIO_read(sbio, mbuf, BUFSIZZ);
        BIO_printf(sbio, "STLS\r\n");
        BIO_read(sbio, sbuf, BUFSIZZ);
    } else if (starttls_proto == PROTO_IMAP) {
        int foundit = 0;
        BIO *fbio = BIO_new(BIO_f_buffer());
        BIO_push(fbio, sbio);
        BIO_gets(fbio, mbuf, BUFSIZZ);
        BIO_printf(fbio, ". CAPABILITY\r\n");
        (void)BIO_flush(fbio);
        do {
            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);
            if (strstr(mbuf, "STARTTLS"))
                foundit = 1;
        }
        while (mbuf_len > 3 && mbuf[0] != '.');
        (void)BIO_flush(fbio);
        BIO_pop(fbio);
        BIO_free(fbio);
        if (!foundit)
            BIO_printf(bio_err,
                       "didn't found STARTTLS in server response,"
                       " try anyway...\n");
        BIO_printf(sbio, ". STARTTLS\r\n");
        BIO_read(sbio, sbuf, BUFSIZZ);
    } else if (starttls_proto == PROTO_FTP) {
        BIO *fbio = BIO_new(BIO_f_buffer());
        BIO_push(fbio, sbio);
        do {
            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);
        }
        while (mbuf_len > 3 && mbuf[3] == '-');
        (void)BIO_flush(fbio);
        BIO_pop(fbio);
        BIO_free(fbio);
        BIO_printf(sbio, "AUTH TLS\r\n");
        BIO_read(sbio, sbuf, BUFSIZZ);
    }
    if (starttls_proto == PROTO_XMPP) {
        int seen = 0;
        BIO_printf(sbio, "<stream:stream "
                   "xmlns:stream='http://etherx.jabber.org/streams' "
                   "xmlns='jabber:client' to='%s' version='1.0'>", xmpphost ?
                   xmpphost : host);
        seen = BIO_read(sbio, mbuf, BUFSIZZ);
        mbuf[seen] = 0;
        while (!strstr
               (mbuf, "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'")
               && !strstr(mbuf,
                          "<starttls xmlns=\"urn:ietf:params:xml:ns:xmpp-tls\""))
        {
            seen = BIO_read(sbio, mbuf, BUFSIZZ);
            if (seen <= 0)
                goto shut;
            mbuf[seen] = 0;
        }
        BIO_printf(sbio,
                   "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>");
        seen = BIO_read(sbio, sbuf, BUFSIZZ);
        sbuf[seen] = 0;
        if (!strstr(sbuf, "<proceed"))
            goto shut;
        mbuf[0] = 0;
    }
    for (;;) {
        FD_ZERO(&readfds);
        FD_ZERO(&writefds);
        if ((SSL_version(con) == DTLS1_VERSION) &&
            DTLSv1_get_timeout(con, &timeout))
            timeoutp = &timeout;
        else
            timeoutp = NULL;
        if (SSL_in_init(con) && !SSL_total_renegotiations(con)) {
            in_init = 1;
            tty_on = 0;
        } else {
            tty_on = 1;
            if (in_init) {
                in_init = 0;
#if 0
# ifndef OPENSSL_NO_TLSEXT
                if (servername != NULL && !SSL_session_reused(con)) {
                    BIO_printf(bio_c_out,
                               "Server did %sacknowledge servername extension.\n",
                               tlsextcbp.ack ? "" : "not ");
                }
# endif
#endif
                if (sess_out) {
                    BIO *stmp = BIO_new_file(sess_out, "w");
                    if (stmp) {
                        PEM_write_bio_SSL_SESSION(stmp, SSL_get_session(con));
                        BIO_free(stmp);
                    } else
                        BIO_printf(bio_err, "Error writing session file %s\n",
                                   sess_out);
                }
                if (c_brief) {
                    BIO_puts(bio_err, "CONNECTION ESTABLISHED\n");
                    print_ssl_summary(bio_err, con);
                }
                print_stuff(bio_c_out, con, full_log);
                if (full_log > 0)
                    full_log--;
                if (starttls_proto) {
                    BIO_printf(bio_err, "%s", mbuf);
                    starttls_proto = PROTO_OFF;
                }
                if (reconnect) {
                    reconnect--;
                    BIO_printf(bio_c_out,
                               "drop connection and then reconnect\n");
                    SSL_shutdown(con);
                    SSL_set_connect_state(con);
                    SHUTDOWN(SSL_get_fd(con));
                    goto re_start;
                }
            }
        }
        ssl_pending = read_ssl && SSL_pending(con);
        if (!ssl_pending) {
#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)
            if (tty_on) {
                if (read_tty)
                    openssl_fdset(fileno(stdin), &readfds);
                if (write_tty)
                    openssl_fdset(fileno(stdout), &writefds);
            }
            if (read_ssl)
                openssl_fdset(SSL_get_fd(con), &readfds);
            if (write_ssl)
                openssl_fdset(SSL_get_fd(con), &writefds);
#else
            if (!tty_on || !write_tty) {
                if (read_ssl)
                    openssl_fdset(SSL_get_fd(con), &readfds);
                if (write_ssl)
                    openssl_fdset(SSL_get_fd(con), &writefds);
            }
#endif
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
            i = 0;
            if (!write_tty) {
                if (read_tty) {
                    tv.tv_sec = 1;
                    tv.tv_usec = 0;
                    i = select(width, (void *)&readfds, (void *)&writefds,
                               NULL, &tv);
# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)
                    if (!i && (!_kbhit() || !read_tty))
                        continue;
# else
                    if (!i && (!((_kbhit())
                                 || (WAIT_OBJECT_0 ==
                                     WaitForSingleObject(GetStdHandle
                                                         (STD_INPUT_HANDLE),
                                                         0)))
                               || !read_tty))
                        continue;
# endif
                } else
                    i = select(width, (void *)&readfds, (void *)&writefds,
                               NULL, timeoutp);
            }
#elif defined(OPENSSL_SYS_NETWARE)
            if (!write_tty) {
                if (read_tty) {
                    tv.tv_sec = 1;
                    tv.tv_usec = 0;
                    i = select(width, (void *)&readfds, (void *)&writefds,
                               NULL, &tv);
                } else
                    i = select(width, (void *)&readfds, (void *)&writefds,
                               NULL, timeoutp);
            }
#else
            i = select(width, (void *)&readfds, (void *)&writefds,
                       NULL, timeoutp);
#endif
            if (i < 0) {
                BIO_printf(bio_err, "bad select %d\n",
                           get_last_socket_error());
                goto shut;
            }
        }
        if ((SSL_version(con) == DTLS1_VERSION)
            && DTLSv1_handle_timeout(con) > 0) {
            BIO_printf(bio_err, "TIMEOUT occurred\n");
        }
        if (!ssl_pending && FD_ISSET(SSL_get_fd(con), &writefds)) {
            k = SSL_write(con, &(cbuf[cbuf_off]), (unsigned int)cbuf_len);
            switch (SSL_get_error(con, k)) {
            case SSL_ERROR_NONE:
                cbuf_off += k;
                cbuf_len -= k;
                if (k <= 0)
                    goto end;
                if (cbuf_len <= 0) {
                    read_tty = 1;
                    write_ssl = 0;
                } else {
                    read_tty = 0;
                    write_ssl = 1;
                }
                break;
            case SSL_ERROR_WANT_WRITE:
                BIO_printf(bio_c_out, "write W BLOCK\n");
                write_ssl = 1;
                read_tty = 0;
                break;
            case SSL_ERROR_WANT_READ:
                BIO_printf(bio_c_out, "write R BLOCK\n");
                write_tty = 0;
                read_ssl = 1;
                write_ssl = 0;
                break;
            case SSL_ERROR_WANT_X509_LOOKUP:
                BIO_printf(bio_c_out, "write X BLOCK\n");
                break;
            case SSL_ERROR_ZERO_RETURN:
                if (cbuf_len != 0) {
                    BIO_printf(bio_c_out, "shutdown\n");
                    ret = 0;
                    goto shut;
                } else {
                    read_tty = 1;
                    write_ssl = 0;
                    break;
                }
            case SSL_ERROR_SYSCALL:
                if ((k != 0) || (cbuf_len != 0)) {
                    BIO_printf(bio_err, "write:errno=%d\n",
                               get_last_socket_error());
                    goto shut;
                } else {
                    read_tty = 1;
                    write_ssl = 0;
                }
                break;
            case SSL_ERROR_SSL:
                ERR_print_errors(bio_err);
                goto shut;
            }
        }
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)
        else if (!ssl_pending && write_tty)
#else
        else if (!ssl_pending && FD_ISSET(fileno(stdout), &writefds))
#endif
        {
#ifdef CHARSET_EBCDIC
            ascii2ebcdic(&(sbuf[sbuf_off]), &(sbuf[sbuf_off]), sbuf_len);
#endif
            i = raw_write_stdout(&(sbuf[sbuf_off]), sbuf_len);
            if (i <= 0) {
                BIO_printf(bio_c_out, "DONE\n");
                ret = 0;
                goto shut;
            }
            sbuf_len -= i;;
            sbuf_off += i;
            if (sbuf_len <= 0) {
                read_ssl = 1;
                write_tty = 0;
            }
        } else if (ssl_pending || FD_ISSET(SSL_get_fd(con), &readfds)) {
#ifdef RENEG
            {
                static int iiii;
                if (++iiii == 52) {
                    SSL_renegotiate(con);
                    iiii = 0;
                }
            }
#endif
#if 1
            k = SSL_read(con, sbuf, 1024   );
#else
            k = SSL_read(con, sbuf, 16);
            {
                char zbuf[10240];
                printf("read=%d pending=%d peek=%d\n", k, SSL_pending(con),
                       SSL_peek(con, zbuf, 10240));
            }
#endif
            switch (SSL_get_error(con, k)) {
            case SSL_ERROR_NONE:
                if (k <= 0)
                    goto end;
                sbuf_off = 0;
                sbuf_len = k;
                read_ssl = 0;
                write_tty = 1;
                break;
            case SSL_ERROR_WANT_WRITE:
                BIO_printf(bio_c_out, "read W BLOCK\n");
                write_ssl = 1;
                read_tty = 0;
                break;
            case SSL_ERROR_WANT_READ:
                BIO_printf(bio_c_out, "read R BLOCK\n");
                write_tty = 0;
                read_ssl = 1;
                if ((read_tty == 0) && (write_ssl == 0))
                    write_ssl = 1;
                break;
            case SSL_ERROR_WANT_X509_LOOKUP:
                BIO_printf(bio_c_out, "read X BLOCK\n");
                break;
            case SSL_ERROR_SYSCALL:
                ret = get_last_socket_error();
                if (c_brief)
                    BIO_puts(bio_err, "CONNECTION CLOSED BY SERVER\n");
                else
                    BIO_printf(bio_err, "read:errno=%d\n", ret);
                goto shut;
            case SSL_ERROR_ZERO_RETURN:
                BIO_printf(bio_c_out, "closed\n");
                ret = 0;
                goto shut;
            case SSL_ERROR_SSL:
                ERR_print_errors(bio_err);
                goto shut;
            }
        }
#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)
# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)
        else if (_kbhit())
# else
        else if ((_kbhit())
                 || (WAIT_OBJECT_0 ==
                     WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))
# endif
#elif defined (OPENSSL_SYS_NETWARE)
        else if (_kbhit())
#else
        else if (FD_ISSET(fileno(stdin), &readfds))
#endif
        {
            if (crlf) {
                int j, lf_num;
                i = raw_read_stdin(cbuf, BUFSIZZ / 2);
                lf_num = 0;
                for (j = 0; j < i; j++)
                    if (cbuf[j] == '\n')
                        lf_num++;
                for (j = i - 1; j >= 0; j--) {
                    cbuf[j + lf_num] = cbuf[j];
                    if (cbuf[j] == '\n') {
                        lf_num--;
                        i++;
                        cbuf[j + lf_num] = '\r';
                    }
                }
                assert(lf_num == 0);
            } else
                i = raw_read_stdin(cbuf, BUFSIZZ);
            if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == 'Q'))) {
                BIO_printf(bio_err, "DONE\n");
                ret = 0;
                goto shut;
            }
            if ((!c_ign_eof) && (cbuf[0] == 'R')) {
                BIO_printf(bio_err, "RENEGOTIATING\n");
                SSL_renegotiate(con);
                cbuf_len = 0;
            }
#ifndef OPENSSL_NO_HEARTBEATS
            else if ((!c_ign_eof) && (cbuf[0] == 'B')) {
                BIO_printf(bio_err, "HEARTBEATING\n");
                SSL_heartbeat(con);
                cbuf_len = 0;
            }
#endif
            else {
                cbuf_len = i;
                cbuf_off = 0;
#ifdef CHARSET_EBCDIC
                ebcdic2ascii(cbuf, cbuf, i);
#endif
            }
            write_ssl = 1;
            read_tty = 0;
        }
    }
    ret = 0;
 shut:
    if (in_init)
        print_stuff(bio_c_out, con, full_log);
    SSL_shutdown(con);
    SHUTDOWN(SSL_get_fd(con));
 end:
    if (con != NULL) {
        if (prexit != 0)
            print_stuff(bio_c_out, con, 1);
        SSL_free(con);
    }
#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)
    if (next_proto.data)
        OPENSSL_free(next_proto.data);
#endif
    if (ctx != NULL)
        SSL_CTX_free(ctx);
    if (cert)
        X509_free(cert);
    if (crls)
        sk_X509_CRL_pop_free(crls, X509_CRL_free);
    if (key)
        EVP_PKEY_free(key);
    if (chain)
        sk_X509_pop_free(chain, X509_free);
    if (pass)
        OPENSSL_free(pass);
    if (vpm)
        X509_VERIFY_PARAM_free(vpm);
    ssl_excert_free(exc);
    if (ssl_args)
        sk_OPENSSL_STRING_free(ssl_args);
    if (cctx)
        SSL_CONF_CTX_free(cctx);
#ifndef OPENSSL_NO_JPAKE
    if (jpake_secret && psk_key)
        OPENSSL_free(psk_key);
#endif
    if (cbuf != NULL) {
        OPENSSL_cleanse(cbuf, BUFSIZZ);
        OPENSSL_free(cbuf);
    }
    if (sbuf != NULL) {
        OPENSSL_cleanse(sbuf, BUFSIZZ);
        OPENSSL_free(sbuf);
    }
    if (mbuf != NULL) {
        OPENSSL_cleanse(mbuf, BUFSIZZ);
        OPENSSL_free(mbuf);
    }
    if (bio_c_out != NULL) {
        BIO_free(bio_c_out);
        bio_c_out = NULL;
    }
    if (bio_c_msg != NULL) {
        BIO_free(bio_c_msg);
        bio_c_msg = NULL;
    }
    apps_shutdown();
    OPENSSL_EXIT(ret);
}
['int MAIN(int argc, char **argv)\n{\n    int build_chain = 0;\n    SSL *con = NULL;\n#ifndef OPENSSL_NO_KRB5\n    KSSL_CTX *kctx;\n#endif\n    int s, k, width, state = 0;\n    char *cbuf = NULL, *sbuf = NULL, *mbuf = NULL;\n    int cbuf_len, cbuf_off;\n    int sbuf_len, sbuf_off;\n    fd_set readfds, writefds;\n    short port = PORT;\n    int full_log = 1;\n    char *host = SSL_HOST_NAME;\n    const char *unix_path = NULL;\n    char *xmpphost = NULL;\n    char *cert_file = NULL, *key_file = NULL, *chain_file = NULL;\n    int cert_format = FORMAT_PEM, key_format = FORMAT_PEM;\n    char *passarg = NULL, *pass = NULL;\n    X509 *cert = NULL;\n    EVP_PKEY *key = NULL;\n    STACK_OF(X509) *chain = NULL;\n    char *CApath = NULL, *CAfile = NULL;\n    char *chCApath = NULL, *chCAfile = NULL;\n    char *vfyCApath = NULL, *vfyCAfile = NULL;\n    int reconnect = 0, badop = 0, verify = SSL_VERIFY_NONE;\n    int crlf = 0;\n    int write_tty, read_tty, write_ssl, read_ssl, tty_on, ssl_pending;\n    SSL_CTX *ctx = NULL;\n    int ret = 1, in_init = 1, i, nbio_test = 0;\n    int starttls_proto = PROTO_OFF;\n    int prexit = 0;\n    X509_VERIFY_PARAM *vpm = NULL;\n    int badarg = 0;\n    const SSL_METHOD *meth = NULL;\n    int socket_type = SOCK_STREAM;\n    BIO *sbio;\n    char *inrand = NULL;\n    int mbuf_len = 0;\n    struct timeval timeout, *timeoutp;\n#ifndef OPENSSL_NO_ENGINE\n    char *engine_id = NULL;\n    char *ssl_client_engine_id = NULL;\n    ENGINE *ssl_client_engine = NULL;\n#endif\n    ENGINE *e = NULL;\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n    struct timeval tv;\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n    char *servername = NULL;\n    tlsextctx tlsextcbp = { NULL, 0 };\n# ifndef OPENSSL_NO_NEXTPROTONEG\n    const char *next_proto_neg_in = NULL;\n# endif\n    const char *alpn_in = NULL;\n# define MAX_SI_TYPES 100\n    unsigned short serverinfo_types[MAX_SI_TYPES];\n    int serverinfo_types_count = 0;\n#endif\n    char *sess_in = NULL;\n    char *sess_out = NULL;\n    struct sockaddr peer;\n    int peerlen = sizeof(peer);\n    int fallback_scsv = 0;\n    int enable_timeouts = 0;\n    long socket_mtu = 0;\n#ifndef OPENSSL_NO_JPAKE\n    static 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    char *srppass = NULL;\n    int srp_lateuser = 0;\n    SRP_ARG srp_arg = { NULL, NULL, 0, 0, 0, 1024 };\n#endif\n    SSL_EXCERT *exc = NULL;\n    SSL_CONF_CTX *cctx = NULL;\n    STACK_OF(OPENSSL_STRING) *ssl_args = NULL;\n    char *crl_file = NULL;\n    int crl_format = FORMAT_PEM;\n    int crl_download = 0;\n    STACK_OF(X509_CRL) *crls = NULL;\n    int sdebug = 0;\n    meth = SSLv23_client_method();\n    apps_startup();\n    c_Pause = 0;\n    c_quiet = 0;\n    c_ign_eof = 0;\n    c_debug = 0;\n    c_msg = 0;\n    c_showcerts = 0;\n    if (bio_err == NULL)\n        bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);\n    if (!load_config(bio_err, NULL))\n        goto end;\n    cctx = SSL_CONF_CTX_new();\n    if (!cctx)\n        goto end;\n    SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CLIENT);\n    SSL_CONF_CTX_set_flags(cctx, SSL_CONF_FLAG_CMDLINE);\n    if (((cbuf = OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n        ((sbuf = OPENSSL_malloc(BUFSIZZ)) == NULL) ||\n        ((mbuf = OPENSSL_malloc(BUFSIZZ)) == NULL)) {\n        BIO_printf(bio_err, "out of memory\\n");\n        goto end;\n    }\n    verify_depth = 0;\n    verify_error = X509_V_OK;\n#ifdef FIONBIO\n    c_nbio = 0;\n#endif\n    argc--;\n    argv++;\n    while (argc >= 1) {\n        if (strcmp(*argv, "-host") == 0) {\n            if (--argc < 1)\n                goto bad;\n            host = *(++argv);\n        } else if (strcmp(*argv, "-port") == 0) {\n            if (--argc < 1)\n                goto bad;\n            port = atoi(*(++argv));\n            if (port == 0)\n                goto bad;\n        } else if (strcmp(*argv, "-connect") == 0) {\n            if (--argc < 1)\n                goto bad;\n            if (!extract_host_port(*(++argv), &host, NULL, &port))\n                goto bad;\n        } else if (strcmp(*argv, "-unix") == 0) {\n            if (--argc < 1)\n                goto bad;\n            unix_path = *(++argv);\n        } else if (strcmp(*argv, "-xmpphost") == 0) {\n            if (--argc < 1)\n                goto bad;\n            xmpphost = *(++argv);\n        } else if (strcmp(*argv, "-verify") == 0) {\n            verify = SSL_VERIFY_PEER;\n            if (--argc < 1)\n                goto bad;\n            verify_depth = atoi(*(++argv));\n            if (!c_quiet)\n                BIO_printf(bio_err, "verify depth is %d\\n", verify_depth);\n        } else if (strcmp(*argv, "-cert") == 0) {\n            if (--argc < 1)\n                goto bad;\n            cert_file = *(++argv);\n        } else if (strcmp(*argv, "-CRL") == 0) {\n            if (--argc < 1)\n                goto bad;\n            crl_file = *(++argv);\n        } else if (strcmp(*argv, "-crl_download") == 0)\n            crl_download = 1;\n        else if (strcmp(*argv, "-sess_out") == 0) {\n            if (--argc < 1)\n                goto bad;\n            sess_out = *(++argv);\n        } else if (strcmp(*argv, "-sess_in") == 0) {\n            if (--argc < 1)\n                goto bad;\n            sess_in = *(++argv);\n        } else if (strcmp(*argv, "-certform") == 0) {\n            if (--argc < 1)\n                goto bad;\n            cert_format = str2fmt(*(++argv));\n        } else if (strcmp(*argv, "-CRLform") == 0) {\n            if (--argc < 1)\n                goto bad;\n            crl_format = str2fmt(*(++argv));\n        } else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm)) {\n            if (badarg)\n                goto bad;\n            continue;\n        } else if (strcmp(*argv, "-verify_return_error") == 0)\n            verify_return_error = 1;\n        else if (strcmp(*argv, "-verify_quiet") == 0)\n            verify_quiet = 1;\n        else if (strcmp(*argv, "-brief") == 0) {\n            c_brief = 1;\n            verify_quiet = 1;\n            c_quiet = 1;\n        } else if (args_excert(&argv, &argc, &badarg, bio_err, &exc)) {\n            if (badarg)\n                goto bad;\n            continue;\n        } else if (args_ssl(&argv, &argc, cctx, &badarg, bio_err, &ssl_args)) {\n            if (badarg)\n                goto bad;\n            continue;\n        } else if (strcmp(*argv, "-prexit") == 0)\n            prexit = 1;\n        else if (strcmp(*argv, "-crlf") == 0)\n            crlf = 1;\n        else if (strcmp(*argv, "-quiet") == 0) {\n            c_quiet = 1;\n            c_ign_eof = 1;\n        } else if (strcmp(*argv, "-ign_eof") == 0)\n            c_ign_eof = 1;\n        else if (strcmp(*argv, "-no_ign_eof") == 0)\n            c_ign_eof = 0;\n        else if (strcmp(*argv, "-pause") == 0)\n            c_Pause = 1;\n        else if (strcmp(*argv, "-debug") == 0)\n            c_debug = 1;\n#ifndef OPENSSL_NO_TLSEXT\n        else if (strcmp(*argv, "-tlsextdebug") == 0)\n            c_tlsextdebug = 1;\n        else if (strcmp(*argv, "-status") == 0)\n            c_status_req = 1;\n#endif\n#ifdef WATT32\n        else if (strcmp(*argv, "-wdebug") == 0)\n            dbug_init();\n#endif\n        else if (strcmp(*argv, "-msg") == 0)\n            c_msg = 1;\n        else if (strcmp(*argv, "-msgfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            bio_c_msg = BIO_new_file(*(++argv), "w");\n        }\n#ifndef OPENSSL_NO_SSL_TRACE\n        else if (strcmp(*argv, "-trace") == 0)\n            c_msg = 2;\n#endif\n        else if (strcmp(*argv, "-security_debug") == 0) {\n            sdebug = 1;\n        } else if (strcmp(*argv, "-security_debug_verbose") == 0) {\n            sdebug = 2;\n        } else if (strcmp(*argv, "-showcerts") == 0)\n            c_showcerts = 1;\n        else if (strcmp(*argv, "-nbio_test") == 0)\n            nbio_test = 1;\n        else if (strcmp(*argv, "-state") == 0)\n            state = 1;\n#ifndef OPENSSL_NO_PSK\n        else if (strcmp(*argv, "-psk_identity") == 0) {\n            if (--argc < 1)\n                goto bad;\n            psk_identity = *(++argv);\n        } else if (strcmp(*argv, "-psk") == 0) {\n            size_t j;\n            if (--argc < 1)\n                goto bad;\n            psk_key = *(++argv);\n            for (j = 0; j < strlen(psk_key); j++) {\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        }\n#endif\n#ifndef OPENSSL_NO_SRP\n        else if (strcmp(*argv, "-srpuser") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srp_arg.srplogin = *(++argv);\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srppass") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srppass = *(++argv);\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srp_strength") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srp_arg.strength = atoi(*(++argv));\n            BIO_printf(bio_err, "SRP minimal length for N is %d\\n",\n                       srp_arg.strength);\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srp_lateuser") == 0) {\n            srp_lateuser = 1;\n            meth = TLSv1_client_method();\n        } else if (strcmp(*argv, "-srp_moregroups") == 0) {\n            srp_arg.amp = 1;\n            meth = TLSv1_client_method();\n        }\n#endif\n#ifndef OPENSSL_NO_SSL3_METHOD\n        else if (strcmp(*argv, "-ssl3") == 0)\n            meth = SSLv3_client_method();\n#endif\n#ifndef OPENSSL_NO_TLS1\n        else if (strcmp(*argv, "-tls1_2") == 0)\n            meth = TLSv1_2_client_method();\n        else if (strcmp(*argv, "-tls1_1") == 0)\n            meth = TLSv1_1_client_method();\n        else if (strcmp(*argv, "-tls1") == 0)\n            meth = TLSv1_client_method();\n#endif\n#ifndef OPENSSL_NO_DTLS1\n        else if (strcmp(*argv, "-dtls") == 0) {\n            meth = DTLS_client_method();\n            socket_type = SOCK_DGRAM;\n        } else if (strcmp(*argv, "-dtls1") == 0) {\n            meth = DTLSv1_client_method();\n            socket_type = SOCK_DGRAM;\n        } else if (strcmp(*argv, "-dtls1_2") == 0) {\n            meth = DTLSv1_2_client_method();\n            socket_type = SOCK_DGRAM;\n        } else if (strcmp(*argv, "-timeout") == 0)\n            enable_timeouts = 1;\n        else if (strcmp(*argv, "-mtu") == 0) {\n            if (--argc < 1)\n                goto bad;\n            socket_mtu = atol(*(++argv));\n        }\n#endif\n        else if (strcmp(*argv, "-fallback_scsv") == 0) {\n            fallback_scsv = 1;\n        } else if (strcmp(*argv, "-keyform") == 0) {\n            if (--argc < 1)\n                goto bad;\n            key_format = str2fmt(*(++argv));\n        } else if (strcmp(*argv, "-pass") == 0) {\n            if (--argc < 1)\n                goto bad;\n            passarg = *(++argv);\n        } else if (strcmp(*argv, "-cert_chain") == 0) {\n            if (--argc < 1)\n                goto bad;\n            chain_file = *(++argv);\n        } else if (strcmp(*argv, "-key") == 0) {\n            if (--argc < 1)\n                goto bad;\n            key_file = *(++argv);\n        } else if (strcmp(*argv, "-reconnect") == 0) {\n            reconnect = 5;\n        } else if (strcmp(*argv, "-CApath") == 0) {\n            if (--argc < 1)\n                goto bad;\n            CApath = *(++argv);\n        } else if (strcmp(*argv, "-chainCApath") == 0) {\n            if (--argc < 1)\n                goto bad;\n            chCApath = *(++argv);\n        } else if (strcmp(*argv, "-verifyCApath") == 0) {\n            if (--argc < 1)\n                goto bad;\n            vfyCApath = *(++argv);\n        } else if (strcmp(*argv, "-build_chain") == 0)\n            build_chain = 1;\n        else if (strcmp(*argv, "-CAfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            CAfile = *(++argv);\n        } else if (strcmp(*argv, "-chainCAfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            chCAfile = *(++argv);\n        } else if (strcmp(*argv, "-verifyCAfile") == 0) {\n            if (--argc < 1)\n                goto bad;\n            vfyCAfile = *(++argv);\n        }\n#ifndef OPENSSL_NO_TLSEXT\n# ifndef OPENSSL_NO_NEXTPROTONEG\n        else if (strcmp(*argv, "-nextprotoneg") == 0) {\n            if (--argc < 1)\n                goto bad;\n            next_proto_neg_in = *(++argv);\n        }\n# endif\n        else if (strcmp(*argv, "-alpn") == 0) {\n            if (--argc < 1)\n                goto bad;\n            alpn_in = *(++argv);\n        } else if (strcmp(*argv, "-serverinfo") == 0) {\n            char *c;\n            int start = 0;\n            int len;\n            if (--argc < 1)\n                goto bad;\n            c = *(++argv);\n            serverinfo_types_count = 0;\n            len = strlen(c);\n            for (i = 0; i <= len; ++i) {\n                if (i == len || c[i] == \',\') {\n                    serverinfo_types[serverinfo_types_count]\n                        = atoi(c + start);\n                    serverinfo_types_count++;\n                    start = i + 1;\n                }\n                if (serverinfo_types_count == MAX_SI_TYPES)\n                    break;\n            }\n        }\n#endif\n#ifdef FIONBIO\n        else if (strcmp(*argv, "-nbio") == 0) {\n            c_nbio = 1;\n        }\n#endif\n        else if (strcmp(*argv, "-starttls") == 0) {\n            if (--argc < 1)\n                goto bad;\n            ++argv;\n            if (strcmp(*argv, "smtp") == 0)\n                starttls_proto = PROTO_SMTP;\n            else if (strcmp(*argv, "pop3") == 0)\n                starttls_proto = PROTO_POP3;\n            else if (strcmp(*argv, "imap") == 0)\n                starttls_proto = PROTO_IMAP;\n            else if (strcmp(*argv, "ftp") == 0)\n                starttls_proto = PROTO_FTP;\n            else if (strcmp(*argv, "xmpp") == 0)\n                starttls_proto = PROTO_XMPP;\n            else\n                goto bad;\n        }\n#ifndef OPENSSL_NO_ENGINE\n        else if (strcmp(*argv, "-engine") == 0) {\n            if (--argc < 1)\n                goto bad;\n            engine_id = *(++argv);\n        } else if (strcmp(*argv, "-ssl_client_engine") == 0) {\n            if (--argc < 1)\n                goto bad;\n            ssl_client_engine_id = *(++argv);\n        }\n#endif\n        else if (strcmp(*argv, "-rand") == 0) {\n            if (--argc < 1)\n                goto bad;\n            inrand = *(++argv);\n        }\n#ifndef OPENSSL_NO_TLSEXT\n        else if (strcmp(*argv, "-servername") == 0) {\n            if (--argc < 1)\n                goto bad;\n            servername = *(++argv);\n        }\n#endif\n#ifndef OPENSSL_NO_JPAKE\n        else if (strcmp(*argv, "-jpake") == 0) {\n            if (--argc < 1)\n                goto bad;\n            jpake_secret = *++argv;\n        }\n#endif\n#ifndef OPENSSL_NO_SRTP\n        else if (strcmp(*argv, "-use_srtp") == 0) {\n            if (--argc < 1)\n                goto bad;\n            srtp_profiles = *(++argv);\n        }\n#endif\n        else if (strcmp(*argv, "-keymatexport") == 0) {\n            if (--argc < 1)\n                goto bad;\n            keymatexportlabel = *(++argv);\n        } else if (strcmp(*argv, "-keymatexportlen") == 0) {\n            if (--argc < 1)\n                goto bad;\n            keymatexportlen = atoi(*(++argv));\n            if (keymatexportlen == 0)\n                goto bad;\n        } else {\n            BIO_printf(bio_err, "unknown option %s\\n", *argv);\n            badop = 1;\n            break;\n        }\n        argc--;\n        argv++;\n    }\n    if (badop) {\n bad:\n        sc_usage();\n        goto end;\n    }\n    if (unix_path && (socket_type != SOCK_STREAM)) {\n        BIO_printf(bio_err,\n                   "Can\'t use unix sockets and datagrams together\\n");\n        goto end;\n    }\n#if !defined(OPENSSL_NO_JPAKE) && !defined(OPENSSL_NO_PSK)\n    if (jpake_secret) {\n        if (psk_key) {\n            BIO_printf(bio_err, "Can\'t use JPAKE and PSK together\\n");\n            goto end;\n        }\n        psk_identity = "JPAKE";\n    }\n#endif\n    OpenSSL_add_ssl_algorithms();\n    SSL_load_error_strings();\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n    next_proto.status = -1;\n    if (next_proto_neg_in) {\n        next_proto.data =\n            next_protos_parse(&next_proto.len, next_proto_neg_in);\n        if (next_proto.data == NULL) {\n            BIO_printf(bio_err, "Error parsing -nextprotoneg argument\\n");\n            goto end;\n        }\n    } else\n        next_proto.data = NULL;\n#endif\n#ifndef OPENSSL_NO_ENGINE\n    e = setup_engine(bio_err, engine_id, 1);\n    if (ssl_client_engine_id) {\n        ssl_client_engine = ENGINE_by_id(ssl_client_engine_id);\n        if (!ssl_client_engine) {\n            BIO_printf(bio_err, "Error getting client auth engine\\n");\n            goto end;\n        }\n    }\n#endif\n    if (!app_passwd(bio_err, passarg, NULL, &pass, NULL)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n    if (key_file == NULL)\n        key_file = cert_file;\n    if (key_file) {\n        key = load_key(bio_err, key_file, key_format, 0, pass, e,\n                       "client certificate private key file");\n        if (!key) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (cert_file) {\n        cert = load_cert(bio_err, cert_file, cert_format,\n                         NULL, e, "client certificate file");\n        if (!cert) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n    if (chain_file) {\n        chain = load_certs(bio_err, chain_file, FORMAT_PEM,\n                           NULL, e, "client certificate chain");\n        if (!chain)\n            goto end;\n    }\n    if (crl_file) {\n        X509_CRL *crl;\n        crl = load_crl(crl_file, crl_format);\n        if (!crl) {\n            BIO_puts(bio_err, "Error loading CRL\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        crls = sk_X509_CRL_new_null();\n        if (!crls || !sk_X509_CRL_push(crls, crl)) {\n            BIO_puts(bio_err, "Error adding CRL\\n");\n            ERR_print_errors(bio_err);\n            X509_CRL_free(crl);\n            goto end;\n        }\n    }\n    if (!load_excert(&exc, bio_err))\n        goto end;\n    if (!app_RAND_load_file(NULL, bio_err, 1) && inrand == NULL\n        && !RAND_status()) {\n        BIO_printf(bio_err,\n                   "warning, not much extra random data, consider using the -rand option\\n");\n    }\n    if (inrand != NULL)\n        BIO_printf(bio_err, "%ld semi-random bytes loaded\\n",\n                   app_RAND_load_files(inrand));\n    if (bio_c_out == NULL) {\n        if (c_quiet && !c_debug) {\n            bio_c_out = BIO_new(BIO_s_null());\n            if (c_msg && !bio_c_msg)\n                bio_c_msg = BIO_new_fp(stdout, BIO_NOCLOSE);\n        } else {\n            if (bio_c_out == NULL)\n                bio_c_out = BIO_new_fp(stdout, BIO_NOCLOSE);\n        }\n    }\n#ifndef OPENSSL_NO_SRP\n    if (!app_passwd(bio_err, srppass, NULL, &srp_arg.srppassin, NULL)) {\n        BIO_printf(bio_err, "Error getting password\\n");\n        goto end;\n    }\n#endif\n    ctx = SSL_CTX_new(meth);\n    if (ctx == NULL) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (sdebug)\n        ssl_ctx_security_debug(ctx, bio_err, sdebug);\n    if (vpm)\n        SSL_CTX_set1_param(ctx, vpm);\n    if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, 1, no_jpake)) {\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n    if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile,\n                         crls, crl_download)) {\n        BIO_printf(bio_err, "Error loading store locations\\n");\n        ERR_print_errors(bio_err);\n        goto end;\n    }\n#ifndef OPENSSL_NO_ENGINE\n    if (ssl_client_engine) {\n        if (!SSL_CTX_set_client_cert_engine(ctx, ssl_client_engine)) {\n            BIO_puts(bio_err, "Error setting client auth engine\\n");\n            ERR_print_errors(bio_err);\n            ENGINE_free(ssl_client_engine);\n            goto end;\n        }\n        ENGINE_free(ssl_client_engine);\n    }\n#endif\n#ifndef OPENSSL_NO_PSK\n# ifdef OPENSSL_NO_JPAKE\n    if (psk_key != NULL)\n# else\n    if (psk_key != NULL || jpake_secret)\n# endif\n    {\n        if (c_debug)\n            BIO_printf(bio_c_out,\n                       "PSK key given or JPAKE in use, setting client callback\\n");\n        SSL_CTX_set_psk_client_callback(ctx, psk_client_cb);\n    }\n#endif\n#ifndef OPENSSL_NO_SRTP\n    if (srtp_profiles != NULL)\n        SSL_CTX_set_tlsext_use_srtp(ctx, srtp_profiles);\n#endif\n    if (exc)\n        ssl_ctx_set_excert(ctx, exc);\n    if (socket_type == SOCK_DGRAM)\n        SSL_CTX_set_read_ahead(ctx, 1);\n#if !defined(OPENSSL_NO_TLSEXT)\n# if !defined(OPENSSL_NO_NEXTPROTONEG)\n    if (next_proto.data)\n        SSL_CTX_set_next_proto_select_cb(ctx, next_proto_cb, &next_proto);\n# endif\n    if (alpn_in) {\n        unsigned short alpn_len;\n        unsigned char *alpn = next_protos_parse(&alpn_len, alpn_in);\n        if (alpn == NULL) {\n            BIO_printf(bio_err, "Error parsing -alpn argument\\n");\n            goto end;\n        }\n        SSL_CTX_set_alpn_protos(ctx, alpn, alpn_len);\n        OPENSSL_free(alpn);\n    }\n#endif\n#ifndef OPENSSL_NO_TLSEXT\n    for (i = 0; i < serverinfo_types_count; i++) {\n        SSL_CTX_add_client_custom_ext(ctx,\n                                      serverinfo_types[i],\n                                      NULL, NULL, NULL,\n                                      serverinfo_cli_parse_cb, NULL);\n    }\n#endif\n    if (state)\n        SSL_CTX_set_info_callback(ctx, apps_ssl_info_callback);\n#if 0\n    else\n        SSL_CTX_set_cipher_list(ctx, getenv("SSL_CIPHER"));\n#endif\n    SSL_CTX_set_verify(ctx, verify, verify_callback);\n    if ((!SSL_CTX_load_verify_locations(ctx, CAfile, CApath)) ||\n        (!SSL_CTX_set_default_verify_paths(ctx))) {\n        ERR_print_errors(bio_err);\n    }\n    ssl_ctx_add_crls(ctx, crls, crl_download);\n    if (!set_cert_key_stuff(ctx, cert, key, chain, build_chain))\n        goto end;\n#ifndef OPENSSL_NO_TLSEXT\n    if (servername != NULL) {\n        tlsextcbp.biodebug = bio_err;\n        SSL_CTX_set_tlsext_servername_callback(ctx, ssl_servername_cb);\n        SSL_CTX_set_tlsext_servername_arg(ctx, &tlsextcbp);\n    }\n# ifndef OPENSSL_NO_SRP\n    if (srp_arg.srplogin) {\n        if (!srp_lateuser && !SSL_CTX_set_srp_username(ctx, srp_arg.srplogin)) {\n            BIO_printf(bio_err, "Unable to set SRP username\\n");\n            goto end;\n        }\n        srp_arg.msg = c_msg;\n        srp_arg.debug = c_debug;\n        SSL_CTX_set_srp_cb_arg(ctx, &srp_arg);\n        SSL_CTX_set_srp_client_pwd_callback(ctx, ssl_give_srp_client_pwd_cb);\n        SSL_CTX_set_srp_strength(ctx, srp_arg.strength);\n        if (c_msg || c_debug || srp_arg.amp == 0)\n            SSL_CTX_set_srp_verify_param_callback(ctx,\n                                                  ssl_srp_verify_param_cb);\n    }\n# endif\n#endif\n    con = SSL_new(ctx);\n    if (sess_in) {\n        SSL_SESSION *sess;\n        BIO *stmp = BIO_new_file(sess_in, "r");\n        if (!stmp) {\n            BIO_printf(bio_err, "Can\'t open session file %s\\n", sess_in);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        sess = PEM_read_bio_SSL_SESSION(stmp, NULL, 0, NULL);\n        BIO_free(stmp);\n        if (!sess) {\n            BIO_printf(bio_err, "Can\'t open session file %s\\n", sess_in);\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n        SSL_set_session(con, sess);\n        SSL_SESSION_free(sess);\n    }\n    if (fallback_scsv)\n        SSL_set_mode(con, SSL_MODE_SEND_FALLBACK_SCSV);\n#ifndef OPENSSL_NO_TLSEXT\n    if (servername != NULL) {\n        if (!SSL_set_tlsext_host_name(con, servername)) {\n            BIO_printf(bio_err, "Unable to set TLS servername extension.\\n");\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n#endif\n#ifndef OPENSSL_NO_KRB5\n    if (con && (kctx = kssl_ctx_new()) != NULL) {\n        SSL_set0_kssl_ctx(con, kctx);\n        kssl_ctx_setstring(kctx, KSSL_SERVER, host);\n    }\n#endif\n#if 0\n# ifdef TLSEXT_TYPE_opaque_prf_input\n    SSL_set_tlsext_opaque_prf_input(con, "Test client", 11);\n# endif\n#endif\n re_start:\n#ifdef NO_SYS_UN_H\n    if (init_client(&s, host, port, socket_type) == 0)\n#else\n    if ((!unix_path && (init_client(&s, host, port, socket_type) == 0)) ||\n        (unix_path && (init_client_unix(&s, unix_path) == 0)))\n#endif\n    {\n        BIO_printf(bio_err, "connect:errno=%d\\n", get_last_socket_error());\n        SHUTDOWN(s);\n        goto end;\n    }\n    BIO_printf(bio_c_out, "CONNECTED(%08X)\\n", s);\n#ifdef FIONBIO\n    if (c_nbio) {\n        unsigned long l = 1;\n        BIO_printf(bio_c_out, "turning on non blocking io\\n");\n        if (BIO_socket_ioctl(s, FIONBIO, &l) < 0) {\n            ERR_print_errors(bio_err);\n            goto end;\n        }\n    }\n#endif\n    if (c_Pause & 0x01)\n        SSL_set_debug(con, 1);\n    if (socket_type == SOCK_DGRAM) {\n        sbio = BIO_new_dgram(s, BIO_NOCLOSE);\n        if (getsockname(s, &peer, (void *)&peerlen) < 0) {\n            BIO_printf(bio_err, "getsockname:errno=%d\\n",\n                       get_last_socket_error());\n            SHUTDOWN(s);\n            goto end;\n        }\n        (void)BIO_ctrl_set_connected(sbio, 1, &peer);\n        if (enable_timeouts) {\n            timeout.tv_sec = 0;\n            timeout.tv_usec = DGRAM_RCV_TIMEOUT;\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_RECV_TIMEOUT, 0, &timeout);\n            timeout.tv_sec = 0;\n            timeout.tv_usec = DGRAM_SND_TIMEOUT;\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_SET_SEND_TIMEOUT, 0, &timeout);\n        }\n        if (socket_mtu) {\n            if (socket_mtu < DTLS_get_link_min_mtu(con)) {\n                BIO_printf(bio_err, "MTU too small. Must be at least %ld\\n",\n                           DTLS_get_link_min_mtu(con));\n                BIO_free(sbio);\n                goto shut;\n            }\n            SSL_set_options(con, SSL_OP_NO_QUERY_MTU);\n            if (!DTLS_set_link_mtu(con, socket_mtu)) {\n                BIO_printf(bio_err, "Failed to set MTU\\n");\n                BIO_free(sbio);\n                goto shut;\n            }\n        } else\n            BIO_ctrl(sbio, BIO_CTRL_DGRAM_MTU_DISCOVER, 0, NULL);\n    } else\n        sbio = BIO_new_socket(s, BIO_NOCLOSE);\n    if (nbio_test) {\n        BIO *test;\n        test = BIO_new(BIO_f_nbio_test());\n        sbio = BIO_push(test, sbio);\n    }\n    if (c_debug) {\n        SSL_set_debug(con, 1);\n        BIO_set_callback(sbio, bio_dump_callback);\n        BIO_set_callback_arg(sbio, (char *)bio_c_out);\n    }\n    if (c_msg) {\n#ifndef OPENSSL_NO_SSL_TRACE\n        if (c_msg == 2)\n            SSL_set_msg_callback(con, SSL_trace);\n        else\n#endif\n            SSL_set_msg_callback(con, msg_cb);\n        SSL_set_msg_callback_arg(con, bio_c_msg ? bio_c_msg : bio_c_out);\n    }\n#ifndef OPENSSL_NO_TLSEXT\n    if (c_tlsextdebug) {\n        SSL_set_tlsext_debug_callback(con, tlsext_cb);\n        SSL_set_tlsext_debug_arg(con, bio_c_out);\n    }\n    if (c_status_req) {\n        SSL_set_tlsext_status_type(con, TLSEXT_STATUSTYPE_ocsp);\n        SSL_CTX_set_tlsext_status_cb(ctx, ocsp_resp_cb);\n        SSL_CTX_set_tlsext_status_arg(ctx, bio_c_out);\n# if 0\n        {\n            STACK_OF(OCSP_RESPID) *ids = sk_OCSP_RESPID_new_null();\n            OCSP_RESPID *id = OCSP_RESPID_new();\n            id->value.byKey = ASN1_OCTET_STRING_new();\n            id->type = V_OCSP_RESPID_KEY;\n            ASN1_STRING_set(id->value.byKey, "Hello World", -1);\n            sk_OCSP_RESPID_push(ids, id);\n            SSL_set_tlsext_status_ids(con, ids);\n        }\n# endif\n    }\n#endif\n#ifndef OPENSSL_NO_JPAKE\n    if (jpake_secret)\n        jpake_client_auth(bio_c_out, sbio, jpake_secret);\n#endif\n    SSL_set_bio(con, sbio, sbio);\n    SSL_set_connect_state(con);\n    width = SSL_get_fd(con) + 1;\n    read_tty = 1;\n    write_tty = 0;\n    tty_on = 0;\n    read_ssl = 1;\n    write_ssl = 1;\n    cbuf_len = 0;\n    cbuf_off = 0;\n    sbuf_len = 0;\n    sbuf_off = 0;\n    if (starttls_proto == PROTO_SMTP) {\n        int foundit = 0;\n        BIO *fbio = BIO_new(BIO_f_buffer());\n        BIO_push(fbio, sbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n        }\n        while (mbuf_len > 3 && mbuf[3] == \'-\');\n        BIO_printf(fbio, "EHLO openssl.client.net\\r\\n");\n        (void)BIO_flush(fbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n            if (strstr(mbuf, "STARTTLS"))\n                foundit = 1;\n        }\n        while (mbuf_len > 3 && mbuf[3] == \'-\');\n        (void)BIO_flush(fbio);\n        BIO_pop(fbio);\n        BIO_free(fbio);\n        if (!foundit)\n            BIO_printf(bio_err,\n                       "didn\'t found starttls in server response,"\n                       " try anyway...\\n");\n        BIO_printf(sbio, "STARTTLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    } else if (starttls_proto == PROTO_POP3) {\n        BIO_read(sbio, mbuf, BUFSIZZ);\n        BIO_printf(sbio, "STLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    } else if (starttls_proto == PROTO_IMAP) {\n        int foundit = 0;\n        BIO *fbio = BIO_new(BIO_f_buffer());\n        BIO_push(fbio, sbio);\n        BIO_gets(fbio, mbuf, BUFSIZZ);\n        BIO_printf(fbio, ". CAPABILITY\\r\\n");\n        (void)BIO_flush(fbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n            if (strstr(mbuf, "STARTTLS"))\n                foundit = 1;\n        }\n        while (mbuf_len > 3 && mbuf[0] != \'.\');\n        (void)BIO_flush(fbio);\n        BIO_pop(fbio);\n        BIO_free(fbio);\n        if (!foundit)\n            BIO_printf(bio_err,\n                       "didn\'t found STARTTLS in server response,"\n                       " try anyway...\\n");\n        BIO_printf(sbio, ". STARTTLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    } else if (starttls_proto == PROTO_FTP) {\n        BIO *fbio = BIO_new(BIO_f_buffer());\n        BIO_push(fbio, sbio);\n        do {\n            mbuf_len = BIO_gets(fbio, mbuf, BUFSIZZ);\n        }\n        while (mbuf_len > 3 && mbuf[3] == \'-\');\n        (void)BIO_flush(fbio);\n        BIO_pop(fbio);\n        BIO_free(fbio);\n        BIO_printf(sbio, "AUTH TLS\\r\\n");\n        BIO_read(sbio, sbuf, BUFSIZZ);\n    }\n    if (starttls_proto == PROTO_XMPP) {\n        int seen = 0;\n        BIO_printf(sbio, "<stream:stream "\n                   "xmlns:stream=\'http://etherx.jabber.org/streams\' "\n                   "xmlns=\'jabber:client\' to=\'%s\' version=\'1.0\'>", xmpphost ?\n                   xmpphost : host);\n        seen = BIO_read(sbio, mbuf, BUFSIZZ);\n        mbuf[seen] = 0;\n        while (!strstr\n               (mbuf, "<starttls xmlns=\'urn:ietf:params:xml:ns:xmpp-tls\'")\n               && !strstr(mbuf,\n                          "<starttls xmlns=\\"urn:ietf:params:xml:ns:xmpp-tls\\""))\n        {\n            seen = BIO_read(sbio, mbuf, BUFSIZZ);\n            if (seen <= 0)\n                goto shut;\n            mbuf[seen] = 0;\n        }\n        BIO_printf(sbio,\n                   "<starttls xmlns=\'urn:ietf:params:xml:ns:xmpp-tls\'/>");\n        seen = BIO_read(sbio, sbuf, BUFSIZZ);\n        sbuf[seen] = 0;\n        if (!strstr(sbuf, "<proceed"))\n            goto shut;\n        mbuf[0] = 0;\n    }\n    for (;;) {\n        FD_ZERO(&readfds);\n        FD_ZERO(&writefds);\n        if ((SSL_version(con) == DTLS1_VERSION) &&\n            DTLSv1_get_timeout(con, &timeout))\n            timeoutp = &timeout;\n        else\n            timeoutp = NULL;\n        if (SSL_in_init(con) && !SSL_total_renegotiations(con)) {\n            in_init = 1;\n            tty_on = 0;\n        } else {\n            tty_on = 1;\n            if (in_init) {\n                in_init = 0;\n#if 0\n# ifndef OPENSSL_NO_TLSEXT\n                if (servername != NULL && !SSL_session_reused(con)) {\n                    BIO_printf(bio_c_out,\n                               "Server did %sacknowledge servername extension.\\n",\n                               tlsextcbp.ack ? "" : "not ");\n                }\n# endif\n#endif\n                if (sess_out) {\n                    BIO *stmp = BIO_new_file(sess_out, "w");\n                    if (stmp) {\n                        PEM_write_bio_SSL_SESSION(stmp, SSL_get_session(con));\n                        BIO_free(stmp);\n                    } else\n                        BIO_printf(bio_err, "Error writing session file %s\\n",\n                                   sess_out);\n                }\n                if (c_brief) {\n                    BIO_puts(bio_err, "CONNECTION ESTABLISHED\\n");\n                    print_ssl_summary(bio_err, con);\n                }\n                print_stuff(bio_c_out, con, full_log);\n                if (full_log > 0)\n                    full_log--;\n                if (starttls_proto) {\n                    BIO_printf(bio_err, "%s", mbuf);\n                    starttls_proto = PROTO_OFF;\n                }\n                if (reconnect) {\n                    reconnect--;\n                    BIO_printf(bio_c_out,\n                               "drop connection and then reconnect\\n");\n                    SSL_shutdown(con);\n                    SSL_set_connect_state(con);\n                    SHUTDOWN(SSL_get_fd(con));\n                    goto re_start;\n                }\n            }\n        }\n        ssl_pending = read_ssl && SSL_pending(con);\n        if (!ssl_pending) {\n#if !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_NETWARE)\n            if (tty_on) {\n                if (read_tty)\n                    openssl_fdset(fileno(stdin), &readfds);\n                if (write_tty)\n                    openssl_fdset(fileno(stdout), &writefds);\n            }\n            if (read_ssl)\n                openssl_fdset(SSL_get_fd(con), &readfds);\n            if (write_ssl)\n                openssl_fdset(SSL_get_fd(con), &writefds);\n#else\n            if (!tty_on || !write_tty) {\n                if (read_ssl)\n                    openssl_fdset(SSL_get_fd(con), &readfds);\n                if (write_ssl)\n                    openssl_fdset(SSL_get_fd(con), &writefds);\n            }\n#endif\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n            i = 0;\n            if (!write_tty) {\n                if (read_tty) {\n                    tv.tv_sec = 1;\n                    tv.tv_usec = 0;\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, &tv);\n# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)\n                    if (!i && (!_kbhit() || !read_tty))\n                        continue;\n# else\n                    if (!i && (!((_kbhit())\n                                 || (WAIT_OBJECT_0 ==\n                                     WaitForSingleObject(GetStdHandle\n                                                         (STD_INPUT_HANDLE),\n                                                         0)))\n                               || !read_tty))\n                        continue;\n# endif\n                } else\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, timeoutp);\n            }\n#elif defined(OPENSSL_SYS_NETWARE)\n            if (!write_tty) {\n                if (read_tty) {\n                    tv.tv_sec = 1;\n                    tv.tv_usec = 0;\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, &tv);\n                } else\n                    i = select(width, (void *)&readfds, (void *)&writefds,\n                               NULL, timeoutp);\n            }\n#else\n            i = select(width, (void *)&readfds, (void *)&writefds,\n                       NULL, timeoutp);\n#endif\n            if (i < 0) {\n                BIO_printf(bio_err, "bad select %d\\n",\n                           get_last_socket_error());\n                goto shut;\n            }\n        }\n        if ((SSL_version(con) == DTLS1_VERSION)\n            && DTLSv1_handle_timeout(con) > 0) {\n            BIO_printf(bio_err, "TIMEOUT occurred\\n");\n        }\n        if (!ssl_pending && FD_ISSET(SSL_get_fd(con), &writefds)) {\n            k = SSL_write(con, &(cbuf[cbuf_off]), (unsigned int)cbuf_len);\n            switch (SSL_get_error(con, k)) {\n            case SSL_ERROR_NONE:\n                cbuf_off += k;\n                cbuf_len -= k;\n                if (k <= 0)\n                    goto end;\n                if (cbuf_len <= 0) {\n                    read_tty = 1;\n                    write_ssl = 0;\n                } else {\n                    read_tty = 0;\n                    write_ssl = 1;\n                }\n                break;\n            case SSL_ERROR_WANT_WRITE:\n                BIO_printf(bio_c_out, "write W BLOCK\\n");\n                write_ssl = 1;\n                read_tty = 0;\n                break;\n            case SSL_ERROR_WANT_READ:\n                BIO_printf(bio_c_out, "write R BLOCK\\n");\n                write_tty = 0;\n                read_ssl = 1;\n                write_ssl = 0;\n                break;\n            case SSL_ERROR_WANT_X509_LOOKUP:\n                BIO_printf(bio_c_out, "write X BLOCK\\n");\n                break;\n            case SSL_ERROR_ZERO_RETURN:\n                if (cbuf_len != 0) {\n                    BIO_printf(bio_c_out, "shutdown\\n");\n                    ret = 0;\n                    goto shut;\n                } else {\n                    read_tty = 1;\n                    write_ssl = 0;\n                    break;\n                }\n            case SSL_ERROR_SYSCALL:\n                if ((k != 0) || (cbuf_len != 0)) {\n                    BIO_printf(bio_err, "write:errno=%d\\n",\n                               get_last_socket_error());\n                    goto shut;\n                } else {\n                    read_tty = 1;\n                    write_ssl = 0;\n                }\n                break;\n            case SSL_ERROR_SSL:\n                ERR_print_errors(bio_err);\n                goto shut;\n            }\n        }\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_NETWARE)\n        else if (!ssl_pending && write_tty)\n#else\n        else if (!ssl_pending && FD_ISSET(fileno(stdout), &writefds))\n#endif\n        {\n#ifdef CHARSET_EBCDIC\n            ascii2ebcdic(&(sbuf[sbuf_off]), &(sbuf[sbuf_off]), sbuf_len);\n#endif\n            i = raw_write_stdout(&(sbuf[sbuf_off]), sbuf_len);\n            if (i <= 0) {\n                BIO_printf(bio_c_out, "DONE\\n");\n                ret = 0;\n                goto shut;\n            }\n            sbuf_len -= i;;\n            sbuf_off += i;\n            if (sbuf_len <= 0) {\n                read_ssl = 1;\n                write_tty = 0;\n            }\n        } else if (ssl_pending || FD_ISSET(SSL_get_fd(con), &readfds)) {\n#ifdef RENEG\n            {\n                static int iiii;\n                if (++iiii == 52) {\n                    SSL_renegotiate(con);\n                    iiii = 0;\n                }\n            }\n#endif\n#if 1\n            k = SSL_read(con, sbuf, 1024   );\n#else\n            k = SSL_read(con, sbuf, 16);\n            {\n                char zbuf[10240];\n                printf("read=%d pending=%d peek=%d\\n", k, SSL_pending(con),\n                       SSL_peek(con, zbuf, 10240));\n            }\n#endif\n            switch (SSL_get_error(con, k)) {\n            case SSL_ERROR_NONE:\n                if (k <= 0)\n                    goto end;\n                sbuf_off = 0;\n                sbuf_len = k;\n                read_ssl = 0;\n                write_tty = 1;\n                break;\n            case SSL_ERROR_WANT_WRITE:\n                BIO_printf(bio_c_out, "read W BLOCK\\n");\n                write_ssl = 1;\n                read_tty = 0;\n                break;\n            case SSL_ERROR_WANT_READ:\n                BIO_printf(bio_c_out, "read R BLOCK\\n");\n                write_tty = 0;\n                read_ssl = 1;\n                if ((read_tty == 0) && (write_ssl == 0))\n                    write_ssl = 1;\n                break;\n            case SSL_ERROR_WANT_X509_LOOKUP:\n                BIO_printf(bio_c_out, "read X BLOCK\\n");\n                break;\n            case SSL_ERROR_SYSCALL:\n                ret = get_last_socket_error();\n                if (c_brief)\n                    BIO_puts(bio_err, "CONNECTION CLOSED BY SERVER\\n");\n                else\n                    BIO_printf(bio_err, "read:errno=%d\\n", ret);\n                goto shut;\n            case SSL_ERROR_ZERO_RETURN:\n                BIO_printf(bio_c_out, "closed\\n");\n                ret = 0;\n                goto shut;\n            case SSL_ERROR_SSL:\n                ERR_print_errors(bio_err);\n                goto shut;\n            }\n        }\n#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_MSDOS)\n# if defined(OPENSSL_SYS_WINCE) || defined(OPENSSL_SYS_MSDOS)\n        else if (_kbhit())\n# else\n        else if ((_kbhit())\n                 || (WAIT_OBJECT_0 ==\n                     WaitForSingleObject(GetStdHandle(STD_INPUT_HANDLE), 0)))\n# endif\n#elif defined (OPENSSL_SYS_NETWARE)\n        else if (_kbhit())\n#else\n        else if (FD_ISSET(fileno(stdin), &readfds))\n#endif\n        {\n            if (crlf) {\n                int j, lf_num;\n                i = raw_read_stdin(cbuf, BUFSIZZ / 2);\n                lf_num = 0;\n                for (j = 0; j < i; j++)\n                    if (cbuf[j] == \'\\n\')\n                        lf_num++;\n                for (j = i - 1; j >= 0; j--) {\n                    cbuf[j + lf_num] = cbuf[j];\n                    if (cbuf[j] == \'\\n\') {\n                        lf_num--;\n                        i++;\n                        cbuf[j + lf_num] = \'\\r\';\n                    }\n                }\n                assert(lf_num == 0);\n            } else\n                i = raw_read_stdin(cbuf, BUFSIZZ);\n            if ((!c_ign_eof) && ((i <= 0) || (cbuf[0] == \'Q\'))) {\n                BIO_printf(bio_err, "DONE\\n");\n                ret = 0;\n                goto shut;\n            }\n            if ((!c_ign_eof) && (cbuf[0] == \'R\')) {\n                BIO_printf(bio_err, "RENEGOTIATING\\n");\n                SSL_renegotiate(con);\n                cbuf_len = 0;\n            }\n#ifndef OPENSSL_NO_HEARTBEATS\n            else if ((!c_ign_eof) && (cbuf[0] == \'B\')) {\n                BIO_printf(bio_err, "HEARTBEATING\\n");\n                SSL_heartbeat(con);\n                cbuf_len = 0;\n            }\n#endif\n            else {\n                cbuf_len = i;\n                cbuf_off = 0;\n#ifdef CHARSET_EBCDIC\n                ebcdic2ascii(cbuf, cbuf, i);\n#endif\n            }\n            write_ssl = 1;\n            read_tty = 0;\n        }\n    }\n    ret = 0;\n shut:\n    if (in_init)\n        print_stuff(bio_c_out, con, full_log);\n    SSL_shutdown(con);\n    SHUTDOWN(SSL_get_fd(con));\n end:\n    if (con != NULL) {\n        if (prexit != 0)\n            print_stuff(bio_c_out, con, 1);\n        SSL_free(con);\n    }\n#if !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG)\n    if (next_proto.data)\n        OPENSSL_free(next_proto.data);\n#endif\n    if (ctx != NULL)\n        SSL_CTX_free(ctx);\n    if (cert)\n        X509_free(cert);\n    if (crls)\n        sk_X509_CRL_pop_free(crls, X509_CRL_free);\n    if (key)\n        EVP_PKEY_free(key);\n    if (chain)\n        sk_X509_pop_free(chain, X509_free);\n    if (pass)\n        OPENSSL_free(pass);\n    if (vpm)\n        X509_VERIFY_PARAM_free(vpm);\n    ssl_excert_free(exc);\n    if (ssl_args)\n        sk_OPENSSL_STRING_free(ssl_args);\n    if (cctx)\n        SSL_CONF_CTX_free(cctx);\n#ifndef OPENSSL_NO_JPAKE\n    if (jpake_secret && psk_key)\n        OPENSSL_free(psk_key);\n#endif\n    if (cbuf != NULL) {\n        OPENSSL_cleanse(cbuf, BUFSIZZ);\n        OPENSSL_free(cbuf);\n    }\n    if (sbuf != NULL) {\n        OPENSSL_cleanse(sbuf, BUFSIZZ);\n        OPENSSL_free(sbuf);\n    }\n    if (mbuf != NULL) {\n        OPENSSL_cleanse(mbuf, BUFSIZZ);\n        OPENSSL_free(mbuf);\n    }\n    if (bio_c_out != NULL) {\n        BIO_free(bio_c_out);\n        bio_c_out = NULL;\n    }\n    if (bio_c_msg != NULL) {\n        BIO_free(bio_c_msg);\n        bio_c_msg = NULL;\n    }\n    apps_shutdown();\n    OPENSSL_EXIT(ret);\n}']