Browse Source

Remove now-dead code

Remove verify_finish_hash (which is no longer called),
update_finish_hash (and all calls to it), and all references to the
finish_md_ctx element of the flow structure.
Ian Goldberg 7 years ago
parent
commit
c7aadd6530
4 changed files with 0 additions and 218 deletions
  1. 0 153
      relay_station/crypto.c
  2. 0 1
      relay_station/crypto.h
  3. 0 63
      relay_station/flow.c
  4. 0 1
      relay_station/flow.h

+ 0 - 153
relay_station/crypto.c

@@ -207,37 +207,6 @@ static int nid_list[] = {
     NID_brainpoolP512r1         /* brainpool512r1 (28) */
 };
 
-/** Updates the hash of all TLS handshake messages upon the
- *  receipt of a new message. This hash is eventually used
- *  to verify the TLS Finished message
- *
- *  Inputs:
- *  	f: the tagged flow
- *  	hs: A pointer to the start of the handshake message
- *
- *  Output:
- *  	0 on success, 1 on failure
- */
-int update_finish_hash(flow *f, uint8_t *hs){
-	//find handshake length
-	const struct handshake_header *hs_hdr;
-	uint8_t *p = hs;
-	hs_hdr = (struct handshake_header*) p;
-	uint32_t hs_len = HANDSHAKE_MESSAGE_LEN(hs_hdr);
-	
-	EVP_DigestUpdate(f->finish_md_ctx, hs, hs_len+4);
-
-#ifdef DEBUG
-	printf("SLITHEEN: adding to finish mac computation:\n");
-	for(int i=0; i< hs_len + 4; i++){
-		printf("%02x ", hs[i]);
-	}
-	printf("\n");
-#endif
-
-	return 0;
-}
-
 /** Extracts the server parameters from the server key
  *  exchange message
  *
@@ -544,128 +513,6 @@ int mark_finished_hash(flow *f, uint8_t *hs){
 	return 0;
 }
 
-/** Verifies the hash in a TLS finished message
- *
- * Adds string derived from the client-relay shared secret to the finished hash.
- * This feature detects and prevents suspicious behaviour in the event of a MiTM
- * or RAD attack.
- *
- * 	Inputs:
- * 		f: the tagged flow
- * 		p: a pointer to the TLS Finished handshake message
- * 		incoming: the direction of the flow
- *
- * 	Output:
- * 		0 on success, 1 on failure
- */
-int verify_finish_hash(flow *f, uint8_t *hs, int32_t incoming){
-	EVP_MD_CTX ctx;
-	uint8_t hash[EVP_MAX_MD_SIZE];
-	uint32_t hash_len;
-	uint8_t *p = hs;
-
-	EVP_MD_CTX_init(&ctx);
-	
-	//get header length
-	struct handshake_header *hs_hdr;
-	hs_hdr = (struct handshake_header*) p;
-	uint32_t fin_length = HANDSHAKE_MESSAGE_LEN(hs_hdr);
-
-	//save old finished to update finished mac hash
-	uint8_t *old_finished = emalloc(fin_length+ HANDSHAKE_HEADER_LEN);
-	memcpy(old_finished, p, fin_length+HANDSHAKE_HEADER_LEN);
-	
-	p += HANDSHAKE_HEADER_LEN;
-
-	//finalize hash of handshake msgs (have not yet added this one)
-	EVP_MD_CTX_copy_ex(&ctx, f->finish_md_ctx);
-	EVP_DigestFinal_ex(&ctx, hash, &hash_len);
-
-	//now use pseudorandom function
-	uint8_t *output = ecalloc(1, fin_length);
-
-	if(incoming){
-		PRF(f, f->master_secret, SSL3_MASTER_SECRET_SIZE, (uint8_t *) TLS_MD_SERVER_FINISH_CONST, TLS_MD_SERVER_FINISH_CONST_SIZE , hash, hash_len, NULL, 0, NULL, 0, output, fin_length);
-	} else {
-		PRF(f, f->master_secret, SSL3_MASTER_SECRET_SIZE, (uint8_t *) TLS_MD_CLIENT_FINISH_CONST, TLS_MD_CLIENT_FINISH_CONST_SIZE , hash, hash_len, NULL, 0, NULL, 0, output, fin_length);
-	}
-
-	//now compare
-	if(CRYPTO_memcmp(p, output, fin_length) != 0){
-		printf("VERIFY FAILED\n");
-		goto err;
-	}
-
-#ifdef DEBUG_HS
-	printf("Old finished:\n");
-	for(int i=0; i< fin_length; i++){
-		printf("%02x ", p[i]);
-	}
-	printf("\n");
-#endif
-
-	//now add extra input seeded with client-relay shared secret
-	if(incoming){
-		uint32_t extra_input_len = SSL3_RANDOM_SIZE;
-		uint8_t *extra_input = calloc(1, extra_input_len);
-
-		PRF(f, f->key, 16,
-			(uint8_t *) SLITHEEN_FINISHED_INPUT_CONST, SLITHEEN_FINISHED_INPUT_CONST_SIZE,
-			NULL, 0, NULL, 0, NULL, 0,
-			extra_input, extra_input_len);
-
-#ifdef DEBUG_HS
-		printf("Extra input:\n");
-		for(int i=0; i< extra_input_len; i++){
-			printf("%02x ", extra_input[i]);
-		}
-		printf("\n");
-#endif
-
-		EVP_MD_CTX_copy_ex(&ctx, f->finish_md_ctx);
-		EVP_DigestUpdate(&ctx, extra_input, extra_input_len);
-
-		EVP_DigestFinal_ex(&ctx, hash, &hash_len);
-
-		PRF(f, f->master_secret, SSL3_MASTER_SECRET_SIZE,
-			(uint8_t *) TLS_MD_SERVER_FINISH_CONST, TLS_MD_SERVER_FINISH_CONST_SIZE ,
-			hash, hash_len, NULL, 0, NULL, 0,
-			output, fin_length);
-
-		//replace existing MAC with modified one
-		memcpy(p, output, fin_length);
-
-#ifdef DEBUG_HS
-		printf("New finished:\n");
-		for(int i=0; i< fin_length; i++){
-			printf("%02x ", p[i]);
-		}
-		printf("\n");
-#endif
-
-		free(extra_input);
-
-	}
-
-	if(update_finish_hash(f, old_finished)){
-		fprintf(stderr, "Error updating finish hash with FINISHED msg\n");
-		goto err;
-	}
-
-	free(old_finished);
-
-	free(output);
-	EVP_MD_CTX_cleanup(&ctx);
-	return 0;
-
-err:
-	if(output != NULL)
-		free(output);
-	if(old_finished != NULL)
-		free(old_finished);
-	EVP_MD_CTX_cleanup(&ctx);
-	return 1;
-}
 
 /** Computes the TLS master secret from the decoy server's
  *  public key parameters and the leaked secret from the

+ 0 - 1
relay_station/crypto.h

@@ -51,7 +51,6 @@ int PRF(flow *f, uint8_t *secret, int32_t secret_len,
 		uint8_t *seed4, int32_t seed4_len,
 		uint8_t *output, int32_t output_len);
 
-int update_finish_hash(flow *f, uint8_t *hs);
 int mark_finished_hash(flow *f, uint8_t *hs);
 int init_ciphers(flow *f);
 void generate_client_super_keys(uint8_t *secret, client *c);

+ 0 - 63
relay_station/flow.c

@@ -141,10 +141,6 @@ flow *add_flow(struct packet_info *info) {
 	new_flow->ecdh = NULL;
 	new_flow->dh = NULL;
 
-	new_flow->finish_md_ctx = EVP_MD_CTX_create();
-	const EVP_MD *md = EVP_sha384();
-	EVP_DigestInit_ex(new_flow->finish_md_ctx, md, NULL);
-
 	new_flow->cipher = NULL;
 	new_flow->clnt_read_ctx = NULL;
 	new_flow->clnt_write_ctx = NULL;
@@ -241,11 +237,6 @@ int update_flow(flow *f, uint8_t *record, uint8_t incoming) {
 #ifdef DEBUG_HS
 					printf("Received tagged client hello (%x:%d -> %x:%d)\n", f->src_ip.s_addr, ntohs(f->src_port), f->dst_ip.s_addr, ntohs(f->dst_port));
 #endif
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish has with CLNT_HELLO msg\n");
-						remove_flow(f);
-						goto err;
-					}
 					if(check_session(f, p, HANDSHAKE_MESSAGE_LEN(handshake_hdr))){
 						fprintf(stderr, "Error checking session, might cause problems\n");
 					}
@@ -269,12 +260,6 @@ int update_flow(flow *f, uint8_t *record, uint8_t incoming) {
 						remove_flow(f);
 						goto err;
 					}
-
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with SRVR_HELLO msg\n");
-						remove_flow(f);
-						goto err;
-					}
 					break;
 				case TLS_NEW_SESS:
 #ifdef DEBUG_HS
@@ -283,35 +268,16 @@ int update_flow(flow *f, uint8_t *record, uint8_t incoming) {
 					if(save_session_ticket(f, p, HANDSHAKE_MESSAGE_LEN(handshake_hdr))){
 						fprintf(stderr, "Failed to save session ticket\n");
 					}
-					
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with NEW_SESS msg\n");
-						remove_flow(f);
-						goto err;
-					}
-					
 					break;
 				case TLS_CERT:
 #ifdef DEBUG_HS
 					printf("Received cert\n");
 #endif
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with CERT msg\n");
-						remove_flow(f);
-						goto err;
-					}
-
 					break;
 				case TLS_SRVR_KEYEX:
 #ifdef DEBUG_HS
 					printf("Received server keyex\n");
 #endif
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with SRVR_KEYEX msg\n");
-						remove_flow(f);
-						goto err;
-					}
-
 					if(extract_parameters(f, p)){
 						printf("Error extracting params\n");
 						remove_flow(f);
@@ -328,47 +294,22 @@ int update_flow(flow *f, uint8_t *record, uint8_t incoming) {
 					break;
 
 				case TLS_CERT_REQ:
-
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with CERT_REQ msg\n");
-						remove_flow(f);
-						goto err;
-					}
-
 					break;
 				case TLS_SRVR_HELLO_DONE:
 #ifdef DEBUG_HS
 					printf("Received server hello done\n");
 #endif
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with HELLO_DONE msg\n");
-						remove_flow(f);
-						goto err;
-					}
-
 					break;
 				case TLS_CERT_VERIFY:
 #ifdef DEBUG_HS
 					printf("received cert verify\n");
 #endif
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with CERT_VERIFY msg\n");
-						remove_flow(f);
-						goto err;
-					}
-
 					break;
 
 				case TLS_CLNT_KEYEX:
 #ifdef DEBUG_HS
 					printf("Received client key exchange\n");
 #endif
-					if(update_finish_hash(f, p)){
-						fprintf(stderr, "Error updating finish hash with CLNT_KEYEX msg\n");
-						remove_flow(f);
-						goto err;
-					}
-
 					break;
 				case TLS_FINISHED:
 #ifdef DEBUG_HS
@@ -547,10 +488,6 @@ int remove_flow(flow *f) {
     }
 
 	//Clean up cipher ctxs
-	EVP_MD_CTX_cleanup(f->finish_md_ctx);
-	if(f->finish_md_ctx != NULL){
-		EVP_MD_CTX_destroy(f->finish_md_ctx);
-	}
 	if(f->clnt_read_ctx != NULL){
 		EVP_CIPHER_CTX_cleanup(f->clnt_read_ctx);
 		OPENSSL_free(f->clnt_read_ctx);

+ 0 - 1
relay_station/flow.h

@@ -168,7 +168,6 @@ typedef struct flow_st {
 	const EVP_MD *message_digest;
 	uint8_t keyex_alg;
 	uint8_t handshake_hash[EVP_MAX_MD_SIZE];
-	EVP_MD_CTX *finish_md_ctx;
 	EVP_CIPHER_CTX *clnt_read_ctx;
 	EVP_CIPHER_CTX *clnt_write_ctx;
 	EVP_CIPHER_CTX *srvr_read_ctx;