char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)
{
    const X509_NAME_ENTRY *ne;
    int i;
    int n, lold, l, l1, l2, num, j, type;
    const char *s;
    char *p;
    unsigned char *q;
    BUF_MEM *b = NULL;
    static const char hex[17] = "0123456789ABCDEF";
    int gs_doit[4];
    char tmp_buf[80];
#ifdef CHARSET_EBCDIC
    unsigned char ebcdic_buf[1024];
#endif
    if (buf == NULL) {
        if ((b = BUF_MEM_new()) == NULL)
            goto err;
        if (!BUF_MEM_grow(b, 200))
            goto err;
        b->data[0] = '\0';
        len = 200;
    } else if (len == 0) {
        return NULL;
    }
    if (a == NULL) {
        if (b) {
            buf = b->data;
            OPENSSL_free(b);
        }
        strncpy(buf, "NO X509_NAME", len);
        buf[len - 1] = '\0';
        return buf;
    }
    len--;
    l = 0;
    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
        ne = sk_X509_NAME_ENTRY_value(a->entries, i);
        n = OBJ_obj2nid(ne->object);
        if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {
            i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);
            s = tmp_buf;
        }
        l1 = strlen(s);
        type = ne->value->type;
        num = ne->value->length;
        if (num > NAME_ONELINE_MAX) {
            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
            goto end;
        }
        q = ne->value->data;
#ifdef CHARSET_EBCDIC
        if (type == V_ASN1_GENERALSTRING ||
            type == V_ASN1_VISIBLESTRING ||
            type == V_ASN1_PRINTABLESTRING ||
            type == V_ASN1_TELETEXSTRING ||
            type == V_ASN1_IA5STRING) {
            if (num > (int)sizeof(ebcdic_buf))
                num = sizeof(ebcdic_buf);
            ascii2ebcdic(ebcdic_buf, q, num);
            q = ebcdic_buf;
        }
#endif
        if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {
            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;
            for (j = 0; j < num; j++)
                if (q[j] != 0)
                    gs_doit[j & 3] = 1;
            if (gs_doit[0] | gs_doit[1] | gs_doit[2])
                gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
            else {
                gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;
                gs_doit[3] = 1;
            }
        } else
            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;
        for (l2 = j = 0; j < num; j++) {
            if (!gs_doit[j & 3])
                continue;
            l2++;
#ifndef CHARSET_EBCDIC
            if ((q[j] < ' ') || (q[j] > '~'))
                l2 += 3;
#else
            if ((os_toascii[q[j]] < os_toascii[' ']) ||
                (os_toascii[q[j]] > os_toascii['~']))
                l2 += 3;
#endif
        }
        lold = l;
        l += 1 + l1 + 1 + l2;
        if (l > NAME_ONELINE_MAX) {
            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);
            goto end;
        }
        if (b != NULL) {
            if (!BUF_MEM_grow(b, l + 1))
                goto err;
            p = &(b->data[lold]);
        } else if (l > len) {
            break;
        } else
            p = &(buf[lold]);
        *(p++) = '/';
        memcpy(p, s, (unsigned int)l1);
        p += l1;
        *(p++) = '=';
#ifndef CHARSET_EBCDIC
        q = ne->value->data;
