diff options
| author | jvoisin | 2017-10-01 20:54:03 +0200 |
|---|---|---|
| committer | jvoisin | 2017-10-02 15:20:53 +0200 |
| commit | 36c06637ad262f0e5fc0c8e70f4c1fc6a565f056 (patch) | |
| tree | ea55e322dd3e02ae7fdc2f35a815a9ba8330f301 /src/sp_cookie_encryption.c | |
| parent | 7418a0e1e9b02aef8535e33d30cfb8f082680f69 (diff) | |
First pass for #9
Diffstat (limited to 'src/sp_cookie_encryption.c')
| -rw-r--r-- | src/sp_cookie_encryption.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/sp_cookie_encryption.c b/src/sp_cookie_encryption.c index a47f6e1..69c438d 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,8 @@ 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 | PHP_SHA256Update(&ctx, (unsigned char*)out, sizeof(out)); | ||
| 29 | } | 28 | } |
| 30 | 29 | ||
| 31 | if (encryption_key) { | 30 | if (encryption_key) { |
| @@ -115,8 +114,11 @@ static zend_string *encrypt_data(char *data, unsigned long long data_len) { | |||
| 115 | 114 | ||
| 116 | assert(sizeof(size_t) <= crypto_secretbox_NONCEBYTES); | 115 | assert(sizeof(size_t) <= crypto_secretbox_NONCEBYTES); |
| 117 | 116 | ||
| 117 | if (0 == nonce_d) { | ||
| 118 | nonce_d = getpid(); | ||
| 119 | } | ||
| 118 | nonce_d++; | 120 | nonce_d++; |
| 119 | sscanf((char*)nonce, "%ud", &nonce_d); | 121 | sscanf((char*)nonce, "%ud", &nonce_d); |
| 120 | 122 | ||
| 121 | memcpy(encrypted_data, nonce, crypto_secretbox_NONCEBYTES); | 123 | memcpy(encrypted_data, nonce, crypto_secretbox_NONCEBYTES); |
| 122 | crypto_secretbox(encrypted_data + crypto_secretbox_NONCEBYTES, | 124 | crypto_secretbox(encrypted_data + crypto_secretbox_NONCEBYTES, |
