From eff3e9ec8fd45bdae1d5ec60f85ad25267a0f242 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Mon, 15 Oct 2012 14:01:48 +1030 Subject: [PATCH] Issue #17, fix new 'rhizomeops' test Was incorrectly supplying bundle secret to "rhizome add" command. --- commandline.c | 10 +++++++--- rhizome_crypto.c | 8 +++++--- tests/rhizomeops | 2 +- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/commandline.c b/commandline.c index c6f4cba4..80988724 100644 --- a/commandline.c +++ b/commandline.c @@ -1035,16 +1035,18 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_ /* Bind an ID to the manifest, and also bind the file. Then finalise the manifest. But if the manifest already contains an ID, don't override it. */ if (authorSidHex[0]) { - if (debug & DEBUG_RHIZOME) - DEBUGF("author=%s", authorSidHex); + if (debug & DEBUG_RHIZOME) DEBUGF("author=%s", authorSidHex); memcpy(m->author, authorSid, SID_SIZE); } - if (rhizome_manifest_get(m, "id", NULL, 0) == NULL) { + const char *id = rhizome_manifest_get(m, "id", NULL, 0); + if (id == NULL) { + if (debug & DEBUG_RHIZOME) DEBUG("creating new bundle"); if (rhizome_manifest_bind_id(m) == -1) { rhizome_manifest_free(m); return WHY("Could not bind manifest to an ID"); } } else { + if (debug & DEBUG_RHIZOME) DEBUGF("modifying existing bundle bid=%s", id); // Modifying an existing bundle. If an author SID is supplied, we must ensure that it is valid, // ie, that identity has permission to alter the bundle. If no author SID is supplied but a BSK // is supplied, then use that to alter the bundle. Otherwise, search the keyring for an @@ -1079,6 +1081,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_ } } if (bskhex[0]) { + if (debug & DEBUG_RHIZOME) DEBUGF("bskhex=%s", bskhex); if (m->haveSecret) { // If a bundle secret key was supplied that does not match the secret key derived from the // author, then warn but carry on using the author's. @@ -1096,6 +1099,7 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_ } // If we still don't know the bundle secret or the author, then search for an author. if (!m->haveSecret && is_sid_any(m->author)) { + if (debug & DEBUG_RHIZOME) DEBUG("bundle author not specified, searching keyring"); int result = rhizome_find_bundle_author(m); if (result != 0) { rhizome_manifest_free(m); diff --git a/rhizome_crypto.c b/rhizome_crypto.c index bd600185..a40d33dd 100644 --- a/rhizome_crypto.c +++ b/rhizome_crypto.c @@ -137,8 +137,10 @@ int rhizome_extract_privatekey(rhizome_manifest *m) { IN(); char *bk = rhizome_manifest_get(m, "BK", NULL, 0); - if (!bk) + if (!bk) { + if (debug & DEBUG_RHIZOME) DEBUG("bundle contains no BK field"); RETURN(1); + } unsigned char bkBytes[RHIZOME_BUNDLE_KEY_BYTES]; if (fromhexstr(bkBytes, bk, RHIZOME_BUNDLE_KEY_BYTES) == -1) RETURN(WHYF("invalid BK field: %s", bk)); @@ -150,12 +152,12 @@ int rhizome_extract_privatekey(rhizome_manifest *m) if (verified == -1) result = WHY("rhizome_bk_xor() failed"); else { - if (debug & DEBUG_RHIZOME) - DEBUGF("identity sid=%s is not the author of bundle with BK=%s", alloca_tohex_sid(m->author), bk); + if (debug & DEBUG_RHIZOME) DEBUGF("identity sid=%s is not the author of bundle with BK=%s", alloca_tohex_sid(m->author), bk); result = 3; } } memset(m->cryptoSignSecret, 0, sizeof m->cryptoSignSecret); + if (debug & DEBUG_RHIZOME) DEBUGF("result=%d", result); RETURN(result); } diff --git a/tests/rhizomeops b/tests/rhizomeops index a1aa050f..429c2b10 100755 --- a/tests/rhizomeops +++ b/tests/rhizomeops @@ -372,7 +372,7 @@ setup_AddUpdateDiscoverAuthor() { } test_AddUpdateDiscoverAuthor() { tfw_cat -v file1_2.manifest - executeOk_servald rhizome add file '' '' file1_2 file1_2.manifest "$file1_secret" + executeOk_servald rhizome add file '' '' file1_2 file1_2.manifest tfw_cat --stderr # Rhizome store contents have new payload. executeOk_servald rhizome list ''