From 7832438b7abedf567ce6376f99949f419abcdff1 Mon Sep 17 00:00:00 2001 From: kkadosh Date: Tue, 29 May 2018 19:34:16 +0000 Subject: Support session encryption Implement session encryption.--- src/sp_config_keywords.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'src/sp_config_keywords.c') diff --git a/src/sp_config_keywords.c b/src/sp_config_keywords.c index 9faaafb..f702f4d 100644 --- a/src/sp_config_keywords.c +++ b/src/sp_config_keywords.c @@ -60,6 +60,49 @@ static int parse_enable(char *line, bool *restrict retval, return ret; } +int parse_session(char *line) { + sp_config_session *session = + pecalloc(sizeof(sp_config_session), 1, 0); + + sp_config_functions sp_config_funcs_session_encryption[] = { + {parse_empty, SP_TOKEN_ENCRYPT, &(session->encrypt)}, + {parse_empty, SP_TOKEN_SIMULATION, &(session->simulation)}, + {0}}; + int ret = parse_keywords(sp_config_funcs_session_encryption, line); + if (0 != ret) { + return ret; + } + if (session->encrypt) { + if (0 == (SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var)) { + sp_log_err( + "config", + "You're trying to use the session cookie encryption feature" + "on line %zu without having set the `.cookie_env_var` option in" + "`sp.global`: please set it first.", + sp_line_no); + pefree(session, 0); + return -1; + } else if (0 == + (SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key)) { + sp_log_err( + "config", + "You're trying to use the session cookie encryption feature" + "on line %zu without having set the `.encryption_key` option in" + "`sp.global`: please set it first.", + sp_line_no); + pefree(session, 0); + return -1; + } + } + + SNUFFLEUPAGUS_G(config).config_session->encrypt = + session->encrypt; + SNUFFLEUPAGUS_G(config).config_session->simulation = + session->simulation; + pefree(session, 0); + return ret; +} + int parse_random(char *line) { return parse_enable(line, &(SNUFFLEUPAGUS_G(config).config_random->enable), NULL); -- cgit v1.3