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