From 7fe8f66fd3cbdce3040c88c511c3d32a48655092 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 18 Jul 2023 00:59:25 +0000 Subject: [PATCH] Yikes. I broke appending? git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4351 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- src/ssb.c | 11 ++++++----- src/ssb.js.c | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/ssb.c b/src/ssb.c index 9e92dcd5..943f4f7d 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -1683,8 +1683,7 @@ bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui { JS_SetPropertyStr(context, root, "previous", JS_NULL); } - JSValue authorstr = JS_NewString(context, author); - JS_SetPropertyStr(context, root, "author", authorstr); + JS_SetPropertyStr(context, root, "author", JS_NewString(context, author)); JS_SetPropertyStr(context, root, "sequence", JS_NewInt64(context, previous_sequence + 1)); int64_t now = (int64_t)time(NULL); @@ -1706,9 +1705,6 @@ bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui tf_printf("crypto_sign_detached failed\n"); } - JS_FreeCString(context, json); - JS_FreeValue(context, jsonval); - char signature_base64[crypto_sign_BYTES * 2]; tf_base64_encode(signature, sizeof(signature), signature_base64, sizeof(signature_base64)); strcat(signature_base64, ".sig.ed25519"); @@ -1733,6 +1729,8 @@ bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui else { tf_printf("Failed to verify message signature.\n"); + tf_printf("json = %s\n", json); + tf_printf("sig = %s\n", signature_base64); } if (!stored && out_id && out_id_size) @@ -1740,6 +1738,9 @@ bool tf_ssb_append_message_with_keys(tf_ssb_t* ssb, const char* author, const ui *out_id = '\0'; } + JS_FreeCString(context, json); + JS_FreeValue(context, jsonval); + JS_FreeValue(context, root); return stored; } diff --git a/src/ssb.js.c b/src/ssb.js.c index 5c98cf7a..b91d8d08 100644 --- a/src/ssb.js.c +++ b/src/ssb.js.c @@ -118,9 +118,9 @@ static JSValue _tf_ssb_appendMessageWithIdentity(JSContext* context, JSValueCons uint8_t private_key[crypto_sign_SECRETKEYBYTES]; if (tf_ssb_db_identity_get_private_key(ssb, user, id, private_key, sizeof(private_key))) { - char id[k_id_base64_len] = { 0 }; - tf_ssb_append_message_with_keys(ssb, id, private_key, argv[2], id, sizeof(id)); - result = JS_NewString(context, id); + char message_id[k_id_base64_len] = { 0 }; + tf_ssb_append_message_with_keys(ssb, id, private_key, argv[2], message_id, sizeof(message_id)); + result = JS_NewString(context, message_id); } else {