2011-12-18 21:40:02 +00:00
|
|
|
#include "sqlite-amalgamation-3070900/sqlite3.h"
|
|
|
|
#include "sha2.h"
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2011-12-20 06:57:24 +00:00
|
|
|
typedef struct rhizome_signature {
|
|
|
|
unsigned char signature[crypto_sign_edwards25519sha512batch_BYTES
|
|
|
|
+crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES];
|
|
|
|
int signatureLength;
|
|
|
|
} rhizome_signature;
|
|
|
|
|
2011-12-18 21:34:31 +00:00
|
|
|
#define MAX_MANIFEST_VARS 256
|
|
|
|
#define MAX_MANIFEST_BYTES 8192
|
|
|
|
typedef struct rhizome_manifest {
|
|
|
|
int manifest_bytes;
|
|
|
|
unsigned char manifestdata[MAX_MANIFEST_BYTES];
|
2011-12-18 21:52:34 +00:00
|
|
|
unsigned char manifesthash[crypto_hash_sha512_BYTES];
|
2011-12-18 21:34:31 +00:00
|
|
|
|
|
|
|
/* CryptoSign key pair for this manifest.
|
|
|
|
The filename as distributed on Rhizome will be the public key
|
|
|
|
of this pair, thus ensuring that noone can tamper with a bundle
|
|
|
|
except the creator. */
|
2011-12-18 21:52:34 +00:00
|
|
|
unsigned char cryptoSignPublic[crypto_sign_edwards25519sha512batch_PUBLICKEYBYTES];
|
|
|
|
unsigned char cryptoSignSecret[crypto_sign_edwards25519sha512batch_SECRETKEYBYTES];
|
2011-12-18 21:34:31 +00:00
|
|
|
|
|
|
|
int var_count;
|
|
|
|
char *vars[MAX_MANIFEST_VARS];
|
|
|
|
char *values[MAX_MANIFEST_VARS];
|
|
|
|
|
|
|
|
int sig_count;
|
|
|
|
unsigned char *signatureBlocks[MAX_MANIFEST_VARS];
|
|
|
|
unsigned char signatureTypes[MAX_MANIFEST_VARS];
|
|
|
|
/* 0x01 = CryptoSign signature of manifest */
|
|
|
|
/* 0x02 = CryptoSign signature of signatory */
|
|
|
|
int signature_errors; /* if non-zero, then manifest should not be trusted */
|
|
|
|
|
2011-12-20 00:55:52 +00:00
|
|
|
/* Absolute path of the file associated with the manifest */
|
|
|
|
char *dataFileName;
|
|
|
|
|
2011-12-18 21:34:31 +00:00
|
|
|
/* Set non-zero after variables have been packed and
|
|
|
|
signature blocks appended.
|
2011-12-20 00:55:52 +00:00
|
|
|
All fields below may not be valid until the manifest has been finalised */
|
2011-12-18 21:34:31 +00:00
|
|
|
int finalised;
|
|
|
|
|
|
|
|
/* When finalised, we keep the filehash and maximum priority due to any
|
|
|
|
group membership handy */
|
|
|
|
long long fileLength;
|
2011-12-20 00:55:52 +00:00
|
|
|
int fileHashedP;
|
2011-12-18 21:34:31 +00:00
|
|
|
char fileHexHash[SHA512_DIGEST_STRING_LENGTH];
|
|
|
|
int fileHighestPriority;
|
|
|
|
|
2011-12-20 05:18:26 +00:00
|
|
|
/* Whether we have the secret for this manifest on hand */
|
|
|
|
int haveSecret;
|
|
|
|
/* Whether the manifest contains a signature that corresponds to the
|
|
|
|
manifest id (ie public key) */
|
|
|
|
int selfSigned;
|
|
|
|
|
2011-12-18 21:34:31 +00:00
|
|
|
/* Version of the manifest. Typically the number of milliseconds since 1970. */
|
|
|
|
long long version;
|
|
|
|
|
2011-12-20 02:54:09 +00:00
|
|
|
int group_count;
|
|
|
|
char *groups[MAX_MANIFEST_VARS];
|
|
|
|
|
2011-12-18 21:34:31 +00:00
|
|
|
} rhizome_manifest;
|
|
|
|
|
2011-12-18 21:40:02 +00:00
|
|
|
extern long long rhizome_space;
|
|
|
|
extern char *rhizome_datastore_path;
|
2011-12-18 21:34:31 +00:00
|
|
|
|
2011-12-18 21:40:02 +00:00
|
|
|
extern sqlite3 *rhizome_db;
|
2011-12-18 21:34:31 +00:00
|
|
|
|
2011-12-20 00:55:52 +00:00
|
|
|
int rhizome_opendb();
|
2011-12-18 21:34:31 +00:00
|
|
|
int rhizome_manifest_createid(rhizome_manifest *m);
|
|
|
|
int rhizome_write_manifest_file(rhizome_manifest *m,char *filename);
|
|
|
|
int rhizome_manifest_sign(rhizome_manifest *m);
|
|
|
|
int rhizome_drop_stored_file(char *id,int maximum_priority);
|
|
|
|
int rhizome_manifest_priority(char *id);
|
|
|
|
rhizome_manifest *rhizome_read_manifest_file(char *filename);
|
|
|
|
int rhizome_hash_file(char *filename,char *hash_out);
|
|
|
|
int rhizome_manifest_get(rhizome_manifest *m,char *var,char *value_out);
|
|
|
|
long long rhizome_manifest_get_ll(rhizome_manifest *m,char *var);
|
|
|
|
int rhizome_manifest_set_ll(rhizome_manifest *m,char *var,long long value);
|
|
|
|
int rhizome_manifest_set(rhizome_manifest *m,char *var,char *value);
|
|
|
|
long long rhizome_file_size(char *filename);
|
|
|
|
void rhizome_manifest_free(rhizome_manifest *m);
|
|
|
|
int rhizome_manifest_pack_variables(rhizome_manifest *m);
|
|
|
|
int rhizome_store_bundle(rhizome_manifest *m,char *associated_filename);
|
|
|
|
int rhizome_manifest_add_group(rhizome_manifest *m,char *groupid);
|
|
|
|
int rhizome_store_file(char *file,char *hash,int priortity);
|
|
|
|
char *rhizome_safe_encode(unsigned char *in,int len);
|
|
|
|
int rhizome_finish_sqlstatement(sqlite3_stmt *statement);
|
|
|
|
int rhizome_bundle_import(char *bundle,char *groups[],int verifyP, int checkFileP, int signP);
|
2011-12-20 00:55:52 +00:00
|
|
|
int rhizome_manifest_finalise(rhizome_manifest *m,int signP);
|
2011-12-20 05:18:26 +00:00
|
|
|
char *rhizome_bytes_to_hex(unsigned char *in,int byteCount);
|
|
|
|
int rhizome_hex_to_bytes(char *in,unsigned char *out,int hexChars);
|
2011-12-20 06:57:24 +00:00
|
|
|
int rhizome_store_keypair_bytes(unsigned char *p,unsigned char *s);
|
|
|
|
int rhizome_find_keypair_bytes(unsigned char *p,unsigned char *s);
|
|
|
|
rhizome_signature *rhizome_sign_hash(unsigned char *hash,unsigned char *publicKeyBytes);
|