- handle AX messages
[oweals/gnunet.git] / src / cadet / cadet_protocol.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001 - 2011 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @author Bartlomiej Polot
23  * @file cadet/cadet_protocol.h
24  */
25
26 #ifndef CADET_PROTOCOL_H_
27 #define CADET_PROTOCOL_H_
28
29 #include "platform.h"
30 #include "gnunet_util_lib.h"
31 #include "cadet.h"
32
33 #ifdef __cplusplus
34
35 struct GNUNET_CADET_TunnelMessage;
36 extern "C"
37 {
38 #if 0
39   /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 /******************************************************************************/
45 /********************      CADET NETWORK MESSAGES     **************************/
46 /******************************************************************************/
47
48 GNUNET_NETWORK_STRUCT_BEGIN
49
50 /**
51  * Message for cadet connection creation.
52  */
53 struct GNUNET_CADET_ConnectionCreate
54 {
55     /**
56      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE
57      *
58      * Size: sizeof (struct GNUNET_CADET_ConnectionCreate) +
59      *       path_length * sizeof (struct GNUNET_PeerIdentity)
60      */
61   struct GNUNET_MessageHeader header;
62
63     /**
64      * ID of the connection
65      */
66   struct GNUNET_CADET_Hash cid;
67
68     /**
69      * path_length structs defining the *whole* path from the origin [0] to the
70      * final destination [path_length-1].
71      */
72   /* struct GNUNET_PeerIdentity peers[path_length]; */
73 };
74
75
76 /**
77  * Message for ack'ing a connection
78  */
79 struct GNUNET_CADET_ConnectionACK
80 {
81     /**
82      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_ACK
83      */
84   struct GNUNET_MessageHeader header;
85
86     /**
87      * ID of the connection.
88      */
89   struct GNUNET_CADET_Hash cid;
90
91 };
92
93
94 /**
95  * Message for encapsulation of a Key eXchange message in a connection.
96  */
97 struct GNUNET_CADET_KX
98 {
99     /**
100      * Type: GNUNET_MESSAGE_TYPE_CADET_KX.
101      */
102   struct GNUNET_MessageHeader header;
103
104     /**
105      * ID of the connection.
106      */
107   struct GNUNET_CADET_Hash cid;
108
109   /* Specific KX message follows. */
110 };
111
112
113
114 /**
115  * Message for encapsulation of a Key eXchange message in a connection.
116  */
117 struct GNUNET_CADET_AX_KX
118 {
119   /**
120    * Type: GNUNET_MESSAGE_TYPE_CADET_AX_KX.
121    */
122   struct GNUNET_MessageHeader header;
123
124   /**
125    * An EdDSA signature of the permanent ECDH key with the Peer's ID key.
126    */
127   struct GNUNET_CRYPTO_EddsaSignature signature;
128
129   /**
130    * Information about what is being signed (@a permanent_key).
131    */
132   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
133
134   /**
135    * Sender's permanent_key public ECC key encoded in a
136    * format suitable for network transmission, as created
137    * using 'gcry_sexp_sprint'.
138    */
139   struct GNUNET_CRYPTO_EcdhePublicKey permanent_key;
140
141   /**
142    * Sender's ephemeral public ECC key encoded in a
143    * format suitable for network transmission, as created
144    * using 'gcry_sexp_sprint'.
145    */
146   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
147
148   /**
149    * Sender's next ephemeral public ECC key encoded in a
150    * format suitable for network transmission, as created
151    * using 'gcry_sexp_sprint'.
152    */
153   struct GNUNET_CRYPTO_EcdhePublicKey ratchet_key;
154 };
155
156
157 /**
158  * Message transmitted with the signed ephemeral key of a peer.  The
159  * session key is then derived from the two ephemeral keys (ECDHE).
160  *
161  * As far as possible, same as CORE's EphemeralKeyMessage.
162  */
163 struct GNUNET_CADET_KX_Ephemeral
164 {
165
166   /**
167    * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL.
168    */
169   struct GNUNET_MessageHeader header;
170
171   /**
172    * Status of the sender (should be in "enum PeerStateMachine"), nbo.
173    */
174   int32_t sender_status GNUNET_PACKED;
175
176   /**
177    * An ECC signature of the 'origin' asserting the validity of
178    * the given ephemeral key.
179    */
180   struct GNUNET_CRYPTO_EddsaSignature signature;
181
182   /**
183    * Information about what is being signed.
184    */
185   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
186
187   /**
188    * At what time was this key created (beginning of validity).
189    */
190   struct GNUNET_TIME_AbsoluteNBO creation_time;
191
192   /**
193    * When does the given ephemeral key expire (end of validity).
194    */
195   struct GNUNET_TIME_AbsoluteNBO expiration_time;
196
197   /**
198    * Ephemeral public ECC key (always for NIST P-521) encoded in a format
199    * suitable for network transmission as created using 'gcry_sexp_sprint'.
200    */
201   struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
202
203   /**
204    * Public key of the signing peer
205    * (persistent version, not the ephemeral public key).
206    */
207   struct GNUNET_PeerIdentity origin_identity;
208
209   /**
210    * Seed for the IV of nonce.
211    */
212   uint32_t iv GNUNET_PACKED;
213
214   /**
215    * Nonce to check liveness of peer.
216    */
217   uint32_t nonce GNUNET_PACKED;
218 };
219
220
221 /**
222  * Response to a PING.  Includes data from the original PING.
223  */
224 struct GNUNET_CADET_KX_Pong
225 {
226   /**
227    * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_PONG.
228    */
229   struct GNUNET_MessageHeader header;
230
231   /**
232    * Seed for the IV
233    */
234   uint32_t iv GNUNET_PACKED;
235
236   /**
237    * Same nonce as in the reve.
238    */
239   uint32_t nonce GNUNET_PACKED;
240 };
241
242
243 /**
244  * Tunnel(ed) message.
245  */
246 struct GNUNET_CADET_Encrypted
247 {
248   /**
249    * Type: GNUNET_MESSAGE_TYPE_CADET_ENCRYPTED
250    */
251   struct GNUNET_MessageHeader header;
252
253   /**
254    * ID of the connection.
255    */
256   struct GNUNET_CADET_Hash cid;
257
258   /**
259    * ID of the packet (hop by hop).
260    */
261   uint32_t pid GNUNET_PACKED;
262
263   /**
264    * Number of hops to live.
265    */
266   uint32_t ttl GNUNET_PACKED;
267
268   /**
269    * Initialization Vector for payload encryption.
270    */
271   uint32_t iv GNUNET_PACKED;
272
273   /**
274    * MAC of the encrypted message, used to verify message integrity.
275    * Everything after this value  will be encrypted and authenticated.
276    */
277   struct GNUNET_CADET_Hash hmac;
278
279   /**
280    * Encrypted content follows.
281    */
282 };
283
284
285 /**
286  * Axolotl tunnel message.
287  */
288 struct GNUNET_CADET_AX
289 {
290   /**
291    * Type: GNUNET_MESSAGE_TYPE_CADET_AXOLOTL_DATA
292    */
293   struct GNUNET_MessageHeader header;
294
295   /**
296    * ID of the connection.
297    */
298   struct GNUNET_CADET_Hash cid;
299
300   /**
301    * ID of the packet (hop by hop).
302    */
303   uint32_t pid GNUNET_PACKED;
304
305   /**
306    * Reserved field for 64b alignment.
307    */
308   uint32_t reserved GNUNET_PACKED;
309
310   /**
311    * MAC of the encrypted message, used to verify message integrity.
312    * Everything after this value  will be encrypted with the header key
313    * and authenticated.
314    */
315   struct GNUNET_CADET_Hash hmac;
316
317   /**
318    * Number of messages sent with the current ratchet key.
319    */
320   uint32_t Ns;
321
322   /**
323    * Number of messages sent with the previous ratchet key.
324    */
325   uint32_t PNs;
326
327   /**
328    * Current ratchet key.
329    */
330   struct GNUNET_CRYPTO_EcdhePublicKey DHRs;
331
332   /**
333    * Encrypted content follows.
334    */
335 };
336
337
338 /**
339  * Message to create a Channel.
340  */
341 struct GNUNET_CADET_ChannelCreate
342 {
343   /**
344    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_CREATE
345    */
346   struct GNUNET_MessageHeader header;
347
348   /**
349    * ID of the channel
350    */
351   CADET_ChannelNumber chid GNUNET_PACKED;
352
353   /**
354    * Destination port.
355    */
356   uint32_t port GNUNET_PACKED;
357
358   /**
359    * Channel options.
360    */
361   uint32_t opt GNUNET_PACKED;
362 };
363
364
365 /**
366  * Message to manage a Channel (ACK, NACK, Destroy).
367  */
368 struct GNUNET_CADET_ChannelManage
369 {
370   /**
371    * Type: GNUNET_MESSAGE_TYPE_CADET_CHANNEL_{ACK|NACK|DESTROY}
372    */
373   struct GNUNET_MessageHeader header;
374
375   /**
376    * ID of the channel
377    */
378   CADET_ChannelNumber chid GNUNET_PACKED;
379 };
380
381
382 /**
383  * Message for cadet data traffic.
384  */
385 struct GNUNET_CADET_Data
386 {
387     /**
388      * Type: GNUNET_MESSAGE_TYPE_CADET_UNICAST,
389      *       GNUNET_MESSAGE_TYPE_CADET_TO_ORIGIN
390      */
391   struct GNUNET_MessageHeader header;
392
393     /**
394      * Unique ID of the payload message
395      */
396   uint32_t mid GNUNET_PACKED;
397
398     /**
399      * ID of the channel
400      */
401   CADET_ChannelNumber chid GNUNET_PACKED;
402
403     /**
404      * Payload follows
405      */
406 };
407
408
409 /**
410  * Message to acknowledge end-to-end data.
411  */
412 struct GNUNET_CADET_DataACK
413 {
414   /**
415    * Type: GNUNET_MESSAGE_TYPE_CADET_DATA_ACK
416    */
417   struct GNUNET_MessageHeader header;
418
419   /**
420    * ID of the channel
421    */
422   CADET_ChannelNumber chid GNUNET_PACKED;
423
424   /**
425    * Bitfield of already-received newer messages
426    * pid +  1 @ LSB
427    * pid + 64 @ MSB
428    */
429   uint64_t futures GNUNET_PACKED;
430
431   /**
432    * Last message ID received.
433    */
434   uint32_t mid GNUNET_PACKED;
435 };
436
437
438 /**
439  * Message to acknowledge cadet encrypted traffic.
440  */
441 struct GNUNET_CADET_ACK
442 {
443     /**
444      * Type: GNUNET_MESSAGE_TYPE_CADET_ACK
445      */
446   struct GNUNET_MessageHeader header;
447
448     /**
449      * Maximum packet ID authorized.
450      */
451   uint32_t ack GNUNET_PACKED;
452
453     /**
454      * ID of the connection.
455      */
456   struct GNUNET_CADET_Hash cid;
457 };
458
459
460 /**
461  * Message to query a peer about its Flow Control status regarding a tunnel.
462  */
463 struct GNUNET_CADET_Poll
464 {
465     /**
466      * Type: GNUNET_MESSAGE_TYPE_CADET_POLL
467      */
468   struct GNUNET_MessageHeader header;
469
470     /**
471      * Last packet sent.
472      */
473   uint32_t pid GNUNET_PACKED;
474
475     /**
476      * ID of the connection.
477      */
478   struct GNUNET_CADET_Hash cid;
479
480 };
481
482
483 /**
484  * Message for notifying a disconnection in a path
485  */
486 struct GNUNET_CADET_ConnectionBroken
487 {
488     /**
489      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN
490      */
491   struct GNUNET_MessageHeader header;
492
493     /**
494      * ID of the connection.
495      */
496   struct GNUNET_CADET_Hash cid;
497
498     /**
499      * ID of the endpoint
500      */
501   struct GNUNET_PeerIdentity peer1;
502
503     /**
504      * ID of the endpoint
505      */
506   struct GNUNET_PeerIdentity peer2;
507 };
508
509
510 /**
511  * Message to destroy a connection.
512  */
513 struct GNUNET_CADET_ConnectionDestroy
514 {
515     /**
516      * Type: GNUNET_MESSAGE_TYPE_CADET_CONNECTION_DESTROY
517      */
518   struct GNUNET_MessageHeader header;
519
520     /**
521      * ID of the connection.
522      */
523   struct GNUNET_CADET_Hash cid;
524 };
525
526
527 GNUNET_NETWORK_STRUCT_END
528
529 #if 0                           /* keep Emacsens' auto-indent happy */
530 {
531 #endif
532 #ifdef __cplusplus
533 }
534 #endif
535
536 /* ifndef CADET_PROTOCOL_H */
537 #endif
538 /* end of cadet_protocol.h */