diff options
Diffstat (limited to 'src/sp_cookie_encryption.c')
| -rw-r--r-- | src/sp_cookie_encryption.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index a47f6e1..a65a748 100644 --- a/src/sp_cookie_encryption.c +++ b/src/sp_cookie_encryption.c | |||
| @@ -9,7 +9,8 @@ static unsigned int nonce_d = 0; | |||
| 9 | static inline void generate_key(unsigned char *key) { | 9 | static inline void generate_key(unsigned char *key) { |
| 10 | PHP_SHA256_CTX ctx; | 10 | PHP_SHA256_CTX ctx; |
| 11 | const char *user_agent = sp_getenv("HTTP_USER_AGENT"); | 11 | const char *user_agent = sp_getenv("HTTP_USER_AGENT"); |
| 12 | const char *remote_addr = sp_getenv("REMOTE_ADDR"); | 12 | const char *env_var = |
| 13 | sp_getenv(SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var); | ||
| 13 | const char *encryption_key = | 14 | const char *encryption_key = |
| 14 | SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key; | 15 | SNUFFLEUPAGUS_G(config).config_snuffleupagus->encryption_key; |
| 15 | 16 | ||
| @@ -22,10 +23,12 @@ static inline void generate_key(unsigned char *key) { | |||
| 22 | PHP_SHA256Update(&ctx, (unsigned char *)user_agent, strlen(user_agent)); | 23 | PHP_SHA256Update(&ctx, (unsigned char *)user_agent, strlen(user_agent)); |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | if (remote_addr) { | 26 | if (env_var) { |
| 26 | char out[128]; | 27 | PHP_SHA256Update(&ctx, (unsigned char*)env_var, strlen(env_var)); |
| 27 | apply_mask_on_ip(out, remote_addr); | 28 | } else { |
| 28 | PHP_SHA256Update(&ctx, (unsigned char*)out, sizeof(out)); | 29 | sp_log_err("cookie_encryption", "The environment variable '%s'" |
| 30 | "is empty, cookies are weakly encrypted.", | ||
| 31 | SNUFFLEUPAGUS_G(config).config_snuffleupagus->cookies_env_var); | ||
| 29 | } | 32 | } |
| 30 | 33 | ||
| 31 | if (encryption_key) { | 34 | if (encryption_key) { |
| @@ -115,8 +118,11 @@ static zend_string *encrypt_data(char *data, unsigned long long data_len) { | |||
| 115 | 118 | ||
| 116 | assert(sizeof(size_t) <= crypto_secretbox_NONCEBYTES); | 119 | assert(sizeof(size_t) <= crypto_secretbox_NONCEBYTES); |
| 117 | 120 | ||
| 121 | if (0 == nonce_d) { | ||
| 122 | nonce_d = getpid(); | ||
| 123 | } | ||
| 118 | nonce_d++; | 124 | nonce_d++; |
| 119 | sscanf((char*)nonce, "%ud", &nonce_d); | 125 | sscanf((char*)nonce, "%ud", &nonce_d); |
| 120 | 126 | ||
| 121 | memcpy(encrypted_data, nonce, crypto_secretbox_NONCEBYTES); | 127 | memcpy(encrypted_data, nonce, crypto_secretbox_NONCEBYTES); |
| 122 | crypto_secretbox(encrypted_data + crypto_secretbox_NONCEBYTES, | 128 | crypto_secretbox(encrypted_data + crypto_secretbox_NONCEBYTES, |
