2004-07-16 14:33:35 +08:00
|
|
|
|
2004-09-28 16:34:51 +08:00
|
|
|
/*
|
2004-09-30 00:00:49 +08:00
|
|
|
* Copyright (C) Igor Sysoev
|
2004-09-28 16:34:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-07-16 00:35:51 +08:00
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
2004-07-16 14:33:35 +08:00
|
|
|
#include <ngx_event.h>
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ngx_str_t engine;
|
|
|
|
} ngx_openssl_conf_t;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
static int ngx_http_ssl_verify_callback(int ok, X509_STORE_CTX *x509_store);
|
2005-09-30 22:41:25 +08:00
|
|
|
static void ngx_ssl_handshake_handler(ngx_event_t *ev);
|
2005-02-16 21:40:36 +08:00
|
|
|
static ngx_int_t ngx_ssl_handle_recv(ngx_connection_t *c, int n);
|
2004-12-03 02:40:46 +08:00
|
|
|
static void ngx_ssl_write_handler(ngx_event_t *wev);
|
|
|
|
static void ngx_ssl_read_handler(ngx_event_t *rev);
|
2005-11-15 21:30:52 +08:00
|
|
|
static void ngx_ssl_shutdown_handler(ngx_event_t *ev);
|
2005-09-30 22:41:25 +08:00
|
|
|
static void ngx_ssl_connection_error(ngx_connection_t *c, int sslerr,
|
|
|
|
ngx_err_t err, char *text);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-09 23:59:20 +08:00
|
|
|
static ngx_int_t ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone,
|
|
|
|
void *data);
|
2007-01-03 23:25:40 +08:00
|
|
|
static int ngx_ssl_new_session(ngx_ssl_conn_t *ssl_conn,
|
|
|
|
ngx_ssl_session_t *sess);
|
|
|
|
static ngx_ssl_session_t *ngx_ssl_get_cached_session(ngx_ssl_conn_t *ssl_conn,
|
|
|
|
u_char *id, int len, int *copy);
|
|
|
|
static void ngx_ssl_remove_session(SSL_CTX *ssl, ngx_ssl_session_t *sess);
|
|
|
|
static void ngx_ssl_expire_sessions(ngx_ssl_session_cache_t *cache,
|
|
|
|
ngx_slab_pool_t *shpool, ngx_uint_t n);
|
2007-01-13 04:57:34 +08:00
|
|
|
static void ngx_ssl_session_rbtree_insert_value(ngx_rbtree_node_t *temp,
|
|
|
|
ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
static void *ngx_openssl_create_conf(ngx_cycle_t *cycle);
|
|
|
|
static char *ngx_openssl_init_conf(ngx_cycle_t *cycle, void *conf);
|
2005-10-27 23:46:13 +08:00
|
|
|
static void ngx_openssl_exit(ngx_cycle_t *cycle);
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
#if !(NGX_SSL_ENGINE)
|
|
|
|
static char *ngx_openssl_noengine(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
|
|
void *conf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_command_t ngx_openssl_commands[] = {
|
|
|
|
|
|
|
|
{ ngx_string("ssl_engine"),
|
|
|
|
NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
|
|
|
|
#if (NGX_SSL_ENGINE)
|
|
|
|
ngx_conf_set_str_slot,
|
|
|
|
#else
|
|
|
|
ngx_openssl_noengine,
|
|
|
|
#endif
|
|
|
|
0,
|
|
|
|
offsetof(ngx_openssl_conf_t, engine),
|
|
|
|
NULL },
|
|
|
|
|
|
|
|
ngx_null_command
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_core_module_t ngx_openssl_module_ctx = {
|
|
|
|
ngx_string("openssl"),
|
|
|
|
ngx_openssl_create_conf,
|
|
|
|
ngx_openssl_init_conf
|
2005-11-15 21:30:52 +08:00
|
|
|
};
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
ngx_module_t ngx_openssl_module = {
|
|
|
|
NGX_MODULE_V1,
|
|
|
|
&ngx_openssl_module_ctx, /* module context */
|
|
|
|
ngx_openssl_commands, /* module directives */
|
|
|
|
NGX_CORE_MODULE, /* module type */
|
|
|
|
NULL, /* init master */
|
|
|
|
NULL, /* init module */
|
|
|
|
NULL, /* init process */
|
|
|
|
NULL, /* init thread */
|
|
|
|
NULL, /* exit thread */
|
|
|
|
NULL, /* exit process */
|
2005-10-27 23:46:13 +08:00
|
|
|
ngx_openssl_exit, /* exit master */
|
2005-09-08 22:36:09 +08:00
|
|
|
NGX_MODULE_V1_PADDING
|
2005-09-30 22:41:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static long ngx_ssl_protocols[] = {
|
|
|
|
SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1,
|
|
|
|
SSL_OP_NO_SSLv3|SSL_OP_NO_TLSv1,
|
|
|
|
SSL_OP_NO_SSLv2|SSL_OP_NO_TLSv1,
|
|
|
|
SSL_OP_NO_TLSv1,
|
|
|
|
SSL_OP_NO_SSLv2|SSL_OP_NO_SSLv3,
|
|
|
|
SSL_OP_NO_SSLv3,
|
|
|
|
SSL_OP_NO_SSLv2,
|
|
|
|
0,
|
|
|
|
};
|
2004-07-23 13:37:29 +08:00
|
|
|
|
|
|
|
|
2007-01-03 07:37:25 +08:00
|
|
|
int ngx_ssl_connection_index;
|
|
|
|
int ngx_ssl_server_conf_index;
|
2007-01-03 23:25:40 +08:00
|
|
|
int ngx_ssl_session_cache_index;
|
2006-08-10 03:59:45 +08:00
|
|
|
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_init(ngx_log_t *log)
|
2004-07-16 00:35:51 +08:00
|
|
|
{
|
2007-01-03 07:32:41 +08:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x00907000
|
|
|
|
OPENSSL_config(NULL);
|
|
|
|
#endif
|
|
|
|
|
2004-07-16 00:35:51 +08:00
|
|
|
SSL_library_init();
|
|
|
|
SSL_load_error_strings();
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
#if (NGX_SSL_ENGINE)
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
ENGINE_load_builtin_engines();
|
2005-09-08 22:36:09 +08:00
|
|
|
#endif
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2007-01-03 07:37:25 +08:00
|
|
|
ngx_ssl_connection_index = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL);
|
2006-08-10 03:59:45 +08:00
|
|
|
|
2007-01-03 07:37:25 +08:00
|
|
|
if (ngx_ssl_connection_index == -1) {
|
2006-08-10 03:59:45 +08:00
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, log, 0, "SSL_get_ex_new_index() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-01-03 07:37:25 +08:00
|
|
|
ngx_ssl_server_conf_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
if (ngx_ssl_server_conf_index == -1) {
|
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, log, 0,
|
|
|
|
"SSL_CTX_get_ex_new_index() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_ssl_session_cache_index = SSL_CTX_get_ex_new_index(0, NULL, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
if (ngx_ssl_session_cache_index == -1) {
|
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, log, 0,
|
|
|
|
"SSL_CTX_get_ex_new_index() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-07-16 00:35:51 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
ngx_int_t
|
2007-01-03 07:37:25 +08:00
|
|
|
ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data)
|
2005-09-30 22:41:25 +08:00
|
|
|
{
|
2005-11-15 21:30:52 +08:00
|
|
|
ssl->ctx = SSL_CTX_new(SSLv23_method());
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
if (ssl->ctx == NULL) {
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, "SSL_CTX_new() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2007-01-03 07:37:25 +08:00
|
|
|
if (SSL_CTX_set_ex_data(ssl->ctx, ngx_ssl_server_conf_index, data) == 0) {
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
|
|
|
"SSL_CTX_set_ex_data() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
/* client side options */
|
|
|
|
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_MICROSOFT_SESS_ID_BUG);
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_NETSCAPE_CHALLENGE_BUG);
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG);
|
|
|
|
|
|
|
|
/* server side options */
|
2005-10-19 20:33:58 +08:00
|
|
|
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG);
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER);
|
|
|
|
|
|
|
|
/* this option allow a potential SSL 2.0 rollback (CAN-2005-2969) */
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_MSIE_SSLV2_RSA_PADDING);
|
|
|
|
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_SSLEAY_080_CLIENT_DH_BUG);
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_TLS_D5_BUG);
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_TLS_BLOCK_PADDING_BUG);
|
|
|
|
|
|
|
|
#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
|
|
|
|
SSL_CTX_set_options(ssl->ctx, SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS);
|
|
|
|
#endif
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
if (ngx_ssl_protocols[protocols >> 1] != 0) {
|
|
|
|
SSL_CTX_set_options(ssl->ctx, ngx_ssl_protocols[protocols >> 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
SSL_CTX_set_mode(ssl->ctx, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
|
|
|
|
|
|
|
SSL_CTX_set_read_ahead(ssl->ctx, 1);
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngx_int_t
|
2005-10-19 20:33:58 +08:00
|
|
|
ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
|
|
|
|
ngx_str_t *key)
|
2005-09-30 22:41:25 +08:00
|
|
|
{
|
2005-10-19 20:33:58 +08:00
|
|
|
if (ngx_conf_full_name(cf->cycle, cert) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SSL_CTX_use_certificate_chain_file(ssl->ctx, (char *) cert->data)
|
|
|
|
== 0)
|
|
|
|
{
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
|
|
|
"SSL_CTX_use_certificate_chain_file(\"%s\") failed",
|
2005-10-19 20:33:58 +08:00
|
|
|
cert->data);
|
2005-09-30 22:41:25 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-10-19 20:33:58 +08:00
|
|
|
if (ngx_conf_full_name(cf->cycle, key) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SSL_CTX_use_PrivateKey_file(ssl->ctx, (char *) key->data,
|
2006-05-07 00:28:56 +08:00
|
|
|
SSL_FILETYPE_PEM)
|
|
|
|
== 0)
|
2005-09-30 22:41:25 +08:00
|
|
|
{
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
2005-10-19 20:33:58 +08:00
|
|
|
"SSL_CTX_use_PrivateKey_file(\"%s\") failed", key->data);
|
2005-09-30 22:41:25 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-07 00:28:56 +08:00
|
|
|
ngx_int_t
|
2006-08-10 03:59:45 +08:00
|
|
|
ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *cert,
|
|
|
|
ngx_int_t depth)
|
2006-05-07 00:28:56 +08:00
|
|
|
{
|
2006-08-10 03:59:45 +08:00
|
|
|
STACK_OF(X509_NAME) *list;
|
|
|
|
|
|
|
|
SSL_CTX_set_verify(ssl->ctx, SSL_VERIFY_PEER, ngx_http_ssl_verify_callback);
|
|
|
|
|
|
|
|
SSL_CTX_set_verify_depth(ssl->ctx, depth);
|
|
|
|
|
|
|
|
if (cert->len == 0) {
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2006-05-07 00:28:56 +08:00
|
|
|
if (ngx_conf_full_name(cf->cycle, cert) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SSL_CTX_load_verify_locations(ssl->ctx, (char *) cert->data, NULL)
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
|
|
|
"SSL_CTX_load_verify_locations(\"%s\") failed",
|
|
|
|
cert->data);
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
list = SSL_load_client_CA_file((char *) cert->data);
|
|
|
|
|
|
|
|
if (list == NULL) {
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
|
|
|
"SSL_load_client_CA_file(\"%s\") failed", cert->data);
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* before 0.9.7h and 0.9.8 SSL_load_client_CA_file()
|
|
|
|
* always leaved an error in the error queue
|
|
|
|
*/
|
|
|
|
|
|
|
|
ERR_clear_error();
|
|
|
|
|
|
|
|
SSL_CTX_set_client_CA_list(ssl->ctx, list);
|
|
|
|
|
2006-05-07 00:28:56 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
static int
|
|
|
|
ngx_http_ssl_verify_callback(int ok, X509_STORE_CTX *x509_store)
|
|
|
|
{
|
|
|
|
char *subject, *issuer;
|
|
|
|
int err, depth;
|
|
|
|
X509 *cert;
|
|
|
|
X509_NAME *name;
|
|
|
|
ngx_connection_t *c;
|
|
|
|
ngx_ssl_conn_t *ssl_conn;
|
|
|
|
|
|
|
|
ssl_conn = X509_STORE_CTX_get_ex_data(x509_store,
|
|
|
|
SSL_get_ex_data_X509_STORE_CTX_idx());
|
|
|
|
|
|
|
|
c = ngx_ssl_get_connection(ssl_conn);
|
|
|
|
|
|
|
|
cert = X509_STORE_CTX_get_current_cert(x509_store);
|
|
|
|
err = X509_STORE_CTX_get_error(x509_store);
|
|
|
|
depth = X509_STORE_CTX_get_error_depth(x509_store);
|
|
|
|
|
|
|
|
name = X509_get_subject_name(cert);
|
|
|
|
subject = name ? X509_NAME_oneline(name, NULL, 0) : "(none)";
|
|
|
|
|
|
|
|
name = X509_get_issuer_name(cert);
|
|
|
|
issuer = name ? X509_NAME_oneline(name, NULL, 0) : "(none)";
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_log_debug5(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2006-08-10 03:59:45 +08:00
|
|
|
"verify:%d, error:%d, depth:%d, "
|
|
|
|
"subject:\"%s\",issuer: \"%s\"",
|
|
|
|
ok, err, depth, subject, issuer);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_generate_rsa512_key(ngx_ssl_t *ssl)
|
|
|
|
{
|
2006-08-10 03:59:45 +08:00
|
|
|
RSA *key;
|
|
|
|
|
2005-10-10 20:59:41 +08:00
|
|
|
if (SSL_CTX_need_tmp_RSA(ssl->ctx) == 0) {
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
key = RSA_generate_key(512, RSA_F4, NULL, NULL);
|
|
|
|
|
|
|
|
if (key) {
|
|
|
|
SSL_CTX_set_tmp_rsa(ssl->ctx, key);
|
|
|
|
|
|
|
|
RSA_free(key);
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, "RSA_generate_key(512) failed");
|
|
|
|
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_create_connection(ngx_ssl_t *ssl, ngx_connection_t *c, ngx_uint_t flags)
|
2005-11-15 21:30:52 +08:00
|
|
|
{
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_ssl_connection_t *sc;
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
sc = ngx_pcalloc(c->pool, sizeof(ngx_ssl_connection_t));
|
|
|
|
if (sc == NULL) {
|
2004-07-17 01:11:43 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2004-07-17 01:11:43 +08:00
|
|
|
if (flags & NGX_SSL_BUFFER) {
|
2005-09-30 22:41:25 +08:00
|
|
|
sc->buffer = 1;
|
2005-09-23 19:02:22 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
sc->buf = ngx_create_temp_buf(c->pool, NGX_SSL_BUFSIZE);
|
|
|
|
if (sc->buf == NULL) {
|
2005-09-23 19:02:22 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
}
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
sc->connection = SSL_new(ssl->ctx);
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (sc->connection == NULL) {
|
2004-07-17 01:11:43 +08:00
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_new() failed");
|
2004-07-16 00:35:51 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (SSL_set_fd(sc->connection, c->fd) == 0) {
|
2004-07-17 01:11:43 +08:00
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_set_fd() failed");
|
2004-07-16 00:35:51 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
if (flags & NGX_SSL_CLIENT) {
|
|
|
|
SSL_set_connect_state(sc->connection);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
SSL_set_accept_state(sc->connection);
|
|
|
|
}
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2007-01-03 07:37:25 +08:00
|
|
|
if (SSL_set_ex_data(sc->connection, ngx_ssl_connection_index, c) == 0) {
|
2006-08-10 03:59:45 +08:00
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_set_ex_data() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
c->ssl = sc;
|
2004-07-16 00:35:51 +08:00
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_set_session(ngx_connection_t *c, ngx_ssl_session_t *session)
|
|
|
|
{
|
|
|
|
if (session) {
|
|
|
|
if (SSL_set_session(c->ssl->connection, session) == 0) {
|
|
|
|
ngx_ssl_error(NGX_LOG_ALERT, c->log, 0, "SSL_set_session() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_handshake(ngx_connection_t *c)
|
2004-07-16 00:35:51 +08:00
|
|
|
{
|
2005-09-30 22:41:25 +08:00
|
|
|
int n, sslerr;
|
|
|
|
ngx_err_t err;
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
n = SSL_do_handshake(c->ssl->connection);
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_do_handshake: %d", n);
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
if (n == 1) {
|
|
|
|
|
|
|
|
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (NGX_DEBUG)
|
|
|
|
{
|
|
|
|
char buf[129], *s, *d;
|
|
|
|
SSL_CIPHER *cipher;
|
|
|
|
|
|
|
|
cipher = SSL_get_current_cipher(c->ssl->connection);
|
|
|
|
|
|
|
|
if (cipher) {
|
|
|
|
SSL_CIPHER_description(cipher, &buf[1], 128);
|
|
|
|
|
|
|
|
for (s = &buf[1], d = buf; *s; s++) {
|
|
|
|
if (*s == ' ' && *d == ' ') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*s == LF || *s == CR) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
*++d = *s;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*d != ' ') {
|
|
|
|
d++;
|
|
|
|
}
|
|
|
|
|
|
|
|
*d = '\0';
|
|
|
|
|
2005-12-05 21:18:09 +08:00
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2005-09-30 22:41:25 +08:00
|
|
|
"SSL: %s, cipher: \"%s\"",
|
2005-11-15 21:30:52 +08:00
|
|
|
SSL_get_version(c->ssl->connection), &buf[1]);
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
if (SSL_session_reused(c->ssl->connection)) {
|
2005-12-05 21:18:09 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2005-09-30 22:41:25 +08:00
|
|
|
"SSL reused session");
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2005-11-15 21:30:52 +08:00
|
|
|
"SSL no shared ciphers");
|
2005-09-30 22:41:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
c->ssl->handshaked = 1;
|
|
|
|
|
|
|
|
c->recv = ngx_ssl_recv;
|
|
|
|
c->send = ngx_ssl_write;
|
2005-11-15 21:30:52 +08:00
|
|
|
c->recv_chain = ngx_ssl_recv_chain;
|
|
|
|
c->send_chain = ngx_ssl_send_chain;
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
return NGX_OK;
|
2005-02-16 21:40:36 +08:00
|
|
|
}
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
sslerr = SSL_get_error(c->ssl->connection, n);
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr);
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (sslerr == SSL_ERROR_WANT_READ) {
|
|
|
|
c->read->ready = 0;
|
|
|
|
c->read->handler = ngx_ssl_handshake_handler;
|
2005-12-19 00:02:44 +08:00
|
|
|
c->write->handler = ngx_ssl_handshake_handler;
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
return NGX_AGAIN;
|
|
|
|
}
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (sslerr == SSL_ERROR_WANT_WRITE) {
|
|
|
|
c->write->ready = 0;
|
2005-12-19 00:02:44 +08:00
|
|
|
c->read->handler = ngx_ssl_handshake_handler;
|
2005-09-30 22:41:25 +08:00
|
|
|
c->write->handler = ngx_ssl_handshake_handler;
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
return NGX_AGAIN;
|
|
|
|
}
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
c->ssl->no_wait_shutdown = 1;
|
|
|
|
c->ssl->no_send_shutdown = 1;
|
2005-12-19 00:02:44 +08:00
|
|
|
c->read->eof = 1;
|
2005-02-16 21:40:36 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) {
|
|
|
|
ngx_log_error(NGX_LOG_INFO, c->log, err,
|
2005-11-15 21:30:52 +08:00
|
|
|
"peer closed connection in SSL handshake");
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-12-19 00:02:44 +08:00
|
|
|
c->read->error = 1;
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_ssl_connection_error(c, sslerr, err, "SSL_do_handshake() failed");
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
static void
|
|
|
|
ngx_ssl_handshake_handler(ngx_event_t *ev)
|
|
|
|
{
|
|
|
|
ngx_connection_t *c;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
c = ev->data;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-10-01 00:02:34 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2005-11-15 21:30:52 +08:00
|
|
|
"SSL handshake handler: %d", ev->write);
|
2005-09-23 19:02:22 +08:00
|
|
|
|
2005-12-19 00:02:44 +08:00
|
|
|
if (ev->timedout) {
|
|
|
|
c->ssl->handler(c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (ngx_ssl_handshake(c) == NGX_AGAIN) {
|
|
|
|
return;
|
|
|
|
}
|
2005-09-23 19:02:22 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
c->ssl->handler(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
ssize_t
|
|
|
|
ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl)
|
|
|
|
{
|
|
|
|
ssize_t n, bytes;
|
|
|
|
ngx_buf_t *b;
|
|
|
|
|
|
|
|
bytes = 0;
|
|
|
|
|
|
|
|
while (cl) {
|
|
|
|
b = cl->buf;
|
|
|
|
|
|
|
|
n = ngx_ssl_recv(c, b->last, b->end - b->last);
|
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
b->last += n;
|
|
|
|
bytes += n;
|
|
|
|
|
|
|
|
if (b->last == b->end) {
|
|
|
|
cl = cl->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytes) {
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ssize_t
|
|
|
|
ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size)
|
|
|
|
{
|
|
|
|
int n, bytes;
|
|
|
|
|
|
|
|
if (c->ssl->last == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
if (c->ssl->last == NGX_DONE) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
bytes = 0;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
/*
|
|
|
|
* SSL_read() may return data in parts, so try to read
|
|
|
|
* until SSL_read() would return no data
|
|
|
|
*/
|
|
|
|
|
|
|
|
for ( ;; ) {
|
|
|
|
|
|
|
|
n = SSL_read(c->ssl->connection, buf, size);
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_read: %d", n);
|
2005-09-30 22:41:25 +08:00
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
bytes += n;
|
2005-02-16 21:40:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
c->ssl->last = ngx_ssl_handle_recv(c, n);
|
|
|
|
|
|
|
|
if (c->ssl->last != NGX_OK) {
|
|
|
|
|
|
|
|
if (bytes) {
|
|
|
|
return bytes;
|
2005-11-15 21:30:52 +08:00
|
|
|
}
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
if (c->ssl->last == NGX_DONE) {
|
|
|
|
return 0;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
}
|
2005-11-15 21:30:52 +08:00
|
|
|
|
|
|
|
return c->ssl->last;
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
}
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
size -= n;
|
|
|
|
|
|
|
|
if (size == 0) {
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf += n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
|
|
|
ngx_ssl_handle_recv(ngx_connection_t *c, int n)
|
|
|
|
{
|
2005-09-30 22:41:25 +08:00
|
|
|
int sslerr;
|
|
|
|
ngx_err_t err;
|
2005-02-16 21:40:36 +08:00
|
|
|
|
|
|
|
if (n > 0) {
|
nginx-0.1.14-RELEASE import
*) Feature: the autoconfiguration directives:
--http-client-body-temp-path=PATH, --http-proxy-temp-path=PATH, and
--http-fastcgi-temp-path=PATH
*) Change: the directory name for the temporary files with the client
request body is specified by directive client_body_temp_path, by
default it is <prefix>/client_body_temp.
*) Feature: the ngx_http_fastcgi_module and the directives:
fastcgi_pass, fastcgi_root, fastcgi_index, fastcgi_params,
fastcgi_connect_timeout, fastcgi_send_timeout, fastcgi_read_timeout,
fastcgi_send_lowat, fastcgi_header_buffer_size, fastcgi_buffers,
fastcgi_busy_buffers_size, fastcgi_temp_path,
fastcgi_max_temp_file_size, fastcgi_temp_file_write_size,
fastcgi_next_upstream, and fastcgi_x_powered_by.
*) Bugfix: the "[alert] zero size buf" error; the bug had appeared in
0.1.3.
*) Change: the URI must be specified after the host name in the
proxy_pass directive.
*) Change: the %3F symbol in the URI was considered as the argument
string start.
*) Feature: the unix domain sockets support in the
ngx_http_proxy_module.
*) Feature: the ssl_engine and ssl_ciphers directives.
Thanks to Sergey Skvortsov for SSL-accelerator.
2005-01-18 21:03:58 +08:00
|
|
|
|
2004-12-03 02:40:46 +08:00
|
|
|
if (c->ssl->saved_write_handler) {
|
|
|
|
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
c->write->handler = c->ssl->saved_write_handler;
|
2004-12-03 02:40:46 +08:00
|
|
|
c->ssl->saved_write_handler = NULL;
|
|
|
|
c->write->ready = 1;
|
|
|
|
|
|
|
|
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-10-19 20:33:58 +08:00
|
|
|
ngx_post_event(c->write, &ngx_posted_events);
|
2004-12-03 02:40:46 +08:00
|
|
|
}
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
return NGX_OK;
|
2004-07-16 00:35:51 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
sslerr = SSL_get_error(c->ssl->connection, n);
|
2004-07-17 01:11:43 +08:00
|
|
|
|
|
|
|
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2004-07-19 03:11:20 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr);
|
|
|
|
|
2004-07-17 01:11:43 +08:00
|
|
|
if (sslerr == SSL_ERROR_WANT_READ) {
|
2004-10-21 23:34:38 +08:00
|
|
|
c->read->ready = 0;
|
2004-07-16 00:35:51 +08:00
|
|
|
return NGX_AGAIN;
|
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-17 01:11:43 +08:00
|
|
|
if (sslerr == SSL_ERROR_WANT_WRITE) {
|
2005-09-07 00:09:32 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_log_error(NGX_LOG_INFO, c->log, 0,
|
2005-11-15 21:30:52 +08:00
|
|
|
"peer started SSL renegotiation");
|
2004-12-03 02:40:46 +08:00
|
|
|
|
|
|
|
c->write->ready = 0;
|
|
|
|
|
|
|
|
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we do not set the timer because there is already the read event timer
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (c->ssl->saved_write_handler == NULL) {
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
c->ssl->saved_write_handler = c->write->handler;
|
|
|
|
c->write->handler = ngx_ssl_write_handler;
|
2004-12-03 02:40:46 +08:00
|
|
|
}
|
|
|
|
|
2004-07-16 00:35:51 +08:00
|
|
|
return NGX_AGAIN;
|
2004-09-30 14:38:49 +08:00
|
|
|
}
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
c->ssl->no_wait_shutdown = 1;
|
|
|
|
c->ssl->no_send_shutdown = 1;
|
2005-12-16 23:07:08 +08:00
|
|
|
c->read->eof = 1;
|
2004-07-19 03:11:20 +08:00
|
|
|
|
2004-07-17 01:11:43 +08:00
|
|
|
if (sslerr == SSL_ERROR_ZERO_RETURN || ERR_peek_error() == 0) {
|
2005-11-15 21:30:52 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
|
|
|
"peer shutdown SSL cleanly");
|
|
|
|
return NGX_DONE;
|
2004-07-16 00:35:51 +08:00
|
|
|
}
|
|
|
|
|
2005-12-19 00:02:44 +08:00
|
|
|
c->read->error = 1;
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_ssl_connection_error(c, sslerr, err, "SSL_read() failed");
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2004-07-16 14:33:35 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
static void
|
|
|
|
ngx_ssl_write_handler(ngx_event_t *wev)
|
2004-12-03 02:40:46 +08:00
|
|
|
{
|
|
|
|
ngx_connection_t *c;
|
|
|
|
|
|
|
|
c = wev->data;
|
2005-09-30 22:41:25 +08:00
|
|
|
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
c->read->handler(c->read);
|
2004-12-03 02:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-24 01:05:37 +08:00
|
|
|
/*
|
|
|
|
* OpenSSL has no SSL_writev() so we copy several bufs into our 16K buffer
|
2004-12-03 02:40:46 +08:00
|
|
|
* before the SSL_write() call to decrease a SSL overhead.
|
2004-07-24 01:05:37 +08:00
|
|
|
*
|
|
|
|
* Besides for protocols such as HTTP it is possible to always buffer
|
|
|
|
* the output to decrease a SSL overhead some more.
|
|
|
|
*/
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
ngx_chain_t *
|
|
|
|
ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
|
2004-07-16 14:33:35 +08:00
|
|
|
{
|
2004-07-23 13:37:29 +08:00
|
|
|
int n;
|
2004-07-26 02:34:14 +08:00
|
|
|
ngx_uint_t flush;
|
2004-07-23 13:37:29 +08:00
|
|
|
ssize_t send, size;
|
|
|
|
ngx_buf_t *buf;
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2006-01-11 23:26:57 +08:00
|
|
|
if (!c->ssl->buffer
|
|
|
|
|| (in && in->next == NULL && !(c->buffered & NGX_SSL_BUFFERED)))
|
|
|
|
{
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
/*
|
2005-11-15 21:30:52 +08:00
|
|
|
* we avoid a buffer copy if
|
|
|
|
* we do not need to buffer the output
|
|
|
|
* or the incoming buf is a single and our buffer is empty
|
2004-07-23 13:37:29 +08:00
|
|
|
*/
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
while (in) {
|
|
|
|
if (ngx_buf_special(in->buf)) {
|
|
|
|
in = in->next;
|
|
|
|
continue;
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
n = ngx_ssl_write(c, in->buf->pos, in->buf->last - in->buf->pos);
|
2004-07-24 01:05:37 +08:00
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
if (n == NGX_ERROR) {
|
|
|
|
return NGX_CHAIN_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == NGX_AGAIN) {
|
2006-01-11 23:26:57 +08:00
|
|
|
c->buffered |= NGX_SSL_BUFFERED;
|
2005-11-15 21:30:52 +08:00
|
|
|
return in;
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
in->buf->pos += n;
|
|
|
|
|
|
|
|
if (in->buf->pos == in->buf->last) {
|
|
|
|
in = in->next;
|
|
|
|
}
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
return in;
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-12-03 02:40:46 +08:00
|
|
|
|
|
|
|
/* the maximum limit size is the maximum uint32_t value - the page size */
|
|
|
|
|
|
|
|
if (limit == 0 || limit > NGX_MAX_UINT32_VALUE - ngx_pagesize) {
|
|
|
|
limit = NGX_MAX_UINT32_VALUE - ngx_pagesize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
buf = c->ssl->buf;
|
2004-07-23 13:37:29 +08:00
|
|
|
send = 0;
|
|
|
|
flush = (in == NULL) ? 1 : 0;
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
for ( ;; ) {
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
while (in && buf->last < buf->end) {
|
2005-12-05 21:18:09 +08:00
|
|
|
if (in->buf->last_buf || in->buf->flush) {
|
2004-07-23 13:37:29 +08:00
|
|
|
flush = 1;
|
2004-07-17 01:11:43 +08:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (ngx_buf_special(in->buf)) {
|
2004-07-24 01:05:37 +08:00
|
|
|
in = in->next;
|
2004-07-23 13:37:29 +08:00
|
|
|
continue;
|
2004-07-17 01:11:43 +08:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
size = in->buf->last - in->buf->pos;
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (size > buf->end - buf->last) {
|
|
|
|
size = buf->end - buf->last;
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (send + size > limit) {
|
2005-11-15 21:30:52 +08:00
|
|
|
size = (ssize_t) (limit - send);
|
2004-07-23 13:37:29 +08:00
|
|
|
flush = 1;
|
2004-07-17 01:11:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
2004-07-23 13:37:29 +08:00
|
|
|
"SSL buf copy: %d", size);
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
ngx_memcpy(buf->last, in->buf->pos, size);
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
buf->last += size;
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
in->buf->pos += size;
|
2005-11-15 21:30:52 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (in->buf->pos == in->buf->last) {
|
|
|
|
in = in->next;
|
|
|
|
}
|
2004-07-17 01:11:43 +08:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
size = buf->last - buf->pos;
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-24 01:05:37 +08:00
|
|
|
if (!flush && buf->last < buf->end && c->ssl->buffer) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
n = ngx_ssl_write(c, buf->pos, size);
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-24 01:05:37 +08:00
|
|
|
if (n == NGX_ERROR) {
|
|
|
|
return NGX_CHAIN_ERROR;
|
2004-07-17 01:11:43 +08:00
|
|
|
}
|
|
|
|
|
2005-05-15 02:42:03 +08:00
|
|
|
if (n == NGX_AGAIN) {
|
2006-01-11 23:26:57 +08:00
|
|
|
c->buffered |= NGX_SSL_BUFFERED;
|
2005-05-15 02:42:03 +08:00
|
|
|
return in;
|
2004-07-23 13:37:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
buf->pos += n;
|
|
|
|
send += n;
|
|
|
|
c->sent += n;
|
2004-07-17 01:11:43 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (n < size) {
|
|
|
|
break;
|
2004-07-16 14:33:35 +08:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (buf->pos == buf->last) {
|
|
|
|
buf->pos = buf->start;
|
|
|
|
buf->last = buf->start;
|
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (in == NULL || send == limit) {
|
|
|
|
break;
|
2004-07-16 14:33:35 +08:00
|
|
|
}
|
2004-07-23 13:37:29 +08:00
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2006-01-11 23:26:57 +08:00
|
|
|
if (buf->pos < buf->last) {
|
|
|
|
c->buffered |= NGX_SSL_BUFFERED;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
c->buffered &= ~NGX_SSL_BUFFERED;
|
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-26 02:34:14 +08:00
|
|
|
return in;
|
2004-07-23 13:37:29 +08:00
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
|
|
|
|
2005-09-07 00:09:32 +08:00
|
|
|
ssize_t
|
2005-02-16 21:40:36 +08:00
|
|
|
ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size)
|
2004-07-23 13:37:29 +08:00
|
|
|
{
|
2005-09-30 22:41:25 +08:00
|
|
|
int n, sslerr;
|
|
|
|
ngx_err_t err;
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL to write: %d", size);
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
n = SSL_write(c->ssl->connection, data, size);
|
2004-07-23 13:37:29 +08:00
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_write: %d", n);
|
|
|
|
|
|
|
|
if (n > 0) {
|
2005-09-07 00:09:32 +08:00
|
|
|
|
2004-12-03 02:40:46 +08:00
|
|
|
if (c->ssl->saved_read_handler) {
|
|
|
|
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
c->read->handler = c->ssl->saved_read_handler;
|
2004-12-03 02:40:46 +08:00
|
|
|
c->ssl->saved_read_handler = NULL;
|
|
|
|
c->read->ready = 1;
|
|
|
|
|
|
|
|
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-10-19 20:33:58 +08:00
|
|
|
ngx_post_event(c->read, &ngx_posted_events);
|
2004-12-03 02:40:46 +08:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
return n;
|
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
sslerr = SSL_get_error(c->ssl->connection, n);
|
2004-07-19 03:11:20 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_get_error: %d", sslerr);
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (sslerr == SSL_ERROR_WANT_WRITE) {
|
|
|
|
c->write->ready = 0;
|
|
|
|
return NGX_AGAIN;
|
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
if (sslerr == SSL_ERROR_WANT_READ) {
|
2004-10-11 23:07:03 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_log_error(NGX_LOG_INFO, c->log, 0,
|
2005-11-15 21:30:52 +08:00
|
|
|
"peer started SSL renegotiation");
|
2004-12-03 02:40:46 +08:00
|
|
|
|
|
|
|
c->read->ready = 0;
|
|
|
|
|
|
|
|
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we do not set the timer because there is already
|
|
|
|
* the write event timer
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (c->ssl->saved_read_handler == NULL) {
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
c->ssl->saved_read_handler = c->read->handler;
|
|
|
|
c->read->handler = ngx_ssl_read_handler;
|
2004-12-03 02:40:46 +08:00
|
|
|
}
|
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
return NGX_AGAIN;
|
2004-10-11 23:07:03 +08:00
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
c->ssl->no_wait_shutdown = 1;
|
|
|
|
c->ssl->no_send_shutdown = 1;
|
2005-12-19 00:02:44 +08:00
|
|
|
c->write->error = 1;
|
2005-09-23 19:02:22 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
ngx_ssl_connection_error(c, sslerr, err, "SSL_write() failed");
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-23 13:37:29 +08:00
|
|
|
return NGX_ERROR;
|
2004-07-16 14:33:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
static void
|
|
|
|
ngx_ssl_read_handler(ngx_event_t *rev)
|
2004-12-03 02:40:46 +08:00
|
|
|
{
|
|
|
|
ngx_connection_t *c;
|
|
|
|
|
|
|
|
c = rev->data;
|
2005-09-30 22:41:25 +08:00
|
|
|
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
c->write->handler(c->write);
|
2004-12-03 02:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-16 21:40:36 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_shutdown(ngx_connection_t *c)
|
2004-07-16 14:33:35 +08:00
|
|
|
{
|
2004-12-03 02:40:46 +08:00
|
|
|
int n, sslerr, mode;
|
2005-12-19 00:02:44 +08:00
|
|
|
ngx_err_t err;
|
2004-07-16 14:33:35 +08:00
|
|
|
ngx_uint_t again;
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
if (c->timedout) {
|
2005-09-30 22:41:25 +08:00
|
|
|
mode = SSL_RECEIVED_SHUTDOWN|SSL_SENT_SHUTDOWN;
|
2004-12-03 02:40:46 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
} else {
|
|
|
|
mode = SSL_get_shutdown(c->ssl->connection);
|
2004-12-03 02:40:46 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (c->ssl->no_wait_shutdown) {
|
|
|
|
mode |= SSL_RECEIVED_SHUTDOWN;
|
2004-07-19 03:11:20 +08:00
|
|
|
}
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
if (c->ssl->no_send_shutdown) {
|
|
|
|
mode |= SSL_SENT_SHUTDOWN;
|
2004-07-19 03:11:20 +08:00
|
|
|
}
|
|
|
|
}
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
SSL_set_shutdown(c->ssl->connection, mode);
|
|
|
|
|
2004-07-16 14:33:35 +08:00
|
|
|
again = 0;
|
2004-11-11 22:07:14 +08:00
|
|
|
sslerr = 0;
|
2004-07-16 14:33:35 +08:00
|
|
|
|
|
|
|
for ( ;; ) {
|
2005-09-23 19:02:22 +08:00
|
|
|
n = SSL_shutdown(c->ssl->connection);
|
2004-07-16 14:33:35 +08:00
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, "SSL_shutdown: %d", n);
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
if (n == 1 || (n == 0 && c->timedout)) {
|
2005-09-23 19:02:22 +08:00
|
|
|
SSL_free(c->ssl->connection);
|
2004-07-16 14:33:35 +08:00
|
|
|
c->ssl = NULL;
|
2005-09-23 19:02:22 +08:00
|
|
|
|
2004-07-16 14:33:35 +08:00
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-03 02:40:46 +08:00
|
|
|
if (n == 0) {
|
|
|
|
again = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-07-16 14:33:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!again) {
|
2005-09-23 19:02:22 +08:00
|
|
|
sslerr = SSL_get_error(c->ssl->connection, n);
|
2004-07-16 14:33:35 +08:00
|
|
|
|
2004-07-19 03:11:20 +08:00
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
|
|
|
"SSL_get_error: %d", sslerr);
|
2004-07-16 14:33:35 +08:00
|
|
|
}
|
|
|
|
|
2005-12-16 23:07:08 +08:00
|
|
|
if (again
|
|
|
|
|| sslerr == SSL_ERROR_WANT_READ
|
|
|
|
|| sslerr == SSL_ERROR_WANT_WRITE)
|
|
|
|
{
|
2005-11-15 21:30:52 +08:00
|
|
|
c->read->handler = ngx_ssl_shutdown_handler;
|
2005-12-16 23:07:08 +08:00
|
|
|
c->write->handler = ngx_ssl_shutdown_handler;
|
2005-11-15 21:30:52 +08:00
|
|
|
|
2004-07-16 14:33:35 +08:00
|
|
|
if (ngx_handle_read_event(c->read, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ngx_handle_write_event(c->write, 0) == NGX_ERROR) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-12-16 23:07:08 +08:00
|
|
|
if (again || sslerr == SSL_ERROR_WANT_READ) {
|
|
|
|
ngx_add_timer(c->read, 30000);
|
|
|
|
}
|
|
|
|
|
2004-07-16 14:33:35 +08:00
|
|
|
return NGX_AGAIN;
|
|
|
|
}
|
|
|
|
|
2005-12-19 00:02:44 +08:00
|
|
|
err = (sslerr == SSL_ERROR_SYSCALL) ? ngx_errno : 0;
|
|
|
|
|
|
|
|
ngx_ssl_connection_error(c, sslerr, err, "SSL_shutdown() failed");
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-23 19:02:22 +08:00
|
|
|
SSL_free(c->ssl->connection);
|
|
|
|
c->ssl = NULL;
|
|
|
|
|
2004-07-16 00:35:51 +08:00
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-15 21:30:52 +08:00
|
|
|
static void
|
|
|
|
ngx_ssl_shutdown_handler(ngx_event_t *ev)
|
|
|
|
{
|
|
|
|
ngx_connection_t *c;
|
|
|
|
ngx_connection_handler_pt handler;
|
|
|
|
|
|
|
|
c = ev->data;
|
|
|
|
handler = c->ssl->handler;
|
|
|
|
|
|
|
|
if (ev->timedout) {
|
|
|
|
c->timedout = 1;
|
|
|
|
}
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, ev->log, 0, "SSL shutdown handler");
|
2005-11-15 21:30:52 +08:00
|
|
|
|
|
|
|
if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
handler(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
static void
|
|
|
|
ngx_ssl_connection_error(ngx_connection_t *c, int sslerr, ngx_err_t err,
|
|
|
|
char *text)
|
|
|
|
{
|
|
|
|
ngx_uint_t level;
|
|
|
|
|
|
|
|
level = NGX_LOG_CRIT;
|
|
|
|
|
|
|
|
if (sslerr == SSL_ERROR_SYSCALL) {
|
|
|
|
|
|
|
|
if (err == NGX_ECONNRESET
|
|
|
|
|| err == NGX_EPIPE
|
|
|
|
|| err == NGX_ENOTCONN
|
2005-12-16 23:07:08 +08:00
|
|
|
#if !(NGX_CRIT_ETIMEDOUT)
|
|
|
|
|| err == NGX_ETIMEDOUT
|
|
|
|
#endif
|
2005-09-30 22:41:25 +08:00
|
|
|
|| err == NGX_ECONNREFUSED
|
|
|
|
|| err == NGX_EHOSTUNREACH)
|
|
|
|
{
|
|
|
|
switch (c->log_error) {
|
|
|
|
|
|
|
|
case NGX_ERROR_IGNORE_ECONNRESET:
|
|
|
|
case NGX_ERROR_INFO:
|
|
|
|
level = NGX_LOG_INFO;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NGX_ERROR_ERR:
|
|
|
|
level = NGX_LOG_ERR;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_ssl_error(level, c->log, err, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-05 21:18:09 +08:00
|
|
|
void ngx_cdecl
|
2005-02-16 21:40:36 +08:00
|
|
|
ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err, char *fmt, ...)
|
2005-11-15 21:30:52 +08:00
|
|
|
{
|
2005-09-30 22:41:25 +08:00
|
|
|
u_long n;
|
2004-11-11 22:07:14 +08:00
|
|
|
va_list args;
|
2005-09-30 22:41:25 +08:00
|
|
|
u_char errstr[NGX_MAX_CONF_ERRSTR], *p, *last;
|
2004-11-11 22:07:14 +08:00
|
|
|
|
|
|
|
last = errstr + NGX_MAX_CONF_ERRSTR;
|
2004-07-16 00:35:51 +08:00
|
|
|
|
|
|
|
va_start(args, fmt);
|
2004-11-11 22:07:14 +08:00
|
|
|
p = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
|
2004-07-16 00:35:51 +08:00
|
|
|
va_end(args);
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
p = ngx_cpystrn(p, (u_char *) " (SSL:", last - p);
|
|
|
|
|
2005-12-05 21:18:09 +08:00
|
|
|
while (p < last) {
|
|
|
|
|
|
|
|
n = ERR_get_error();
|
|
|
|
|
|
|
|
if (n == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
*p++ = ' ';
|
|
|
|
|
|
|
|
ERR_error_string_n(n, (char *) p, last - p);
|
|
|
|
|
|
|
|
while (p < last && *p) {
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2004-07-16 00:35:51 +08:00
|
|
|
|
2004-07-17 01:11:43 +08:00
|
|
|
ngx_log_error(level, log, err, "%s)", errstr);
|
2004-07-16 00:35:51 +08:00
|
|
|
}
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx,
|
|
|
|
ssize_t builtin_session_cache, ngx_shm_zone_t *shm_zone, time_t timeout)
|
|
|
|
{
|
|
|
|
long cache_mode;
|
|
|
|
|
|
|
|
cache_mode = SSL_SESS_CACHE_SERVER;
|
|
|
|
|
|
|
|
if (shm_zone && builtin_session_cache == NGX_SSL_NO_BUILTIN_SCACHE) {
|
|
|
|
cache_mode |= SSL_SESS_CACHE_NO_INTERNAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SSL_CTX_set_session_cache_mode(ssl->ctx, cache_mode);
|
|
|
|
|
|
|
|
SSL_CTX_set_session_id_context(ssl->ctx, sess_ctx->data, sess_ctx->len);
|
|
|
|
|
|
|
|
if (builtin_session_cache != NGX_SSL_NO_BUILTIN_SCACHE) {
|
|
|
|
|
|
|
|
if (builtin_session_cache != NGX_SSL_DFLT_BUILTIN_SCACHE) {
|
|
|
|
SSL_CTX_sess_set_cache_size(ssl->ctx, builtin_session_cache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:57:09 +08:00
|
|
|
SSL_CTX_set_timeout(ssl->ctx, timeout);
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
if (shm_zone) {
|
|
|
|
shm_zone->init = ngx_ssl_session_cache_init;
|
|
|
|
|
|
|
|
SSL_CTX_sess_set_new_cb(ssl->ctx, ngx_ssl_new_session);
|
|
|
|
SSL_CTX_sess_set_get_cb(ssl->ctx, ngx_ssl_get_cached_session);
|
|
|
|
SSL_CTX_sess_set_remove_cb(ssl->ctx, ngx_ssl_remove_session);
|
|
|
|
|
|
|
|
if (SSL_CTX_set_ex_data(ssl->ctx, ngx_ssl_session_cache_index, shm_zone)
|
|
|
|
== 0)
|
|
|
|
{
|
|
|
|
ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0,
|
|
|
|
"SSL_CTX_set_ex_data() failed");
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_int_t
|
2007-01-09 23:59:20 +08:00
|
|
|
ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data)
|
2007-01-03 23:25:40 +08:00
|
|
|
{
|
|
|
|
ngx_slab_pool_t *shpool;
|
|
|
|
ngx_rbtree_node_t *sentinel;
|
|
|
|
ngx_ssl_session_cache_t *cache;
|
|
|
|
|
2007-01-09 23:59:20 +08:00
|
|
|
if (data) {
|
|
|
|
shm_zone->data = data;
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
|
|
|
|
|
|
|
|
cache = ngx_slab_alloc(shpool, sizeof(ngx_ssl_session_cache_t));
|
|
|
|
if (cache == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
cache->session_cache_head.prev = NULL;
|
|
|
|
cache->session_cache_head.next = &cache->session_cache_tail;
|
|
|
|
|
|
|
|
cache->session_cache_tail.prev = &cache->session_cache_head;
|
|
|
|
cache->session_cache_tail.next = NULL;
|
|
|
|
|
|
|
|
cache->session_rbtree = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_t));
|
|
|
|
if (cache->session_rbtree == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
sentinel = ngx_slab_alloc(shpool, sizeof(ngx_rbtree_node_t));
|
|
|
|
if (sentinel == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_rbtree_sentinel_init(sentinel);
|
|
|
|
|
|
|
|
cache->session_rbtree->root = sentinel;
|
|
|
|
cache->session_rbtree->sentinel = sentinel;
|
2007-01-13 04:57:34 +08:00
|
|
|
cache->session_rbtree->insert = ngx_ssl_session_rbtree_insert_value;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
shm_zone->data = cache;
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2007-01-12 01:39:02 +08:00
|
|
|
* The length of the session id is 16 bytes for SSLv2 sessions and
|
|
|
|
* between 1 and 32 bytes for SSLv3/TLSv1, typically 32 bytes.
|
|
|
|
* It seems that the typical length of the external ASN1 representation
|
|
|
|
* of a session is 118 or 119 bytes for SSLv3/TSLv1.
|
2007-01-12 02:59:17 +08:00
|
|
|
*
|
|
|
|
* Thus on 32-bit platforms we allocate separately an rbtree node,
|
|
|
|
* a session id, and an ASN1 representation, they take accordingly
|
|
|
|
* 64, 32, and 128 bytes.
|
|
|
|
*
|
|
|
|
* On 64-bit platforms we allocate separately an rbtree node + session_id,
|
|
|
|
* and an ASN1 representation, they take accordingly 128 and 128 bytes.
|
2007-01-12 01:39:02 +08:00
|
|
|
*
|
2007-01-03 23:25:40 +08:00
|
|
|
* OpenSSL's i2d_SSL_SESSION() and d2i_SSL_SESSION are slow,
|
|
|
|
* so they are outside the code locked by shared pool mutex
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int
|
|
|
|
ngx_ssl_new_session(ngx_ssl_conn_t *ssl_conn, ngx_ssl_session_t *sess)
|
|
|
|
{
|
|
|
|
int len;
|
2007-01-12 01:39:02 +08:00
|
|
|
u_char *p, *id, *cached_sess;
|
2007-01-03 23:25:40 +08:00
|
|
|
uint32_t hash;
|
|
|
|
SSL_CTX *ssl_ctx;
|
|
|
|
ngx_time_t *tp;
|
|
|
|
ngx_shm_zone_t *shm_zone;
|
|
|
|
ngx_connection_t *c;
|
|
|
|
ngx_slab_pool_t *shpool;
|
|
|
|
ngx_ssl_sess_id_t *sess_id;
|
|
|
|
ngx_ssl_session_cache_t *cache;
|
|
|
|
u_char buf[NGX_SSL_MAX_SESSION_SIZE];
|
|
|
|
|
|
|
|
len = i2d_SSL_SESSION(sess, NULL);
|
|
|
|
|
|
|
|
/* do not cache too big session */
|
|
|
|
|
|
|
|
if (len > (int) NGX_SSL_MAX_SESSION_SIZE) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = buf;
|
|
|
|
i2d_SSL_SESSION(sess, &p);
|
|
|
|
|
|
|
|
c = ngx_ssl_get_connection(ssl_conn);
|
|
|
|
|
|
|
|
ssl_ctx = SSL_get_SSL_CTX(ssl_conn);
|
|
|
|
shm_zone = SSL_CTX_get_ex_data(ssl_ctx, ngx_ssl_session_cache_index);
|
|
|
|
|
|
|
|
cache = shm_zone->data;
|
|
|
|
shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
|
|
|
|
|
|
|
|
ngx_shmtx_lock(&shpool->mutex);
|
|
|
|
|
|
|
|
/* drop one or two expired sessions */
|
|
|
|
ngx_ssl_expire_sessions(cache, shpool, 1);
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
cached_sess = ngx_slab_alloc_locked(shpool, len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
if (cached_sess == NULL) {
|
|
|
|
|
|
|
|
/* drop the oldest non-expired session and try once more */
|
|
|
|
|
|
|
|
ngx_ssl_expire_sessions(cache, shpool, 0);
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
cached_sess = ngx_slab_alloc_locked(shpool, len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
if (cached_sess == NULL) {
|
2007-01-12 02:59:17 +08:00
|
|
|
sess_id = NULL;
|
2007-01-03 23:25:40 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:59:17 +08:00
|
|
|
sess_id = ngx_slab_alloc_locked(shpool, sizeof(ngx_ssl_sess_id_t));
|
|
|
|
if (sess_id == NULL) {
|
2007-01-03 23:25:40 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:59:17 +08:00
|
|
|
#if (NGX_PTR_SIZE == 8)
|
|
|
|
|
|
|
|
id = sess_id->sess_id;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
id = ngx_slab_alloc_locked(shpool, sess->session_id_length);
|
|
|
|
if (id == NULL) {
|
2007-01-03 23:25:40 +08:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:59:17 +08:00
|
|
|
#endif
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
ngx_memcpy(cached_sess, buf, len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
ngx_memcpy(id, sess->session_id, sess->session_id_length);
|
|
|
|
|
|
|
|
hash = ngx_crc32_short(sess->session_id, sess->session_id_length);
|
|
|
|
|
|
|
|
ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
|
|
|
"http ssl new session: %08XD:%d:%d",
|
|
|
|
hash, sess->session_id_length, len);
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
tp = ngx_timeofday();
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
sess_id->node.key = hash;
|
|
|
|
sess_id->node.data = (u_char) sess->session_id_length;
|
|
|
|
sess_id->id = id;
|
|
|
|
sess_id->len = len;
|
|
|
|
sess_id->session = cached_sess;
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
sess_id->expire = tp->sec + SSL_CTX_get_timeout(ssl_ctx);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
sess_id->next = cache->session_cache_head.next;
|
|
|
|
sess_id->next->prev = sess_id;
|
|
|
|
sess_id->prev = &cache->session_cache_head;
|
|
|
|
cache->session_cache_head.next = sess_id;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
ngx_rbtree_insert(cache->session_rbtree, &sess_id->node);
|
|
|
|
|
|
|
|
ngx_shmtx_unlock(&shpool->mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
|
|
|
|
if (cached_sess) {
|
|
|
|
ngx_slab_free_locked(shpool, cached_sess);
|
|
|
|
}
|
|
|
|
|
2007-01-12 02:59:17 +08:00
|
|
|
if (sess_id) {
|
|
|
|
ngx_slab_free_locked(shpool, sess_id);
|
2007-01-03 23:25:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ngx_shmtx_unlock(&shpool->mutex);
|
|
|
|
|
|
|
|
ngx_log_error(NGX_LOG_ALERT, c->log, 0,
|
|
|
|
"could not add new SSL session to the session cache");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ngx_ssl_session_t *
|
|
|
|
ngx_ssl_get_cached_session(ngx_ssl_conn_t *ssl_conn, u_char *id, int len,
|
|
|
|
int *copy)
|
|
|
|
{
|
2007-01-09 00:20:33 +08:00
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x0090707fL
|
2007-01-03 23:25:40 +08:00
|
|
|
const
|
|
|
|
#endif
|
|
|
|
u_char *p;
|
|
|
|
uint32_t hash;
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_int_t rc;
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_time_t *tp;
|
|
|
|
ngx_shm_zone_t *shm_zone;
|
|
|
|
ngx_slab_pool_t *shpool;
|
|
|
|
ngx_connection_t *c;
|
|
|
|
ngx_rbtree_node_t *node, *sentinel;
|
|
|
|
ngx_ssl_session_t *sess;
|
|
|
|
ngx_ssl_sess_id_t *sess_id;
|
|
|
|
ngx_ssl_session_cache_t *cache;
|
|
|
|
u_char buf[NGX_SSL_MAX_SESSION_SIZE];
|
|
|
|
|
|
|
|
c = ngx_ssl_get_connection(ssl_conn);
|
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
hash = ngx_crc32_short(id, (size_t) len);
|
2007-01-03 23:25:40 +08:00
|
|
|
*copy = 0;
|
|
|
|
|
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
|
|
|
|
"http ssl get session: %08XD:%d", hash, len);
|
|
|
|
|
|
|
|
shm_zone = SSL_CTX_get_ex_data(SSL_get_SSL_CTX(ssl_conn),
|
|
|
|
ngx_ssl_session_cache_index);
|
|
|
|
|
|
|
|
cache = shm_zone->data;
|
|
|
|
|
|
|
|
if (cache->session_rbtree == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sess = NULL;
|
|
|
|
|
|
|
|
shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
|
|
|
|
|
|
|
|
ngx_shmtx_lock(&shpool->mutex);
|
|
|
|
|
|
|
|
node = cache->session_rbtree->root;
|
|
|
|
sentinel = cache->session_rbtree->sentinel;
|
|
|
|
|
|
|
|
while (node != sentinel) {
|
|
|
|
|
|
|
|
if (hash < node->key) {
|
|
|
|
node = node->left;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hash > node->key) {
|
|
|
|
node = node->right;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-12 01:05:18 +08:00
|
|
|
/* hash == node->key */
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-12 01:05:18 +08:00
|
|
|
do {
|
2007-01-13 04:57:34 +08:00
|
|
|
sess_id = (ngx_ssl_sess_id_t *) node;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 05:58:02 +08:00
|
|
|
rc = ngx_memn2cmp(id, sess_id->id,
|
2007-01-13 04:57:34 +08:00
|
|
|
(size_t) len, (size_t) node->data);
|
|
|
|
if (rc == 0) {
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
tp = ngx_timeofday();
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
if (sess_id->expire > tp->sec) {
|
|
|
|
ngx_memcpy(buf, sess_id->session, sess_id->len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_shmtx_unlock(&shpool->mutex);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
p = buf;
|
|
|
|
sess = d2i_SSL_SESSION(NULL, &p, sess_id->len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
return sess;
|
|
|
|
}
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
sess_id->next->prev = sess_id->prev;
|
|
|
|
sess_id->prev->next = sess_id->next;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_rbtree_delete(cache->session_rbtree, node);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id->session);
|
2007-01-12 02:59:17 +08:00
|
|
|
#if (NGX_PTR_SIZE == 4)
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id->id);
|
2007-01-12 02:59:17 +08:00
|
|
|
#endif
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
sess = NULL;
|
2007-01-12 01:05:18 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
goto done;
|
2007-01-03 23:25:40 +08:00
|
|
|
}
|
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
node = (rc < 0) ? node->left : node->right;
|
2007-01-12 01:05:18 +08:00
|
|
|
|
|
|
|
} while (node != sentinel && hash == node->key);
|
|
|
|
|
|
|
|
break;
|
2007-01-03 23:25:40 +08:00
|
|
|
}
|
|
|
|
|
2007-01-12 01:05:18 +08:00
|
|
|
done:
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_shmtx_unlock(&shpool->mutex);
|
|
|
|
|
|
|
|
return sess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ngx_ssl_remove_session(SSL_CTX *ssl, ngx_ssl_session_t *sess)
|
|
|
|
{
|
2007-01-13 04:57:34 +08:00
|
|
|
size_t len;
|
|
|
|
u_char *id;
|
2007-01-03 23:25:40 +08:00
|
|
|
uint32_t hash;
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_int_t rc;
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_shm_zone_t *shm_zone;
|
|
|
|
ngx_slab_pool_t *shpool;
|
|
|
|
ngx_rbtree_node_t *node, *sentinel;
|
|
|
|
ngx_ssl_sess_id_t *sess_id;
|
|
|
|
ngx_ssl_session_cache_t *cache;
|
|
|
|
|
|
|
|
shm_zone = SSL_CTX_get_ex_data(ssl, ngx_ssl_session_cache_index);
|
|
|
|
|
|
|
|
cache = shm_zone->data;
|
|
|
|
|
|
|
|
id = sess->session_id;
|
2007-01-13 04:57:34 +08:00
|
|
|
len = (size_t) sess->session_id_length;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
hash = ngx_crc32_short(id, len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
|
2007-01-13 04:57:34 +08:00
|
|
|
"http ssl remove session: %08XD:%uz", hash, len);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;
|
|
|
|
|
|
|
|
ngx_shmtx_lock(&shpool->mutex);
|
|
|
|
|
|
|
|
node = cache->session_rbtree->root;
|
|
|
|
sentinel = cache->session_rbtree->sentinel;
|
|
|
|
|
|
|
|
while (node != sentinel) {
|
|
|
|
|
|
|
|
if (hash < node->key) {
|
|
|
|
node = node->left;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hash > node->key) {
|
|
|
|
node = node->right;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-01-12 01:05:18 +08:00
|
|
|
/* hash == node->key */
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-12 01:05:18 +08:00
|
|
|
do {
|
2007-01-13 04:57:34 +08:00
|
|
|
sess_id = (ngx_ssl_sess_id_t *) node;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 05:58:02 +08:00
|
|
|
rc = ngx_memn2cmp(id, sess_id->id, len, (size_t) node->data);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
if (rc == 0) {
|
|
|
|
sess_id->next->prev = sess_id->prev;
|
|
|
|
sess_id->prev->next = sess_id->next;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_rbtree_delete(cache->session_rbtree, node);
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id->session);
|
2007-01-12 02:59:17 +08:00
|
|
|
#if (NGX_PTR_SIZE == 4)
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id->id);
|
2007-01-12 02:59:17 +08:00
|
|
|
#endif
|
2007-01-13 04:57:34 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id);
|
2007-01-12 01:05:18 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
goto done;
|
2007-01-13 04:26:39 +08:00
|
|
|
}
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
node = (rc < 0) ? node->left : node->right;
|
2007-01-12 01:05:18 +08:00
|
|
|
|
|
|
|
} while (node != sentinel && hash == node->key);
|
|
|
|
|
|
|
|
break;
|
2007-01-03 23:25:40 +08:00
|
|
|
}
|
|
|
|
|
2007-01-12 01:05:18 +08:00
|
|
|
done:
|
|
|
|
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_shmtx_unlock(&shpool->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ngx_ssl_expire_sessions(ngx_ssl_session_cache_t *cache,
|
|
|
|
ngx_slab_pool_t *shpool, ngx_uint_t n)
|
|
|
|
{
|
2007-01-12 01:39:02 +08:00
|
|
|
ngx_time_t *tp;
|
|
|
|
ngx_ssl_sess_id_t *sess_id;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
tp = ngx_timeofday();
|
|
|
|
|
|
|
|
while (n < 3) {
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
sess_id = cache->session_cache_tail.prev;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
if (sess_id == &cache->session_cache_head) {
|
2007-01-03 23:25:40 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
if (n++ != 0 && sess_id->expire > tp->sec) {
|
2007-01-03 23:25:40 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
sess_id->next->prev = sess_id->prev;
|
|
|
|
sess_id->prev->next = sess_id->next;
|
2007-01-03 23:25:40 +08:00
|
|
|
|
|
|
|
ngx_rbtree_delete(cache->session_rbtree, &sess_id->node);
|
|
|
|
|
|
|
|
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ngx_cycle->log, 0,
|
|
|
|
"expire session: %08Xi", sess_id->node.key);
|
|
|
|
|
2007-01-12 01:39:02 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id->session);
|
2007-01-12 02:59:17 +08:00
|
|
|
#if (NGX_PTR_SIZE == 4)
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id->id);
|
2007-01-12 02:59:17 +08:00
|
|
|
#endif
|
2007-01-03 23:25:40 +08:00
|
|
|
ngx_slab_free_locked(shpool, sess_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
static void
|
|
|
|
ngx_ssl_session_rbtree_insert_value(ngx_rbtree_node_t *temp,
|
|
|
|
ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
|
|
|
|
{
|
|
|
|
ngx_ssl_sess_id_t *sess_id, *sess_id_temp;
|
|
|
|
|
|
|
|
for ( ;; ) {
|
|
|
|
|
|
|
|
if (node->key < temp->key) {
|
|
|
|
|
|
|
|
if (temp->left == sentinel) {
|
|
|
|
temp->left = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = temp->left;
|
|
|
|
|
|
|
|
} else if (node->key > temp->key) {
|
|
|
|
|
2007-01-19 03:40:31 +08:00
|
|
|
if (temp->right == sentinel) {
|
2007-01-13 04:57:34 +08:00
|
|
|
temp->right = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = temp->right;
|
|
|
|
|
|
|
|
} else { /* node->key == temp->key */
|
|
|
|
|
|
|
|
sess_id = (ngx_ssl_sess_id_t *) node;
|
|
|
|
sess_id_temp = (ngx_ssl_sess_id_t *) temp;
|
|
|
|
|
2007-01-13 05:58:02 +08:00
|
|
|
if (ngx_memn2cmp(sess_id->id, sess_id_temp->id,
|
2007-01-13 04:57:34 +08:00
|
|
|
(size_t) node->data, (size_t) temp->data)
|
|
|
|
< 0)
|
|
|
|
{
|
|
|
|
if (temp->left == sentinel) {
|
|
|
|
temp->left = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = temp->left;
|
2007-01-19 03:40:31 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
} else {
|
2007-01-19 03:40:31 +08:00
|
|
|
|
2007-01-13 04:57:34 +08:00
|
|
|
if (temp->right == sentinel) {
|
|
|
|
temp->right = node;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = temp->right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->parent = temp;
|
|
|
|
node->left = sentinel;
|
|
|
|
node->right = sentinel;
|
|
|
|
ngx_rbt_red(node);
|
2007-01-19 03:40:31 +08:00
|
|
|
}
|
2007-01-13 04:57:34 +08:00
|
|
|
|
|
|
|
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
void
|
|
|
|
ngx_ssl_cleanup_ctx(void *data)
|
|
|
|
{
|
2005-12-16 23:07:08 +08:00
|
|
|
ngx_ssl_t *ssl = data;
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
|
2005-12-16 23:07:08 +08:00
|
|
|
SSL_CTX_free(ssl->ctx);
|
nginx-0.1.29-RELEASE import
*) Feature: the ngx_http_ssi_module supports "include virtual" command.
*) Feature: the ngx_http_ssi_module supports the condition command like
'if expr="$NAME"' and "else" and "endif" commands. Only one nested
level is supported.
*) Feature: the ngx_http_ssi_module supports the DATE_LOCAL and
DATE_GMT variables and "config timefmt" command.
*) Feature: the "ssi_ignore_recycled_buffers" directive.
*) Bugfix: the "echo" command did not show the default value for the
empty QUERY_STRING variable.
*) Change: the ngx_http_proxy_module was rewritten.
*) Feature: the "proxy_redirect", "proxy_pass_request_headers",
"proxy_pass_request_body", and "proxy_method" directives.
*) Feature: the "proxy_set_header" directive. The "proxy_x_var" was
canceled and must be replaced with the proxy_set_header directive.
*) Change: the "proxy_preserve_host" is canceled and must be replaced
with the "proxy_set_header Host $host" and the "proxy_redirect off"
directives, the "proxy_set_header Host $host:$proxy_port" directive
and the appropriate proxy_redirect directives.
*) Change: the "proxy_set_x_real_ip" is canceled and must be replaced
with the "proxy_set_header X-Real-IP $remote_addr" directive.
*) Change: the "proxy_add_x_forwarded_for" is canceled and must be
replaced with
the "proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for"
directive.
*) Change: the "proxy_set_x_url" is canceled and must be replaced with
the "proxy_set_header X-URL http://$host:$server_port$request_uri"
directive.
*) Feature: the "fastcgi_param" directive.
*) Change: the "fastcgi_root", "fastcgi_set_var" and "fastcgi_params"
directive are canceled and must be replaced with the fastcgi_param
directives.
*) Feature: the "index" directive can use the variables.
*) Feature: the "index" directive can be used at http and server levels.
*) Change: the last index only in the "index" directive can be absolute.
*) Feature: the "rewrite" directive can use the variables.
*) Feature: the "internal" directive.
*) Feature: the CONTENT_LENGTH, CONTENT_TYPE, REMOTE_PORT, SERVER_ADDR,
SERVER_PORT, SERVER_PROTOCOL, DOCUMENT_ROOT, SERVER_NAME,
REQUEST_METHOD, REQUEST_URI, and REMOTE_USER variables.
*) Change: nginx now passes the invalid lines in a client request
headers or a backend response header.
*) Bugfix: if the backend did not transfer response for a long time and
the "send_timeout" was less than "proxy_read_timeout", then nginx
returned the 408 response.
*) Bugfix: the segmentation fault was occurred if the backend sent an
invalid line in response header; the bug had appeared in 0.1.26.
*) Bugfix: the segmentation fault may occurred in FastCGI fault
tolerance configuration.
*) Bugfix: the "expires" directive did not remove the previous
"Expires" and "Cache-Control" headers.
*) Bugfix: nginx did not take into account trailing dot in "Host"
header line.
*) Bugfix: the ngx_http_auth_module did not work under Linux.
*) Bugfix: the rewrite directive worked incorrectly, if the arguments
were in a request.
*) Bugfix: nginx could not be built on MacOS X.
2005-05-12 22:58:06 +08:00
|
|
|
}
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
2006-02-08 23:33:12 +08:00
|
|
|
{
|
2006-08-10 03:59:45 +08:00
|
|
|
s->data = (u_char *) SSL_get_version(c->ssl->connection);
|
|
|
|
return NGX_OK;
|
2006-02-08 23:33:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_get_cipher_name(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
2006-02-08 23:33:12 +08:00
|
|
|
{
|
2006-08-10 03:59:45 +08:00
|
|
|
s->data = (u_char *) SSL_get_cipher_name(c->ssl->connection);
|
|
|
|
return NGX_OK;
|
2006-02-08 23:33:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-05-07 00:28:56 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_get_subject_dn(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
size_t len;
|
|
|
|
X509 *cert;
|
|
|
|
X509_NAME *name;
|
|
|
|
|
|
|
|
s->len = 0;
|
|
|
|
|
|
|
|
cert = SSL_get_peer_certificate(c->ssl->connection);
|
|
|
|
if (cert == NULL) {
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = X509_get_subject_name(cert);
|
|
|
|
if (name == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = X509_NAME_oneline(name, NULL, 0);
|
|
|
|
|
|
|
|
for (len = 0; p[len]; len++) { /* void */ }
|
|
|
|
|
|
|
|
s->len = len;
|
|
|
|
s->data = ngx_palloc(pool, len);
|
|
|
|
if (s->data == NULL) {
|
|
|
|
OPENSSL_free(p);
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_memcpy(s->data, p, len);
|
|
|
|
|
|
|
|
OPENSSL_free(p);
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_get_issuer_dn(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
size_t len;
|
|
|
|
X509 *cert;
|
|
|
|
X509_NAME *name;
|
|
|
|
|
|
|
|
s->len = 0;
|
|
|
|
|
|
|
|
cert = SSL_get_peer_certificate(c->ssl->connection);
|
|
|
|
if (cert == NULL) {
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = X509_get_issuer_name(cert);
|
|
|
|
if (name == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = X509_NAME_oneline(name, NULL, 0);
|
|
|
|
|
|
|
|
for (len = 0; p[len]; len++) { /* void */ }
|
|
|
|
|
|
|
|
s->len = len;
|
|
|
|
s->data = ngx_palloc(pool, len);
|
|
|
|
if (s->data == NULL) {
|
|
|
|
OPENSSL_free(p);
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ngx_memcpy(s->data, p, len);
|
|
|
|
|
|
|
|
OPENSSL_free(p);
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-10 03:59:45 +08:00
|
|
|
ngx_int_t
|
|
|
|
ngx_ssl_get_serial_number(ngx_connection_t *c, ngx_pool_t *pool, ngx_str_t *s)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
X509 *cert;
|
|
|
|
BIO *bio;
|
|
|
|
|
|
|
|
s->len = 0;
|
|
|
|
|
|
|
|
cert = SSL_get_peer_certificate(c->ssl->connection);
|
|
|
|
if (cert == NULL) {
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio = BIO_new(BIO_s_mem());
|
|
|
|
if (bio == NULL) {
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
i2a_ASN1_INTEGER(bio, X509_get_serialNumber(cert));
|
|
|
|
len = BIO_pending(bio);
|
|
|
|
|
|
|
|
s->len = len;
|
|
|
|
s->data = ngx_palloc(pool, len);
|
|
|
|
if (s->data == NULL) {
|
|
|
|
BIO_free(bio);
|
|
|
|
return NGX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
BIO_read(bio, s->data, len);
|
|
|
|
BIO_free(bio);
|
|
|
|
|
|
|
|
return NGX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
static void *
|
|
|
|
ngx_openssl_create_conf(ngx_cycle_t *cycle)
|
|
|
|
{
|
|
|
|
ngx_openssl_conf_t *oscf;
|
2005-11-15 21:30:52 +08:00
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
oscf = ngx_pcalloc(cycle->pool, sizeof(ngx_openssl_conf_t));
|
|
|
|
if (oscf == NULL) {
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
2005-11-15 21:30:52 +08:00
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
/*
|
|
|
|
* set by ngx_pcalloc():
|
2005-11-15 21:30:52 +08:00
|
|
|
*
|
2005-09-08 22:36:09 +08:00
|
|
|
* oscf->engine.len = 0;
|
|
|
|
* oscf->engine.data = NULL;
|
2005-11-15 21:30:52 +08:00
|
|
|
*/
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
return oscf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
ngx_openssl_init_conf(ngx_cycle_t *cycle, void *conf)
|
|
|
|
{
|
|
|
|
#if (NGX_SSL_ENGINE)
|
|
|
|
ngx_openssl_conf_t *oscf = conf;
|
2005-10-27 23:46:13 +08:00
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
ENGINE *engine;
|
|
|
|
|
|
|
|
if (oscf->engine.len == 0) {
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
2005-11-15 21:30:52 +08:00
|
|
|
|
2005-09-08 22:36:09 +08:00
|
|
|
engine = ENGINE_by_id((const char *) oscf->engine.data);
|
|
|
|
|
|
|
|
if (engine == NULL) {
|
|
|
|
ngx_ssl_error(NGX_LOG_WARN, cycle->log, 0,
|
|
|
|
"ENGINE_by_id(\"%V\") failed", &oscf->engine);
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) {
|
|
|
|
ngx_ssl_error(NGX_LOG_WARN, cycle->log, 0,
|
|
|
|
"ENGINE_set_default(\"%V\", ENGINE_METHOD_ALL) failed",
|
|
|
|
&oscf->engine);
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ENGINE_free(engine);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NGX_CONF_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if !(NGX_SSL_ENGINE)
|
|
|
|
|
|
|
|
static char *
|
|
|
|
ngx_openssl_noengine(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
|
|
|
|
{
|
|
|
|
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
|
2005-10-19 20:33:58 +08:00
|
|
|
"\"ssl_engine\" directive is available only in "
|
|
|
|
"OpenSSL 0.9.7 and higher,");
|
2005-09-08 22:36:09 +08:00
|
|
|
|
|
|
|
return NGX_CONF_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2005-10-27 23:46:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
ngx_openssl_exit(ngx_cycle_t *cycle)
|
|
|
|
{
|
|
|
|
#if (NGX_SSL_ENGINE)
|
|
|
|
ENGINE_cleanup();
|
|
|
|
#endif
|
|
|
|
}
|