GNUnet debian-0.24.3-29-g453fda2cf
 
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 {
489 break;
491 length += (body->name.name ? strlen (body->name.name) : 0);
492 break;
495 break;
497 length += (body->text.text ? strlen (body->text.text) : 0);
498 break;
500 length += (body->file.uri ? strlen (body->file.uri) : 0);
501 break;
503 length += body->privacy.length;
504 break;
506 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
507 break;
510 length += body->transcript.length;
511 break;
513 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
514 break;
516 length += body->talk.length;
517 break;
519 length += body->secret.length;
520 break;
521 default:
522 break;
523 }
524
525 return length;
526}
527
528
529uint16_t
531 enum GNUNET_GenericReturnValue include_header)
532{
533 uint16_t length;
534
535 GNUNET_assert (message);
536
537 length = 0;
538
539 if (GNUNET_YES == include_header)
541 &(message->header.signature));
542
543 length += get_message_kind_size (message->header.kind, include_header);
544 length += get_message_body_size (message->header.kind, &(message->body));
545
546 return length;
547}
548
549
550static uint16_t
552 enum GNUNET_GenericReturnValue include_body)
553{
554 uint16_t minimum_size;
555
556 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
557
558 if (message)
559 return minimum_size + get_message_body_kind_size (message->kind)
560 + (include_body == GNUNET_YES?
561 get_message_body_size (message->kind, &(message->body)) : 0);
562 else
563 return minimum_size;
564}
565
566
567static uint16_t
569{
570 uint16_t padding;
571 uint16_t kind_size;
572
573 padding = 0;
574
575 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
576 {
578 GNUNET_YES);
579
580 if (kind_size > padding)
581 padding = kind_size;
582 }
583
584 return padding + GNUNET_MESSENGER_PADDING_MIN;
585}
586
587
588#define max(x, y) (x > y? x : y)
589
590static uint16_t
591calc_padded_length (uint16_t length)
592{
593 static uint16_t usual_padding = 0;
594 uint16_t padded_length;
595
596 if (! usual_padding)
597 usual_padding = calc_usual_padding ();
598
599 padded_length = max (
601 usual_padding);
602
603 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
605
606 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
608
609 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
611
613
614}
615
616
617#define min(x, y) (x < y? x : y)
618
619#define encode_step_ext(dst, offset, src, size) do { \
620 GNUNET_memcpy (dst + offset, src, size); \
621 offset += size; \
622} while (0)
623
624#define encode_step(dst, offset, src) do { \
625 encode_step_ext (dst, offset, src, sizeof(*src)); \
626} while (0)
627
628#define encode_step_key(dst, offset, src, length) do { \
629 ssize_t result = GNUNET_CRYPTO_write_public_key_to_buffer ( \
630 src, dst + offset, length - offset); \
631 if (result < 0) \
632 GNUNET_break (0); \
633 else \
634 offset += result; \
635} while (0)
636
637#define encode_step_signature(dst, offset, src, length) do { \
638 ssize_t result = GNUNET_CRYPTO_write_signature_to_buffer ( \
639 src, dst + offset, length - offset); \
640 if (result < 0) \
641 GNUNET_break (0); \
642 else \
643 offset += result; \
644} while (0)
645
646static void
648 const struct GNUNET_MESSENGER_MessageBody *body,
649 uint16_t length,
650 char *buffer,
651 uint16_t offset)
652{
653 uint32_t value0, value1;
654
655 GNUNET_assert ((body) && (buffer));
656
657 switch (kind)
658 {
660 value0 = GNUNET_htobe32 (body->info.messenger_version);
661
662 encode_step (buffer, offset, &value0);
663 break;
665 encode_step (buffer, offset, &(body->join.epoch));
666 encode_step_key (buffer, offset, &(body->join.key), length);
667 break;
669 encode_step (buffer, offset, &(body->leave.epoch));
670 break;
672 if (body->name.name)
674 buffer,
675 offset,
676 body->name.name,
677 min (length - offset, strlen (body->name.name)));
678 break;
680 encode_step_key (buffer, offset, &(body->key.key), length);
681 break;
683 encode_step (buffer, offset, &(body->peer.peer));
684 break;
686 encode_step (buffer, offset, &(body->id.id));
687 break;
689 encode_step (buffer, offset, &(body->miss.peer));
690 break;
692 encode_step (buffer, offset, &(body->merge.epochs[0]));
693 encode_step (buffer, offset, &(body->merge.epochs[1]));
694 encode_step (buffer, offset, &(body->merge.previous));
695 break;
697 encode_step (buffer, offset, &(body->request.hash));
698 break;
700 encode_step (buffer, offset, &(body->invite.door));
701 encode_step (buffer, offset, &(body->invite.key));
702 break;
704 if (body->text.text)
706 buffer,
707 offset,
708 body->text.text,
709 min (length - offset, strlen (body->text.text)));
710 break;
712 encode_step (buffer, offset, &(body->file.key));
713 encode_step (buffer, offset, &(body->file.hash));
714 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
715 if (body->file.uri)
716 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
717 strlen (
718 body->file.uri)));
719 break;
721 if (body->privacy.data)
722 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
723 body->privacy.
724 length));
725 break;
727 encode_step (buffer, offset, &(body->deletion.hash));
728 encode_step (buffer, offset, &(body->deletion.delay));
729 break;
731 value0 = GNUNET_htobe32 (body->connection.amount);
732 value1 = GNUNET_htobe32 (body->connection.flags);
733
734 encode_step (buffer, offset, &value0);
735 encode_step (buffer, offset, &value1);
736 break;
738 encode_step_ext (buffer, offset, body->ticket.identifier,
739 min (length - offset, strlen (body->ticket.identifier)));
740 break;
742 encode_step (buffer, offset, &(body->transcript.hash));
743 encode_step_key (buffer, offset, &(body->transcript.key), length);
744
745 if (body->transcript.data)
746 encode_step_ext (buffer, offset, body->transcript.data, min (length
747 - offset,
748 body->
749 transcript.
750 length));
751 break;
753 encode_step (buffer, offset, &(body->tag.hash));
754
755 if (body->tag.tag)
756 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
757 strlen (
758 body->tag.tag)));
759 break;
761 value0 = GNUNET_htobe32 (body->subscribtion.flags);
762
763 encode_step (buffer, offset, &(body->subscribtion.discourse));
764 encode_step (buffer, offset, &(body->subscribtion.time));
765 encode_step (buffer, offset, &value0);
766 break;
768 encode_step (buffer, offset, &(body->talk.discourse));
769
770 if (body->talk.data)
771 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
772 body->talk.
773 length));
774 break;
776 encode_step (buffer, offset, &(body->announcement.identifier));
777 encode_step (buffer, offset, &(body->announcement.key));
778 encode_step (buffer, offset, &(body->announcement.nonce));
779 encode_step (buffer, offset, &(body->announcement.timeout));
780 encode_step (buffer, offset, &(body->announcement.hmac));
781 break;
783 encode_step (buffer, offset, &(body->secret.identifier));
784 encode_step (buffer, offset, &(body->secret.iv));
785 encode_step (buffer, offset, &(body->secret.hmac));
786
787 if (body->secret.data)
788 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
789 body->secret.
790 length));
791 break;
793 encode_step (buffer, offset, &(body->appeal.event));
794 encode_step (buffer, offset, &(body->appeal.key));
795 encode_step (buffer, offset, &(body->appeal.timeout));
796 break;
798 encode_step (buffer, offset, &(body->access.event));
799 encode_step (buffer, offset, &(body->access.key));
800 encode_step (buffer, offset, &(body->access.hmac));
801 break;
803 encode_step (buffer, offset, &(body->revolution.identifier));
804 encode_step (buffer, offset, &(body->revolution.nonce));
805 encode_step (buffer, offset, &(body->revolution.hmac));
806 break;
808 encode_step (buffer, offset, &(body->group.identifier));
809 encode_step (buffer, offset, &(body->group.initiator));
810 encode_step (buffer, offset, &(body->group.partner));
811 encode_step (buffer, offset, &(body->group.timeout));
812 break;
814 encode_step (buffer, offset, &(body->authorization.identifier));
815 encode_step (buffer, offset, &(body->authorization.event));
816 encode_step (buffer, offset, &(body->authorization.key));
817 encode_step (buffer, offset, &(body->authorization.hmac));
818 break;
819 default:
820 break;
821 }
822
823 if (offset >= length)
824 return;
825
826 {
827 uint16_t padding;
828 uint16_t used_padding;
829
830 padding = length - offset;
831 used_padding = sizeof(padding) + sizeof(char);
832
833 GNUNET_assert (padding >= used_padding);
834
835 buffer[offset++] = '\0';
836
837 if (padding > used_padding)
839 padding - used_padding);
840
841 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
842 sizeof(padding));
843 }
844}
845
846
847void
849 uint16_t length,
850 char *buffer,
851 enum GNUNET_GenericReturnValue include_header)
852{
853 uint16_t offset;
854 kind_t kind;
855
856 GNUNET_assert ((message) && (buffer));
857
858 offset = 0;
859
860 if (GNUNET_YES == include_header)
861 encode_step_signature (buffer, offset, &(message->header.signature),
862 length);
863
864 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
865
866 if (GNUNET_YES == include_header)
867 {
868 encode_step (buffer, offset, &(message->header.timestamp));
869 encode_step (buffer, offset, &(message->header.sender_id));
870 encode_step (buffer, offset, &(message->header.previous));
871 }
872
873 encode_step (buffer, offset, &kind);
874
875 encode_message_body (message->header.kind, &(message->body),
876 length, buffer, offset);
877}
878
879
880static void
882 uint16_t length,
883 char *buffer)
884{
885 struct GNUNET_HashCode hash;
886 uint16_t offset;
887 kind_t kind;
888
889 GNUNET_assert ((message) && (buffer));
890
891 offset = sizeof(hash);
892 kind = GNUNET_htobe32 ((kind_t) message->kind);
893
894 encode_step (buffer, offset, &kind);
895
896 encode_message_body (message->kind, &(message->body), length, buffer, offset);
897
899 buffer + sizeof(hash),
900 length - sizeof(hash),
901 &hash);
902
903 GNUNET_memcpy (buffer, &hash, sizeof(hash));
904}
905
906
907#define decode_step_ext(src, offset, dst, size) do { \
908 GNUNET_memcpy (dst, src + offset, size); \
909 offset += size; \
910} while (0)
911
912#define decode_step(src, offset, dst) do { \
913 decode_step_ext (src, offset, dst, sizeof(*dst)); \
914} while (0)
915
916#define decode_step_malloc(src, offset, dst, size, zero) do { \
917 dst = GNUNET_malloc (size + zero); \
918 if (zero) dst[size] = 0; \
919 decode_step_ext (src, offset, dst, size); \
920} while (0)
921
922#define decode_step_key(src, offset, dst, length) do { \
923 enum GNUNET_GenericReturnValue result; \
924 size_t read; \
925 result = GNUNET_CRYPTO_read_public_key_from_buffer ( \
926 src + offset, length - offset, dst, &read); \
927 if (GNUNET_SYSERR == result) \
928 GNUNET_break (0); \
929 else \
930 offset += read; \
931} while (0)
932
933static uint16_t
935 struct GNUNET_MESSENGER_MessageBody *body,
936 uint16_t length,
937 const char *buffer,
938 uint16_t offset)
939{
940 uint16_t padding;
941 uint32_t value0, value1;
942
943 GNUNET_assert ((kind) && (body) && (buffer));
944
945 padding = 0;
946
947 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
948
949 if (padding > length - offset)
950 padding = 0;
951
952 {
953 uint16_t end_zero;
954 end_zero = length - padding;
955
956 if ((padding) && (buffer[end_zero] != '\0'))
957 padding = 0;
958 }
959
960 length -= padding;
961
962 switch (*kind)
963 {
965 decode_step (buffer, offset, &value0);
966
967 body->info.messenger_version = GNUNET_be32toh (value0);
968 break;
970 decode_step (buffer, offset, &(body->join.epoch));
971 decode_step_key (buffer, offset, &(body->join.key), length);
972 break;
974 decode_step (buffer, offset, &(body->leave.epoch));
975 break;
977 if (length > offset)
978 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
979 else
980 body->name.name = NULL;
981 break;
983 decode_step_key (buffer, offset, &(body->key.key), length);
984 break;
986 decode_step (buffer, offset, &(body->peer.peer));
987 break;
989 decode_step (buffer, offset, &(body->id.id));
990 break;
992 decode_step (buffer, offset, &(body->miss.peer));
993 break;
995 decode_step (buffer, offset, &(body->merge.epochs[0]));
996 decode_step (buffer, offset, &(body->merge.epochs[1]));
997 decode_step (buffer, offset, &(body->merge.previous));
998 break;
1000 decode_step (buffer, offset, &(body->request.hash));
1001 break;
1003 decode_step (buffer, offset, &(body->invite.door));
1004 decode_step (buffer, offset, &(body->invite.key));
1005 break;
1007 if (length > offset)
1008 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1009 else
1010 body->text.text = NULL;
1011 break;
1013 decode_step (buffer, offset, &(body->file.key));
1014 decode_step (buffer, offset, &(body->file.hash));
1015 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1016 if (length > offset)
1017 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1018 else
1019 body->file.uri = NULL;
1020 break;
1022 if (length > offset)
1023 {
1024 body->privacy.length = (length - offset);
1025 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1026 0);
1027 }
1028 else
1029 {
1030 body->privacy.length = 0;
1031 body->privacy.data = NULL;
1032 }
1033
1034 break;
1036 decode_step (buffer, offset, &(body->deletion.hash));
1037 decode_step (buffer, offset, &(body->deletion.delay));
1038 break;
1040 decode_step (buffer, offset, &value0);
1041 decode_step (buffer, offset, &value1);
1042
1043 body->connection.amount = GNUNET_be32toh (value0);
1044 body->connection.flags = GNUNET_be32toh (value1);
1045 break;
1047 if (length > offset)
1048 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1049 - offset, 1);
1050 else
1051 body->ticket.identifier = NULL;
1052 break;
1054 decode_step (buffer, offset, &(body->transcript.hash));
1055 decode_step_key (buffer, offset, &(body->transcript.key), length);
1056
1057 if (length > offset)
1058 {
1059 body->transcript.length = (length - offset);
1060 decode_step_malloc (buffer, offset, body->transcript.data,
1061 length - offset, 0);
1062 }
1063 else
1064 {
1065 body->transcript.length = 0;
1066 body->transcript.data = NULL;
1067 }
1068
1069 break;
1071 decode_step (buffer, offset, &(body->tag.hash));
1072 if (length > offset)
1073 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1074 else
1075 body->tag.tag = NULL;
1076 break;
1078 decode_step (buffer, offset, &(body->subscribtion.discourse));
1079 decode_step (buffer, offset, &(body->subscribtion.time));
1080 decode_step (buffer, offset, &value0);
1081
1082 body->subscribtion.flags = GNUNET_be32toh (value0);
1083 break;
1085 decode_step (buffer, offset, &(body->talk.discourse));
1086
1087 if (length > offset)
1088 {
1089 body->talk.length = (length - offset);
1090 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1091 0);
1092 }
1093 else
1094 {
1095 body->talk.length = 0;
1096 body->talk.data = NULL;
1097 }
1098
1099 break;
1101 decode_step (buffer, offset, &(body->announcement.identifier));
1102 decode_step (buffer, offset, &(body->announcement.key));
1103 decode_step (buffer, offset, &(body->announcement.nonce));
1104 decode_step (buffer, offset, &(body->announcement.timeout));
1105 decode_step (buffer, offset, &(body->announcement.hmac));
1106 break;
1108 decode_step (buffer, offset, &(body->secret.identifier));
1109 decode_step (buffer, offset, &(body->secret.iv));
1110 decode_step (buffer, offset, &(body->secret.hmac));
1111
1112 if (length > offset)
1113 {
1114 body->secret.length = (length - offset);
1115 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1116 0);
1117 }
1118 else
1119 {
1120 body->secret.length = 0;
1121 body->secret.data = NULL;
1122 }
1123
1124 break;
1126 decode_step (buffer, offset, &(body->appeal.event));
1127 decode_step (buffer, offset, &(body->appeal.key));
1128 decode_step (buffer, offset, &(body->appeal.timeout));
1129 break;
1131 decode_step (buffer, offset, &(body->access.event));
1132 decode_step (buffer, offset, &(body->access.key));
1133 decode_step (buffer, offset, &(body->access.hmac));
1134 break;
1136 decode_step (buffer, offset, &(body->revolution.identifier));
1137 decode_step (buffer, offset, &(body->revolution.nonce));
1138 decode_step (buffer, offset, &(body->revolution.hmac));
1139 break;
1141 decode_step (buffer, offset, &(body->group.identifier));
1142 decode_step (buffer, offset, &(body->group.initiator));
1143 decode_step (buffer, offset, &(body->group.partner));
1144 decode_step (buffer, offset, &(body->group.timeout));
1145 break;
1147 decode_step (buffer, offset, &(body->authorization.identifier));
1148 decode_step (buffer, offset, &(body->authorization.event));
1149 decode_step (buffer, offset, &(body->authorization.key));
1150 decode_step (buffer, offset, &(body->authorization.hmac));
1151 break;
1152 default:
1154 break;
1155 }
1156
1157 return padding;
1158}
1159
1160
1163 uint16_t length,
1164 const char *buffer,
1165 enum GNUNET_GenericReturnValue include_header,
1166 uint16_t *padding)
1167{
1168 uint16_t offset;
1169 uint16_t count;
1170 kind_t kind;
1171
1173 (message) &&
1174 (buffer) &&
1176 include_header)));
1177
1178 offset = 0;
1179
1180 if (GNUNET_YES == include_header)
1181 {
1182 ssize_t result;
1183
1185 &(message->header.signature), buffer, length - offset);
1186
1187 if (result < 0)
1188 return GNUNET_NO;
1189 else
1190 offset += result;
1191 }
1192
1193 count = length - offset;
1195 include_header))
1196 return GNUNET_NO;
1197
1198 if (GNUNET_YES == include_header)
1199 {
1200 decode_step (buffer, offset, &(message->header.timestamp));
1201 decode_step (buffer, offset, &(message->header.sender_id));
1202 decode_step (buffer, offset, &(message->header.previous));
1203 }
1204
1205 decode_step (buffer, offset, &kind);
1206 kind = GNUNET_be32toh (kind);
1207
1208 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1209
1210 if (count < get_message_kind_size (message->header.kind, include_header))
1211 return GNUNET_NO;
1212
1213 {
1214 uint16_t result;
1215 result = decode_message_body (&(message->header.kind),
1216 &(message->body), length, buffer, offset);
1217
1218 if (padding)
1219 *padding = result;
1220 }
1221
1222 return GNUNET_YES;
1223}
1224
1225
1226static enum GNUNET_GenericReturnValue
1228 uint16_t length,
1229 const char *buffer)
1230{
1231 struct GNUNET_HashCode expected, hash;
1232 uint16_t offset;
1233 kind_t kind;
1234
1235 GNUNET_assert ((message) && (buffer));
1236
1237 offset = sizeof(hash);
1238
1239 if (length < get_short_message_size (NULL, GNUNET_NO))
1240 return GNUNET_NO;
1241
1242 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1243
1245 buffer + sizeof(hash),
1246 length - sizeof(hash),
1247 &expected);
1248
1249 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1250 return GNUNET_NO;
1251
1252 decode_step (buffer, offset, &kind);
1253 kind = GNUNET_be32toh (kind);
1254
1255 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1256
1257 if (length < get_short_message_size (message, GNUNET_NO))
1258 return GNUNET_NO;
1259
1260 decode_message_body (&(message->kind), &(message->body), length, buffer,
1261 offset);
1262
1263 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1264 return GNUNET_NO;
1265
1266 return GNUNET_YES;
1267}
1268
1269
1270void
1272 uint16_t length,
1273 const char *buffer,
1274 struct GNUNET_HashCode *hash)
1275{
1276 ssize_t offset;
1277
1278 GNUNET_assert ((message) && (buffer) && (hash));
1279
1281
1282 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1283}
1284
1285
1286void
1288 uint16_t length,
1289 char *buffer,
1290 const struct GNUNET_HashCode *hash,
1291 const struct GNUNET_CRYPTO_PrivateKey *key)
1292{
1293 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1294
1295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1296 GNUNET_h2s (hash));
1297
1298 {
1299 struct GNUNET_MESSENGER_MessageSignature signature;
1300
1302 signature.purpose.size = htonl (sizeof(signature));
1303
1304 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1305 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
1306 }
1307
1308 message->header.signature.type = key->type;
1309
1310 {
1311 uint16_t offset = 0;
1313 buffer,
1314 offset,
1315 &(message->header.signature),
1316 length);
1317 }
1318}
1319
1320
1321void
1323 uint16_t length,
1324 char *buffer,
1325 const struct GNUNET_HashCode *hash,
1326 const struct GNUNET_CONFIGURATION_Handle *cfg)
1327{
1328 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1329
1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1331 GNUNET_h2s (hash));
1332
1333 {
1334 struct GNUNET_MESSENGER_MessageSignature signature;
1336 signature.purpose.size = htonl (sizeof (signature));
1337
1338 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1340 &(message->header.signature.
1341 eddsa_signature));
1342 }
1343
1345
1346 {
1347 uint16_t offset = 0;
1349 buffer,
1350 offset,
1351 &(message->header.signature),
1352 length);
1353 }
1354}
1355
1356
1357static void
1360 struct GNUNET_HashCode *hmac)
1361{
1362 struct GNUNET_CRYPTO_AuthKey auth_key;
1363
1364 GNUNET_assert ((message) && (key) && (hmac));
1365
1366 switch (message->header.kind)
1367 {
1370 &auth_key, key,
1371 &(message->body.announcement.nonce),
1373 &(message->body.announcement.identifier),
1374 sizeof (message->body.announcement.identifier),
1375 NULL);
1376
1377 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1378 sizeof (message->body.announcement)
1379 - sizeof (*hmac),
1380 hmac);
1381 break;
1384 &auth_key, key, &(message->body.access.event),
1385 sizeof (message->body.access.event), NULL);
1386
1387 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1388 sizeof (message->body.access)
1389 - sizeof (*hmac),
1390 hmac);
1391 break;
1394 &auth_key, key,
1395 &(message->body.revolution.nonce),
1397 &(message->body.revolution.identifier),
1398 sizeof (message->body.revolution.identifier),
1399 NULL);
1400
1401 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1402 sizeof (message->body.revolution)
1403 - sizeof (*hmac),
1404 hmac);
1405 break;
1408 &auth_key, key,
1409 &(message->body.authorization.event),
1410 sizeof (message->body.authorization.event),
1411 &(message->body.authorization.identifier),
1412 sizeof (message->body.authorization.identifier),
1413 NULL);
1414
1415 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1416 sizeof (message->body.authorization)
1417 - sizeof (*hmac),
1418 hmac);
1419 break;
1420 default:
1421 break;
1422 }
1423}
1424
1425
1426void
1429{
1430 struct GNUNET_HashCode *hmac;
1431
1432 GNUNET_assert ((message) && (key));
1433
1434 switch (message->header.kind)
1435 {
1437 hmac = &(message->body.announcement.hmac);
1438 break;
1440 hmac = &(message->body.access.hmac);
1441 break;
1443 hmac = &(message->body.revolution.hmac);
1444 break;
1446 hmac = &(message->body.authorization.hmac);
1447 break;
1448 default:
1449 hmac = NULL;
1450 break;
1451 }
1452
1453 if (! hmac)
1454 return;
1455
1456 calc_message_hmac (message, key, hmac);
1457}
1458
1459
1462 const struct GNUNET_HashCode *hash,
1463 const struct GNUNET_CRYPTO_PublicKey *key)
1464{
1465 struct GNUNET_MESSENGER_MessageSignature signature;
1466
1467 GNUNET_assert ((message) && (hash) && (key));
1468
1469 if (key->type != message->header.signature.type)
1470 return GNUNET_SYSERR;
1471
1473 signature.purpose.size = htonl (sizeof(signature));
1474
1475 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1476
1479 &(message->header.signature), key);
1480}
1481
1482
1485 const struct GNUNET_HashCode *hash,
1486 const struct GNUNET_PeerIdentity *identity)
1487{
1488 struct GNUNET_MESSENGER_MessageSignature signature;
1489
1490 GNUNET_assert ((message) && (hash) && (identity));
1491
1492 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1493 return GNUNET_SYSERR;
1494
1496 signature.purpose.size = htonl (sizeof(signature));
1497
1498 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1499
1502 &(message->header.signature.
1503 eddsa_signature), identity);
1504}
1505
1506
1510{
1511 const struct GNUNET_HashCode *msg_hmac;
1512 struct GNUNET_HashCode hmac;
1513
1514 GNUNET_assert ((message) && (key));
1515
1516 switch (message->header.kind)
1517 {
1519 msg_hmac = &(message->body.announcement.hmac);
1520 break;
1522 msg_hmac = &(message->body.access.hmac);
1523 break;
1525 msg_hmac = &(message->body.revolution.hmac);
1526 break;
1528 msg_hmac = &(message->body.authorization.hmac);
1529 break;
1530 default:
1531 msg_hmac = NULL;
1532 break;
1533 }
1534
1535 if (! msg_hmac)
1536 return GNUNET_SYSERR;
1537
1538 calc_message_hmac (message, key, &hmac);
1539
1540 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1541 return GNUNET_OK;
1542
1543 return GNUNET_SYSERR;
1544}
1545
1546
1549 const struct GNUNET_CRYPTO_PublicKey *key)
1550{
1551 struct GNUNET_CRYPTO_EcdhePublicKey hpke_key;
1553 struct GNUNET_MESSENGER_ShortMessage shortened;
1554 uint16_t length, padded_length, encoded_length;
1555 uint8_t *data;
1556
1557 GNUNET_assert ((message) && (key));
1558
1559 if (GNUNET_YES == is_service_message (message))
1560 return GNUNET_NO;
1561
1562 fold_short_message (message, &shortened);
1563
1564 length = get_short_message_size (&shortened, GNUNET_YES);
1565 padded_length = calc_padded_length (length + encryption_overhead);
1566
1567 GNUNET_assert (padded_length >= length + encryption_overhead);
1568
1570 message->body.privacy.data = GNUNET_malloc (padded_length);
1571 message->body.privacy.length = padded_length;
1572
1574 encoded_length = (padded_length - encryption_overhead);
1575
1576 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1577
1578 result = GNUNET_NO;
1579 data = GNUNET_malloc (encoded_length);
1580
1581 encode_short_message (&shortened, encoded_length, (char *) data);
1582
1584 (const uint8_t*)
1585 "messenger",
1586 strlen ("messenger"),
1587 NULL, 0,
1588 (const uint8_t*) data,
1589 encoded_length,
1590 (uint8_t*) message->body.
1591 privacy.data,
1592 NULL))
1593 {
1594 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1595
1596 unfold_short_message (&shortened, message);
1597 goto cleanup;
1598 }
1599
1600 destroy_message_body (shortened.kind, &(shortened.body));
1602
1603cleanup:
1604 GNUNET_free (data);
1605 return result;
1606}
1607
1608
1611 const struct GNUNET_CRYPTO_PrivateKey *key)
1612{
1613 struct GNUNET_CRYPTO_EcdhePrivateKey hpke_key;
1615 uint16_t padded_length, encoded_length;
1616 uint8_t *data;
1617
1618 GNUNET_assert ((message) && (key) &&
1620
1621 padded_length = message->body.privacy.length;
1622
1623 if (padded_length < encryption_overhead)
1624 {
1626 "Message length too short to decrypt!\n");
1627
1628 return GNUNET_NO;
1629 }
1630
1632 encoded_length = (padded_length - encryption_overhead);
1633
1634 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1635
1636 result = GNUNET_NO;
1637 data = GNUNET_malloc (encoded_length);
1638
1639 if (GNUNET_OK !=
1641 (uint8_t*) "messenger",
1642 strlen ("messenger"),
1643 NULL, 0,
1644 (uint8_t*) message->body.privacy.data,
1645 padded_length,
1646 (uint8_t*) data,
1647 NULL))
1648 {
1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1650
1651 goto cleanup;
1652 }
1653
1654 {
1655 struct GNUNET_MESSENGER_ShortMessage shortened;
1656 if (GNUNET_YES != decode_short_message (&shortened,
1657 encoded_length,
1658 (char*) data))
1659 {
1661 "Decoding decrypted message failed!\n");
1662
1663 goto cleanup;
1664 }
1665
1666 unfold_short_message (&shortened, message);
1668 }
1669
1670cleanup:
1671 GNUNET_free (data);
1672 return result;
1673}
1674
1675
1678 const struct GNUNET_CRYPTO_PublicKey *key)
1679{
1680 struct GNUNET_MESSENGER_Message *transcript;
1681
1682 GNUNET_assert ((message) && (key));
1683
1684 if (GNUNET_YES == is_service_message (message))
1685 return NULL;
1686
1688
1689 if (! transcript)
1690 {
1691 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1692 return NULL;
1693 }
1694
1695 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1696 sizeof(transcript->body.transcript.key));
1697
1698 {
1699 struct GNUNET_MESSENGER_ShortMessage shortened;
1700 uint16_t data_length;
1701
1702 fold_short_message (message, &shortened);
1703
1704 data_length = get_short_message_size (&shortened, GNUNET_YES);
1705
1706 transcript->body.transcript.data = GNUNET_malloc (data_length);
1707 transcript->body.transcript.length = data_length;
1708
1709 encode_short_message (&shortened, data_length,
1710 transcript->body.transcript.data);
1711 }
1712
1713 return transcript;
1714}
1715
1716
1719 const union GNUNET_MESSENGER_EpochIdentifier *identifier
1720 ,
1722{
1724 struct GNUNET_MESSENGER_ShortMessage shortened;
1725 uint16_t length, padded_length;
1726 uint8_t *data;
1727
1728 GNUNET_assert ((message) && (identifier) && (key));
1729
1730 fold_short_message (message, &shortened);
1731
1732 length = get_short_message_size (&shortened, GNUNET_YES);
1733 padded_length = calc_padded_length (length + 0);
1734
1735 GNUNET_assert (padded_length >= length + 0);
1736
1738
1739 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1740 sizeof (message->body.secret.identifier));
1741
1743 &(message->body.secret.iv),
1745
1746 message->body.secret.data = GNUNET_malloc (padded_length);
1747 message->body.secret.length = padded_length;
1748
1749 result = GNUNET_NO;
1750 data = GNUNET_malloc (padded_length);
1751
1752 encode_short_message (&shortened, padded_length, (char *) data);
1753
1754 {
1756
1758 message->body.secret.iv,
1760 NULL);
1761
1762 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1763 &iv, message->body.secret.data))
1764 {
1765 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1766
1767 unfold_short_message (&shortened, message);
1768 goto cleanup;
1769 }
1770 }
1771
1772 {
1773 struct GNUNET_CRYPTO_AuthKey auth_key;
1774
1776 message->body.secret.iv,
1778 NULL);
1779
1780 GNUNET_CRYPTO_hmac (&auth_key, data, padded_length, &(message->body.secret.
1781 hmac));
1782 }
1783
1784 destroy_message_body (shortened.kind, &(shortened.body));
1786
1787cleanup:
1788 GNUNET_free (data);
1789 return result;
1790}
1791
1792
1796{
1798 uint16_t padded_length;
1799 uint8_t *data;
1800
1801 GNUNET_assert ((message) && (key) &&
1803
1804 padded_length = message->body.secret.length;
1805
1806 result = GNUNET_NO;
1807 data = GNUNET_malloc (padded_length);
1808
1809 {
1811
1813 message->body.secret.iv,
1815 NULL);
1816
1817 if (-1 == GNUNET_CRYPTO_symmetric_decrypt (message->body.secret.data,
1818 padded_length,
1819 key, &iv, data))
1820 {
1821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1822
1823 goto cleanup;
1824 }
1825 }
1826
1827 {
1828 struct GNUNET_CRYPTO_AuthKey auth_key;
1829 struct GNUNET_HashCode hmac;
1830
1832 message->body.secret.iv,
1834 NULL);
1835
1836 GNUNET_CRYPTO_hmac (&auth_key, data, padded_length, &hmac);
1837
1838 if (0 != GNUNET_CRYPTO_hash_cmp (&(message->body.secret.hmac), &hmac))
1839 {
1841 "Decrypted message does not match HMAC!\n");
1842
1843 goto cleanup;
1844 }
1845 }
1846
1847 {
1848 struct GNUNET_MESSENGER_ShortMessage shortened;
1849 if (GNUNET_YES != decode_short_message (&shortened,
1850 padded_length,
1851 (char*) data))
1852 {
1854 "Decoding decrypted message failed!\n");
1855
1856 goto cleanup;
1857 }
1858
1859 unfold_short_message (&shortened, message);
1861 }
1862
1863cleanup:
1864 GNUNET_free (data);
1865 return result;
1866}
1867
1868
1871{
1872 uint16_t data_length;
1873 struct GNUNET_MESSENGER_ShortMessage shortened;
1874
1875 GNUNET_assert ((message) &&
1877
1878 data_length = message->body.transcript.length;
1879
1880 if (GNUNET_YES != decode_short_message (&shortened,
1881 data_length,
1882 message->body.transcript.data))
1883 {
1885 "Decoding decrypted message failed!\n");
1886
1887 return GNUNET_NO;
1888 }
1889
1890 unfold_short_message (&shortened, message);
1891 return GNUNET_YES;
1892}
1893
1894
1897 const struct GNUNET_CRYPTO_EcdhePrivateKey *key,
1898 struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key
1899 )
1900{
1901 GNUNET_assert ((message) && (key) && (shared_key) &&
1903
1904 if (GNUNET_OK !=
1906 (uint8_t*) "messenger",
1907 strlen ("messenger"),
1908 NULL, 0,
1909 (uint8_t*) message->body.access.key,
1911 (uint8_t*) shared_key,
1912 NULL))
1913 {
1914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1915 return GNUNET_NO;
1916 }
1917
1918 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1919 {
1920 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1921 return GNUNET_NO;
1922 }
1923
1924 return GNUNET_YES;
1925}
1926
1927
1930 const struct
1933 shared_key)
1934{
1936
1937 GNUNET_assert ((message) && (key) && (shared_key) &&
1939
1941 &(message->body.authorization.event),
1942 sizeof (message->body.authorization.event),
1943 &(message->body.authorization.identifier),
1944 sizeof (message->body.authorization.
1945 identifier),
1946 NULL);
1947
1950 key,
1951 &iv,
1952 shared_key))
1953 {
1954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1955 return GNUNET_NO;
1956 }
1957
1958 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1959 {
1960 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1961 return GNUNET_NO;
1962 }
1963
1964 return GNUNET_YES;
1965}
1966
1967
1970{
1973
1974 GNUNET_assert (message);
1975
1976 timestamp = GNUNET_TIME_absolute_ntoh (message->header.timestamp);
1977
1978 switch (message->header.kind)
1979 {
1981 timeout = GNUNET_TIME_relative_ntoh (message->body.deletion.delay);
1982 break;
1984 timeout = GNUNET_TIME_relative_ntoh (message->body.announcement.timeout);
1985 break;
1987 timeout = GNUNET_TIME_relative_ntoh (message->body.appeal.timeout);
1988 break;
1990 timeout = GNUNET_TIME_relative_ntoh (message->body.group.timeout);
1991 break;
1992 default:
1994 break;
1995 }
1996
1998
2002
2003 return timeout;
2004}
2005
2006
2007struct GNUNET_MQ_Envelope*
2009 struct GNUNET_HashCode *hash,
2012 const void *cls)
2013{
2014 struct GNUNET_MessageHeader *header;
2015 uint16_t length, padded_length;
2016 struct GNUNET_MQ_Envelope *env;
2017 char *buffer;
2018
2019 GNUNET_assert (message);
2020
2022 "Packing message kind=%u and sender: %s\n",
2023 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2024
2025 length = get_message_size (message, GNUNET_YES);
2026 padded_length = calc_padded_length (length);
2027
2029 {
2030 env = GNUNET_MQ_msg_extra (header, padded_length,
2032 buffer = (char*) &(header[1]);
2033 }
2034 else
2035 {
2036 env = NULL;
2037 buffer = GNUNET_malloc (padded_length);
2038 }
2039
2040 encode_message (message, padded_length, buffer, GNUNET_YES);
2041
2042 if (hash)
2043 {
2044 hash_message (message, length, buffer, hash);
2045
2046 if (sign)
2047 sign (cls, message, length, buffer, hash);
2048 }
2049
2051 GNUNET_free (buffer);
2052
2053 return env;
2054}
2055
2056
2059{
2060 GNUNET_assert (message);
2061
2062 switch (message->header.kind)
2063 {
2069 return GNUNET_YES;
2070 default:
2071 return GNUNET_NO;
2072 }
2073}
2074
2075
2078{
2079 GNUNET_assert (message);
2080
2081 if (GNUNET_YES == is_peer_message (message))
2082 return GNUNET_YES;
2083
2084 switch (message->header.kind)
2085 {
2087 return GNUNET_YES; // Reserved for connection handling only!
2089 return GNUNET_YES; // Reserved for member handling only!
2091 return GNUNET_YES; // Reserved for member handling only!
2093 return GNUNET_YES; // Reserved for member name handling only!
2095 return GNUNET_YES; // Reserved for member key handling only!
2097 return GNUNET_YES; // Reserved for connection handling only!
2099 return GNUNET_YES; // Reserved for member id handling only!
2101 return GNUNET_YES; // Reserved for connection handling only!
2103 return GNUNET_YES; // Reserved for peers only!
2105 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2107 return GNUNET_NO;
2109 return GNUNET_NO;
2111 return GNUNET_NO;
2113 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2115 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2117 return GNUNET_YES; // Reserved for connection handling only!
2119 return GNUNET_NO;
2121 return GNUNET_NO;
2123 return GNUNET_NO;
2125 return GNUNET_YES; // Reserved for subscription handling only!
2127 return GNUNET_NO;
2129 return GNUNET_YES; // Reserved for epoch and group key exchange!
2131 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2133 return GNUNET_YES; // Reserved for epoch key exchange!
2135 return GNUNET_YES; // Reserved for epoch and group key exchange!
2137 return GNUNET_YES; // Reserved for epoch and group key revoking!
2139 return GNUNET_YES; // Reserved for group key exchange!
2141 return GNUNET_YES; // Reserved for epoch and group key exchange!
2142 default:
2143 return GNUNET_SYSERR;
2144 }
2145}
2146
2147
2150{
2151 GNUNET_assert (message);
2152
2153 switch (message->header.kind)
2154 {
2156 return GNUNET_YES;
2158 return GNUNET_YES;
2160 return GNUNET_YES;
2161 default:
2162 return GNUNET_NO;
2163 }
2164}
2165
2166
2169{
2170 GNUNET_assert (message);
2171
2172 if (GNUNET_YES == is_peer_message (message))
2173 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2174
2175 switch (message->header.kind)
2176 {
2178 return GNUNET_SYSERR; // Reserved for connection handling only!
2180 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2182 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2184 return GNUNET_YES;
2186 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2188 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2190 return GNUNET_NO; // Reserved for member id handling only!
2192 return GNUNET_SYSERR; // Reserved for connection handling only!
2194 return GNUNET_SYSERR; // Reserved for peers only!
2196 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2198 return GNUNET_YES;
2200 return GNUNET_YES;
2202 return GNUNET_YES;
2204 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2206 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2208 return GNUNET_SYSERR; // Reserved for connection handling only!
2210 return GNUNET_YES;
2212 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2214 return GNUNET_YES;
2216 return GNUNET_YES;
2218 return GNUNET_YES;
2220 return GNUNET_NO; // Should only be used for implicit key exchange!
2222 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2224 return GNUNET_NO; // Should only be used for implicit key exchange!
2226 return GNUNET_NO; // Should only be used for implicit key exchange!
2228 return GNUNET_NO; // Should only be used for implicit key exchange!
2230 return GNUNET_NO; // Should only be used for implicit key exchange!
2232 return GNUNET_NO; // Should only be used for implicit key exchange!
2233 default:
2234 return GNUNET_SYSERR;
2235 }
2236}
2237
2238
2239const struct GNUNET_ShortHashCode*
2241{
2242 GNUNET_assert (message);
2243
2244 switch (message->header.kind)
2245 {
2247 return &(message->body.subscribtion.discourse);
2249 return &(message->body.talk.discourse);
2250 default:
2251 return NULL;
2252 }
2253}
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 @44 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign a given block with a specific purpose using the host's peer identity.
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_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_EcdhePrivateKey *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_read_signature_from_buffer(struct GNUNET_CRYPTO_Signature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_Signature from a compact buffer.
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition crypto_pkey.c:85
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_EcdhePublicKey *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.
#define GNUNET_be32toh(x)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
ssize_t GNUNET_CRYPTO_signature_get_length(const struct GNUNET_CRYPTO_Signature *sig)
Get the compacted length of a GNUNET_CRYPTO_Signature.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_CRYPTO_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_PrivateKey.
#define GNUNET_CRYPTO_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_PublicKey.
#define GNUNET_htobe32(x)
#define GNUNET_PACKED
gcc-ism to get packed structs.
#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 subscribtion 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:630
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:741
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)
#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)
enum GNUNET_GenericReturnValue verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
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...
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
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 encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
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)
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 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...
const uint16_t encryption_overhead
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)
enum GNUNET_GenericReturnValue decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
#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)
enum GNUNET_GenericReturnValue extract_access_message_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_EcdhePrivateKey *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 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.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
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.
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
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
uint32_t type
Type of signature.
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_MessageSubscribtion subscribtion
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_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.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_CRYPTO_Signature signature
The signature of the senders private key.
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_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_CRYPTO_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_CRYPTO_PublicKey key
The new public key which replaces the current senders 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_EccSignaturePurpose 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 subscribtion.
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_PublicKey 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.