186 #define STR(x) vstring_str(x)
187 #define LEN(x) VSTRING_LEN(x)
195 TLS_SCACHE_ENTRY *entry;
197 ssize_t binary_data_len;
205 binary_data_len = session_len + offsetof(TLS_SCACHE_ENTRY, session);
206 entry = (TLS_SCACHE_ENTRY *)
mymalloc(binary_data_len);
207 entry->timestamp = time((time_t *) 0);
208 memcpy(entry->session, session, session_len);
214 hex_encode(hex_data, (
char *) entry, binary_data_len);
220 msg_info(
"write %s TLS cache entry %s: time=%ld [data %ld bytes]",
221 cp->
cache_label, cache_id, (
long) entry->timestamp,
234 static int tls_scache_decode(
TLS_SCACHE *cp,
const char *cache_id,
235 const char *hex_data, ssize_t hex_data_len,
238 TLS_SCACHE_ENTRY *entry;
244 if (hex_data_len < 2 * (offsetof(TLS_SCACHE_ENTRY, session))) {
245 msg_warn(
"%s TLS cache: truncated entry for %s: %.100s",
255 #define FREE_AND_RETURN(ptr, x) { vstring_free(ptr); return (x); }
258 if (
hex_decode(bin_data, hex_data, hex_data_len) == 0) {
259 msg_warn(
"%s TLS cache: malformed entry for %s: %.100s",
261 FREE_AND_RETURN(bin_data, 0);
263 entry = (TLS_SCACHE_ENTRY *)
STR(bin_data);
269 msg_info(
"read %s TLS cache entry %s: time=%ld [data %ld bytes]",
270 cp->
cache_label, cache_id, (
long) entry->timestamp,
271 (
long) (
LEN(bin_data) - offsetof(TLS_SCACHE_ENTRY, session)));
276 if (entry->timestamp + cp->
timeout < time((time_t *) 0))
277 FREE_AND_RETURN(bin_data, 0);
282 if (out_session != 0)
284 LEN(bin_data) - offsetof(TLS_SCACHE_ENTRY, session));
289 FREE_AND_RETURN(bin_data, 1);
297 const char *hex_data;
314 if ((hex_data =
dict_get(cp->
db, cache_id)) == 0)
320 if (tls_scache_decode(cp, cache_id, hex_data, strlen(hex_data),
332 const char *buf, ssize_t len)
340 msg_info(
"put %s session id=%s [data %ld bytes]",
346 hex_data = tls_scache_encode(cp, cache_id, buf, len);
396 found_entry = (
dict_seq(cp->
db, first_next, &member, &value) == 0);
398 keep_entry = tls_scache_decode(cp, member, value, strlen(value),
400 if (keep_entry && out_cache_id)
442 return (found_entry);
468 int verbose,
int timeout)
477 msg_info(
"open %s TLS cache %s", cache_label, dbname);
483 #ifdef SINGLE_UPDATER
484 #define DICT_FLAGS (DICT_FLAG_DUP_REPLACE | DICT_FLAG_OPEN_LOCK \
485 | DICT_FLAG_UTF8_REQUEST)
488 (DICT_FLAG_DUP_REPLACE | DICT_FLAG_LOCK | DICT_FLAG_SYNC_UPDATE \
489 | DICT_FLAG_UTF8_REQUEST)
498 msg_fatal(
"dictionary %s does not support update operations", dbname);
500 msg_fatal(
"dictionary %s does not support delete operations", dbname);
502 msg_fatal(
"dictionary %s does not support sequence operations", dbname);
556 for (i = 0; i < 2 && keys[i]; ++i) {
558 if (
timecmp(keys[i]->tout + timeout, now) > 0)
563 }
else if (keys[0]) {
564 if (
timecmp(keys[0]->tout, now) > 0)
588 if (keys[0] == 0 || keys[0]->tout < keys[1]->tout) {
void tls_scache_close(TLS_SCACHE *)
char * mystrdup(const char *str)
#define dict_put(dp, key, val)
#define TLS_TICKET_NAMELEN
int(* delete)(struct DICT *, const char *)
TLS_TICKET_KEY * tls_scache_key_rotate(TLS_TICKET_KEY *)
int tls_scache_sequence(TLS_SCACHE *, int, char **, VSTRING *)
DICT * dict_open(const char *, int, int)
int timecmp(time_t t1, time_t t2)
TLS_SCACHE * tls_scache_open(const char *, const char *, int, int)
int tls_scache_lookup(TLS_SCACHE *, const char *, VSTRING *)
int(* update)(struct DICT *, const char *, const char *)
#define dict_get(dp, key)
VSTRING * hex_encode(VSTRING *result, const char *in, ssize_t len)
TLS_TICKET_KEY * tls_scache_key(unsigned char *, time_t, int)
int tls_scache_update(TLS_SCACHE *, const char *, const char *, ssize_t)
#define dict_seq(dp, f, key, val)
#define VSTRING_RESET(vp)
void msg_warn(const char *fmt,...)
VSTRING * vstring_alloc(ssize_t len)
NORETURN msg_fatal(const char *fmt,...)
VSTRING * vstring_free(VSTRING *vp)
int tls_scache_delete(TLS_SCACHE *, const char *)
VSTRING * vstring_memcpy(VSTRING *vp, const char *src, ssize_t len)
int(* sequence)(struct DICT *, int, const char **, const char **)
VSTRING * hex_decode(VSTRING *result, const char *in, ssize_t len)
#define dict_del(dp, key)
#define TLS_SCACHE_FLAG_DEL_SAVED_CURSOR
void * mymalloc(ssize_t len)
void msg_info(const char *fmt,...)