Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.13.12 ]​[ nginx-1.12.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #ifndef _NGX_EVENT_OPENSSL_H_INCLUDED_
0009 #define _NGX_EVENT_OPENSSL_H_INCLUDED_
0010 
0011 
0012 #include <ngx_config.h>
0013 #include <ngx_core.h>
0014 
0015 #include <openssl/ssl.h>
0016 #include <openssl/err.h>
0017 #include <openssl/bn.h>
0018 #include <openssl/conf.h>
0019 #include <openssl/crypto.h>
0020 #include <openssl/dh.h>
0021 #ifndef OPENSSL_NO_ENGINE
0022 #include <openssl/engine.h>
0023 #endif
0024 #include <openssl/evp.h>
0025 #ifndef OPENSSL_NO_OCSP
0026 #include <openssl/ocsp.h>
0027 #endif
0028 #include <openssl/rand.h>
0029 #include <openssl/rsa.h>
0030 #include <openssl/x509.h>
0031 #include <openssl/x509v3.h>
0032 
0033 #define NGX_SSL_NAME     "OpenSSL"
0034 
0035 
0036 #if (defined LIBRESSL_VERSION_NUMBER && OPENSSL_VERSION_NUMBER == 0x20000000L)
0037 #undef OPENSSL_VERSION_NUMBER
0038 #define OPENSSL_VERSION_NUMBER  0x1000107fL
0039 #endif
0040 
0041 
0042 #if (OPENSSL_VERSION_NUMBER >= 0x10100001L)
0043 
0044 #define ngx_ssl_version()       OpenSSL_version(OPENSSL_VERSION)
0045 
0046 #else
0047 
0048 #define ngx_ssl_version()       SSLeay_version(SSLEAY_VERSION)
0049 
0050 #endif
0051 
0052 
0053 #define ngx_ssl_session_t       SSL_SESSION
0054 #define ngx_ssl_conn_t          SSL
0055 
0056 
0057 struct ngx_ssl_s {
0058     SSL_CTX                    *ctx;
0059     ngx_log_t                  *log;
0060     size_t                      buffer_size;
0061 };
0062 
0063 
0064 struct ngx_ssl_connection_s {
0065     ngx_ssl_conn_t             *connection;
0066     SSL_CTX                    *session_ctx;
0067 
0068     ngx_int_t                   last;
0069     ngx_buf_t                  *buf;
0070     size_t                      buffer_size;
0071 
0072     ngx_connection_handler_pt   handler;
0073 
0074     ngx_event_handler_pt        saved_read_handler;
0075     ngx_event_handler_pt        saved_write_handler;
0076 
0077     unsigned                    handshaked:1;
0078     unsigned                    renegotiation:1;
0079     unsigned                    buffer:1;
0080     unsigned                    no_wait_shutdown:1;
0081     unsigned                    no_send_shutdown:1;
0082     unsigned                    handshake_buffer_set:1;
0083 };
0084 
0085 
0086 #define NGX_SSL_NO_SCACHE            -2
0087 #define NGX_SSL_NONE_SCACHE          -3
0088 #define NGX_SSL_NO_BUILTIN_SCACHE    -4
0089 #define NGX_SSL_DFLT_BUILTIN_SCACHE  -5
0090 
0091 
0092 #define NGX_SSL_MAX_SESSION_SIZE  4096
0093 
0094 typedef struct ngx_ssl_sess_id_s  ngx_ssl_sess_id_t;
0095 
0096 struct ngx_ssl_sess_id_s {
0097     ngx_rbtree_node_t           node;
0098     u_char                     *id;
0099     size_t                      len;
0100     u_char                     *session;
0101     ngx_queue_t                 queue;
0102     time_t                      expire;
0103 #if (NGX_PTR_SIZE == 8)
0104     void                       *stub;
0105     u_char                      sess_id[32];
0106 #endif
0107 };
0108 
0109 
0110 typedef struct {
0111     ngx_rbtree_t                session_rbtree;
0112     ngx_rbtree_node_t           sentinel;
0113     ngx_queue_t                 expire_queue;
0114 } ngx_ssl_session_cache_t;
0115 
0116 
0117 #ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB
0118 
0119 typedef struct {
0120     size_t                      size;
0121     u_char                      name[16];
0122     u_char                      hmac_key[32];
0123     u_char                      aes_key[32];
0124 } ngx_ssl_session_ticket_key_t;
0125 
0126 #endif
0127 
0128 
0129 #define NGX_SSL_SSLv2    0x0002
0130 #define NGX_SSL_SSLv3    0x0004
0131 #define NGX_SSL_TLSv1    0x0008
0132 #define NGX_SSL_TLSv1_1  0x0010
0133 #define NGX_SSL_TLSv1_2  0x0020
0134 
0135 
0136 #define NGX_SSL_BUFFER   1
0137 #define NGX_SSL_CLIENT   2
0138 
0139 #define NGX_SSL_BUFSIZE  16384
0140 
0141 
0142 ngx_int_t ngx_ssl_init(ngx_log_t *log);
0143 ngx_int_t ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data);
0144 ngx_int_t ngx_ssl_certificates(ngx_conf_t *cf, ngx_ssl_t *ssl,
0145     ngx_array_t *certs, ngx_array_t *keys, ngx_array_t *passwords);
0146 ngx_int_t ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
0147     ngx_str_t *cert, ngx_str_t *key, ngx_array_t *passwords);
0148 ngx_int_t ngx_ssl_ciphers(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *ciphers,
0149     ngx_uint_t prefer_server_ciphers);
0150 ngx_int_t ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
0151     ngx_str_t *cert, ngx_int_t depth);
0152 ngx_int_t ngx_ssl_trusted_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
0153     ngx_str_t *cert, ngx_int_t depth);
0154 ngx_int_t ngx_ssl_crl(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *crl);
0155 ngx_int_t ngx_ssl_stapling(ngx_conf_t *cf, ngx_ssl_t *ssl,
0156     ngx_str_t *file, ngx_str_t *responder, ngx_uint_t verify);
0157 ngx_int_t ngx_ssl_stapling_resolver(ngx_conf_t *cf, ngx_ssl_t *ssl,
0158     ngx_resolver_t *resolver, ngx_msec_t resolver_timeout);
0159 RSA *ngx_ssl_rsa512_key_callback(ngx_ssl_conn_t *ssl_conn, int is_export,
0160     int key_length);
0161 ngx_array_t *ngx_ssl_read_password_file(ngx_conf_t *cf, ngx_str_t *file);
0162 ngx_int_t ngx_ssl_dhparam(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file);
0163 ngx_int_t ngx_ssl_ecdh_curve(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *name);
0164 ngx_int_t ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx,
0165     ssize_t builtin_session_cache, ngx_shm_zone_t *shm_zone, time_t timeout);
0166 ngx_int_t ngx_ssl_session_ticket_keys(ngx_conf_t *cf, ngx_ssl_t *ssl,
0167     ngx_array_t *paths);
0168 ngx_int_t ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data);
0169 ngx_int_t ngx_ssl_create_connection(ngx_ssl_t *ssl, ngx_connection_t *c,
0170     ngx_uint_t flags);
0171 
0172 void ngx_ssl_remove_cached_session(SSL_CTX *ssl, ngx_ssl_session_t *sess);
0173 ngx_int_t ngx_ssl_set_session(ngx_connection_t *c, ngx_ssl_session_t *session);
0174 #define ngx_ssl_get_session(c)      SSL_get1_session(c->ssl->connection)
0175 #define ngx_ssl_free_session        SSL_SESSION_free
0176 #define ngx_ssl_get_connection(ssl_conn)                                      \
0177     SSL_get_ex_data(ssl_conn, ngx_ssl_connection_index)
0178 #define ngx_ssl_get_server_conf(ssl_ctx)                                      \
0179     SSL_CTX_get_ex_data(ssl_ctx, ngx_ssl_server_conf_index)
0180 
0181 #define ngx_ssl_verify_error_optional(n)                                      \
0182     (n == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT                              \
0183      || n == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN                             \
0184      || n == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY                     \
0185      || n == X509_V_ERR_CERT_UNTRUSTED                                        \
0186      || n == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE)
0187 
0188 ngx_int_t ngx_ssl_check_host(ngx_connection_t *c, ngx_str_t *name);
0189 
0190 
0191 ngx_int_t ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool,
0192     ngx_str_t *s);
0193 ngx_int_t ngx_ssl_get_cipher_name(ngx_connection_t *c, ngx_pool_t *pool,
0194     ngx_str_t *s);
0195 ngx_int_t ngx_ssl_get_ciphers(ngx_connection_t *c, ngx_pool_t *pool,
0196     ngx_str_t *s);
0197 ngx_int_t ngx_ssl_get_curves(ngx_connection_t *c, ngx_pool_t *pool,
0198     ngx_str_t *s);
0199 ngx_int_t ngx_ssl_get_session_id(ngx_connection_t *c, ngx_pool_t *pool,
0200     ngx_str_t *s);
0201 ngx_int_t ngx_ssl_get_session_reused(ngx_connection_t *c, ngx_pool_t *pool,
0202     ngx_str_t *s);
0203 ngx_int_t ngx_ssl_get_server_name(ngx_connection_t *c, ngx_pool_t *pool,
0204     ngx_str_t *s);
0205 ngx_int_t ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool,
0206     ngx_str_t *s);
0207 ngx_int_t ngx_ssl_get_certificate(ngx_connection_t *c, ngx_pool_t *pool,
0208     ngx_str_t *s);
0209 ngx_int_t ngx_ssl_get_subject_dn(ngx_connection_t *c, ngx_pool_t *pool,
0210     ngx_str_t *s);
0211 ngx_int_t ngx_ssl_get_issuer_dn(ngx_connection_t *c, ngx_pool_t *pool,
0212     ngx_str_t *s);
0213 ngx_int_t ngx_ssl_get_subject_dn_legacy(ngx_connection_t *c, ngx_pool_t *pool,
0214     ngx_str_t *s);
0215 ngx_int_t ngx_ssl_get_issuer_dn_legacy(ngx_connection_t *c, ngx_pool_t *pool,
0216     ngx_str_t *s);
0217 ngx_int_t ngx_ssl_get_serial_number(ngx_connection_t *c, ngx_pool_t *pool,
0218     ngx_str_t *s);
0219 ngx_int_t ngx_ssl_get_fingerprint(ngx_connection_t *c, ngx_pool_t *pool,
0220     ngx_str_t *s);
0221 ngx_int_t ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool,
0222     ngx_str_t *s);
0223 ngx_int_t ngx_ssl_get_client_v_start(ngx_connection_t *c, ngx_pool_t *pool,
0224     ngx_str_t *s);
0225 ngx_int_t ngx_ssl_get_client_v_end(ngx_connection_t *c, ngx_pool_t *pool,
0226     ngx_str_t *s);
0227 ngx_int_t ngx_ssl_get_client_v_remain(ngx_connection_t *c, ngx_pool_t *pool,
0228     ngx_str_t *s);
0229 
0230 
0231 ngx_int_t ngx_ssl_handshake(ngx_connection_t *c);
0232 ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
0233 ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
0234 ssize_t ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl, off_t limit);
0235 ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
0236     off_t limit);
0237 void ngx_ssl_free_buffer(ngx_connection_t *c);
0238 ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c);
0239 void ngx_cdecl ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
0240     char *fmt, ...);
0241 void ngx_ssl_cleanup_ctx(void *data);
0242 
0243 
0244 extern int  ngx_ssl_connection_index;
0245 extern int  ngx_ssl_server_conf_index;
0246 extern int  ngx_ssl_session_cache_index;
0247 extern int  ngx_ssl_session_ticket_keys_index;
0248 extern int  ngx_ssl_certificate_index;
0249 extern int  ngx_ssl_next_certificate_index;
0250 extern int  ngx_ssl_certificate_name_index;
0251 extern int  ngx_ssl_stapling_index;
0252 
0253 
0254 #endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */