0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
660
|
4 * Copyright (C) Nginx, Inc.
|
0
|
5 */
|
|
6
|
|
7
|
|
8 #ifndef _NGX_EVENT_OPENSSL_H_INCLUDED_
|
|
9 #define _NGX_EVENT_OPENSSL_H_INCLUDED_
|
|
10
|
|
11
|
|
12 #include <ngx_config.h>
|
|
13 #include <ngx_core.h>
|
|
14
|
|
15 #include <openssl/ssl.h>
|
|
16 #include <openssl/err.h>
|
272
|
17 #include <openssl/conf.h>
|
90
|
18 #include <openssl/engine.h>
|
564
|
19 #include <openssl/evp.h>
|
688
|
20 #include <openssl/ocsp.h>
|
90
|
21
|
96
|
22 #define NGX_SSL_NAME "OpenSSL"
|
|
23
|
|
24
|
220
|
25 #define ngx_ssl_session_t SSL_SESSION
|
|
26 #define ngx_ssl_conn_t SSL
|
|
27
|
|
28
|
96
|
29 typedef struct {
|
|
30 SSL_CTX *ctx;
|
|
31 ngx_log_t *log;
|
|
32 } ngx_ssl_t;
|
90
|
33
|
0
|
34
|
|
35 typedef struct {
|
220
|
36 ngx_ssl_conn_t *connection;
|
196
|
37
|
96
|
38 ngx_int_t last;
|
|
39 ngx_buf_t *buf;
|
|
40
|
|
41 ngx_connection_handler_pt handler;
|
0
|
42
|
96
|
43 ngx_event_handler_pt saved_read_handler;
|
|
44 ngx_event_handler_pt saved_write_handler;
|
28
|
45
|
96
|
46 unsigned handshaked:1;
|
542
|
47 unsigned renegotiation:1;
|
96
|
48 unsigned buffer:1;
|
|
49 unsigned no_wait_shutdown:1;
|
|
50 unsigned no_send_shutdown:1;
|
|
51 } ngx_ssl_connection_t;
|
0
|
52
|
|
53
|
378
|
54 #define NGX_SSL_NO_SCACHE -2
|
|
55 #define NGX_SSL_NONE_SCACHE -3
|
|
56 #define NGX_SSL_NO_BUILTIN_SCACHE -4
|
|
57 #define NGX_SSL_DFLT_BUILTIN_SCACHE -5
|
272
|
58
|
|
59
|
358
|
60 #define NGX_SSL_MAX_SESSION_SIZE 4096
|
272
|
61
|
274
|
62 typedef struct ngx_ssl_sess_id_s ngx_ssl_sess_id_t;
|
272
|
63
|
274
|
64 struct ngx_ssl_sess_id_s {
|
272
|
65 ngx_rbtree_node_t node;
|
|
66 u_char *id;
|
|
67 size_t len;
|
274
|
68 u_char *session;
|
358
|
69 ngx_queue_t queue;
|
272
|
70 time_t expire;
|
274
|
71 #if (NGX_PTR_SIZE == 8)
|
|
72 void *stub;
|
|
73 u_char sess_id[32];
|
|
74 #endif
|
272
|
75 };
|
|
76
|
|
77
|
|
78 typedef struct {
|
358
|
79 ngx_rbtree_t session_rbtree;
|
|
80 ngx_rbtree_node_t sentinel;
|
|
81 ngx_queue_t expire_queue;
|
272
|
82 } ngx_ssl_session_cache_t;
|
|
83
|
|
84
|
|
85
|
658
|
86 #define NGX_SSL_SSLv2 0x0002
|
|
87 #define NGX_SSL_SSLv3 0x0004
|
|
88 #define NGX_SSL_TLSv1 0x0008
|
|
89 #define NGX_SSL_TLSv1_1 0x0010
|
|
90 #define NGX_SSL_TLSv1_2 0x0020
|
0
|
91
|
|
92
|
96
|
93 #define NGX_SSL_BUFFER 1
|
126
|
94 #define NGX_SSL_CLIENT 2
|
0
|
95
|
96
|
96 #define NGX_SSL_BUFSIZE 16384
|
0
|
97
|
|
98
|
|
99 ngx_int_t ngx_ssl_init(ngx_log_t *log);
|
272
|
100 ngx_int_t ngx_ssl_create(ngx_ssl_t *ssl, ngx_uint_t protocols, void *data);
|
112
|
101 ngx_int_t ngx_ssl_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
|
102 ngx_str_t *cert, ngx_str_t *key);
|
196
|
103 ngx_int_t ngx_ssl_client_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
220
|
104 ngx_str_t *cert, ngx_int_t depth);
|
688
|
105 ngx_int_t ngx_ssl_trusted_certificate(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
|
106 ngx_str_t *cert, ngx_int_t depth);
|
510
|
107 ngx_int_t ngx_ssl_crl(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *crl);
|
688
|
108 ngx_int_t ngx_ssl_stapling(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
|
109 ngx_str_t *file, ngx_str_t *responder, ngx_uint_t verify);
|
|
110 ngx_int_t ngx_ssl_stapling_resolver(ngx_conf_t *cf, ngx_ssl_t *ssl,
|
|
111 ngx_resolver_t *resolver, ngx_msec_t resolver_timeout);
|
632
|
112 RSA *ngx_ssl_rsa512_key_callback(SSL *ssl, int is_export, int key_length);
|
380
|
113 ngx_int_t ngx_ssl_dhparam(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *file);
|
632
|
114 ngx_int_t ngx_ssl_ecdh_curve(ngx_conf_t *cf, ngx_ssl_t *ssl, ngx_str_t *name);
|
272
|
115 ngx_int_t ngx_ssl_session_cache(ngx_ssl_t *ssl, ngx_str_t *sess_ctx,
|
|
116 ssize_t builtin_session_cache, ngx_shm_zone_t *shm_zone, time_t timeout);
|
634
|
117 ngx_int_t ngx_ssl_session_cache_init(ngx_shm_zone_t *shm_zone, void *data);
|
96
|
118 ngx_int_t ngx_ssl_create_connection(ngx_ssl_t *ssl, ngx_connection_t *c,
|
92
|
119 ngx_uint_t flags);
|
126
|
120
|
366
|
121 void ngx_ssl_remove_cached_session(SSL_CTX *ssl, ngx_ssl_session_t *sess);
|
126
|
122 ngx_int_t ngx_ssl_set_session(ngx_connection_t *c, ngx_ssl_session_t *session);
|
160
|
123 #define ngx_ssl_get_session(c) SSL_get1_session(c->ssl->connection)
|
|
124 #define ngx_ssl_free_session SSL_SESSION_free
|
272
|
125 #define ngx_ssl_get_connection(ssl_conn) \
|
|
126 SSL_get_ex_data(ssl_conn, ngx_ssl_connection_index)
|
|
127 #define ngx_ssl_get_server_conf(ssl_ctx) \
|
|
128 SSL_CTX_get_ex_data(ssl_ctx, ngx_ssl_server_conf_index)
|
160
|
129
|
690
|
130 #define ngx_ssl_verify_error_optional(n) \
|
|
131 (n == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT \
|
|
132 || n == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN \
|
|
133 || n == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY \
|
|
134 || n == X509_V_ERR_CERT_UNTRUSTED \
|
|
135 || n == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE)
|
|
136
|
160
|
137
|
220
|
138 ngx_int_t ngx_ssl_get_protocol(ngx_connection_t *c, ngx_pool_t *pool,
|
|
139 ngx_str_t *s);
|
|
140 ngx_int_t ngx_ssl_get_cipher_name(ngx_connection_t *c, ngx_pool_t *pool,
|
|
141 ngx_str_t *s);
|
530
|
142 ngx_int_t ngx_ssl_get_session_id(ngx_connection_t *c, ngx_pool_t *pool,
|
|
143 ngx_str_t *s);
|
390
|
144 ngx_int_t ngx_ssl_get_raw_certificate(ngx_connection_t *c, ngx_pool_t *pool,
|
|
145 ngx_str_t *s);
|
380
|
146 ngx_int_t ngx_ssl_get_certificate(ngx_connection_t *c, ngx_pool_t *pool,
|
|
147 ngx_str_t *s);
|
196
|
148 ngx_int_t ngx_ssl_get_subject_dn(ngx_connection_t *c, ngx_pool_t *pool,
|
|
149 ngx_str_t *s);
|
|
150 ngx_int_t ngx_ssl_get_issuer_dn(ngx_connection_t *c, ngx_pool_t *pool,
|
|
151 ngx_str_t *s);
|
220
|
152 ngx_int_t ngx_ssl_get_serial_number(ngx_connection_t *c, ngx_pool_t *pool,
|
|
153 ngx_str_t *s);
|
510
|
154 ngx_int_t ngx_ssl_get_client_verify(ngx_connection_t *c, ngx_pool_t *pool,
|
|
155 ngx_str_t *s);
|
220
|
156
|
196
|
157
|
96
|
158 ngx_int_t ngx_ssl_handshake(ngx_connection_t *c);
|
18
|
159 ssize_t ngx_ssl_recv(ngx_connection_t *c, u_char *buf, size_t size);
|
88
|
160 ssize_t ngx_ssl_write(ngx_connection_t *c, u_char *data, size_t size);
|
126
|
161 ssize_t ngx_ssl_recv_chain(ngx_connection_t *c, ngx_chain_t *cl);
|
0
|
162 ngx_chain_t *ngx_ssl_send_chain(ngx_connection_t *c, ngx_chain_t *in,
|
38
|
163 off_t limit);
|
358
|
164 void ngx_ssl_free_buffer(ngx_connection_t *c);
|
0
|
165 ngx_int_t ngx_ssl_shutdown(ngx_connection_t *c);
|
132
|
166 void ngx_cdecl ngx_ssl_error(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
|
38
|
167 char *fmt, ...);
|
58
|
168 void ngx_ssl_cleanup_ctx(void *data);
|
0
|
169
|
|
170
|
272
|
171 extern int ngx_ssl_connection_index;
|
|
172 extern int ngx_ssl_server_conf_index;
|
|
173 extern int ngx_ssl_session_cache_index;
|
688
|
174 extern int ngx_ssl_certificate_index;
|
|
175 extern int ngx_ssl_stapling_index;
|
220
|
176
|
|
177
|
0
|
178 #endif /* _NGX_EVENT_OPENSSL_H_INCLUDED_ */
|