diff options
| author | Ben Fuhrmannek | 2016-10-12 14:57:47 +0200 |
|---|---|---|
| committer | Ben Fuhrmannek | 2016-10-12 14:57:47 +0200 |
| commit | 1a3fd5eeb9a5859aefedb9302adb6ecd6a1873a7 (patch) | |
| tree | a8925768de344632ec89e051a3c71a3c7c61ffd3 /crypt.c | |
| parent | 2e4fbdbdd8ff3b1d1a0edb579392506ef3ed98e2 (diff) | |
comments and whitespace cleanup
Diffstat (limited to 'crypt.c')
| -rw-r--r-- | crypt.c | 50 |
1 files changed, 25 insertions, 25 deletions
| @@ -41,7 +41,7 @@ static void suhosin_get_ipv4(char *buf) | |||
| 41 | memset(buf, 0, 4); | 41 | memset(buf, 0, 4); |
| 42 | return; | 42 | return; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | for (i=0; i<4; i++) { | 45 | for (i=0; i<4; i++) { |
| 46 | if (raddr[0] == 0) { | 46 | if (raddr[0] == 0) { |
| 47 | buf[i] = 0; | 47 | buf[i] = 0; |
| @@ -59,11 +59,11 @@ zend_string *suhosin_encrypt_string(char *str, int len, char *var, int vlen, cha | |||
| 59 | int padded_len, i, slen; | 59 | int padded_len, i, slen; |
| 60 | unsigned char *crypted, *tmp; | 60 | unsigned char *crypted, *tmp; |
| 61 | unsigned int check = 0x13579BDF; | 61 | unsigned int check = 0x13579BDF; |
| 62 | 62 | ||
| 63 | if (str == NULL) { | 63 | if (str == NULL) { |
| 64 | return NULL; | 64 | return NULL; |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | if (len == 0) { | 67 | if (len == 0) { |
| 68 | return ZSTR_EMPTY_ALLOC(); | 68 | return ZSTR_EMPTY_ALLOC(); |
| 69 | } | 69 | } |
| @@ -86,10 +86,10 @@ zend_string *suhosin_encrypt_string(char *str, int len, char *var, int vlen, cha | |||
| 86 | check += check << 1; | 86 | check += check << 1; |
| 87 | check ^= (unsigned char)str[i]; | 87 | check ^= (unsigned char)str[i]; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | /* store ip value */ | 90 | /* store ip value */ |
| 91 | suhosin_get_ipv4((char *)crypted + 4); | 91 | suhosin_get_ipv4((char *)crypted + 4); |
| 92 | 92 | ||
| 93 | /* store check value */ | 93 | /* store check value */ |
| 94 | crypted[8] = check & 0xff; | 94 | crypted[8] = check & 0xff; |
| 95 | crypted[9] = (check >> 8) & 0xff; | 95 | crypted[9] = (check >> 8) & 0xff; |
| @@ -101,7 +101,7 @@ zend_string *suhosin_encrypt_string(char *str, int len, char *var, int vlen, cha | |||
| 101 | crypted[13] = (len >> 8) & 0xff; | 101 | crypted[13] = (len >> 8) & 0xff; |
| 102 | crypted[14] = (len >> 16) & 0xff; | 102 | crypted[14] = (len >> 16) & 0xff; |
| 103 | crypted[15] = (len >> 24) & 0xff; | 103 | crypted[15] = (len >> 24) & 0xff; |
| 104 | 104 | ||
| 105 | for (i = 0, tmp = crypted; i < padded_len + 16; i += 16, tmp += 16) { | 105 | for (i = 0, tmp = crypted; i < padded_len + 16; i += 16, tmp += 16) { |
| 106 | if (i > 0) { | 106 | if (i > 0) { |
| 107 | int j; | 107 | int j; |
| @@ -109,7 +109,7 @@ zend_string *suhosin_encrypt_string(char *str, int len, char *var, int vlen, cha | |||
| 109 | } | 109 | } |
| 110 | suhosin_aes_encrypt((char *)tmp); | 110 | suhosin_aes_encrypt((char *)tmp); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| 113 | zend_string *zs = php_base64_encode(crypted, padded_len+16); | 113 | zend_string *zs = php_base64_encode(crypted, padded_len+16); |
| 114 | efree(crypted); | 114 | efree(crypted); |
| 115 | // slen=strlen((char *)tmp); | 115 | // slen=strlen((char *)tmp); |
| @@ -129,11 +129,11 @@ zend_string *suhosin_decrypt_string(char *str, int padded_len, char *var, int vl | |||
| 129 | SDEBUG("decrypting string |%s|", str); | 129 | SDEBUG("decrypting string |%s|", str); |
| 130 | int i; | 130 | int i; |
| 131 | unsigned int check = 0x13579BDF; | 131 | unsigned int check = 0x13579BDF; |
| 132 | 132 | ||
| 133 | if (str == NULL) { | 133 | if (str == NULL) { |
| 134 | return NULL; | 134 | return NULL; |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | if (padded_len == 0) { | 137 | if (padded_len == 0) { |
| 138 | return ZSTR_EMPTY_ALLOC(); | 138 | return ZSTR_EMPTY_ALLOC(); |
| 139 | } | 139 | } |
| @@ -146,7 +146,7 @@ zend_string *suhosin_decrypt_string(char *str, int padded_len, char *var, int vl | |||
| 146 | case '_': str[i]='+'; break; | 146 | case '_': str[i]='+'; break; |
| 147 | } | 147 | } |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | zend_string *decrypted_zs = php_base64_decode((unsigned char *)str, padded_len); | 150 | zend_string *decrypted_zs = php_base64_decode((unsigned char *)str, padded_len); |
| 151 | if (decrypted_zs == NULL) { | 151 | if (decrypted_zs == NULL) { |
| 152 | return NULL; | 152 | return NULL; |
| @@ -158,7 +158,7 @@ zend_string *suhosin_decrypt_string(char *str, int padded_len, char *var, int vl | |||
| 158 | if (len < 2*16 || (len % 16) != 0) { | 158 | if (len < 2*16 || (len % 16) != 0) { |
| 159 | goto error_out; | 159 | goto error_out; |
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | unsigned char *tmp; | 162 | unsigned char *tmp; |
| 163 | for (i = len - 16, tmp = decrypted + i; i >= 0; i -= 16, tmp -= 16) { | 163 | for (i = len - 16, tmp = decrypted + i; i >= 0; i -= 16, tmp -= 16) { |
| 164 | suhosin_aes_decrypt((char *)tmp); | 164 | suhosin_aes_decrypt((char *)tmp); |
| @@ -176,7 +176,7 @@ zend_string *suhosin_decrypt_string(char *str, int padded_len, char *var, int vl | |||
| 176 | o_len |= decrypted[13]; | 176 | o_len |= decrypted[13]; |
| 177 | o_len <<= 8; | 177 | o_len <<= 8; |
| 178 | o_len |= decrypted[12]; | 178 | o_len |= decrypted[12]; |
| 179 | 179 | ||
| 180 | if (o_len < 0 || o_len > len-16) { | 180 | if (o_len < 0 || o_len > len-16) { |
| 181 | goto error_out; | 181 | goto error_out; |
| 182 | } | 182 | } |
| @@ -192,13 +192,13 @@ zend_string *suhosin_decrypt_string(char *str, int padded_len, char *var, int vl | |||
| 192 | check += check << 1; | 192 | check += check << 1; |
| 193 | check ^= decrypted[16+i]; | 193 | check ^= decrypted[16+i]; |
| 194 | } | 194 | } |
| 195 | 195 | ||
| 196 | /* check value */ | 196 | /* check value */ |
| 197 | int invalid = (decrypted[8] != (check & 0xff)) || | 197 | int invalid = (decrypted[8] != (check & 0xff)) || |
| 198 | (decrypted[9] != ((check >> 8) & 0xff)) || | 198 | (decrypted[9] != ((check >> 8) & 0xff)) || |
| 199 | (decrypted[10] != ((check >> 16) & 0xff)) || | 199 | (decrypted[10] != ((check >> 16) & 0xff)) || |
| 200 | (decrypted[11] != ((check >> 24) & 0xff)); | 200 | (decrypted[11] != ((check >> 24) & 0xff)); |
| 201 | 201 | ||
| 202 | /* check IP */ | 202 | /* check IP */ |
| 203 | if (check_ra) { | 203 | if (check_ra) { |
| 204 | if (check_ra > 4) { | 204 | if (check_ra > 4) { |
| @@ -210,16 +210,16 @@ zend_string *suhosin_decrypt_string(char *str, int padded_len, char *var, int vl | |||
| 210 | goto error_out; | 210 | goto error_out; |
| 211 | } | 211 | } |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | if (invalid) { | 214 | if (invalid) { |
| 215 | goto error_out; | 215 | goto error_out; |
| 216 | } | 216 | } |
| 217 | 217 | ||
| 218 | memmove(decrypted, decrypted+16, o_len); | 218 | memmove(decrypted, decrypted+16, o_len); |
| 219 | decrypted[o_len] = 0; | 219 | decrypted[o_len] = 0; |
| 220 | ZSTR_LEN(decrypted_zs) = o_len; | 220 | ZSTR_LEN(decrypted_zs) = o_len; |
| 221 | /* we do not realloc() here because 16 byte less | 221 | /* we do not realloc() here because 16 byte less |
| 222 | is simply not worth the overhead */ | 222 | is simply not worth the overhead */ |
| 223 | return decrypted_zs; | 223 | return decrypted_zs; |
| 224 | 224 | ||
| 225 | error_out: | 225 | error_out: |
| @@ -236,21 +236,21 @@ char *suhosin_generate_key(char *key, zend_bool ua, zend_bool dr, long raddr, ch | |||
| 236 | char *_dr = NULL; | 236 | char *_dr = NULL; |
| 237 | char *_ra = NULL; | 237 | char *_ra = NULL; |
| 238 | PHP_SHA256_CTX ctx; | 238 | PHP_SHA256_CTX ctx; |
| 239 | 239 | ||
| 240 | if (ua) { | 240 | if (ua) { |
| 241 | _ua = suhosin_getenv(ZEND_STRL("HTTP_USER_AGENT")); | 241 | _ua = suhosin_getenv(ZEND_STRL("HTTP_USER_AGENT")); |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | if (dr) { | 244 | if (dr) { |
| 245 | _dr = suhosin_getenv(ZEND_STRL("DOCUMENT_ROOT")); | 245 | _dr = suhosin_getenv(ZEND_STRL("DOCUMENT_ROOT")); |
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | if (raddr > 0) { | 248 | if (raddr > 0) { |
| 249 | _ra = suhosin_getenv(ZEND_STRL("REMOTE_ADDR")); | 249 | _ra = suhosin_getenv(ZEND_STRL("REMOTE_ADDR")); |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | SDEBUG("KEY: %s - UA: %s - DR: %s - RA: %s", key,_ua,_dr,_ra); | 252 | SDEBUG("KEY: %s - UA: %s - DR: %s - RA: %s", key,_ua,_dr,_ra); |
| 253 | 253 | ||
| 254 | PHP_SHA256Init(&ctx); | 254 | PHP_SHA256Init(&ctx); |
| 255 | if (key == NULL || *key == 0) { | 255 | if (key == NULL || *key == 0) { |
| 256 | PHP_SHA256Update(&ctx, (unsigned char*)ZEND_STRL("D3F4UL7")); | 256 | PHP_SHA256Update(&ctx, (unsigned char*)ZEND_STRL("D3F4UL7")); |
| @@ -269,7 +269,7 @@ char *suhosin_generate_key(char *key, zend_bool ua, zend_bool dr, long raddr, ch | |||
| 269 | } else { | 269 | } else { |
| 270 | long dots = 0; | 270 | long dots = 0; |
| 271 | char *tmp = _ra; | 271 | char *tmp = _ra; |
| 272 | 272 | ||
| 273 | while (*tmp) { | 273 | while (*tmp) { |
| 274 | if (*tmp == '.') { | 274 | if (*tmp == '.') { |
| 275 | dots++; | 275 | dots++; |
| @@ -284,6 +284,6 @@ char *suhosin_generate_key(char *key, zend_bool ua, zend_bool dr, long raddr, ch | |||
| 284 | } | 284 | } |
| 285 | PHP_SHA256Final((unsigned char *)cryptkey, &ctx); | 285 | PHP_SHA256Final((unsigned char *)cryptkey, &ctx); |
| 286 | cryptkey[32] = 0; /* uhmm... not really a string */ | 286 | cryptkey[32] = 0; /* uhmm... not really a string */ |
| 287 | 287 | ||
| 288 | return cryptkey; | 288 | return cryptkey; |
| 289 | } | 289 | } |
