summaryrefslogtreecommitdiff
path: root/ratox.c
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2014-09-22 11:57:47 +0100
committersin <sin@2f30.org>2014-09-22 11:57:47 +0100
commit3db70cdbb681a7eb22721d404c594b018114d87c (patch)
treedb34eb3464c19a0087800306a4308a7d0c467bd9 /ratox.c
parenta91dcb3ae4a5a01a9546d11563198831de1cda7e (diff)
Make sure to report when .ratox.data doesn't match our encryption config
Diffstat (limited to 'ratox.c')
-rw-r--r--ratox.c23
1 files changed, 14 insertions, 9 deletions
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);