#endif
        for (j = 0; j < num; j++) {
            if (!gs_doit[j & 3])
                continue;
#ifndef CHARSET_EBCDIC
            n = q[j];
            if ((n < ' ') || (n > '~')) {
                *(p++) = '\\';
                *(p++) = 'x';
                *(p++) = hex[(n >> 4) & 0x0f];
                *(p++) = hex[n & 0x0f];
            } else
                *(p++) = n;
#else
            n = os_toascii[q[j]];
            if ((n < os_toascii[' ']) || (n > os_toascii['~'])) {
                *(p++) = '\\';
                *(p++) = 'x';
                *(p++) = hex[(n >> 4) & 0x0f];
                *(p++) = hex[n & 0x0f];
            } else
                *(p++) = q[j];
#endif
        }
        *p = '\0';
    }
    if (b != NULL) {
        p = b->data;
        OPENSSL_free(b);
    } else
        p = buf;
    if (i == 0)
        *p = '\0';
    return (p);
 err:
    X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);
 end:
    BUF_MEM_free(b);
    return (NULL);
}
['static int init_ssl_connection(SSL *con)\n{\n    int i;\n    const char *str;\n    X509 *peer;\n    long verify_err;\n    char buf[BUFSIZ];\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    const unsigned char *next_proto_neg;\n    unsigned next_proto_neg_len;\n#endif\n    unsigned char *exportedkeymat;\n    int retry = 0;\n#ifndef OPENSSL_NO_DTLS\n    if (dtlslisten) {\n        BIO_ADDR *client = NULL;\n        if ((client = BIO_ADDR_new()) == NULL) {\n            BIO_printf(bio_err, "ERROR - memory\\n");\n            return 0;\n        }\n        i = DTLSv1_listen(con, client);\n        if (i > 0) {\n            BIO *wbio;\n            int fd = -1;\n            wbio = SSL_get_wbio(con);\n            if (wbio) {\n                BIO_get_fd(wbio, &fd);\n            }\n            if (!wbio || BIO_connect(fd, client, 0) == 0) {\n                BIO_printf(bio_err, "ERROR - unable to connect\\n");\n                BIO_ADDR_free(client);\n                return 0;\n            }\n            BIO_ADDR_free(client);\n            dtlslisten = 0;\n            i = SSL_accept(con);\n        } else {\n            BIO_ADDR_free(client);\n        }\n    } else\n#endif\n    do {\n        i = SSL_accept(con);\n        if (i <= 0)\n            retry = BIO_sock_should_retry(i);\n#ifdef CERT_CB_TEST_RETRY\n        {\n            while (i <= 0\n                    && SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP\n                    && SSL_get_state(con) == TLS_ST_SR_CLNT_HELLO) {\n                BIO_printf(bio_err,\n                           "LOOKUP from certificate callback during accept\\n");\n                i = SSL_accept(con);\n                if (i <= 0)\n                    retry = BIO_sock_should_retry(i);\n            }\n        }\n#endif\n#ifndef OPENSSL_NO_SRP\n        while (i <= 0\n               && SSL_get_error(con, i) == SSL_ERROR_WANT_X509_LOOKUP) {\n            BIO_printf(bio_s_out, "LOOKUP during accept %s\\n",\n                       srp_callback_parm.login);\n            SRP_user_pwd_free(srp_callback_parm.user);\n            srp_callback_parm.user =\n                SRP_VBASE_get1_by_user(srp_callback_parm.vb,\n                                       srp_callback_parm.login);\n            if (srp_callback_parm.user)\n                BIO_printf(bio_s_out, "LOOKUP done %s\\n",\n                           srp_callback_parm.user->info);\n            else\n                BIO_printf(bio_s_out, "LOOKUP not successful\\n");\n            i = SSL_accept(con);\n            if (i <= 0)\n                retry = BIO_sock_should_retry(i);\n        }\n#endif\n    } while (i < 0 && SSL_waiting_for_async(con));\n    if (i <= 0) {\n        if ((dtlslisten && i == 0)\n                || (!dtlslisten && retry)) {\n            BIO_printf(bio_s_out, "DELAY\\n");\n            return (1);\n        }\n        BIO_printf(bio_err, "ERROR\\n");\n        verify_err = SSL_get_verify_result(con);\n        if (verify_err != X509_V_OK) {\n            BIO_printf(bio_err, "verify error:%s\\n",\n                       X509_verify_cert_error_string(verify_err));\n        }\n        ERR_print_errors(bio_err);\n        return (0);\n    }\n    if (s_brief)\n        print_ssl_summary(con);\n    PEM_write_bio_SSL_SESSION(bio_s_out, SSL_get_session(con));\n    peer = SSL_get_peer_certificate(con);\n    if (peer != NULL) {\n        BIO_printf(bio_s_out, "Client certificate\\n");\n        PEM_write_bio_X509(bio_s_out, peer);\n        X509_NAME_oneline(X509_get_subject_name(peer), buf, sizeof buf);\n        BIO_printf(bio_s_out, "subject=%s\\n", buf);\n        X509_NAME_oneline(X509_get_issuer_name(peer), buf, sizeof buf);\n        BIO_printf(bio_s_out, "issuer=%s\\n", buf);\n        X509_free(peer);\n        peer = NULL;\n    }\n    if (SSL_get_shared_ciphers(con, buf, sizeof buf) != NULL)\n        BIO_printf(bio_s_out, "Shared ciphers:%s\\n", buf);\n    str = SSL_CIPHER_get_name(SSL_get_current_cipher(con));\n    ssl_print_sigalgs(bio_s_out, con);\n#ifndef OPENSSL_NO_EC\n    ssl_print_point_formats(bio_s_out, con);\n    ssl_print_curves(bio_s_out, con, 0);\n#endif\n    BIO_printf(bio_s_out, "CIPHER is %s\\n", (str != NULL) ? str : "(NONE)");\n#if !defined(OPENSSL_NO_NEXTPROTONEG)\n    SSL_get0_next_proto_negotiated(con, &next_proto_neg, &next_proto_neg_len);\n    if (next_proto_neg) {\n        BIO_printf(bio_s_out, "NEXTPROTO is ");\n        BIO_write(bio_s_out, next_proto_neg, next_proto_neg_len);\n        BIO_printf(bio_s_out, "\\n");\n    }\n#endif\n#ifndef OPENSSL_NO_SRTP\n    {\n        SRTP_PROTECTION_PROFILE *srtp_profile\n            = SSL_get_selected_srtp_profile(con);\n        if (srtp_profile)\n            BIO_printf(bio_s_out, "SRTP Extension negotiated, profile=%s\\n",\n                       srtp_profile->name);\n    }\n#endif\n    if (SSL_session_reused(con))\n        BIO_printf(bio_s_out, "Reused session-id\\n");\n    BIO_printf(bio_s_out, "Secure Renegotiation IS%s supported\\n",\n               SSL_get_secure_renegotiation_support(con) ? "" : " NOT");\n    if (keymatexportlabel != NULL) {\n        BIO_printf(bio_s_out, "Keying material exporter:\\n");\n        BIO_printf(bio_s_out, "    Label: \'%s\'\\n", keymatexportlabel);\n        BIO_printf(bio_s_out, "    Length: %i bytes\\n", keymatexportlen);\n        exportedkeymat = app_malloc(keymatexportlen, "export key");\n        if (!SSL_export_keying_material(con, exportedkeymat,\n                                        keymatexportlen,\n                                        keymatexportlabel,\n                                        strlen(keymatexportlabel),\n                                        NULL, 0, 0)) {\n            BIO_printf(bio_s_out, "    Error\\n");\n        } else {\n            BIO_printf(bio_s_out, "    Keying material: ");\n            for (i = 0; i < keymatexportlen; i++)\n                BIO_printf(bio_s_out, "%02X", exportedkeymat[i]);\n            BIO_printf(bio_s_out, "\\n");\n        }\n        OPENSSL_free(exportedkeymat);\n    }\n    (void)BIO_flush(bio_s_out);\n    return (1);\n}', 'char *X509_NAME_oneline(const X509_NAME *a, char *buf, int len)\n{\n    const X509_NAME_ENTRY *ne;\n    int i;\n    int n, lold, l, l1, l2, num, j, type;\n    const char *s;\n    char *p;\n    unsigned char *q;\n    BUF_MEM *b = NULL;\n    static const char hex[17] = "0123456789ABCDEF";\n    int gs_doit[4];\n    char tmp_buf[80];\n#ifdef CHARSET_EBCDIC\n    unsigned char ebcdic_buf[1024];\n#endif\n    if (buf == NULL) {\n        if ((b = BUF_MEM_new()) == NULL)\n            goto err;\n        if (!BUF_MEM_grow(b, 200))\n            goto err;\n        b->data[0] = \'\\0\';\n        len = 200;\n    } else if (len == 0) {\n        return NULL;\n    }\n    if (a == NULL) {\n        if (b) {\n            buf = b->data;\n            OPENSSL_free(b);\n        }\n        strncpy(buf, "NO X509_NAME", len);\n        buf[len - 1] = \'\\0\';\n        return buf;\n    }\n    len--;\n    l = 0;\n    for (i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {\n        ne = sk_X509_NAME_ENTRY_value(a->entries, i);\n        n = OBJ_obj2nid(ne->object);\n        if ((n == NID_undef) || ((s = OBJ_nid2sn(n)) == NULL)) {\n            i2t_ASN1_OBJECT(tmp_buf, sizeof(tmp_buf), ne->object);\n            s = tmp_buf;\n        }\n        l1 = strlen(s);\n        type = ne->value->type;\n        num = ne->value->length;\n        if (num > NAME_ONELINE_MAX) {\n            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n            goto end;\n        }\n        q = ne->value->data;\n#ifdef CHARSET_EBCDIC\n        if (type == V_ASN1_GENERALSTRING ||\n            type == V_ASN1_VISIBLESTRING ||\n            type == V_ASN1_PRINTABLESTRING ||\n            type == V_ASN1_TELETEXSTRING ||\n            type == V_ASN1_IA5STRING) {\n            if (num > (int)sizeof(ebcdic_buf))\n                num = sizeof(ebcdic_buf);\n            ascii2ebcdic(ebcdic_buf, q, num);\n            q = ebcdic_buf;\n        }\n#endif\n        if ((type == V_ASN1_GENERALSTRING) && ((num % 4) == 0)) {\n            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 0;\n            for (j = 0; j < num; j++)\n                if (q[j] != 0)\n                    gs_doit[j & 3] = 1;\n            if (gs_doit[0] | gs_doit[1] | gs_doit[2])\n                gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n            else {\n                gs_doit[0] = gs_doit[1] = gs_doit[2] = 0;\n                gs_doit[3] = 1;\n            }\n        } else\n            gs_doit[0] = gs_doit[1] = gs_doit[2] = gs_doit[3] = 1;\n        for (l2 = j = 0; j < num; j++) {\n            if (!gs_doit[j & 3])\n                continue;\n            l2++;\n#ifndef CHARSET_EBCDIC\n            if ((q[j] < \' \') || (q[j] > \'~\'))\n                l2 += 3;\n#else\n            if ((os_toascii[q[j]] < os_toascii[\' \']) ||\n                (os_toascii[q[j]] > os_toascii[\'~\']))\n                l2 += 3;\n#endif\n        }\n        lold = l;\n        l += 1 + l1 + 1 + l2;\n        if (l > NAME_ONELINE_MAX) {\n            X509err(X509_F_X509_NAME_ONELINE, X509_R_NAME_TOO_LONG);\n            goto end;\n        }\n        if (b != NULL) {\n            if (!BUF_MEM_grow(b, l + 1))\n                goto err;\n            p = &(b->data[lold]);\n        } else if (l > len) {\n            break;\n        } else\n            p = &(buf[lold]);\n        *(p++) = \'/\';\n        memcpy(p, s, (unsigned int)l1);\n        p += l1;\n        *(p++) = \'=\';\n#ifndef CHARSET_EBCDIC\n        q = ne->value->data;\n#endif\n        for (j = 0; j < num; j++) {\n            if (!gs_doit[j & 3])\n                continue;\n#ifndef CHARSET_EBCDIC\n            n = q[j];\n            if ((n < \' \') || (n > \'~\')) {\n                *(p++) = \'\\\\\';\n                *(p++) = \'x\';\n                *(p++) = hex[(n >> 4) & 0x0f];\n                *(p++) = hex[n & 0x0f];\n            } else\n                *(p++) = n;\n#else\n            n = os_toascii[q[j]];\n            if ((n < os_toascii[\' \']) || (n > os_toascii[\'~\'])) {\n                *(p++) = \'\\\\\';\n                *(p++) = \'x\';\n                *(p++) = hex[(n >> 4) & 0x0f];\n                *(p++) = hex[n & 0x0f];\n            } else\n                *(p++) = q[j];\n#endif\n        }\n        *p = \'\\0\';\n    }\n    if (b != NULL) {\n        p = b->data;\n        OPENSSL_free(b);\n    } else\n        p = buf;\n    if (i == 0)\n        *p = \'\\0\';\n    return (p);\n err:\n    X509err(X509_F_X509_NAME_ONELINE, ERR_R_MALLOC_FAILURE);\n end:\n    BUF_MEM_free(b);\n    return (NULL);\n}']