mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-05-02 08:42:55 +00:00
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:
parent
6d2eb268ed
commit
ccacd19dfa
@ -80,6 +80,7 @@ static void directory_send(struct subscriber *directory_service, struct subscrib
|
|||||||
|
|
||||||
// send a registration packet for each unlocked identity
|
// send a registration packet for each unlocked identity
|
||||||
static void directory_send_keyring(struct subscriber *directory_service){
|
static void directory_send_keyring(struct subscriber *directory_service){
|
||||||
|
assert(keyring != NULL);
|
||||||
keyring_iterator it;
|
keyring_iterator it;
|
||||||
keyring_iterator_start(keyring, &it);
|
keyring_iterator_start(keyring, &it);
|
||||||
while(keyring_next_keytype(&it, KEYTYPE_DID)){
|
while(keyring_next_keytype(&it, KEYTYPE_DID)){
|
||||||
|
@ -92,6 +92,7 @@ JNIEXPORT jint JNICALL Java_org_servalproject_servaldna_ServalDCommand_server(
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
{
|
{
|
||||||
|
assert(keyring == NULL);
|
||||||
const char *cpin = keyring_pin?(*env)->GetStringUTFChars(env, keyring_pin, NULL):NULL;
|
const char *cpin = keyring_pin?(*env)->GetStringUTFChars(env, keyring_pin, NULL):NULL;
|
||||||
if (cpin != NULL){
|
if (cpin != NULL){
|
||||||
keyring = keyring_open_instance(cpin);
|
keyring = keyring_open_instance(cpin);
|
||||||
|
@ -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);
|
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 > 0);
|
||||||
assert(r->u.sendmsg.message.length <= MESSAGE_PLY_MAX_LEN);
|
assert(r->u.sendmsg.message.length <= MESSAGE_PLY_MAX_LEN);
|
||||||
|
assert(keyring != NULL);
|
||||||
keyring_identity *id = keyring_find_identity(keyring, &r->bid);
|
keyring_identity *id = keyring_find_identity(keyring, &r->bid);
|
||||||
if (!id){
|
if (!id){
|
||||||
http_request_simple_response(&r->http, 500, "TODO, detailed errors");
|
http_request_simple_response(&r->http, 500, "TODO, detailed errors");
|
||||||
|
4
meshms.c
4
meshms.c
@ -640,6 +640,7 @@ enum meshms_status meshms_conversations_list(const keyring_identity *id, const s
|
|||||||
enum meshms_status status = MESHMS_STATUS_ERROR;
|
enum meshms_status status = MESHMS_STATUS_ERROR;
|
||||||
rhizome_manifest *m=NULL;
|
rhizome_manifest *m=NULL;
|
||||||
|
|
||||||
|
assert(keyring != NULL);
|
||||||
assert(id || my_sid);
|
assert(id || my_sid);
|
||||||
if (!my_sid){
|
if (!my_sid){
|
||||||
my_sid = id->box_pk;
|
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)
|
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);
|
bzero(iter, sizeof *iter);
|
||||||
DEBUGF(meshms, "iter=%p me=%s them=%s", iter,
|
DEBUGF(meshms, "iter=%p me=%s them=%s", iter,
|
||||||
me ? alloca_tohex_sid_t(*me) : "NULL",
|
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)
|
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);
|
assert(message_len != 0);
|
||||||
if (message_len > MESSAGE_PLY_MAX_LEN) {
|
if (message_len > MESSAGE_PLY_MAX_LEN) {
|
||||||
WHY("message too long");
|
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)
|
enum meshms_status meshms_mark_read(const sid_t *sender, const sid_t *recipient, uint64_t offset)
|
||||||
{
|
{
|
||||||
|
assert(keyring != NULL);
|
||||||
rhizome_manifest *m=NULL;
|
rhizome_manifest *m=NULL;
|
||||||
enum meshms_status status = MESHMS_STATUS_ERROR;
|
enum meshms_status status = MESHMS_STATUS_ERROR;
|
||||||
struct meshms_conversations *conv = NULL;
|
struct meshms_conversations *conv = NULL;
|
||||||
|
@ -57,6 +57,7 @@ static __thread struct subscriber *my_subscriber=NULL;
|
|||||||
struct subscriber *get_my_subscriber(bool_t create){
|
struct subscriber *get_my_subscriber(bool_t create){
|
||||||
if (!serverMode)
|
if (!serverMode)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
assert(keyring != NULL);
|
||||||
if (my_subscriber && my_subscriber->reachable != REACHABLE_SELF)
|
if (my_subscriber && my_subscriber->reachable != REACHABLE_SELF)
|
||||||
my_subscriber = NULL;
|
my_subscriber = NULL;
|
||||||
if (!my_subscriber){
|
if (!my_subscriber){
|
||||||
|
@ -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,
|
static int mdp_process_identity_request(struct socket_address *client, struct mdp_header *header,
|
||||||
struct overlay_buffer *payload)
|
struct overlay_buffer *payload)
|
||||||
{
|
{
|
||||||
|
assert(keyring != NULL);
|
||||||
if (ob_remaining(payload)<sizeof(struct mdp_identity_request)){
|
if (ob_remaining(payload)<sizeof(struct mdp_identity_request)){
|
||||||
mdp_reply_error(client, header);
|
mdp_reply_error(client, header);
|
||||||
return WHY("Request too small");
|
return WHY("Request too small");
|
||||||
}
|
}
|
||||||
struct mdp_identity_request request;
|
struct mdp_identity_request request;
|
||||||
ob_get_bytes(payload, (uint8_t *)&request, sizeof(request));
|
ob_get_bytes(payload, (uint8_t *)&request, sizeof(request));
|
||||||
|
|
||||||
switch(request.action){
|
switch(request.action){
|
||||||
case ACTION_LOCK:
|
case ACTION_LOCK:
|
||||||
switch (request.type){
|
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,
|
static int mdp_search_identities(struct socket_address *client, struct mdp_header *header,
|
||||||
struct overlay_buffer *payload)
|
struct overlay_buffer *payload)
|
||||||
{
|
{
|
||||||
|
assert(keyring != NULL);
|
||||||
keyring_iterator it;
|
keyring_iterator it;
|
||||||
keyring_iterator_start(keyring, &it);
|
keyring_iterator_start(keyring, &it);
|
||||||
|
|
||||||
|
@ -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)
|
static int overlay_mdp_service_dnalookup(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
||||||
{
|
{
|
||||||
IN();
|
IN();
|
||||||
|
assert(keyring != NULL);
|
||||||
keyring_iterator it;
|
keyring_iterator it;
|
||||||
keyring_iterator_start(keyring, &it);
|
keyring_iterator_start(keyring, &it);
|
||||||
char did[64+1];
|
char did[64+1];
|
||||||
|
@ -199,6 +199,7 @@ static int keyring_process_challenge(keyring_file *k, struct subscriber *subscri
|
|||||||
DEFINE_BINDING(MDP_PORT_KEYMAPREQUEST, keyring_mapping_request);
|
DEFINE_BINDING(MDP_PORT_KEYMAPREQUEST, keyring_mapping_request);
|
||||||
static int keyring_mapping_request(struct internal_mdp_header *header, struct overlay_buffer *payload)
|
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
|
/* The authcryption of the MDP frame proves that the SAS key is owned by the
|
||||||
owner of the SID, and so is absolutely compulsory. */
|
owner of the SID, and so is absolutely compulsory. */
|
||||||
|
@ -1482,6 +1482,7 @@ struct rhizome_bundle_result rhizome_fill_manifest(rhizome_manifest *m, const ch
|
|||||||
int rhizome_lookup_author(rhizome_manifest *m)
|
int rhizome_lookup_author(rhizome_manifest *m)
|
||||||
{
|
{
|
||||||
IN();
|
IN();
|
||||||
|
assert(keyring != NULL);
|
||||||
switch (m->authorship) {
|
switch (m->authorship) {
|
||||||
case AUTHOR_LOCAL:
|
case AUTHOR_LOCAL:
|
||||||
case AUTHOR_AUTHENTIC:
|
case AUTHOR_AUTHENTIC:
|
||||||
|
@ -181,6 +181,7 @@ static enum rhizome_bundle_authorship set_authentic(rhizome_manifest *m, const k
|
|||||||
* and finally update the database with the result.
|
* 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){
|
static enum rhizome_bundle_authorship try_author(rhizome_manifest *m, const keyring_identity *id, const sid_t *sid){
|
||||||
|
assert(keyring != NULL);
|
||||||
if (!sid)
|
if (!sid)
|
||||||
return AUTHOR_UNKNOWN;
|
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)
|
void rhizome_authenticate_author(rhizome_manifest *m)
|
||||||
{
|
{
|
||||||
IN();
|
IN();
|
||||||
|
assert(keyring != NULL);
|
||||||
DEBUGF(rhizome, "authenticate author for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->keypair.public_key) : "(none)");
|
DEBUGF(rhizome, "authenticate author for bid=%s", m->has_id ? alloca_tohex_rhizome_bid_t(m->keypair.public_key) : "(none)");
|
||||||
switch (m->authorship) {
|
switch (m->authorship) {
|
||||||
case ANONYMOUS:
|
case ANONYMOUS:
|
||||||
@ -320,6 +322,7 @@ void rhizome_authenticate_author(rhizome_manifest *m)
|
|||||||
int rhizome_manifest_add_bundle_key(rhizome_manifest *m)
|
int rhizome_manifest_add_bundle_key(rhizome_manifest *m)
|
||||||
{
|
{
|
||||||
IN();
|
IN();
|
||||||
|
assert(keyring != NULL);
|
||||||
assert(m->haveSecret);
|
assert(m->haveSecret);
|
||||||
switch (m->authorship) {
|
switch (m->authorship) {
|
||||||
case ANONYMOUS: // there can be no BK field without an author
|
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)
|
int rhizome_derive_payload_key(rhizome_manifest *m)
|
||||||
{
|
{
|
||||||
|
assert(keyring != NULL);
|
||||||
assert(m->payloadEncryption == PAYLOAD_ENCRYPTED);
|
assert(m->payloadEncryption == PAYLOAD_ENCRYPTED);
|
||||||
unsigned char hash[crypto_hash_sha512_BYTES];
|
unsigned char hash[crypto_hash_sha512_BYTES];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user