2 This file is part of GNUnet.
3 Copyright (C) 2007 - 2017 GNUnet e.V.
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.
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.
17 * @file cadet/cadet_protocol.h
18 * @brief P2P messages used by CADET
19 * @author Bartlomiej Polot
20 * @author Christian Grothoff
23 #ifndef CADET_PROTOCOL_H_
24 #define CADET_PROTOCOL_H_
27 * At best, enable when debugging #5328!
31 #warning NEVER run this in production! KX debugging is on!
35 #include "gnunet_util_lib.h"
40 struct GNUNET_CADET_TunnelMessage;
44 /* keep Emacsens' auto-indent happy */
49 /******************************************************************************/
50 /******************** CADET NETWORK MESSAGES **************************/
51 /******************************************************************************/
53 GNUNET_NETWORK_STRUCT_BEGIN
56 /******************************************************************************/
57 /***************************** CONNECTION **********************************/
58 /******************************************************************************/
62 * Message for cadet connection creation.
64 struct GNUNET_CADET_ConnectionCreateMessage
67 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
69 * Size: sizeof (struct GNUNET_CADET_ConnectionCreateMessage) +
70 * path_length * sizeof (struct GNUNET_PeerIdentity)
72 struct GNUNET_MessageHeader header;
75 * Connection options in network byte order.
76 * #GNUNET_CADET_OPTION_DEFAULT for buffered;
77 * #GNUNET_CADET_OPTION_NOBUFFER for unbuffered.
78 * Other flags are ignored and should not be set at this level.
80 uint32_t options GNUNET_PACKED;
83 * ID of the connection
85 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
88 * path_length structs defining the *whole* path from the origin [0] to the
89 * final destination [path_length-1].
91 /* struct GNUNET_PeerIdentity peers[path_length]; */
96 * Message for ack'ing a connection
98 struct GNUNET_CADET_ConnectionCreateAckMessage
101 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
103 struct GNUNET_MessageHeader header;
108 uint32_t reserved GNUNET_PACKED;
111 * ID of the connection.
113 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
119 * Message for notifying a disconnection in a path
121 struct GNUNET_CADET_ConnectionBrokenMessage
124 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
126 struct GNUNET_MessageHeader header;
131 uint32_t reserved GNUNET_PACKED;
134 * ID of the connection.
136 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
141 struct GNUNET_PeerIdentity peer1;
146 struct GNUNET_PeerIdentity peer2;
151 * Message to destroy a connection.
153 struct GNUNET_CADET_ConnectionDestroyMessage
156 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
158 struct GNUNET_MessageHeader header;
163 uint32_t reserved GNUNET_PACKED;
166 * ID of the connection.
168 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
172 /******************************************************************************/
173 /******************************* TUNNEL ***********************************/
174 /******************************************************************************/
177 * Unique identifier (counter) for an encrypted message in a channel.
178 * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
179 * and #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
180 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
183 struct CadetEncryptedMessageIdentifier
186 * This number is incremented by one per message. It may wrap around.
187 * In network byte order.
189 uint32_t pid GNUNET_PACKED;
194 * Flags to be used in GNUNET_CADET_KX.
196 enum GNUNET_CADET_KX_Flags {
199 * Should the peer reply with its KX details?
201 GNUNET_CADET_KX_FLAG_NONE = 0,
204 * The peer should reply with its KX details?
206 GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
211 * Message for a Key eXchange for a tunnel.
213 struct GNUNET_CADET_TunnelKeyExchangeMessage
216 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
217 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
218 * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
220 struct GNUNET_MessageHeader header;
223 * Flags for the key exchange in NBO, based on
224 * `enum GNUNET_CADET_KX_Flags`.
226 uint32_t flags GNUNET_PACKED;
229 * ID of the connection.
231 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
234 * Sender's ephemeral public ECC key encoded in a
235 * format suitable for network transmission, as created
236 * using 'gcry_sexp_sprint'.
238 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
242 * Sender's ephemeral public ECC key encoded in a
243 * format suitable for network transmission, as created
244 * using 'gcry_sexp_sprint'.
246 struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral_key_XXX; // for debugging KX-crypto!
249 * Sender's ephemeral public ECC key encoded in a
250 * format suitable for network transmission, as created
251 * using 'gcry_sexp_sprint'.
253 struct GNUNET_CRYPTO_EddsaPrivateKey private_key_XXX; // for debugging KX-crypto!
257 * Sender's next ephemeral public ECC key encoded in a
258 * format suitable for network transmission, as created
259 * using 'gcry_sexp_sprint'.
261 struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
267 * Message for a Key eXchange for a tunnel, with authentication.
268 * Used as a response to the initial KX as well as for rekeying.
270 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
274 * Message header with key material.
276 struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
280 * Received ephemeral public ECC key encoded in a
281 * format suitable for network transmission, as created
282 * using 'gcry_sexp_sprint'.
284 struct GNUNET_CRYPTO_EcdhePublicKey r_ephemeral_key_XXX; // for debugging KX-crypto!
288 * KDF-proof that sender could compute the 3-DH, used in lieu of a
289 * signature or payload data.
291 struct GNUNET_HashCode auth;
297 * Encrypted axolotl header with numbers that identify which
298 * keys in which ratchet are to be used to decrypt the body.
300 struct GNUNET_CADET_AxHeader
304 * Number of messages sent with the current ratchet key.
306 uint32_t Ns GNUNET_PACKED;
309 * Number of messages sent with the previous ratchet key.
311 uint32_t PNs GNUNET_PACKED;
314 * Current ratchet key.
316 struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
322 * Axolotl-encrypted tunnel message with application payload.
324 struct GNUNET_CADET_TunnelEncryptedMessage
327 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
329 struct GNUNET_MessageHeader header;
332 * Reserved, for alignment.
334 uint32_t reserved GNUNET_PACKED;
337 * ID of the connection.
339 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
342 * MAC of the encrypted message, used to verify message integrity.
343 * Everything after this value will be encrypted with the header key
346 struct GNUNET_ShortHashCode hmac;
349 * Axolotl-header that specifies which keys to use in which ratchet
350 * to decrypt the body that follows.
352 struct GNUNET_CADET_AxHeader ax_header;
355 * Encrypted content follows.
360 /******************************************************************************/
361 /******************************* CHANNEL ***********************************/
362 /******************************************************************************/
366 * Message to create a Channel.
368 struct GNUNET_CADET_ChannelOpenMessage
371 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
373 struct GNUNET_MessageHeader header;
378 uint32_t opt GNUNET_PACKED;
381 * Hash of destination port and listener.
383 struct GNUNET_HashCode h_port;
386 * ID of the channel within the tunnel.
388 struct GNUNET_CADET_ChannelTunnelNumber ctn;
393 * Message to acknowledge opening a channel of type
394 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
396 struct GNUNET_CADET_ChannelOpenAckMessage
399 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
401 struct GNUNET_MessageHeader header;
406 uint32_t reserved GNUNET_PACKED;
411 struct GNUNET_CADET_ChannelTunnelNumber ctn;
414 * Port number of the channel, used to prove to the
415 * initiator that the receiver knows the port.
417 struct GNUNET_HashCode port;
422 * Message to destroy a channel of type
423 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
425 struct GNUNET_CADET_ChannelDestroyMessage
428 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
430 struct GNUNET_MessageHeader header;
435 uint32_t reserved GNUNET_PACKED;
440 struct GNUNET_CADET_ChannelTunnelNumber ctn;
445 * Number used to uniquely identify messages in a CADET Channel.
447 struct ChannelMessageIdentifier
450 * Unique ID of the message, cycles around, in NBO.
452 uint32_t mid GNUNET_PACKED;
457 * Message for cadet data traffic.
459 struct GNUNET_CADET_ChannelAppDataMessage
462 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
464 struct GNUNET_MessageHeader header;
467 * Unique ID of the payload message.
469 struct ChannelMessageIdentifier mid;
474 struct GNUNET_CADET_ChannelTunnelNumber ctn;
483 * Message to acknowledge end-to-end data.
485 struct GNUNET_CADET_ChannelDataAckMessage
488 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
490 struct GNUNET_MessageHeader header;
495 struct GNUNET_CADET_ChannelTunnelNumber ctn;
498 * Bitfield of already-received newer messages. Note that bit 0
499 * corresponds to @e mid + 1.
504 uint64_t futures GNUNET_PACKED;
507 * Next message ID expected.
509 struct ChannelMessageIdentifier mid;
513 GNUNET_NETWORK_STRUCT_END
515 #if 0 /* keep Emacsens' auto-indent happy */
522 /* ifndef CADET_PROTOCOL_H */
524 /* end of cadet_protocol.h */