forked from cory/tildefriends
		
	Report some information when importing messages and discover an old verification bug.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4293 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										19
									
								
								src/ssb.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								src/ssb.c
									
									
									
									
									
								
							| @@ -963,7 +963,7 @@ bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* ou | |||||||
| 		} | 		} | ||||||
| 		return true; | 		return true; | ||||||
| 	} | 	} | ||||||
| 	else if (out_sequence_before_author) | 	else | ||||||
| 	{ | 	{ | ||||||
| 		JSValue reordered = JS_NewObject(context); | 		JSValue reordered = JS_NewObject(context); | ||||||
| 		JS_SetPropertyStr(context, reordered, "previous", JS_GetPropertyStr(context, val, "previous")); | 		JS_SetPropertyStr(context, reordered, "previous", JS_GetPropertyStr(context, val, "previous")); | ||||||
| @@ -976,8 +976,11 @@ bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* ou | |||||||
| 		bool result = _tf_ssb_verify_and_strip_signature_internal(context, reordered, out_id, out_id_size, out_signature, out_signature_size); | 		bool result = _tf_ssb_verify_and_strip_signature_internal(context, reordered, out_id, out_id_size, out_signature, out_signature_size); | ||||||
| 		JS_FreeValue(context, reordered); | 		JS_FreeValue(context, reordered); | ||||||
| 		if (result) | 		if (result) | ||||||
|  | 		{ | ||||||
|  | 			if (out_sequence_before_author) | ||||||
| 			{ | 			{ | ||||||
| 				*out_sequence_before_author = true; | 				*out_sequence_before_author = true; | ||||||
|  | 			} | ||||||
| 			return true; | 			return true; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @@ -3373,25 +3376,33 @@ tf_ssb_blob_wants_t* tf_ssb_connection_get_blob_wants_state(tf_ssb_connection_t* | |||||||
| 	return connection ? &connection->blob_wants : NULL; | 	return connection ? &connection->blob_wants : NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value) | bool tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value, bool* out_is_new) | ||||||
| { | { | ||||||
| 	JSContext* context = tf_ssb_get_context(ssb); | 	JSContext* context = tf_ssb_get_context(ssb); | ||||||
| 	char signature[crypto_sign_BYTES + 128] = { 0 }; | 	char signature[crypto_sign_BYTES + 128] = { 0 }; | ||||||
| 	char id[crypto_hash_sha256_BYTES * 2 + 1] = { 0 }; | 	char id[crypto_hash_sha256_BYTES * 2 + 1] = { 0 }; | ||||||
| 	bool sequence_before_author = false; | 	bool sequence_before_author = false; | ||||||
|  | 	if (out_is_new) | ||||||
|  | 	{ | ||||||
|  | 		*out_is_new = false; | ||||||
|  | 	} | ||||||
| 	if (tf_ssb_verify_and_strip_signature(context, value, id, sizeof(id), signature, sizeof(signature), &sequence_before_author)) | 	if (tf_ssb_verify_and_strip_signature(context, value, id, sizeof(id), signature, sizeof(signature), &sequence_before_author)) | ||||||
| 	{ | 	{ | ||||||
| 		if (tf_ssb_db_store_message(ssb, context, id, value, signature, sequence_before_author)) | 		if (tf_ssb_db_store_message(ssb, context, id, value, signature, sequence_before_author)) | ||||||
| 		{ | 		{ | ||||||
| 			tf_ssb_notify_message_added(ssb, id); | 			tf_ssb_notify_message_added(ssb, id); | ||||||
| 			return true; | 			if (out_is_new) | ||||||
|  | 			{ | ||||||
|  | 				*out_is_new = true; | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 		return true; | ||||||
|  | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| 		tf_printf("failed to verify message\n"); | 		tf_printf("failed to verify message\n"); | ||||||
| 	} |  | ||||||
| 		return false; | 		return false; | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| bool tf_ssb_connection_get_sent_clock(tf_ssb_connection_t* connection) | bool tf_ssb_connection_get_sent_clock(tf_ssb_connection_t* connection) | ||||||
|   | |||||||
| @@ -108,7 +108,7 @@ bool tf_ssb_id_bin_to_str(char* str, size_t str_size, const uint8_t* bin); | |||||||
|  |  | ||||||
| bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* out_id, size_t out_id_size, char* out_signature, size_t out_signature_size, bool* out_sequence_before_author); | bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* out_id, size_t out_id_size, char* out_signature, size_t out_signature_size, bool* out_sequence_before_author); | ||||||
| void tf_ssb_calculate_message_id(JSContext* context, JSValue message, char* out_id, size_t out_id_size); | void tf_ssb_calculate_message_id(JSContext* context, JSValue message, char* out_id, size_t out_id_size); | ||||||
| bool tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value); | bool tf_ssb_verify_strip_and_store_message(tf_ssb_t* ssb, JSValue value, bool* out_is_new); | ||||||
|  |  | ||||||
| bool tf_ssb_connection_is_client(tf_ssb_connection_t* connection); | bool tf_ssb_connection_is_client(tf_ssb_connection_t* connection); | ||||||
| const char* tf_ssb_connection_get_host(tf_ssb_connection_t* connection); | const char* tf_ssb_connection_get_host(tf_ssb_connection_t* connection); | ||||||
|   | |||||||
							
								
								
									
										10
									
								
								src/ssb.js.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/ssb.js.c
									
									
									
									
									
								
							| @@ -642,7 +642,15 @@ static JSValue _tf_ssb_sqlAsync(JSContext* context, JSValueConst this_val, int a | |||||||
| static JSValue _tf_ssb_storeMessage(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) | static JSValue _tf_ssb_storeMessage(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv) | ||||||
| { | { | ||||||
| 	tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId); | 	tf_ssb_t* ssb = JS_GetOpaque(this_val, _tf_ssb_classId); | ||||||
| 	return tf_ssb_verify_strip_and_store_message(ssb, argv[0]) ? JS_TRUE : JS_FALSE; | 	bool is_new = false; | ||||||
|  | 	if (tf_ssb_verify_strip_and_store_message(ssb, argv[0], &is_new)) | ||||||
|  | 	{ | ||||||
|  | 		return is_new ? JS_TRUE : JS_FALSE; | ||||||
|  | 	} | ||||||
|  | 	else | ||||||
|  | 	{ | ||||||
|  | 		return JS_UNDEFINED; | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| typedef struct _broadcasts_t | typedef struct _broadcasts_t | ||||||
|   | |||||||
| @@ -937,7 +937,7 @@ static void _tf_ssb_rpc_ebt_replicate(tf_ssb_connection_t* connection, uint8_t f | |||||||
| 	if (!JS_IsUndefined(author)) | 	if (!JS_IsUndefined(author)) | ||||||
| 	{ | 	{ | ||||||
| 		/* Looks like a message. */ | 		/* Looks like a message. */ | ||||||
| 		tf_ssb_verify_strip_and_store_message(ssb, args); | 		tf_ssb_verify_strip_and_store_message(ssb, args, NULL); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user