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.
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/>.
20 * @file cadet/cadet_protocol.h
21 * @brief P2P messages used by CADET
22 * @author Bartlomiej Polot
23 * @author Christian Grothoff
26 #ifndef CADET_PROTOCOL_H_
27 #define CADET_PROTOCOL_H_
30 * At best, enable when debugging #5328!
34 #warning NEVER run this in production! KX debugging is on!
38 #include "gnunet_util_lib.h"
43 struct GNUNET_CADET_TunnelMessage;
47 /* keep Emacsens' auto-indent happy */
52 /******************************************************************************/
53 /******************** CADET NETWORK MESSAGES **************************/
54 /******************************************************************************/
56 GNUNET_NETWORK_STRUCT_BEGIN
59 /******************************************************************************/
60 /***************************** CONNECTION **********************************/
61 /******************************************************************************/
65 * Message for cadet connection creation.
67 struct GNUNET_CADET_ConnectionCreateMessage
70 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
72 * Size: sizeof (struct GNUNET_CADET_ConnectionCreateMessage) +
73 * path_length * sizeof (struct GNUNET_PeerIdentity)
75 struct GNUNET_MessageHeader header;
78 * Connection options in network byte order.
79 * #GNUNET_CADET_OPTION_DEFAULT for buffered;
80 * #GNUNET_CADET_OPTION_NOBUFFER for unbuffered.
81 * Other flags are ignored and should not be set at this level.
83 uint32_t options GNUNET_PACKED;
86 * ID of the connection
88 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
91 * path_length structs defining the *whole* path from the origin [0] to the
92 * final destination [path_length-1].
94 /* struct GNUNET_PeerIdentity peers[path_length]; */
99 * Message for ack'ing a connection
101 struct GNUNET_CADET_ConnectionCreateAckMessage
104 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE_ACK
106 struct GNUNET_MessageHeader header;
111 uint32_t reserved GNUNET_PACKED;
114 * ID of the connection.
116 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
122 * Message for notifying a disconnection in a path
124 struct GNUNET_CADET_ConnectionBrokenMessage
127 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN.
129 struct GNUNET_MessageHeader header;
134 uint32_t reserved GNUNET_PACKED;
137 * ID of the connection.
139 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
144 struct GNUNET_PeerIdentity peer1;
149 struct GNUNET_PeerIdentity peer2;
154 * Message to destroy a connection.
156 struct GNUNET_CADET_ConnectionDestroyMessage
159 * Type: #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
161 struct GNUNET_MessageHeader header;
166 uint32_t reserved GNUNET_PACKED;
169 * ID of the connection.
171 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
175 /******************************************************************************/
176 /******************************* TUNNEL ***********************************/
177 /******************************************************************************/
180 * Unique identifier (counter) for an encrypted message in a channel.
181 * Used to match #GNUNET_MESSAGE_TYPE_CADET_CONNECTION_HOP_BY_HOP_ENCRYPTED_ACK
182 * and #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED_POLL messages
183 * against the respective #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
186 struct CadetEncryptedMessageIdentifier
189 * This number is incremented by one per message. It may wrap around.
190 * In network byte order.
192 uint32_t pid GNUNET_PACKED;
197 * Flags to be used in GNUNET_CADET_KX.
199 enum GNUNET_CADET_KX_Flags {
202 * Should the peer reply with its KX details?
204 GNUNET_CADET_KX_FLAG_NONE = 0,
207 * The peer should reply with its KX details?
209 GNUNET_CADET_KX_FLAG_FORCE_REPLY = 1
214 * Message for a Key eXchange for a tunnel.
216 struct GNUNET_CADET_TunnelKeyExchangeMessage
219 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX or
220 * #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_KX_AUTH as part
221 * of `struct GNUNET_CADET_TunnelKeyExchangeAuthMessage`.
223 struct GNUNET_MessageHeader header;
226 * Flags for the key exchange in NBO, based on
227 * `enum GNUNET_CADET_KX_Flags`.
229 uint32_t flags GNUNET_PACKED;
232 * ID of the connection.
234 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
237 * Sender's ephemeral public ECC key encoded in a
238 * format suitable for network transmission, as created
239 * using 'gcry_sexp_sprint'.
241 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
245 * Sender's ephemeral public ECC key encoded in a
246 * format suitable for network transmission, as created
247 * using 'gcry_sexp_sprint'.
249 struct GNUNET_CRYPTO_EcdhePrivateKey ephemeral_key_XXX; // for debugging KX-crypto!
252 * Sender's ephemeral public ECC key encoded in a
253 * format suitable for network transmission, as created
254 * using 'gcry_sexp_sprint'.
256 struct GNUNET_CRYPTO_EddsaPrivateKey private_key_XXX; // for debugging KX-crypto!
260 * Sender's next ephemeral public ECC key encoded in a
261 * format suitable for network transmission, as created
262 * using 'gcry_sexp_sprint'.
264 struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
270 * Message for a Key eXchange for a tunnel, with authentication.
271 * Used as a response to the initial KX as well as for rekeying.
273 struct GNUNET_CADET_TunnelKeyExchangeAuthMessage
277 * Message header with key material.
279 struct GNUNET_CADET_TunnelKeyExchangeMessage kx;
283 * Received ephemeral public ECC key encoded in a
284 * format suitable for network transmission, as created
285 * using 'gcry_sexp_sprint'.
287 struct GNUNET_CRYPTO_EcdhePublicKey r_ephemeral_key_XXX; // for debugging KX-crypto!
291 * KDF-proof that sender could compute the 3-DH, used in lieu of a
292 * signature or payload data.
294 struct GNUNET_HashCode auth;
300 * Encrypted axolotl header with numbers that identify which
301 * keys in which ratchet are to be used to decrypt the body.
303 struct GNUNET_CADET_AxHeader
307 * Number of messages sent with the current ratchet key.
309 uint32_t Ns GNUNET_PACKED;
312 * Number of messages sent with the previous ratchet key.
314 uint32_t PNs GNUNET_PACKED;
317 * Current ratchet key.
319 struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
325 * Axolotl-encrypted tunnel message with application payload.
327 struct GNUNET_CADET_TunnelEncryptedMessage
330 * Type: #GNUNET_MESSAGE_TYPE_CADET_TUNNEL_ENCRYPTED
332 struct GNUNET_MessageHeader header;
335 * Reserved, for alignment.
337 uint32_t reserved GNUNET_PACKED;
340 * ID of the connection.
342 struct GNUNET_CADET_ConnectionTunnelIdentifier cid;
345 * MAC of the encrypted message, used to verify message integrity.
346 * Everything after this value will be encrypted with the header key
349 struct GNUNET_ShortHashCode hmac;
352 * Axolotl-header that specifies which keys to use in which ratchet
353 * to decrypt the body that follows.
355 struct GNUNET_CADET_AxHeader ax_header;
358 * Encrypted content follows.
363 /******************************************************************************/
364 /******************************* CHANNEL ***********************************/
365 /******************************************************************************/
369 * Message to create a Channel.
371 struct GNUNET_CADET_ChannelOpenMessage
374 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN
376 struct GNUNET_MessageHeader header;
381 uint32_t opt GNUNET_PACKED;
384 * Hash of destination port and listener.
386 struct GNUNET_HashCode h_port;
389 * ID of the channel within the tunnel.
391 struct GNUNET_CADET_ChannelTunnelNumber ctn;
396 * Message to acknowledge opening a channel of type
397 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK.
399 struct GNUNET_CADET_ChannelOpenAckMessage
402 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_OPEN_ACK
404 struct GNUNET_MessageHeader header;
409 uint32_t reserved GNUNET_PACKED;
414 struct GNUNET_CADET_ChannelTunnelNumber ctn;
417 * Port number of the channel, used to prove to the
418 * initiator that the receiver knows the port.
420 struct GNUNET_HashCode port;
425 * Message to destroy a channel of type
426 * #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY.
428 struct GNUNET_CADET_ChannelDestroyMessage
431 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_DESTROY
433 struct GNUNET_MessageHeader header;
438 uint32_t reserved GNUNET_PACKED;
443 struct GNUNET_CADET_ChannelTunnelNumber ctn;
448 * Number used to uniquely identify messages in a CADET Channel.
450 struct ChannelMessageIdentifier
453 * Unique ID of the message, cycles around, in NBO.
455 uint32_t mid GNUNET_PACKED;
460 * Message for cadet data traffic.
462 struct GNUNET_CADET_ChannelAppDataMessage
465 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA.
467 struct GNUNET_MessageHeader header;
470 * Unique ID of the payload message.
472 struct ChannelMessageIdentifier mid;
477 struct GNUNET_CADET_ChannelTunnelNumber ctn;
486 * Message to acknowledge end-to-end data.
488 struct GNUNET_CADET_ChannelDataAckMessage
491 * Type: #GNUNET_MESSAGE_TYPE_CADET_CHANNEL_APP_DATA_ACK
493 struct GNUNET_MessageHeader header;
498 struct GNUNET_CADET_ChannelTunnelNumber ctn;
501 * Bitfield of already-received newer messages. Note that bit 0
502 * corresponds to @e mid + 1.
507 uint64_t futures GNUNET_PACKED;
510 * Next message ID expected.
512 struct ChannelMessageIdentifier mid;
516 GNUNET_NETWORK_STRUCT_END
518 #if 0 /* keep Emacsens' auto-indent happy */
525 /* ifndef CADET_PROTOCOL_H */
527 /* end of cadet_protocol.h */