diff options
Diffstat (limited to '')
| -rw-r--r-- | src/sp_crypt.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/sp_crypt.c b/src/sp_crypt.c index 6d48554..3b65616 100644 --- a/src/sp_crypt.c +++ b/src/sp_crypt.c | |||
| @@ -32,6 +32,7 @@ void generate_key(unsigned char *key) { | |||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | PHP_SHA256Final((unsigned char *)key, &ctx); | 34 | PHP_SHA256Final((unsigned char *)key, &ctx); |
| 35 | ZEND_SECURE_ZERO(&ctx, sizeof(ctx)); | ||
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | // This function return 0 upon success , non-zero otherwise | 38 | // This function return 0 upon success , non-zero otherwise |
| @@ -42,6 +43,11 @@ int decrypt_zval(zval *pDest, bool simulation, zend_hash_key *hash_key) { | |||
| 42 | 43 | ||
| 43 | zend_string *debase64 = php_base64_decode((unsigned char *)(Z_STRVAL_P(pDest)), Z_STRLEN_P(pDest)); | 44 | zend_string *debase64 = php_base64_decode((unsigned char *)(Z_STRVAL_P(pDest)), Z_STRLEN_P(pDest)); |
| 44 | 45 | ||
| 46 | if (!debase64) { | ||
| 47 | sp_log_drop( "cookie_encryption", "Unable to base64-decode the cookie"); | ||
| 48 | return ZEND_HASH_APPLY_REMOVE; | ||
| 49 | } | ||
| 50 | |||
| 45 | if (ZSTR_LEN(debase64) < crypto_secretbox_NONCEBYTES) { | 51 | if (ZSTR_LEN(debase64) < crypto_secretbox_NONCEBYTES) { |
| 46 | if (true == simulation) { | 52 | if (true == simulation) { |
| 47 | sp_log_simulation( | 53 | sp_log_simulation( |
| @@ -115,6 +121,7 @@ int decrypt_zval(zval *pDest, bool simulation, zend_hash_key *hash_key) { | |||
| 115 | ret = ZEND_HASH_APPLY_KEEP; | 121 | ret = ZEND_HASH_APPLY_KEEP; |
| 116 | 122 | ||
| 117 | out: | 123 | out: |
| 124 | ZEND_SECURE_ZERO(key, sizeof(key)); | ||
| 118 | zend_string_efree(debase64); | 125 | zend_string_efree(debase64); |
| 119 | efree(decrypted); | 126 | efree(decrypted); |
| 120 | efree(backup); | 127 | efree(backup); |
| @@ -164,6 +171,8 @@ zend_string *encrypt_zval(zend_string *data) { | |||
| 164 | z = php_base64_encode(encrypted_data, emsg_and_nonce_len); | 171 | z = php_base64_encode(encrypted_data, emsg_and_nonce_len); |
| 165 | } | 172 | } |
| 166 | 173 | ||
| 174 | ZEND_SECURE_ZERO(key, sizeof(key)); | ||
| 175 | ZEND_SECURE_ZERO(nonce, sizeof(nonce)); | ||
| 167 | efree(data_to_encrypt); | 176 | efree(data_to_encrypt); |
| 168 | efree(encrypted_data); | 177 | efree(encrypted_data); |
| 169 | 178 | ||
