GNUnet 0.26.2-106-g126384b46
 
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,
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.hmac));
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.hmac));
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
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),
1402 return GNUNET_NO;
1403
1404 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.announcement),
1405 sizeof (message->body.announcement)
1406 - sizeof (*hmac),
1407 hmac);
1408 return GNUNET_YES;
1411 &auth_key, sizeof (auth_key),
1414 key, sizeof (*key),
1416 return GNUNET_NO;
1417
1418 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.access),
1419 sizeof (message->body.access)
1420 - sizeof (*hmac),
1421 hmac);
1422 return GNUNET_YES;
1425 &auth_key, sizeof (auth_key),
1428 key, sizeof (*key),
1431 return GNUNET_NO;
1432
1433 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.revolution),
1434 sizeof (message->body.revolution)
1435 - sizeof (*hmac),
1436 hmac);
1437 return GNUNET_YES;
1440 &auth_key, sizeof (auth_key),
1443 key, sizeof (*key),
1446 return GNUNET_NO;
1447
1448 GNUNET_CRYPTO_hmac (&auth_key, &(message->body.authorization),
1449 sizeof (message->body.authorization)
1450 - sizeof (*hmac),
1451 hmac);
1452 return GNUNET_YES;
1453 default:
1454 return GNUNET_SYSERR;
1455 }
1456}
1457
1458
1462{
1463 struct GNUNET_HashCode *hmac;
1464
1465 GNUNET_assert ((message) && (key));
1466
1467 switch (message->header.kind)
1468 {
1470 hmac = &(message->body.announcement.hmac);
1471 break;
1473 hmac = &(message->body.access.hmac);
1474 break;
1476 hmac = &(message->body.revolution.hmac);
1477 break;
1479 hmac = &(message->body.authorization.hmac);
1480 break;
1481 default:
1482 hmac = NULL;
1483 break;
1484 }
1485
1486 if (! hmac)
1487 return GNUNET_SYSERR;
1488
1489 return calc_message_hmac (message, key, hmac);
1490}
1491
1492
1495 const struct GNUNET_HashCode *hash,
1497{
1498 struct GNUNET_MESSENGER_MessageSignature signature;
1499
1500 GNUNET_assert ((message) && (hash) && (key));
1501
1502 if (key->type != message->header.signature.type)
1503 return GNUNET_SYSERR;
1504
1506 signature.purpose.size = htonl (sizeof(signature));
1507
1508 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1509
1512 &(message->header.signature), key);
1513}
1514
1515
1518 const struct GNUNET_HashCode *hash,
1519 const struct GNUNET_PeerIdentity *identity)
1520{
1521 struct GNUNET_MESSENGER_MessageSignature signature;
1522
1523 GNUNET_assert ((message) && (hash) && (identity));
1524
1525 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1526 return GNUNET_SYSERR;
1527
1529 signature.purpose.size = htonl (sizeof(signature));
1530
1531 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1532
1535 &(message->header.signature.
1536 eddsa_signature), identity);
1537}
1538
1539
1543{
1544 const struct GNUNET_HashCode *msg_hmac;
1545 struct GNUNET_HashCode hmac;
1546
1547 GNUNET_assert ((message) && (key));
1548
1549 switch (message->header.kind)
1550 {
1552 msg_hmac = &(message->body.announcement.hmac);
1553 break;
1555 msg_hmac = &(message->body.access.hmac);
1556 break;
1558 msg_hmac = &(message->body.revolution.hmac);
1559 break;
1561 msg_hmac = &(message->body.authorization.hmac);
1562 break;
1563 default:
1564 msg_hmac = NULL;
1565 break;
1566 }
1567
1568 if (! msg_hmac)
1569 return GNUNET_SYSERR;
1570
1571 if (GNUNET_YES != calc_message_hmac (message, key, &hmac))
1572 return GNUNET_SYSERR;
1573
1574 if (0 == GNUNET_CRYPTO_hash_cmp (&hmac, msg_hmac))
1575 return GNUNET_OK;
1576
1577 return GNUNET_SYSERR;
1578}
1579
1580
1583 const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
1584{
1586 struct GNUNET_MESSENGER_ShortMessage shortened;
1587 uint16_t length, padded_length, encoded_length;
1588 uint8_t *data;
1589
1590 GNUNET_assert ((message) && (hpke_key));
1591
1592 if (GNUNET_YES == is_service_message (message))
1593 return GNUNET_NO;
1594
1595 fold_short_message (message, &shortened);
1596
1597 length = get_short_message_size (&shortened, GNUNET_YES);
1598 padded_length = calc_padded_length (length + encryption_overhead);
1599
1600 GNUNET_assert (padded_length >= length + encryption_overhead);
1601
1603 message->body.privacy.data = GNUNET_malloc (padded_length);
1604 message->body.privacy.length = padded_length;
1605
1606 encoded_length = (padded_length - encryption_overhead);
1607
1608 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1609
1610 result = GNUNET_NO;
1611 data = GNUNET_malloc (encoded_length);
1612
1613 encode_short_message (&shortened, encoded_length, (char *) data);
1614
1616 (const uint8_t*)
1617 "messenger",
1618 strlen ("messenger"),
1619 NULL, 0,
1620 (const uint8_t*) data,
1621 encoded_length,
1622 (uint8_t*) message->body.
1623 privacy.data,
1624 NULL))
1625 {
1626 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1627
1628 unfold_short_message (&shortened, message);
1629 goto cleanup;
1630 }
1631
1632 destroy_message_body (shortened.kind, &(shortened.body));
1634
1635cleanup:
1636 GNUNET_free (data);
1637 return result;
1638}
1639
1640
1643 const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
1644{
1646 uint16_t padded_length, encoded_length;
1647 uint8_t *data;
1648
1649 GNUNET_assert ((message) && (hpke_key) &&
1651
1652 padded_length = message->body.privacy.length;
1653
1654 if (padded_length < encryption_overhead)
1655 {
1657 "Message length too short to decrypt!\n");
1658
1659 return GNUNET_NO;
1660 }
1661
1662 encoded_length = (padded_length - encryption_overhead);
1663
1664 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1665
1666 result = GNUNET_NO;
1667 data = GNUNET_malloc (encoded_length);
1668
1669 if (GNUNET_OK !=
1671 (uint8_t*) "messenger",
1672 strlen ("messenger"),
1673 NULL, 0,
1674 (uint8_t*) message->body.privacy.data,
1675 padded_length,
1676 (uint8_t*) data,
1677 NULL))
1678 {
1679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1680
1681 goto cleanup;
1682 }
1683
1684 {
1685 struct GNUNET_MESSENGER_ShortMessage shortened;
1686 if (GNUNET_YES != decode_short_message (&shortened,
1687 encoded_length,
1688 (char*) data))
1689 {
1691 "Decoding decrypted message failed!\n");
1692
1693 goto cleanup;
1694 }
1695
1696 unfold_short_message (&shortened, message);
1698 }
1699
1700cleanup:
1701 GNUNET_free (data);
1702 return result;
1703}
1704
1705
1709{
1710 struct GNUNET_MESSENGER_Message *transcript;
1711
1712 GNUNET_assert ((message) && (key));
1713
1714 if (GNUNET_YES == is_service_message (message))
1715 return NULL;
1716
1718
1719 if (! transcript)
1720 {
1721 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1722 return NULL;
1723 }
1724
1725 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1726 sizeof(transcript->body.transcript.key));
1727
1728 {
1729 struct GNUNET_MESSENGER_ShortMessage shortened;
1730 uint16_t data_length;
1731
1732 fold_short_message (message, &shortened);
1733
1734 data_length = get_short_message_size (&shortened, GNUNET_YES);
1735
1736 transcript->body.transcript.data = GNUNET_malloc (data_length);
1737 transcript->body.transcript.length = data_length;
1738
1739 encode_short_message (&shortened, data_length,
1740 transcript->body.transcript.data);
1741 }
1742
1743 return transcript;
1744}
1745
1746
1749 const union GNUNET_MESSENGER_EpochIdentifier *identifier
1750 ,
1752{
1754 struct GNUNET_MESSENGER_ShortMessage shortened;
1755 uint16_t length, padded_length;
1756 uint8_t *data;
1757
1758 GNUNET_assert ((message) && (identifier) && (key));
1759
1760 fold_short_message (message, &shortened);
1761
1762 length = get_short_message_size (&shortened, GNUNET_YES);
1763 padded_length = calc_padded_length (length + 0);
1764
1765 GNUNET_assert (padded_length >= length + 0);
1766
1768
1769 GNUNET_memcpy (&(message->body.secret.identifier), identifier,
1770 sizeof (message->body.secret.identifier));
1771
1773 &(message->body.secret.iv),
1775
1776 message->body.secret.data = GNUNET_malloc (padded_length);
1777 message->body.secret.length = padded_length;
1778
1779 result = GNUNET_NO;
1780 data = GNUNET_malloc (padded_length);
1781
1782 encode_short_message (&shortened, padded_length, (char *) data);
1783
1784 {
1786
1788 &iv, sizeof (iv),
1791 key, sizeof (*key),
1793 {
1794 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
1795 unfold_short_message (&shortened, message);
1796 goto cleanup;
1797 }
1798
1799 if (-1 == GNUNET_CRYPTO_symmetric_encrypt (data, padded_length, key,
1800 &iv, message->body.secret.data))
1801 {
1802 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1803 unfold_short_message (&shortened, message);
1804 goto cleanup;
1805 }
1806 }
1807
1808 {
1809 struct GNUNET_CRYPTO_AuthKey auth_key;
1810
1812 &auth_key, sizeof (auth_key),
1815 key, sizeof (*key),
1817 {
1818 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving authentication key failed!\n");
1819 unfold_short_message (&shortened, message);
1820 goto cleanup;
1821 }
1822
1823 GNUNET_CRYPTO_hmac (&auth_key, message->body.secret.data, padded_length,
1824 &(message->body.secret.hmac));
1825 }
1826
1827 destroy_message_body (shortened.kind, &(shortened.body));
1829
1830cleanup:
1831 GNUNET_free (data);
1832 return result;
1833}
1834
1835
1839{
1841 uint16_t padded_length;
1842 uint8_t *data;
1843
1844 GNUNET_assert ((message) && (key) &&
1846
1847 padded_length = message->body.secret.length;
1848
1849 {
1850 struct GNUNET_CRYPTO_AuthKey auth_key;
1851 struct GNUNET_HashCode hmac;
1852
1854 &auth_key, sizeof (auth_key),
1857 key, sizeof (*key),
1859 {
1860 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving authentication key failed!\n");
1861 return GNUNET_NO;
1862 }
1863
1864 GNUNET_CRYPTO_hmac (&auth_key, message->body.secret.data, padded_length,
1865 &hmac);
1866
1867 if (0 != GNUNET_CRYPTO_hash_cmp (&(message->body.secret.hmac), &hmac))
1868 {
1870 "Decrypted message does not match HMAC!\n");
1871 return GNUNET_NO;
1872 }
1873 }
1874
1875 result = GNUNET_NO;
1876 data = GNUNET_malloc (padded_length);
1877
1878 {
1880
1882 &iv, sizeof (iv),
1885 key,
1886 sizeof (*key),
1888 {
1889 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
1890 goto cleanup;
1891 }
1892
1893 if (-1 == GNUNET_CRYPTO_symmetric_decrypt (message->body.secret.data,
1894 padded_length,
1895 key, &iv, data))
1896 {
1897 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1898 goto cleanup;
1899 }
1900 }
1901
1902 {
1903 struct GNUNET_MESSENGER_ShortMessage shortened;
1904 if (GNUNET_YES != decode_short_message (&shortened,
1905 padded_length,
1906 (char*) data))
1907 {
1909 "Decoding decrypted message failed!\n");
1910
1911 goto cleanup;
1912 }
1913
1914 unfold_short_message (&shortened, message);
1916 }
1917
1918cleanup:
1919 GNUNET_free (data);
1920 return result;
1921}
1922
1923
1926{
1927 uint16_t data_length;
1928 struct GNUNET_MESSENGER_ShortMessage shortened;
1929
1930 GNUNET_assert ((message) &&
1932
1933 data_length = message->body.transcript.length;
1934
1935 if (GNUNET_YES != decode_short_message (&shortened,
1936 data_length,
1937 message->body.transcript.data))
1938 {
1940 "Decoding decrypted message failed!\n");
1941
1942 return GNUNET_NO;
1943 }
1944
1945 unfold_short_message (&shortened, message);
1946 return GNUNET_YES;
1947}
1948
1949
1952 const struct GNUNET_CRYPTO_HpkePrivateKey *key,
1953 struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key
1954 )
1955{
1956 GNUNET_assert ((message) && (key) && (shared_key) &&
1958
1959 if (GNUNET_OK !=
1961 (uint8_t*) "messenger",
1962 strlen ("messenger"),
1963 NULL, 0,
1964 (uint8_t*) message->body.access.key,
1966 (uint8_t*) shared_key,
1967 NULL))
1968 {
1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
1970 return GNUNET_NO;
1971 }
1972
1973 if (GNUNET_OK != verify_message_by_key (message, shared_key))
1974 {
1975 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
1976 return GNUNET_NO;
1977 }
1978
1979 return GNUNET_YES;
1980}
1981
1982
1985 const struct
1988 shared_key)
1989{
1991
1992 GNUNET_assert ((message) && (key) && (shared_key) &&
1994
1996 &iv, sizeof (iv),
1999 key,
2000 sizeof (*key),
2003 {
2004 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deriving initialization vector failed!\n");
2005 return GNUNET_NO;
2006 }
2007
2010 key,
2011 &iv,
2012 shared_key))
2013 {
2014 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting shared key failed!\n");
2015 return GNUNET_NO;
2016 }
2017
2018 if (GNUNET_OK != verify_message_by_key (message, shared_key))
2019 {
2020 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Shared key mismatches HMAC!\n");
2021 return GNUNET_NO;
2022 }
2023
2024 return GNUNET_YES;
2025}
2026
2027
2030{
2033
2034 GNUNET_assert (message);
2035
2036 timestamp = GNUNET_TIME_absolute_ntoh (message->header.timestamp);
2037
2038 switch (message->header.kind)
2039 {
2041 timeout = GNUNET_TIME_relative_ntoh (message->body.deletion.delay);
2042 break;
2044 timeout = GNUNET_TIME_relative_ntoh (message->body.announcement.timeout);
2045 break;
2047 timeout = GNUNET_TIME_relative_ntoh (message->body.appeal.timeout);
2048 break;
2050 timeout = GNUNET_TIME_relative_ntoh (message->body.group.timeout);
2051 break;
2052 default:
2054 break;
2055 }
2056
2058
2062
2063 return timeout;
2064}
2065
2066
2067struct GNUNET_MQ_Envelope*
2069 struct GNUNET_HashCode *hash,
2071{
2072 struct GNUNET_MessageHeader *header;
2073 uint16_t length, padded_length;
2074 struct GNUNET_MQ_Envelope *env;
2075 char *buffer;
2076
2077 GNUNET_assert (message);
2078
2080 "Packing message kind=%u and sender: %s\n",
2081 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
2082
2083 length = get_message_size (message, GNUNET_YES);
2084 padded_length = calc_padded_length (length);
2085
2087 {
2088 env = GNUNET_MQ_msg_extra (header, padded_length,
2090 buffer = (char*) &(header[1]);
2091 }
2092 else
2093 {
2094 env = NULL;
2095 buffer = GNUNET_malloc (padded_length);
2096 }
2097
2098 encode_message (message, padded_length, buffer, GNUNET_YES);
2099
2100 if (hash)
2101 hash_message (message, length, buffer, hash);
2102
2104 GNUNET_free (buffer);
2105
2106 return env;
2107}
2108
2109
2112{
2113 GNUNET_assert (message);
2114
2115 switch (message->header.kind)
2116 {
2122 return GNUNET_YES;
2123 default:
2124 return GNUNET_NO;
2125 }
2126}
2127
2128
2131{
2132 GNUNET_assert (message);
2133
2134 if (GNUNET_YES == is_peer_message (message))
2135 return GNUNET_YES;
2136
2137 switch (message->header.kind)
2138 {
2140 return GNUNET_YES; // Reserved for connection handling only!
2142 return GNUNET_YES; // Reserved for member handling only!
2144 return GNUNET_YES; // Reserved for member handling only!
2146 return GNUNET_YES; // Reserved for member name handling only!
2148 return GNUNET_YES; // Reserved for member key handling only!
2150 return GNUNET_YES; // Reserved for connection handling only!
2152 return GNUNET_YES; // Reserved for member id handling only!
2154 return GNUNET_YES; // Reserved for connection handling only!
2156 return GNUNET_YES; // Reserved for peers only!
2158 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
2160 return GNUNET_NO;
2162 return GNUNET_NO;
2164 return GNUNET_NO;
2166 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2168 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
2170 return GNUNET_YES; // Reserved for connection handling only!
2172 return GNUNET_NO;
2174 return GNUNET_NO;
2176 return GNUNET_NO;
2178 return GNUNET_YES; // Reserved for subscription handling only!
2180 return GNUNET_NO;
2182 return GNUNET_YES; // Reserved for epoch and group key exchange!
2184 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
2186 return GNUNET_YES; // Reserved for epoch key exchange!
2188 return GNUNET_YES; // Reserved for epoch and group key exchange!
2190 return GNUNET_YES; // Reserved for epoch and group key revoking!
2192 return GNUNET_YES; // Reserved for group key exchange!
2194 return GNUNET_YES; // Reserved for epoch and group key exchange!
2195 default:
2196 return GNUNET_SYSERR;
2197 }
2198}
2199
2200
2203{
2204 GNUNET_assert (message);
2205
2206 switch (message->header.kind)
2207 {
2209 return GNUNET_YES;
2211 return GNUNET_YES;
2213 return GNUNET_YES;
2214 default:
2215 return GNUNET_NO;
2216 }
2217}
2218
2219
2222{
2223 GNUNET_assert (message);
2224
2225 if (GNUNET_YES == is_peer_message (message))
2226 return GNUNET_SYSERR; // Requires signature of peer rather than member!
2227
2228 switch (message->header.kind)
2229 {
2231 return GNUNET_SYSERR; // Reserved for connection handling only!
2233 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
2235 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
2237 return GNUNET_YES;
2239 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
2241 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
2243 return GNUNET_NO; // Reserved for member id handling only!
2245 return GNUNET_SYSERR; // Reserved for connection handling only!
2247 return GNUNET_SYSERR; // Reserved for peers only!
2249 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
2251 return GNUNET_YES;
2253 return GNUNET_YES;
2255 return GNUNET_YES;
2257 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2259 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
2261 return GNUNET_SYSERR; // Reserved for connection handling only!
2263 return GNUNET_YES;
2265 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
2267 return GNUNET_YES;
2269 return GNUNET_YES;
2271 return GNUNET_YES;
2273 return GNUNET_NO; // Should only be used for implicit key exchange!
2275 return GNUNET_NO; // Should only be used for implicit forward secrecy!
2277 return GNUNET_NO; // Should only be used for implicit key exchange!
2279 return GNUNET_NO; // Should only be used for implicit key exchange!
2281 return GNUNET_NO; // Should only be used for implicit key exchange!
2283 return GNUNET_NO; // Should only be used for implicit key exchange!
2285 return GNUNET_NO; // Should only be used for implicit key exchange!
2286 default:
2287 return GNUNET_SYSERR;
2288 }
2289}
2290
2291
2292const struct GNUNET_ShortHashCode*
2294{
2295 GNUNET_assert (message);
2296
2297 switch (message->header.kind)
2298 {
2300 return &(message->body.subscription.discourse);
2302 return &(message->body.talk.discourse);
2303 default:
2304 return NULL;
2305 }
2306}
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.
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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_SignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
Verify a given signature with a peer's identity.
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
#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:85
#define GNUNET_htobe32(x)
#define GNUNET_PACKED
gcc-ism to get packed structs.
ssize_t GNUNET_CRYPTO_read_blinded_key_signature_from_buffer(struct GNUNET_CRYPTO_BlindableKeySignature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_BlindableKeySignature from a compact buffer.
#define GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSENGER_AUTHORIZATION_KEY_BYTES
#define GNUNET_MESSENGER_ACCESS_KEY_BYTES
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
#define GNUNET_MESSENGER_EPOCH_NONCE_BYTES
#define GNUNET_MESSENGER_SECRET_IV_BYTES
#define GNUNET_MESSENGER_KIND_MAX
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_AUTHORIZATION
The authorization kind.
@ GNUNET_MESSENGER_KIND_ANNOUNCEMENT
The announcement kind.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_APPEAL
The appeal kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_ACCESS
The access kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_REVOLUTION
The revolution kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_SECRET
The secret kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBTION
The subscription kind.
@ GNUNET_MESSENGER_KIND_DELETION
The deletion kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_GROUP
The group kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_zero_(void)
Return relative time of 0ms.
Definition time.c:133
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition time.c:626
struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_minute_(void)
Return relative time of 1 minute.
Definition time.c:178
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition time.c:452
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePublicKey *hpke_key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
#define decode_step(src, offset, dst)
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)
enum GNUNET_GenericReturnValue extract_access_message_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Extracts the shared epoch or group key from an access message using the private ephemeral key from an...
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a 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 is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
enum GNUNET_GenericReturnValue verify_message_by_key(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key)
Verifies the hmac of a given message body with a specific shared key.
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 extract_authorization_message_key(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *key, struct GNUNET_CRYPTO_SymmetricSessionKey *shared_key)
Extracts the shared epoch or group key from an authorization message using a previously exchanged sha...
enum GNUNET_GenericReturnValue decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_HpkePrivateKey *hpke_key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
const uint16_t encryption_overhead
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 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.
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)
#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 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)
#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.
static enum GNUNET_GenericReturnValue calc_message_hmac(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_SymmetricSessionKey *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 ...
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_SALT_SECRET_KEY
#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_SECRET_IV
#define GNUNET_MESSENGER_SALT_GROUP_KEY
type for (message) authentication keys
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
A public key used for decryption.
A public key used for encryption.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
A 512-bit hashcode.
struct GNUNET_HashCode hmac
The hmac of the access.
struct GNUNET_HashCode event
The hash of the linked announcement or group message event.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)+16+sizeof(struct GNUNET_CRYPTO_HpkeEncapsulation)]
The encrypted group or epoch key.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the announcement.
struct GNUNET_HashCode hmac
The hmac of the announcement.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to appeal access.
struct GNUNET_CRYPTO_EcdhePublicKey key
The public key to receive access.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the appeal.
struct GNUNET_HashCode event
The hash of the linked announcement message event.
struct GNUNET_HashCode event
The hash of the linked group message event.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode hmac
The hmac of the authorization.
uint8_t key[sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey)]
The encrypted group or epoch key.
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessageAnnouncement announcement
struct GNUNET_MESSENGER_MessageGroup group
struct GNUNET_MESSENGER_MessageSecret secret
struct GNUNET_MESSENGER_MessageDeletion deletion
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageText text
struct GNUNET_MESSENGER_MessageRequest request
struct GNUNET_MESSENGER_MessageMerge merge
struct GNUNET_MESSENGER_MessageId id
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageLeave leave
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_MESSENGER_MessageRevolution revolution
struct GNUNET_MESSENGER_MessageTalk talk
struct GNUNET_MESSENGER_MessageFile file
struct GNUNET_MESSENGER_MessageTag tag
struct GNUNET_MESSENGER_MessageKey key
struct GNUNET_MESSENGER_MessageInvite invite
struct GNUNET_MESSENGER_MessageAccess access
struct GNUNET_MESSENGER_MessageSubscribtion subscription
struct GNUNET_MESSENGER_MessageAuthorization authorization
struct GNUNET_MESSENGER_MessageAppeal appeal
struct GNUNET_MESSENGER_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageTicket ticket
struct GNUNET_MESSENGER_MessageInfo info
uint32_t amount
The amount of connections of a peer.
uint32_t flags
The flags about the connections of a peer.
struct GNUNET_HashCode hash
The hash of the message to delete.
struct GNUNET_TIME_RelativeNBO delay
The delay of the delete operation to get processed.
char * uri
The uri of the encrypted file.
struct GNUNET_HashCode hash
The hash of the original file.
struct GNUNET_CRYPTO_SymmetricSessionKey key
The symmetric key to decrypt the file.
char name[NAME_MAX]
The name of the original file.
struct GNUNET_TIME_RelativeNBO timeout
The timeout of the group formation.
struct GNUNET_HashCode initiator
The hash of the initiator group announcement.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the group in an epoch.
struct GNUNET_HashCode partner
The hash of the partner group announcement.
The header of a GNUNET_MESSENGER_Message.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
struct GNUNET_CRYPTO_BlindableKeySignature signature
The signature of the senders private key.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
uint32_t messenger_version
The version of GNUnet Messenger API.
union GNUNET_MESSENGER_RoomKey key
The hash identifying the port of the room.
struct GNUNET_PeerIdentity door
The peer identity of an open door to a room.
struct GNUNET_CRYPTO_BlindablePublicKey key
The senders blindable public key to verify its signatures.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The senders HPKE public key to encrypt private messages with.
struct GNUNET_CRYPTO_BlindablePublicKey key
The new blindable public key which replaces the current senders public key.
struct GNUNET_CRYPTO_HpkePublicKey hpke_key
The new HPKE public key which replaces the current senders HPKE public key.
struct GNUNET_HashCode epoch
The previous epoch the message was sent from.
struct GNUNET_HashCode previous
The hash of a second previous message.
struct GNUNET_HashCode epochs[2]
The previous epochs the message was sent from.
struct GNUNET_PeerIdentity peer
The peer identity of a disconnected door to a room.
char * name
The new name which replaces the current senders name.
struct GNUNET_PeerIdentity peer
The peer identity of the sender opening a room.
uint16_t length
The length of the encrypted message.
char * data
The data of the encrypted message.
struct GNUNET_HashCode hash
The hash of the requested message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
union GNUNET_MESSENGER_EpochNonce nonce
The nonce of the revolution.
struct GNUNET_HashCode hmac
The hmac of the revolution.
uint8_t iv[sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector)]
The IV of the secret message.
union GNUNET_MESSENGER_EpochIdentifier identifier
The identifier of the announcement in an epoch.
char * data
The data of the encrypted message.
struct GNUNET_HashCode hmac
The hmac of the encrypted message.
uint16_t length
The length of the encrypted message.
struct GNUNET_CRYPTO_SignaturePurpose purpose
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscription.
struct GNUNET_HashCode hash
The hash of the message to tag.
uint16_t length
The length of the talk message data.
char * data
The data of the talk message.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
char * identifier
The identifier of a ticket.
uint16_t length
The length of the transcribed message.
struct GNUNET_HashCode hash
The hash of the original message.
struct GNUNET_CRYPTO_BlindablePublicKey key
The key from the recipient of the original message.
char * data
The data of the transcribed message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind
Header for all communications.
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.