2012-01-12 03:38:24 +00:00
|
|
|
/*
|
2014-11-19 13:31:12 +00:00
|
|
|
Serval DNA - Rhizome manifest operations
|
2012-01-12 03:38:24 +00:00
|
|
|
Copyright (C) 2010 Paul Gardner-Stephen
|
2014-11-19 13:31:12 +00:00
|
|
|
Copyright (C) 2013-2014 Serval Project Inc.
|
2012-01-12 03:38:24 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2012-09-25 04:01:34 +00:00
|
|
|
#include <stdlib.h>
|
2013-09-30 07:12:25 +00:00
|
|
|
#include <assert.h>
|
2013-10-11 17:24:18 +00:00
|
|
|
#include <sys/uio.h>
|
2017-09-11 03:13:38 +00:00
|
|
|
#include "lang.h" // for FALLTHROUGH
|
2012-02-23 02:15:42 +00:00
|
|
|
#include "serval.h"
|
2012-12-11 05:29:46 +00:00
|
|
|
#include "conf.h"
|
2016-10-16 00:14:36 +00:00
|
|
|
#include "crypto.h"
|
2012-01-12 03:38:24 +00:00
|
|
|
#include "rhizome.h"
|
2016-09-20 04:03:19 +00:00
|
|
|
#include "str.h"
|
2016-09-20 02:45:26 +00:00
|
|
|
#include "numeric_str.h"
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
#include "mem.h"
|
2013-10-16 03:00:00 +00:00
|
|
|
#include "keyring.h"
|
2013-11-25 02:39:54 +00:00
|
|
|
#include "dataformats.h"
|
2017-11-24 00:03:39 +00:00
|
|
|
#include "debug.h"
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
|
|
|
static const char *rhizome_manifest_get(const rhizome_manifest *m, const char *var)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < m->var_count; ++i)
|
|
|
|
if (strcmp(m->vars[i], var) == 0)
|
|
|
|
return m->values[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-11-17 13:11:03 +00:00
|
|
|
/* Remove the field with the given label from the manifest
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
*/
|
|
|
|
static int _rhizome_manifest_del(struct __sourceloc __whence, rhizome_manifest *m, const char *var)
|
|
|
|
{
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "DEL manifest %p %s", m, var);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
int ret = 0;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < m->var_count; ++i)
|
|
|
|
if (strcmp(m->vars[i], var) == 0) {
|
|
|
|
free((char *) m->vars[i]);
|
|
|
|
free((char *) m->values[i]);
|
|
|
|
--m->var_count;
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (; i < m->var_count; ++i) {
|
|
|
|
m->vars[i] = m->vars[i + 1];
|
|
|
|
m->values[i] = m->values[i + 1];
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define rhizome_manifest_set(m,var,value) _rhizome_manifest_set(__WHENCE__, (m), (var), (value))
|
2013-12-11 00:41:34 +00:00
|
|
|
#define rhizome_manifest_set_ui64(m,var,value) _rhizome_manifest_set_ui64(__WHENCE__, (m), (var), (value))
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
#define rhizome_manifest_del(m,var) _rhizome_manifest_del(__WHENCE__, (m), (var))
|
|
|
|
|
|
|
|
static const char *_rhizome_manifest_set(struct __sourceloc __whence, rhizome_manifest *m, const char *var, const char *value)
|
|
|
|
{
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "SET manifest %p %s = %s", m, var, alloca_str_toprint(value));
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
unsigned i;
|
|
|
|
for(i=0;i<m->var_count;i++)
|
|
|
|
if (strcmp(m->vars[i],var) == 0) {
|
|
|
|
const char *ret = str_edup(value);
|
|
|
|
if (ret == NULL)
|
|
|
|
return NULL;
|
|
|
|
free((char *)m->values[i]);
|
|
|
|
m->values[i] = ret;
|
|
|
|
return ret;
|
|
|
|
}
|
2015-10-26 05:25:41 +00:00
|
|
|
if (m->var_count >= NELS(m->vars)) {
|
|
|
|
WHY("no more manifest vars");
|
|
|
|
return NULL;
|
|
|
|
}
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if ((m->vars[m->var_count] = str_edup(var)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
const char *ret = m->values[m->var_count] = str_edup(value);
|
|
|
|
if (ret == NULL) {
|
|
|
|
free((char *)m->vars[i]);
|
|
|
|
m->vars[i] = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
m->var_count++;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-11 00:41:34 +00:00
|
|
|
static const char *_rhizome_manifest_set_ui64(struct __sourceloc __whence, rhizome_manifest *m, char *var, uint64_t value)
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
{
|
|
|
|
char str[50];
|
2013-12-11 00:41:34 +00:00
|
|
|
snprintf(str, sizeof str, "%" PRIu64, value);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
return rhizome_manifest_set(m, var, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_set_id(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_bid_t *bidp)
|
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
if (bidp) {
|
2016-09-27 00:58:46 +00:00
|
|
|
if (m->has_id && (bidp == &m->keypair.public_key || cmp_rhizome_bid_t(&m->keypair.public_key, bidp) == 0))
|
2014-11-18 08:12:43 +00:00
|
|
|
return; // unchanged
|
|
|
|
const char *v = rhizome_manifest_set(m, "id", alloca_tohex_rhizome_bid_t(*bidp));
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
2016-09-27 00:58:46 +00:00
|
|
|
m->keypair.public_key = *bidp;
|
2014-11-18 08:12:43 +00:00
|
|
|
m->has_id = 1;
|
|
|
|
} else if (m->has_id) {
|
2016-09-27 00:58:46 +00:00
|
|
|
bzero(&m->keypair.public_key, sizeof m->keypair.public_key); // not strictly necessary but aids debugging
|
2014-11-18 08:12:43 +00:00
|
|
|
m->has_id = 0;
|
|
|
|
} else
|
|
|
|
return; // unchanged
|
|
|
|
// The BID has changed.
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2014-11-18 08:12:43 +00:00
|
|
|
// Any existing secret key and bundle key are no longer valid.
|
|
|
|
if (m->haveSecret) {
|
|
|
|
m->haveSecret = SECRET_UNKNOWN;
|
2016-09-27 00:58:46 +00:00
|
|
|
bzero(m->keypair.private_key.binary, sizeof m->keypair.private_key.binary); // not strictly necessary but aids debugging
|
2014-11-18 08:12:43 +00:00
|
|
|
}
|
|
|
|
if (m->has_bundle_key) {
|
|
|
|
m->has_bundle_key = 0;
|
|
|
|
m->bundle_key = RHIZOME_BK_NONE; // not strictly necessary but aids debugging
|
|
|
|
}
|
|
|
|
// Any authenticated author is no longer authenticated, but is still known to be in the keyring.
|
|
|
|
if (m->authorship == AUTHOR_AUTHENTIC)
|
|
|
|
m->authorship = AUTHOR_LOCAL;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-11 00:41:34 +00:00
|
|
|
void _rhizome_manifest_set_version(struct __sourceloc __whence, rhizome_manifest *m, uint64_t version)
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
if (version) {
|
|
|
|
const char *v = rhizome_manifest_set_ui64(m, "version", version);
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
} else
|
|
|
|
rhizome_manifest_del(m, "version");
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
m->version = version;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 16:51:27 +00:00
|
|
|
void _rhizome_manifest_del_version(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
_rhizome_manifest_set_version(__whence, m, 0);
|
|
|
|
}
|
|
|
|
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
void _rhizome_manifest_set_filesize(struct __sourceloc __whence, rhizome_manifest *m, uint64_t size)
|
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
if (size == RHIZOME_SIZE_UNSET) {
|
|
|
|
rhizome_manifest_del(m, "filesize");
|
|
|
|
} else {
|
|
|
|
const char *v = rhizome_manifest_set_ui64(m, "filesize", size);
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
}
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
m->filesize = size;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 16:51:27 +00:00
|
|
|
void _rhizome_manifest_del_filesize(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
_rhizome_manifest_set_filesize(__whence, m, RHIZOME_SIZE_UNSET);
|
|
|
|
}
|
|
|
|
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
/* Must always set file size before setting the file hash, to avoid assertion failures.
|
|
|
|
*/
|
|
|
|
void _rhizome_manifest_set_filehash(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_filehash_t *hash)
|
|
|
|
{
|
|
|
|
if (hash) {
|
|
|
|
const char *v = rhizome_manifest_set(m, "filehash", alloca_tohex_rhizome_filehash_t(*hash));
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->filehash = *hash;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->has_filehash = 1;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
} else {
|
|
|
|
rhizome_manifest_del(m, "filehash");
|
|
|
|
m->filehash = RHIZOME_FILEHASH_NONE;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->has_filehash = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 16:51:27 +00:00
|
|
|
void _rhizome_manifest_del_filehash(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
_rhizome_manifest_set_filehash(__whence, m, NULL);
|
|
|
|
}
|
|
|
|
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
void _rhizome_manifest_set_tail(struct __sourceloc __whence, rhizome_manifest *m, uint64_t tail)
|
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
if (tail == RHIZOME_SIZE_UNSET) {
|
|
|
|
rhizome_manifest_del(m, "tail");
|
|
|
|
m->is_journal = 0;
|
|
|
|
} else {
|
|
|
|
const char *v = rhizome_manifest_set_ui64(m, "tail", tail);
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->is_journal = 1;
|
|
|
|
}
|
2015-03-18 16:51:27 +00:00
|
|
|
m->tail = tail;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_set_bundle_key(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_bk_t *bkp)
|
|
|
|
{
|
|
|
|
if (bkp) {
|
|
|
|
const char *v = rhizome_manifest_set(m, "BK", alloca_tohex_rhizome_bk_t(*bkp));
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->bundle_key = *bkp;
|
|
|
|
m->has_bundle_key = 1;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
_rhizome_manifest_del_bundle_key(__whence, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_del_bundle_key(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->has_bundle_key) {
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
rhizome_manifest_del(m, "BK");
|
|
|
|
m->has_bundle_key = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
m->bundle_key = RHIZOME_BK_NONE; // not strictly necessary, but aids debugging
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
assert(rhizome_manifest_get(m, "BK") == NULL);
|
|
|
|
// Once there is no BK field, any authenticated authorship is no longer.
|
|
|
|
if (m->authorship == AUTHOR_AUTHENTIC)
|
|
|
|
m->authorship = AUTHOR_LOCAL;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_set_service(struct __sourceloc __whence, rhizome_manifest *m, const char *service)
|
|
|
|
{
|
|
|
|
if (service) {
|
2013-12-02 00:42:31 +00:00
|
|
|
assert(rhizome_str_is_manifest_service(service));
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
const char *v = rhizome_manifest_set(m, "service", service);
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->service = v;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
_rhizome_manifest_del_service(__whence, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_del_service(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->service) {
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
m->service = NULL;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
rhizome_manifest_del(m, "service");
|
|
|
|
} else
|
|
|
|
assert(rhizome_manifest_get(m, "service") == NULL);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_set_name(struct __sourceloc __whence, rhizome_manifest *m, const char *name)
|
|
|
|
{
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if (name) {
|
2013-12-02 00:42:31 +00:00
|
|
|
assert(rhizome_str_is_manifest_name(name));
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
const char *v = rhizome_manifest_set(m, "name", name);
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->name = v;
|
|
|
|
} else {
|
|
|
|
rhizome_manifest_del(m, "name");
|
|
|
|
m->name = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 07:28:03 +00:00
|
|
|
void _rhizome_manifest_del_name(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->name) {
|
|
|
|
m->name = NULL;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
rhizome_manifest_del(m, "name");
|
|
|
|
} else
|
|
|
|
assert(rhizome_manifest_get(m, "name") == NULL);
|
|
|
|
}
|
|
|
|
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
void _rhizome_manifest_set_date(struct __sourceloc __whence, rhizome_manifest *m, time_ms_t date)
|
|
|
|
{
|
2013-12-11 00:41:34 +00:00
|
|
|
const char *v = rhizome_manifest_set_ui64(m, "date", (uint64_t)date);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->date = date;
|
|
|
|
m->has_date = 1;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2014-11-18 08:12:43 +00:00
|
|
|
void _rhizome_manifest_del_date(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->has_date) {
|
|
|
|
m->has_date = 0;
|
|
|
|
m->finalised = 0;
|
|
|
|
rhizome_manifest_del(m, "date");
|
|
|
|
} else
|
|
|
|
assert(rhizome_manifest_get(m, "date") == NULL);
|
|
|
|
}
|
|
|
|
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
void _rhizome_manifest_set_sender(struct __sourceloc __whence, rhizome_manifest *m, const sid_t *sidp)
|
|
|
|
{
|
|
|
|
if (sidp) {
|
|
|
|
const char *v = rhizome_manifest_set(m, "sender", alloca_tohex_sid_t(*sidp));
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->sender = *sidp;
|
|
|
|
m->has_sender = 1;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
_rhizome_manifest_del_sender(__whence, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_del_sender(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->has_sender) {
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
rhizome_manifest_del(m, "sender");
|
|
|
|
m->sender = SID_ANY;
|
|
|
|
m->has_sender = 0;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
assert(rhizome_manifest_get(m, "sender") == NULL);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_set_recipient(struct __sourceloc __whence, rhizome_manifest *m, const sid_t *sidp)
|
|
|
|
{
|
|
|
|
if (sidp) {
|
|
|
|
const char *v = rhizome_manifest_set(m, "recipient", alloca_tohex_sid_t(*sidp));
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
m->recipient = *sidp;
|
|
|
|
m->has_recipient = 1;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
_rhizome_manifest_del_recipient(__whence, m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_del_recipient(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->has_recipient) {
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
rhizome_manifest_del(m, "recipient");
|
|
|
|
m->recipient = SID_ANY;
|
|
|
|
m->has_recipient = 0;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
2013-11-05 07:28:03 +00:00
|
|
|
} else
|
|
|
|
assert(rhizome_manifest_get(m, "recipient") == NULL);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_set_crypt(struct __sourceloc __whence, rhizome_manifest *m, enum rhizome_manifest_crypt flag)
|
|
|
|
{
|
|
|
|
switch (flag) {
|
|
|
|
case PAYLOAD_CRYPT_UNKNOWN:
|
|
|
|
rhizome_manifest_del(m, "crypt");
|
|
|
|
break;
|
|
|
|
case PAYLOAD_CLEAR: {
|
|
|
|
const char *v = rhizome_manifest_set(m, "crypt", "0");
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PAYLOAD_ENCRYPTED: {
|
|
|
|
const char *v = rhizome_manifest_set(m, "crypt", "1");
|
|
|
|
assert(v); // TODO: remove known manifest fields from vars[]
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: abort();
|
|
|
|
}
|
|
|
|
m->payloadEncryption = flag;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->finalised = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-11 07:43:38 +00:00
|
|
|
void _rhizome_manifest_set_rowid(struct __sourceloc __whence, rhizome_manifest *m, uint64_t rowid)
|
|
|
|
{
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "SET manifest %p rowid = %"PRIu64, m, rowid);
|
2013-11-11 07:43:38 +00:00
|
|
|
m->rowid = rowid;
|
|
|
|
}
|
|
|
|
|
2013-11-05 07:28:03 +00:00
|
|
|
void _rhizome_manifest_set_inserttime(struct __sourceloc __whence, rhizome_manifest *m, time_ms_t time)
|
|
|
|
{
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "SET manifest %p inserttime = %"PRItime_ms_t, m, time);
|
2013-11-05 07:28:03 +00:00
|
|
|
m->inserttime = time;
|
|
|
|
}
|
|
|
|
|
2016-05-31 03:20:32 +00:00
|
|
|
void _rhizome_manifest_set_author(struct __sourceloc __whence, rhizome_manifest *m, const keyring_identity *id, const sid_t *sidp)
|
|
|
|
{
|
|
|
|
if (id) {
|
|
|
|
if (m->author_identity == id)
|
|
|
|
return;
|
|
|
|
sidp = id->box_pk;
|
|
|
|
} else if (sidp) {
|
|
|
|
if (m->authorship != ANONYMOUS && cmp_sid_t(&m->author, sidp) == 0)
|
|
|
|
return;
|
|
|
|
} else {
|
2013-11-05 07:28:03 +00:00
|
|
|
_rhizome_manifest_del_author(__whence, m);
|
2016-05-31 03:20:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUGF(rhizome_manifest, "SET manifest %p author = %s", m, alloca_tohex_sid_t(*sidp));
|
|
|
|
m->author = *sidp;
|
|
|
|
m->author_identity = id;
|
|
|
|
m->authorship = AUTHOR_NOT_CHECKED;
|
2013-11-05 07:28:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _rhizome_manifest_del_author(struct __sourceloc __whence, rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
if (m->authorship != ANONYMOUS) {
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "DEL manifest %p author", m);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
m->author = SID_ANY;
|
2016-05-31 03:20:32 +00:00
|
|
|
m->author_identity = NULL;
|
2013-11-05 07:28:03 +00:00
|
|
|
m->authorship = ANONYMOUS;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-12 03:38:24 +00:00
|
|
|
|
2013-11-28 07:14:37 +00:00
|
|
|
/* Compute the hash of the manifest's body, including the NUL byte that separates the body from
|
|
|
|
* the signature block, and verify that a signature is present and is correct.
|
|
|
|
*
|
2013-12-19 08:43:39 +00:00
|
|
|
* If the manifest signature is valid, ie, the signature is a self-signature using the
|
|
|
|
* manifest's own private key, then sets the m->selfSigned flag and returns 1.
|
2013-11-28 07:14:37 +00:00
|
|
|
*
|
2013-12-19 08:43:39 +00:00
|
|
|
* If there are no signatures or if the signature block does not verify, then clears the
|
|
|
|
* m->selfSigned flag and returns 0.
|
2013-11-28 07:14:37 +00:00
|
|
|
*
|
2013-12-19 08:43:39 +00:00
|
|
|
* Only call this function on manifests for which rhizome_manifest_validate(m) has returned true
|
|
|
|
* (ie, m->finalised is set).
|
2013-11-28 07:14:37 +00:00
|
|
|
*/
|
2012-05-25 23:54:47 +00:00
|
|
|
int rhizome_manifest_verify(rhizome_manifest *m)
|
|
|
|
{
|
2013-12-19 08:43:39 +00:00
|
|
|
assert(m->finalised);
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(m->manifest_body_bytes > 0);
|
|
|
|
assert(m->manifest_all_bytes > 0);
|
|
|
|
assert(m->manifest_body_bytes <= m->manifest_all_bytes);
|
2014-04-29 05:38:02 +00:00
|
|
|
assert(m->sig_count == 0);
|
2013-11-28 07:14:37 +00:00
|
|
|
if (m->manifest_body_bytes == m->manifest_all_bytes)
|
|
|
|
assert(m->manifestdata[m->manifest_body_bytes - 1] == '\0');
|
|
|
|
// Hash the body
|
2016-03-07 04:04:53 +00:00
|
|
|
crypto_hash_sha512(m->manifesthash.binary, m->manifestdata, m->manifest_body_bytes);
|
2013-11-28 07:14:37 +00:00
|
|
|
// Read signature blocks
|
|
|
|
unsigned ofs = m->manifest_body_bytes;
|
|
|
|
while (ofs < m->manifest_all_bytes) {
|
|
|
|
if (rhizome_manifest_extract_signature(m, &ofs) == -1)
|
2013-10-30 03:15:51 +00:00
|
|
|
break;
|
2012-05-25 23:54:47 +00:00
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(ofs <= m->manifest_all_bytes);
|
|
|
|
// Make sure the first signatory's public key is the bundle ID
|
|
|
|
assert(m->has_id);
|
|
|
|
if (m->sig_count == 0) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUG(rhizome_manifest, "Manifest has no signature blocks, but should have self-signature block");
|
2013-11-28 07:14:37 +00:00
|
|
|
m->selfSigned = 0;
|
|
|
|
return 0;
|
2012-05-25 23:54:47 +00:00
|
|
|
}
|
2016-09-27 00:58:46 +00:00
|
|
|
if (memcmp(m->signatories[0], m->keypair.public_key.binary, sizeof m->keypair.public_key.binary) != 0) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Manifest id does not match first signature block (signature key is %s)",
|
2016-04-12 06:13:56 +00:00
|
|
|
alloca_tohex(m->signatories[0], crypto_sign_PUBLICKEYBYTES)
|
2015-07-06 08:19:49 +00:00
|
|
|
);
|
2013-11-28 07:14:37 +00:00
|
|
|
m->selfSigned = 0;
|
|
|
|
return 0;
|
2012-05-25 23:54:47 +00:00
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
m->selfSigned = 1;
|
|
|
|
return 1;
|
2012-05-25 23:54:47 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 07:14:37 +00:00
|
|
|
static void rhizome_manifest_clear(rhizome_manifest *m)
|
2013-08-01 02:07:35 +00:00
|
|
|
{
|
2013-11-28 07:14:37 +00:00
|
|
|
while (m->var_count) {
|
|
|
|
--m->var_count;
|
|
|
|
free((char *) m->vars[m->var_count]);
|
|
|
|
free((char *) m->values[m->var_count]);
|
|
|
|
m->vars[m->var_count] = m->values[m->var_count] = NULL;
|
|
|
|
}
|
|
|
|
while (m->sig_count) {
|
|
|
|
--m->sig_count;
|
|
|
|
free(m->signatories[m->sig_count]);
|
|
|
|
m->signatories[m->sig_count] = NULL;
|
|
|
|
}
|
2014-07-09 19:49:38 +00:00
|
|
|
m->malformed = NULL;
|
2013-11-28 07:14:37 +00:00
|
|
|
m->has_id = 0;
|
2013-12-19 08:43:39 +00:00
|
|
|
m->has_filehash = 0;
|
2013-11-28 07:14:37 +00:00
|
|
|
m->is_journal = 0;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
m->filesize = RHIZOME_SIZE_UNSET;
|
|
|
|
m->tail = RHIZOME_SIZE_UNSET;
|
2013-11-28 07:14:37 +00:00
|
|
|
m->version = 0;
|
|
|
|
// TODO initialise more fields
|
|
|
|
}
|
|
|
|
|
|
|
|
int rhizome_manifest_inspect(const char *buf, size_t len, struct rhizome_manifest_summary *summ)
|
|
|
|
{
|
|
|
|
const char *const end = buf + len;
|
|
|
|
int has_bid = 0;
|
|
|
|
int has_version = 0;
|
|
|
|
const char *begin = buf;
|
2014-11-19 02:47:40 +00:00
|
|
|
const char *eol = NULL;
|
2013-11-28 07:14:37 +00:00
|
|
|
enum { Label, Value, Error } state = Label;
|
|
|
|
const char *p;
|
|
|
|
for (p = buf; state != Error && p < end && *p; ++p)
|
|
|
|
switch (state) {
|
|
|
|
case Label:
|
|
|
|
if (*p == '=') {
|
2014-11-19 02:47:40 +00:00
|
|
|
if (!rhizome_manifest_field_label_is_valid(begin, p - begin))
|
|
|
|
state = Error; // bad field name
|
2013-11-28 07:14:37 +00:00
|
|
|
else {
|
|
|
|
int *has = NULL;
|
|
|
|
if (p == begin + 2 && strncmp(begin, "id", 2) == 0)
|
|
|
|
has = &has_bid;
|
|
|
|
else if (p == begin + 7 && strncmp(begin, "version", 7) == 0)
|
|
|
|
has = &has_version;
|
|
|
|
state = Value;
|
|
|
|
if (has) {
|
|
|
|
if (*has)
|
|
|
|
state = Error; // duplicate
|
|
|
|
else {
|
|
|
|
*has = 1;
|
|
|
|
begin = p + 1;
|
|
|
|
}
|
|
|
|
}
|
2012-07-12 07:09:01 +00:00
|
|
|
}
|
2014-11-19 02:47:40 +00:00
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
|
|
|
case Value:
|
2014-11-19 02:47:40 +00:00
|
|
|
if (*p == '\r' && !eol)
|
|
|
|
eol = p;
|
|
|
|
else if (*p == '\n') {
|
|
|
|
if (!eol)
|
|
|
|
eol = p;
|
2013-11-28 07:14:37 +00:00
|
|
|
if (has_bid == 1) {
|
|
|
|
const char *e;
|
2015-03-27 18:23:09 +00:00
|
|
|
if (parse_rhizome_bid_t(&summ->bid, begin, eol - begin, &e) == 0 && e == eol)
|
2013-11-28 07:14:37 +00:00
|
|
|
has_bid = 2;
|
|
|
|
else
|
|
|
|
state = Error; // invalid "id" field
|
|
|
|
} else if (has_version == 1) {
|
|
|
|
const char *e;
|
2013-12-11 00:41:34 +00:00
|
|
|
if (str_to_uint64(begin, 10, &summ->version, &e) && e == eol)
|
2013-11-28 07:14:37 +00:00
|
|
|
has_version = 2;
|
|
|
|
else
|
|
|
|
state = Error; // invalid "version" field
|
2012-07-12 07:09:01 +00:00
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
if (state == Value) {
|
|
|
|
state = Label;
|
|
|
|
begin = p + 1;
|
2014-11-19 02:47:40 +00:00
|
|
|
eol = NULL;
|
2012-07-12 07:09:01 +00:00
|
|
|
}
|
2014-11-19 02:47:40 +00:00
|
|
|
} else if (eol)
|
|
|
|
state = Error; // CR not followed by LF
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (p < end && *p == '\0')
|
|
|
|
++p;
|
|
|
|
summ->body_len = p - buf;
|
|
|
|
return state == Label && has_bid == 2 && has_version == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse a Rhizome text manifest from its internal buffer up to and including the terminating NUL
|
|
|
|
* character which marks the start of the signature block.
|
|
|
|
*
|
|
|
|
* Prior to calling, the caller must set up m->manifest_all_bytes to the length of the manifest
|
|
|
|
* text, including the signature block, and set m->manifestdata[0..m->manifest_all_bytes-1] to
|
|
|
|
* contain the manifest text and signature block to be parsed.
|
|
|
|
*
|
|
|
|
* A "well formed" manifest consists of a series of zero or more lines with the form:
|
|
|
|
*
|
|
|
|
* LABEL "=" VALUE [ CR ] LF
|
|
|
|
*
|
|
|
|
* where LABEL matches the regular expression [A-Za-z][A-Za-z0-9]* (identifier without underscore)
|
|
|
|
* VALUE is any value that does not contain NUL, CR or LF (leading and trailing spaces are
|
|
|
|
* not stripped from VALUE)
|
|
|
|
* NUL is ASCII 0
|
|
|
|
* CR is ASCII 13
|
|
|
|
* LF is ASCII 10
|
|
|
|
*
|
|
|
|
* Unpacks all parsed field labels and string values into the m->vars[] and m->values[] arrays, as
|
|
|
|
* pointers to malloc(3)ed NUL terminated strings, in the order they appear, and sets m->var_count
|
|
|
|
* to the number of fields unpacked. Sets m->manifest_body_bytes to the number of bytes in the text
|
|
|
|
* portion up to and including the optional NUL that starts the signature block (if present).
|
|
|
|
*
|
|
|
|
* Returns 1 if the manifest is not well formed (syntax violation), any essential field is
|
|
|
|
* malformed, or if there are any duplicate fields. In this case the m->vars[] and m->values[]
|
|
|
|
* arrays are not set and the manifest is returned to the state it was in prior to calling.
|
|
|
|
*
|
|
|
|
* Returns 0 if the manifest is well formed, if there are no duplicate fields, and if all essential
|
|
|
|
* fields are valid. Counts invalid non-essential fields and unrecognised fields in m->malformed.
|
|
|
|
*
|
|
|
|
* Returns -1 if there is an unrecoverable error (eg, malloc(3) returns NULL, out of memory).
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
|
|
|
*/
|
2013-12-19 08:37:14 +00:00
|
|
|
int rhizome_manifest_parse(rhizome_manifest *m)
|
2013-11-28 07:14:37 +00:00
|
|
|
{
|
|
|
|
IN();
|
|
|
|
assert(m->manifest_all_bytes <= sizeof m->manifestdata);
|
|
|
|
assert(m->manifest_body_bytes == 0);
|
|
|
|
assert(m->var_count == 0);
|
2013-12-19 08:43:39 +00:00
|
|
|
assert(!m->finalised);
|
2014-07-09 19:49:38 +00:00
|
|
|
assert(m->malformed == NULL);
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(!m->has_id);
|
2013-12-19 08:43:39 +00:00
|
|
|
assert(!m->has_filehash);
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(!m->is_journal);
|
|
|
|
assert(m->filesize == RHIZOME_SIZE_UNSET);
|
|
|
|
assert(m->tail == RHIZOME_SIZE_UNSET);
|
|
|
|
assert(m->version == 0);
|
2013-12-19 08:43:39 +00:00
|
|
|
assert(!m->has_date);
|
|
|
|
assert(!m->has_sender);
|
|
|
|
assert(!m->has_recipient);
|
|
|
|
assert(m->payloadEncryption == PAYLOAD_CRYPT_UNKNOWN);
|
2014-11-17 13:11:03 +00:00
|
|
|
unsigned invalid = 0;
|
2014-11-18 08:12:43 +00:00
|
|
|
unsigned has_invalid_core = 0;
|
2013-11-28 07:14:37 +00:00
|
|
|
unsigned has_duplicate = 0;
|
|
|
|
const char *const end = (const char *)m->manifestdata + m->manifest_all_bytes;
|
|
|
|
const char *p;
|
|
|
|
unsigned line_number = 0;
|
2014-11-17 13:11:03 +00:00
|
|
|
for (p = (const char *)m->manifestdata; !invalid && p < end && *p; ++p) {
|
2013-11-28 07:14:37 +00:00
|
|
|
++line_number;
|
|
|
|
const char *const plabel = p++;
|
2014-11-17 13:11:03 +00:00
|
|
|
while (p < end && *p && *p != '=' && *p != '\n')
|
2013-11-28 07:14:37 +00:00
|
|
|
++p;
|
2014-11-17 13:11:03 +00:00
|
|
|
if (p == end || *p != '=') {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Invalid manifest line %u: %s", line_number, alloca_toprint(-1, plabel, p - plabel + 1));
|
2015-12-07 11:21:59 +00:00
|
|
|
++invalid;
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2014-11-17 13:11:03 +00:00
|
|
|
assert(p < end);
|
|
|
|
assert(*p == '=');
|
2013-11-28 07:14:37 +00:00
|
|
|
const char *const pvalue = ++p;
|
|
|
|
while (p < end && *p && *p != '\n')
|
|
|
|
++p;
|
|
|
|
if (p >= end || *p != '\n') {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Missing manifest newline at line %u: %s", line_number, alloca_toprint(-1, plabel, p - plabel));
|
2015-12-07 11:21:59 +00:00
|
|
|
++invalid;
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
const char *const eol = (p > pvalue && p[-1] == '\r') ? p - 1 : p;
|
2014-11-17 13:11:03 +00:00
|
|
|
enum rhizome_manifest_parse_status status = rhizome_manifest_parse_field(m, plabel, pvalue - plabel - 1, pvalue, eol - pvalue);
|
|
|
|
int status_ok = 0;
|
2013-11-28 07:14:37 +00:00
|
|
|
switch (status) {
|
2014-11-17 13:11:03 +00:00
|
|
|
case RHIZOME_MANIFEST_ERROR:
|
|
|
|
RETURN(-1);
|
|
|
|
case RHIZOME_MANIFEST_OK:
|
|
|
|
status_ok = 1;
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
2014-11-17 13:11:03 +00:00
|
|
|
case RHIZOME_MANIFEST_SYNTAX_ERROR:
|
|
|
|
status_ok = 1;
|
|
|
|
++invalid;
|
|
|
|
break;
|
|
|
|
case RHIZOME_MANIFEST_DUPLICATE_FIELD:
|
|
|
|
status_ok = 1;
|
2013-11-28 07:14:37 +00:00
|
|
|
++has_duplicate;
|
|
|
|
break;
|
2014-11-17 13:11:03 +00:00
|
|
|
case RHIZOME_MANIFEST_INVALID:
|
|
|
|
status_ok = 1;
|
2014-11-18 08:12:43 +00:00
|
|
|
++has_invalid_core;
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
2014-11-17 13:11:03 +00:00
|
|
|
case RHIZOME_MANIFEST_MALFORMED:
|
|
|
|
status_ok = 1;
|
2014-07-09 19:49:38 +00:00
|
|
|
m->malformed = "Invalid field";
|
2013-11-28 07:14:37 +00:00
|
|
|
break;
|
2014-11-17 13:11:03 +00:00
|
|
|
case RHIZOME_MANIFEST_OVERFLOW:
|
|
|
|
status_ok = 1;
|
|
|
|
++invalid;
|
|
|
|
break;
|
2013-11-28 07:14:37 +00:00
|
|
|
}
|
2014-11-17 13:11:03 +00:00
|
|
|
if (!status_ok)
|
|
|
|
FATALF("status = %d", status);
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(p < end);
|
|
|
|
assert(*p == '\n');
|
2012-07-12 07:09:01 +00:00
|
|
|
}
|
2015-12-07 11:21:59 +00:00
|
|
|
if ((p < end && *p) || invalid || has_invalid_core || has_duplicate) {
|
2013-11-28 07:14:37 +00:00
|
|
|
rhizome_manifest_clear(m);
|
|
|
|
RETURN(1);
|
2012-07-12 07:09:01 +00:00
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
// The null byte is included in the body (and checksum), not the signature block
|
|
|
|
if (p < end) {
|
|
|
|
assert(*p == '\0');
|
|
|
|
++p;
|
2012-07-12 07:09:01 +00:00
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
m->manifest_body_bytes = p - (const char *)m->manifestdata;
|
|
|
|
RETURN(0);
|
|
|
|
OUT();
|
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
typedef int MANIFEST_FIELD_TESTER(const rhizome_manifest *);
|
2015-03-23 07:02:57 +00:00
|
|
|
typedef void MANIFEST_FIELD_UNSETTER(struct __sourceloc, rhizome_manifest *);
|
|
|
|
typedef void MANIFEST_FIELD_COPIER(struct __sourceloc, rhizome_manifest *, const rhizome_manifest *);
|
2014-11-18 08:12:43 +00:00
|
|
|
typedef int MANIFEST_FIELD_PARSER(rhizome_manifest *, const char *);
|
2014-11-17 13:11:03 +00:00
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_id(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->has_id;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_id(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_id(m, NULL);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_id(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
2016-09-27 00:58:46 +00:00
|
|
|
rhizome_manifest_set_id(m, srcm->has_id ? &srcm->keypair.public_key : NULL);
|
2015-03-16 12:06:38 +00:00
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_id(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
rhizome_bid_t bid;
|
|
|
|
if (str_to_rhizome_bid_t(&bid, text) == -1)
|
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_id(m, &bid);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_version(const rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
return m->version != 0;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_version(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
2015-03-23 07:02:57 +00:00
|
|
|
rhizome_manifest_del_version(m);
|
2014-11-18 08:12:43 +00:00
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_version(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_version(m, srcm->version);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_version(rhizome_manifest *m, const char *text)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
|
|
|
uint64_t version;
|
|
|
|
if (!str_to_uint64(text, 10, &version, NULL) || version == 0)
|
2014-11-18 08:12:43 +00:00
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_version(m, version);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_filehash(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->has_filehash;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_filehash(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_filehash(m, NULL);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_filehash(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_filehash(m, srcm->has_filehash ? &srcm->filehash : NULL);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_filehash(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
rhizome_filehash_t hash;
|
|
|
|
if (str_to_rhizome_filehash_t(&hash, text) == -1)
|
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_filehash(m, &hash);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_filesize(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->filesize != RHIZOME_SIZE_UNSET;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_filesize(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_filesize(m, RHIZOME_SIZE_UNSET);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_filesize(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_filesize(m, srcm->filesize);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_filesize(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
uint64_t size;
|
|
|
|
if (!str_to_uint64(text, 10, &size, NULL) || size == RHIZOME_SIZE_UNSET)
|
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_filesize(m, size);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_tail(const rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
return m->is_journal;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_tail(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_tail(m, RHIZOME_SIZE_UNSET);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_tail(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_tail(m, srcm->tail);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_tail(rhizome_manifest *m, const char *text)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
|
|
|
uint64_t tail;
|
|
|
|
if (!str_to_uint64(text, 10, &tail, NULL) || tail == RHIZOME_SIZE_UNSET)
|
2014-11-18 08:12:43 +00:00
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_tail(m, tail);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_BK(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->has_bundle_key;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_BK(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
2015-03-23 07:02:57 +00:00
|
|
|
rhizome_manifest_del_bundle_key(m);
|
2014-11-18 08:12:43 +00:00
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_BK(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_bundle_key(m, srcm->has_bundle_key ? &srcm->bundle_key : NULL);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_BK(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
rhizome_bk_t bk;
|
|
|
|
if (str_to_rhizome_bk_t(&bk, text) == -1)
|
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_bundle_key(m, &bk);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_service(const rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
return m->service != NULL;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_service(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_del_service(m);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_service(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_service(m, srcm->service);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_service(rhizome_manifest *m, const char *text)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
|
|
|
if (!rhizome_str_is_manifest_service(text))
|
2014-11-18 08:12:43 +00:00
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_service(m, text);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_date(const rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
return m->has_date;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_date(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_del_date(m);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_date(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
if (srcm->has_date)
|
|
|
|
rhizome_manifest_set_date(m, srcm->date);
|
|
|
|
else
|
|
|
|
rhizome_manifest_del_date(m);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_date(rhizome_manifest *m, const char *text)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
|
|
|
int64_t date;
|
|
|
|
if (!str_to_int64(text, 10, &date, NULL))
|
2014-11-18 08:12:43 +00:00
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_date(m, date);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_sender(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->has_sender;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_sender(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_sender(m, NULL);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_sender(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_sender(m, srcm->has_sender ? &srcm->sender : NULL);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_sender(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
sid_t sid;
|
|
|
|
if (str_to_sid_t(&sid, text) == -1)
|
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_sender(m, &sid);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_recipient(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->has_recipient;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_recipient(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_recipient(m, NULL);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_recipient(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_recipient(m, srcm->has_recipient ? &srcm->recipient : NULL);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_recipient(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
sid_t sid;
|
|
|
|
if (str_to_sid_t(&sid, text) == -1)
|
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_recipient(m, &sid);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_name(const rhizome_manifest *m)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
2014-11-18 08:12:43 +00:00
|
|
|
return m->name != NULL;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_name(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_del_name(m);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_name(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_name(m, srcm->name);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_name(rhizome_manifest *m, const char *text)
|
|
|
|
{
|
|
|
|
rhizome_manifest_set_name(m, text);
|
|
|
|
return 1;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static int _rhizome_manifest_test_crypt(const rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
return m->payloadEncryption != PAYLOAD_CRYPT_UNKNOWN;
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_unset_crypt(struct __sourceloc __whence, rhizome_manifest *m)
|
2014-11-18 08:12:43 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_crypt(m, PAYLOAD_CRYPT_UNKNOWN);
|
|
|
|
}
|
2015-03-23 07:02:57 +00:00
|
|
|
static void _rhizome_manifest_copy_crypt(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
rhizome_manifest_set_crypt(m, srcm->payloadEncryption);
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
static int _rhizome_manifest_parse_crypt(rhizome_manifest *m, const char *text)
|
2014-11-17 13:11:03 +00:00
|
|
|
{
|
|
|
|
if (!(strcmp(text, "0") == 0 || strcmp(text, "1") == 0))
|
2014-11-18 08:12:43 +00:00
|
|
|
return 0;
|
|
|
|
rhizome_manifest_set_crypt(m, (text[0] == '1') ? PAYLOAD_ENCRYPTED : PAYLOAD_CLEAR);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct rhizome_manifest_field_descriptor {
|
|
|
|
const char *label;
|
|
|
|
int core;
|
|
|
|
MANIFEST_FIELD_TESTER *test;
|
|
|
|
MANIFEST_FIELD_UNSETTER *unset;
|
2015-03-16 12:06:38 +00:00
|
|
|
MANIFEST_FIELD_COPIER *copy;
|
2014-11-18 08:12:43 +00:00
|
|
|
MANIFEST_FIELD_PARSER *parse;
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
rhizome_manifest_fields[] = {
|
2015-03-16 12:06:38 +00:00
|
|
|
#define FIELD(CORE, NAME) \
|
|
|
|
{ #NAME, CORE, _rhizome_manifest_test_ ## NAME, _rhizome_manifest_unset_ ## NAME, _rhizome_manifest_copy_ ## NAME, _rhizome_manifest_parse_ ## NAME }
|
|
|
|
FIELD(1, id),
|
|
|
|
FIELD(1, version),
|
|
|
|
FIELD(1, filehash),
|
|
|
|
FIELD(1, filesize),
|
|
|
|
FIELD(1, tail),
|
|
|
|
FIELD(0, BK),
|
|
|
|
FIELD(0, service),
|
|
|
|
FIELD(0, date),
|
|
|
|
FIELD(0, sender),
|
|
|
|
FIELD(0, recipient),
|
|
|
|
FIELD(0, name),
|
|
|
|
FIELD(0, crypt),
|
|
|
|
#undef FIELD
|
2014-11-18 08:12:43 +00:00
|
|
|
};
|
2014-11-17 13:11:03 +00:00
|
|
|
|
2015-03-16 12:06:38 +00:00
|
|
|
static struct rhizome_manifest_field_descriptor *get_rhizome_manifest_field_descriptor(const char *label)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < NELS(rhizome_manifest_fields); ++i)
|
|
|
|
if (strcasecmp(label, rhizome_manifest_fields[i].label) == 0)
|
|
|
|
return &rhizome_manifest_fields[i];
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Overwrite a Rhizome manifest with fields from another. Used in the "add bundle" application API
|
|
|
|
* when the application supplies a partial manifest to override or add to existing manifest fields.
|
|
|
|
*
|
|
|
|
* Returns -1 if a field in the destination manifest cannot be overwritten for an unrecoverable
|
|
|
|
* reason, eg, out of memory or too many variables, leaving the destination manifest in an undefined
|
|
|
|
* state.
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
|
|
|
*/
|
2015-03-23 07:02:57 +00:00
|
|
|
int _rhizome_manifest_overwrite(struct __sourceloc __whence, rhizome_manifest *m, const rhizome_manifest *srcm)
|
2015-03-16 12:06:38 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < NELS(rhizome_manifest_fields); ++i) {
|
|
|
|
struct rhizome_manifest_field_descriptor *desc = &rhizome_manifest_fields[i];
|
2015-03-23 07:02:57 +00:00
|
|
|
if (desc->test(srcm)) {
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "COPY manifest %p %s to:", srcm, desc->label);
|
2015-03-23 07:02:57 +00:00
|
|
|
desc->copy(__whence, m, srcm);
|
|
|
|
}
|
2015-03-16 12:06:38 +00:00
|
|
|
}
|
|
|
|
for (i = 0; i < srcm->var_count; ++i) {
|
|
|
|
struct rhizome_manifest_field_descriptor *desc = get_rhizome_manifest_field_descriptor(srcm->vars[i]);
|
|
|
|
if (!desc)
|
2015-03-23 07:02:57 +00:00
|
|
|
if (_rhizome_manifest_set(__whence, m, srcm->vars[i], srcm->values[i]) == NULL)
|
2015-03-16 12:06:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-19 02:47:40 +00:00
|
|
|
int rhizome_manifest_field_label_is_valid(const char *field_label, size_t field_label_len)
|
|
|
|
{
|
|
|
|
if (field_label_len == 0 || field_label_len > MAX_MANIFEST_FIELD_LABEL_LEN)
|
|
|
|
return 0;
|
|
|
|
if (!isalpha(field_label[0]))
|
|
|
|
return 0;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 1; i != field_label_len; ++i)
|
|
|
|
if (!isalnum(field_label[i]))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rhizome_manifest_field_value_is_valid(const char *field_value, size_t field_value_len)
|
|
|
|
{
|
|
|
|
if (field_value_len >= MAX_MANIFEST_BYTES)
|
|
|
|
return 0;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < field_value_len; ++i)
|
|
|
|
if (field_value[i] == '\0' || field_value[i] == '\r' || field_value[i] == '\n')
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2014-11-17 13:11:03 +00:00
|
|
|
/* Parse a single Rhizome manifest field. Used for incremental construction or modification of
|
|
|
|
* manifests.
|
|
|
|
*
|
|
|
|
* If the supplied field_label is invalid (does not conform to the syntax for field names) or the
|
|
|
|
* field_value string is too long or contains a NUL (ASCII 0), CR (ASCII 13) or LF (ASCII 10), then
|
|
|
|
* returns RHIZOME_MANIFEST_SYNTAX_ERROR and leaves the manifest unchanged.
|
|
|
|
*
|
|
|
|
* If a field with the given label already exists in the manifest, then returns
|
|
|
|
* RHIZOME_MANIFEST_DUPLICATE_FIELD without modifying the manifest. (To overwrite an existing
|
|
|
|
* field, first remove it by calling rhizome_manifest_remove_field() then call
|
|
|
|
* rhizome_manifest_parse_field().)
|
|
|
|
*
|
2014-11-18 08:12:43 +00:00
|
|
|
* If the maximum number of fields are already occupied in the manifest, then returns
|
|
|
|
* RHIZOME_MANIFEST_OVERFLOW and leaves the manifest unchanged.
|
|
|
|
*
|
2014-11-17 13:11:03 +00:00
|
|
|
* If the supplied field_value is invalid (does not parse according to the field's syntax, eg,
|
|
|
|
* unsigned integer) then returns RHIZOME_MANIFEST_INVALID if it is a core field, otherwise returns
|
2014-11-18 08:12:43 +00:00
|
|
|
* RHIZOME_MANIFEST_MALFORMED and leaves the manifest unchanged. Unsupported fields are not parsed;
|
|
|
|
* their value string is simply stored, so they cannot evoke a MALFORMED result.
|
2014-11-17 13:11:03 +00:00
|
|
|
*
|
|
|
|
* Otherwise, sets the relevant element(s) of the manifest structure and appends the field_label and
|
|
|
|
* field_value strings into the m->vars[] and m->values[] arrays, as pointers to malloc(3)ed NUL
|
|
|
|
* terminated strings, and increments m->var_count. Returns RHIZOME_MANIFEST_OK.
|
|
|
|
*
|
|
|
|
* Returns -1 (RHIZOME_MANIFEST_ERROR) if there is an unrecoverable error (eg, malloc(3) returns
|
|
|
|
* NULL, out of memory).
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
|
|
|
*/
|
|
|
|
enum rhizome_manifest_parse_status
|
|
|
|
rhizome_manifest_parse_field(rhizome_manifest *m, const char *field_label, size_t field_label_len, const char *field_value, size_t field_value_len)
|
|
|
|
{
|
|
|
|
// Syntax check on field label.
|
2014-11-19 02:47:40 +00:00
|
|
|
if (!rhizome_manifest_field_label_is_valid(field_label, field_label_len)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Invalid manifest field name: %s", alloca_toprint(100, field_label, field_label_len));
|
2014-11-17 13:11:03 +00:00
|
|
|
return RHIZOME_MANIFEST_SYNTAX_ERROR;
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
const char *label = alloca_strndup(field_label, field_label_len);
|
2014-11-17 13:11:03 +00:00
|
|
|
// Sanity and syntax check on field value.
|
2014-11-19 02:47:40 +00:00
|
|
|
if (!rhizome_manifest_field_value_is_valid(field_value, field_value_len)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Invalid manifest field value: %s=%s", label, alloca_toprint(100, field_value, field_value_len));
|
2014-11-17 13:11:03 +00:00
|
|
|
return RHIZOME_MANIFEST_SYNTAX_ERROR;
|
|
|
|
}
|
2014-11-18 08:12:43 +00:00
|
|
|
const char *value = alloca_strndup(field_value, field_value_len);
|
2015-03-16 12:06:38 +00:00
|
|
|
struct rhizome_manifest_field_descriptor *desc = get_rhizome_manifest_field_descriptor(label);
|
2014-11-17 13:11:03 +00:00
|
|
|
enum rhizome_manifest_parse_status status = RHIZOME_MANIFEST_OK;
|
2014-11-18 08:12:43 +00:00
|
|
|
assert(m->var_count <= NELS(m->vars));
|
|
|
|
if (desc ? desc->test(m) : rhizome_manifest_get(m, label) != NULL) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Duplicate field at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
|
2014-11-17 13:11:03 +00:00
|
|
|
status = RHIZOME_MANIFEST_DUPLICATE_FIELD;
|
2014-11-18 08:12:43 +00:00
|
|
|
} else if (m->var_count == NELS(m->vars)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Manifest field limit reached at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
|
2014-11-17 13:11:03 +00:00
|
|
|
status = RHIZOME_MANIFEST_OVERFLOW;
|
2014-11-18 08:12:43 +00:00
|
|
|
} else if (desc) {
|
|
|
|
if (!desc->parse(m, value)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Manifest field parse failed at %s=%s", label, alloca_toprint(100, field_value, field_value_len));
|
2014-11-18 08:12:43 +00:00
|
|
|
status = desc->core ? RHIZOME_MANIFEST_INVALID : RHIZOME_MANIFEST_MALFORMED;
|
|
|
|
}
|
2015-03-16 12:06:38 +00:00
|
|
|
} else if (rhizome_manifest_set(m, label, value) == NULL)
|
2014-11-18 08:12:43 +00:00
|
|
|
status = RHIZOME_MANIFEST_ERROR;
|
|
|
|
if (status != RHIZOME_MANIFEST_OK) {
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "SKIP manifest %p %s = %s (status=%d)", m, label, alloca_str_toprint(value), status);
|
2014-11-17 13:11:03 +00:00
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2014-11-19 02:56:50 +00:00
|
|
|
/* Remove the field with the given label from the manifest.
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
|
|
|
*/
|
|
|
|
int rhizome_manifest_remove_field(rhizome_manifest *m, const char *field_label, size_t field_label_len)
|
|
|
|
{
|
|
|
|
if (!rhizome_manifest_field_label_is_valid(field_label, field_label_len)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome_manifest, "Invalid manifest field name: %s", alloca_toprint(100, field_label, field_label_len));
|
2014-11-19 02:56:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const char *label = alloca_strndup(field_label, field_label_len);
|
|
|
|
struct rhizome_manifest_field_descriptor *desc = NULL;
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; desc == NULL && i < NELS(rhizome_manifest_fields); ++i)
|
|
|
|
if (strcasecmp(label, rhizome_manifest_fields[i].label) == 0)
|
|
|
|
desc = &rhizome_manifest_fields[i];
|
|
|
|
if (!desc)
|
|
|
|
return rhizome_manifest_del(m, label);
|
|
|
|
if (!desc->test(m))
|
|
|
|
return 0;
|
2015-03-23 07:02:57 +00:00
|
|
|
desc->unset(__WHENCE__, m);
|
2014-11-19 02:56:50 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-19 08:43:39 +00:00
|
|
|
/* If all essential (transport) fields are present and well formed then sets the m->finalised field
|
|
|
|
* and returns 1, otherwise returns 0.
|
|
|
|
*
|
2014-07-09 19:49:38 +00:00
|
|
|
* Sets m->malformed if any non-essential fields are missing or invalid. It is up to the caller to
|
|
|
|
* check m->malformed and decide whether or not to process a malformed manifest.
|
2013-12-19 08:43:39 +00:00
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
2013-11-28 07:14:37 +00:00
|
|
|
*/
|
|
|
|
int rhizome_manifest_validate(rhizome_manifest *m)
|
|
|
|
{
|
2016-06-28 03:39:02 +00:00
|
|
|
return (m->finalised || rhizome_manifest_validate_reason(m) == NULL) ? 1 : 0;
|
2014-07-09 19:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If all essential (transport) fields are present and well formed then sets the m->finalised field
|
|
|
|
* and returns NULL, otherwise returns a pointer to a static string (not malloc(3)ed) describing the
|
|
|
|
* problem.
|
|
|
|
*
|
|
|
|
* If any non-essential fields are missing or invalid, then sets m->malformed to point to a static
|
|
|
|
* string describing the problem. It is up to the caller to check m->malformed and decide whether
|
|
|
|
* or not to process a malformed manifest.
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
|
|
|
*/
|
|
|
|
const char *rhizome_manifest_validate_reason(rhizome_manifest *m)
|
|
|
|
{
|
|
|
|
const char *reason = NULL;
|
|
|
|
if (!m->has_id)
|
|
|
|
reason = "Missing 'id' field";
|
|
|
|
else if (m->version == 0)
|
|
|
|
reason = "Missing 'version' field";
|
|
|
|
else if (m->filesize == RHIZOME_SIZE_UNSET)
|
|
|
|
reason = "Missing 'filesize' field";
|
|
|
|
else if (m->filesize == 0 && m->has_filehash)
|
|
|
|
reason = "Spurious 'filehash' field";
|
|
|
|
else if (m->filesize != 0 && !m->has_filehash)
|
|
|
|
reason = "Missing 'filehash' field";
|
2015-07-06 08:19:49 +00:00
|
|
|
if (reason)
|
|
|
|
DEBUG(rhizome_manifest, reason);
|
2014-07-09 19:49:38 +00:00
|
|
|
if (m->service == NULL)
|
|
|
|
m->malformed = "Missing 'service' field";
|
2013-12-19 08:43:39 +00:00
|
|
|
else if (strcmp(m->service, RHIZOME_SERVICE_FILE) == 0) {
|
2014-07-09 19:49:38 +00:00
|
|
|
if (m->name == NULL)
|
|
|
|
m->malformed = "Manifest with service='" RHIZOME_SERVICE_FILE "' missing 'name' field";
|
2014-11-18 08:12:43 +00:00
|
|
|
} else if (strcmp(m->service, RHIZOME_SERVICE_MESHMS) == 0
|
|
|
|
|| strcmp(m->service, RHIZOME_SERVICE_MESHMS2) == 0
|
2013-12-19 08:43:39 +00:00
|
|
|
) {
|
2014-07-09 19:49:38 +00:00
|
|
|
if (!m->has_recipient)
|
|
|
|
m->malformed = "Manifest missing 'recipient' field";
|
|
|
|
else if (!m->has_sender)
|
|
|
|
m->malformed = "Manifest missing 'sender' field";
|
2013-08-01 02:07:35 +00:00
|
|
|
}
|
2014-07-09 19:49:38 +00:00
|
|
|
else if (!rhizome_str_is_manifest_service(m->service))
|
|
|
|
m->malformed = "Manifest invalid 'service' field";
|
|
|
|
else if (!m->has_date)
|
|
|
|
m->malformed = "Missing 'date' field";
|
2015-07-06 08:19:49 +00:00
|
|
|
if (m->malformed)
|
|
|
|
DEBUG(rhizome_manifest, m->malformed);
|
2014-07-09 19:49:38 +00:00
|
|
|
m->finalised = (reason == NULL);
|
|
|
|
return reason;
|
2012-01-12 03:38:24 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 08:37:14 +00:00
|
|
|
int rhizome_read_manifest_from_file(rhizome_manifest *m, const char *filename)
|
2013-08-01 02:07:35 +00:00
|
|
|
{
|
2013-12-19 08:37:14 +00:00
|
|
|
ssize_t bytes = read_whole_file(filename, m->manifestdata, sizeof m->manifestdata);
|
|
|
|
if (bytes == -1)
|
|
|
|
return -1;
|
|
|
|
m->manifest_all_bytes = (size_t) bytes;
|
|
|
|
return rhizome_manifest_parse(m);
|
2013-08-01 02:07:35 +00:00
|
|
|
}
|
|
|
|
|
2012-10-16 06:16:52 +00:00
|
|
|
rhizome_manifest *_rhizome_new_manifest(struct __sourceloc __whence)
|
2012-01-12 03:38:24 +00:00
|
|
|
{
|
2016-03-22 23:44:32 +00:00
|
|
|
rhizome_manifest *m=emalloc_zero(sizeof(rhizome_manifest));
|
|
|
|
if (m){
|
|
|
|
DEBUGF(rhizome_manifest, "NEW manifest %p", m);
|
2013-07-08 05:27:47 +00:00
|
|
|
|
2016-03-22 23:44:32 +00:00
|
|
|
// Set global defaults for a manifest (which are not zero)
|
|
|
|
rhizome_manifest_clear(m);
|
|
|
|
}
|
2012-01-28 01:15:45 +00:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2012-10-16 06:16:52 +00:00
|
|
|
void _rhizome_manifest_free(struct __sourceloc __whence, rhizome_manifest *m)
|
2012-01-28 01:15:45 +00:00
|
|
|
{
|
|
|
|
if (!m) return;
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome_manifest, "FREE manifest %p", m);
|
|
|
|
|
2013-10-30 03:15:51 +00:00
|
|
|
/* Free variable and signature blocks. */
|
2013-11-28 07:14:37 +00:00
|
|
|
rhizome_manifest_clear(m);
|
2017-09-11 04:39:05 +00:00
|
|
|
free(m);
|
2012-01-12 03:38:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-07 11:30:52 +00:00
|
|
|
/* Converts the variable list into manifest text body and computes the hash. Does not sign.
|
|
|
|
* Returns 0 if successful, -1 if the result exceeds the manifest size limit.
|
2013-11-28 07:14:37 +00:00
|
|
|
*/
|
2015-12-07 11:30:52 +00:00
|
|
|
static struct rhizome_bundle_result rhizome_manifest_pack_variables(rhizome_manifest *m)
|
2012-01-12 03:38:24 +00:00
|
|
|
{
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(m->var_count <= NELS(m->vars));
|
2015-10-13 08:12:22 +00:00
|
|
|
strbuf sb = strbuf_local_buf(m->manifestdata);
|
2013-10-30 03:15:51 +00:00
|
|
|
unsigned i;
|
2013-11-28 07:14:37 +00:00
|
|
|
for (i = 0; i < m->var_count; ++i) {
|
|
|
|
strbuf_puts(sb, m->vars[i]);
|
|
|
|
strbuf_putc(sb, '=');
|
|
|
|
strbuf_puts(sb, m->values[i]);
|
|
|
|
strbuf_putc(sb, '\n');
|
|
|
|
}
|
2015-12-07 11:30:52 +00:00
|
|
|
if (strbuf_overrun(sb)) {
|
|
|
|
return rhizome_bundle_result_sprintf(
|
|
|
|
RHIZOME_BUNDLE_STATUS_MANIFEST_TOO_BIG,
|
|
|
|
"Manifest too big: body of %zu bytes exceeds limit of %zu",
|
|
|
|
strbuf_count(sb) + 1, sizeof m->manifestdata);
|
|
|
|
}
|
2013-11-28 07:14:37 +00:00
|
|
|
m->manifest_body_bytes = strbuf_len(sb) + 1;
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "Repacked variables into manifest: %zu bytes", m->manifest_body_bytes);
|
2013-11-28 07:14:37 +00:00
|
|
|
m->manifest_all_bytes = m->manifest_body_bytes;
|
|
|
|
m->selfSigned = 0;
|
2015-12-07 11:30:52 +00:00
|
|
|
return rhizome_bundle_result(RHIZOME_BUNDLE_STATUS_NEW);
|
2012-01-12 03:38:24 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 07:14:37 +00:00
|
|
|
/* Sign this manifest using it's own BID secret key. Manifest must not already be signed.
|
|
|
|
* Manifest body hash must already be computed.
|
2012-06-25 06:16:22 +00:00
|
|
|
*/
|
2015-12-07 11:30:52 +00:00
|
|
|
static struct rhizome_bundle_result rhizome_manifest_selfsign(rhizome_manifest *m)
|
2012-01-12 03:38:24 +00:00
|
|
|
{
|
2013-11-28 07:14:37 +00:00
|
|
|
assert(m->manifest_body_bytes > 0);
|
|
|
|
assert(m->manifest_body_bytes <= sizeof m->manifestdata);
|
|
|
|
assert(m->manifestdata[m->manifest_body_bytes - 1] == '\0');
|
|
|
|
assert(m->manifest_body_bytes == m->manifest_all_bytes); // no signature yet
|
2012-10-11 07:28:24 +00:00
|
|
|
if (!m->haveSecret)
|
2015-12-07 11:30:52 +00:00
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_READONLY, "Missing bundle secret");
|
2016-04-12 06:13:56 +00:00
|
|
|
|
|
|
|
size_t sigLen = 1 + crypto_sign_BYTES + crypto_sign_PUBLICKEYBYTES;
|
|
|
|
if (sizeof m->manifestdata - m->manifest_body_bytes < sigLen)
|
2015-12-07 11:30:52 +00:00
|
|
|
return rhizome_bundle_result_sprintf(RHIZOME_BUNDLE_STATUS_MANIFEST_TOO_BIG,
|
|
|
|
"Manifest too big: body of %zu + signature of %zu bytes exceeds limit of %zu",
|
|
|
|
m->manifest_body_bytes,
|
2016-04-12 06:13:56 +00:00
|
|
|
sigLen,
|
2015-12-07 11:30:52 +00:00
|
|
|
sizeof m->manifestdata);
|
2016-04-12 06:13:56 +00:00
|
|
|
|
|
|
|
crypto_hash_sha512(m->manifesthash.binary, m->manifestdata, m->manifest_body_bytes);
|
|
|
|
uint8_t *p = &m->manifestdata[m->manifest_body_bytes];
|
|
|
|
*p++ = 0x17; // CryptoSign
|
2016-09-27 00:58:46 +00:00
|
|
|
if (crypto_sign_detached(p, NULL, m->manifesthash.binary, sizeof m->manifesthash.binary, m->keypair.binary))
|
2016-04-12 06:13:56 +00:00
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_ERROR, "crypto_sign_detached() failed");
|
|
|
|
p+=crypto_sign_BYTES;
|
2016-09-27 00:58:46 +00:00
|
|
|
bcopy(m->keypair.public_key.binary, p, crypto_sign_BYTES);
|
2016-04-12 06:13:56 +00:00
|
|
|
m->manifest_all_bytes = m->manifest_body_bytes + sigLen;
|
2013-12-27 18:56:22 +00:00
|
|
|
m->selfSigned = 1;
|
2015-12-07 11:30:52 +00:00
|
|
|
return rhizome_bundle_result(RHIZOME_BUNDLE_STATUS_NEW);
|
2012-01-12 03:38:24 +00:00
|
|
|
}
|
|
|
|
|
2013-10-11 05:36:12 +00:00
|
|
|
int rhizome_write_manifest_file(rhizome_manifest *m, const char *path, char append)
|
2012-01-12 03:38:24 +00:00
|
|
|
{
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "write manifest (%zd bytes) to %s", m->manifest_all_bytes, path);
|
2013-12-19 08:43:39 +00:00
|
|
|
assert(m->finalised);
|
2013-10-11 05:36:12 +00:00
|
|
|
int fd = open(path, O_WRONLY | O_CREAT | (append ? O_APPEND : 0), 0666);
|
|
|
|
if (fd == -1)
|
|
|
|
return WHYF_perror("open(%s,O_WRONLY|O_CREAT%s,0666)", alloca_str_toprint(path), append ? "|O_APPEND" : "");
|
2013-01-11 03:49:26 +00:00
|
|
|
int ret = 0;
|
2013-10-11 17:24:18 +00:00
|
|
|
unsigned char marker[4];
|
|
|
|
struct iovec iov[2];
|
|
|
|
int iovcnt = 1;
|
|
|
|
iov[0].iov_base = m->manifestdata;
|
|
|
|
iov[0].iov_len = m->manifest_all_bytes;
|
|
|
|
if (append) {
|
2013-01-11 03:49:26 +00:00
|
|
|
write_uint16(marker, m->manifest_all_bytes);
|
2013-10-11 17:24:18 +00:00
|
|
|
marker[2] = 0x41;
|
|
|
|
marker[3] = 0x10;
|
|
|
|
iov[1].iov_base = marker;
|
|
|
|
iov[1].iov_len = sizeof marker;
|
|
|
|
iovcnt = 2;
|
2012-05-24 01:58:32 +00:00
|
|
|
}
|
2013-10-11 17:24:18 +00:00
|
|
|
if (writev_all(fd, iov, iovcnt) == -1)
|
|
|
|
ret = -1;
|
2013-10-11 05:36:12 +00:00
|
|
|
if (close(fd) == -1)
|
|
|
|
ret = WHY_perror("close");
|
2013-01-11 03:49:26 +00:00
|
|
|
return ret;
|
2012-01-12 03:38:24 +00:00
|
|
|
}
|
|
|
|
|
2012-05-24 07:41:55 +00:00
|
|
|
int rhizome_manifest_dump(rhizome_manifest *m, const char *msg)
|
2012-01-12 03:38:24 +00:00
|
|
|
{
|
2013-10-30 03:15:51 +00:00
|
|
|
unsigned i;
|
2012-05-24 07:41:55 +00:00
|
|
|
WHYF("Dumping manifest %s:", msg);
|
2012-01-12 03:38:24 +00:00
|
|
|
for(i=0;i<m->var_count;i++)
|
2012-05-24 07:41:55 +00:00
|
|
|
WHYF("[%s]=[%s]\n", m->vars[i], m->values[i]);
|
2012-01-12 03:38:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-12-07 11:30:52 +00:00
|
|
|
struct rhizome_bundle_result rhizome_manifest_finalise(rhizome_manifest *m, rhizome_manifest **mout, int deduplicate)
|
2012-01-12 03:38:24 +00:00
|
|
|
{
|
2013-01-03 03:46:33 +00:00
|
|
|
IN();
|
2014-07-02 07:46:19 +00:00
|
|
|
assert(*mout == NULL);
|
2015-12-07 11:30:52 +00:00
|
|
|
if (!m->finalised) {
|
|
|
|
const char *reason = rhizome_manifest_validate_reason(m);
|
|
|
|
if (reason)
|
|
|
|
RETURN(rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_INVALID, reason));
|
|
|
|
}
|
2015-04-13 05:18:34 +00:00
|
|
|
// The duplicate detection logic exists to filter out files repeatedly added with no existing
|
|
|
|
// manifest (ie, "de-bounce" for the "Add File" user interface action).
|
|
|
|
// 1. If a manifest was supplied with a bundle ID, don't check for a duplicate.
|
|
|
|
// 2. Never perform duplicate detection on journals (the first append does not supply a bundle ID,
|
|
|
|
// but all subsequent appends supply a bundle ID, so are caught by case (1)).
|
|
|
|
if (deduplicate && m->haveSecret != EXISTING_BUNDLE_ID && !m->is_journal) {
|
2013-12-19 08:43:39 +00:00
|
|
|
enum rhizome_bundle_status status = rhizome_find_duplicate(m, mout);
|
|
|
|
switch (status) {
|
|
|
|
case RHIZOME_BUNDLE_STATUS_DUPLICATE:
|
2014-07-02 07:46:19 +00:00
|
|
|
assert(*mout != NULL);
|
|
|
|
assert(*mout != m);
|
2015-12-07 11:30:52 +00:00
|
|
|
RETURN(rhizome_bundle_result(status));
|
2013-12-19 08:43:39 +00:00
|
|
|
case RHIZOME_BUNDLE_STATUS_ERROR:
|
2014-07-02 07:46:19 +00:00
|
|
|
if (*mout != NULL && *mout != m) {
|
|
|
|
rhizome_manifest_free(*mout);
|
|
|
|
*mout = NULL;
|
|
|
|
}
|
2015-12-07 11:30:52 +00:00
|
|
|
RETURN(rhizome_bundle_result(status));
|
2013-12-19 08:43:39 +00:00
|
|
|
case RHIZOME_BUNDLE_STATUS_NEW:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FATALF("rhizome_find_duplicate() returned %d", status);
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 07:46:19 +00:00
|
|
|
assert(*mout == NULL);
|
2013-12-19 08:43:39 +00:00
|
|
|
*mout = m;
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
2013-01-15 00:02:48 +00:00
|
|
|
/* Convert to final form for signing and writing to disk */
|
2015-12-07 11:30:52 +00:00
|
|
|
struct rhizome_bundle_result result = rhizome_manifest_pack_variables(m);
|
|
|
|
if (result.status != RHIZOME_BUNDLE_STATUS_NEW)
|
|
|
|
RETURN(result);
|
|
|
|
rhizome_bundle_result_free(&result);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
2013-01-15 00:02:48 +00:00
|
|
|
/* Sign it */
|
2013-12-27 18:56:22 +00:00
|
|
|
assert(!m->selfSigned);
|
2015-12-07 11:30:52 +00:00
|
|
|
result = rhizome_manifest_selfsign(m);
|
|
|
|
if (result.status == RHIZOME_BUNDLE_STATUS_NEW) {
|
|
|
|
assert(m->selfSigned);
|
|
|
|
rhizome_bundle_result_free(&result);
|
|
|
|
/* mark manifest as finalised */
|
|
|
|
result.status = rhizome_add_manifest_to_store(m, mout);
|
|
|
|
}
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
2015-12-07 11:30:52 +00:00
|
|
|
RETURN(result);
|
2013-02-16 17:47:24 +00:00
|
|
|
OUT();
|
2012-12-20 04:48:59 +00:00
|
|
|
}
|
2012-01-12 03:38:24 +00:00
|
|
|
|
2013-12-30 05:28:45 +00:00
|
|
|
/* Returns 1 if the name was successfully set, 0 if not.
|
|
|
|
*/
|
|
|
|
int rhizome_manifest_set_name_from_path(rhizome_manifest *m, const char *filepath)
|
|
|
|
{
|
|
|
|
const char *name = strrchr(filepath, '/');
|
2014-03-12 03:52:38 +00:00
|
|
|
if (name)
|
|
|
|
++name; // skip '/'
|
|
|
|
else
|
2013-12-30 05:28:45 +00:00
|
|
|
name = filepath;
|
|
|
|
if (!rhizome_str_is_manifest_name(name)) {
|
|
|
|
WARNF("invalid rhizome name %s -- not used", alloca_str_toprint(name));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
rhizome_manifest_set_name(m, name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2013-12-19 08:43:39 +00:00
|
|
|
/* Fill in a few missing manifest fields, to make it easier to use when adding new files:
|
|
|
|
* - use the current time for "date" and "version"
|
|
|
|
* - use the given author SID, or the 'sender' if present, as the author
|
|
|
|
* - create an ID if there is none, otherwise authenticate the existing one
|
|
|
|
* - if service is file, then use the payload file's basename for "name"
|
2015-03-16 12:10:08 +00:00
|
|
|
*
|
2015-11-30 13:53:15 +00:00
|
|
|
* Return a rhizome_bundle_status code together with a pointer to a text string describing the
|
|
|
|
* reason for the failure (always an internal/unrecoverable error). The string is accompanied by a
|
|
|
|
* pointer to a "free" method (eg, free(3)) that must be called to release the string before the
|
|
|
|
* pointer is discarded.
|
2013-12-19 08:43:39 +00:00
|
|
|
*/
|
2016-05-31 03:20:32 +00:00
|
|
|
struct rhizome_bundle_result rhizome_fill_manifest(rhizome_manifest *m, const char *filepath)
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
{
|
2013-11-05 07:28:03 +00:00
|
|
|
/* Set version of manifest from current time if not already set. */
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if (m->version == 0)
|
|
|
|
rhizome_manifest_set_version(m, gettime_ms());
|
|
|
|
|
2014-11-14 02:31:44 +00:00
|
|
|
/* Fill in the bundle secret and bundle ID.
|
2013-11-05 07:28:03 +00:00
|
|
|
*/
|
2014-11-14 02:31:44 +00:00
|
|
|
switch (m->haveSecret) {
|
|
|
|
case SECRET_UNKNOWN:
|
|
|
|
// If the Bundle Id is already known, then derive the bundle secret from BK if known.
|
|
|
|
if (m->has_id) {
|
2016-09-27 00:58:46 +00:00
|
|
|
DEBUGF(rhizome, "discover secret for bundle bid=%s", alloca_tohex_rhizome_bid_t(m->keypair.public_key));
|
2014-11-14 02:31:44 +00:00
|
|
|
rhizome_authenticate_author(m);
|
|
|
|
break;
|
|
|
|
}
|
2015-11-30 14:09:34 +00:00
|
|
|
// If there is no Bundle Id, then create a new bundle Id and secret from scratch.
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUG(rhizome, "creating new bundle");
|
2015-03-16 12:10:08 +00:00
|
|
|
if (rhizome_manifest_createid(m) == -1) {
|
2015-11-30 13:53:15 +00:00
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_ERROR, "Could not bind manifest to an ID");
|
2015-03-16 12:10:08 +00:00
|
|
|
}
|
2020-07-09 23:58:02 +00:00
|
|
|
// to set the BK field...
|
|
|
|
FALLTHROUGH; // fall through
|
2014-11-14 02:31:44 +00:00
|
|
|
case NEW_BUNDLE_ID:
|
|
|
|
assert(m->has_id);
|
2017-10-19 11:43:30 +00:00
|
|
|
// If the manifest has no author but does have a 'sender' field, then use the
|
2015-11-30 14:09:34 +00:00
|
|
|
// sender as the author.
|
|
|
|
if (m->authorship == ANONYMOUS && m->has_sender)
|
|
|
|
rhizome_manifest_set_author(m, &m->sender);
|
|
|
|
// If we know the author then set the BK field.
|
2014-11-14 02:31:44 +00:00
|
|
|
if (m->authorship != ANONYMOUS) {
|
2016-09-27 00:58:46 +00:00
|
|
|
DEBUGF(rhizome, "set BK field for bid=%s", alloca_tohex_rhizome_bid_t(m->keypair.public_key));
|
2015-11-30 14:09:34 +00:00
|
|
|
rhizome_manifest_add_bundle_key(m);
|
2014-11-14 02:31:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EXISTING_BUNDLE_ID:
|
|
|
|
// If modifying an existing bundle, try to discover the bundle secret key and the author.
|
|
|
|
assert(m->has_id);
|
2016-09-27 00:58:46 +00:00
|
|
|
DEBUGF(rhizome, "modifying existing bundle bid=%s", alloca_tohex_rhizome_bid_t(m->keypair.public_key));
|
2013-11-05 07:28:03 +00:00
|
|
|
rhizome_authenticate_author(m);
|
|
|
|
// TODO assert that new version > old version?
|
2016-05-31 03:20:32 +00:00
|
|
|
break;
|
|
|
|
default:
|
2014-11-14 02:31:44 +00:00
|
|
|
FATALF("haveSecret = %d", m->haveSecret);
|
2016-05-31 03:20:32 +00:00
|
|
|
}
|
|
|
|
|
2015-11-30 13:53:15 +00:00
|
|
|
switch (m->authorship) {
|
|
|
|
case ANONYMOUS:
|
|
|
|
case AUTHOR_AUTHENTIC:
|
2016-05-31 03:20:32 +00:00
|
|
|
break; // all good
|
2015-11-30 13:53:15 +00:00
|
|
|
case AUTHOR_UNKNOWN:
|
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_READONLY, "Author is not in keyring");
|
|
|
|
case AUTHOR_IMPOSTOR:
|
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_READONLY, "Incorrect author");
|
|
|
|
case AUTHENTICATION_ERROR:
|
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_ERROR, "Error authenticating author");
|
2016-05-31 03:20:32 +00:00
|
|
|
default:
|
2015-11-30 13:53:15 +00:00
|
|
|
FATALF("m->authorship = %d", (int)m->authorship);
|
2016-05-31 03:20:32 +00:00
|
|
|
}
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
2014-11-14 02:31:44 +00:00
|
|
|
/* Service field must already be set.
|
|
|
|
*/
|
2016-05-31 03:20:32 +00:00
|
|
|
if (m->service == NULL)
|
2015-11-30 13:53:15 +00:00
|
|
|
return rhizome_bundle_result_static(RHIZOME_BUNDLE_STATUS_INVALID, "Missing 'service' field");
|
2016-05-31 03:20:32 +00:00
|
|
|
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "manifest contains service=%s", m->service);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
2014-11-14 02:31:44 +00:00
|
|
|
/* Fill in 'date' field to current time unless already set.
|
|
|
|
*/
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if (!m->has_date) {
|
|
|
|
rhizome_manifest_set_date(m, (int64_t) gettime_ms());
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "missing 'date', set default date=%"PRItime_ms_t, m->date);
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
}
|
|
|
|
|
2014-11-14 02:31:44 +00:00
|
|
|
/* Fill in 'name' field if service=file.
|
|
|
|
*/
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if (strcasecmp(RHIZOME_SERVICE_FILE, m->service) == 0) {
|
2013-12-18 07:12:45 +00:00
|
|
|
if (m->name) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "manifest already contains name=%s", alloca_str_toprint(m->name));
|
2013-12-30 05:28:45 +00:00
|
|
|
} else if (filepath)
|
|
|
|
rhizome_manifest_set_name_from_path(m, filepath);
|
2015-07-06 08:19:49 +00:00
|
|
|
else
|
|
|
|
DEBUGF(rhizome, "manifest missing 'name'");
|
2013-01-03 05:42:24 +00:00
|
|
|
}
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
|
2014-11-14 02:31:44 +00:00
|
|
|
/* Fill in 'crypt' field. Anything sent from one person to another should be considered private
|
|
|
|
* and encrypted by default.
|
|
|
|
*/
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
if ( m->payloadEncryption == PAYLOAD_CRYPT_UNKNOWN
|
|
|
|
&& m->has_recipient
|
|
|
|
&& !is_sid_t_broadcast(m->recipient)
|
|
|
|
) {
|
2016-05-31 03:20:32 +00:00
|
|
|
DEBUGF(rhizome, "Implicitly adding payload encryption due to presense of recipient field");
|
Refactor manifest: specific setter functions
Replace generic rhizome_manifest_set() and rhizome_manifest_set_ll()
with per-field setter functions, eg, rhizome_manifest_set_filesize().
Struct rhizome_manifest elements for all known fields, to replace the
use of rhizome_manifest_get() and rhizome_manifest_get_ll() everywhere:
sender, recipient, service, name, date, bundle_key.
Add boolean validity flags for binary blob types, to avoid having to compare
with many bytes of all-zero to detect presence, eg, has_sender, has_recipient,
has_author, has_bundle_key. These maintained by the setter functions.
Rename existing manifest struct elements to be the same as their field
names: fileLength -> filesize, journalTail -> tail.
More use of unsigned int, size_t and uint64_t for payload sizes, offsets, byte
counts, etc. especially in rhizome_store.c and meshms.c. More uniform use of
size_t to dimension memory buffers. Fix some printf(3) style format strings
for 64-bit correctness on 32-bit systems. Use new constant RHIZOME_SIZE_UNSET
instead of -1 to indicate unknown dimension, and explicitly assert its absence
before comparisons and arithmetic, for safety.
Replace some 'int' loop variables with 'unsigned' where appropriate.
Fix bugs discovered in MeshMS bundle private/public key generation and
bundle secret key handling for export/extract commands.
Instrument the first MeshMS test case to aid debugging.
New debug config flag: debug.manifest logs all modifications to all manifest
fields by setter functions.
Rename debug config flag: debug.rhizome_bind -> debug.rhizome_sql_bind.
2013-10-30 12:52:19 +00:00
|
|
|
rhizome_manifest_set_crypt(m, PAYLOAD_ENCRYPTED);
|
|
|
|
}
|
|
|
|
|
2015-11-30 13:53:15 +00:00
|
|
|
return rhizome_bundle_result(RHIZOME_BUNDLE_STATUS_NEW);
|
2013-02-15 21:04:44 +00:00
|
|
|
}
|
2013-11-04 13:17:09 +00:00
|
|
|
|
2016-10-16 00:14:36 +00:00
|
|
|
/* Work out the authorship status of the bundle without performing expensive cryptographic checks.
|
2013-11-05 07:28:03 +00:00
|
|
|
* Sets the 'authorship' element and returns 1 if an author was found, 0 if not.
|
|
|
|
*
|
|
|
|
* @author Andrew Bettison <andrew@servalproject.com>
|
|
|
|
*/
|
2013-11-04 13:17:09 +00:00
|
|
|
int rhizome_lookup_author(rhizome_manifest *m)
|
|
|
|
{
|
2013-11-05 07:28:03 +00:00
|
|
|
IN();
|
2013-11-04 13:17:09 +00:00
|
|
|
switch (m->authorship) {
|
2015-09-28 07:54:15 +00:00
|
|
|
case AUTHOR_LOCAL:
|
|
|
|
case AUTHOR_AUTHENTIC:
|
2016-10-16 00:14:36 +00:00
|
|
|
case AUTHOR_REMOTE:
|
2015-09-28 07:54:15 +00:00
|
|
|
RETURN(1);
|
2013-11-04 13:17:09 +00:00
|
|
|
case AUTHOR_NOT_CHECKED:
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome, "manifest %p lookup author=%s", m, alloca_tohex_sid_t(m->author));
|
2017-09-12 05:34:24 +00:00
|
|
|
if (keyring && keyring_find_identity_sid(keyring, &m->author)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "found author");
|
2013-11-05 07:28:03 +00:00
|
|
|
m->authorship = AUTHOR_LOCAL;
|
|
|
|
RETURN(1);
|
2013-11-04 13:17:09 +00:00
|
|
|
}
|
2013-11-05 07:28:03 +00:00
|
|
|
// fall through
|
|
|
|
case ANONYMOUS:
|
2013-11-04 13:17:09 +00:00
|
|
|
if (m->has_sender) {
|
2016-03-22 23:44:32 +00:00
|
|
|
DEBUGF(rhizome, "manifest %p lookup sender=%s", m, alloca_tohex_sid_t(m->sender));
|
2017-09-12 05:34:24 +00:00
|
|
|
if (keyring && keyring_find_identity_sid(keyring, &m->sender)) {
|
2015-07-06 08:19:49 +00:00
|
|
|
DEBUGF(rhizome, "found sender");
|
2013-11-05 07:28:03 +00:00
|
|
|
rhizome_manifest_set_author(m, &m->sender);
|
2013-11-04 13:17:09 +00:00
|
|
|
m->authorship = AUTHOR_LOCAL;
|
2013-11-05 07:28:03 +00:00
|
|
|
RETURN(1);
|
2016-10-16 00:14:36 +00:00
|
|
|
} else if(crypto_ismatching_sign_sid(&m->keypair.public_key, &m->sender)) {
|
|
|
|
// if the author matches the bundle id...
|
|
|
|
DEBUGF(rhizome, "sender matches manifest signature");
|
|
|
|
m->author = m->sender;
|
|
|
|
m->authorship = AUTHOR_REMOTE;
|
|
|
|
RETURN(1);
|
2013-11-04 13:17:09 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-28 07:54:15 +00:00
|
|
|
// fall through
|
2013-11-05 07:28:03 +00:00
|
|
|
case AUTHENTICATION_ERROR:
|
2013-11-04 13:17:09 +00:00
|
|
|
case AUTHOR_UNKNOWN:
|
|
|
|
case AUTHOR_IMPOSTOR:
|
2013-11-05 07:28:03 +00:00
|
|
|
RETURN(0);
|
2013-11-04 13:17:09 +00:00
|
|
|
}
|
2013-11-05 07:28:03 +00:00
|
|
|
FATALF("m->authorship = %d", m->authorship);
|
|
|
|
RETURN(0);
|
|
|
|
OUT();
|
2013-11-04 13:17:09 +00:00
|
|
|
}
|