diff options
-rw-r--r-- | auto_tests/encryptsave_test.c | 8 | ||||
-rw-r--r-- | toxcore/tox.h | 8 | ||||
-rw-r--r-- | toxencryptsave/toxencryptsave.c | 8 | ||||
-rw-r--r-- | toxencryptsave/toxencryptsave.h | 58 |
4 files changed, 63 insertions, 19 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index de78a0c2..e2f41f43 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -55,7 +55,7 @@ END_TEST | |||
55 | 55 | ||
56 | START_TEST(test_save_friend) | 56 | START_TEST(test_save_friend) |
57 | { | 57 | { |
58 | TOX_ERR_NEW err = TOX_ERR_NEW_OK; | 58 | TOX_ERR_ENCRYPTED_NEW err = TOX_ERR_ENCRYPTED_NEW_OK; |
59 | Tox *tox1 = tox_new(0, 0, 0, 0); | 59 | Tox *tox1 = tox_new(0, 0, 0, 0); |
60 | Tox *tox2 = tox_new(0, 0, 0, 0); | 60 | Tox *tox2 = tox_new(0, 0, 0, 0); |
61 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); | 61 | ck_assert_msg(tox1 || tox2, "Failed to create 2 tox instances"); |
@@ -73,7 +73,7 @@ START_TEST(test_save_friend) | |||
73 | //ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing"); | 73 | //ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing"); |
74 | 74 | ||
75 | Tox *tox3 = tox_encrypted_new(0, data, size, "correcthorsebatterystaple", 25, &err); | 75 | Tox *tox3 = tox_encrypted_new(0, data, size, "correcthorsebatterystaple", 25, &err); |
76 | ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new"); | 76 | ck_assert_msg(err == TOX_ERR_ENCRYPTED_NEW_OK, "failed to encrypted new"); |
77 | uint8_t address2[TOX_PUBLIC_KEY_SIZE]; | 77 | uint8_t address2[TOX_PUBLIC_KEY_SIZE]; |
78 | test = tox_friend_get_public_key(tox3, 0, address2, 0); | 78 | test = tox_friend_get_public_key(tox3, 0, address2, 0); |
79 | ck_assert_msg(test == 1, "no friends!"); | 79 | ck_assert_msg(test == 1, "no friends!"); |
@@ -90,7 +90,7 @@ START_TEST(test_save_friend) | |||
90 | 90 | ||
91 | // first test tox_encrypted_key_new | 91 | // first test tox_encrypted_key_new |
92 | Tox *tox4 = tox_encrypted_key_new(0, data2, size, key, &err); | 92 | Tox *tox4 = tox_encrypted_key_new(0, data2, size, key, &err); |
93 | ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new the second"); | 93 | ck_assert_msg(err == TOX_ERR_ENCRYPTED_NEW_OK, "failed to encrypted new the second"); |
94 | uint8_t address4[TOX_PUBLIC_KEY_SIZE]; | 94 | uint8_t address4[TOX_PUBLIC_KEY_SIZE]; |
95 | test = tox_friend_get_public_key(tox4, 0, address4, 0); | 95 | test = tox_friend_get_public_key(tox4, 0, address4, 0); |
96 | ck_assert_msg(test == 1, "no friends! the second"); | 96 | ck_assert_msg(test == 1, "no friends! the second"); |
@@ -107,7 +107,7 @@ START_TEST(test_save_friend) | |||
107 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste | 107 | // and now with the code in use (I only bothered with manually to debug this, and it seems a waste |
108 | // to remove the manual check now that it's there) | 108 | // to remove the manual check now that it's there) |
109 | Tox *tox5 = tox_encrypted_new(0, data2, size, pw, pwlen, &err); | 109 | Tox *tox5 = tox_encrypted_new(0, data2, size, pw, pwlen, &err); |
110 | ck_assert_msg(err == TOX_ERR_NEW_OK, "failed to encrypted new the third"); | 110 | ck_assert_msg(err == TOX_ERR_ENCRYPTED_NEW_OK, "failed to encrypted new the third"); |
111 | uint8_t address5[TOX_PUBLIC_KEY_SIZE]; | 111 | uint8_t address5[TOX_PUBLIC_KEY_SIZE]; |
112 | test = tox_friend_get_public_key(tox4, 0, address5, 0); | 112 | test = tox_friend_get_public_key(tox4, 0, address5, 0); |
113 | ck_assert_msg(test == 1, "no friends! the third"); | 113 | ck_assert_msg(test == 1, "no friends! the third"); |
diff --git a/toxcore/tox.h b/toxcore/tox.h index f645282e..e9d007db 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h | |||
@@ -488,14 +488,6 @@ typedef enum TOX_ERR_NEW { | |||
488 | */ | 488 | */ |
489 | TOX_ERR_NEW_LOAD_ENCRYPTED, | 489 | TOX_ERR_NEW_LOAD_ENCRYPTED, |
490 | /** | 490 | /** |
491 | * The encrypted byte array could not be decrypted. Either the data was | ||
492 | * corrupt or the password/key was incorrect. | ||
493 | * | ||
494 | * NOTE: This error code is only set by tox_encrypted_new() and | ||
495 | * tox_encrypted_key_new(), in the toxencryptsave module. | ||
496 | */ | ||
497 | TOX_ERR_NEW_LOAD_DECRYPTION_FAILED, | ||
498 | /** | ||
499 | * The data format was invalid. This can happen when loading data that was | 491 | * The data format was invalid. This can happen when loading data that was |
500 | * saved by an older version of Tox, or when the data has been corrupted. | 492 | * saved by an older version of Tox, or when the data has been corrupted. |
501 | * When loading from badly formatted data, some data may have been loaded, | 493 | * When loading from badly formatted data, some data may have been loaded, |
diff --git a/toxencryptsave/toxencryptsave.c b/toxencryptsave/toxencryptsave.c index 587c7048..874f0fd0 100644 --- a/toxencryptsave/toxencryptsave.c +++ b/toxencryptsave/toxencryptsave.c | |||
@@ -300,14 +300,14 @@ int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, | |||
300 | * returns NULL on failure; see the documentation in toxcore/tox.h. | 300 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
301 | */ | 301 | */ |
302 | Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, | 302 | Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, |
303 | size_t pplength, TOX_ERR_NEW *error) | 303 | size_t pplength, TOX_ERR_ENCRYPTED_NEW *error) |
304 | { | 304 | { |
305 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 305 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
306 | uint8_t temp_data[decrypt_length]; | 306 | uint8_t temp_data[decrypt_length]; |
307 | 307 | ||
308 | if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) | 308 | if (tox_pass_decrypt(data, length, passphrase, pplength, temp_data) |
309 | != decrypt_length) { | 309 | != decrypt_length) { |
310 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); | 310 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED); |
311 | return NULL; | 311 | return NULL; |
312 | } | 312 | } |
313 | 313 | ||
@@ -320,14 +320,14 @@ Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, s | |||
320 | * returns NULL on failure; see the documentation in toxcore/tox.h. | 320 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
321 | */ | 321 | */ |
322 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, | 322 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, |
323 | TOX_ERR_NEW *error) | 323 | TOX_ERR_ENCRYPTED_NEW *error) |
324 | { | 324 | { |
325 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; | 325 | uint32_t decrypt_length = length - TOX_PASS_ENCRYPTION_EXTRA_LENGTH; |
326 | uint8_t temp_data[decrypt_length]; | 326 | uint8_t temp_data[decrypt_length]; |
327 | 327 | ||
328 | if (tox_pass_key_decrypt(data, length, key, temp_data) | 328 | if (tox_pass_key_decrypt(data, length, key, temp_data) |
329 | != decrypt_length) { | 329 | != decrypt_length) { |
330 | SET_ERROR_PARAMETER(error, TOX_ERR_NEW_LOAD_DECRYPTION_FAILED); | 330 | SET_ERROR_PARAMETER(error, TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED); |
331 | return NULL; | 331 | return NULL; |
332 | } | 332 | } |
333 | 333 | ||
diff --git a/toxencryptsave/toxencryptsave.h b/toxencryptsave/toxencryptsave.h index 9b613cac..db272592 100644 --- a/toxencryptsave/toxencryptsave.h +++ b/toxencryptsave/toxencryptsave.h | |||
@@ -35,7 +35,6 @@ extern "C" { | |||
35 | #define TOX_DEFINED | 35 | #define TOX_DEFINED |
36 | typedef struct Tox Tox; | 36 | typedef struct Tox Tox; |
37 | struct Tox_Options; | 37 | struct Tox_Options; |
38 | typedef enum TOX_ERR_NEW TOX_ERR_NEW; | ||
39 | #endif | 38 | #endif |
40 | 39 | ||
41 | // these functions provide access to these defines in toxencryptsave.c, which | 40 | // these functions provide access to these defines in toxencryptsave.c, which |
@@ -110,13 +109,66 @@ int tox_encrypted_save(const Tox *tox, uint8_t *data, uint8_t *passphrase, uint3 | |||
110 | */ | 109 | */ |
111 | int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); | 110 | int tox_pass_decrypt(const uint8_t *data, uint32_t length, uint8_t *passphrase, uint32_t pplength, uint8_t *out); |
112 | 111 | ||
112 | typedef enum TOX_ERR_ENCRYPTED_NEW { | ||
113 | TOX_ERR_ENCRYPTED_NEW_OK, | ||
114 | TOX_ERR_ENCRYPTED_NEW_NULL, | ||
115 | /** | ||
116 | * The function was unable to allocate enough memory to store the internal | ||
117 | * structures for the Tox object. | ||
118 | */ | ||
119 | TOX_ERR_ENCRYPTED_NEW_MALLOC, | ||
120 | /** | ||
121 | * The function was unable to bind to a port. This may mean that all ports | ||
122 | * have already been bound, e.g. by other Tox instances, or it may mean | ||
123 | * a permission error. You may be able to gather more information from errno. | ||
124 | */ | ||
125 | TOX_ERR_ENCRYPTED_NEW_PORT_ALLOC, | ||
126 | /** | ||
127 | * proxy_type was invalid. | ||
128 | */ | ||
129 | TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_TYPE, | ||
130 | /** | ||
131 | * proxy_type was valid but the proxy_host passed had an invalid format | ||
132 | * or was NULL. | ||
133 | */ | ||
134 | TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_HOST, | ||
135 | /** | ||
136 | * proxy_type was valid, but the proxy_port was invalid. | ||
137 | */ | ||
138 | TOX_ERR_ENCRYPTED_NEW_PROXY_BAD_PORT, | ||
139 | /** | ||
140 | * The proxy host passed could not be resolved. | ||
141 | */ | ||
142 | TOX_ERR_ENCRYPTED_NEW_PROXY_NOT_FOUND, | ||
143 | /** | ||
144 | * The byte array to be loaded contained an encrypted save. | ||
145 | */ | ||
146 | TOX_ERR_ENCRYPTED_NEW_LOAD_ENCRYPTED, | ||
147 | /** | ||
148 | * The data format was invalid. This can happen when loading data that was | ||
149 | * saved by an older version of Tox, or when the data has been corrupted. | ||
150 | * When loading from badly formatted data, some data may have been loaded, | ||
151 | * and the rest is discarded. Passing an invalid length parameter also | ||
152 | * causes this error. | ||
153 | */ | ||
154 | TOX_ERR_ENCRYPTED_NEW_LOAD_BAD_FORMAT, | ||
155 | /** | ||
156 | * The encrypted byte array could not be decrypted. Either the data was | ||
157 | * corrupt or the password/key was incorrect. | ||
158 | * | ||
159 | * NOTE: This error code is only set by tox_encrypted_new() and | ||
160 | * tox_encrypted_key_new(), in the toxencryptsave module. | ||
161 | */ | ||
162 | TOX_ERR_ENCRYPTED_NEW_LOAD_DECRYPTION_FAILED | ||
163 | } TOX_ERR_ENCRYPTED_NEW; | ||
164 | |||
113 | /* Load the new messenger from encrypted data of size length. | 165 | /* Load the new messenger from encrypted data of size length. |
114 | * All other arguments are like toxcore/tox_new(). | 166 | * All other arguments are like toxcore/tox_new(). |
115 | * | 167 | * |
116 | * returns NULL on failure; see the documentation in toxcore/tox.h. | 168 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
117 | */ | 169 | */ |
118 | Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, | 170 | Tox *tox_encrypted_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *passphrase, |
119 | size_t pplength, TOX_ERR_NEW *error); | 171 | size_t pplength, TOX_ERR_ENCRYPTED_NEW *error); |
120 | 172 | ||
121 | 173 | ||
122 | /******************************* BEGIN PART 1 ******************************* | 174 | /******************************* BEGIN PART 1 ******************************* |
@@ -190,7 +242,7 @@ int tox_pass_key_decrypt(const uint8_t *data, uint32_t length, const uint8_t *ke | |||
190 | * returns NULL on failure; see the documentation in toxcore/tox.h. | 242 | * returns NULL on failure; see the documentation in toxcore/tox.h. |
191 | */ | 243 | */ |
192 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, | 244 | Tox *tox_encrypted_key_new(const struct Tox_Options *options, const uint8_t *data, size_t length, uint8_t *key, |
193 | TOX_ERR_NEW *error); | 245 | TOX_ERR_ENCRYPTED_NEW *error); |
194 | 246 | ||
195 | 247 | ||
196 | /* Determines whether or not the given data is encrypted (by checking the magic number) | 248 | /* Determines whether or not the given data is encrypted (by checking the magic number) |