From 5c40edb55de5b3b52c36db05bb12893600e8d7d9 Mon Sep 17 00:00:00 2001 From: gardners Date: Sat, 26 May 2012 11:55:56 +0930 Subject: [PATCH] Fixed bugs with importing files using user-supplied manifest (was not decoding BKs) --- commandline.c | 19 ++++++++++++++++--- rhizome_bundle.c | 6 ++++++ rhizome_crypto.c | 6 ++++-- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/commandline.c b/commandline.c index c79c48ff..93d2fa62 100644 --- a/commandline.c +++ b/commandline.c @@ -1196,14 +1196,27 @@ int app_rhizome_add_file(int argc, const char *const *argv, struct command_line_ Then finalise the manifest. But if the manifest already contains an ID, don't override it. */ - if (rhizome_manifest_get(m, "id", NULL, 0)==NULL) - if (rhizome_manifest_bind_id(m,authorSid)) + if (rhizome_manifest_get(m, "id", NULL, 0)==NULL) { + if (rhizome_manifest_bind_id(m,authorSid)) { + rhizome_manifest_free(m); m=NULL; return WHY("Could not bind manifest to an ID"); + } + } else { + /* User supplied manifest has a BID, so see if we can extract the + private key from a BK entry */ + if (rhizome_extract_privatekey(m,authorSid)) + { + rhizome_manifest_free(m); m=NULL; + return WHY("Could not extract BID secret key. Does the manifest have a BK, did you supply the correct author SID?"); + } + } #warning need to sanely determine whether to encrypt a file #warning payload encryption disabled for now int encryptP=0; - if (rhizome_manifest_bind_file(m,filepath,encryptP)) + if (rhizome_manifest_bind_file(m,filepath,encryptP)) { + rhizome_manifest_free(m); return WHYF("Could not bind manifest to file '%s'",filepath); + } /* Add the manifest and its associated file to the Rhizome database, generating an "id" in the * process */ diff --git a/rhizome_bundle.c b/rhizome_bundle.c index fcc1ca8e..dc76b65e 100644 --- a/rhizome_bundle.c +++ b/rhizome_bundle.c @@ -148,6 +148,12 @@ int rhizome_read_manifest_file(rhizome_manifest *m, const char *filename, int bu */ m->vars[m->var_count]=strdup(var); m->values[m->var_count]=strdup(value); + if (!strcasecmp(var,"ID")) + { + /* Parse hex string of ID into public key */ + rhizome_hex_to_bytes(value,m->cryptoSignPublic, + crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES*2); + } m->var_count++; } } else { diff --git a/rhizome_crypto.c b/rhizome_crypto.c index fdd8d7c6..3cb47244 100644 --- a/rhizome_crypto.c +++ b/rhizome_crypto.c @@ -170,7 +170,7 @@ int rhizome_extract_privatekey(rhizome_manifest *m,const char *authorHex) ge25519_pack(pk, &gepk); bzero(&scsk,sizeof(scsk)); if (memcmp(pk, m->cryptoSignPublic, crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES)) { - if (0) { + if (1) { char hex[17]; rhizome_bytes_to_hex_upper(m->cryptoSignPublic, hex, 8); WHYF(" stored public key = %s*", hex); @@ -178,8 +178,10 @@ int rhizome_extract_privatekey(rhizome_manifest *m,const char *authorHex) WHYF("computed public key = %s*", hex); } return WHY("BID secret key decoded from BK was not valid"); - } else + } else { + m->haveSecret=1; return 0; + } #else //!ge25519 /* XXX Need to test key by signing and testing signature validity. */ /* For the time being barf so that the caller does not think we have a validated BK