GNUnet 0.28.0-dev.2-10-g49d3de5da
 
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--2026 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_pils_service.h"
31#include "gnunet_signatures.h"
32#include "gnunet_util_lib.h"
33
34const uint16_t encryption_overhead =
36
42
48
51{
52 struct GNUNET_MESSENGER_Message *message;
53
54 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
55 message->header.kind = kind;
56
57 switch (message->header.kind)
58 {
60 message->body.name.name = NULL;
61 break;
63 message->body.text.text = NULL;
64 break;
66 message->body.file.uri = NULL;
67 break;
69 message->body.privacy.length = 0;
70 message->body.privacy.data = NULL;
71 break;
73 message->body.ticket.identifier = NULL;
74 break;
76 message->body.transcript.length = 0;
77 message->body.transcript.data = NULL;
78 break;
80 message->body.tag.tag = NULL;
81 break;
83 message->body.talk.length = 0;
84 message->body.talk.data = NULL;
85 break;
87 message->body.secret.length = 0;
88 message->body.secret.data = NULL;
89 break;
90 default:
91 break;
92 }
93
94 return message;
95}
96
97
100{
101 struct GNUNET_MESSENGER_Message *copy;
102
103 GNUNET_assert (message);
104
105 copy = GNUNET_new (struct GNUNET_MESSENGER_Message);
106 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
107
108 switch (message->header.kind)
109 {
111 copy->body.name.name = message->body.name.name? GNUNET_strdup (
112 message->body.name.name) : NULL;
113 break;
115 copy->body.text.text = message->body.text.text? GNUNET_strdup (
116 message->body.text.text) : NULL;
117 break;
119 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
120 message->body.file.uri) : NULL;
121 break;
124 copy->body.privacy.length) : NULL;
125
126 if (copy->body.privacy.data)
127 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
128 copy->body.privacy.length);
129
130 break;
132 copy->body.ticket.identifier = message->body.ticket.identifier?
134 message->body.ticket.identifier) : NULL;
135 break;
138 copy->body.transcript.length) : NULL;
139
140 if (copy->body.transcript.data)
142 copy->body.transcript.length);
143
144 break;
146 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
147 message->body.tag.tag) : NULL;
148 break;
150 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
151 copy->body.talk.length) : NULL;
152
153 if (copy->body.talk.data)
154 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
155 copy->body.talk.length);
156
157 break;
159 copy->body.secret.data = copy->body.secret.length ? GNUNET_malloc (
160 copy->body.secret.length) : NULL;
161
162 if (copy->body.secret.data)
163 GNUNET_memcpy (copy->body.secret.data, message->body.secret.data,
164 copy->body.secret.length);
165
166 break;
167 default:
168 break;
169 }
170
171 return copy;
172}
173
174
175void
178{
180
181 GNUNET_assert ((message) && (header));
182
183 kind = message->header.kind;
184
185 GNUNET_memcpy (&(message->header), header,
186 sizeof(struct GNUNET_MESSENGER_MessageHeader));
187
188 message->header.kind = kind;
189}
190
191
192static void
195{
197
198 switch (kind)
199 {
201 if (body->name.name)
203 break;
205 if (body->text.text)
207 break;
209 if (body->file.uri)
211 break;
213 if (body->privacy.data)
215 break;
219 break;
221 if (body->transcript.data)
223 break;
225 if (body->tag.tag)
227 break;
229 if (body->talk.data)
231 break;
233 if (body->secret.data)
235 break;
236 default:
237 break;
238 }
239}
240
241
242void
244{
245 GNUNET_assert (message);
246
247 destroy_message_body (message->header.kind, &(message->body));
248}
249
250
251void
253{
254 GNUNET_assert (message);
255
256 destroy_message_body (message->header.kind, &(message->body));
257
258 GNUNET_free (message);
259}
260
261
264{
265 GNUNET_assert (message);
266
267 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
269 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
270 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
272 return GNUNET_YES;
273 else
274 return GNUNET_NO;
275}
276
277
278static void
280 struct GNUNET_MESSENGER_ShortMessage *shortened)
281{
282 shortened->kind = message->header.kind;
283
284 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
286}
287
288
289static void
291 struct GNUNET_MESSENGER_Message *message)
292{
293 destroy_message_body (message->header.kind, &(message->body));
294
295 message->header.kind = shortened->kind;
296
297 GNUNET_memcpy (&(message->body), &(shortened->body),
298 sizeof(struct GNUNET_MESSENGER_MessageBody));
299}
300
301
302#define member_size(type, member) sizeof(((type*) NULL)->member)
303
304static uint16_t
306{
307 uint16_t length;
308
309 length = 0;
310
311 switch (kind)
312 {
314 length += member_size (struct GNUNET_MESSENGER_Message,
316 break;
318 length += member_size (struct GNUNET_MESSENGER_Message,
319 body.join.epoch);
320 break;
322 length += member_size (struct GNUNET_MESSENGER_Message,
324 break;
327 break;
329 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
330 break;
333 break;
335 length += member_size (struct GNUNET_MESSENGER_Message,
336 body.merge.epochs[0]);
337 length += member_size (struct GNUNET_MESSENGER_Message,
338 body.merge.epochs[1]);
339 length += member_size (struct GNUNET_MESSENGER_Message,
341 break;
344 break;
348 break;
353 break;
356 length += member_size (struct GNUNET_MESSENGER_Message,
358 break;
360 length += member_size (struct GNUNET_MESSENGER_Message,
362 length += member_size (struct GNUNET_MESSENGER_Message,
364 break;
366 length += member_size (struct GNUNET_MESSENGER_Message,
368 break;
371 break;
373 length += member_size (struct GNUNET_MESSENGER_Message,
375 length += member_size (struct GNUNET_MESSENGER_Message,
377 length += member_size (struct GNUNET_MESSENGER_Message,
379 break;
381 length += member_size (struct GNUNET_MESSENGER_Message,
383 break;
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 length += member_size (struct GNUNET_MESSENGER_Message,
395 break;
397 length += member_size (struct GNUNET_MESSENGER_Message,
399 length += member_size (struct GNUNET_MESSENGER_Message,
400 body.secret.iv);
401 length += member_size (struct GNUNET_MESSENGER_Message,
402 body.secret.mac);
403 break;
405 length += member_size (struct GNUNET_MESSENGER_Message,
407 length += member_size (struct GNUNET_MESSENGER_Message,
408 body.appeal.key);
409 length += member_size (struct GNUNET_MESSENGER_Message,
411 break;
413 length += member_size (struct GNUNET_MESSENGER_Message,
415 length += member_size (struct GNUNET_MESSENGER_Message,
416 body.access.key);
417 length += member_size (struct GNUNET_MESSENGER_Message,
419 break;
421 length += member_size (struct GNUNET_MESSENGER_Message,
423 length += member_size (struct GNUNET_MESSENGER_Message,
425 length += member_size (struct GNUNET_MESSENGER_Message,
427 break;
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 length += member_size (struct GNUNET_MESSENGER_Message,
437 break;
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 length += member_size (struct GNUNET_MESSENGER_Message,
447 break;
448 default:
449 break;
450 }
451
452 return length;
453}
454
455
456typedef uint32_t kind_t;
457
458uint16_t
460 enum GNUNET_GenericReturnValue include_header)
461{
462 uint16_t length;
463
464 length = 0;
465
466 if (GNUNET_YES == include_header)
467 {
471 }
472
473 length += sizeof(kind_t);
474
475 return length + get_message_body_kind_size (kind);
476}
477
478
479static uint16_t
482{
483 uint16_t length;
484
485 length = 0;
486
487 switch (kind)
488 {
492 break;
494 length += (body->name.name ? strlen (body->name.name) : 0);
495 break;
499 break;
501 length += (body->text.text ? strlen (body->text.text) : 0);
502 break;
504 length += (body->file.uri ? strlen (body->file.uri) : 0);
505 break;
507 length += body->privacy.length;
508 break;
510 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
511 break;
514 length += body->transcript.length;
515 break;
517 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
518 break;
520 length += body->talk.length;
521 break;
523 length += body->secret.length;
524 break;
525 default:
526 break;
527 }
528
529 return length;
530}
531
532
533uint16_t
535 enum GNUNET_GenericReturnValue include_header)
536{
537 uint16_t length;
538
539 GNUNET_assert (message);
540
541 length = 0;
542
543 if (GNUNET_YES == include_header)
545 &(message->header.signature));
546
547 length += get_message_kind_size (message->header.kind, include_header);
548 length += get_message_body_size (message->header.kind, &(message->body));
549
550 return length;
551}
552
553
554static uint16_t
556 enum GNUNET_GenericReturnValue include_body)
557{
558 uint16_t minimum_size;
559
560 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
561
562 if (message)
563 return minimum_size + get_message_body_kind_size (message->kind)
564 + (include_body == GNUNET_YES?
565 get_message_body_size (message->kind, &(message->body)) : 0);
566 else
567 return minimum_size;
568}
569
570
571static uint16_t
573{
574 uint16_t padding;
575 uint16_t kind_size;
576
577 padding = 0;
578
579 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
580 {
582 GNUNET_YES);
583
584 if (kind_size > padding)
585 padding = kind_size;
586 }
587
588 return padding + GNUNET_MESSENGER_PADDING_MIN;
589}
590
591
592#define max(x, y) (x > y? x : y)
593
594static uint16_t
595calc_padded_length (uint16_t length)
596{
597 static uint16_t usual_padding = 0;
598 uint16_t padded_length;
599
600 if (! usual_padding)
601 usual_padding = calc_usual_padding ();
602
603 padded_length = max (
605 usual_padding);
606
607 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
609
610 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
612
613 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
615
617
618}
619
620
621#define min(x, y) (x < y? x : y)
622
623#define encode_step_ext(dst, offset, src, size) do { \
624 GNUNET_memcpy (dst + offset, src, size); \
625 offset += size; \
626} while (0)
627
628#define encode_step(dst, offset, src) do { \
629 encode_step_ext (dst, offset, src, sizeof(*src)); \
630} while (0)
631
632#define encode_step_key(dst, offset, src, length) do { \
633 ssize_t result = GNUNET_CRYPTO_write_blindable_pk_to_buffer ( \
634 src, dst + offset, length - offset); \
635 if (result < 0) \
636 GNUNET_break (0); \
637 else \
638 offset += result; \
639} while (0)
640
641#define encode_step_hpke_key(dst, offset, src, length) do { \
642 ssize_t result = GNUNET_CRYPTO_write_hpke_pk_to_buffer ( \
643 src, dst + offset, length - offset); \
644 if (result < 0) \
645 GNUNET_break (0); \
646 else \
647 offset += result; \
648} while (0)
649
650#define encode_step_signature(dst, offset, src, length) do { \
651 ssize_t result = GNUNET_CRYPTO_write_blinded_key_signature_to_buffer ( \
652 src, dst + offset, length - offset); \
653 if (result < 0) \
654 GNUNET_break (0); \
655 else \
656 offset += result; \
657} while (0)
658
659static void
661 const struct GNUNET_MESSENGER_MessageBody *body,
662 uint16_t length,
663 char *buffer,
664 uint16_t offset)
665{
666 uint32_t value0, value1;
667
668 GNUNET_assert ((body) && (buffer));
669
670 switch (kind)
671 {
673 value0 = GNUNET_htobe32 (body->info.messenger_version);
674
675 encode_step (buffer, offset, &value0);
676 break;
678 encode_step (buffer, offset, &(body->join.epoch));
679 encode_step_key (buffer, offset, &(body->join.key), length);
680 encode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
681 break;
683 encode_step (buffer, offset, &(body->leave.epoch));
684 break;
686 if (body->name.name)
688 buffer,
689 offset,
690 body->name.name,
691 min (length - offset, strlen (body->name.name)));
692 break;
694 encode_step_key (buffer, offset, &(body->key.key), length);
695 encode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
696 break;
698 encode_step (buffer, offset, &(body->peer.peer));
699 break;
701 encode_step (buffer, offset, &(body->id.id));
702 break;
704 encode_step (buffer, offset, &(body->miss.peer));
705 break;
707 encode_step (buffer, offset, &(body->merge.epochs[0]));
708 encode_step (buffer, offset, &(body->merge.epochs[1]));
709 encode_step (buffer, offset, &(body->merge.previous));
710 break;
712 encode_step (buffer, offset, &(body->request.hash));
713 break;
715 encode_step (buffer, offset, &(body->invite.door));
716 encode_step (buffer, offset, &(body->invite.key));
717 break;
719 if (body->text.text)
721 buffer,
722 offset,
723 body->text.text,
724 min (length - offset, strlen (body->text.text)));
725 break;
727 encode_step (buffer, offset, &(body->file.key));
728 encode_step (buffer, offset, &(body->file.hash));
729 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
730 if (body->file.uri)
731 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
732 strlen (
733 body->file.uri)));
734 break;
736 if (body->privacy.data)
737 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
738 body->privacy.
739 length));
740 break;
742 encode_step (buffer, offset, &(body->deletion.hash));
743 encode_step (buffer, offset, &(body->deletion.delay));
744 break;
746 value0 = GNUNET_htobe32 (body->connection.amount);
747 value1 = GNUNET_htobe32 (body->connection.flags);
748
749 encode_step (buffer, offset, &value0);
750 encode_step (buffer, offset, &value1);
751 break;
753 encode_step_ext (buffer, offset, body->ticket.identifier,
754 min (length - offset, strlen (body->ticket.identifier)));
755 break;
757 encode_step (buffer, offset, &(body->transcript.hash));
758 encode_step_key (buffer, offset, &(body->transcript.key), length);
759
760 if (body->transcript.data)
761 encode_step_ext (buffer, offset, body->transcript.data, min (length
762 - offset,
763 body->
764 transcript.
765 length));
766 break;
768 encode_step (buffer, offset, &(body->tag.hash));
769
770 if (body->tag.tag)
771 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
772 strlen (
773 body->tag.tag)));
774 break;
776 value0 = GNUNET_htobe32 (body->subscription.flags);
777
778 encode_step (buffer, offset, &(body->subscription.discourse));
779 encode_step (buffer, offset, &(body->subscription.time));
780 encode_step (buffer, offset, &value0);
781 break;
783 encode_step (buffer, offset, &(body->talk.discourse));
784
785 if (body->talk.data)
786 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
787 body->talk.
788 length));
789 break;
791 encode_step (buffer, offset, &(body->announcement.identifier));
792 encode_step (buffer, offset, &(body->announcement.key));
793 encode_step (buffer, offset, &(body->announcement.nonce));
794 encode_step (buffer, offset, &(body->announcement.timeout));
795 encode_step (buffer, offset, &(body->announcement.hmac));
796 break;
798 encode_step (buffer, offset, &(body->secret.identifier));
799 encode_step (buffer, offset, &(body->secret.iv));
800 encode_step (buffer, offset, &(body->secret.mac));
801
802 if (body->secret.data)
803 encode_step_ext (buffer, offset, body->secret.data, min (length - offset,
804 body->secret.
805 length));
806 break;
808 encode_step (buffer, offset, &(body->appeal.event));
809 encode_step (buffer, offset, &(body->appeal.key));
810 encode_step (buffer, offset, &(body->appeal.timeout));
811 break;
813 encode_step (buffer, offset, &(body->access.event));
814 encode_step (buffer, offset, &(body->access.key));
815 encode_step (buffer, offset, &(body->access.hmac));
816 break;
818 encode_step (buffer, offset, &(body->revolution.identifier));
819 encode_step (buffer, offset, &(body->revolution.nonce));
820 encode_step (buffer, offset, &(body->revolution.hmac));
821 break;
823 encode_step (buffer, offset, &(body->group.identifier));
824 encode_step (buffer, offset, &(body->group.initiator));
825 encode_step (buffer, offset, &(body->group.partner));
826 encode_step (buffer, offset, &(body->group.timeout));
827 break;
829 encode_step (buffer, offset, &(body->authorization.identifier));
830 encode_step (buffer, offset, &(body->authorization.event));
831 encode_step (buffer, offset, &(body->authorization.key));
832 encode_step (buffer, offset, &(body->authorization.hmac));
833 break;
834 default:
835 break;
836 }
837
838 if (offset >= length)
839 return;
840
841 {
842 uint16_t padding;
843 uint16_t used_padding;
844
845 padding = length - offset;
846 used_padding = sizeof(padding) + sizeof(char);
847
848 GNUNET_assert (padding >= used_padding);
849
850 buffer[offset++] = '\0';
851
852 if (padding > used_padding)
854 padding - used_padding);
855
856 GNUNET_memcpy (buffer + length - sizeof(padding), &padding,
857 sizeof(padding));
858 }
859}
860
861
862void
864 uint16_t length,
865 char *buffer)
866{
867 uint16_t offset = 0;
868
869 GNUNET_assert ((message) && (buffer));
870
871 encode_step_signature (buffer, offset, &(message->header.signature),
872 length);
873}
874
875
876void
878 uint16_t length,
879 char *buffer,
880 enum GNUNET_GenericReturnValue include_header)
881{
882 uint16_t offset;
883 kind_t kind;
884
885 GNUNET_assert ((message) && (buffer));
886
887 offset = 0;
888
889 if (GNUNET_YES == include_header)
890 encode_step_signature (buffer, offset, &(message->header.signature),
891 length);
892
893 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
894
895 if (GNUNET_YES == include_header)
896 {
897 encode_step (buffer, offset, &(message->header.timestamp));
898 encode_step (buffer, offset, &(message->header.sender_id));
899 encode_step (buffer, offset, &(message->header.previous));
900 }
901
902 encode_step (buffer, offset, &kind);
903
904 encode_message_body (message->header.kind, &(message->body),
905 length, buffer, offset);
906}
907
908
909static void
911 uint16_t length,
912 char *buffer)
913{
914 struct GNUNET_HashCode hash;
915 uint16_t offset;
916 kind_t kind;
917
918 GNUNET_assert ((message) && (buffer));
919
920 offset = sizeof(hash);
921 kind = GNUNET_htobe32 ((kind_t) message->kind);
922
923 encode_step (buffer, offset, &kind);
924
925 encode_message_body (message->kind, &(message->body), length, buffer, offset);
926
928 buffer + sizeof(hash),
929 length - sizeof(hash),
930 &hash);
931
932 GNUNET_memcpy (buffer, &hash, sizeof(hash));
933}
934
935
936#define decode_step_ext(src, offset, dst, size) do { \
937 GNUNET_memcpy (dst, src + offset, size); \
938 offset += size; \
939} while (0)
940
941#define decode_step(src, offset, dst) do { \
942 decode_step_ext (src, offset, dst, sizeof(*dst)); \
943} while (0)
944
945#define decode_step_malloc(src, offset, dst, size, zero) do { \
946 dst = GNUNET_malloc (size + zero); \
947 if (zero) dst[size] = 0; \
948 decode_step_ext (src, offset, dst, size); \
949} while (0)
950
951#define decode_step_key(src, offset, dst, length) do { \
952 enum GNUNET_GenericReturnValue result; \
953 size_t read; \
954 result = GNUNET_CRYPTO_read_blindable_pk_from_buffer ( \
955 src + offset, length - offset, dst, &read); \
956 if (GNUNET_SYSERR == result) \
957 GNUNET_break (0); \
958 else \
959 offset += read; \
960} while (0)
961
962#define decode_step_hpke_key(src, offset, dst, length) do { \
963 enum GNUNET_GenericReturnValue result; \
964 size_t read; \
965 result = GNUNET_CRYPTO_read_hpke_pk_from_buffer ( \
966 src + offset, length - offset, dst, &read); \
967 if (GNUNET_SYSERR == result) \
968 GNUNET_break (0); \
969 else \
970 offset += read; \
971} while (0)
972
973static uint16_t
975 struct GNUNET_MESSENGER_MessageBody *body,
976 uint16_t length,
977 const char *buffer,
978 uint16_t offset)
979{
980 uint16_t padding;
981 uint32_t value0, value1;
982
983 GNUNET_assert ((kind) && (body) && (buffer));
984
985 padding = 0;
986
987 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
988
989 if (padding > length - offset)
990 padding = 0;
991
992 {
993 uint16_t end_zero;
994 end_zero = length - padding;
995
996 if ((padding) && (buffer[end_zero] != '\0'))
997 padding = 0;
998 }
999
1000 length -= padding;
1001
1002 switch (*kind)
1003 {
1005 decode_step (buffer, offset, &value0);
1006
1007 body->info.messenger_version = GNUNET_be32toh (value0);
1008 break;
1010 decode_step (buffer, offset, &(body->join.epoch));
1011 decode_step_key (buffer, offset, &(body->join.key), length);
1012 decode_step_hpke_key (buffer, offset, &(body->join.hpke_key), length);
1013 break;
1015 decode_step (buffer, offset, &(body->leave.epoch));
1016 break;
1018 if (length > offset)
1019 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
1020 else
1021 body->name.name = NULL;
1022 break;
1024 decode_step_key (buffer, offset, &(body->key.key), length);
1025 decode_step_hpke_key (buffer, offset, &(body->key.hpke_key), length);
1026 break;
1028 decode_step (buffer, offset, &(body->peer.peer));
1029 break;
1031 decode_step (buffer, offset, &(body->id.id));
1032 break;
1034 decode_step (buffer, offset, &(body->miss.peer));
1035 break;
1037 decode_step (buffer, offset, &(body->merge.epochs[0]));
1038 decode_step (buffer, offset, &(body->merge.epochs[1]));
1039 decode_step (buffer, offset, &(body->merge.previous));
1040 break;
1042 decode_step (buffer, offset, &(body->request.hash));
1043 break;
1045 decode_step (buffer, offset, &(body->invite.door));
1046 decode_step (buffer, offset, &(body->invite.key));
1047 break;
1049 if (length > offset)
1050 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
1051 else
1052 body->text.text = NULL;
1053 break;
1055 decode_step (buffer, offset, &(body->file.key));
1056 decode_step (buffer, offset, &(body->file.hash));
1057 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
1058 if (length > offset)
1059 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
1060 else
1061 body->file.uri = NULL;
1062 break;
1064 if (length > offset)
1065 {
1066 body->privacy.length = (length - offset);
1067 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
1068 0);
1069 }
1070 else
1071 {
1072 body->privacy.length = 0;
1073 body->privacy.data = NULL;
1074 }
1075
1076 break;
1078 decode_step (buffer, offset, &(body->deletion.hash));
1079 decode_step (buffer, offset, &(body->deletion.delay));
1080 break;
1082 decode_step (buffer, offset, &value0);
1083 decode_step (buffer, offset, &value1);
1084
1085 body->connection.amount = GNUNET_be32toh (value0);
1086 body->connection.flags = GNUNET_be32toh (value1);
1087 break;
1089 if (length > offset)
1090 decode_step_malloc (buffer, offset, body->ticket.identifier, length
1091 - offset, 1);
1092 else
1093 body->ticket.identifier = NULL;
1094 break;
1096 decode_step (buffer, offset, &(body->transcript.hash));
1097 decode_step_key (buffer, offset, &(body->transcript.key), length);
1098
1099 if (length > offset)
1100 {
1101 body->transcript.length = (length - offset);
1102 decode_step_malloc (buffer, offset, body->transcript.data,
1103 length - offset, 0);
1104 }
1105 else
1106 {
1107 body->transcript.length = 0;
1108 body->transcript.data = NULL;
1109 }
1110
1111 break;
1113 decode_step (buffer, offset, &(body->tag.hash));
1114 if (length > offset)
1115 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
1116 else
1117 body->tag.tag = NULL;
1118 break;
1120 decode_step (buffer, offset, &(body->subscription.discourse));
1121 decode_step (buffer, offset, &(body->subscription.time));
1122 decode_step (buffer, offset, &value0);
1123
1124 body->subscription.flags = GNUNET_be32toh (value0);
1125 break;
1127 decode_step (buffer, offset, &(body->talk.discourse));
1128
1129 if (length > offset)
1130 {
1131 body->talk.length = (length - offset);
1132 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
1133 0);
1134 }
1135 else
1136 {
1137 body->talk.length = 0;
1138 body->talk.data = NULL;
1139 }
1140
1141 break;
1143 decode_step (buffer, offset, &(body->announcement.identifier));
1144 decode_step (buffer, offset, &(body->announcement.key));
1145 decode_step (buffer, offset, &(body->announcement.nonce));
1146 decode_step (buffer, offset, &(body->announcement.timeout));
1147 decode_step (buffer, offset, &(body->announcement.hmac));
1148 break;
1150 decode_step (buffer, offset, &(body->secret.identifier));
1151 decode_step (buffer, offset, &(body->secret.iv));
1152 decode_step (buffer, offset, &(body->secret.mac));
1153
1154 if (length > offset)
1155 {
1156 body->secret.length = (length - offset);
1157 decode_step_malloc (buffer, offset, body->secret.data, length - offset,
1158 0);
1159 }
1160 else
1161 {
1162 body->secret.length = 0;
1163 body->secret.data = NULL;
1164 }
1165
1166 break;
1168 decode_step (buffer, offset, &(body->appeal.event));
1169 decode_step (buffer, offset, &(body->appeal.key));
1170 decode_step (buffer, offset, &(body->appeal.timeout));
1171 break;
1173 decode_step (buffer, offset, &(body->access.event));
1174 decode_step (buffer, offset, &(body->access.key));
1175 decode_step (buffer, offset, &(body->access.hmac));
1176 break;
1178 decode_step (buffer, offset, &(body->revolution.identifier));
1179 decode_step (buffer, offset, &(body->revolution.nonce));
1180 decode_step (buffer, offset, &(body->revolution.hmac));
1181 break;
1183 decode_step (buffer, offset, &(body->group.identifier));
1184 decode_step (buffer, offset, &(body->group.initiator));
1185 decode_step (buffer, offset, &(body->group.partner));
1186 decode_step (buffer, offset, &(body->group.timeout));
1187 break;
1189 decode_step (buffer, offset, &(body->authorization.identifier));
1190 decode_step (buffer, offset, &(body->authorization.event));
1191 decode_step (buffer, offset, &(body->authorization.key));
1192 decode_step (buffer, offset, &(body->authorization.hmac));
1193 break;
1194 default:
1196 break;
1197 }
1198
1199 return padding;
1200}
1201
1202
1205 uint16_t length,
1206 const char *buffer,
1207 enum GNUNET_GenericReturnValue include_header,
1208 uint16_t *padding)
1209{
1210 uint16_t offset;
1211 uint16_t count;
1212 kind_t kind;
1213
1215 (message) &&
1216 (buffer) &&
1218 include_header)));
1219
1220 offset = 0;
1221
1222 if (GNUNET_YES == include_header)
1223 {
1224 ssize_t result;
1225
1227 &(message->header.signature), buffer, length - offset);
1228
1229 if (result < 0)
1230 return GNUNET_NO;
1231 else
1232 offset += result;
1233 }
1234
1235 count = length - offset;
1237 include_header))
1238 return GNUNET_NO;
1239
1240 if (GNUNET_YES == include_header)
1241 {
1242 decode_step (buffer, offset, &(message->header.timestamp));
1243 decode_step (buffer, offset, &(message->header.sender_id));
1244 decode_step (buffer, offset, &(message->header.previous));
1245 }
1246
1247 decode_step (buffer, offset, &kind);
1248 kind = GNUNET_be32toh (kind);
1249
1250 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1251
1252 if (count < get_message_kind_size (message->header.kind, include_header))
1253 return GNUNET_NO;
1254
1255 {
1256 uint16_t result;
1257 result = decode_message_body (&(message->header.kind),
1258 &(message->body), length, buffer, offset);
1259
1260 if (padding)
1261 *padding = result;
1262 }
1263
1264 return GNUNET_YES;
1265}
1266
1267
1268static enum GNUNET_GenericReturnValue
1270 uint16_t length,
1271 const char *buffer)
1272{
1273 struct GNUNET_HashCode expected, hash;
1274 uint16_t offset;
1275 kind_t kind;
1276
1277 GNUNET_assert ((message) && (buffer));
1278
1279 offset = sizeof(hash);
1280
1281 if (length < get_short_message_size (NULL, GNUNET_NO))
1282 return GNUNET_NO;
1283
1284 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1285
1287 buffer + sizeof(hash),
1288 length - sizeof(hash),
1289 &expected);
1290
1291 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1292 return GNUNET_NO;
1293
1294 decode_step (buffer, offset, &kind);
1295 kind = GNUNET_be32toh (kind);
1296
1297 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1298
1299 if (length < get_short_message_size (message, GNUNET_NO))
1300 return GNUNET_NO;
1301
1302 decode_message_body (&(message->kind), &(message->body), length, buffer,
1303 offset);
1304
1305 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1306 return GNUNET_NO;
1307
1308 return GNUNET_YES;
1309}
1310
1311
1312void
1314 uint16_t length,
1315 const char *buffer,
1316 struct GNUNET_HashCode *hash)
1317{
1318 ssize_t offset;
1319
1320 GNUNET_assert ((message) && (buffer) && (hash));
1321
1323 signature));
1324
1325 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1326}
1327
1328
1329void
1331 const struct GNUNET_HashCode *hash,
1333{
1334 struct GNUNET_MESSENGER_MessageSignature signature;
1335
1336 GNUNET_assert ((message) && (hash) && (key));
1337
1338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1339 GNUNET_h2s (hash));
1340
1342 signature.purpose.size = htonl (sizeof(signature));
1343
1344 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1345
1347 &(message->header.signature));
1348 message->header.signature.type = key->type;
1349}
1350
1351
1354 const struct GNUNET_HashCode *hash,
1355 struct GNUNET_PILS_Handle *pils,
1357 void *cls)
1358{
1359 struct GNUNET_MESSENGER_MessageSignature signature;
1360 struct GNUNET_PILS_Operation *operation;
1361
1362 GNUNET_assert ((message) && (hash) && (pils));
1363
1364 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1365 GNUNET_h2s (hash));
1366
1368 signature.purpose.size = htonl (sizeof (signature));
1369
1370 GNUNET_memcpy (&(signature.hash), hash, sizeof (signature.hash));
1371
1372 operation = GNUNET_PILS_sign_by_peer_identity (pils, &(signature.purpose),
1373 sign_cb, cls);
1374
1375 if (! operation)
1376 return NULL;
1377
1379 return operation;
1380}
1381
1382
1383static enum GNUNET_GenericReturnValue
1385 const struct GNUNET_CRYPTO_AeadSecretKey *key,
1386 struct GNUNET_HashCode *hmac)
1387{
1388 struct GNUNET_CRYPTO_AuthKey auth_key;
1389
1390 GNUNET_assert ((message) && (key) && (hmac));
1391
1392 switch (message->header.kind)
1393 {
1396 &auth_key, sizeof (auth_key),
1399 key, sizeof (*key),
1403 return GNUNET_NO;
1404
1405 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1406 sizeof (message->body.announcement)
1407 - sizeof (*hmac),
1408 hmac);
1409 return GNUNET_YES;
1412 &auth_key, sizeof (auth_key),
1415 key, sizeof (*key),
1417 return GNUNET_NO;
1418
1419 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1420 sizeof (message->body.access)
1421 - sizeof (*hmac),
1422 hmac);
1423 return GNUNET_YES;
1426 &auth_key, sizeof (auth_key),
1429 key, sizeof (*key),
1433 return GNUNET_NO;
1434
1435 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1436 sizeof (message->body.revolution)
1437 - sizeof (*hmac),
1438 hmac);
1439 return GNUNET_YES;
1442 &auth_key, sizeof (auth_key),
1445 key, sizeof (*key),
1448 return GNUNET_NO;
1449
1450 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1451 sizeof (message->body.authorization)
1452 - sizeof (*hmac),
1453 hmac);
1454 return GNUNET_YES;
1455 default:
1456 return GNUNET_SYSERR;
1457 }
1458}
1459
1460
1463 const struct GNUNET_CRYPTO_AeadSecretKey *key)
1464{
1465 struct GNUNET_HashCode *hmac;
1466
1467 GNUNET_assert ((message) && (key));
1468
1469 switch (message->header.kind)
1470 {
1472 hmac = &(message->body.announcement.hmac);
1473 break;
1475 hmac = &(message->body.access.hmac);
1476 break;
1478 hmac = &(message->body.revolution.hmac);
1479 break;
1481 hmac = &(message->body.authorization.hmac);
1482 break;
1483 default:
1484 hmac = NULL;
1485 break;
1486 }
1487
1488 if (! hmac)
1489 return GNUNET_SYSERR;
1490
1491 return calc_message_hmac (message, key, hmac);
1492}
1493
1494
1497 const struct GNUNET_HashCode *hash,
1499{
1500 struct GNUNET_MESSENGER_MessageSignature signature;
1501
1502 GNUNET_assert ((message) && (hash) && (key));
1503
1504 if (key->type != message->header.signature.type)
1505 return GNUNET_SYSERR;
1506
1508 signature.purpose.size = htonl (sizeof(signature));
1509
1510 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1511
1514 &(message->header.signature), key);
1515}
1516
1517
1520 const struct GNUNET_HashCode *hash,
1521 const struct GNUNET_PeerIdentity *identity)
1522{
1523 struct GNUNET_MESSENGER_MessageSignature signature;
1524
1525 GNUNET_assert ((message) && (hash) && (identity));
1526
1527 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1528 return GNUNET_SYSERR;
1529
1531 signature.purpose.size = htonl (sizeof(signature));
1532
1533 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1534
1537 &(message->header.signature.
1538 eddsa_signature), identity);
1539}
1540
1541
1544 const struct GNUNET_CRYPTO_AeadSecretKey *key)
1545{
1546 const struct GNUNET_HashCode *msg_hmac;
1547 struct GNUNET_HashCode hmac;
1548
1549 GNUNET_assert ((message) && (key));
1550
1551 switch (message->header.kind)
1552 {
1554 msg_hmac = &(message->body.announcement.hmac);
1555 break;
1557 msg_hmac = &(message->body.access.hmac);
1558 break;
1560 msg_hmac = &(message->body.revolution.hmac);
1561 break;
1563 msg_hmac = &(message->body.authorization.hmac);
1564 break;
1565 default:
1566 msg_hmac = NULL;
1567 break;
1568 }
1569
1570 if (! msg_hmac)
1571 return GNUNET_SYSERR;
1572
1573 if (GNUNET_YES != calc_message_hmac (message, key, &hmac))
1574 return GNUNET_SYSERR;
1575
1576 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1577 return GNUNET_OK;
1578
1579 return GNUNET_SYSERR;
1580}
1581
1582
1585 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
1586{
1588 struct GNUNET_MESSENGER_ShortMessage shortened;
1589 uint16_t length, padded_length, encoded_length;
1590 uint8_t *data;
1591
1592 GNUNET_assert ((message) && (hpke_key));
1593
1594 if (GNUNET_YES == is_service_message (message))
1595 return GNUNET_NO;
1596
1597 fold_short_message (message, &shortened);
1598
1599 length = get_short_message_size (&shortened, GNUNET_YES);
1600 padded_length = calc_padded_length (length + encryption_overhead);
1601
1602 GNUNET_assert (padded_length >= length + encryption_overhead);
1603
1605 message->body.privacy.data = GNUNET_malloc (padded_length);
1606 message->body.privacy.length = padded_length;
1607
1608 encoded_length = (padded_length - encryption_overhead);
1609
1610 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1611
1612 result = GNUNET_NO;
1613 data = GNUNET_malloc (encoded_length);
1614
1615 encode_short_message (&shortened, encoded_length, (char *) data);
1616
1618 (const uint8_t*)
1619 "messenger",
1620 strlen ("messenger"),
1621 NULL, 0,
1622 (const uint8_t*) data,
1623 encoded_length,
1624 (uint8_t*) message->body.
1625 privacy.data,
1626 NULL))
1627 {
1628 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1629
1630 unfold_short_message (&shortened, message);
1631 goto cleanup;
1632 }
1633
1634 destroy_message_body (shortened.kind, &(shortened.body));
1636
1637cleanup:
1638 GNUNET_free (data);
1639 return result;
1640}
1641
1642
1645 const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
1646{
1648 uint16_t padded_length, encoded_length;
1649 uint8_t *data;
1650
1651 GNUNET_assert ((message) && (hpke_key) &&
1653
1654 padded_length = message->body.privacy.length;
1655
1656 if (padded_length < encryption_overhead)
1657 {
1659 "Message length too short to decrypt!\n");
1660
1661 return GNUNET_NO;
1662 }
1663
1664 encoded_length = (padded_length - encryption_overhead);
1665
1666 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1667
1668 result = GNUNET_NO;
1669 data = GNUNET_malloc (encoded_length);
1670
1671 if (GNUNET_OK !=
1673 (uint8_t*) "messenger",
1674 strlen ("messenger"),
1675 NULL, 0,
1676 (uint8_t*) message->body.privacy.data,
1677 padded_length,
1678 (uint8_t*) data,
1679 NULL))
1680 {
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1682
1683 goto cleanup;
1684 }
1685
1686 {
1687 struct GNUNET_MESSENGER_ShortMessage shortened;
1688 if (GNUNET_YES != decode_short_message (&shortened,
1689 encoded_length,
1690 (char*) data))
1691 {
1693 "Decoding decrypted message failed!\n");
1694
1695 goto cleanup;
1696 }
1697
1698 unfold_short_message (&shortened, message);
1700 }
1701
1702cleanup:
1703 GNUNET_free (data);
1704 return result;
1705}
1706
1707
1711{
1712 struct GNUNET_MESSENGER_Message *transcript;
1713
1714 GNUNET_assert ((message) && (key));
1715
1716 if (GNUNET_YES == is_service_message (message))
1717 return NULL;
1718
1720
1721 if (! transcript)
1722 {
1723 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1724 return NULL;
1725 }
1726
1727 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1728 sizeof(transcript->body.transcript.key));
1729
1730 {
1731 struct GNUNET_MESSENGER_ShortMessage shortened;
1732 uint16_t data_length;
1733
1734 fold_short_message (message, &shortened);
1735
1736 data_length = get_short_message_size (&shortened, GNUNET_YES);
1737
1738 transcript->body.transcript.data = GNUNET_malloc (data_length);
1739 transcript->body.transcript.length = data_length;
1740
1741 encode_short_message (&shortened, data_length,
1742 transcript->body.transcript.data);
1743 }
1744
1745 return transcript;
1746}
1747
1748
1751 const union GNUNET_MESSENGER_EpochIdentifier *identifier
1752 ,
1753 const struct GNUNET_CRYPTO_AeadSecretKey *key)
1754{
1756 struct GNUNET_MESSENGER_ShortMessage shortened;
1757 uint16_t length, padded_length;
1758 uint8_t *data;
1759
1760 GNUNET_assert ((message) && (identifier) && (key));
1761
1762 fold_short_message (message, &shortened);
1763
1764 length = get_short_message_size (&shortened, GNUNET_YES);
1765 padded_length = calc_padded_length (length + 0);
1766
1767 GNUNET_assert (padded_length >= length + 0);
1768
1770
1771 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1772 sizeof (message->body.secret.identifier));
1773
1775 &(message->body.secret.iv),
1777
1778 message->body.secret.data = GNUNET_malloc (padded_length);
1779 message->body.secret.length = padded_length;
1780
1781 result = GNUNET_NO;
1782 data = GNUNET_malloc (padded_length);
1783
1784 encode_short_message (&shortened, padded_length, (char *) data);
1785
1786 if (GNUNET_OK != GNUNET_CRYPTO_aead_encrypt (padded_length,
1787 data,
1788 0,
1789 NULL,
1790 key,
1791 &message->body.secret.iv,
1792 (unsigned char*) message->body.
1793 secret.data,
1794 &message->body.secret.mac))
1795 {
1796 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1797 unfold_short_message (&shortened, message);
1798 goto cleanup;
1799 }
1800
1801 destroy_message_body (shortened.kind, &(shortened.body));
1803
1804cleanup:
1805 GNUNET_free (data);
1806 return result;
1807}
1808
1809
1812 const struct GNUNET_CRYPTO_AeadSecretKey *key)
1813{
1815 uint16_t padded_length;
1816 uint8_t *data;
1817
1818 GNUNET_assert ((message) && (key) &&
1820
1821 padded_length = message->body.secret.length;
1822
1823 result = GNUNET_NO;
1824 data = GNUNET_malloc (padded_length);
1825
1826 if (-1 == GNUNET_CRYPTO_aead_decrypt (padded_length,
1827 (unsigned char*) message->body.secret.
1828 data,
1829 0,
1830 NULL,
1831 key,
1832 &message->body.secret.iv,
1833 &message->body.secret.mac,
1834 data))
1835 {
1836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1837 goto cleanup;
1838 }
1839
1840 {
1841 struct GNUNET_MESSENGER_ShortMessage shortened;
1842 if (GNUNET_YES != decode_short_message (&shortened,
1843 padded_length,
1844 (char*) data))
1845 {
1847 "Decoding decrypted message failed!\n");
1848
1849 goto cleanup;
1850 }
1851
1852 unfold_short_message (&shortened, message);
1854 }
1855
1856cleanup:
1857 GNUNET_free (data);
1858 return result;
1859}
1860
1861
1864{
1865 uint16_t data_length;
1866 struct GNUNET_MESSENGER_ShortMessage shortened;
1867
1868 GNUNET_assert ((message) &&
1870
1871 data_length = message->body.transcript.length;
1872
1873 if (GNUNET_YES != decode_short_message (&shortened,
1874 data_length,
1875 message->body.transcript.data))
1876 {
1878 "Decoding decrypted message failed!\n");
1879
1880 return GNUNET_NO;
1881 }
1882
1883 unfold_short_message (&shortened, message);
1884 return GNUNET_YES;
1885}
1886
1887
1890 const struct GNUNET_CRYPTO_HpkePrivateKey *key,
1891 struct GNUNET_CRYPTO_AeadSecretKey *shared_key
1892 )
1893{
1894 GNUNET_assert ((message) && (key) && (shared_key) &&
1896
1897 if (GNUNET_OK !=
1899 (uint8_t*) "messenger",
1900 strlen ("messenger"),
1901 NULL, 0,
1902 (uint8_t*) message->body.access.key,
1904 (uint8_t*) shared_key,
1905 NULL))
1906 {
1907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1908 return GNUNET_NO;
1909 }
1910
1911 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1912 {
1913 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1914 return GNUNET_NO;
1915 }
1916
1917 return GNUNET_YES;
1918}
1919
1920
1923 const struct
1926 shared_key)
1927{
1928 struct GNUNET_CRYPTO_AeadNonce iv;
1929
1930 GNUNET_assert ((message) && (key) && (shared_key) &&
1932
1934 &iv, sizeof (iv),
1937 key,
1938 sizeof (*key),
1941 {
1943 "Deriving initialization vector failed!\n");
1944 return GNUNET_NO;
1945 }
1946
1948 ,
1949 message->body.authorization.key,
1950 0,
1951 NULL,
1952 key,
1953 &iv,
1954 &message->body.authorization.mac,
1955 shared_key))
1956 {
1957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1958 return GNUNET_NO;
1959 }
1960
1961 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1962 {
1963 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1964 return GNUNET_NO;
1965 }
1966
1967 return GNUNET_YES;
1968}
1969
1970
1973{
1976
1977 GNUNET_assert (message);
1978
1979 timestamp = GNUNET_TIME_absolute_ntoh (message->header.timestamp);
1980
1981 switch (message->header.kind)
1982 {
1984 timeout = GNUNET_TIME_relative_ntoh (message->body.deletion.delay);
1985 break;
1987 timeout = GNUNET_TIME_relative_ntoh (message->body.announcement.timeout);
1988 break;
1990 timeout = GNUNET_TIME_relative_ntoh (message->body.appeal.timeout);
1991 break;
1993 timeout = GNUNET_TIME_relative_ntoh (message->body.group.timeout);
1994 break;
1995 default:
1997 break;
1998 }
1999
2001
2005
2006 return timeout;
2007}
2008
2009
2010struct GNUNET_MQ_Envelope*
2012 struct GNUNET_HashCode *hash,
2014{
2015 struct GNUNET_MessageHeader *header;
2016 uint16_t length, padded_length;
2017 struct GNUNET_MQ_Envelope *env;
2018 char *buffer;
2019
2020 GNUNET_assert (message);
2021
2023 "Packing message kind=%u and sender: %s\n",
2024 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2025
2026 length = get_message_size (message, GNUNET_YES);
2027 padded_length = calc_padded_length (length);
2028
2030 {
2031 env = GNUNET_MQ_msg_extra (header, padded_length,
2033 buffer = (char*) &(header[1]);
2034 }
2035 else
2036 {
2037 env = NULL;
2038 buffer = GNUNET_malloc (padded_length);
2039 }
2040
2041 encode_message (message, padded_length, buffer, GNUNET_YES);
2042
2043 if (hash)
2044 hash_message (message, length, buffer, hash);
2045
2047 GNUNET_free (buffer);
2048
2049 return env;
2050}
2051
2052
2055{
2056 GNUNET_assert (message);
2057
2058 switch (message->header.kind)
2059 {
2065 return GNUNET_YES;
2066 default:
2067 return GNUNET_NO;
2068 }
2069}
2070
2071
2074{
2075 GNUNET_assert (message);
2076
2077 if (GNUNET_YES == is_peer_message (message))
2078 return GNUNET_YES;
2079
2080 switch (message->header.kind)
2081 {
2083 return GNUNET_YES; // Reserved for connection handling only!
2085 return GNUNET_YES; // Reserved for member handling only!
2087 return GNUNET_YES; // Reserved for member handling only!
2089 return GNUNET_YES; // Reserved for member name handling only!
2091 return GNUNET_YES; // Reserved for member key handling only!
2093 return GNUNET_YES; // Reserved for connection handling only!
2095 return GNUNET_YES; // Reserved for member id handling only!
2097 return GNUNET_YES; // Reserved for connection handling only!
2099 return GNUNET_YES; // Reserved for peers only!
2101 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2103 return GNUNET_NO;
2105 return GNUNET_NO;
2107 return GNUNET_NO;
2109 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2111 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2113 return GNUNET_YES; // Reserved for connection handling only!
2115 return GNUNET_NO;
2117 return GNUNET_NO;
2119 return GNUNET_NO;
2121 return GNUNET_YES; // Reserved for subscription handling only!
2123 return GNUNET_NO;
2125 return GNUNET_YES; // Reserved for epoch and group key exchange!
2127 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2129 return GNUNET_YES; // Reserved for epoch key exchange!
2131 return GNUNET_YES; // Reserved for epoch and group key exchange!
2133 return GNUNET_YES; // Reserved for epoch and group key revoking!
2135 return GNUNET_YES; // Reserved for group key exchange!
2137 return GNUNET_YES; // Reserved for epoch and group key exchange!
2138 default:
2139 return GNUNET_SYSERR;
2140 }
2141}
2142
2143
2146{
2147 GNUNET_assert (message);
2148
2149 switch (message->header.kind)
2150 {
2152 return GNUNET_YES;
2154 return GNUNET_YES;
2156 return GNUNET_YES;
2157 default:
2158 return GNUNET_NO;
2159 }
2160}
2161
2162
2165{
2166 GNUNET_assert (message);
2167
2168 if (GNUNET_YES == is_peer_message (message))
2169 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2170
2171 switch (message->header.kind)
2172 {
2174 return GNUNET_SYSERR; // Reserved for connection handling only!
2176 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2178 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2180 return GNUNET_YES;
2182 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2184 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2186 return GNUNET_NO; // Reserved for member id handling only!
2188 return GNUNET_SYSERR; // Reserved for connection handling only!
2190 return GNUNET_SYSERR; // Reserved for peers only!
2192 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2194 return GNUNET_YES;
2196 return GNUNET_YES;
2198 return GNUNET_YES;
2200 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2202 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2204 return GNUNET_SYSERR; // Reserved for connection handling only!
2206 return GNUNET_YES;
2208 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2210 return GNUNET_YES;
2212 return GNUNET_YES;
2214 return GNUNET_YES;
2216 return GNUNET_NO; // Should only be used for implicit key exchange!
2218 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2220 return GNUNET_NO; // Should only be used for implicit key exchange!
2222 return GNUNET_NO; // Should only be used for implicit key exchange!
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!
2229 default:
2230 return GNUNET_SYSERR;
2231 }
2232}
2233
2234
2235const struct GNUNET_ShortHashCode*
2237{
2238 GNUNET_assert (message);
2239
2240 switch (message->header.kind)
2241 {
2243 return &(message->body.subscription.discourse);
2245 return &(message->body.talk.discourse);
2246 default:
2247 return NULL;
2248 }
2249}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static void sign_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
Definition gnunet-abd.c:675
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_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
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 @52 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
struct GNUNET_PILS_Operation * GNUNET_PILS_sign_by_peer_identity(struct GNUNET_PILS_Handle *handle, const struct GNUNET_CRYPTO_SignaturePurpose *purpose, GNUNET_PILS_SignResultCallback cb, void *cb_cls)
Sign data with the peer id.
Definition pils_api.c:528
void(* GNUNET_PILS_SignResultCallback)(void *cls, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig)
A handler/callback to be called for signatures.
#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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_decrypt(size_t ct_len, const unsigned char ct[ct_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, const struct GNUNET_CRYPTO_AeadMac *mac, void *pt)
Decrypt the given data using XChaCha20-Poly1305.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_aead_encrypt(size_t pt_len, const unsigned char pt[pt_len], size_t aad_len, const unsigned char aad[aad_len], const struct GNUNET_CRYPTO_AeadSecretKey *key, const struct GNUNET_CRYPTO_AeadNonce *nonce, void *ct, struct GNUNET_CRYPTO_AeadMac *mac)
Encrypt the given data using XChaCha20-Poly1305.
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.
@ 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:40
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)
#define GNUNET_CRYPTO_hkdf_gnunet(result, out_len, xts, xts_len, skm, skm_len,...)
A peculiar HKDF instantiation that tried to mimic Truncated NMAC.
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.
#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_kdf_arg_auto(d)
#define GNUNET_CRYPTO_blinded_key_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_BlindablePrivateKey.
#define GNUNET_CRYPTO_kdf_arg(d, s)
#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:87
#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)
void encode_message_signature(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes the signature of a given message into a buffer of a maximum length in bytes.
#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)
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 maximum 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 decrypt_secret_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
Decrypts a secret message using a given shared key and replaces its body and kind with the inner encr...
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_PackMode mode)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
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.
struct GNUNET_PILS_Operation * sign_message_by_peer(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, struct GNUNET_PILS_Handle *pils, const GNUNET_PILS_SignResultCallback sign_cb, void *cls)
Signs the hash of a message with the peer identity of a given pils service going into a callback with...
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.
void sign_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Signs the hash of a message with a given private key.
enum GNUNET_GenericReturnValue encrypt_secret_message(struct GNUNET_MESSENGER_Message *message, const union GNUNET_MESSENGER_EpochIdentifier *identifier, const struct GNUNET_CRYPTO_AeadSecretKey *key)
Encrypts a message using a given shared key from an announcement of an epoch and replaces its body an...
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
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)
enum GNUNET_GenericReturnValue extract_access_message_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_AeadSecretKey *shared_key)
Extracts the shared epoch or group key from an access message using the private ephemeral key from an...
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.
#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 extract_authorization_message_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key, struct GNUNET_CRYPTO_AeadSecretKey *shared_key)
Extracts the shared epoch or group key from an authorization message using a previously exchanged sha...
#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)
enum GNUNET_GenericReturnValue sign_message_by_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
Signs the message body via it's own hmac with a specific shared key.
uint32_t kind_t
#define min(x, y)
#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.
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key)
Verifies the hmac of a given message body with a specific shared key.
static enum GNUNET_GenericReturnValue calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_AeadSecretKey *key, struct GNUNET_HashCode *hmac)
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 maximum 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 ...
#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
#define GNUNET_MESSENGER_SALT_EPOCH_KEY
#define GNUNET_MESSENGER_SALT_ANNOUNCEMENT_KEY
#define GNUNET_MESSENGER_PADDING_LEVEL2
#define GNUNET_MESSENGER_PADDING_LEVEL1
#define GNUNET_MESSENGER_SALT_GROUP_KEY
type for session keys
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.
struct GNUNET_CRYPTO_AeadMac mac
The mac of the key.
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_AeadSecretKey)]
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.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
char * data
The data of the encrypted message.
struct GNUNET_CRYPTO_AeadMac mac
The mac of the encrypted message.
struct GNUNET_CRYPTO_AeadNonce iv
The IV of the secret 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.
A handle for the PILS service.
Definition pils_api.c:82
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.