mirror of
https://gitlab.com/openconnect/ocserv.git
synced 2026-02-10 16:57:00 +08:00
Simplified the TLS hash table initialization.
This commit is contained in:
@@ -47,7 +47,7 @@ int handle_resume_delete_req(main_server_st * s, struct proc_st *proc,
|
||||
|
||||
key = hash_any(req->session_id.data, req->session_id.len, 0);
|
||||
|
||||
cache = htable_firstval(&s->tls_db->ht, &iter, key);
|
||||
cache = htable_firstval(s->tls_db.ht, &iter, key);
|
||||
while (cache != NULL) {
|
||||
if (req->session_id.len == cache->session_id_size &&
|
||||
memcmp(req->session_id.data, cache->session_id,
|
||||
@@ -56,13 +56,13 @@ int handle_resume_delete_req(main_server_st * s, struct proc_st *proc,
|
||||
cache->session_data_size = 0;
|
||||
cache->session_id_size = 0;
|
||||
|
||||
htable_delval(&s->tls_db->ht, &iter);
|
||||
htable_delval(s->tls_db.ht, &iter);
|
||||
talloc_free(cache);
|
||||
s->tls_db->entries--;
|
||||
s->tls_db.entries--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
cache = htable_nextval(&s->tls_db->ht, &iter, key);
|
||||
cache = htable_nextval(s->tls_db.ht, &iter, key);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -80,7 +80,7 @@ int handle_resume_fetch_req(main_server_st * s, struct proc_st *proc,
|
||||
|
||||
key = hash_any(req->session_id.data, req->session_id.len, 0);
|
||||
|
||||
cache = htable_firstval(&s->tls_db->ht, &iter, key);
|
||||
cache = htable_firstval(s->tls_db.ht, &iter, key);
|
||||
while (cache != NULL) {
|
||||
if (req->session_id.len == cache->session_id_size &&
|
||||
memcmp(req->session_id.data, cache->session_id,
|
||||
@@ -108,7 +108,7 @@ int handle_resume_fetch_req(main_server_st * s, struct proc_st *proc,
|
||||
}
|
||||
}
|
||||
|
||||
cache = htable_nextval(&s->tls_db->ht, &iter, key);
|
||||
cache = htable_nextval(s->tls_db.ht, &iter, key);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -128,7 +128,7 @@ int handle_resume_store_req(main_server_st * s, struct proc_st *proc,
|
||||
return -1;
|
||||
|
||||
max = MAX(2 * s->config->max_clients, DEFAULT_MAX_CACHED_TLS_SESSIONS);
|
||||
if (s->tls_db->entries >= max) {
|
||||
if (s->tls_db.entries >= max) {
|
||||
mslog(s, NULL, LOG_INFO,
|
||||
"maximum number of stored TLS sessions reached (%u)",
|
||||
max);
|
||||
@@ -138,7 +138,7 @@ int handle_resume_store_req(main_server_st * s, struct proc_st *proc,
|
||||
|
||||
key = hash_any(req->session_id.data, req->session_id.len, 0);
|
||||
|
||||
cache = talloc(s, tls_cache_st);
|
||||
cache = talloc(s->tls_db.ht, tls_cache_st);
|
||||
if (cache == NULL)
|
||||
return -1;
|
||||
|
||||
@@ -151,8 +151,8 @@ int handle_resume_store_req(main_server_st * s, struct proc_st *proc,
|
||||
req->session_data.len);
|
||||
memcpy(&cache->remote_addr, &proc->remote_addr, proc->remote_addr_len);
|
||||
|
||||
htable_add(&s->tls_db->ht, key, cache);
|
||||
s->tls_db->entries++;
|
||||
htable_add(s->tls_db.ht, key, cache);
|
||||
s->tls_db.entries++;
|
||||
|
||||
mslog_hex(s, proc, LOG_DEBUG, "TLS session DB storing",
|
||||
req->session_id.data,
|
||||
@@ -169,7 +169,7 @@ void expire_tls_sessions(main_server_st * s)
|
||||
|
||||
now = time(0);
|
||||
|
||||
cache = htable_first(&s->tls_db->ht, &iter);
|
||||
cache = htable_first(s->tls_db.ht, &iter);
|
||||
while (cache != NULL) {
|
||||
gnutls_datum_t d;
|
||||
|
||||
@@ -182,12 +182,12 @@ void expire_tls_sessions(main_server_st * s)
|
||||
cache->session_data_size = 0;
|
||||
cache->session_id_size = 0;
|
||||
|
||||
htable_delval(&s->tls_db->ht, &iter);
|
||||
htable_delval(s->tls_db.ht, &iter);
|
||||
safe_memset(cache->session_data, 0, cache->session_data_size);
|
||||
talloc_free(cache);
|
||||
s->tls_db->entries--;
|
||||
s->tls_db.entries--;
|
||||
}
|
||||
cache = htable_next(&s->tls_db->ht, &iter);
|
||||
cache = htable_next(s->tls_db.ht, &iter);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
@@ -585,7 +585,7 @@ void clear_lists(main_server_st *s)
|
||||
talloc_free(script_tmp);
|
||||
}
|
||||
|
||||
tls_cache_deinit(s->tls_db);
|
||||
tls_cache_deinit(&s->tls_db);
|
||||
ip_lease_deinit(&s->ip_leases);
|
||||
ctl_handler_deinit(s);
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ typedef struct main_server_st {
|
||||
|
||||
struct ip_lease_db_st ip_leases;
|
||||
|
||||
hash_db_st *tls_db;
|
||||
tls_sess_db_st tls_db;
|
||||
tls_st *creds;
|
||||
|
||||
uint8_t cookie_key[COOKIE_KEY_SIZE];
|
||||
|
||||
22
src/tlslib.c
22
src/tlslib.c
@@ -182,26 +182,22 @@ const tls_cache_st *e = _e;
|
||||
return hash_any(e->session_id, e->session_id_size, 0);
|
||||
}
|
||||
|
||||
void tls_cache_init(void *pool, hash_db_st** _db)
|
||||
void tls_cache_init(void *pool, tls_sess_db_st* db)
|
||||
{
|
||||
hash_db_st * db;
|
||||
|
||||
db = talloc(pool, hash_db_st);
|
||||
if (db == NULL)
|
||||
db->ht = talloc(pool, struct htable);
|
||||
if (db->ht == NULL)
|
||||
exit(1);
|
||||
|
||||
htable_init(&db->ht, rehash, NULL);
|
||||
htable_init(db->ht, rehash, NULL);
|
||||
db->entries = 0;
|
||||
|
||||
*_db = db;
|
||||
}
|
||||
|
||||
void tls_cache_deinit(hash_db_st* db)
|
||||
void tls_cache_deinit(tls_sess_db_st* db)
|
||||
{
|
||||
tls_cache_st* cache;
|
||||
struct htable_iter iter;
|
||||
|
||||
cache = htable_first(&db->ht, &iter);
|
||||
cache = htable_first(db->ht, &iter);
|
||||
while(cache != NULL) {
|
||||
if (cache->session_data_size > 0) {
|
||||
safe_memset(cache->session_data, 0, cache->session_data_size);
|
||||
@@ -210,11 +206,11 @@ struct htable_iter iter;
|
||||
}
|
||||
talloc_free(cache);
|
||||
|
||||
cache = htable_next(&db->ht, &iter);
|
||||
cache = htable_next(db->ht, &iter);
|
||||
}
|
||||
htable_clear(&db->ht);
|
||||
htable_clear(db->ht);
|
||||
db->entries = 0;
|
||||
talloc_free(db);
|
||||
talloc_free(db->ht);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
10
src/tlslib.h
10
src/tlslib.h
@@ -26,6 +26,12 @@
|
||||
#include <vpn.h>
|
||||
#include <ccan/htable/htable.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct htable *ht;
|
||||
unsigned int entries;
|
||||
} tls_sess_db_st;
|
||||
|
||||
#define tls_puts(s, str) tls_send(s, str, sizeof(str)-1)
|
||||
|
||||
int __attribute__ ((format(printf, 2, 3)))
|
||||
@@ -110,8 +116,8 @@ typedef struct
|
||||
#define TLS_SESSION_EXPIRATION_TIME 600
|
||||
#define DEFAULT_MAX_CACHED_TLS_SESSIONS 64
|
||||
|
||||
void tls_cache_init(void *pool, hash_db_st** db);
|
||||
void tls_cache_deinit(hash_db_st* db);
|
||||
void tls_cache_init(void *pool, tls_sess_db_st* db);
|
||||
void tls_cache_deinit(tls_sess_db_st* db);
|
||||
void *calc_sha1_hash(void *pool, char* file, unsigned cert);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user