Commit fa4898d0 authored by Michael Tremer's avatar Michael Tremer

database: Correct error code on verification

If the first signature check returned an error, the error code was
overwritten by the second signature check, returning an overall
incorrect result.
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 1d55c508
...@@ -641,6 +641,9 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) { ...@@ -641,6 +641,9 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) {
} }
} }
int sig1_valid = 0;
int sig2_valid = 0;
// Check first signature // Check first signature
if (db->signature1.data) { if (db->signature1.data) {
hexdump(db->ctx, db->signature1.data, db->signature1.length); hexdump(db->ctx, db->signature1.data, db->signature1.length);
...@@ -650,14 +653,14 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) { ...@@ -650,14 +653,14 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) {
if (r == 0) { if (r == 0) {
DEBUG(db->ctx, "The first signature is invalid\n"); DEBUG(db->ctx, "The first signature is invalid\n");
r = 1;
} else if (r == 1) { } else if (r == 1) {
DEBUG(db->ctx, "The first signature is valid\n"); DEBUG(db->ctx, "The first signature is valid\n");
r = 0; sig1_valid = 1;
} else { } else {
ERROR(db->ctx, "Error verifying the first signature: %s\n", ERROR(db->ctx, "Error verifying the first signature: %s\n",
ERR_error_string(ERR_get_error(), NULL)); ERR_error_string(ERR_get_error(), NULL));
r = -1; r = -1;
goto CLEANUP;
} }
} }
...@@ -670,14 +673,14 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) { ...@@ -670,14 +673,14 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) {
if (r == 0) { if (r == 0) {
DEBUG(db->ctx, "The second signature is invalid\n"); DEBUG(db->ctx, "The second signature is invalid\n");
r = 1;
} else if (r == 1) { } else if (r == 1) {
DEBUG(db->ctx, "The second signature is valid\n"); DEBUG(db->ctx, "The second signature is valid\n");
r = 0; sig2_valid = 1;
} else { } else {
ERROR(db->ctx, "Error verifying the second signature: %s\n", ERROR(db->ctx, "Error verifying the second signature: %s\n",
ERR_error_string(ERR_get_error(), NULL)); ERR_error_string(ERR_get_error(), NULL));
r = -1; r = -1;
goto CLEANUP;
} }
} }
...@@ -685,6 +688,12 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) { ...@@ -685,6 +688,12 @@ LOC_EXPORT int loc_database_verify(struct loc_database* db, FILE* f) {
INFO(db->ctx, "Signature checked in %.4fms\n", INFO(db->ctx, "Signature checked in %.4fms\n",
(double)(end - start) / CLOCKS_PER_SEC * 1000); (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:
// Cleanup // Cleanup
EVP_MD_CTX_free(mdctx); EVP_MD_CTX_free(mdctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment