xref: /unit/src/nxt_tls.h (revision 1920:7c19530e2502)
1 
2 /*
3  * Copyright (C) Igor Sysoev
4  * Copyright (C) NGINX, Inc.
5  */
6 
7 #ifndef _NXT_TLS_H_INCLUDED_
8 #define _NXT_TLS_H_INCLUDED_
9 
10 
11 #include <nxt_conf.h>
12 
13 
14 /*
15  * The SSL/TLS libraries lack vector I/O interface yet add noticeable
16  * overhead to each SSL/TLS record so buffering allows to decrease the
17  * overhead.  The typical overhead size is about 30 bytes, however, TLS
18  * supports also random padding up to 255 bytes.  The maximum SSLv3/TLS
19  * record size is 16K.  However, large records increase decryption latency.
20  * 4K is good compromise between 1-6% of SSL/TLS overhead and the latency.
21  * 4K buffer allows to send one SSL/TLS record (4096-bytes data and up to
22  * 224-bytes overhead) in three 1440-bytes TCP/IPv4 packets with timestamps
23  * and compatible with tunnels.
24  */
25 
26 #define NXT_TLS_BUFFER_SIZE       4096
27 
28 
29 typedef struct nxt_tls_conf_s         nxt_tls_conf_t;
30 typedef struct nxt_tls_bundle_conf_s  nxt_tls_bundle_conf_t;
31 typedef struct nxt_tls_init_s         nxt_tls_init_t;
32 
33 typedef struct {
34     nxt_int_t                     (*library_init)(nxt_task_t *task);
35     void                          (*library_free)(nxt_task_t *task);
36 
37     nxt_int_t                     (*server_init)(nxt_task_t *task, nxt_mp_t *mp,
38                                       nxt_tls_init_t *tls_init,
39                                       nxt_bool_t last);
40     void                          (*server_free)(nxt_task_t *task,
41                                       nxt_tls_conf_t *conf);
42 } nxt_tls_lib_t;
43 
44 
45 typedef struct {
46     nxt_tls_bundle_conf_t         *bundle;
47 
48     nxt_str_t                     name;
49 } nxt_tls_bundle_hash_item_t;
50 
51 
52 struct nxt_tls_bundle_conf_s {
53     void                          *ctx;
54 
55     nxt_fd_t                      chain_file;
56     nxt_str_t                     name;
57 
58     nxt_tls_bundle_conf_t         *next;
59 };
60 
61 
62 struct nxt_tls_conf_s {
63     nxt_tls_bundle_conf_t         *bundle;
64     nxt_lvlhsh_t                  bundle_hash;
65 
66     void                          (*conn_init)(nxt_task_t *task,
67                                       nxt_tls_conf_t *conf, nxt_conn_t *c);
68 
69     const nxt_tls_lib_t           *lib;
70 
71     char                          *ciphers;
72 
73     char                          *ca_certificate;
74 
75     size_t                        buffer_size;
76 
77     uint8_t                       no_wait_shutdown;  /* 1 bit */
78 };
79 
80 
81 struct nxt_tls_init_s {
82     size_t                        cache_size;
83     nxt_time_t                    timeout;
84     nxt_conf_value_t              *conf_cmds;
85 
86     nxt_tls_conf_t                *conf;
87 };
88 
89 
90 #if (NXT_HAVE_OPENSSL)
91 extern const nxt_tls_lib_t        nxt_openssl_lib;
92 
93 void nxt_cdecl nxt_openssl_log_error(nxt_task_t *task, nxt_uint_t level,
94     const char *fmt, ...);
95 u_char *nxt_openssl_copy_error(u_char *p, u_char *end);
96 #endif
97 
98 #if (NXT_HAVE_GNUTLS)
99 extern const nxt_tls_lib_t        nxt_gnutls_lib;
100 #endif
101 
102 #if (NXT_HAVE_CYASSL)
103 extern const nxt_tls_lib_t        nxt_cyassl_lib;
104 #endif
105 
106 #if (NXT_HAVE_POLARSSL)
107 extern const nxt_tls_lib_t        nxt_polar_lib;
108 #endif
109 
110 
111 #endif /* _NXT_TLS_H_INCLUDED_ */
112