From 3db70cdbb681a7eb22721d404c594b018114d87c Mon Sep 17 00:00:00 2001 From: sin Date: Mon, 22 Sep 2014 11:57:47 +0100 Subject: Make sure to report when .ratox.data doesn't match our encryption config --- ratox.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'ratox.c') diff --git a/ratox.c b/ratox.c index f7034c7..bc8d069 100644 --- a/ratox.c +++ b/ratox.c @@ -579,12 +579,13 @@ dataload(void) uint8_t *data; int r; - if (encryptsave == 1) - readpass(); - fp = fopen(DATAFILE, "r"); - if (!fp) + if (!fp) { + /* First time round, just set our pass */ + if (encryptsave == 1) + readpass(); return; + } fseek(fp, 0, SEEK_END); sz = ftell(fp); @@ -601,6 +602,12 @@ dataload(void) exit(EXIT_FAILURE); } + if (tox_is_data_encrypted(data) ^ encryptsave) { + fprintf(stderr, "Ensure %s matches your encryption configuration\n", + DATAFILE); + exit(EXIT_FAILURE); + } + if (encryptsave == 1) { while (1) { r = tox_encrypted_load(tox, data, sz, passphrase, pplen); @@ -611,12 +618,10 @@ dataload(void) } } else { r = tox_load(tox, data, sz); - if (r < 0) + if (r < 0) { fprintf(stderr, "tox_load() failed\n"); - else if (r == 1) - fprintf(stderr, "Found encrypted %s but encryption is disabled\n", - DATAFILE); - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); + } } free(data); -- cgit v1.2.3