⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ssl_engine_kernel.c

📁 linux网络服务器工具
💻 C
📖 第 1 页 / 共 5 页
字号:
            ASN1_INTEGER *sn = X509_REVOKED_get_serialNumber(revoked);            if (!ASN1_INTEGER_cmp(sn, X509_get_serialNumber(cert))) {                if (s->loglevel >= APLOG_DEBUG) {                    char *cp = X509_NAME_oneline(issuer, NULL, 0);                    long serial = ASN1_INTEGER_get(sn);                    ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,                                 "Certificate with serial %ld (0x%lX) "                                 "revoked per CRL from issuer %s",                                 serial, serial, cp);                    modssl_free(cp);                }                X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);                X509_OBJECT_free_contents(&obj);                return FALSE;            }        }        X509_OBJECT_free_contents(&obj);    }    return ok;}#define SSLPROXY_CERT_CB_LOG_FMT \   "Proxy client certificate callback: (%s) "static void modssl_proxy_info_log(server_rec *s,                                  X509_INFO *info,                                  const char *msg){    SSLSrvConfigRec *sc = mySrvConfig(s);    char name_buf[256];    X509_NAME *name;    char *dn;    if (s->loglevel < APLOG_DEBUG) {        return;    }    name = X509_get_subject_name(info->x509);    dn = X509_NAME_oneline(name, name_buf, sizeof(name_buf));    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                 SSLPROXY_CERT_CB_LOG_FMT "%s, sending %s",                 sc->vhost_id, msg, dn ? dn : "-uknown-");}/* * caller will decrement the cert and key reference * so we need to increment here to prevent them from * being freed. */#define modssl_set_cert_info(info, cert, pkey) \    *cert = info->x509; \    X509_reference_inc(*cert); \    *pkey = info->x_pkey->dec_pkey; \    EVP_PKEY_reference_inc(*pkey)int ssl_callback_proxy_cert(SSL *ssl, MODSSL_CLIENT_CERT_CB_ARG_TYPE **x509, EVP_PKEY **pkey){    conn_rec *c = (conn_rec *)SSL_get_app_data(ssl);    server_rec *s = c->base_server;    SSLSrvConfigRec *sc = mySrvConfig(s);    X509_NAME *ca_name, *issuer;    X509_INFO *info;    STACK_OF(X509_NAME) *ca_list;    STACK_OF(X509_INFO) *certs = sc->proxy->pkp->certs;    int i, j;    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                 SSLPROXY_CERT_CB_LOG_FMT "entered",                 sc->vhost_id);    if (!certs || (sk_X509_INFO_num(certs) <= 0)) {        ap_log_error(APLOG_MARK, APLOG_WARNING, 0, s,                     SSLPROXY_CERT_CB_LOG_FMT                     "downstream server wanted client certificate "                     "but none are configured", sc->vhost_id);        return FALSE;    }    ca_list = SSL_get_client_CA_list(ssl);    if (!ca_list || (sk_X509_NAME_num(ca_list) <= 0)) {        /*         * downstream server didn't send us a list of acceptable CA certs,         * so we send the first client cert in the list.         */        info = sk_X509_INFO_value(certs, 0);        modssl_proxy_info_log(s, info, "no acceptable CA list");        modssl_set_cert_info(info, x509, pkey);        return TRUE;    }    for (i = 0; i < sk_X509_NAME_num(ca_list); i++) {        ca_name = sk_X509_NAME_value(ca_list, i);        for (j = 0; j < sk_X509_INFO_num(certs); j++) {            info = sk_X509_INFO_value(certs, j);            issuer = X509_get_issuer_name(info->x509);            if (X509_NAME_cmp(issuer, ca_name) == 0) {                modssl_proxy_info_log(s, info, "found acceptable cert");                modssl_set_cert_info(info, x509, pkey);                return TRUE;            }        }    }    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                 SSLPROXY_CERT_CB_LOG_FMT                 "no client certificate found!?", sc->vhost_id);    return FALSE;}static void ssl_session_log(server_rec *s,                            const char *request,                            unsigned char *id,                            unsigned int idlen,                            const char *status,                            const char *result,                            long timeout){    char buf[SSL_SESSION_ID_STRING_LEN];    char timeout_str[56] = {'\0'};    if (s->loglevel < APLOG_DEBUG) {        return;    }    if (timeout) {        apr_snprintf(timeout_str, sizeof(timeout_str),                     "timeout=%lds ", (timeout - time(NULL)));    }    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                 "Inter-Process Session Cache: "                 "request=%s status=%s id=%s %s(session %s)",                 request, status,                 SSL_SESSION_id2sz(id, idlen, buf, sizeof(buf)),                 timeout_str, result);}/* *  This callback function is executed by OpenSSL whenever a new SSL_SESSION is *  added to the internal OpenSSL session cache. We use this hook to spread the *  SSL_SESSION also to the inter-process disk-cache to make share it with our *  other Apache pre-forked server processes. */int ssl_callback_NewSessionCacheEntry(SSL *ssl, SSL_SESSION *session){    /* Get Apache context back through OpenSSL context */    conn_rec *conn      = (conn_rec *)SSL_get_app_data(ssl);    server_rec *s       = conn->base_server;    SSLSrvConfigRec *sc = mySrvConfig(s);    long timeout        = sc->session_cache_timeout;    BOOL rc;    unsigned char *id;    unsigned int idlen;    /*     * Set the timeout also for the internal OpenSSL cache, because this way     * our inter-process cache is consulted only when it's really necessary.     */    SSL_set_timeout(session, timeout);    /*     * Store the SSL_SESSION in the inter-process cache with the     * same expire time, so it expires automatically there, too.     */    id = SSL_SESSION_get_session_id(session);    idlen = SSL_SESSION_get_session_id_length(session);    timeout += modssl_session_get_time(session);    rc = ssl_scache_store(s, id, idlen, timeout, session);    ssl_session_log(s, "SET", id, idlen,                    rc == TRUE ? "OK" : "BAD",                    "caching", timeout);    /*     * return 0 which means to OpenSSL that the session is still     * valid and was not freed by us with SSL_SESSION_free().     */    return 0;}/* *  This callback function is executed by OpenSSL whenever a *  SSL_SESSION is looked up in the internal OpenSSL cache and it *  was not found. We use this to lookup the SSL_SESSION in the *  inter-process disk-cache where it was perhaps stored by one *  of our other Apache pre-forked server processes. */SSL_SESSION *ssl_callback_GetSessionCacheEntry(SSL *ssl,                                               unsigned char *id,                                               int idlen, int *do_copy){    /* Get Apache context back through OpenSSL context */    conn_rec *conn = (conn_rec *)SSL_get_app_data(ssl);    server_rec *s  = conn->base_server;    SSL_SESSION *session;    /*     * Try to retrieve the SSL_SESSION from the inter-process cache     */    session = ssl_scache_retrieve(s, id, idlen);    ssl_session_log(s, "GET", id, idlen,                    session ? "FOUND" : "MISSED",                    session ? "reuse" : "renewal", 0);    /*     * Return NULL or the retrieved SSL_SESSION. But indicate (by     * setting do_copy to 0) that the reference count on the     * SSL_SESSION should not be incremented by the SSL library,     * because we will no longer hold a reference to it ourself.     */    *do_copy = 0;    return session;}/* *  This callback function is executed by OpenSSL whenever a *  SSL_SESSION is removed from the the internal OpenSSL cache. *  We use this to remove the SSL_SESSION in the inter-process *  disk-cache, too. */void ssl_callback_DelSessionCacheEntry(SSL_CTX *ctx,                                       SSL_SESSION *session){    server_rec *s;    SSLSrvConfigRec *sc;    unsigned char *id;    unsigned int idlen;    /*     * Get Apache context back through OpenSSL context     */    if (!(s = (server_rec *)SSL_CTX_get_app_data(ctx))) {        return; /* on server shutdown Apache is already gone */    }    sc = mySrvConfig(s);    /*     * Remove the SSL_SESSION from the inter-process cache     */    id = SSL_SESSION_get_session_id(session);    idlen = SSL_SESSION_get_session_id_length(session);    ssl_scache_remove(s, id, idlen);    ssl_session_log(s, "REM", id, idlen,                    "OK", "dead", 0);    return;}/* * This callback function is executed while OpenSSL processes the * SSL handshake and does SSL record layer stuff. We use it to * trace OpenSSL's processing in out SSL logfile. */void ssl_callback_LogTracingState(MODSSL_INFO_CB_ARG_TYPE ssl, int where, int rc){    conn_rec *c;    server_rec *s;    SSLSrvConfigRec *sc;    /*     * find corresponding server     */    if (!(c = (conn_rec *)SSL_get_app_data((SSL *)ssl))) {        return;    }    s = c->base_server;    if (!(sc = mySrvConfig(s))) {        return;    }    /*     * create the various trace messages     */    if (s->loglevel >= APLOG_DEBUG) {        if (where & SSL_CB_HANDSHAKE_START) {            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                         "%s: Handshake: start", SSL_LIBRARY_NAME);        }        else if (where & SSL_CB_HANDSHAKE_DONE) {            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                         "%s: Handshake: done", SSL_LIBRARY_NAME);        }        else if (where & SSL_CB_LOOP) {            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                         "%s: Loop: %s",                         SSL_LIBRARY_NAME, SSL_state_string_long(ssl));        }        else if (where & SSL_CB_READ) {            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                         "%s: Read: %s",                         SSL_LIBRARY_NAME, SSL_state_string_long(ssl));        }        else if (where & SSL_CB_WRITE) {            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                         "%s: Write: %s",                         SSL_LIBRARY_NAME, SSL_state_string_long(ssl));        }        else if (where & SSL_CB_ALERT) {            char *str = (where & SSL_CB_READ) ? "read" : "write";            ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                         "%s: Alert: %s:%s:%s",                         SSL_LIBRARY_NAME, str,                         SSL_alert_type_string_long(rc),                         SSL_alert_desc_string_long(rc));        }        else if (where & SSL_CB_EXIT) {            if (rc == 0) {                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                             "%s: Exit: failed in %s",                             SSL_LIBRARY_NAME, SSL_state_string_long(ssl));            }            else if (rc < 0) {                ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,                             "%s: Exit: error in %s",                             SSL_LIBRARY_NAME, SSL_state_string_long(ssl));            }        }    }    /*     * Because SSL renegotations can happen at any time (not only after     * SSL_accept()), the best way to log the current connection details is     * right after a finished handshake.     */    if (where & SSL_CB_HANDSHAKE_DONE) {        ap_log_error(APLOG_MARK, APLOG_INFO, 0, s,                     "Connection: Client IP: %s, Protocol: %s, "                     "Cipher: %s (%s/%s bits)",                     ssl_var_lookup(NULL, s, c, NULL, "REMOTE_ADDR"),                     ssl_var_lookup(NULL, s, c, NULL, "SSL_PROTOCOL"),                     ssl_var_lookup(NULL, s, c, NULL, "SSL_CIPHER"),                     ssl_var_lookup(NULL, s, c, NULL, "SSL_CIPHER_USEKEYSIZE"),                     ssl_var_lookup(NULL, s, c, NULL, "SSL_CIPHER_ALGKEYSIZE"));    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -