I think this fixes the questionable archaic sequence / author order issue.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3813 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
37
src/ssb.c
37
src/ssb.c
@ -489,7 +489,7 @@ void tf_ssb_calculate_message_id(JSContext* context, JSValue message, char* out_
|
||||
JS_FreeValue(context, idval);
|
||||
}
|
||||
|
||||
bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* out_signature, size_t out_signature_size)
|
||||
static bool _tf_ssb_verify_and_strip_signature_internal(JSContext* context, JSValue val, char* out_signature, size_t out_signature_size)
|
||||
{
|
||||
bool verified = false;
|
||||
JSValue signature = JS_GetPropertyStr(context, val, "signature");
|
||||
@ -553,6 +553,37 @@ bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* ou
|
||||
return verified;
|
||||
}
|
||||
|
||||
bool tf_ssb_verify_and_strip_signature(JSContext* context, JSValue val, char* out_signature, size_t out_signature_size, bool* out_sequence_before_author)
|
||||
{
|
||||
if (_tf_ssb_verify_and_strip_signature_internal(context, val, out_signature, out_signature_size))
|
||||
{
|
||||
if (out_sequence_before_author)
|
||||
{
|
||||
*out_sequence_before_author = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (out_sequence_before_author)
|
||||
{
|
||||
JSValue reordered = JS_NewObject(context);
|
||||
JS_SetPropertyStr(context, reordered, "previous", JS_GetPropertyStr(context, val, "previous"));
|
||||
JS_SetPropertyStr(context, reordered, "sequence", JS_GetPropertyStr(context, val, "sequence"));
|
||||
JS_SetPropertyStr(context, reordered, "author", JS_GetPropertyStr(context, val, "author"));
|
||||
JS_SetPropertyStr(context, reordered, "timestamp", JS_GetPropertyStr(context, val, "timestamp"));
|
||||
JS_SetPropertyStr(context, reordered, "hash", JS_GetPropertyStr(context, val, "hash"));
|
||||
JS_SetPropertyStr(context, reordered, "content", JS_GetPropertyStr(context, val, "content"));
|
||||
JS_SetPropertyStr(context, reordered, "signature", JS_GetPropertyStr(context, val, "signature"));
|
||||
bool result = _tf_ssb_verify_and_strip_signature_internal(context, reordered, out_signature, out_signature_size);
|
||||
JS_FreeValue(context, reordered);
|
||||
if (result)
|
||||
{
|
||||
*out_sequence_before_author = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void tf_ssb_send_close(tf_ssb_t* ssb)
|
||||
{
|
||||
for (tf_ssb_connection_t* connection = ssb->connections; connection; connection = connection->next)
|
||||
@ -1183,12 +1214,12 @@ void tf_ssb_append_message(tf_ssb_t* ssb, JSValue message)
|
||||
char id[sodium_base64_ENCODED_LEN(crypto_hash_sha256_BYTES, sodium_base64_VARIANT_ORIGINAL) + 7 + 1];
|
||||
tf_ssb_calculate_message_id(ssb->context, root, id, sizeof(id));
|
||||
if (valid &&
|
||||
!tf_ssb_db_store_message(ssb, ssb->context, id, root, signature_base64))
|
||||
!tf_ssb_db_store_message(ssb, ssb->context, id, root, signature_base64, false))
|
||||
{
|
||||
printf("message not stored.\n");
|
||||
}
|
||||
|
||||
if (!tf_ssb_verify_and_strip_signature(ssb->context, root, NULL, 0))
|
||||
if (!tf_ssb_verify_and_strip_signature(ssb->context, root, NULL, 0, NULL))
|
||||
{
|
||||
printf("Failed to verify message signature.\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user