diff options
| -rw-r--r-- | ot_accesslist.c | 2 | ||||
| -rw-r--r-- | ot_livesync.c | 10 | ||||
| -rw-r--r-- | ot_udp.c | 24 |
3 files changed, 27 insertions, 9 deletions
diff --git a/ot_accesslist.c b/ot_accesslist.c index f1bb885..8e9afdc 100644 --- a/ot_accesslist.c +++ b/ot_accesslist.c | |||
| @@ -197,7 +197,7 @@ int accesslist_hashisvalid(ot_hash hash) { | |||
| 197 | 197 | ||
| 198 | /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */ | 198 | /* If we found a matching hash on the main list, scan the list of dynamically deleted hashes */ |
| 199 | accesslist_delete = g_accesslist_delete; | 199 | accesslist_delete = g_accesslist_delete; |
| 200 | if ((exactmatch != NULL) && accesslist_delete && bsearch(hash, accesslist_add->list, accesslist_add->size, OT_HASH_COMPARE_SIZE, vector_compare_hash)) | 200 | if ((exactmatch != NULL) && accesslist_delete && bsearch(hash, accesslist_delete->list, accesslist_delete->size, OT_HASH_COMPARE_SIZE, vector_compare_hash)) |
| 201 | exactmatch = NULL; | 201 | exactmatch = NULL; |
| 202 | #endif | 202 | #endif |
| 203 | 203 | ||
diff --git a/ot_livesync.c b/ot_livesync.c index 269b8d8..f620592 100644 --- a/ot_livesync.c +++ b/ot_livesync.c | |||
| @@ -136,10 +136,18 @@ static void livesync_issue_peersync(sync_buffer *buf) { | |||
| 136 | static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) { | 136 | static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) { |
| 137 | size_t off = sizeof(g_tracker_id) + sizeof(uint32_t); | 137 | size_t off = sizeof(g_tracker_id) + sizeof(uint32_t); |
| 138 | 138 | ||
| 139 | /* Prepare peer record for v4mapped expansion */ | ||
| 140 | if (peer_size == OT_PEER_SIZE4) | ||
| 141 | memcpy(&ws->peer, V4mappedprefix, sizeof(V4mappedprefix)); | ||
| 142 | |||
| 139 | /* Now basic sanity checks have been done on the live sync packet | 143 | /* Now basic sanity checks have been done on the live sync packet |
| 140 | We might add more testing and logging. */ | 144 | We might add more testing and logging. */ |
| 141 | while ((ssize_t)(off + sizeof(ot_hash) + peer_size) <= ws->request_size) { | 145 | while ((ssize_t)(off + sizeof(ot_hash) + peer_size) <= ws->request_size) { |
| 142 | memcpy(&ws->peer, ws->request + off + sizeof(ot_hash), peer_size); | 146 | char *peer_ip = ws->request + off + sizeof(ot_hash); |
| 147 | if (peer_size == OT_PEER_SIZE4) | ||
| 148 | memcpy(&ws->peer[0] + sizeof(V4mappedprefix), peer_ip, peer_size); | ||
| 149 | else | ||
| 150 | memcpy(&ws->peer, peer_ip, peer_size); | ||
| 143 | ws->hash = (ot_hash *)(ws->request + off); | 151 | ws->hash = (ot_hash *)(ws->request + off); |
| 144 | 152 | ||
| 145 | if (!g_opentracker_running) | 153 | if (!g_opentracker_running) |
| @@ -25,8 +25,8 @@ | |||
| 25 | static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff }; | 25 | static const uint8_t g_static_connid[8] = { 0x23, 0x42, 0x05, 0x17, 0xde, 0x41, 0x50, 0xff }; |
| 26 | #endif | 26 | #endif |
| 27 | static uint32_t g_rijndael_round_key[44] = {0}; | 27 | static uint32_t g_rijndael_round_key[44] = {0}; |
| 28 | static uint32_t g_key_of_the_hour[2] = {0}; | 28 | static volatile uint32_t g_key_of_the_hour[2] = {0}; |
| 29 | static ot_time g_hour_of_the_key; | 29 | static volatile ot_time g_hour_of_the_key; |
| 30 | 30 | ||
| 31 | static void udp_generate_rijndael_round_key(void) { | 31 | static void udp_generate_rijndael_round_key(void) { |
| 32 | uint32_t key[16]; | 32 | uint32_t key[16]; |
| @@ -52,19 +52,29 @@ static void udp_generate_rijndael_round_key(void) { | |||
| 52 | static void udp_make_connectionid(uint32_t connid[2], const ot_ip6 remoteip, int age) { | 52 | static void udp_make_connectionid(uint32_t connid[2], const ot_ip6 remoteip, int age) { |
| 53 | uint32_t plain[4], crypt[4]; | 53 | uint32_t plain[4], crypt[4]; |
| 54 | int i; | 54 | int i; |
| 55 | uint32_t current_key_of_the_hour; | ||
| 56 | |||
| 55 | if (g_now_minutes - g_hour_of_the_key >= 60) { | 57 | if (g_now_minutes - g_hour_of_the_key >= 60) { |
| 56 | g_hour_of_the_key = g_now_minutes; | 58 | uint32_t old_key_of_the_hour = g_key_of_the_hour[0]; |
| 57 | g_key_of_the_hour[1] = g_key_of_the_hour[0]; | ||
| 58 | #ifdef WANT_ARC4RANDOM | 59 | #ifdef WANT_ARC4RANDOM |
| 59 | g_key_of_the_hour[0] = arc4random(); | 60 | uint32_t new_key_of_the_hour = arc4random(); |
| 60 | #else | 61 | #else |
| 61 | g_key_of_the_hour[0] = random(); | 62 | uint32_t new_key_of_the_hour = random(); |
| 62 | #endif | 63 | #endif |
| 64 | /* If in the meantime another thread has performed | ||
| 65 | key rotation, do not overwrite their results */ | ||
| 66 | if (g_now_minutes - g_hour_of_the_key >= 60) { | ||
| 67 | /* Upgrade en bloc */ | ||
| 68 | g_hour_of_the_key = g_now_minutes; | ||
| 69 | g_key_of_the_hour[0] = new_key_of_the_hour; | ||
| 70 | g_key_of_the_hour[1] = old_key_of_the_hour; | ||
| 71 | } | ||
| 63 | } | 72 | } |
| 64 | 73 | ||
| 65 | memcpy(plain, remoteip, sizeof(plain)); | 74 | memcpy(plain, remoteip, sizeof(plain)); |
| 75 | current_key_of_the_hour = g_key_of_the_hour[age]; | ||
| 66 | for (i = 0; i < 4; ++i) | 76 | for (i = 0; i < 4; ++i) |
| 67 | plain[i] ^= g_key_of_the_hour[age]; | 77 | plain[i] ^= current_key_of_the_hour; |
| 68 | rijndaelEncrypt128(g_rijndael_round_key, (uint8_t *)plain, (uint8_t *)crypt); | 78 | rijndaelEncrypt128(g_rijndael_round_key, (uint8_t *)plain, (uint8_t *)crypt); |
| 69 | connid[0] = crypt[0] ^ crypt[1]; | 79 | connid[0] = crypt[0] ^ crypt[1]; |
| 70 | connid[1] = crypt[2] ^ crypt[3]; | 80 | connid[1] = crypt[2] ^ crypt[3]; |
