src/event/ngx_event_openssl.h - nginx-1.7.10

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_EVENT_OPENSSL_H_INCLUDED_
  6. #define _NGX_EVENT_OPENSSL_H_INCLUDED_


  7. #include <ngx_config.h>
  8. #include <ngx_core.h>

  9. #include <openssl/ssl.h>
  10. #include <openssl/err.h>
  11. #include <openssl/bn.h>
  12. #include <openssl/conf.h>
  13. #include <openssl/crypto.h>
  14. #include <openssl/dh.h>
  15. #ifndef OPENSSL_NO_ENGINE
  16. #include <openssl/engine.h>
  17. #endif
  18. #include <openssl/evp.h>
  19. #ifndef OPENSSL_NO_OCSP
  20. #include <openssl/ocsp.h>
  21. #endif
  22. #include <openssl/rand.h>
  23. #include <openssl/rsa.h>
  24. #include <openssl/x509.h>
  25. #include <openssl/x509v3.h>

  26. #define NGX_SSL_NAME     "OpenSSL"


  27. #define ngx_ssl_session_t       SSL_SESSION
  28. #define ngx_ssl_conn_t          SSL


  29. typedef struct {
  30.     SSL_CTX                    *ctx;
  31.     ngx_log_t                  *log;
  32.     size_t                      buffer_size;
  33. } ngx_ssl_t;


  34. typedef struct {
  35.     ngx_ssl_conn_t             *connection;

  36.     ngx_int_t                   last;
  37.     ngx_buf_t                  *buf;
  38.     size_t                      buffer_size;

  39.     ngx_connection_handler_pt   handler;

  40.     ngx_event_handler_pt        saved_read_handler;
  41.     ngx_event_handler_pt        saved_write_handler;

  42.     unsigned                    handshaked:1;
  43.     unsigned                    renegotiation:1;
  44.     unsigned                    buffer:1;
  45.     unsigned                    no_wait_shutdown:1;
  46.     unsigned                    no_send_shutdown:1;
  47.     unsigned                    handshake_buffer_set:1;
  48. } ngx_ssl_connection_t;


  49. #define NGX_SSL_NO_SCACHE            -2
  50. #define NGX_SSL_NONE_SCACHE          -3
  51. #define NGX_SSL_NO_BUILTIN_SCACHE    -4
  52. #define NGX_SSL_DFLT_BUILTIN_SCACHE  -5


  53. #define NGX_SSL_MAX_SESSION_SIZE  4096

  54. typedef struct ngx_ssl_sess_id_s  ngx_ssl_sess_id_t;

  55. struct ngx_ssl_sess_id_s {
  56.     ngx_rbtree_node_t           node;
  57.     u_char                     *id;
  58.     size_t                      len;
  59.     u_char                     *session;
  60.     ngx_queue_t                 queue;
  61.     time_t                      expire;
  62. #if (NGX_PTR_SIZE == 8)
  63.     void                       *stub;
  64.     u_char                      sess_id[32];
  65. #endif
  66. };


  67. typedef struct {
  68.     ngx_rbtree_t                session_rbtree;
  69.     ngx_rbtree_node_t           sentinel;
  70.     ngx_queue_t                 expire_queue;
  71. } ngx_ssl_session_cache_t;


  72. #ifdef SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB

  73. typedef struct {
  74.     u_char                      name[16];
  75.     u_char                      aes_key[16];
  76.     u_char                      hmac_key[16];
  77. } ngx_ssl_session_ticket_key_t;

  78. #endif


  79. #define NGX_SSL_SSLv2    0x0002
  80. #define NGX_SSL_SSLv3    0x0004
  81. #define NGX_SSL_TLSv1    0x0008
  82. #define NGX_SSL_TLSv1_1  0x0010
  83. #define NGX_SSL_TLSv1_2  0x0020


  84. #define NGX_SSL_BUFFER   1
  85. #define NGX_SSL_CLIENT   2

  86. #define NGX_SSL_BUFSIZE  16384


  87. ngx_int_t ngx_ssl_init(ngx_log_t *log);
  88. ngx_int_t ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data);
  89. ngx_int_t ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
  90.     ngx_str_t *cert, ngx_str_t *key, ngx_array_t *passwords);
  91. ngx_int_t ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
  92.     ngx_str_t *cert, ngx_int_t depth);
  93. ngx_int_t ngx_ssl_trusted_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
  94.     ngx_str_t *cert, ngx_int_t depth);
  95. ngx_int_t ngx_ssl_crl(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *crl);
  96. ngx_int_t ngx_ssl_stapling(ngx_conf_t *cf, ngx_ssl_t *ssl,
  97.     ngx_str_t *file, ngx_str_t *responder, ngx_uint_t verify);
  98. ngx_int_t ngx_ssl_stapling_resolver(ngx_conf_t *cf, ngx_ssl_t *ssl,
  99.     ngx_resolver_t *resolver, ngx_msec_t resolver_timeout);
  100. RSA *ngx_ssl_rsa512_key_callback(ngx_ssl_conn_t *ssl_conn, int is_export,
  101.     int key_length);
  102. ngx_array_t *ngx_ssl_read_password_file(ngx_conf_t *cf, ngx_str_t *file);
  103. ngx_int_t ngx_ssl_dhparam(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file);
  104. ngx_int_t ngx_ssl_ecdh_curve(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *name);
  105. ngx_int_t ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx,
  106.     ssize_t builtin_session_cache, ngx_shm_zone_t *shm_zone, time_t timeout);
  107. ngx_int_t ngx_ssl_session_ticket_keys(ngx_conf_t *cf, ngx_ssl_t *ssl,
  108.     ngx_array_t *paths);
  109. ngx_int_t ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data);
  110. ngx_int_t ngx_ssl_create_connection(ngx_ssl_t *ssl, ngx_connection_t *c,
  111.     ngx_uint_t flags);

  112. void ngx_ssl_remove_cached_session(SSL_CTX *ssl, ngx_ssl_session_t *sess);
  113. ngx_int_t ngx_ssl_set_session(ngx_connection_t *c, ngx_ssl_session_t *session);
  114. #define ngx_ssl_get_session(c)      SSL_get1_session(c->ssl->connection)
  115. #define ngx_ssl_free_session        SSL_SESSION_free
  116. #define ngx_ssl_get_connection(ssl_conn)                                      \
  117.     SSL_get_ex_data(ssl_conn, ngx_ssl_connection_index)
  118. #define ngx_ssl_get_server_conf(ssl_ctx)                                      \
  119.     SSL_CTX_get_ex_data(ssl_ctx, ngx_ssl_server_conf_index)

  120. #define ngx_ssl_verify_error_optional(n)                                      \
  121.     (n == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT                              \
  122.      || n == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN                             \
  123.      || n == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY                     \
  124.      || n == X509_V_ERR_CERT_UNTRUSTED                                        \
  125.      || n == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE)

  126. ngx_int_t ngx_ssl_check_host(ngx_connection_t *c, ngx_str_t *name);


  127. ngx_int_t ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool,
  128.     ngx_str_t *s);
  129. ngx_int_t ngx_ssl_get_cipher_name(ngx_connection_t *c, ngx_pool_t *pool,
  130.     ngx_str_t *s);
  131. ngx_int_t ngx_ssl_get_session_id(ngx_connection_t *c, ngx_pool_t *pool,
  132.     ngx_str_t *s);
  133. ngx_int_t ngx_ssl_get_session_reused(ngx_connection_t *c, ngx_pool_t *pool,
  134.     ngx_str_t *s);
  135. ngx_int_t ngx_ssl_get_server_name(ngx_connection_t *c, ngx_pool_t *pool,
  136.     ngx_str_t *s);
  137. ngx_int_t ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool,
  138.     ngx_str_t *s);
  139. ngx_int_t ngx_ssl_get_certificate(ngx_connection_t *c, ngx_pool_t *pool,
  140.     ngx_str_t *s);
  141. ngx_int_t ngx_ssl_get_subject_dn(ngx_connection_t *c, ngx_pool_t *pool,
  142.     ngx_str_t *s);
  143. ngx_int_t ngx_ssl_get_issuer_dn(ngx_connection_t *c, ngx_pool_t *pool,
  144.     ngx_str_t *s);
  145. ngx_int_t ngx_ssl_get_serial_number(ngx_connection_t *c, ngx_pool_t *pool,
  146.     ngx_str_t *s);
  147. ngx_int_t ngx_ssl_get_fingerprint(ngx_connection_t *c, ngx_pool_t *pool,
  148.     ngx_str_t *s);
  149. ngx_int_t ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool,
  150.     ngx_str_t *s);


  151. ngx_int_t ngx_ssl_handshake(ngx_connection_t *c);
  152. ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
  153. ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
  154. ssize_t ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl, off_t limit);
  155. ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
  156.     off_t limit);
  157. void ngx_ssl_free_buffer(ngx_connection_t *c);
  158. ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c);
  159. void ngx_cdecl ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
  160.     char *fmt, ...);
  161. void ngx_ssl_cleanup_ctx(void *data);


  162. extern int  ngx_ssl_connection_index;
  163. extern int  ngx_ssl_server_conf_index;
  164. extern int  ngx_ssl_session_cache_index;
  165. extern int  ngx_ssl_session_ticket_keys_index;
  166. extern int  ngx_ssl_certificate_index;
  167. extern int  ngx_ssl_stapling_index;


  168. #endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */