diff options
Diffstat (limited to 'auto_tests/encryptsave_test.c')
-rw-r--r-- | auto_tests/encryptsave_test.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/auto_tests/encryptsave_test.c b/auto_tests/encryptsave_test.c index 752f906f..b335cbe1 100644 --- a/auto_tests/encryptsave_test.c +++ b/auto_tests/encryptsave_test.c | |||
@@ -25,6 +25,9 @@ unsigned char known_key[crypto_box_BEFORENMBYTES] = {0x29, 0x36, 0x1c, 0x9e, 0x6 | |||
25 | char* pw = "hunter2"; | 25 | char* pw = "hunter2"; |
26 | unsigned int pwlen = 7; | 26 | unsigned int pwlen = 7; |
27 | 27 | ||
28 | unsigned char known_key2[crypto_box_BEFORENMBYTES] = {0x7a, 0xfa, 0x95, 0x45, 0x36, 0x8a, 0xa2, 0x5c, 0x40, 0xfd, 0xc0, 0xe2, 0x35, 0x8, 0x7, 0x88, 0xfa, 0xf9, 0x37, 0x86, 0xeb, 0xff, 0x50, 0x4f, 0x3, 0xe2, 0xf6, 0xd9, 0xef, 0x9, 0x17, 0x1}; | ||
29 | // same as above, except standard opslimit instead of extra ops limit for test_known_kdf, and hash pw before kdf for compat | ||
30 | |||
28 | /* cause I'm shameless */ | 31 | /* cause I'm shameless */ |
29 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) | 32 | void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) |
30 | { | 33 | { |
@@ -61,11 +64,13 @@ START_TEST(test_save_friend) | |||
61 | tox_get_address(tox2, address); | 64 | tox_get_address(tox2, address); |
62 | int test = tox_add_friend(tox1, address, (uint8_t *)"Gentoo", 7); | 65 | int test = tox_add_friend(tox1, address, (uint8_t *)"Gentoo", 7); |
63 | ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); | 66 | ck_assert_msg(test == 0, "Failed to add friend error code: %i", test); |
67 | |||
64 | uint32_t size = tox_encrypted_size(tox1); | 68 | uint32_t size = tox_encrypted_size(tox1); |
65 | uint8_t data[size]; | 69 | uint8_t data[size]; |
66 | test = tox_encrypted_save(tox1, data, "correcthorsebatterystaple", 25); | 70 | test = tox_encrypted_save(tox1, data, "correcthorsebatterystaple", 25); |
67 | ck_assert_msg(test == 0, "failed to encrypted save"); | 71 | ck_assert_msg(test == 0, "failed to encrypted save"); |
68 | ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing"); | 72 | ck_assert_msg(tox_is_save_encrypted(data) == 1, "magic number missing"); |
73 | |||
69 | Tox *tox3 = tox_new(0); | 74 | Tox *tox3 = tox_new(0); |
70 | test = tox_encrypted_load(tox3, data, size, "correcthorsebatterystaple", 25); | 75 | test = tox_encrypted_load(tox3, data, size, "correcthorsebatterystaple", 25); |
71 | ck_assert_msg(test == 0, "failed to encrypted load"); | 76 | ck_assert_msg(test == 0, "failed to encrypted load"); |
@@ -73,6 +78,41 @@ START_TEST(test_save_friend) | |||
73 | test = tox_get_client_id(tox3, 0, address2); | 78 | test = tox_get_client_id(tox3, 0, address2); |
74 | ck_assert_msg(test == 0, "no friends!"); | 79 | ck_assert_msg(test == 0, "no friends!"); |
75 | ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match!"); | 80 | ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match!"); |
81 | |||
82 | size = tox_encrypted_size(tox3); | ||
83 | uint8_t data2[size]; | ||
84 | uint8_t key[32 + crypto_box_BEFORENMBYTES]; | ||
85 | memcpy(key, salt, 32); memcpy(key+32, known_key2, crypto_box_BEFORENMBYTES); | ||
86 | test = tox_encrypted_key_save(tox3, data2, key); | ||
87 | ck_assert_msg(test == 0, "failed to encrypted save the second"); | ||
88 | ck_assert_msg(tox_is_save_encrypted(data2) == 1, "magic number the second missing"); | ||
89 | |||
90 | // first test tox_encrypted_key_load | ||
91 | Tox* tox4 = tox_new(0); | ||
92 | test = tox_encrypted_key_load(tox4, data2, size, key); | ||
93 | ck_assert_msg(test == 0, "failed to encrypted load the second"); | ||
94 | uint8_t address4[TOX_CLIENT_ID_SIZE]; | ||
95 | test = tox_get_client_id(tox4, 0, address4); | ||
96 | ck_assert_msg(test == 0, "no friends! the second"); | ||
97 | ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match! the second"); | ||
98 | |||
99 | // now test compaitibilty with tox_encrypted_load, first manually... | ||
100 | uint8_t out1[size], out2[size]; | ||
101 | printf("Trying to decrypt from pw:\n"); | ||
102 | uint32_t sz1 = tox_pass_decrypt(data2+TOX_ENC_SAVE_MAGIC_LENGTH, size-TOX_ENC_SAVE_MAGIC_LENGTH, pw, pwlen, out1); | ||
103 | uint32_t sz2 = tox_pass_key_decrypt(data2+TOX_ENC_SAVE_MAGIC_LENGTH, size-TOX_ENC_SAVE_MAGIC_LENGTH, key, out2); | ||
104 | ck_assert_msg(sz1 == sz2, "differing output sizes"); | ||
105 | ck_assert_msg(memcmp(out1, out2, sz1) == 0, "differing output data"); | ||
106 | |||
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) | ||
109 | Tox* tox5 = tox_new(0); | ||
110 | test = tox_encrypted_load(tox5, data2, size, pw, pwlen); | ||
111 | ck_assert_msg(test == 0, "failed to encrypted load the third"); | ||
112 | uint8_t address5[TOX_CLIENT_ID_SIZE]; | ||
113 | test = tox_get_client_id(tox4, 0, address5); | ||
114 | ck_assert_msg(test == 0, "no friends! the third"); | ||
115 | ck_assert_msg(memcmp(address, address2, TOX_CLIENT_ID_SIZE) == 0, "addresses don't match! the third"); | ||
76 | } | 116 | } |
77 | END_TEST | 117 | END_TEST |
78 | 118 | ||