Browse Source

fixed trailing whitespace and indentation for all socks proxy code

cecylia 4 years ago
parent
commit
1ba11d2588
6 changed files with 291 additions and 293 deletions
  1. 227 227
      client/crypto.c
  2. 12 12
      client/crypto.h
  3. 3 5
      client/socks5proxy.c
  4. 23 23
      client/socks5proxy.h
  5. 25 25
      client/tagging.c
  6. 1 1
      client/util.c

+ 227 - 227
client/crypto.c

@@ -10,14 +10,14 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Additional permission under GNU GPL version 3 section 7
- * 
+ *
  * If you modify this Program, or any covered work, by linking or combining
- * it with the OpenSSL library (or a modified version of that library), 
+ * it with the OpenSSL library (or a modified version of that library),
  * containing parts covered by the terms of the OpenSSL Licence and the
  * SSLeay license, the licensors of this Program grant you additional
  * permission to convey the resulting work. Corresponding Source for a
@@ -47,106 +47,106 @@ static super_data *super;
 
 /* PRF using sha384, as defined in RFC 5246 */
 int PRF(uint8_t *secret, int32_t secret_len,
-		uint8_t *seed1, int32_t seed1_len,
-		uint8_t *seed2, int32_t seed2_len,
-		uint8_t *seed3, int32_t seed3_len,
-		uint8_t *seed4, int32_t seed4_len,
-		uint8_t *output, int32_t output_len){
+        uint8_t *seed1, int32_t seed1_len,
+        uint8_t *seed2, int32_t seed2_len,
+        uint8_t *seed3, int32_t seed3_len,
+        uint8_t *seed4, int32_t seed4_len,
+        uint8_t *output, int32_t output_len){
 
-	EVP_MD_CTX *ctx, *ctx_tmp, *ctx_init;
-	EVP_PKEY *mac_key;
-	const EVP_MD *md = EVP_sha256();
+    EVP_MD_CTX *ctx, *ctx_tmp, *ctx_init;
+    EVP_PKEY *mac_key;
+    const EVP_MD *md = EVP_sha256();
 
-	uint8_t A[EVP_MAX_MD_SIZE];
-	size_t len, A_len;
-	int chunk = EVP_MD_size(md);
-	int remaining = output_len;
+    uint8_t A[EVP_MAX_MD_SIZE];
+    size_t len, A_len;
+    int chunk = EVP_MD_size(md);
+    int remaining = output_len;
 
-	uint8_t *out = output;
+    uint8_t *out = output;
 
 #if OPENSSL_VERSION_NUMBER >= 0x1010000eL
-        ctx = EVP_MD_CTX_new();
-        ctx_tmp = EVP_MD_CTX_new();
-        ctx_init = EVP_MD_CTX_new();
+    ctx = EVP_MD_CTX_new();
+    ctx_tmp = EVP_MD_CTX_new();
+    ctx_init = EVP_MD_CTX_new();
 #else
-        ctx = ecalloc(1, sizeof(EVP_MD_CTX));
-	EVP_MD_CTX_init(ctx);
-        ctx_tmp = ecalloc(1, sizeof(EVP_MD_CTX));
-	EVP_MD_CTX_init(ctx_tmp);
-        ctx_init = ecalloc(1, sizeof(EVP_MD_CTX));
-	EVP_MD_CTX_init(ctx_init);
+    ctx = ecalloc(1, sizeof(EVP_MD_CTX));
+    EVP_MD_CTX_init(ctx);
+    ctx_tmp = ecalloc(1, sizeof(EVP_MD_CTX));
+    EVP_MD_CTX_init(ctx_tmp);
+    ctx_init = ecalloc(1, sizeof(EVP_MD_CTX));
+    EVP_MD_CTX_init(ctx_init);
 #endif
 
-	EVP_MD_CTX_set_flags(ctx_init, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
-
-	mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, secret, secret_len);
-
-	/* Calculate first A value */
-	EVP_DigestSignInit(ctx_init, NULL, md, NULL, mac_key);
-	EVP_MD_CTX_copy_ex(ctx, ctx_init);
-	if(seed1 != NULL && seed1_len > 0){
-		EVP_DigestSignUpdate(ctx, seed1, seed1_len);
-	}
-	if(seed2 != NULL && seed2_len > 0){
-		EVP_DigestSignUpdate(ctx, seed2, seed2_len);
-	}
-	if(seed3 != NULL && seed3_len > 0){
-		EVP_DigestSignUpdate(ctx, seed3, seed3_len);
-	}
-	if(seed4 != NULL && seed4_len > 0){
-		EVP_DigestSignUpdate(ctx, seed4, seed4_len);
-	}
-	EVP_DigestSignFinal(ctx, A, &A_len);
-
-	//iterate until desired length is achieved
-	while(remaining > 0){
-		/* Now compute SHA384(secret, A+seed) */
-		EVP_MD_CTX_copy_ex(ctx, ctx_init);
-		EVP_DigestSignUpdate(ctx, A, A_len);
-		EVP_MD_CTX_copy_ex(ctx_tmp, ctx);
-		if(seed1 != NULL && seed1_len > 0){
-			EVP_DigestSignUpdate(ctx, seed1, seed1_len);
-		}
-		if(seed2 != NULL && seed2_len > 0){
-			EVP_DigestSignUpdate(ctx, seed2, seed2_len);
-		}
-		if(seed3 != NULL && seed3_len > 0){
-			EVP_DigestSignUpdate(ctx, seed3, seed3_len);
-		}
-		if(seed4 != NULL && seed4_len > 0){
-			EVP_DigestSignUpdate(ctx, seed4, seed4_len);
-		}
-		
-		if(remaining > chunk){
-			EVP_DigestSignFinal(ctx, out, &len);
-			out += len;
-			remaining -= len;
-
-			/* Next A value */
-			EVP_DigestSignFinal(ctx_tmp, A, &A_len);
-		} else {
-			EVP_DigestSignFinal(ctx, A, &A_len);
-			memcpy(out, A, remaining);
-			remaining -= remaining;
-		}
-	}
-
-	EVP_PKEY_free(mac_key);
+    EVP_MD_CTX_set_flags(ctx_init, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
+
+    mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, secret, secret_len);
+
+    /* Calculate first A value */
+    EVP_DigestSignInit(ctx_init, NULL, md, NULL, mac_key);
+    EVP_MD_CTX_copy_ex(ctx, ctx_init);
+    if(seed1 != NULL && seed1_len > 0){
+        EVP_DigestSignUpdate(ctx, seed1, seed1_len);
+    }
+    if(seed2 != NULL && seed2_len > 0){
+        EVP_DigestSignUpdate(ctx, seed2, seed2_len);
+    }
+    if(seed3 != NULL && seed3_len > 0){
+        EVP_DigestSignUpdate(ctx, seed3, seed3_len);
+    }
+    if(seed4 != NULL && seed4_len > 0){
+        EVP_DigestSignUpdate(ctx, seed4, seed4_len);
+    }
+    EVP_DigestSignFinal(ctx, A, &A_len);
+
+    //iterate until desired length is achieved
+    while(remaining > 0){
+        /* Now compute SHA384(secret, A+seed) */
+        EVP_MD_CTX_copy_ex(ctx, ctx_init);
+        EVP_DigestSignUpdate(ctx, A, A_len);
+        EVP_MD_CTX_copy_ex(ctx_tmp, ctx);
+        if(seed1 != NULL && seed1_len > 0){
+            EVP_DigestSignUpdate(ctx, seed1, seed1_len);
+        }
+        if(seed2 != NULL && seed2_len > 0){
+            EVP_DigestSignUpdate(ctx, seed2, seed2_len);
+        }
+        if(seed3 != NULL && seed3_len > 0){
+            EVP_DigestSignUpdate(ctx, seed3, seed3_len);
+        }
+        if(seed4 != NULL && seed4_len > 0){
+            EVP_DigestSignUpdate(ctx, seed4, seed4_len);
+        }
+
+        if(remaining > chunk){
+            EVP_DigestSignFinal(ctx, out, &len);
+            out += len;
+            remaining -= len;
+
+            /* Next A value */
+            EVP_DigestSignFinal(ctx_tmp, A, &A_len);
+        } else {
+            EVP_DigestSignFinal(ctx, A, &A_len);
+            memcpy(out, A, remaining);
+            remaining -= remaining;
+        }
+    }
+
+    EVP_PKEY_free(mac_key);
 
 #if OPENSSL_VERSION_NUMBER >= 0x1010000eL
-        EVP_MD_CTX_free(ctx);
-        EVP_MD_CTX_free(ctx_tmp);
-        EVP_MD_CTX_free(ctx_init);
+    EVP_MD_CTX_free(ctx);
+    EVP_MD_CTX_free(ctx_tmp);
+    EVP_MD_CTX_free(ctx_init);
 #else
-	EVP_MD_CTX_cleanup(ctx);
-	EVP_MD_CTX_cleanup(ctx_tmp);
-	EVP_MD_CTX_cleanup(ctx_init);
-        free(ctx);
-        free(ctx_tmp);
-        free(ctx_init);
+    EVP_MD_CTX_cleanup(ctx);
+    EVP_MD_CTX_cleanup(ctx_tmp);
+    EVP_MD_CTX_cleanup(ctx_init);
+    free(ctx);
+    free(ctx_tmp);
+    free(ctx_init);
 #endif
 
-	return 1;
+    return 1;
 }
 
 
