Add global keyring assertions

Many functions require that the global 'keyring' pointer is set,
but there were no assertions to document this precondition.
This commit is contained in:
Andrew Bettison 2016-11-11 10:42:49 +10:30
parent 6d2eb268ed
commit ccacd19dfa
10 changed files with 18 additions and 2 deletions

View File

@ -80,6 +80,7 @@ static void directory_send(struct subscriber *directory_service, struct subscrib
// send a registration packet for each unlocked identity
static void directory_send_keyring(struct subscriber *directory_service){
assert(keyring != NULL);
keyring_iterator it;
keyring_iterator_start(keyring, &it);
while(keyring_next_keytype(&it, KEYTYPE_DID)){

View File

@ -92,6 +92,7 @@ JNIEXPORT jint JNICALL Java_org_servalproject_servaldna_ServalDCommand_server(
int ret = -1;
{
assert(keyring == NULL);
const char *cpin = keyring_pin?(*env)->GetStringUTFChars(env, keyring_pin, NULL):NULL;
if (cpin != NULL){
keyring = keyring_open_instance(cpin);

View File

@ -75,7 +75,7 @@ static int send_content_end(struct http_request *hr)
return http_response_form_part(r, 400, "Missing", PART_MESSAGE, NULL, 0);
assert(r->u.sendmsg.message.length > 0);
assert(r->u.sendmsg.message.length <= MESSAGE_PLY_MAX_LEN);
assert(keyring != NULL);
keyring_identity *id = keyring_find_identity(keyring, &r->bid);
if (!id){
http_request_simple_response(&r->http, 500, "TODO, detailed errors");

View File

@ -640,6 +640,7 @@ enum meshms_status meshms_conversations_list(const keyring_identity *id, const s
enum meshms_status status = MESHMS_STATUS_ERROR;
rhizome_manifest *m=NULL;
assert(keyring != NULL);
assert(id || my_sid);
if (!my_sid){
my_sid = id->box_pk;
@ -688,6 +689,7 @@ void meshms_conversation_iterator_advance(struct meshms_conversation_iterator *i
enum meshms_status meshms_message_iterator_open(struct meshms_message_iterator *iter, const sid_t *me, const sid_t *them)
{
assert(keyring != NULL);
bzero(iter, sizeof *iter);
DEBUGF(meshms, "iter=%p me=%s them=%s", iter,
me ? alloca_tohex_sid_t(*me) : "NULL",
@ -863,6 +865,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
enum meshms_status meshms_send_message(const sid_t *sender, const sid_t *recipient, const char *message, size_t message_len)
{
assert(keyring != NULL);
assert(message_len != 0);
if (message_len > MESSAGE_PLY_MAX_LEN) {
WHY("message too long");
@ -942,6 +945,7 @@ end:
enum meshms_status meshms_mark_read(const sid_t *sender, const sid_t *recipient, uint64_t offset)
{
assert(keyring != NULL);
rhizome_manifest *m=NULL;
enum meshms_status status = MESHMS_STATUS_ERROR;
struct meshms_conversations *conv = NULL;

View File

@ -57,6 +57,7 @@ static __thread struct subscriber *my_subscriber=NULL;
struct subscriber *get_my_subscriber(bool_t create){
if (!serverMode)
return NULL;
assert(keyring != NULL);
if (my_subscriber && my_subscriber->reachable != REACHABLE_SELF)
my_subscriber = NULL;
if (!my_subscriber){

View File

@ -1197,13 +1197,14 @@ static void overlay_mdp_scan(struct sched_ent *alarm)
static int mdp_process_identity_request(struct socket_address *client, struct mdp_header *header,
struct overlay_buffer *payload)
{
assert(keyring != NULL);
if (ob_remaining(payload)<sizeof(struct mdp_identity_request)){
mdp_reply_error(client, header);
return WHY("Request too small");
}
struct mdp_identity_request request;
ob_get_bytes(payload, (uint8_t *)&request, sizeof(request));
switch(request.action){
case ACTION_LOCK:
switch (request.type){
@ -1259,6 +1260,7 @@ static int mdp_process_identity_request(struct socket_address *client, struct md
static int mdp_search_identities(struct socket_address *client, struct mdp_header *header,
struct overlay_buffer *payload)
{
assert(keyring != NULL);
keyring_iterator it;
keyring_iterator_start(keyring, &it);

View File

@ -28,6 +28,7 @@ DEFINE_BINDING(MDP_PORT_DNALOOKUP, overlay_mdp_service_dnalookup);
static int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, struct overlay_buffer *payload)
{
IN();
assert(keyring != NULL);
keyring_iterator it;
keyring_iterator_start(keyring, &it);
char did[64+1];

View File

@ -199,6 +199,7 @@ static int keyring_process_challenge(keyring_file *k, struct subscriber *subscri
DEFINE_BINDING(MDP_PORT_KEYMAPREQUEST, keyring_mapping_request);
static int keyring_mapping_request(struct internal_mdp_header *header, struct overlay_buffer *payload)
{
assert(keyring != NULL);
/* The authcryption of the MDP frame proves that the SAS key is owned by the
owner of the SID, and so is absolutely compulsory. */

View File

@ -1482,6 +1482,7 @@ struct rhizome_bundle_result rhizome_fill_manifest(rhizome_manifest *m, const ch
int rhizome_lookup_author(rhizome_manifest *m)
{
IN();
assert(keyring != NULL);
switch (m->authorship) {
case AUTHOR_LOCAL:
case AUTHOR_AUTHENTIC:

View File

@ -181,6 +181,7 @@ static enum rhizome_bundle_authorship set_authentic(rhizome_manifest *m, const k
* and finally update the database with the result.
*/
static enum rhizome_bundle_authorship try_author(rhizome_manifest *m, const keyring_identity *id, const sid_t *sid){
assert(keyring != NULL);
if (!sid)
return AUTHOR_UNKNOWN;
@ -254,6 +255,7 @@ static enum rhizome_bundle_authorship try_author(rhizome_manifest *m, const keyr
void rhizome_authenticate_author(rhizome_manifest *m)
{
IN();
assert(keyring != NULL);
DEBUGF(rhizome, "authenticate author for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->keypair.public_key) : "(none)");
switch (m->authorship) {
case ANONYMOUS:
@ -320,6 +322,7 @@ void rhizome_authenticate_author(rhizome_manifest *m)
int rhizome_manifest_add_bundle_key(rhizome_manifest *m)
{
IN();
assert(keyring != NULL);
assert(m->haveSecret);
switch (m->authorship) {
case ANONYMOUS: // there can be no BK field without an author
@ -564,6 +567,7 @@ int rhizome_crypt_xor_block(unsigned char *buffer, size_t buffer_size, uint64_t
*/
int rhizome_derive_payload_key(rhizome_manifest *m)
{
assert(keyring != NULL);
assert(m->payloadEncryption == PAYLOAD_ENCRYPTED);
unsigned char hash[crypto_hash_sha512_BYTES];