1 /*-
2  * SSLsplit - transparent SSL/TLS interception
3  * https://www.roe.ch/SSLsplit
4  *
5  * Copyright (c) 2009-2019, Daniel Roethlisberger <daniel@roe.ch>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  * 1. Redistributions of source code must retain the above copyright notice,
11  *    this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  *    this list of conditions and the following disclaimer in the documentation
14  *    and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef CACHEMGR_H
30 #define CACHEMGR_H
31 
32 #include "cache.h"
33 #include "cachefkcrt.h"
34 #include "cachetgcrt.h"
35 #include "cachessess.h"
36 #include "cachedsess.h"
37 
38 extern cache_t *cachemgr_fkcrt;
39 extern cache_t *cachemgr_tgcrt;
40 extern cache_t *cachemgr_ssess;
41 extern cache_t *cachemgr_dsess;
42 
43 int cachemgr_preinit(void) WUNRES;
44 int cachemgr_init(void) WUNRES;
45 void cachemgr_fini(void);
46 void cachemgr_gc(void);
47 
48 #define cachemgr_fkcrt_get(key) \
49         cache_get(cachemgr_fkcrt, cachefkcrt_mkkey(key))
50 #define cachemgr_fkcrt_set(key, val) \
51         cache_set(cachemgr_fkcrt, cachefkcrt_mkkey(key), cachefkcrt_mkval(val))
52 #define cachemgr_fkcrt_del(key) \
53         cache_del(cachemgr_fkcrt, cachefkcrt_mkkey(key))
54 
55 #define cachemgr_tgcrt_get(key) \
56         cache_get(cachemgr_tgcrt, cachetgcrt_mkkey(key))
57 #define cachemgr_tgcrt_set(key, val) \
58         cache_set(cachemgr_tgcrt, cachetgcrt_mkkey(key), cachetgcrt_mkval(val))
59 #define cachemgr_tgcrt_del(key) \
60         cache_del(cachemgr_tgcrt, cachetgcrt_mkkey(key))
61 
62 #define cachemgr_ssess_get(key, keysz) \
63         cache_get(cachemgr_ssess, cachessess_mkkey((key), (keysz)))
64 #define cachemgr_ssess_set(val) \
65         { \
66                 unsigned int len; \
67                 const unsigned char* id = SSL_SESSION_get_id(val, &len); \
68                 cache_set(cachemgr_ssess, \
69                           cachessess_mkkey(id, len), \
70                           cachessess_mkval(val));    \
71         }
72 #define cachemgr_ssess_del(val) \
73         { \
74                 unsigned int len; \
75                 const unsigned char* id = SSL_SESSION_get_id(val, &len); \
76                 cache_del(cachemgr_ssess, \
77                           cachessess_mkkey(id, len)); \
78         }
79 #define cachemgr_dsess_get(addr, addrlen, sni) \
80         cache_get(cachemgr_dsess, cachedsess_mkkey((addr), (addrlen), (sni)))
81 #define cachemgr_dsess_set(addr, addrlen, sni, val) \
82         cache_set(cachemgr_dsess, cachedsess_mkkey((addr), (addrlen), (sni)), \
83                                   cachedsess_mkval(val))
84 #define cachemgr_dsess_del(addr, addrlen, sni) \
85         cache_del(cachemgr_dsess, cachedsess_mkkey((addr), (addrlen), (sni)))
86 
87 #endif /* !CACHEMGR_H */
88 
89 /* vim: set noet ft=c: */
90