summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-15 20:56:22 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-15 20:56:22 -0400
commitb15230583c31799d650584b05f4cfce8cd726aea (patch)
treec9d56f3fd9bad409374302e6eb92e9343cb859c1 /core
parent36cb9b003d2f9e8162c39ffa3ab1afa3743b13a4 (diff)
Fixed loading and a small problem with the length of crypto requests.
Diffstat (limited to 'core')
-rw-r--r--core/Messenger.c10
-rw-r--r--core/friend_requests.c2
-rw-r--r--core/net_crypto.c4
3 files changed, 12 insertions, 4 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index bed59d4d..4ed8bc41 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -810,10 +810,18 @@ int Messenger_load(Messenger *m, uint8_t * data, uint32_t length)
810 810
811 uint32_t i; 811 uint32_t i;
812 for (i = 0; i < num; ++i) { 812 for (i = 0; i < num; ++i) {
813 if(temp[i].status != 0) { 813 if(temp[i].status >= 3) {
814 int fnum = m_addfriend_norequest(m, temp[i].client_id); 814 int fnum = m_addfriend_norequest(m, temp[i].client_id);
815 setfriendname(m, fnum, temp[i].name); 815 setfriendname(m, fnum, temp[i].name);
816 /* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */ 816 /* set_friend_statusmessage(fnum, temp[i].statusmessage, temp[i].statusmessage_length); */
817 } else if (temp[i].status != 0) {
818 /* TODO: this is not a good way to do this. */
819 uint8_t address[FRIEND_ADDRESS_SIZE];
820 memcpy(address, temp[i].client_id, crypto_box_PUBLICKEYBYTES);
821 memcpy(address + crypto_box_PUBLICKEYBYTES, &(temp[i].friendrequest_nospam), sizeof(uint32_t));
822 uint16_t checksum = address_checksum(address, FRIEND_ADDRESS_SIZE - sizeof(checksum));
823 memcpy(address + crypto_box_PUBLICKEYBYTES + sizeof(uint32_t), &checksum, sizeof(checksum));
824 m_addfriend(m, address, temp[i].info, temp[i].info_size);
817 } 825 }
818 } 826 }
819 free(temp); 827 free(temp);
diff --git a/core/friend_requests.c b/core/friend_requests.c
index ae19ebdd..d4f8dd63 100644
--- a/core/friend_requests.c
+++ b/core/friend_requests.c
@@ -35,7 +35,7 @@ int send_friendrequest(uint8_t * public_key, uint32_t nospam_num, uint8_t * data
35{ 35{
36 if(length - sizeof(nospam_num) > MAX_DATA_SIZE) 36 if(length - sizeof(nospam_num) > MAX_DATA_SIZE)
37 return -1; 37 return -1;
38 38
39 uint8_t temp[MAX_DATA_SIZE]; 39 uint8_t temp[MAX_DATA_SIZE];
40 memcpy(temp, &nospam_num, sizeof(nospam_num)); 40 memcpy(temp, &nospam_num, sizeof(nospam_num));
41 memcpy(temp + sizeof(nospam_num), data, length); 41 memcpy(temp + sizeof(nospam_num), data, length);
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 376708ab..a05208ef 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -228,7 +228,7 @@ int create_request(uint8_t *packet, uint8_t *public_key, uint8_t *data, uint32_t
228 memcpy(temp + 1, data, length); 228 memcpy(temp + 1, data, length);
229 temp[0] = request_id; 229 temp[0] = request_id;
230 random_nonce(nonce); 230 random_nonce(nonce);
231 int len = encrypt_data(public_key, self_secret_key, nonce, temp, length, 231 int len = encrypt_data(public_key, self_secret_key, nonce, temp, length + 1,
232 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet); 232 1 + crypto_box_PUBLICKEYBYTES * 2 + crypto_box_NONCEBYTES + packet);
233 if (len == -1) 233 if (len == -1)
234 return -1; 234 return -1;
@@ -287,7 +287,7 @@ static int cryptopacket_handle(IP_Port source, uint8_t * packet, uint32_t length
287 if (len == -1 || len == 0) 287 if (len == -1 || len == 0)
288 return 1; 288 return 1;
289 if (!cryptopackethandlers[number]) return 1; 289 if (!cryptopackethandlers[number]) return 1;
290 cryptopackethandlers[number](source, public_key, data, len - 1); 290 cryptopackethandlers[number](source, public_key, data, len);
291 291
292 } else { /* if request is not for us, try routing it. */ 292 } else { /* if request is not for us, try routing it. */
293 if(route_packet(packet + 1, packet, length) == length) 293 if(route_packet(packet + 1, packet, length) == length)