mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-29 23:54:08 +00:00
fix various bugs preventing obfuscated sender / conversation list
bundle from working.
This commit is contained in:
parent
2431f64125
commit
1c0837f8cd
137
meshms.c
137
meshms.c
@ -107,60 +107,60 @@ rhizome_manifest *meshms_find_or_create_manifestid
|
|||||||
// meshms add message <sender SID> <recipient SID> <sender DID> <recipient DID> <message text>
|
// meshms add message <sender SID> <recipient SID> <sender DID> <recipient DID> <message text>
|
||||||
int app_meshms_add_message(const struct cli_parsed *parsed, void *context)
|
int app_meshms_add_message(const struct cli_parsed *parsed, void *context)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (create_serval_instance_dir() == -1)
|
if (create_serval_instance_dir() == -1)
|
||||||
return -1;
|
return -1;
|
||||||
if (!(keyring = keyring_open_instance_cli(parsed)))
|
if (!(keyring = keyring_open_instance_cli(parsed)))
|
||||||
return -1;
|
return -1;
|
||||||
if (rhizome_opendb() == -1)
|
if (rhizome_opendb() == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (config.debug.verbose)
|
if (config.debug.verbose)
|
||||||
DEBUG_cli_parsed(parsed);
|
DEBUG_cli_parsed(parsed);
|
||||||
//sender_sid = author_sid
|
//sender_sid = author_sid
|
||||||
const char *sender_did, *recipient_did, *payload, *sender_sid, *recipient_sid;
|
const char *sender_did, *recipient_did, *payload, *sender_sid, *recipient_sid;
|
||||||
|
|
||||||
// Parse mandatory arguments
|
// Parse mandatory arguments
|
||||||
cli_arg(parsed, "sender_sid", &sender_sid, cli_optional_sid, "");
|
cli_arg(parsed, "sender_sid", &sender_sid, cli_optional_sid, "");
|
||||||
cli_arg(parsed, "recipient_sid", &recipient_sid, cli_optional_sid, "");
|
cli_arg(parsed, "recipient_sid", &recipient_sid, cli_optional_sid, "");
|
||||||
cli_arg(parsed, "sender_did", &sender_did, cli_optional_did, "");
|
cli_arg(parsed, "sender_did", &sender_did, cli_optional_did, "");
|
||||||
cli_arg(parsed, "recipient_did", &recipient_did, cli_optional_did, "");
|
cli_arg(parsed, "recipient_did", &recipient_did, cli_optional_did, "");
|
||||||
cli_arg(parsed, "payload", &payload, NULL, "");
|
cli_arg(parsed, "payload", &payload, NULL, "");
|
||||||
// Sanity check passed arguments
|
// Sanity check passed arguments
|
||||||
if ( (strcmp(sender_did,"") == 0) || (strcmp(recipient_did,"") == 0) || (strcmp(sender_sid,"") == 0) || (strcmp(recipient_sid,"" ) == 0) )
|
if ( (strcmp(sender_did,"") == 0) || (strcmp(recipient_did,"") == 0) || (strcmp(sender_sid,"") == 0) || (strcmp(recipient_sid,"" ) == 0) )
|
||||||
{
|
{
|
||||||
cli_puts("One or more missing arguments"); cli_delim("\n");
|
cli_puts("One or more missing arguments"); cli_delim("\n");
|
||||||
}
|
}
|
||||||
sid_t aSid;
|
sid_t aSid;
|
||||||
if (sender_sid[0] && str_to_sid_t(&aSid, sender_sid) == -1)
|
if (sender_sid[0] && str_to_sid_t(&aSid, sender_sid) == -1)
|
||||||
return WHYF("invalid sender_sid: %s", sender_sid);
|
return WHYF("invalid sender_sid: %s", sender_sid);
|
||||||
if (recipient_sid[0] && str_to_sid_t(&aSid, recipient_sid) == -1)
|
if (recipient_sid[0] && str_to_sid_t(&aSid, recipient_sid) == -1)
|
||||||
return WHYF("invalid recipient_sid: %s", recipient_sid);
|
return WHYF("invalid recipient_sid: %s", recipient_sid);
|
||||||
|
|
||||||
// Create serialised meshms message for appending to the conversation ply
|
// Create serialised meshms message for appending to the conversation ply
|
||||||
unsigned int length_int = 1;
|
unsigned int length_int = 1;
|
||||||
int offset_buf=0;
|
int offset_buf=0;
|
||||||
unsigned long long send_date_ll=gettime_ms();
|
unsigned long long send_date_ll=gettime_ms();
|
||||||
unsigned char *buffer_serialize;
|
unsigned char *buffer_serialize;
|
||||||
buffer_serialize=malloc(strlen(payload)+100); // make sure we have plenty of space
|
buffer_serialize=malloc(strlen(payload)+100); // make sure we have plenty of space
|
||||||
|
|
||||||
// encode twice: first to work out the final length, then once more to write it correctly
|
// encode twice: first to work out the final length, then once more to write it correctly
|
||||||
ret = serialize_meshms(buffer_serialize,&offset_buf,length_int,sender_did, recipient_did, send_date_ll, payload, strlen(payload)+1);
|
ret = serialize_meshms(buffer_serialize,&offset_buf,length_int,sender_did, recipient_did, send_date_ll, payload, strlen(payload)+1);
|
||||||
while(length_int!=offset_buf) {
|
while(length_int!=offset_buf) {
|
||||||
length_int=offset_buf;
|
length_int=offset_buf;
|
||||||
offset_buf=0;
|
offset_buf=0;
|
||||||
ret = serialize_meshms(buffer_serialize,&offset_buf,length_int,sender_did, recipient_did, send_date_ll, payload, strlen(payload)+1);
|
ret = serialize_meshms(buffer_serialize,&offset_buf,length_int,sender_did, recipient_did, send_date_ll, payload, strlen(payload)+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret=meshms_append_messageblock(sender_sid,recipient_sid,
|
ret=meshms_append_messageblock(sender_sid,recipient_sid,
|
||||||
buffer_serialize,length_int);
|
buffer_serialize,length_int);
|
||||||
free(buffer_serialize);
|
free(buffer_serialize);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int meshms_remember_conversation(const char *sender_sid_hex,
|
int meshms_remember_conversation(const char *sender_sid_hex,
|
||||||
rhizome_manifest *m)
|
rhizome_manifest *m)
|
||||||
{
|
{
|
||||||
// Check if the BID:recipient pair exists in the meshms conversation log
|
// Check if the BID:recipient pair exists in the meshms conversation log
|
||||||
// bundle.
|
// bundle.
|
||||||
@ -232,7 +232,7 @@ int meshms_remember_conversation(const char *sender_sid_hex,
|
|||||||
rhizome_manifest_free(l);
|
rhizome_manifest_free(l);
|
||||||
return WHYF("malloc(%d) failed when reading existing conversation index.",
|
return WHYF("malloc(%d) failed when reading existing conversation index.",
|
||||||
l->fileLength);
|
l->fileLength);
|
||||||
}
|
}
|
||||||
if (l->fileLength) {
|
if (l->fileLength) {
|
||||||
int ret = meshms_read_message(l,buffer_file);
|
int ret = meshms_read_message(l,buffer_file);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
@ -304,10 +304,10 @@ int meshms_append_messageblock(const char *sender_sid_hex,
|
|||||||
const unsigned char *buffer_serialize,
|
const unsigned char *buffer_serialize,
|
||||||
int length_int)
|
int length_int)
|
||||||
{
|
{
|
||||||
// Find the manifest (or create it if it doesn't yet exist)
|
// Find the manifest (or create it if it doesn't yet exist)
|
||||||
rhizome_manifest *m=meshms_find_or_create_manifestid(sender_sid_hex,
|
rhizome_manifest *m=meshms_find_or_create_manifestid(sender_sid_hex,
|
||||||
recipient_sid_hex,1);
|
recipient_sid_hex,1);
|
||||||
if (!m) return -1;
|
if (!m) return WHYF("Could not read manifest");
|
||||||
|
|
||||||
// Read the bundle file containing the meshms messages
|
// Read the bundle file containing the meshms messages
|
||||||
// (and keep enough space to append the new message
|
// (and keep enough space to append the new message
|
||||||
@ -339,7 +339,7 @@ int meshms_append_messageblock(const char *sender_sid_hex,
|
|||||||
free(buffer_file);
|
free(buffer_file);
|
||||||
|
|
||||||
rhizome_manifest *mout = NULL;
|
rhizome_manifest *mout = NULL;
|
||||||
ret=rhizome_manifest_finalise(m,&mout);
|
ret|=rhizome_manifest_finalise(m,&mout);
|
||||||
if (ret<0){
|
if (ret<0){
|
||||||
cli_printf("Error in manifest finalise");
|
cli_printf("Error in manifest finalise");
|
||||||
rhizome_manifest_free(m);
|
rhizome_manifest_free(m);
|
||||||
@ -347,46 +347,11 @@ int meshms_append_messageblock(const char *sender_sid_hex,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
char bid[RHIZOME_MANIFEST_ID_STRLEN + 1];
|
|
||||||
rhizome_bytes_to_hex_upper(mout->cryptoSignPublic, bid, RHIZOME_MANIFEST_ID_BYTES);
|
|
||||||
cli_puts("manifestid");
|
|
||||||
cli_delim(":");
|
|
||||||
cli_puts(bid);
|
|
||||||
cli_delim("\n");
|
|
||||||
}
|
|
||||||
{
|
|
||||||
char secret[RHIZOME_BUNDLE_KEY_STRLEN + 1];
|
|
||||||
rhizome_bytes_to_hex_upper(mout->cryptoSignSecret, secret, RHIZOME_BUNDLE_KEY_BYTES);
|
|
||||||
cli_puts("secret");
|
|
||||||
cli_delim(":");
|
|
||||||
cli_puts(secret);
|
|
||||||
cli_delim("\n");
|
|
||||||
}
|
|
||||||
cli_puts("version"); cli_delim(":"); cli_printf("%lld", m->version); cli_delim("\n");
|
|
||||||
cli_puts("filesize");
|
|
||||||
cli_delim(":");
|
|
||||||
cli_printf("%lld", mout->fileLength);
|
|
||||||
cli_delim("\n");
|
|
||||||
if (mout->fileLength != 0) {
|
|
||||||
cli_puts("filehash");
|
|
||||||
cli_delim(":");
|
|
||||||
cli_puts(mout->fileHexHash);
|
|
||||||
cli_delim("\n");
|
|
||||||
}
|
|
||||||
const char *name_manifest = rhizome_manifest_get(mout, "name", NULL, 0);
|
|
||||||
if (name_manifest) {
|
|
||||||
cli_puts("name");
|
|
||||||
cli_delim(":");
|
|
||||||
cli_puts(name_manifest);
|
|
||||||
cli_delim("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mout != m)
|
if (mout != m)
|
||||||
rhizome_manifest_free(mout);
|
rhizome_manifest_free(mout);
|
||||||
rhizome_manifest_free(m);
|
rhizome_manifest_free(m);
|
||||||
|
|
||||||
return ret ;
|
return ret ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int app_meshms_list_messages(const struct cli_parsed *parsed, void *context)
|
int app_meshms_list_messages(const struct cli_parsed *parsed, void *context)
|
||||||
|
@ -200,6 +200,8 @@ int rhizome_find_secret(const unsigned char *authorSid, int *rs_len, const unsig
|
|||||||
int rhizome_extract_privatekey(rhizome_manifest *m, rhizome_bk_t *bsk)
|
int rhizome_extract_privatekey(rhizome_manifest *m, rhizome_bk_t *bsk)
|
||||||
{
|
{
|
||||||
IN();
|
IN();
|
||||||
|
if (m->haveSecret) RETURN(0);
|
||||||
|
|
||||||
unsigned char bkBytes[RHIZOME_BUNDLE_KEY_BYTES];
|
unsigned char bkBytes[RHIZOME_BUNDLE_KEY_BYTES];
|
||||||
char *bk = rhizome_manifest_get(m, "BK", NULL, 0);
|
char *bk = rhizome_manifest_get(m, "BK", NULL, 0);
|
||||||
int result;
|
int result;
|
||||||
@ -723,6 +725,9 @@ int rhizome_obfuscated_manifest_generate_outgoing_bid
|
|||||||
crypto_sign_edwards25519sha512batch_SECRETKEYBYTES);
|
crypto_sign_edwards25519sha512batch_SECRETKEYBYTES);
|
||||||
if (crypto_sign_compute_public_key(m->cryptoSignSecret,m->cryptoSignPublic))
|
if (crypto_sign_compute_public_key(m->cryptoSignSecret,m->cryptoSignPublic))
|
||||||
return WHY("Could not compute BID");
|
return WHY("Could not compute BID");
|
||||||
|
m->haveSecret=1;
|
||||||
|
|
||||||
|
rhizome_manifest_set(m,"id",alloca_tohex_bid(m->cryptoSignPublic));
|
||||||
|
|
||||||
// Clear out sensitive data
|
// Clear out sensitive data
|
||||||
bzero(secret,1024);
|
bzero(secret,1024);
|
||||||
|
@ -1229,17 +1229,20 @@ int rhizome_meshms_find_conversation(const char *sender_sid_hex,
|
|||||||
if(keyring_find_sid(keyring,&cn,&in,&kp,authorSid.binary))
|
if(keyring_find_sid(keyring,&cn,&in,&kp,authorSid.binary))
|
||||||
{
|
{
|
||||||
// We are the sender, so the BID is precisely determined
|
// We are the sender, so the BID is precisely determined
|
||||||
rhizome_manifest m;
|
rhizome_manifest *m=rhizome_new_manifest();
|
||||||
sid_t rxSid;
|
if (m) {
|
||||||
if (str_to_sid_t(&rxSid, recipient_sid_hex)==-1)
|
sid_t rxSid;
|
||||||
RETURN(WHYF("invalid recipient_sid: '%s'", recipient_sid_hex));
|
if (str_to_sid_t(&rxSid, recipient_sid_hex)==-1)
|
||||||
if (!rhizome_obfuscated_manifest_generate_outgoing_bid
|
RETURN(WHYF("invalid recipient_sid: '%s'", recipient_sid_hex));
|
||||||
(&m,authorSid.binary,recipient_sid_hex))
|
if (!rhizome_obfuscated_manifest_generate_outgoing_bid
|
||||||
{
|
(m,authorSid.binary,recipient_sid_hex))
|
||||||
tohex(manifest_id_hex,m.cryptoSignPublic,
|
{
|
||||||
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES);
|
tohex(manifest_id_hex,m->cryptoSignPublic,
|
||||||
RETURN(0);
|
crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES);
|
||||||
}
|
rhizome_manifest_free(m);
|
||||||
|
RETURN(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf b = strbuf_alloca(1024);
|
strbuf b = strbuf_alloca(1024);
|
||||||
|
@ -30,12 +30,6 @@ setup() {
|
|||||||
setup_rhizome
|
setup_rhizome
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_createPly() {
|
|
||||||
set_instance +A
|
|
||||||
create_identities 2
|
|
||||||
assert [ $SIDA1 != $SIDA2 ]
|
|
||||||
}
|
|
||||||
|
|
||||||
doc_createPly="Create thread ply by sending a message"
|
doc_createPly="Create thread ply by sending a message"
|
||||||
setup_createPly() {
|
setup_createPly() {
|
||||||
setup
|
setup
|
||||||
@ -52,8 +46,10 @@ setup_discriminatePlys() {
|
|||||||
}
|
}
|
||||||
test_discriminatePlys() {
|
test_discriminatePlys() {
|
||||||
executeOk_servald meshms add message 12345 67890 $SIDA1 $SIDA2 "Message-1"
|
executeOk_servald meshms add message 12345 67890 $SIDA1 $SIDA2 "Message-1"
|
||||||
|
tfw_cat --stderr --stdout
|
||||||
executeOk_servald rhizome list
|
executeOk_servald rhizome list
|
||||||
assert_rhizome_list --fromhere=1 --author=$SIDA1 '' --and-others
|
assert_rhizome_list --fromhere=1 --author=$SIDA1 '' --and-others
|
||||||
|
tfw_cat --stderr --stdout
|
||||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||||
assertStdoutGrep --stdout --stderr --matches=0 '^0:.*:received:meshms:Message-1'
|
assertStdoutGrep --stdout --stderr --matches=0 '^0:.*:received:meshms:Message-1'
|
||||||
assertStdoutGrep --stdout --stderr --matches=1 '^0:.*:unacknowledged:meshms:Message-1'
|
assertStdoutGrep --stdout --stderr --matches=1 '^0:.*:unacknowledged:meshms:Message-1'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user