Debian Codegraph @

contrib/mod_tls.h

raw symbols SCIP
1 /*
2 * ProFTPD - mod_tls API
3 * Copyright (c) 2002-2016 TJ Saunders
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18 *
19 * As a special exemption, TJ Saunders and other respective copyright holders
20 * give permission to link this program with OpenSSL, and distribute the
21 * resulting executable, without including the source code for OpenSSL in the
22 * source distribution.
23 */
24
25 #ifndef MOD_TLS_H
26 #define MOD_TLS_H
27
28 #include "conf.h"
29
30 #include <openssl/err.h>
31 #include <openssl/bio.h>
32 #include <openssl/ssl.h>
33 #if defined(PR_USE_OPENSSL_OCSP)
34 # include <openssl/ocsp.h>
35 #endif /* PR_USE_OPENSSL_OCSP */
36
37 /* For mod_tls-related modules wishing to log info to the TLSLog file. */
38 int tls_log(const char *, ...)
39 #ifdef __GNUC__
40 __attribute__ ((format (printf, 1, 2)));
41 #else
42 ;
43 #endif
44
45 /* API for modules that which to register SSL session cache handlers. */
46
47 #if OPENSSL_VERSION_NUMBER >= 0x0090707f
48 # define TLS_D2I_SSL_SESSION_CONST const
49 #else
50 # define TLS_D2I_SSL_SESSION_CONST
51 #endif
52
53 typedef struct sess_cache_st {
54 const char *cache_name;
55
56 /* Memory pool for this cache. */
57 pool *cache_pool;
58
59 /* Arbitrary cache-specific data */
60 void *cache_data;
61
62 /* Timeout (in secs) of entries in this cache. */
63 long cache_timeout;
64
65 /* Additional OpenSSL session caching flags desired by the session cache
66 * handler. These will be OR'd with SSL_SESS_CACHE_SERVER. See
67 * SSL_CTX_set_session_cache_mode(3) for details.
68 */
69 long cache_mode;
70
71 /* Initialize the cache handler. Returns zero on success, -1 otherwise (with
72 * errno set appropriately).
73 */
74 int (*open)(struct sess_cache_st *cache, char *info, long timeout);
75
76 /* Destroy the cache handler, cleaning up any associated resources. Returns
77 * zero on success, -1 otherwise (with errno set appropriately).
78 */
79 int (*close)(struct sess_cache_st *cache);
80
81 /* Add a new session entry to the cache. The provided sess_id is effectively
82 * the cache lookup key.
83 */
84 int (*add)(struct sess_cache_st *cache, const unsigned char *sess_id,
85 unsigned int sess_id_len, time_t expires, SSL_SESSION *sess);
86
87 /* Retrieve a session from the cache, using the provided sess_id key. */
88 SSL_SESSION *(*get)(struct sess_cache_st *cache, const unsigned char *sess_id,
89 unsigned int sess_id_len);
90
91 /* Remove the specified session from the cache. */
92 int (*delete)(struct sess_cache_st *cache, const unsigned char *sess_id,
93 unsigned int sess_id_len);
94
95 /* Clear the cache of all sessions, regardless of their normal expiration
96 * time. Returns the number of cleared sessions on success, -1 otherwise
97 * (with errno set appropriately).
98 */
99 int (*clear)(struct sess_cache_st *cache);
100
101 /* Remove the entire cache. Returns zero on success, -1 otherwise (with
102 * errno set appropriately).
103 */
104 int (*remove)(struct sess_cache_st *cache);
105
106 /* Query the cache for information: count of sessions currently cached,
107 * hits/misses/expirations, etc. Returns zero on success, -1 otherwise
108 * (with errno set appropriately).
109 */
110 int (*status)(struct sess_cache_st *cache, void (*writef)(void *, const char *, ...), void *arg, int flags);
111
112 } tls_sess_cache_t;
113
114 /* Use this flag to indicate to the status callback that details on all
115 * sessions in the cache are to be shown. These details include the
116 * session ID, session ID context, session creation time, session expiration
117 * time, session protocol (SSLv3, TLSv1, etc), and ciphersuite.
118 */
119 #define TLS_SESS_CACHE_STATUS_FL_SHOW_SESSIONS 0x001
120
121 int tls_sess_cache_register(const char *name, tls_sess_cache_t *handler);
122 int tls_sess_cache_unregister(const char *name);
123
124 /* API for modules that which to register OCSP response cache handlers. */
125
126 typedef struct ocsp_cache_st {
127 const char *cache_name;
128
129 /* Memory pool for this cache. */
130 pool *cache_pool;
131
132 /* Arbitrary cache-specific data */
133 void *cache_data;
134
135 /* Initialize the cache handler. Returns zero on success, -1 otherwise (with
136 * errno set appropriately).
137 */
138 int (*open)(struct ocsp_cache_st *cache, char *info);
139
140 /* Destroy the cache handler, cleaning up any associated resources. Returns
141 * zero on success, -1 otherwise (with errno set appropriately).
142 */
143 int (*close)(struct ocsp_cache_st *cache);
144
145 #if defined(PR_USE_OPENSSL_OCSP)
146 /* Add a new OCSP response to the cache. The provided cert_fingerprint
147 * (a hex-encoded, NUL-terminated string) is effectively the cache lookup key.
148 */
149 int (*add)(struct ocsp_cache_st *cache, const char *cert_fingerprint,
150 OCSP_RESPONSE *resp, time_t age);
151
152 /* Retrieve an OCSP response from the cache, using the provided lookup key. */
153 OCSP_RESPONSE *(*get)(struct ocsp_cache_st *cache,
154 const char *cert_fingerprint, time_t *age);
155 #endif /* PR_USE_OPENSSL_OCSP */
156
157 /* Remove the specified certificate's response from the cache. */
158 int (*delete)(struct ocsp_cache_st *cache, const char *cert_fingerprint);
159
160 /* Clear the cache of all OCSP responses, regardless of their normal
161 * expiration time. Returns the number of cleared responses on success,
162 * -1 otherwise (with errno set appropriately).
163 */
164 int (*clear)(struct ocsp_cache_st *cache);
165
166 /* Remove the entire cache. Returns zero on success, -1 otherwise (with
167 * errno set appropriately).
168 */
169 int (*remove)(struct ocsp_cache_st *cache);
170
171 /* Query the cache for information: count of responses currently cached,
172 * hits/misses/expirations, etc. Returns zero on success, -1 otherwise
173 * (with errno set appropriately).
174 */
175 int (*status)(struct ocsp_cache_st *cache, void (*writef)(void *, const char *, ...), void *arg, int flags);
176
177 } tls_ocsp_cache_t;
178
179 int tls_ocsp_cache_register(const char *name, tls_ocsp_cache_t *handler);
180 int tls_ocsp_cache_unregister(const char *name);
181
182 #endif /* MOD_TLS_H */