@@ -155,8 +155,8 @@ int PRF(uint8_t *secret, int32_t secret_len,
  */
 int generate_super_keys(uint8_t *secret){
 
-	super = calloc(1, sizeof(super_data));
-	
+    super = calloc(1, sizeof(super_data));
+
     EVP_MD_CTX *mac_ctx;
 
     const EVP_MD *md = EVP_sha256();
@@ -180,7 +180,7 @@ int generate_super_keys(uint8_t *secret){
             key_block, total_len);
 
 #ifdef DEBUG
-	int i;
+    int i;
     printf("secret: \n");
     for(i=0; i< SLITHEEN_SUPER_SECRET_SIZE; i++){
         printf("%02x ", secret[i]);
@@ -205,220 +205,220 @@ int generate_super_keys(uint8_t *secret){
     mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, mac_secret, mac_len);
     EVP_DigestSignInit(mac_ctx, NULL, md, NULL, mac_key);
 
-	super->header_key = malloc(key_len);
-	super->body_key = malloc(key_len);
-	memcpy(super->header_key, hdr_key, key_len);
-	memcpy(super->body_key, bdy_key, key_len);
+    super->header_key = malloc(key_len);
+    super->body_key = malloc(key_len);
+    memcpy(super->header_key, hdr_key, key_len);
+    memcpy(super->body_key, bdy_key, key_len);
     super->body_mac_ctx = mac_ctx;
 
     //Free everything
     free(key_block);
     EVP_PKEY_free(mac_key);
 
-	return 0;
+    return 0;
 }
 
 int peek_header(uint8_t *data){
 
-	EVP_CIPHER_CTX *hdr_ctx = NULL;
+    EVP_CIPHER_CTX *hdr_ctx = NULL;
 
-	int32_t out_len;
-	uint8_t *p = data;
-	int retval = 1;
+    int32_t out_len;
+    uint8_t *p = data;
+    int retval = 1;
 
-	//decrypt header
+    //decrypt header
 #ifdef DEBUG_PEEK
-	int i;
-	printf("Encrypted header:\n");
-	for(i=0; i< SLITHEEN_HEADER_LEN; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
+    int i;
+    printf("Encrypted header:\n");
+    for(i=0; i< SLITHEEN_HEADER_LEN; i++){
+        printf("%02x ", p[i]);
+    }
+    printf("\n");
 #endif
 
     hdr_ctx = EVP_CIPHER_CTX_new();
 
     EVP_CipherInit_ex(hdr_ctx, EVP_aes_256_ecb(), NULL, super->header_key, NULL, 0);
 
-	if(!EVP_CipherUpdate(hdr_ctx, p, &out_len, p, SLITHEEN_HEADER_LEN)){
-		retval =  0;
-		goto end;
-	}
+    if(!EVP_CipherUpdate(hdr_ctx, p, &out_len, p, SLITHEEN_HEADER_LEN)){
+        retval =  0;
+        goto end;
+    }
 
-	struct slitheen_hdr *sl_hdr = (struct slitheen_hdr *) p;
+    struct slitheen_hdr *sl_hdr = (struct slitheen_hdr *) p;
 
-        //Finally, check to see if the last few bytes are zeroed.
-        if(sl_hdr->zeros){
-            //zeros have been corrupted, decryption failed
-            printf("Decryption failed!\n");
-            retval = 0;
-            goto end;
-        }
+    //Finally, check to see if the last few bytes are zeroed.
+    if(sl_hdr->zeros){
+        //zeros have been corrupted, decryption failed
+        printf("Decryption failed!\n");
+        retval = 0;
+        goto end;
+    }
 
 #ifdef DEBUG_PARSE
-	printf("Decrypted header (%d bytes):\n", SLITHEEN_HEADER_LEN);
-	for(i=0; i< SLITHEEN_HEADER_LEN; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
-	fflush(stdout);
+    printf("Decrypted header (%d bytes):\n", SLITHEEN_HEADER_LEN);
+    for(i=0; i< SLITHEEN_HEADER_LEN; i++){
+        printf("%02x ", p[i]);
+    }
+    printf("\n");
+    fflush(stdout);
 #endif
 
-	retval = 1;
+    retval = 1;
 
 end:
-	if(hdr_ctx != NULL){
-		EVP_CIPHER_CTX_cleanup(hdr_ctx);
-		OPENSSL_free(hdr_ctx);
-	}
+    if(hdr_ctx != NULL){
+        EVP_CIPHER_CTX_cleanup(hdr_ctx);
+        OPENSSL_free(hdr_ctx);
+    }
 
-	return retval;
+    return retval;
 
 }
 
 int super_decrypt(uint8_t *data){
 
-	EVP_CIPHER_CTX *bdy_ctx = NULL;
-	EVP_CIPHER_CTX *hdr_ctx = NULL;
+    EVP_CIPHER_CTX *bdy_ctx = NULL;
+    EVP_CIPHER_CTX *hdr_ctx = NULL;
 
-	uint8_t *p = data;
-	int32_t out_len, len;
-	uint8_t output[EVP_MAX_MD_SIZE];
-	size_t mac_len;
-	int i, retval = 1;
+    uint8_t *p = data;
+    int32_t out_len, len;
+    uint8_t output[EVP_MAX_MD_SIZE];
+    size_t mac_len;
+    int i, retval = 1;
 
-	//decrypt header
+    //decrypt header
 #ifdef DEBUG
-	printf("Encrypted header:\n");
-	for(i=0; i< SLITHEEN_HEADER_LEN; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
+    printf("Encrypted header:\n");
+    for(i=0; i< SLITHEEN_HEADER_LEN; i++){
+        printf("%02x ", p[i]);
+    }
+    printf("\n");
 #endif
 
     hdr_ctx = EVP_CIPHER_CTX_new();
 
     EVP_CipherInit_ex(hdr_ctx, EVP_aes_256_ecb(), NULL, super->header_key, NULL, 0);
 
-	if(!EVP_CipherUpdate(hdr_ctx, p, &out_len, p, SLITHEEN_HEADER_LEN)){
-		printf("Decryption failed!");
-		retval =  0;
-		goto end;
-	}
+    if(!EVP_CipherUpdate(hdr_ctx, p, &out_len, p, SLITHEEN_HEADER_LEN)){
+        printf("Decryption failed!");
+        retval =  0;
+        goto end;
+    }
 
-	struct slitheen_hdr *sl_hdr = (struct slitheen_hdr *) p;
-	len = htons(sl_hdr->len);
+    struct slitheen_hdr *sl_hdr = (struct slitheen_hdr *) p;
+    len = htons(sl_hdr->len);
 
-	if(!sl_hdr->len){//there are no data to be decrypted
-		retval =  1;
-		goto end;
-	}
+    if(!sl_hdr->len){//there are no data to be decrypted
+        retval =  1;
+        goto end;
+    }
 
-	if(len %16){ //add padding to len
-		len += 16 - len%16;
-	}
+    if(len %16){ //add padding to len
+        len += 16 - len%16;
+    }
 
 
 #ifdef DEBUG
-	printf("Decrypted header (%d bytes):\n", SLITHEEN_HEADER_LEN);
-	for(i=0; i< SLITHEEN_HEADER_LEN; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
-	fflush(stdout);
+    printf("Decrypted header (%d bytes):\n", SLITHEEN_HEADER_LEN);
+    for(i=0; i< SLITHEEN_HEADER_LEN; i++){
+        printf("%02x ", p[i]);
+    }
+    printf("\n");
+    fflush(stdout);
 #endif
-	
-	p += SLITHEEN_HEADER_LEN;
 
-	//initialize body cipher context with IV
+    p += SLITHEEN_HEADER_LEN;
+
+    //initialize body cipher context with IV
     bdy_ctx = EVP_CIPHER_CTX_new();
     EVP_CipherInit_ex(bdy_ctx, EVP_aes_256_cbc(), NULL, super->body_key, p, 0);
-	p+=16;
+    p+=16;
 
-	//compute mac
-	EVP_MD_CTX *mac_ctx;
+    //compute mac
+    EVP_MD_CTX *mac_ctx;
 #if OPENSSL_VERSION_NUMBER >= 0x1010000eL
-        mac_ctx = EVP_MD_CTX_new();
+    mac_ctx = EVP_MD_CTX_new();
 #else
-        mac_ctx = ecalloc(1, sizeof(EVP_MD_CTX));
-	EVP_MD_CTX_init(mac_ctx);
+    mac_ctx = ecalloc(1, sizeof(EVP_MD_CTX));
+    EVP_MD_CTX_init(mac_ctx);
 #endif
-	EVP_MD_CTX_copy_ex(mac_ctx, super->body_mac_ctx);
+    EVP_MD_CTX_copy_ex(mac_ctx, super->body_mac_ctx);
 
-	EVP_DigestSignUpdate(mac_ctx, p, len);
+    EVP_DigestSignUpdate(mac_ctx, p, len);
 
-        EVP_DigestSignFinal(mac_ctx, output, &mac_len);
+    EVP_DigestSignFinal(mac_ctx, output, &mac_len);
 
 #if OPENSSL_VERSION_NUMBER >= 0x1010000eL
-        EVP_MD_CTX_free(mac_ctx);
+    EVP_MD_CTX_free(mac_ctx);
 #else
-	EVP_MD_CTX_cleanup(mac_ctx);
-        free(mac_ctx);
+    EVP_MD_CTX_cleanup(mac_ctx);
+    free(mac_ctx);
 #endif
 
 #ifdef DEBUG_PARSE
-	printf("Received mac:\n");
-	for(i=0; i< 16; i++){
-		printf("%02x ", p[len+i]);
-	}
-	printf("\n");
-	fflush(stdout);
+    printf("Received mac:\n");
+    for(i=0; i< 16; i++){
+        printf("%02x ", p[len+i]);
+    }
+    printf("\n");
+    fflush(stdout);
 #endif
 
 #ifdef DEBUG_PARSE
-	printf("Computed mac:\n");
-	for(i=0; i< 16; i++){
-		printf("%02x ", output[i]);
-	}
-	printf("\n");
-	fflush(stdout);
+    printf("Computed mac:\n");
+    for(i=0; i< 16; i++){
+        printf("%02x ", output[i]);
+    }
+    printf("\n");
+    fflush(stdout);
 #endif
 
-	if(memcmp(p+len, output, 16)){
-		printf("MAC verification failed\n");
-		retval =  0;
-		goto end;
-	}
+    if(memcmp(p+len, output, 16)){
+        printf("MAC verification failed\n");
+        retval =  0;
+        goto end;
+    }
 
-	//decrypt body
+    //decrypt body
 #ifdef DEBUG_PARSE
-	printf("Encrypted data (%d bytes):\n", len);
-	for(i=0; i< len; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
+    printf("Encrypted data (%d bytes):\n", len);
+    for(i=0; i< len; i++){
+        printf("%02x ", p[i]);
+    }
+    printf("\n");
 #endif
 
-	if(!EVP_CipherUpdate(bdy_ctx, p, &out_len, p, len)){
-		printf("Decryption failed!");
-		retval =  0;
-		goto end;
-	}
+    if(!EVP_CipherUpdate(bdy_ctx, p, &out_len, p, len)){
+        printf("Decryption failed!");
+        retval =  0;
+        goto end;
+    }
 
 #ifdef DEBUG
-	printf("Decrypted data (%d bytes):\n", out_len);
-	for(i=0; i< out_len; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
-	fflush(stdout);
+    printf("Decrypted data (%d bytes):\n", out_len);
+    for(i=0; i< out_len; i++){
+        printf("%02x ", p[i]);
+    }
+    printf("\n");
+    fflush(stdout);
 #endif
 
-	p += out_len;
+    p += out_len;
 
-	retval = 1;
+    retval = 1;
 
 end:
-	if(hdr_ctx != NULL){
-		EVP_CIPHER_CTX_cleanup(hdr_ctx);
-		OPENSSL_free(hdr_ctx);
-	}
-	if(bdy_ctx != NULL){
-		EVP_CIPHER_CTX_cleanup(bdy_ctx);
-		OPENSSL_free(bdy_ctx);
-	}
-
-	return retval;
+    if(hdr_ctx != NULL){
+        EVP_CIPHER_CTX_cleanup(hdr_ctx);
+        OPENSSL_free(hdr_ctx);
+    }
+    if(bdy_ctx != NULL){
+        EVP_CIPHER_CTX_cleanup(bdy_ctx);
+        OPENSSL_free(bdy_ctx);
+    }
+
+    return retval;
 
 }
 

+ 12 - 12
client/crypto.h

@@ -10,14 +10,14 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Additional permission under GNU GPL version 3 section 7
- * 
+ *
  * If you modify this Program, or any covered work, by linking or combining
- * it with the OpenSSL library (or a modified version of that library), 
+ * it with the OpenSSL library (or a modified version of that library),
  * containing parts covered by the terms of [name of library's license],
  * the licensors of this Program grant you additional permission to convey
  * the resulting work. {Corresponding Source for a non-source form of such
@@ -31,24 +31,24 @@
 #include <openssl/evp.h>
 
 # define n2s(c,s)        ((s=(((unsigned int)(c[0]))<< 8)| \
-							(((unsigned int)(c[1]))    )),c+=2)
+            (((unsigned int)(c[1]))    )),c+=2)
 
 
 int PRF(uint8_t *secret, int32_t secret_len,
-		uint8_t *seed1, int32_t seed1_len,
-		uint8_t *seed2, int32_t seed2_len,
-		uint8_t *seed3, int32_t seed3_len,
-		uint8_t *seed4, int32_t seed4_len,
-		uint8_t *output, int32_t output_len);
+        uint8_t *seed1, int32_t seed1_len,
+        uint8_t *seed2, int32_t seed2_len,
+        uint8_t *seed3, int32_t seed3_len,
+        uint8_t *seed4, int32_t seed4_len,
+        uint8_t *output, int32_t output_len);
 
 int peek_header(uint8_t *data);
 int super_decrypt(uint8_t *data);
 int generate_super_keys(uint8_t *secret);
 
 typedef struct super_data_st {
-	uint8_t *header_key;
-	uint8_t *body_key;
-	EVP_MD_CTX *body_mac_ctx;
+    uint8_t *header_key;
+    uint8_t *body_key;
+    EVP_MD_CTX *body_mac_ctx;
 } super_data;
 
 #define PRE_MASTER_LEN 256

+ 3 - 5
client/socks5proxy.c

@@ -137,7 +137,7 @@ int main(void){
         addr_size = sizeof(remote_addr);
         int new_socket;
         new_socket = accept(listen_socket, (struct sockaddr *) &remote_addr,
-                                        &addr_size);
+                &addr_size);
         if(new_socket < 0){
             perror("accept");
             exit(1);
@@ -560,7 +560,7 @@ void *multiplex_data(void *args){
 #ifdef DEBUG_UPSTREAM
                         printf("Received %d data bytes from sockfd (id %d):\n", bytes_read, conn->stream_id);
                         for(int i=0; i< bytes_read; i++){
-                                printf("%02x ", buffer[i]);
+                            printf("%02x ", buffer[i]);
                         }
                         printf("\n");
                         printf("%s\n", buffer);
@@ -751,7 +751,7 @@ void *demultiplex_data(void *args){
                 if(sl_hdr->counter > expected_next_count){
                     //save any future data
                     printf("Received header with count %lu. Expected count %lu.\n",
-                                        sl_hdr->counter, expected_next_count);
+                            sl_hdr->counter, expected_next_count);
                     if((saved_data == NULL) || (saved_data->count > sl_hdr->counter)){
                         data_block *new_block = malloc(sizeof(data_block));
                         new_block->count = sl_hdr->counter;
@@ -852,5 +852,3 @@ int remove_connection(uint16_t stream_id){
 
     return 1;
 }
-
-

+ 23 - 23
client/socks5proxy.h

@@ -40,18 +40,18 @@ void *ous_IO();
 int remove_connection(uint16_t stream_id);
 
 struct __attribute__ ((__packed__)) slitheen_hdr {
-	uint64_t counter;
-	uint16_t stream_id;
-	uint16_t len;
-	uint16_t garbage;
-	uint16_t zeros;
+    uint64_t counter;
+    uint16_t stream_id;
+    uint16_t len;
+    uint16_t garbage;
+    uint16_t zeros;
 };
 
 #define SLITHEEN_HEADER_LEN 16
 
 struct __attribute__ ((__packed__)) slitheen_up_hdr{
-	uint16_t stream_id;
-	uint16_t len;
+    uint16_t stream_id;
+    uint16_t len;
 };
 
 #define NEW_STREAM 0
@@ -60,34 +60,34 @@ struct __attribute__ ((__packed__)) slitheen_up_hdr{
 
 
 typedef struct connection_st{
-	uint16_t stream_id;
-        int32_t socket;
-        uint8_t state;
-	struct connection_st *next;
+    uint16_t stream_id;
+    int32_t socket;
+    uint8_t state;
+    struct connection_st *next;
 } connection;
 
 typedef struct connection_table_st{
-	connection *first;
+    connection *first;
 } connection_table;
 
 typedef struct data_block_st {
-	uint64_t count;
-	uint8_t *data;
-        uint16_t len;
-        int32_t socket;
-	struct data_block_st *next;
+    uint64_t count;
+    uint8_t *data;
+    uint16_t len;
+    int32_t socket;
+    struct data_block_st *next;
 } data_block;
 
 struct socks_method_req {
-	uint8_t version;
-	uint8_t num_methods;
+    uint8_t version;
+    uint8_t num_methods;
 };
 
 struct socks_req {
-	uint8_t version;
-	uint8_t cmd;
-	uint8_t rsvd;
-	uint8_t addr_type;
+    uint8_t version;
+    uint8_t cmd;
+    uint8_t rsvd;
+    uint8_t addr_type;
 };
 
 #endif /* _SOCKS5PROXY_H_ */

+ 25 - 25
client/tagging.c

@@ -10,14 +10,14 @@
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * Additional permission under GNU GPL version 3 section 7
- * 
+ *
  * If you modify this Program, or any covered work, by linking or combining
- * it with the OpenSSL library (or a modified version of that library), 
+ * it with the OpenSSL library (or a modified version of that library),
  * containing parts covered by the terms of the OpenSSL Licence and the
  * SSLeay license, the licensors of this Program grant you additional
  * permission to convey the resulting work. Corresponding Source for a
@@ -47,7 +47,7 @@ byte twistpub[PTWIST_BYTES];
 
 
 static void gen_tag(byte *tag, byte stored_key[16],
-	const byte *context, size_t context_len)
+        const byte *context, size_t context_len)
 {
     byte seckey[PTWIST_BYTES];
     byte sharedsec[PTWIST_BYTES+context_len];
@@ -88,21 +88,21 @@ static void gen_tag(byte *tag, byte stored_key[16],
     value_to_hash[16+PTWIST_RESP_BYTES-1] &= PTWIST_RESP_MASK;
 
     while(1) {
-	unsigned int firstbits;
+        unsigned int firstbits;
 
-	md_map_sh256(hashout, value_to_hash, puzzle_len);
+        md_map_sh256(hashout, value_to_hash, puzzle_len);
 #if PTWIST_PUZZLE_STRENGTH < 32
-	/* This assumes that you're on an architecture that doesn't care
-	 * about alignment, and is little endian. */
-	firstbits = *(unsigned int*)hashout;
-	if ((firstbits & PTWIST_PUZZLE_MASK) == 0) {
-	    break;
-	}
-	/* Increment R and try again. */
-	for(i=0;i<PTWIST_RESP_BYTES;++i) {
-	    if (++value_to_hash[16+i]) break;
-	}
-	value_to_hash[16+PTWIST_RESP_BYTES-1] &= PTWIST_RESP_MASK;
+        /* This assumes that you're on an architecture that doesn't care
+         * about alignment, and is little endian. */
+        firstbits = *(unsigned int*)hashout;
+        if ((firstbits & PTWIST_PUZZLE_MASK) == 0) {
+            break;
+        }
+        /* Increment R and try again. */
+        for(i=0;i<PTWIST_RESP_BYTES;++i) {
+            if (++value_to_hash[16+i]) break;
+        }
+        value_to_hash[16+PTWIST_RESP_BYTES-1] &= PTWIST_RESP_MASK;
 #else
 #error "Code assumes PTWIST_PUZZLE_STRENGTH < 32"
 #endif
@@ -154,24 +154,24 @@ int generate_slitheen_id(byte *slitheen_id, byte stored_key[16])
     /* Read the public keys */
     fp = fopen("pubkey", "rb");
     if (fp == NULL) {
-		perror("fopen");
-		exit(1);
+        perror("fopen");
+        exit(1);
     }
     res = fread(mainpub, PTWIST_BYTES, 1, fp);
     if (res < 1) {
-		perror("fread");
-		exit(1);
+        perror("fread");
+        exit(1);
     }
     res = fread(twistpub, PTWIST_BYTES, 1, fp);
     if (res < 1) {
-		perror("fread");
-		exit(1);
+        perror("fread");
+        exit(1);
     }
     fclose(fp);
 
-	tag = slitheen_id;
+    tag = slitheen_id;
 
-	gen_tag(tag, stored_key, (const byte *)"context", 7);
+    gen_tag(tag, stored_key, (const byte *)"context", 7);
 
     return 0;
 }

+ 1 - 1
client/util.c

@@ -35,7 +35,7 @@ void *emalloc(size_t size){
     void *ptr = malloc(size);
     if (ptr == NULL){
         fprintf(stderr, "Memory failure. Exiting...\n");
-	exit(1);
+        exit(1);
     }
 
     return ptr;