aboutsummaryrefslogtreecommitdiff
path: root/src/service/cadet/cadet_protocol.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/cadet/cadet_protocol.h')
-rw-r--r--src/service/cadet/cadet_protocol.h541
1 files changed, 541 insertions, 0 deletions
diff --git a/src/service/cadet/cadet_protocol.h b/src/service/cadet/cadet_protocol.h
new file mode 100644
index 000000000..117a7922e
--- /dev/null
+++ b/src/service/cadet/cadet_protocol.h
@@ -0,0 +1,541 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2007 - 2017 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file cadet/cadet_protocol.h
23 * @brief P2P messages used by CADET
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
26 */
27
28#ifndef CADET_PROTOCOL_H_
29#define CADET_PROTOCOL_H_
30
31/**
32 * At best, enable when debugging #5328!
33 */
34#define DEBUG_KX 0
35#if DEBUG_KX
36#warning NEVER run this in production! KX debugging is on!
37#endif
38
39#include "platform.h"
40#include "gnunet_util_lib.h"
41#include "cadet.h"
42
43#ifdef __cplusplus
44
45struct GNUNET_CADET_TunnelMessage;
46extern "C"
47{
48#if 0
49/* keep Emacsens' auto-indent happy */
50}
51#endif
52#endif
53
54/******************************************************************************/
55/******************** CADET NETWORK MESSAGES **************************/
56/******************************************************************************/
57
58GNUNET_NETWORK_STRUCT_BEGIN
59
60
61/******************************************************************************/
62/***************************** CONNECTION **********************************/
63/******************************************************************************/
64
65
66/**
67 * Message for cadet connection creation.
68 */
69struct GNUNET_CADET_ConnectionCreateMessage
70{
71 /**
72 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
73 *
74 * Size: sizeof (struct GNUNET_CADET_ConnectionCreateMessage) +
75 * path_length * sizeof (struct GNUNET_PeerIdentity)
76 */
77 struct GNUNET_MessageHeader header;
78
79 /**
80 * Connection options in network byte order.
81 * #GNUNET_CADET_OPTION_DEFAULT for buffered;
82 * #GNUNET_CADET_OPTION_NOBUFFER for unbuffered.
83 * Other flags are ignored and should not be set at this level.
84 */
85 uint32_t options GNUNET_PACKED;
86
87 /**
88 * This flag indicates the peer sending the connection create
89 * meassage likes to trigger a KX handshake.
90 */
91 int has_monotime;
92
93 /**
94 * This monotonic time is set, if a peer likes to trigger a KX, but is not
95 * the peer that should start the KX. (xrs,t3ss)
96 */
97 struct GNUNET_TIME_AbsoluteNBO monotime;
98
99 /**
100 * We sign the monotime. The receiving peer can check the signature, to verify
101 * the sending peer.
102 */
103 struct GNUNET_CRYPTO_EddsaSignature monotime_sig;
104
105 /**
106 * ID of the connection
107 */
108 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
109
110 /**
111 * path_length structs defining the *whole* path from the origin [0] to the
112 * final destination [path_length-1].
113 */
114 /* struct GNUNET_PeerIdentity peers[path_length]; */
115};
116
117
118/**
119 * Message for ack'ing a connection
120 */
121struct GNUNET_CADET_ConnectionCreateAckMessage
122{
123 /**
124 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
125 */
126 struct GNUNET_MessageHeader header;
127
128 /**
129 * For alignment.
130 */
131 uint32_t reserved GNUNET_PACKED;
132
133 /**
134 * ID of the connection.
135 */
136 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
137};
138
139
140/**
141 * Message for notifying a disconnection in a path
142 */
143struct GNUNET_CADET_ConnectionBrokenMessage
144{
145 /**
146 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
147 */
148 struct GNUNET_MessageHeader header;
149
150 /**
151 * For alignment.
152 */
153 uint32_t reserved GNUNET_PACKED;
154
155 /**
156 * ID of the connection.
157 */
158 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
159
160 /**
161 * ID of the endpoint
162 */
163 struct GNUNET_PeerIdentity peer1;
164
165 /**
166 * ID of the endpoint
167 */
168 struct GNUNET_PeerIdentity peer2;
169};
170
171
172/**
173 * Message to destroy a connection.
174 */
175struct GNUNET_CADET_ConnectionDestroyMessage
176{
177 /**
178 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
179 */
180 struct GNUNET_MessageHeader header;
181
182 /**
183 * For alignment.
184 */
185 uint32_t reserved GNUNET_PACKED;
186
187 /**
188 * ID of the connection.
189 */
190 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
191};
192
193
194/******************************************************************************/
195/******************************* TUNNEL ***********************************/
196/******************************************************************************/
197
198/**
199 * Unique identifier (counter) for an encrypted message in a channel.
200 * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
201 * and #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
202 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
203 * messages.
204 */
205struct CadetEncryptedMessageIdentifier
206{
207 /**
208 * This number is incremented by one per message. It may wrap around.
209 * In network byte order.
210 */
211 uint32_t pid GNUNET_PACKED;
212};
213
214
215/**
216 * Flags to be used in GNUNET_CADET_KX.
217 */
218enum GNUNET_CADET_KX_Flags
219{
220 /**
221 * Should the peer reply with its KX details?
222 */
223 GNUNET_CADET_KX_FLAG_NONE = 0,
224
225 /**
226 * The peer should reply with its KX details?
227 */
228 GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
229};
230
231
232/**
233 * Message for a Key eXchange for a tunnel.
234 */
235struct GNUNET_CADET_TunnelKeyExchangeMessage
236{
237 /**
238 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
239 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
240 * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
241 */
242 struct GNUNET_MessageHeader header;
243
244 /**
245 * Flags for the key exchange in NBO, based on
246 * `enum GNUNET_CADET_KX_Flags`.
247 */
248 uint32_t flags GNUNET_PACKED;
249
250 /**
251 * ID of the connection.
252 */
253 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
254
255 /**
256 * Sender's ephemeral public ECC key encoded in a
257 * format suitable for network transmission, as created
258 * using 'gcry_sexp_sprint'.
259 */
260 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
261
262#if DEBUG_KX
263 /**
264 * Sender's ephemeral public ECC key encoded in a
265 * format suitable for network transmission, as created
266 * using 'gcry_sexp_sprint'.
267 */
268 struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral_key_XXX; // for debugging KX-crypto!
269
270 /**
271 * Sender's ephemeral public ECC key encoded in a
272 * format suitable for network transmission, as created
273 * using 'gcry_sexp_sprint'.
274 */
275 struct GNUNET_CRYPTO_EddsaPrivateKey private_key_XXX; // for debugging KX-crypto!
276#endif
277
278 /**
279 * Sender's next ephemeral public ECC key encoded in a
280 * format suitable for network transmission, as created
281 * using 'gcry_sexp_sprint'.
282 */
283 struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
284};
285
286
287/**
288 * Message for a Key eXchange for a tunnel, with authentication.
289 * Used as a response to the initial KX as well as for rekeying.
290 */
291struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
292{
293 /**
294 * Message header with key material.
295 */
296 struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
297
298#if DEBUG_KX
299 /**
300 * Received ephemeral public ECC key encoded in a
301 * format suitable for network transmission, as created
302 * using 'gcry_sexp_sprint'.
303 */
304 struct GNUNET_CRYPTO_EcdhePublicKey r_ephemeral_key_XXX; // for debugging KX-crypto!
305#endif
306
307 /**
308 * KDF-proof that sender could compute the 3-DH, used in lieu of a
309 * signature or payload data.
310 */
311 struct GNUNET_HashCode auth;
312};
313
314
315/**
316 * Encrypted axolotl header with numbers that identify which
317 * keys in which ratchet are to be used to decrypt the body.
318 */
319struct GNUNET_CADET_AxHeader
320{
321 /**
322 * Number of messages sent with the current ratchet key.
323 */
324 uint32_t Ns GNUNET_PACKED;
325
326 /**
327 * Number of messages sent with the previous ratchet key.
328 */
329 uint32_t PNs GNUNET_PACKED;
330
331 /**
332 * Current ratchet key.
333 */
334 struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
335};
336
337
338/**
339 * Axolotl-encrypted tunnel message with application payload.
340 */
341struct GNUNET_CADET_TunnelEncryptedMessage
342{
343 /**
344 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
345 */
346 struct GNUNET_MessageHeader header;
347
348 /**
349 * Reserved, for alignment.
350 */
351 uint32_t reserved GNUNET_PACKED;
352
353 /**
354 * ID of the connection.
355 */
356 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
357
358 /**
359 * MAC of the encrypted message, used to verify message integrity.
360 * Everything after this value will be encrypted with the header key
361 * and authenticated.
362 */
363 struct GNUNET_ShortHashCode hmac;
364
365 /**
366 * Axolotl-header that specifies which keys to use in which ratchet
367 * to decrypt the body that follows.
368 */
369 struct GNUNET_CADET_AxHeader ax_header;
370
371 /**
372 * Encrypted content follows.
373 */
374};
375
376
377/******************************************************************************/
378/******************************* CHANNEL ***********************************/
379/******************************************************************************/
380
381
382/**
383 * Message to create a Channel.
384 */
385struct GNUNET_CADET_ChannelOpenMessage
386{
387 /**
388 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
389 */
390 struct GNUNET_MessageHeader header;
391
392 /**
393 * Channel options.
394 */
395 uint32_t opt GNUNET_PACKED;
396
397 /**
398 * Hash of destination port and listener.
399 */
400 struct GNUNET_HashCode h_port;
401
402 /**
403 * ID of the channel within the tunnel.
404 */
405 struct GNUNET_CADET_ChannelTunnelNumber ctn;
406};
407
408
409/**
410 * Message to acknowledge opening a channel of type
411 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
412 */
413struct GNUNET_CADET_ChannelOpenAckMessage
414{
415 /**
416 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
417 */
418 struct GNUNET_MessageHeader header;
419
420 /**
421 * For alignment.
422 */
423 uint32_t reserved GNUNET_PACKED;
424
425 /**
426 * ID of the channel
427 */
428 struct GNUNET_CADET_ChannelTunnelNumber ctn;
429
430 /**
431 * Port number of the channel, used to prove to the
432 * initiator that the receiver knows the port.
433 */
434 struct GNUNET_HashCode port;
435};
436
437
438/**
439 * Message to destroy a channel of type
440 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
441 */
442struct GNUNET_CADET_ChannelDestroyMessage
443{
444 /**
445 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
446 */
447 struct GNUNET_MessageHeader header;
448
449 /**
450 * For alignment.
451 */
452 uint32_t reserved GNUNET_PACKED;
453
454 /**
455 * ID of the channel
456 */
457 struct GNUNET_CADET_ChannelTunnelNumber ctn;
458};
459
460
461/**
462 * Number used to uniquely identify messages in a CADET Channel.
463 */
464struct ChannelMessageIdentifier
465{
466 /**
467 * Unique ID of the message, cycles around, in NBO.
468 */
469 uint32_t mid GNUNET_PACKED;
470};
471
472
473/**
474 * Message for cadet data traffic.
475 */
476struct GNUNET_CADET_ChannelAppDataMessage
477{
478 /**
479 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
480 */
481 struct GNUNET_MessageHeader header;
482
483 /**
484 * Unique ID of the payload message.
485 */
486 struct ChannelMessageIdentifier mid;
487
488 /**
489 * ID of the channel
490 */
491 struct GNUNET_CADET_ChannelTunnelNumber ctn;
492
493 /**
494 * Payload follows
495 */
496};
497
498
499/**
500 * Message to acknowledge end-to-end data.
501 */
502struct GNUNET_CADET_ChannelDataAckMessage
503{
504 /**
505 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
506 */
507 struct GNUNET_MessageHeader header;
508
509 /**
510 * ID of the channel
511 */
512 struct GNUNET_CADET_ChannelTunnelNumber ctn;
513
514 /**
515 * Bitfield of already-received newer messages. Note that bit 0
516 * corresponds to @e mid + 1.
517 *
518 * pid + 0 @ LSB
519 * pid + 63 @ MSB
520 */
521 uint64_t futures GNUNET_PACKED;
522
523 /**
524 * Next message ID expected.
525 */
526 struct ChannelMessageIdentifier mid;
527};
528
529
530GNUNET_NETWORK_STRUCT_END
531
532#if 0 /* keep Emacsens' auto-indent happy */
533{
534#endif
535#ifdef __cplusplus
536}
537#endif
538
539/* ifndef CADET_PROTOCOL_H */
540#endif
541/* end of cadet_protocol.h */