aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-04-27 19:14:00 +0000
committerBart Polot <bart@net.in.tum.de>2015-04-27 19:14:00 +0000
commitd00ca8d9b73b5c74b7659a2d254012c7e526280a (patch)
tree6320d589c5d3a15a64a584a96229608b049a8801 /src/cadet
parent728f4f354734161d5b90704c8468258100f46917 (diff)
downloadgnunet-d00ca8d9b73b5c74b7659a2d254012c7e526280a.tar.gz
gnunet-d00ca8d9b73b5c74b7659a2d254012c7e526280a.zip
- added basic axolotl support
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_protocol.h42
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c205
-rw-r--r--src/cadet/gnunet-service-cadet_connection.h38
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c5
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c22
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.h17
6 files changed, 306 insertions, 23 deletions
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index dacf3d884..dc91af304 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -238,6 +238,48 @@ struct GNUNET_CADET_Encrypted
238 238
239 239
240/** 240/**
241 * Axolotl tunnel message.
242 */
243struct GNUNET_CADET_AX
244{
245 /**
246 * Type: GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
247 */
248 struct GNUNET_MessageHeader header;
249
250 /**
251 * ID of the connection.
252 */
253 struct GNUNET_CADET_Hash cid;
254
255 /**
256 * ID of the packet (hop by hop).
257 */
258 uint32_t pid GNUNET_PACKED;
259
260 /**
261 * Number of hops to live.
262 */
263 uint32_t ttl GNUNET_PACKED;
264
265 /**
266 * Initialization Vector for payload encryption.
267 */
268 uint32_t iv GNUNET_PACKED;
269
270 /**
271 * MAC of the encrypted message, used to verify message integrity.
272 * Everything after this value will be encrypted and authenticated.
273 */
274 struct GNUNET_CADET_Hash hmac;
275
276 /**
277 * Encrypted content follows.
278 */
279};
280
281
282/**
241 * Message to create a Channel. 283 * Message to create a Channel.
242 */ 284 */
243struct GNUNET_CADET_ChannelCreate 285struct GNUNET_CADET_ChannelCreate
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index 80c5267b8..ddb1a6c60 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -2347,6 +2347,25 @@ handle_cadet_kx (const struct GNUNET_PeerIdentity *peer,
2347 2347
2348 2348
2349/** 2349/**
2350 * Core handler for key exchange traffic (ephemeral key, ping, pong).
2351 *
2352 * @param cls Closure (unused).
2353 * @param message Message received.
2354 * @param peer Peer who sent the message.
2355 *
2356 * @return GNUNET_OK to keep the connection open,
2357 * GNUNET_SYSERR to close it (signal serious error)
2358 */
2359int
2360GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
2361 const struct GNUNET_MessageHeader *message)
2362{
2363 return handle_cadet_kx (peer,
2364 (struct GNUNET_CADET_KX *) message);
2365}
2366
2367
2368/**
2350 * Core handler for encrypted cadet network traffic (channel mgmt, data). 2369 * Core handler for encrypted cadet network traffic (channel mgmt, data).
2351 * 2370 *
2352 * @param cls Closure (unused). 2371 * @param cls Closure (unused).
@@ -2366,21 +2385,191 @@ GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
2366 2385
2367 2386
2368/** 2387/**
2369 * Core handler for key exchange traffic (ephemeral key, ping, pong). 2388 * Check the message against internal state and test if it goes FWD or BCK.
2389 *
2390 * Updates the PID, state and timeout values for the connection.
2391 *
2392 * @param message Message to check. It must belong to an existing connection.
2393 * @param minimum_size The message cannot be smaller than this value.
2394 * @param c Connection this message should belong. If NULL, check fails.
2395 * @param neighbor Neighbor that sent the message.
2396 */
2397static int
2398check_message (const struct GNUNET_MessageHeader *message,
2399 size_t minimum_size,
2400 struct CadetConnection *c,
2401 const struct GNUNET_PeerIdentity *neighbor,
2402 uint32_t pid)
2403{
2404 GNUNET_PEER_Id neighbor_id;
2405 struct CadetFlowControl *fc;
2406 struct CadetPeer *hop;
2407 int fwd;
2408
2409 /* Check size */
2410 if (ntohs (message->size) < minimum_size)
2411 {
2412 GNUNET_break_op (0);
2413 return GNUNET_SYSERR;
2414 }
2415
2416 /* Check connection */
2417 if (NULL == c)
2418 {
2419 GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
2420 LOG (GNUNET_ERROR_TYPE_DEBUG, "enc_ax on unknown connection %s\n",
2421 GNUNET_h2s (GC_h2hc (&c->id)));
2422 send_broken_unknown (&c->id, &my_full_id, NULL, neighbor);
2423 return GNUNET_OK;
2424 }
2425
2426 /* Check if origin is as expected */
2427 neighbor_id = GNUNET_PEER_search (neighbor);
2428 hop = get_prev_hop (c);
2429 if (neighbor_id == GCP_get_short_id (hop))
2430 {
2431 fwd = GNUNET_YES;
2432 }
2433 else
2434 {
2435 hop = get_next_hop (c);
2436 if (neighbor_id == GCP_get_short_id (hop))
2437 {
2438 fwd = GNUNET_NO;
2439 }
2440 else
2441 {
2442 /* Unexpected peer sending traffic on a connection. */
2443 GNUNET_break_op (0);
2444 return GNUNET_SYSERR;
2445 }
2446 }
2447
2448 /* Check PID */
2449 fc = fwd ? &c->bck_fc : &c->fwd_fc;
2450 LOG (GNUNET_ERROR_TYPE_DEBUG, " PID %u (expected %u - %u)\n",
2451 pid, fc->last_pid_recv + 1, fc->last_ack_sent);
2452 if (GC_is_pid_bigger (pid, fc->last_ack_sent))
2453 {
2454 GNUNET_break_op (0);
2455 GNUNET_STATISTICS_update (stats, "# unsolicited message", 1, GNUNET_NO);
2456 LOG (GNUNET_ERROR_TYPE_WARNING, "Received PID %u, (prev %u), ACK %u\n",
2457 pid, fc->last_pid_recv, fc->last_ack_sent);
2458 return GNUNET_SYSERR;
2459 }
2460 if (GC_is_pid_bigger (pid, fc->last_pid_recv))
2461 {
2462 unsigned int delta;
2463
2464 delta = pid - fc->last_pid_recv;
2465 fc->last_pid_recv = pid;
2466 fc->recv_bitmap <<= delta;
2467 fc->recv_bitmap |= 1;
2468 }
2469 else
2470 {
2471 GNUNET_STATISTICS_update (stats, "# out of order PID", 1, GNUNET_NO);
2472 if (GNUNET_NO == is_ooo_ok (fc->last_pid_recv, pid, fc->recv_bitmap))
2473 {
2474 LOG (GNUNET_ERROR_TYPE_WARNING, "PID %u not expected (%u+), dropping!\n",
2475 pid, fc->last_pid_recv - 31);
2476 return GNUNET_SYSERR;
2477 }
2478 fc->recv_bitmap |= get_recv_bitmask (fc->last_pid_recv, pid);
2479 }
2480 if (CADET_CONNECTION_SENT == c->state || CADET_CONNECTION_ACK == c->state)
2481 connection_change_state (c, CADET_CONNECTION_READY);
2482 connection_reset_timeout (c, fwd);
2483
2484 return fwd;
2485}
2486
2487
2488/**
2489 * Core handler for axolotl key exchange traffic.
2370 * 2490 *
2371 * @param cls Closure (unused). 2491 * @param cls Closure (unused).
2372 * @param message Message received. 2492 * @param message Message received.
2373 * @param peer Peer who sent the message. 2493 * @param peer Neighbor who sent the message.
2374 * 2494 *
2375 * @return GNUNET_OK to keep the connection open, 2495 * @return GNUNET_OK, to keep the connection open.
2376 * GNUNET_SYSERR to close it (signal serious error)
2377 */ 2496 */
2378int 2497int
2379GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer, 2498GCC_handle_ax_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
2380 const struct GNUNET_MessageHeader *message) 2499 const struct GNUNET_MessageHeader *message)
2381{ 2500{
2382 return handle_cadet_kx (peer, 2501 struct GNUNET_CADET_AX *msg;
2383 (struct GNUNET_CADET_KX *) message); 2502 struct CadetConnection *c;
2503 size_t expected_size;
2504 uint32_t pid;
2505 uint32_t ttl;
2506 int fwd;
2507
2508 msg = (struct GNUNET_CADET_AX *) message;
2509 log_message (message, peer, &msg->cid);
2510
2511 expected_size = sizeof (struct GNUNET_CADET_AX)
2512 + sizeof (struct GNUNET_MessageHeader);
2513 c = connection_get (&msg->cid);
2514 pid = ntohl (msg->pid);
2515 fwd = check_message (message, expected_size, c, peer, pid);
2516
2517 /* If something went wrong, discard message. */
2518 if (GNUNET_SYSERR == fwd)
2519 return GNUNET_OK;
2520
2521 /* Is this message for us? */
2522 if (GCC_is_terminal (c, fwd))
2523 {
2524 GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO);
2525
2526 if (NULL == c->t)
2527 {
2528 GNUNET_break (GNUNET_NO != c->destroy);
2529 return GNUNET_OK;
2530 }
2531 GCT_handle_ax (c->t, msg); //FIXME ax
2532 GCC_send_ack (c, fwd, GNUNET_NO);
2533 return GNUNET_OK;
2534 }
2535
2536 /* Message not for us: forward to next hop */
2537 ttl = ntohl (msg->ttl);
2538 LOG (GNUNET_ERROR_TYPE_DEBUG, " forwarding, ttl: %u\n", ttl);
2539 if (ttl == 0)
2540 {
2541 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
2542 LOG (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
2543 GCC_send_ack (c, fwd, GNUNET_NO);
2544 return GNUNET_OK;
2545 }
2546
2547 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
2548 GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg->header, 0, 0, c, fwd,
2549 GNUNET_NO, NULL, NULL));
2550
2551
2552
2553 return GNUNET_OK;
2554}
2555
2556
2557
2558/**
2559 * Core handler for axolotl encrypted cadet network traffic.
2560 *
2561 * @param cls Closure (unused).
2562 * @param message Message received.
2563 * @param peer Neighbor who sent the message.
2564 *
2565 * @return GNUNET_OK, to keep the connection open.
2566 */
2567int
2568GCC_handle_ax (void *cls, const struct GNUNET_PeerIdentity *peer,
2569 struct GNUNET_MessageHeader *message)
2570{
2571 return handle_cadet_encrypted (peer,
2572 (struct GNUNET_CADET_Encrypted *)message);
2384} 2573}
2385 2574
2386 2575
diff --git a/src/cadet/gnunet-service-cadet_connection.h b/src/cadet/gnunet-service-cadet_connection.h
index 0ee9c67a5..e6604f392 100644
--- a/src/cadet/gnunet-service-cadet_connection.h
+++ b/src/cadet/gnunet-service-cadet_connection.h
@@ -165,7 +165,7 @@ GCC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
165 const struct GNUNET_MessageHeader *message); 165 const struct GNUNET_MessageHeader *message);
166 166
167/** 167/**
168 * Core handler for encrypted cadet network traffic (channel mgmt, data). 168 * Core handler for key exchange traffic (ephemeral key, ping, pong).
169 * 169 *
170 * @param cls Closure (unused). 170 * @param cls Closure (unused).
171 * @param message Message received. 171 * @param message Message received.
@@ -175,11 +175,11 @@ GCC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
175 * GNUNET_SYSERR to close it (signal serious error) 175 * GNUNET_SYSERR to close it (signal serious error)
176 */ 176 */
177int 177int
178GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer, 178GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
179 const struct GNUNET_MessageHeader *message); 179 const struct GNUNET_MessageHeader *message);
180 180
181/** 181/**
182 * Core handler for key exchange traffic (ephemeral key, ping, pong). 182 * Core handler for encrypted cadet network traffic (channel mgmt, data).
183 * 183 *
184 * @param cls Closure (unused). 184 * @param cls Closure (unused).
185 * @param message Message received. 185 * @param message Message received.
@@ -189,8 +189,34 @@ GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
189 * GNUNET_SYSERR to close it (signal serious error) 189 * GNUNET_SYSERR to close it (signal serious error)
190 */ 190 */
191int 191int
192GCC_handle_kx (void *cls, const struct GNUNET_PeerIdentity *peer, 192GCC_handle_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
193 const struct GNUNET_MessageHeader *message); 193 const struct GNUNET_MessageHeader *message);
194
195/**
196 * Core handler for axolotl key exchange traffic.
197 *
198 * @param cls Closure (unused).
199 * @param message Message received.
200 * @param peer Neighbor who sent the message.
201 *
202 * @return GNUNET_OK, to keep the connection open.
203 */
204int
205GCC_handle_ax_kx (void *cls, const struct GNUNET_PeerIdentity *peer,
206 const struct GNUNET_MessageHeader *message);
207
208/**
209 * Core handler for axolotl encrypted cadet network traffic.
210 *
211 * @param cls Closure (unused).
212 * @param message Message received.
213 * @param peer Neighbor who sent the message.
214 *
215 * @return GNUNET_OK, to keep the connection open.
216 */
217int
218GCC_handle_ax (void *cls, const struct GNUNET_PeerIdentity *peer,
219 struct GNUNET_MessageHeader *message);
194 220
195/** 221/**
196 * Core handler for cadet network traffic point-to-point acks. 222 * Core handler for cadet network traffic point-to-point acks.
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index bfb11fc7f..1462c5daa 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -482,9 +482,10 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
482 sizeof (struct GNUNET_CADET_ACK)}, 482 sizeof (struct GNUNET_CADET_ACK)},
483 {&GCC_handle_poll, GNUNET_MESSAGE_TYPE_CADET_POLL, 483 {&GCC_handle_poll, GNUNET_MESSAGE_TYPE_CADET_POLL,
484 sizeof (struct GNUNET_CADET_Poll)}, 484 sizeof (struct GNUNET_CADET_Poll)},
485 {&GCC_handle_encrypted, GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED, 0},
486 {&GCC_handle_kx, GNUNET_MESSAGE_TYPE_CADET_KX, 0}, 485 {&GCC_handle_kx, GNUNET_MESSAGE_TYPE_CADET_KX, 0},
487 {NULL, 0, 0} 486 {&GCC_handle_encrypted, GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED, 0},
487 {&GCC_handle_ax_kx, GNUNET_MESSAGE_TYPE_CADET_AX_KX, 0}, {NULL, 0, 0},
488 {&GCC_handle_ax, GNUNET_MESSAGE_TYPE_CADET_AX, 0}
488}; 489};
489 490
490 491
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index d757fc81f..bb6c82d3e 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -2113,13 +2113,12 @@ handle_decrypted (struct CadetTunnel *t,
2113/******************************************************************************/ 2113/******************************************************************************/
2114/******************************** API ***********************************/ 2114/******************************** API ***********************************/
2115/******************************************************************************/ 2115/******************************************************************************/
2116
2117/** 2116/**
2118 * Decrypt and demultiplex by message type. Call appropriate handler 2117 * Decrypt old format and demultiplex by message type. Call appropriate handler
2119 * for every message. 2118 * for a message towards a channel of a local tunnel.
2120 * 2119 *
2121 * @param t Tunnel this message came on. 2120 * @param t Tunnel this message came on.
2122 * @param msg Encrypted message. 2121 * @param msg Message header.
2123 */ 2122 */
2124void 2123void
2125GCT_handle_encrypted (struct CadetTunnel *t, 2124GCT_handle_encrypted (struct CadetTunnel *t,
@@ -2160,6 +2159,21 @@ GCT_handle_encrypted (struct CadetTunnel *t,
2160 2159
2161 2160
2162/** 2161/**
2162 * Decrypt axolotl and demultiplex by message type. Call appropriate handler
2163 * for a message towards a channel of a local tunnel.
2164 *
2165 * @param t Tunnel this message came on.
2166 * @param msg Message header.
2167 */
2168void
2169GCT_handle_ax (struct CadetTunnel *t,
2170 const struct GNUNET_CADET_AX *msg)
2171{
2172 //FIXME ax
2173}
2174
2175
2176/**
2163 * Demultiplex an encapsulated KX message by message type. 2177 * Demultiplex an encapsulated KX message by message type.
2164 * 2178 *
2165 * @param t Tunnel on which the message came. 2179 * @param t Tunnel on which the message came.
diff --git a/src/cadet/gnunet-service-cadet_tunnel.h b/src/cadet/gnunet-service-cadet_tunnel.h
index 681ddcb93..5e5b77c58 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.h
+++ b/src/cadet/gnunet-service-cadet_tunnel.h
@@ -270,9 +270,8 @@ struct CadetChannel *
270GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid); 270GCT_get_channel (struct CadetTunnel *t, CADET_ChannelNumber chid);
271 271
272/** 272/**
273 * Decrypt and demultiplex by message type. Call appropriate handler 273 * Decrypt old format and demultiplex by message type. Call appropriate handler
274 * for a message 274 * for a message towards a channel of a local tunnel.
275 * towards a channel of a local tunnel.
276 * 275 *
277 * @param t Tunnel this message came on. 276 * @param t Tunnel this message came on.
278 * @param msg Message header. 277 * @param msg Message header.
@@ -282,6 +281,18 @@ GCT_handle_encrypted (struct CadetTunnel *t,
282 const struct GNUNET_CADET_Encrypted *msg); 281 const struct GNUNET_CADET_Encrypted *msg);
283 282
284/** 283/**
284 * Decrypt axolotl and demultiplex by message type. Call appropriate handler
285 * for a message towards a channel of a local tunnel.
286 *
287 * @param t Tunnel this message came on.
288 * @param msg Message header.
289 */
290void
291GCT_handle_ax (struct CadetTunnel *t,
292 const struct GNUNET_CADET_AX *msg);
293
294
295/**
285 * Demultiplex an encapsulated KX message by message type. 296 * Demultiplex an encapsulated KX message by message type.
286 * 297 *
287 * @param t Tunnel on which the message came. 298 * @param t Tunnel on which the message came.