GNUnet 0.26.2-16-ge86b66bd5
 
Loading...
Searching...
No Matches
messenger_api_message.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2025 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 */
27
28#include "gnunet_common.h"
30#include "gnunet_signatures.h"
31
32const uint16_t encryption_overhead =
34
40
46
49{
50 struct GNUNET_MESSENGER_Message *message;
51
52 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
53 message->header.kind = kind;
54
55 switch (message->header.kind)
56 {
58 message->body.name.name = NULL;
59 break;
61 message->body.text.text = NULL;
62 break;
64 message->body.file.uri = NULL;
65 break;
67 message->body.privacy.length = 0;
68 message->body.privacy.data = NULL;
69 break;
71 message->body.ticket.identifier = NULL;
72 break;
74 message->body.transcript.length = 0;
75 message->body.transcript.data = NULL;
76 break;
78 message->body.tag.tag = NULL;
79 break;
81 message->body.talk.length = 0;
82 message->body.talk.data = NULL;
83 break;
85 message->body.secret.length = 0;
86 message->body.secret.data = NULL;
87 break;
88 default:
89 break;
90 }
91
92 return message;
93}
94
95
98{
99 struct GNUNET_MESSENGER_Message *copy;
100
101 GNUNET_assert (message);
102
103 copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
104 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
105
106 switch (message->header.kind)
107 {
109 copy->body.name.name = message->body.name.name? GNUNET_strdup (
110 message->body.name.name) : NULL;
111 break;
113 copy->body.text.text = message->body.text.text? GNUNET_strdup (
114 message->body.text.text) : NULL;
115 break;
117 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
118 message->body.file.uri) : NULL;
119 break;
122 copy->body.privacy.length) : NULL;
123
124 if (copy->body.privacy.data)
125 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
126 copy->body.privacy.length);
127
128 break;
130 copy->body.ticket.identifier = message->body.ticket.identifier?
132 message->body.ticket.identifier) : NULL;
133 break;
136 copy->body.transcript.length) : NULL;
137
138 if (copy->body.transcript.data)
140 copy->body.transcript.length);
141
142 break;
144 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
145 message->body.tag.tag) : NULL;
146 break;
148 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
149 copy->body.talk.length) : NULL;
150
151 if (copy->body.talk.data)
152 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
153 copy->body.talk.length);
154
155 break;
157 copy->body.secret.data = copy->body.secret.length ? GNUNET_malloc (
158 copy->body.secret.length) : NULL;
159
160 if (copy->body.secret.data)
161 GNUNET_memcpy (copy->body.secret.data, message->body.secret.data,
162 copy->body.secret.length);
163
164 break;
165 default:
166 break;
167 }
168
169 return copy;
170}
171
172
173void
176{
178
179 GNUNET_assert ((message) && (header));
180
181 kind = message->header.kind;
182
183 GNUNET_memcpy (&(message->header), header,
184 sizeof(struct GNUNET_MESSENGER_MessageHeader));
185
186 message->header.kind = kind;
187}
188
189
190static void
193{
195
196 switch (kind)
197 {
199 if (body->name.name)
201 break;
203 if (body->text.text)
205 break;
207 if (body->file.uri)
209 break;
211 if (body->privacy.data)
213 break;
217 break;
219 if (body->transcript.data)
221 break;
223 if (body->tag.tag)
225 break;
227 if (body->talk.data)
229 break;
231 if (body->secret.data)
233 break;
234 default:
235 break;
236 }
237}
238
239
240void
242{
243 GNUNET_assert (message);
244
245 destroy_message_body (message->header.kind, &(message->body));
246}
247
248
249void
251{
252 GNUNET_assert (message);
253
254 destroy_message_body (message->header.kind, &(message->body));
255
256 GNUNET_free (message);
257}
258
259
262{
263 GNUNET_assert (message);
264
265 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
267 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
268 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
270 return GNUNET_YES;
271 else
272 return GNUNET_NO;
273}
274
275
276static void
278 struct GNUNET_MESSENGER_ShortMessage *shortened)
279{
280 shortened->kind = message->header.kind;
281
282 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
284}
285
286
287static void
289 struct GNUNET_MESSENGER_Message *message)
290{
291 destroy_message_body (message->header.kind, &(message->body));
292
293 message->header.kind = shortened->kind;
294
295 GNUNET_memcpy (&(message->body), &(shortened->body),
296 sizeof(struct GNUNET_MESSENGER_MessageBody));
297}
298
299
300#define member_size(type, member) sizeof(((type*) NULL)->member)
301
302static uint16_t
304{
305 uint16_t length;
306
307 length = 0;
308
309 switch (kind)
310 {
312 length += member_size (struct GNUNET_MESSENGER_Message,
314 break;
316 length += member_size (struct GNUNET_MESSENGER_Message,
317 body.join.epoch);
318 break;
320 length += member_size (struct GNUNET_MESSENGER_Message,
322 break;
325 break;
327 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
328 break;
331 break;
333 length += member_size (struct GNUNET_MESSENGER_Message,
334 body.merge.epochs[0]);
335 length += member_size (struct GNUNET_MESSENGER_Message,
336 body.merge.epochs[1]);
337 length += member_size (struct GNUNET_MESSENGER_Message,
339 break;
342 break;
346 break;
351 break;
354 length += member_size (struct GNUNET_MESSENGER_Message,
356 break;
358 length += member_size (struct GNUNET_MESSENGER_Message,
360 length += member_size (struct GNUNET_MESSENGER_Message,
362 break;
364 length += member_size (struct GNUNET_MESSENGER_Message,
366 break;
369 break;
371 length += member_size (struct GNUNET_MESSENGER_Message,
373 length += member_size (struct GNUNET_MESSENGER_Message,
375 length += member_size (struct GNUNET_MESSENGER_Message,
377 break;
379 length += member_size (struct GNUNET_MESSENGER_Message,
381 break;
383 length += member_size (struct GNUNET_MESSENGER_Message,
385 length += member_size (struct GNUNET_MESSENGER_Message,
387 length += member_size (struct GNUNET_MESSENGER_Message,
389 length += member_size (struct GNUNET_MESSENGER_Message,
391 length += member_size (struct GNUNET_MESSENGER_Message,
393 break;
395 length += member_size (struct GNUNET_MESSENGER_Message,
397 length += member_size (struct GNUNET_MESSENGER_Message,
398 body.secret.iv);
399 length += member_size (struct GNUNET_MESSENGER_Message,
401 break;
403 length += member_size (struct GNUNET_MESSENGER_Message,
405 length += member_size (struct GNUNET_MESSENGER_Message,
406 body.appeal.key);
407 length += member_size (struct GNUNET_MESSENGER_Message,
409 break;
411 length += member_size (struct GNUNET_MESSENGER_Message,
413 length += member_size (struct GNUNET_MESSENGER_Message,
414 body.access.key);
415 length += member_size (struct GNUNET_MESSENGER_Message,
417 break;
419 length += member_size (struct GNUNET_MESSENGER_Message,
421 length += member_size (struct GNUNET_MESSENGER_Message,
423 length += member_size (struct GNUNET_MESSENGER_Message,
425 break;
427 length += member_size (struct GNUNET_MESSENGER_Message,
429 length += member_size (struct GNUNET_MESSENGER_Message,
431 length += member_size (struct GNUNET_MESSENGER_Message,
433 length += member_size (struct GNUNET_MESSENGER_Message,
435 break;
437 length += member_size (struct GNUNET_MESSENGER_Message,
439 length += member_size (struct GNUNET_MESSENGER_Message,
441 length += member_size (struct GNUNET_MESSENGER_Message,
443 length += member_size (struct GNUNET_MESSENGER_Message,
445 break;
446 default:
447 break;
448 }
449
450 return length;
451}
452
453
454typedef uint32_t kind_t;
455
456uint16_t
458 enum GNUNET_GenericReturnValue include_header)
459{
460 uint16_t length;
461
462 length = 0;
463
464 if (GNUNET_YES == include_header)
465 {
469 }
470
471 length += sizeof(kind_t);
472
473 return length + get_message_body_kind_size (kind);
474}
475
476
477static uint16_t
480{
481 uint16_t length;
482
483 length = 0;
484
485 switch (kind)
486 {
490 break;
492 length += (body->name.name ? strlen (body->name.name) : 0);
493 break;
497 break;
499 length += (body->text.text ? strlen (body->text.text) : 0);
500 break;
502 length += (body->file.uri ? strlen (body->file.uri) : 0);
503 break;
505 length += body->privacy.length;
506 break;
508 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
509 break;
512 length += body->transcript.length;
513 break;
515 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
516 break;
518 length += body->talk.length;
519 break;
521 length += body->secret.length;
522 break;
523 default:
524 break;
525 }
526
527 return length;
528}
529
530
531uint16_t
533 enum GNUNET_GenericReturnValue include_header)
534{
535 uint16_t length;
536
537 GNUNET_assert (message);
538
539 length = 0;
540
541 if (GNUNET_YES == include_header)
543 &(message->header.signature));
544
545 length += get_message_kind_size (message->header.kind, include_header);
546 length += get_message_body_size (message->header.kind, &(message->body));
547
548 return length;
549}
550
551
552static uint16_t
554 enum GNUNET_GenericReturnValue include_body)
555{
556 uint16_t minimum_size;
557
558 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
559
560 if (message)
561 return minimum_size + get_message_body_kind_size (message->kind)
562 + (include_body == GNUNET_YES?
563 get_message_body_size (message->kind, &(message->body)) : 0);
564 else
565 return minimum_size;
566}
567
568
569static uint16_t
571{
572 uint16_t padding;
573 uint16_t kind_size;
574
575 padding = 0;
576
577 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
578 {
580 GNUNET_YES);
581
582 if (kind_size > padding)
583 padding = kind_size;
584 }
585
586 return padding + GNUNET_MESSENGER_PADDING_MIN;
587}
588
589
590#define max(x, y) (x > y? x : y)
591
592static uint16_t
593calc_padded_length (uint16_t length)
594{
595 static uint16_t usual_padding = 0;
596 uint16_t padded_length;
597
598 if (! usual_padding)
599 usual_padding = calc_usual_padding ();
600
601 padded_length = max (
603 usual_padding);
604
605 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
607
608 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
610
611 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
613
615
616}
617
618
619#define min(x, y) (x < y? x : y)
620
621#define encode_step_ext(dst, offset, src, size) do { \
622 GNUNET_memcpy (dst + offset, src, size); \
623 offset += size; \
624} while (0)
625
626#define encode_step(dst, offset, src) do { \
627 encode_step_ext (dst, offset, src, sizeof(*src)); \
628} while (0)
629
630#define encode_step_key(dst, offset, src, length) do { \
631 ssize_t result = GNUNET_CRYPTO_write_blindable_pk_to_buffer ( \
632 src, dst + offset, length - offset); \
633 if (result < 0) \
634 GNUNET_break (0); \
635 else \
636 offset += result; \
637} while (0)
638
639#define encode_step_hpke_key(dst, offset, src, length) do { \
640 ssize_t result = GNUNET_CRYPTO_write_hpke_pk_to_buffer ( \
641 src, dst + offset, length - offset); \
642 if (result < 0) \
643 GNUNET_break (0); \
644 else \
645 offset += result; \
646} while (0)
647
648#define encode_step_signature(dst, offset, src, length) do { \
649 ssize_t result = GNUNET_CRYPTO_write_blinded_key_signature_to_buffer ( \
650 src, dst + offset, length - offset); \
651 if (result < 0) \
652 GNUNET_break (0); \
653 else \
654 offset += result; \
655} while (0)
656
657static void
659 const struct GNUNET_MESSENGER_MessageBody *body,
660 uint16_t length,
661 char *buffer,
662 uint16_t offset)
663{
664 uint32_t value0, value1;
665
666 GNUNET_assert ((body) && (buffer));
667
668 switch (kind)
669 {
671 value0 = GNUNET_htobe32 (body->info.messenger_version);
672
673 encode_step (buffer, offset, &value0);
674 break;
676 encode_step (buffer, offset, &(body->join.epoch));
677 encode_step_key (buffer, offset, &(body->join.key), length);
678 encode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
679 break;
681 encode_step (buffer, offset, &(body->leave.epoch));
682 break;
684 if (body->name.name)
686 buffer,
687 offset,
688 body->name.name,
689 min (length - offset, strlen (body->name.name)));
690 break;
692 encode_step_key (buffer, offset, &(body->key.key), length);
693 encode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
694 break;
696 encode_step (buffer, offset, &(body->peer.peer));
697 break;
699 encode_step (buffer, offset, &(body->id.id));
700 break;
702 encode_step (buffer, offset, &(body->miss.peer));
703 break;
705 encode_step (buffer, offset, &(body->merge.epochs[0]));
706 encode_step (buffer, offset, &(body->merge.epochs[1]));
707 encode_step (buffer, offset, &(body->merge.previous));
708 break;
710 encode_step (buffer, offset, &(body->request.hash));
711 break;
713 encode_step (buffer, offset, &(body->invite.door));
714 encode_step (buffer, offset, &(body->invite.key));
715 break;
717 if (body->text.text)
719 buffer,
720 offset,
721 body->text.text,
722 min (length - offset, strlen (body->text.text)));
723 break;
725 encode_step (buffer, offset, &(body->file.key));
726 encode_step (buffer, offset, &(body->file.hash));
727 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
728 if (body->file.uri)
729 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
730 strlen (
731 body->file.uri)));
732 break;
734 if (body->privacy.data)
735 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
736 body->privacy.
737 length));
738 break;
740 encode_step (buffer, offset, &(body->deletion.hash));
741 encode_step (buffer, offset, &(body->deletion.delay));
742 break;
744 value0 = GNUNET_htobe32 (body->connection.amount);
745 value1 = GNUNET_htobe32 (body->connection.flags);
746
747 encode_step (buffer, offset, &value0);
748 encode_step (buffer, offset, &value1);
749 break;
751 encode_step_ext (buffer, offset, body->ticket.identifier,
752 min (length - offset, strlen (body->ticket.identifier)));
753 break;
755 encode_step (buffer, offset, &(body->transcript.hash));
756 encode_step_key (buffer, offset, &(body->transcript.key), length);
757
758 if (body->transcript.data)
759 encode_step_ext (buffer, offset, body->transcript.data, min (length
760 - offset,
761 body->
762 transcript.
763 length));
764 break;
766 encode_step (buffer, offset, &(body->tag.hash));
767
768 if (body->tag.tag)
769 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
770 strlen (
771 body->tag.tag)));
772 break;
774 value0 = GNUNET_htobe32 (body->subscription.flags);
775
776 encode_step (buffer, offset, &(body->subscription.discourse));
777 encode_step (buffer, offset, &(body->subscription.time));
778 encode_step (buffer, offset, &value0);
779 break;
781 encode_step (buffer, offset, &(body->talk.discourse));
782
783 if (body->talk.data)
784 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
785 body->talk.
786 length));
787 break;
789 encode_step (buffer, offset, &(body->announcement.identifier));
790 encode_step (buffer, offset, &(body->announcement.key));
791 encode_step (buffer, offset, &(body->announcement.nonce));
792 encode_step (buffer, offset, &(body->announcement.timeout));
793 encode_step (buffer, offset, &(body->announcement.hmac));
794 break;
796 encode_step (buffer, offset, &(body->secret.identifier));
797 encode_step (buffer, offset, &(body->secret.iv));
798 encode_step (buffer, offset, &(body->secret.hmac));
799
800 if (body->secret.data)
801 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
802 body->secret.
803 length));
804 break;
806 encode_step (buffer, offset, &(body->appeal.event));
807 encode_step (buffer, offset, &(body->appeal.key));
808 encode_step (buffer, offset, &(body->appeal.timeout));
809 break;
811 encode_step (buffer, offset, &(body->access.event));
812 encode_step (buffer, offset, &(body->access.key));
813 encode_step (buffer, offset, &(body->access.hmac));
814 break;
816 encode_step (buffer, offset, &(body->revolution.identifier));
817 encode_step (buffer, offset, &(body->revolution.nonce));
818 encode_step (buffer, offset, &(body->revolution.hmac));
819 break;
821 encode_step (buffer, offset, &(body->group.identifier));
822 encode_step (buffer, offset, &(body->group.initiator));
823 encode_step (buffer, offset, &(body->group.partner));
824 encode_step (buffer, offset, &(body->group.timeout));
825 break;
827 encode_step (buffer, offset, &(body->authorization.identifier));
828 encode_step (buffer, offset, &(body->authorization.event));
829 encode_step (buffer, offset, &(body->authorization.key));
830 encode_step (buffer, offset, &(body->authorization.hmac));
831 break;
832 default:
833 break;
834 }
835
836 if (offset >= length)
837 return;
838
839 {
840 uint16_t padding;
841 uint16_t used_padding;
842
843 padding = length - offset;
844 used_padding = sizeof(padding) + sizeof(char);
845
846 GNUNET_assert (padding >= used_padding);
847
848 buffer[offset++] = '\0';
849
850 if (padding > used_padding)
852 padding - used_padding);
853
854 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
855 sizeof(padding));
856 }
857}
858
859
860void
862 uint16_t length,
863 char *buffer,
864 enum GNUNET_GenericReturnValue include_header)
865{
866 uint16_t offset;
867 kind_t kind;
868
869 GNUNET_assert ((message) && (buffer));
870
871 offset = 0;
872
873 if (GNUNET_YES == include_header)
874 encode_step_signature (buffer, offset, &(message->header.signature),
875 length);
876
877 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
878
879 if (GNUNET_YES == include_header)
880 {
881 encode_step (buffer, offset, &(message->header.timestamp));
882 encode_step (buffer, offset, &(message->header.sender_id));
883 encode_step (buffer, offset, &(message->header.previous));
884 }
885
886 encode_step (buffer, offset, &kind);
887
888 encode_message_body (message->header.kind, &(message->body),
889 length, buffer, offset);
890}
891
892
893static void
895 uint16_t length,
896 char *buffer)
897{
898 struct GNUNET_HashCode hash;
899 uint16_t offset;
900 kind_t kind;
901
902 GNUNET_assert ((message) && (buffer));
903
904 offset = sizeof(hash);
905 kind = GNUNET_htobe32 ((kind_t) message->kind);
906
907 encode_step (buffer, offset, &kind);
908
909 encode_message_body (message->kind, &(message->body), length, buffer, offset);
910
912 buffer + sizeof(hash),
913 length - sizeof(hash),
914 &hash);
915
916 GNUNET_memcpy (buffer, &hash, sizeof(hash));
917}
918
919
920#define decode_step_ext(src, offset, dst, size) do { \
921 GNUNET_memcpy (dst, src + offset, size); \
922 offset += size; \
923} while (0)
924
925#define decode_step(src, offset, dst) do { \
926 decode_step_ext (src, offset, dst, sizeof(*dst)); \
927} while (0)
928
929#define decode_step_malloc(src, offset, dst, size, zero) do { \
930 dst = GNUNET_malloc (size + zero); \
931 if (zero) dst[size] = 0; \
932 decode_step_ext (src, offset, dst, size); \
933} while (0)
934
935#define decode_step_key(src, offset, dst, length) do { \
936 enum GNUNET_GenericReturnValue result; \
937 size_t read; \
938 result = GNUNET_CRYPTO_read_blindable_pk_from_buffer ( \
939 src + offset, length - offset, dst, &read); \
940 if (GNUNET_SYSERR == result) \
941 GNUNET_break (0); \
942 else \
943 offset += read; \
944} while (0)
945
946#define decode_step_hpke_key(src, offset, dst, length) do { \
947 enum GNUNET_GenericReturnValue result; \
948 size_t read; \
949 result = GNUNET_CRYPTO_read_hpke_pk_from_buffer ( \
950 src + offset, length - offset, dst, &read); \
951 if (GNUNET_SYSERR == result) \
952 GNUNET_break (0); \
953 else \
954 offset += read; \
955} while (0)
956
957static uint16_t
959 struct GNUNET_MESSENGER_MessageBody *body,
960 uint16_t length,
961 const char *buffer,
962 uint16_t offset)
963{
964 uint16_t padding;
965 uint32_t value0, value1;
966
967 GNUNET_assert ((kind) && (body) && (buffer));
968
969 padding = 0;
970
971 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
972
973 if (padding > length - offset)
974 padding = 0;
975
976 {
977 uint16_t end_zero;
978 end_zero = length - padding;
979
980 if ((padding) && (buffer[end_zero] != '\0'))
981 padding = 0;
982 }
983
984 length -= padding;
985
986 switch (*kind)
987 {
989 decode_step (buffer, offset, &value0);
990
991 body->info.messenger_version = GNUNET_be32toh (value0);
992 break;
994 decode_step (buffer, offset, &(body->join.epoch));
995 decode_step_key (buffer, offset, &(body->join.key), length);
996 decode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
997 break;
999 decode_step (buffer, offset, &(body->leave.epoch));
1000 break;
1002 if (length > offset)
1003 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
1004 else
1005 body->name.name = NULL;
1006 break;
1008 decode_step_key (buffer, offset, &(body->key.key), length);
1009 decode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
1010 break;
1012 decode_step (buffer, offset, &(body->peer.peer));
1013 break;
1015 decode_step (buffer, offset, &(body->id.id));
1016 break;
1018 decode_step (buffer, offset, &(body->miss.peer));
1019 break;
1021 decode_step (buffer, offset, &(body->merge.epochs[0]));
1022 decode_step (buffer, offset, &(body->merge.epochs[1]));
1023 decode_step (buffer, offset, &(body->merge.previous));
1024 break;
1026 decode_step (buffer, offset, &(body->request.hash));
1027 break;
1029 decode_step (buffer, offset, &(body->invite.door));
1030 decode_step (buffer, offset, &(body->invite.key));
1031 break;
1033 if (length > offset)
1034 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1035 else
1036 body->text.text = NULL;
1037 break;
1039 decode_step (buffer, offset, &(body->file.key));
1040 decode_step (buffer, offset, &(body->file.hash));
1041 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1042 if (length > offset)
1043 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1044 else
1045 body->file.uri = NULL;
1046 break;
1048 if (length > offset)
1049 {
1050 body->privacy.length = (length - offset);
1051 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1052 0);
1053 }
1054 else
1055 {
1056 body->privacy.length = 0;
1057 body->privacy.data = NULL;
1058 }
1059
1060 break;
1062 decode_step (buffer, offset, &(body->deletion.hash));
1063 decode_step (buffer, offset, &(body->deletion.delay));
1064 break;
1066 decode_step (buffer, offset, &value0);
1067 decode_step (buffer, offset, &value1);
1068
1069 body->connection.amount = GNUNET_be32toh (value0);
1070 body->connection.flags = GNUNET_be32toh (value1);
1071 break;
1073 if (length > offset)
1074 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1075 - offset, 1);
1076 else
1077 body->ticket.identifier = NULL;
1078 break;
1080 decode_step (buffer, offset, &(body->transcript.hash));
1081 decode_step_key (buffer, offset, &(body->transcript.key), length);
1082
1083 if (length > offset)
1084 {
1085 body->transcript.length = (length - offset);
1086 decode_step_malloc (buffer, offset, body->transcript.data,
1087 length - offset, 0);
1088 }
1089 else
1090 {
1091 body->transcript.length = 0;
1092 body->transcript.data = NULL;
1093 }
1094
1095 break;
1097 decode_step (buffer, offset, &(body->tag.hash));
1098 if (length > offset)
1099 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1100 else
1101 body->tag.tag = NULL;
1102 break;
1104 decode_step (buffer, offset, &(body->subscription.discourse));
1105 decode_step (buffer, offset, &(body->subscription.time));
1106 decode_step (buffer, offset, &value0);
1107
1108 body->subscription.flags = GNUNET_be32toh (value0);
1109 break;
1111 decode_step (buffer, offset, &(body->talk.discourse));
1112
1113 if (length > offset)
1114 {
1115 body->talk.length = (length - offset);
1116 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1117 0);
1118 }
1119 else
1120 {
1121 body->talk.length = 0;
1122 body->talk.data = NULL;
1123 }
1124
1125 break;
1127 decode_step (buffer, offset, &(body->announcement.identifier));
1128 decode_step (buffer, offset, &(body->announcement.key));
1129 decode_step (buffer, offset, &(body->announcement.nonce));
1130 decode_step (buffer, offset, &(body->announcement.timeout));
1131 decode_step (buffer, offset, &(body->announcement.hmac));
1132 break;
1134 decode_step (buffer, offset, &(body->secret.identifier));
1135 decode_step (buffer, offset, &(body->secret.iv));
1136 decode_step (buffer, offset, &(body->secret.hmac));
1137
1138 if (length > offset)
1139 {
1140 body->secret.length = (length - offset);
1141 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1142 0);
1143 }
1144 else
1145 {
1146 body->secret.length = 0;
1147 body->secret.data = NULL;
1148 }
1149
1150 break;
1152 decode_step (buffer, offset, &(body->appeal.event));
1153 decode_step (buffer, offset, &(body->appeal.key));
1154 decode_step (buffer, offset, &(body->appeal.timeout));
1155 break;
1157 decode_step (buffer, offset, &(body->access.event));
1158 decode_step (buffer, offset, &(body->access.key));
1159 decode_step (buffer, offset, &(body->access.hmac));
1160 break;
1162 decode_step (buffer, offset, &(body->revolution.identifier));
1163 decode_step (buffer, offset, &(body->revolution.nonce));
1164 decode_step (buffer, offset, &(body->revolution.hmac));
1165 break;
1167 decode_step (buffer, offset, &(body->group.identifier));
1168 decode_step (buffer, offset, &(body->group.initiator));
1169 decode_step (buffer, offset, &(body->group.partner));
1170 decode_step (buffer, offset, &(body->group.timeout));
1171 break;
1173 decode_step (buffer, offset, &(body->authorization.identifier));
1174 decode_step (buffer, offset, &(body->authorization.event));
1175 decode_step (buffer, offset, &(body->authorization.key));
1176 decode_step (buffer, offset, &(body->authorization.hmac));
1177 break;
1178 default:
1180 break;
1181 }
1182
1183 return padding;
1184}
1185
1186
1189 uint16_t length,
1190 const char *buffer,
1191 enum GNUNET_GenericReturnValue include_header,
1192 uint16_t *padding)
1193{
1194 uint16_t offset;
1195 uint16_t count;
1196 kind_t kind;
1197
1199 (message) &&
1200 (buffer) &&
1202 include_header)));
1203
1204 offset = 0;
1205
1206 if (GNUNET_YES == include_header)
1207 {
1208 ssize_t result;
1209
1211 &(message->header.signature), buffer, length - offset);
1212
1213 if (result < 0)
1214 return GNUNET_NO;
1215 else
1216 offset += result;
1217 }
1218
1219 count = length - offset;
1221 include_header))
1222 return GNUNET_NO;
1223
1224 if (GNUNET_YES == include_header)
1225 {
1226 decode_step (buffer, offset, &(message->header.timestamp));
1227 decode_step (buffer, offset, &(message->header.sender_id));
1228 decode_step (buffer, offset, &(message->header.previous));
1229 }
1230
1231 decode_step (buffer, offset, &kind);
1232 kind = GNUNET_be32toh (kind);
1233
1234 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1235
1236 if (count < get_message_kind_size (message->header.kind, include_header))
1237 return GNUNET_NO;
1238
1239 {
1240 uint16_t result;
1241 result = decode_message_body (&(message->header.kind),
1242 &(message->body), length, buffer, offset);
1243
1244 if (padding)
1245 *padding = result;
1246 }
1247
1248 return GNUNET_YES;
1249}
1250
1251
1252static enum GNUNET_GenericReturnValue
1254 uint16_t length,
1255 const char *buffer)
1256{
1257 struct GNUNET_HashCode expected, hash;
1258 uint16_t offset;
1259 kind_t kind;
1260
1261 GNUNET_assert ((message) && (buffer));
1262
1263 offset = sizeof(hash);
1264
1265 if (length < get_short_message_size (NULL, GNUNET_NO))
1266 return GNUNET_NO;
1267
1268 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1269
1271 buffer + sizeof(hash),
1272 length - sizeof(hash),
1273 &expected);
1274
1275 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1276 return GNUNET_NO;
1277
1278 decode_step (buffer, offset, &kind);
1279 kind = GNUNET_be32toh (kind);
1280
1281 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1282
1283 if (length < get_short_message_size (message, GNUNET_NO))
1284 return GNUNET_NO;
1285
1286 decode_message_body (&(message->kind), &(message->body), length, buffer,
1287 offset);
1288
1289 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1290 return GNUNET_NO;
1291
1292 return GNUNET_YES;
1293}
1294
1295
1296void
1298 uint16_t length,
1299 const char *buffer,
1300 struct GNUNET_HashCode *hash)
1301{
1302 ssize_t offset;
1303
1304 GNUNET_assert ((message) && (buffer) && (hash));
1305
1307 signature));
1308
1309 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1310}
1311
1312
1313void
1315 uint16_t length,
1316 char *buffer,
1317 const struct GNUNET_HashCode *hash,
1319{
1320 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1321
1322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1323 GNUNET_h2s (hash));
1324
1325 {
1326 struct GNUNET_MESSENGER_MessageSignature signature;
1327
1329 signature.purpose.size = htonl (sizeof(signature));
1330
1331 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1332 GNUNET_CRYPTO_blinded_key_sign (key, &signature, &(message->header.signature
1333 ));
1334 }
1335
1336 message->header.signature.type = key->type;
1337
1338 {
1339 uint16_t offset = 0;
1341 buffer,
1342 offset,
1343 &(message->header.signature),
1344 length);
1345 }
1346}
1347
1348
1349void
1351 uint16_t length,
1352 char *buffer,
1353 const struct GNUNET_HashCode *hash,
1354 const struct GNUNET_CONFIGURATION_Handle *cfg)
1355{
1356 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1357
1358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1359 GNUNET_h2s (hash));
1360
1361 {
1362 struct GNUNET_MESSENGER_MessageSignature signature;
1364 signature.purpose.size = htonl (sizeof (signature));
1365
1366 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1368 &(message->header.signature
1369 .
1370 eddsa_signature));
1371 }
1372
1374
1375 {
1376 uint16_t offset = 0;
1378 buffer,
1379 offset,
1380 &(message->header.signature),
1381 length);
1382 }
1383}
1384
1385
1386static void
1389 struct GNUNET_HashCode *hmac)
1390{
1391 struct GNUNET_CRYPTO_AuthKey auth_key;
1392
1393 GNUNET_assert ((message) && (key) && (hmac));
1394
1395 switch (message->header.kind)
1396 {
1399 &auth_key, key,
1400 &(message->body.announcement.nonce),
1402 &(message->body.announcement.identifier),
1403 sizeof (message->body.announcement.identifier),
1404 NULL);
1405
1406 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1407 sizeof (message->body.announcement)
1408 - sizeof (*hmac),
1409 hmac);
1410 break;
1413 &auth_key, key, &(message->body.access.event),
1414 sizeof (message->body.access.event), NULL);
1415
1416 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1417 sizeof (message->body.access)
1418 - sizeof (*hmac),
1419 hmac);
1420 break;
1423 &auth_key, key,
1424 &(message->body.revolution.nonce),
1426 &(message->body.revolution.identifier),
1427 sizeof (message->body.revolution.identifier),
1428 NULL);
1429
1430 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1431 sizeof (message->body.revolution)
1432 - sizeof (*hmac),
1433 hmac);
1434 break;
1437 &auth_key, key,
1438 &(message->body.authorization.event),
1439 sizeof (message->body.authorization.event),
1440 &(message->body.authorization.identifier),
1441 sizeof (message->body.authorization.identifier),
1442 NULL);
1443
1444 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1445 sizeof (message->body.authorization)
1446 - sizeof (*hmac),
1447 hmac);
1448 break;
1449 default:
1450 break;
1451 }
1452}
1453
1454
1455void
1458{
1459 struct GNUNET_HashCode *hmac;
1460
1461 GNUNET_assert ((message) && (key));
1462
1463 switch (message->header.kind)
1464 {
1466 hmac = &(message->body.announcement.hmac);
1467 break;
1469 hmac = &(message->body.access.hmac);
1470 break;
1472 hmac = &(message->body.revolution.hmac);
1473 break;
1475 hmac = &(message->body.authorization.hmac);
1476 break;
1477 default:
1478 hmac = NULL;
1479 break;
1480 }
1481
1482 if (! hmac)
1483 return;
1484
1485 calc_message_hmac (message, key, hmac);
1486}
1487
1488
1491 const struct GNUNET_HashCode *hash,
1493{
1494 struct GNUNET_MESSENGER_MessageSignature signature;
1495
1496 GNUNET_assert ((message) && (hash) && (key));
1497
1498 if (key->type != message->header.signature.type)
1499 return GNUNET_SYSERR;
1500
1502 signature.purpose.size = htonl (sizeof(signature));
1503
1504 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1505
1508 &(message->header.signature), key);
1509}
1510
1511
1514 const struct GNUNET_HashCode *hash,
1515 const struct GNUNET_PeerIdentity *identity)
1516{
1517 struct GNUNET_MESSENGER_MessageSignature signature;
1518
1519 GNUNET_assert ((message) && (hash) && (identity));
1520
1521 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1522 return GNUNET_SYSERR;
1523
1525 signature.purpose.size = htonl (sizeof(signature));
1526
1527 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1528
1531 &(message->header.signature.
1532 eddsa_signature), identity);
1533}
1534
1535
1539{
1540 const struct GNUNET_HashCode *msg_hmac;
1541 struct GNUNET_HashCode hmac;
1542
1543 GNUNET_assert ((message) && (key));
1544
1545 switch (message->header.kind)
1546 {
1548 msg_hmac = &(message->body.announcement.hmac);
1549 break;
1551 msg_hmac = &(message->body.access.hmac);
1552 break;
1554 msg_hmac = &(message->body.revolution.hmac);
1555 break;
1557 msg_hmac = &(message->body.authorization.hmac);
1558 break;
1559 default:
1560 msg_hmac = NULL;
1561 break;
1562 }
1563
1564 if (! msg_hmac)
1565 return GNUNET_SYSERR;
1566
1567 calc_message_hmac (message, key, &hmac);
1568
1569 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1570 return GNUNET_OK;
1571
1572 return GNUNET_SYSERR;
1573}
1574
1575
1578 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
1579{
1581 struct GNUNET_MESSENGER_ShortMessage shortened;
1582 uint16_t length, padded_length, encoded_length;
1583 uint8_t *data;
1584
1585 GNUNET_assert ((message) && (hpke_key));
1586
1587 if (GNUNET_YES == is_service_message (message))
1588 return GNUNET_NO;
1589
1590 fold_short_message (message, &shortened);
1591
1592 length = get_short_message_size (&shortened, GNUNET_YES);
1593 padded_length = calc_padded_length (length + encryption_overhead);
1594
1595 GNUNET_assert (padded_length >= length + encryption_overhead);
1596
1598 message->body.privacy.data = GNUNET_malloc (padded_length);
1599 message->body.privacy.length = padded_length;
1600
1601 encoded_length = (padded_length - encryption_overhead);
1602
1603 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1604
1605 result = GNUNET_NO;
1606 data = GNUNET_malloc (encoded_length);
1607
1608 encode_short_message (&shortened, encoded_length, (char *) data);
1609
1611 (const uint8_t*)
1612 "messenger",
1613 strlen ("messenger"),
1614 NULL, 0,
1615 (const uint8_t*) data,
1616 encoded_length,
1617 (uint8_t*) message->body.
1618 privacy.data,
1619 NULL))
1620 {
1621 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1622
1623 unfold_short_message (&shortened, message);
1624 goto cleanup;
1625 }
1626
1627 destroy_message_body (shortened.kind, &(shortened.body));
1629
1630cleanup:
1631 GNUNET_free (data);
1632 return result;
1633}
1634
1635
1638 const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
1639{
1641 uint16_t padded_length, encoded_length;
1642 uint8_t *data;
1643
1644 GNUNET_assert ((message) && (hpke_key) &&
1646
1647 padded_length = message->body.privacy.length;
1648
1649 if (padded_length < encryption_overhead)
1650 {
1652 "Message length too short to decrypt!\n");
1653
1654 return GNUNET_NO;
1655 }
1656
1657 encoded_length = (padded_length - encryption_overhead);
1658
1659 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1660
1661 result = GNUNET_NO;
1662 data = GNUNET_malloc (encoded_length);
1663
1664 if (GNUNET_OK !=
1666 (uint8_t*) "messenger",
1667 strlen ("messenger"),
1668 NULL, 0,
1669 (uint8_t*) message->body.privacy.data,
1670 padded_length,
1671 (uint8_t*) data,
1672 NULL))
1673 {
1674 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1675
1676 goto cleanup;
1677 }
1678
1679 {
1680 struct GNUNET_MESSENGER_ShortMessage shortened;
1681 if (GNUNET_YES != decode_short_message (&shortened,
1682 encoded_length,
1683 (char*) data))
1684 {
1686 "Decoding decrypted message failed!\n");
1687
1688 goto cleanup;
1689 }
1690
1691 unfold_short_message (&shortened, message);
1693 }
1694
1695cleanup:
1696 GNUNET_free (data);
1697 return result;
1698}
1699
1700
1704{
1705 struct GNUNET_MESSENGER_Message *transcript;
1706
1707 GNUNET_assert ((message) && (key));
1708
1709 if (GNUNET_YES == is_service_message (message))
1710 return NULL;
1711
1713
1714 if (! transcript)
1715 {
1716 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1717 return NULL;
1718 }
1719
1720 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1721 sizeof(transcript->body.transcript.key));
1722
1723 {
1724 struct GNUNET_MESSENGER_ShortMessage shortened;
1725 uint16_t data_length;
1726
1727 fold_short_message (message, &shortened);
1728
1729 data_length = get_short_message_size (&shortened, GNUNET_YES);
1730
1731 transcript->body.transcript.data = GNUNET_malloc (data_length);
1732 transcript->body.transcript.length = data_length;
1733
1734 encode_short_message (&shortened, data_length,
1735 transcript->body.transcript.data);
1736 }
1737
1738 return transcript;
1739}
1740
1741
1744 const union GNUNET_MESSENGER_EpochIdentifier *identifier
1745 ,
1747{
1749 struct GNUNET_MESSENGER_ShortMessage shortened;
1750 uint16_t length, padded_length;
1751 uint8_t *data;
1752
1753 GNUNET_assert ((message) && (identifier) && (key));
1754
1755 fold_short_message (message, &shortened);
1756
1757 length = get_short_message_size (&shortened, GNUNET_YES);
1758 padded_length = calc_padded_length (length + 0);
1759
1760 GNUNET_assert (padded_length >= length + 0);
1761
1763
1764 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1765 sizeof (message->body.secret.identifier));
1766
1768 &(message->body.secret.iv),
1770
1771 message->body.secret.data = GNUNET_malloc (padded_length);
1772 message->body.secret.length = padded_length;
1773
1774 result = GNUNET_NO;
1775 data = GNUNET_malloc (padded_length);
1776
1777 encode_short_message (&shortened, padded_length, (char *) data);
1778
1779 {
1781
1783 message->body.secret.iv,
1785 NULL);
1786
1787 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1788 &iv, message->body.secret.data))
1789 {
1790 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1791
1792 unfold_short_message (&shortened, message);
1793 goto cleanup;
1794 }
1795 }
1796
1797 {
1798 struct GNUNET_CRYPTO_AuthKey auth_key;
1799
1801 message->body.secret.iv,
1803 NULL);
1804
1805 GNUNET_CRYPTO_hmac (&auth_key, data, padded_length, &(message->body.secret.
1806 hmac));
1807 }
1808
1809 destroy_message_body (shortened.kind, &(shortened.body));
1811
1812cleanup:
1813 GNUNET_free (data);
1814 return result;
1815}
1816
1817
1821{
1823 uint16_t padded_length;
1824 uint8_t *data;
1825
1826 GNUNET_assert ((message) && (key) &&
1828
1829 padded_length = message->body.secret.length;
1830
1831 result = GNUNET_NO;
1832 data = GNUNET_malloc (padded_length);
1833
1834 {
1836
1838 message->body.secret.iv,
1840 NULL);
1841
1842 if (-1 == GNUNET_CRYPTO_symmetric_decrypt (message->body.secret.data,
1843 padded_length,
1844 key, &iv, data))
1845 {
1846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1847
1848 goto cleanup;
1849 }
1850 }
1851
1852 {
1853 struct GNUNET_CRYPTO_AuthKey auth_key;
1854 struct GNUNET_HashCode hmac;
1855
1857 message->body.secret.iv,
1859 NULL);
1860
1861 GNUNET_CRYPTO_hmac (&auth_key, data, padded_length, &hmac);
1862
1863 if (0 != GNUNET_CRYPTO_hash_cmp (&(message->body.secret.hmac), &hmac))
1864 {
1866 "Decrypted message does not match HMAC!\n");
1867
1868 goto cleanup;
1869 }
1870 }
1871
1872 {
1873 struct GNUNET_MESSENGER_ShortMessage shortened;
1874 if (GNUNET_YES != decode_short_message (&shortened,
1875 padded_length,
1876 (char*) data))
1877 {
1879 "Decoding decrypted message failed!\n");
1880
1881 goto cleanup;
1882 }
1883
1884 unfold_short_message (&shortened, message);
1886 }
1887
1888cleanup:
1889 GNUNET_free (data);
1890 return result;
1891}
1892
1893
1896{
1897 uint16_t data_length;
1898 struct GNUNET_MESSENGER_ShortMessage shortened;
1899
1900 GNUNET_assert ((message) &&
1902
1903 data_length = message->body.transcript.length;
1904
1905 if (GNUNET_YES != decode_short_message (&shortened,
1906 data_length,
1907 message->body.transcript.data))
1908 {
1910 "Decoding decrypted message failed!\n");
1911
1912 return GNUNET_NO;
1913 }
1914
1915 unfold_short_message (&shortened, message);
1916 return GNUNET_YES;
1917}
1918
1919
1922 const struct GNUNET_CRYPTO_HpkePrivateKey *key,
1923 struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key
1924 )
1925{
1926 GNUNET_assert ((message) && (key) && (shared_key) &&
1928
1929 if (GNUNET_OK !=
1931 (uint8_t*) "messenger",
1932 strlen ("messenger"),
1933 NULL, 0,
1934 (uint8_t*) message->body.access.key,
1936 (uint8_t*) shared_key,
1937 NULL))
1938 {
1939 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1940 return GNUNET_NO;
1941 }
1942
1943 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1944 {
1945 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1946 return GNUNET_NO;
1947 }
1948
1949 return GNUNET_YES;
1950}
1951
1952
1955 const struct
1958 shared_key)
1959{
1961
1962 GNUNET_assert ((message) && (key) && (shared_key) &&
1964
1966 &(message->body.authorization.event),
1967 sizeof (message->body.authorization.event),
1968 &(message->body.authorization.identifier),
1969 sizeof (message->body.authorization.
1970 identifier),
1971 NULL);
1972
1975 key,
1976 &iv,
1977 shared_key))
1978 {
1979 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1980 return GNUNET_NO;
1981 }
1982
1983 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1984 {
1985 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1986 return GNUNET_NO;
1987 }
1988
1989 return GNUNET_YES;
1990}
1991
1992
1995{
1998
1999 GNUNET_assert (message);
2000
2001 timestamp = GNUNET_TIME_absolute_ntoh (message->header.timestamp);
2002
2003 switch (message->header.kind)
2004 {
2006 timeout = GNUNET_TIME_relative_ntoh (message->body.deletion.delay);
2007 break;
2009 timeout = GNUNET_TIME_relative_ntoh (message->body.announcement.timeout);
2010 break;
2012 timeout = GNUNET_TIME_relative_ntoh (message->body.appeal.timeout);
2013 break;
2015 timeout = GNUNET_TIME_relative_ntoh (message->body.group.timeout);
2016 break;
2017 default:
2019 break;
2020 }
2021
2023
2027
2028 return timeout;
2029}
2030
2031
2032struct GNUNET_MQ_Envelope*
2034 struct GNUNET_HashCode *hash,
2037 const void *cls)
2038{
2039 struct GNUNET_MessageHeader *header;
2040 uint16_t length, padded_length;
2041 struct GNUNET_MQ_Envelope *env;
2042 char *buffer;
2043
2044 GNUNET_assert (message);
2045
2047 "Packing message kind=%u and sender: %s\n",
2048 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2049
2050 length = get_message_size (message, GNUNET_YES);
2051 padded_length = calc_padded_length (length);
2052
2054 {
2055 env = GNUNET_MQ_msg_extra (header, padded_length,
2057 buffer = (char*) &(header[1]);
2058 }
2059 else
2060 {
2061 env = NULL;
2062 buffer = GNUNET_malloc (padded_length);
2063 }
2064
2065 encode_message (message, padded_length, buffer, GNUNET_YES);
2066
2067 if (hash)
2068 {
2069 hash_message (message, length, buffer, hash);
2070
2071 if (sign)
2072 sign (cls, message, length, buffer, hash);
2073 }
2074
2076 GNUNET_free (buffer);
2077
2078 return env;
2079}
2080
2081
2084{
2085 GNUNET_assert (message);
2086
2087 switch (message->header.kind)
2088 {
2094 return GNUNET_YES;
2095 default:
2096 return GNUNET_NO;
2097 }
2098}
2099
2100
2103{
2104 GNUNET_assert (message);
2105
2106 if (GNUNET_YES == is_peer_message (message))
2107 return GNUNET_YES;
2108
2109 switch (message->header.kind)
2110 {
2112 return GNUNET_YES; // Reserved for connection handling only!
2114 return GNUNET_YES; // Reserved for member handling only!
2116 return GNUNET_YES; // Reserved for member handling only!
2118 return GNUNET_YES; // Reserved for member name handling only!
2120 return GNUNET_YES; // Reserved for member key handling only!
2122 return GNUNET_YES; // Reserved for connection handling only!
2124 return GNUNET_YES; // Reserved for member id handling only!
2126 return GNUNET_YES; // Reserved for connection handling only!
2128 return GNUNET_YES; // Reserved for peers only!
2130 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2132 return GNUNET_NO;
2134 return GNUNET_NO;
2136 return GNUNET_NO;
2138 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2140 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2142 return GNUNET_YES; // Reserved for connection handling only!
2144 return GNUNET_NO;
2146 return GNUNET_NO;
2148 return GNUNET_NO;
2150 return GNUNET_YES; // Reserved for subscription handling only!
2152 return GNUNET_NO;
2154 return GNUNET_YES; // Reserved for epoch and group key exchange!
2156 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2158 return GNUNET_YES; // Reserved for epoch key exchange!
2160 return GNUNET_YES; // Reserved for epoch and group key exchange!
2162 return GNUNET_YES; // Reserved for epoch and group key revoking!
2164 return GNUNET_YES; // Reserved for group key exchange!
2166 return GNUNET_YES; // Reserved for epoch and group key exchange!
2167 default:
2168 return GNUNET_SYSERR;
2169 }
2170}
2171
2172
2175{
2176 GNUNET_assert (message);
2177
2178 switch (message->header.kind)
2179 {
2181 return GNUNET_YES;
2183 return GNUNET_YES;
2185 return GNUNET_YES;
2186 default:
2187 return GNUNET_NO;
2188 }
2189}
2190
2191
2194{
2195 GNUNET_assert (message);
2196
2197 if (GNUNET_YES == is_peer_message (message))
2198 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2199
2200 switch (message->header.kind)
2201 {
2203 return GNUNET_SYSERR; // Reserved for connection handling only!
2205 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2207 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2209 return GNUNET_YES;
2211 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2213 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2215 return GNUNET_NO; // Reserved for member id handling only!
2217 return GNUNET_SYSERR; // Reserved for connection handling only!
2219 return GNUNET_SYSERR; // Reserved for peers only!
2221 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2223 return GNUNET_YES;
2225 return GNUNET_YES;
2227 return GNUNET_YES;
2229 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2231 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2233 return GNUNET_SYSERR; // Reserved for connection handling only!
2235 return GNUNET_YES;
2237 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2239 return GNUNET_YES;
2241 return GNUNET_YES;
2243 return GNUNET_YES;
2245 return GNUNET_NO; // Should only be used for implicit key exchange!
2247 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2249 return GNUNET_NO; // Should only be used for implicit key exchange!
2251 return GNUNET_NO; // Should only be used for implicit key exchange!
2253 return GNUNET_NO; // Should only be used for implicit key exchange!
2255 return GNUNET_NO; // Should only be used for implicit key exchange!
2257 return GNUNET_NO; // Should only be used for implicit key exchange!
2258 default:
2259 return GNUNET_SYSERR;
2260 }
2261}
2262
2263
2264const struct GNUNET_ShortHashCode*
2266{
2267 GNUNET_assert (message);
2268
2269 switch (message->header.kind)
2270 {
2272 return &(message->body.subscription.discourse);
2274 return &(message->body.talk.discourse);
2275 default:
2276 return NULL;
2277 }
2278}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition gnunet-arm.c:118
static uint64_t timestamp(void)
Get current timestamp.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static int result
Global testing status.
static void cleanup()
Cleanup task.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
static enum @49 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
void GNUNET_CRYPTO_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_blinded_key_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign a given block with a specific purpose using the host's peer identity.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
Verify a given signature with a peer's identity.
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
#define GNUNET_CRYPTO_blinded_key_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_BlindablePublicKey.
#define GNUNET_log(kind,...)
#define GNUNET_be32toh(x)
ssize_t GNUNET_CRYPTO_hpke_pk_get_length(const struct GNUNET_CRYPTO_HpkePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_HpkePublicKey.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_HpkePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_HpkePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
RFC9180 HPKE encryption.
ssize_t GNUNET_CRYPTO_blinded_key_signature_get_length(const struct GNUNET_CRYPTO_BlindableKeySignature *sig)
Get the compacted length of a #GNUNET_CRYPTO_Signature.
#define GNUNET_CRYPTO_blinded_key_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_BlindablePrivateKey.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
ssize_t GNUNET_CRYPTO_blindable_pk_get_length(const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePublicKey.
Definition crypto_pkey.c:85
#define GNUNET_htobe32(x)
#define GNUNET_PACKED
gcc-ism to get packed structs.
ssize_t GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(struct GNUNET_CRYPTO_BlindableKeySignature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_BlindableKeySignature from a compact buffer.
#define GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES
#define GNUNET_MESSENGER_ACCESS_KEY_BYTES
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
#define GNUNET_MESSENGER_EPOCH_NONCE_BYTES
#define GNUNET_MESSENGER_SECRET_IV_BYTES
#define GNUNET_MESSENGER_KIND_MAX
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_SECRET
The secret kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition time.c:178
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition time.c:452
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
#define decode_step(src, offset, dst)
#define encode_step_ext(dst, offset, src, size)
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
enum GNUNET_GenericReturnValue extract_access_message_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Extracts the shared epoch or group key from an access message using the private ephemeral key from an...
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
struct GNUNET_TIME_Relative get_message_timeout(const struct GNUNET_MESSENGER_Message *message)
Return the relative timeout of the content from a given message that controls when a delayed handling...
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Verifies the hmac of a given message body with a specific shared key.
static uint16_t get_message_body_size(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
static void fold_short_message(const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
#define decode_step_key(src, offset, dst, length)
#define decode_step_hpke_key(src, offset, dst, length)
static uint16_t calc_padded_length(uint16_t length)
enum GNUNET_GenericReturnValue filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message should be sent by a client.
#define decode_step_malloc(src, offset, dst, size, zero)
#define encode_step(dst, offset, src)
enum GNUNET_GenericReturnValue verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
enum GNUNET_GenericReturnValue extract_authorization_message_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Extracts the shared epoch or group key from an authorization message using a previously exchanged sha...
enum GNUNET_GenericReturnValue decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
const uint16_t encryption_overhead
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
static void encode_message_body(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, char *buffer, uint16_t offset)
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
static void encode_short_message(const struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, char *buffer)
static enum GNUNET_GenericReturnValue decode_short_message(struct GNUNET_MESSENGER_ShortMessage *message, uint16_t length, const char *buffer)
const struct GNUNET_ShortHashCode * get_message_discourse(const struct GNUNET_MESSENGER_Message *message)
Returns the discourse hash of a message depending on its kind.
enum GNUNET_GenericReturnValue is_epoch_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a certain kind of message from storage contains some specific details that might be r...
enum GNUNET_GenericReturnValue verify_message_by_peer(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
Verifies the signature of a given message and its hash with a specific peer's identity.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
#define decode_step_ext(src, offset, dst, size)
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
#define encode_step_hpke_key(dst, offset, src, length)
#define encode_step_signature(dst, offset, src, length)
static uint16_t calc_usual_padding()
static uint16_t decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
static void calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_HashCode *hmac)
enum GNUNET_GenericReturnValue decrypt_secret_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Decrypts a secret message using a given shared key and replaces its body and kind with the inner encr...
uint32_t kind_t
#define min(x, y)
void sign_message_by_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Signs the message body via it's own hmac with a specific shared key.
#define max(x, y)
void copy_message_header(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_MessageHeader *header)
Copy message header details from another message to a given message.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
void sign_message_by_peer(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signs the hash of a message with the peer identity of a given config and writes the signature into th...
enum GNUNET_GenericReturnValue read_transcript_message(struct GNUNET_MESSENGER_Message *message)
Read the original message from a transcript message and replaces its body and kind with the inner enc...
#define encode_step_key(dst, offset, src, length)
enum GNUNET_GenericReturnValue is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
enum GNUNET_GenericReturnValue encrypt_secret_message(struct GNUNET_MESSENGER_Message *message, const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Encrypts a message using a given shared key from an announcement of an epoch and replaces its body an...
#define member_size(type, member)
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
GNUNET_MESSENGER_PackMode
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
#define GNUNET_MESSENGER_PADDING_LEVEL0
#define GNUNET_MESSENGER_PADDING_MIN
void(* GNUNET_MESSENGER_SignFunction)(const void *cls, struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash)
#define GNUNET_MESSENGER_PADDING_LEVEL2
#define GNUNET_MESSENGER_PADDING_LEVEL1
type for (message) authentication keys
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
A public key used for decryption.
A public key used for encryption.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
A 512-bit hashcode.
struct GNUNET_HashCode hmac
The hmac of the access.
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the announcement.
struct GNUNET_HashCode hmac
The hmac of the announcement.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to appeal access.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to receive access.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the appeal.
struct GNUNET_HashCode event
The hash of the linked announcement message event.
struct GNUNET_HashCode event
The hash of the linked group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode hmac
The hmac of the authorization.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)]
The encrypted group or epoch key.
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageSecret secret
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageLeave leave
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageTalk talk
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageSubscribtion subscription
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_MESSENGER_MessageAppeal appeal
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageTicket ticket
struct GNUNET_MESSENGER_MessageInfo info
uint32_t amount
The amount of connections of a peer.
uint32_t flags
The flags about the connections of a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
char * uri
The uri of the encrypted file.
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
char name[NAME_MAX]
The name of the original file.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the group formation.
struct GNUNET_HashCode initiator
The hash of the initiator group announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode partner
The hash of the partner group announcement.
The header of a GNUNET_MESSENGER_Message.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_CRYPTO_BlindableKeySignature signature
The signature of the senders private key.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
uint32_t messenger_version
The version of GNUnet Messenger API.
union GNUNET_MESSENGER_RoomKey key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_CRYPTO_BlindablePublicKey key
The senders blindable public key to verify its signatures.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The senders HPKE public key to encrypt private messages with.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new blindable public key which replaces the current senders public key.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The new HPKE public key which replaces the current senders HPKE public key.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_HashCode epochs[2]
The previous epochs the message was sent from.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
char * name
The new name which replaces the current senders name.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
uint16_t length
The length of the encrypted message.
char * data
The data of the encrypted message.
struct GNUNET_HashCode hash
The hash of the requested message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the revolution.
struct GNUNET_HashCode hmac
The hmac of the revolution.
uint8_t iv[sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector)]
The IV of the secret message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
char * data
The data of the encrypted message.
struct GNUNET_HashCode hmac
The hmac of the encrypted message.
uint16_t length
The length of the encrypted message.
struct GNUNET_CRYPTO_SignaturePurpose purpose
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscription.
struct GNUNET_HashCode hash
The hash of the message to tag.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
char * identifier
The identifier of a ticket.
uint16_t length
The length of the transcribed message.
struct GNUNET_HashCode hash
The hash of the original message.
struct GNUNET_CRYPTO_BlindablePublicKey key
The key from the recipient of the original message.
char * data
The data of the transcribed message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind
Header for all communications.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
An epoch identifier unifies an epoch identifier code and its 256bit hash representation.