struct loc_database_objects {
char* data;
- off_t offset;
size_t length;
size_t count;
};
/*
Maps arbitrary objects from the database into memory.
*/
-static int loc_database_map_objects(struct loc_database* db,
- struct loc_database_objects* objects, const size_t size,
- off_t offset, size_t length) {
+static int loc_database_map_objects(struct loc_database* db, struct loc_database_objects* objects,
+ const size_t size, const off_t offset, const size_t length) {
// Store parameters
objects->data = db->data + offset;
- objects->offset = offset;
objects->length = length;
objects->count = objects->length / size;
LOC_EXPORT int loc_database_new(struct loc_ctx* ctx, struct loc_database** database, FILE* f) {
struct loc_database* db = NULL;
- int r;
+ int r = 1;
// Fail on invalid file handle
if (!f) {
}
}
+ int sig1_valid = 0;
+ int sig2_valid = 0;
+
// Check first signature
- if (db->signature1.data) {
+ if (db->signature1.length) {
hexdump(db->ctx, db->signature1.data, db->signature1.length);
r = EVP_DigestVerifyFinal(mdctx,
if (r == 0) {
DEBUG(db->ctx, "The first signature is invalid\n");
- r = 1;
} else if (r == 1) {
DEBUG(db->ctx, "The first signature is valid\n");
- r = 0;
+ sig1_valid = 1;
} else {
ERROR(db->ctx, "Error verifying the first signature: %s\n",
ERR_error_string(ERR_get_error(), NULL));
r = -1;
+ goto CLEANUP;
}
}
// Check second signature only when the first one was invalid
- if (r && db->signature2.data) {
+ if (db->signature2.length) {
hexdump(db->ctx, db->signature2.data, db->signature2.length);
r = EVP_DigestVerifyFinal(mdctx,
if (r == 0) {
DEBUG(db->ctx, "The second signature is invalid\n");
- r = 1;
} else if (r == 1) {
DEBUG(db->ctx, "The second signature is valid\n");
- r = 0;
+ sig2_valid = 1;
} else {
ERROR(db->ctx, "Error verifying the second signature: %s\n",
ERR_error_string(ERR_get_error(), NULL));
r = -1;
+ goto CLEANUP;
}
}
INFO(db->ctx, "Signature checked in %.4fms\n",
(double)(end - start) / CLOCKS_PER_SEC * 1000);
+ // Check if at least one signature as okay
+ if (sig1_valid || sig2_valid)
+ r = 0;
+ else
+ r = 1;
+
CLEANUP:
// Cleanup
EVP_MD_CTX_free(mdctx);
// Initialise graph search
e->network_stack_depth = 1;
e->networks_visited = calloc(db->network_node_objects.count, sizeof(*e->networks_visited));
- printf("COUNT = %zu, P = %p\n", db->network_node_objects.count, e->networks_visited);
if (!e->networks_visited) {
ERROR(db->ctx, "Could not allocated visited networks: %m\n");
r = 1;