GNUnet 0.22.2
messenger_api_message.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
27
28#include "gnunet_common.h"
30#include "gnunet_signatures.h"
31
32const uint16_t encryption_overhead =
34
36{
39};
40
42{
45};
46
49{
50 struct GNUNET_MESSENGER_Message *message;
51
52 message = GNUNET_new (struct GNUNET_MESSENGER_Message);
53 message->header.kind = kind;
54
55 switch (message->header.kind)
56 {
58 message->body.name.name = NULL;
59 break;
61 message->body.text.text = NULL;
62 break;
64 message->body.file.uri = NULL;
65 break;
67 message->body.privacy.length = 0;
68 message->body.privacy.data = NULL;
69 break;
71 message->body.ticket.identifier = NULL;
72 break;
74 message->body.transcript.length = 0;
75 message->body.transcript.data = NULL;
76 break;
78 message->body.tag.tag = NULL;
79 break;
81 message->body.talk.length = 0;
82 message->body.talk.data = NULL;
83 break;
84 default:
85 break;
86 }
87
88 return message;
89}
90
91
94{
95 struct GNUNET_MESSENGER_Message *copy;
96
97 GNUNET_assert (message);
98
100 GNUNET_memcpy (copy, message, sizeof(struct GNUNET_MESSENGER_Message));
101
102 switch (message->header.kind)
103 {
105 copy->body.name.name = message->body.name.name? GNUNET_strdup (
106 message->body.name.name) : NULL;
107 break;
109 copy->body.text.text = message->body.text.text? GNUNET_strdup (
110 message->body.text.text) : NULL;
111 break;
113 copy->body.file.uri = message->body.file.uri? GNUNET_strdup (
114 message->body.file.uri) : NULL;
115 break;
118 copy->body.privacy.length) : NULL;
119
120 if (copy->body.privacy.data)
121 GNUNET_memcpy (copy->body.privacy.data, message->body.privacy.data,
122 copy->body.privacy.length);
123
124 break;
126 copy->body.ticket.identifier = message->body.ticket.identifier?
128 message->body.ticket.identifier) : NULL;
129 break;
132 copy->body.transcript.length) : NULL;
133
134 if (copy->body.transcript.data)
136 copy->body.transcript.length);
137
138 break;
140 copy->body.tag.tag = message->body.tag.tag? GNUNET_strdup (
141 message->body.tag.tag) : NULL;
142 break;
144 copy->body.talk.data = copy->body.talk.length ? GNUNET_malloc (
145 copy->body.talk.length) : NULL;
146
147 if (copy->body.talk.data)
148 GNUNET_memcpy (copy->body.talk.data, message->body.talk.data,
149 copy->body.talk.length);
150
151 break;
152 default:
153 break;
154 }
155
156 return copy;
157}
158
159
160void
163{
165
166 GNUNET_assert ((message) && (header));
167
168 kind = message->header.kind;
169
170 GNUNET_memcpy (&(message->header), header,
171 sizeof(struct GNUNET_MESSENGER_MessageHeader));
172
173 message->header.kind = kind;
174}
175
176
177static void
180{
182
183 switch (kind)
184 {
186 if (body->name.name)
188 break;
190 if (body->text.text)
192 break;
194 if (body->file.uri)
196 break;
198 if (body->privacy.data)
200 break;
204 break;
206 if (body->transcript.data)
208 break;
210 if (body->tag.tag)
212 break;
214 if (body->talk.data)
216 break;
217 default:
218 break;
219 }
220}
221
222
223void
225{
226 GNUNET_assert (message);
227
228 destroy_message_body (message->header.kind, &(message->body));
229}
230
231
232void
234{
235 GNUNET_assert (message);
236
237 destroy_message_body (message->header.kind, &(message->body));
238
239 GNUNET_free (message);
240}
241
242
245{
246 GNUNET_assert (message);
247
248 if ((GNUNET_MESSENGER_KIND_JOIN == message->header.kind) ||
250 (GNUNET_MESSENGER_KIND_NAME == message->header.kind) ||
251 (GNUNET_MESSENGER_KIND_KEY == message->header.kind) ||
253 return GNUNET_YES;
254 else
255 return GNUNET_NO;
256}
257
258
259static void
261 struct GNUNET_MESSENGER_ShortMessage *shortened)
262{
263 shortened->kind = message->header.kind;
264
265 GNUNET_memcpy (&(shortened->body), &(message->body), sizeof(struct
267}
268
269
270static void
272 struct GNUNET_MESSENGER_Message *message)
273{
274 destroy_message_body (message->header.kind, &(message->body));
275
276 message->header.kind = shortened->kind;
277
278 GNUNET_memcpy (&(message->body), &(shortened->body),
279 sizeof(struct GNUNET_MESSENGER_MessageBody));
280}
281
282
283#define member_size(type, member) sizeof(((type*) NULL)->member)
284
285static uint16_t
287{
288 uint16_t length;
289
290 length = 0;
291
292 switch (kind)
293 {
295 length += member_size (struct GNUNET_MESSENGER_Message,
297 break;
300 break;
302 length += member_size (struct GNUNET_MESSENGER_Message, body.id.id);
303 break;
306 break;
308 length += member_size (struct GNUNET_MESSENGER_Message,
310 break;
313 break;
317 break;
322 break;
325 break;
328 length += member_size (struct GNUNET_MESSENGER_Message,
330 break;
332 length += member_size (struct GNUNET_MESSENGER_Message,
334 length += member_size (struct GNUNET_MESSENGER_Message,
336 break;
338 length += member_size (struct GNUNET_MESSENGER_Message,
340 break;
343 break;
345 length += member_size (struct GNUNET_MESSENGER_Message,
347 length += member_size (struct GNUNET_MESSENGER_Message,
349 length += member_size (struct GNUNET_MESSENGER_Message,
351 break;
353 length += member_size (struct GNUNET_MESSENGER_Message,
355 break;
356 default:
357 break;
358 }
359
360 return length;
361}
362
363
364typedef uint32_t kind_t;
365
366uint16_t
368 enum GNUNET_GenericReturnValue include_header)
369{
370 uint16_t length;
371
372 length = 0;
373
374 if (GNUNET_YES == include_header)
375 {
379 }
380
381 length += sizeof(kind_t);
382
383 return length + get_message_body_kind_size (kind);
384}
385
386
387static uint16_t
390{
391 uint16_t length;
392
393 length = 0;
394
395 switch (kind)
396 {
399 break;
401 length += (body->name.name ? strlen (body->name.name) : 0);
402 break;
405 break;
407 length += (body->text.text ? strlen (body->text.text) : 0);
408 break;
410 length += (body->file.uri ? strlen (body->file.uri) : 0);
411 break;
413 length += body->privacy.length;
414 break;
416 length += (body->ticket.identifier ? strlen (body->ticket.identifier) : 0);
417 break;
420 length += body->transcript.length;
421 break;
423 length += (body->tag.tag ? strlen (body->tag.tag) : 0);
424 break;
426 length += body->talk.length;
427 break;
428 default:
429 break;
430 }
431
432 return length;
433}
434
435
436uint16_t
438 enum GNUNET_GenericReturnValue include_header)
439{
440 uint16_t length;
441
442 GNUNET_assert (message);
443
444 length = 0;
445
446 if (GNUNET_YES == include_header)
448 &(message->header.signature));
449
450 length += get_message_kind_size (message->header.kind, include_header);
451 length += get_message_body_size (message->header.kind, &(message->body));
452
453 return length;
454}
455
456
457static uint16_t
459 enum GNUNET_GenericReturnValue include_body)
460{
461 uint16_t minimum_size;
462
463 minimum_size = sizeof(struct GNUNET_HashCode) + sizeof(kind_t);
464
465 if (message)
466 return minimum_size + get_message_body_kind_size (message->kind)
467 + (include_body == GNUNET_YES?
468 get_message_body_size (message->kind, &(message->body)) : 0);
469 else
470 return minimum_size;
471}
472
473
474static uint16_t
476{
477 uint16_t padding;
478 uint16_t kind_size;
479
480 padding = 0;
481
482 for (unsigned int i = 0; i <= GNUNET_MESSENGER_KIND_MAX; i++)
483 {
485 GNUNET_YES);
486
487 if (kind_size > padding)
488 padding = kind_size;
489 }
490
491 return padding + GNUNET_MESSENGER_PADDING_MIN;
492}
493
494
495#define max(x, y) (x > y? x : y)
496
497static uint16_t
498calc_padded_length (uint16_t length)
499{
500 static uint16_t usual_padding = 0;
501 uint16_t padded_length;
502
503 if (! usual_padding)
504 usual_padding = calc_usual_padding ();
505
506 padded_length = max (
508 usual_padding
509 );
510
511 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL0)
513
514 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL1)
516
517 if (padded_length <= GNUNET_MESSENGER_PADDING_LEVEL2)
519
521
522}
523
524
525#define min(x, y) (x < y? x : y)
526
527#define encode_step_ext(dst, offset, src, size) do { \
528 GNUNET_memcpy (dst + offset, src, size); \
529 offset += size; \
530} while (0)
531
532#define encode_step(dst, offset, src) do { \
533 encode_step_ext (dst, offset, src, sizeof(*src)); \
534} while (0)
535
536#define encode_step_key(dst, offset, src, length) do { \
537 ssize_t result = GNUNET_CRYPTO_write_public_key_to_buffer ( \
538 src, dst + offset, length - offset \
539 ); \
540 if (result < 0) \
541 GNUNET_break (0); \
542 else \
543 offset += result; \
544} while (0)
545
546#define encode_step_signature(dst, offset, src, length) do { \
547 ssize_t result = GNUNET_CRYPTO_write_signature_to_buffer ( \
548 src, dst + offset, length - offset \
549 ); \
550 if (result < 0) \
551 GNUNET_break (0); \
552 else \
553 offset += result; \
554} while (0)
555
556static void
558 const struct GNUNET_MESSENGER_MessageBody *body,
559 uint16_t length,
560 char *buffer,
561 uint16_t offset)
562{
563 uint32_t value0, value1;
564
565 GNUNET_assert ((body) && (buffer));
566
567 switch (kind)
568 {
570 value0 = GNUNET_htobe32 (body->info.messenger_version);
571
572 encode_step (buffer, offset, &value0);
573 break;
575 encode_step_key (buffer, offset, &(body->join.key), length);
576 break;
578 break;
580 if (body->name.name)
581 encode_step_ext (buffer, offset, body->name.name, min (length - offset,
582 strlen (
583 body->name.name))
584 );
585 break;
587 encode_step_key (buffer, offset, &(body->key.key), length);
588 break;
590 encode_step (buffer, offset, &(body->peer.peer));
591 break;
593 encode_step (buffer, offset, &(body->id.id));
594 break;
596 encode_step (buffer, offset, &(body->miss.peer));
597 break;
599 encode_step (buffer, offset, &(body->merge.previous));
600 break;
602 encode_step (buffer, offset, &(body->request.hash));
603 break;
605 encode_step (buffer, offset, &(body->invite.door));
606 encode_step (buffer, offset, &(body->invite.key));
607 break;
609 if (body->text.text)
610 encode_step_ext (buffer, offset, body->text.text, min (length - offset,
611 strlen (
612 body->text.text))
613 );
614 break;
616 encode_step (buffer, offset, &(body->file.key));
617 encode_step (buffer, offset, &(body->file.hash));
618 encode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
619 if (body->file.uri)
620 encode_step_ext (buffer, offset, body->file.uri, min (length - offset,
621 strlen (
622 body->file.uri)));
623 break;
625 encode_step (buffer, offset, &(body->privacy.key));
626
627 if (body->privacy.data)
628 encode_step_ext (buffer, offset, body->privacy.data, min (length - offset,
629 body->privacy.
630 length));
631 break;
633 encode_step (buffer, offset, &(body->deletion.hash));
634 encode_step (buffer, offset, &(body->deletion.delay));
635 break;
637 value0 = GNUNET_htobe32 (body->connection.amount);
638 value1 = GNUNET_htobe32 (body->connection.flags);
639
640 encode_step (buffer, offset, &value0);
641 encode_step (buffer, offset, &value1);
642 break;
644 encode_step_ext (buffer, offset, body->ticket.identifier,
645 min (length - offset, strlen (body->ticket.identifier)));
646 break;
648 encode_step (buffer, offset, &(body->transcript.hash));
649 encode_step_key (buffer, offset, &(body->transcript.key), length);
650
651 if (body->transcript.data)
652 encode_step_ext (buffer, offset, body->transcript.data, min (length
653 - offset,
654 body->
655 transcript.
656 length));
657 break;
659 encode_step (buffer, offset, &(body->tag.hash));
660
661 if (body->tag.tag)
662 encode_step_ext (buffer, offset, body->tag.tag, min (length - offset,
663 strlen (
664 body->tag.tag)));
665 break;
667 value0 = GNUNET_htobe32 (body->subscribe.flags);
668
669 encode_step (buffer, offset, &(body->subscribe.discourse));
670 encode_step (buffer, offset, &(body->subscribe.time));
671 encode_step (buffer, offset, &value0);
672 break;
674 encode_step (buffer, offset, &(body->talk.discourse));
675
676 if (body->talk.data)
677 encode_step_ext (buffer, offset, body->talk.data, min (length - offset,
678 body->talk.
679 length));
680 break;
681 default:
682 break;
683 }
684
685 if (offset >= length)
686 return;
687
688 {
689 uint16_t padding;
690 uint16_t used_padding;
691
692 padding = length - offset;
693 used_padding = sizeof(padding) + sizeof(char);
694
695 GNUNET_assert (padding >= used_padding);
696
697 buffer[offset++] = '\0';
698
699 if (padding > used_padding)
701 padding - used_padding);
702
703 GNUNET_memcpy (buffer + length - sizeof(padding), &padding, sizeof(padding));
704 }
705}
706
707
708void
710 uint16_t length,
711 char *buffer,
712 enum GNUNET_GenericReturnValue include_header)
713{
714 uint16_t offset;
715 kind_t kind;
716
717 GNUNET_assert ((message) && (buffer));
718
719 offset = 0;
720
721 if (GNUNET_YES == include_header)
722 encode_step_signature (buffer, offset, &(message->header.signature),
723 length);
724
725 kind = GNUNET_htobe32 ((kind_t) message->header.kind);
726
727 if (GNUNET_YES == include_header)
728 {
729 encode_step (buffer, offset, &(message->header.timestamp));
730 encode_step (buffer, offset, &(message->header.sender_id));
731 encode_step (buffer, offset, &(message->header.previous));
732 }
733
734 encode_step (buffer, offset, &kind);
735
736 encode_message_body (message->header.kind, &(message->body),
737 length, buffer, offset);
738}
739
740
741static void
743 uint16_t length,
744 char *buffer)
745{
746 struct GNUNET_HashCode hash;
747 uint16_t offset;
748 kind_t kind;
749
750 GNUNET_assert ((message) && (buffer));
751
752 offset = sizeof(hash);
753 kind = GNUNET_htobe32 ((kind_t) message->kind);
754
755 encode_step (buffer, offset, &kind);
756
757 encode_message_body (message->kind, &(message->body), length, buffer, offset);
758
760 buffer + sizeof(hash),
761 length - sizeof(hash),
762 &hash);
763
764 GNUNET_memcpy (buffer, &hash, sizeof(hash));
765}
766
767
768#define decode_step_ext(src, offset, dst, size) do { \
769 GNUNET_memcpy (dst, src + offset, size); \
770 offset += size; \
771} while (0)
772
773#define decode_step(src, offset, dst) do { \
774 decode_step_ext (src, offset, dst, sizeof(*dst)); \
775} while (0)
776
777#define decode_step_malloc(src, offset, dst, size, zero) do { \
778 dst = GNUNET_malloc (size + zero); \
779 if (zero) dst[size] = 0; \
780 decode_step_ext (src, offset, dst, size); \
781} while (0)
782
783#define decode_step_key(src, offset, dst, length) do { \
784 enum GNUNET_GenericReturnValue result; \
785 size_t read; \
786 result = GNUNET_CRYPTO_read_public_key_from_buffer ( \
787 src + offset, length - offset, dst, &read \
788 ); \
789 if (GNUNET_SYSERR == result) \
790 GNUNET_break (0); \
791 else \
792 offset += read; \
793} while (0)
794
795static uint16_t
797 struct GNUNET_MESSENGER_MessageBody *body,
798 uint16_t length,
799 const char *buffer,
800 uint16_t offset)
801{
802 uint16_t padding;
803 uint32_t value0, value1;
804
805 GNUNET_assert ((kind) && (body) && (buffer));
806
807 padding = 0;
808
809 GNUNET_memcpy (&padding, buffer + length - sizeof(padding), sizeof(padding));
810
811 if (padding > length - offset)
812 padding = 0;
813
814 {
815 uint16_t end_zero;
816 end_zero = length - padding;
817
818 if ((padding) && (buffer[end_zero] != '\0'))
819 padding = 0;
820 }
821
822 length -= padding;
823
824 switch (*kind)
825 {
827 decode_step (buffer, offset, &value0);
828
829 body->info.messenger_version = GNUNET_be32toh (value0);
830 break;
832 decode_step_key (buffer, offset, &(body->join.key), length);
833 break;
835 break;
837 if (length > offset)
838 decode_step_malloc (buffer, offset, body->name.name, length - offset, 1);
839 else
840 body->name.name = NULL;
841 break;
843 decode_step_key (buffer, offset, &(body->key.key), length);
844 break;
846 decode_step (buffer, offset, &(body->peer.peer));
847 break;
849 decode_step (buffer, offset, &(body->id.id));
850 break;
852 decode_step (buffer, offset, &(body->miss.peer));
853 break;
855 decode_step (buffer, offset, &(body->merge.previous));
856 break;
858 decode_step (buffer, offset, &(body->request.hash));
859 break;
861 decode_step (buffer, offset, &(body->invite.door));
862 decode_step (buffer, offset, &(body->invite.key));
863 break;
865 if (length > offset)
866 decode_step_malloc (buffer, offset, body->text.text, length - offset, 1);
867 else
868 body->text.text = NULL;
869 break;
871 decode_step (buffer, offset, &(body->file.key));
872 decode_step (buffer, offset, &(body->file.hash));
873 decode_step_ext (buffer, offset, body->file.name, sizeof(body->file.name));
874 if (length > offset)
875 decode_step_malloc (buffer, offset, body->file.uri, length - offset, 1);
876 else
877 body->file.uri = NULL;
878 break;
880 decode_step (buffer, offset, &(body->privacy.key));
881
882 if (length > offset)
883 {
884 body->privacy.length = (length - offset);
885 decode_step_malloc (buffer, offset, body->privacy.data, length - offset,
886 0);
887 }
888 else
889 {
890 body->privacy.length = 0;
891 body->privacy.data = NULL;
892 }
893
894 break;
896 decode_step (buffer, offset, &(body->deletion.hash));
897 decode_step (buffer, offset, &(body->deletion.delay));
898 break;
900 decode_step (buffer, offset, &value0);
901 decode_step (buffer, offset, &value1);
902
903 body->connection.amount = GNUNET_be32toh (value0);
904 body->connection.flags = GNUNET_be32toh (value1);
905 break;
907 if (length > offset)
908 decode_step_malloc (buffer, offset, body->ticket.identifier, length
909 - offset, 1);
910 else
911 body->ticket.identifier = NULL;
912 break;
914 decode_step (buffer, offset, &(body->transcript.hash));
915 decode_step_key (buffer, offset, &(body->transcript.key), length);
916
917 if (length > offset)
918 {
919 body->transcript.length = (length - offset);
920 decode_step_malloc (buffer, offset, body->transcript.data,
921 length - offset, 0);
922 }
923 else
924 {
925 body->transcript.length = 0;
926 body->transcript.data = NULL;
927 }
928
929 break;
931 decode_step (buffer, offset, &(body->tag.hash));
932 if (length > offset)
933 decode_step_malloc (buffer, offset, body->tag.tag, length - offset, 1);
934 else
935 body->tag.tag = NULL;
936 break;
938 decode_step (buffer, offset, &(body->subscribe.discourse));
939 decode_step (buffer, offset, &(body->subscribe.time));
940 decode_step (buffer, offset, &value0);
941
942 body->subscribe.flags = GNUNET_be32toh (value0);
943 break;
945 decode_step (buffer, offset, &(body->talk.discourse));
946
947 if (length > offset)
948 {
949 body->talk.length = (length - offset);
950 decode_step_malloc (buffer, offset, body->talk.data, length - offset,
951 0);
952 }
953 else
954 {
955 body->talk.length = 0;
956 body->talk.data = NULL;
957 }
958
959 break;
960 default:
962 break;
963 }
964
965 return padding;
966}
967
968
971 uint16_t length,
972 const char *buffer,
973 enum GNUNET_GenericReturnValue include_header,
974 uint16_t *padding)
975{
976 uint16_t offset;
977 uint16_t count;
978 kind_t kind;
979
981 (message) &&
982 (buffer) &&
984 include_header))
985 );
986
987 offset = 0;
988
989 if (GNUNET_YES == include_header)
990 {
991 ssize_t result;
992
994 &(message->header.signature), buffer, length - offset);
995
996 if (result < 0)
997 return GNUNET_NO;
998 else
999 offset += result;
1000 }
1001
1002 count = length - offset;
1004 include_header))
1005 return GNUNET_NO;
1006
1007 if (GNUNET_YES == include_header)
1008 {
1009 decode_step (buffer, offset, &(message->header.timestamp));
1010 decode_step (buffer, offset, &(message->header.sender_id));
1011 decode_step (buffer, offset, &(message->header.previous));
1012 }
1013
1014 decode_step (buffer, offset, &kind);
1015 kind = GNUNET_be32toh (kind);
1016
1017 message->header.kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1018
1019 if (count < get_message_kind_size (message->header.kind, include_header))
1020 return GNUNET_NO;
1021
1022 {
1023 uint16_t result;
1024 result = decode_message_body (&(message->header.kind),
1025 &(message->body), length, buffer, offset);
1026
1027 if (padding)
1028 *padding = result;
1029 }
1030
1031 return GNUNET_YES;
1032}
1033
1034
1035static enum GNUNET_GenericReturnValue
1037 uint16_t length,
1038 const char *buffer)
1039{
1040 struct GNUNET_HashCode expected, hash;
1041 uint16_t offset;
1042 kind_t kind;
1043
1044 GNUNET_assert ((message) && (buffer));
1045
1046 offset = sizeof(hash);
1047
1048 if (length < get_short_message_size (NULL, GNUNET_NO))
1049 return GNUNET_NO;
1050
1051 GNUNET_memcpy (&hash, buffer, sizeof(hash));
1052
1054 buffer + sizeof(hash),
1055 length - sizeof(hash),
1056 &expected);
1057
1058 if (0 != GNUNET_CRYPTO_hash_cmp (&hash, &expected))
1059 return GNUNET_NO;
1060
1061 decode_step (buffer, offset, &kind);
1062 kind = GNUNET_be32toh (kind);
1063
1064 message->kind = (enum GNUNET_MESSENGER_MessageKind) kind;
1065
1066 if (length < get_short_message_size (message, GNUNET_NO))
1067 return GNUNET_NO;
1068
1069 decode_message_body (&(message->kind), &(message->body), length, buffer,
1070 offset);
1071
1072 if (GNUNET_MESSENGER_KIND_UNKNOWN == message->kind)
1073 return GNUNET_NO;
1074
1075 return GNUNET_YES;
1076}
1077
1078
1079void
1081 uint16_t length,
1082 const char *buffer,
1083 struct GNUNET_HashCode *hash)
1084{
1085 ssize_t offset;
1086
1087 GNUNET_assert ((message) && (buffer) && (hash));
1088
1090
1091 GNUNET_CRYPTO_hash (buffer + offset, length - offset, hash);
1092}
1093
1094
1095void
1097 uint16_t length,
1098 char *buffer,
1099 const struct GNUNET_HashCode *hash,
1100 const struct GNUNET_CRYPTO_PrivateKey *key)
1101{
1102 GNUNET_assert ((message) && (buffer) && (hash) && (key));
1103
1104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by member: %s\n",
1105 GNUNET_h2s (hash));
1106
1107 {
1108 struct GNUNET_MESSENGER_MessageSignature signature;
1109
1111 signature.purpose.size = htonl (sizeof(signature));
1112
1113 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1114 GNUNET_CRYPTO_sign (key, &signature, &(message->header.signature));
1115 }
1116
1117 message->header.signature.type = key->type;
1118
1119 {
1120 uint16_t offset = 0;
1121 encode_step_signature (buffer, offset, &(message->header.signature), length);
1122 }
1123}
1124
1125
1126void
1128 uint16_t length,
1129 char *buffer,
1130 const struct GNUNET_HashCode *hash,
1131 const struct GNUNET_CONFIGURATION_Handle *cfg)
1132{
1133 GNUNET_assert ((message) && (buffer) && (hash) && (cfg));
1134
1135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sign message by peer: %s\n",
1136 GNUNET_h2s (hash));
1137
1138 {
1139 struct GNUNET_MESSENGER_MessageSignature signature;
1141 signature.purpose.size = htonl (sizeof(signature));
1142
1143 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1145 &(message->header.signature.
1146 eddsa_signature));
1147 }
1148
1150
1151 {
1152 uint16_t offset = 0;
1153 encode_step_signature (buffer, offset, &(message->header.signature), length);
1154 }
1155}
1156
1157
1160 const struct GNUNET_HashCode *hash,
1161 const struct GNUNET_CRYPTO_PublicKey *key)
1162{
1163 struct GNUNET_MESSENGER_MessageSignature signature;
1164
1165 GNUNET_assert ((message) && (hash) && (key));
1166
1167 if (key->type != message->header.signature.type)
1168 return GNUNET_SYSERR;
1169
1171 signature.purpose.size = htonl (sizeof(signature));
1172
1173 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1174
1177 &(message->header.signature), key);
1178}
1179
1180
1183 const struct GNUNET_HashCode *hash,
1184 const struct GNUNET_PeerIdentity *identity)
1185{
1186 struct GNUNET_MESSENGER_MessageSignature signature;
1187
1188 GNUNET_assert ((message) && (hash) && (identity));
1189
1190 if (ntohl (GNUNET_PUBLIC_KEY_TYPE_EDDSA) != message->header.signature.type)
1191 return GNUNET_SYSERR;
1192
1194 signature.purpose.size = htonl (sizeof(signature));
1195
1196 GNUNET_memcpy (&(signature.hash), hash, sizeof(signature.hash));
1197
1200 &(message->header.signature.
1201 eddsa_signature), identity);
1202}
1203
1204
1207 const struct GNUNET_CRYPTO_PublicKey *key)
1208{
1209 struct GNUNET_CRYPTO_EcdhePublicKey hpke_key;
1211 struct GNUNET_MESSENGER_ShortMessage shortened;
1212 uint16_t length, padded_length, encoded_length;
1213 uint8_t *data;
1214
1215 GNUNET_assert ((message) && (key));
1216
1217 if (GNUNET_YES == is_service_message (message))
1218 return GNUNET_NO;
1219
1220 fold_short_message (message, &shortened);
1221
1222 length = get_short_message_size (&shortened, GNUNET_YES);
1223 padded_length = calc_padded_length (length + encryption_overhead);
1224
1225 GNUNET_assert (padded_length >= length + encryption_overhead);
1226
1228 message->body.privacy.data = GNUNET_malloc (padded_length);
1229 message->body.privacy.length = padded_length;
1230
1232 encoded_length = (padded_length - encryption_overhead);
1233
1234 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1235
1236 result = GNUNET_NO;
1237 data = GNUNET_malloc (encoded_length);
1238
1239 encode_short_message (&shortened, encoded_length, (char *) data);
1240
1242 (uint8_t*) "messenger",
1243 strlen ("messenger"),
1244 NULL, 0,
1245 (uint8_t*) data,
1246 encoded_length,
1247 (uint8_t*) message->body.
1248 privacy.data,
1249 NULL))
1250 {
1251 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Encrypting message failed!\n");
1252
1253 unfold_short_message (&shortened, message);
1254 goto cleanup;
1255 }
1256
1257 destroy_message_body (shortened.kind, &(shortened.body));
1259
1260cleanup:
1261 GNUNET_free (data);
1262 return result;
1263}
1264
1265
1268 const struct GNUNET_CRYPTO_PrivateKey *key)
1269{
1270 struct GNUNET_CRYPTO_EcdhePrivateKey hpke_key;
1272 uint16_t padded_length, encoded_length;
1273 uint8_t *data;
1274
1275 GNUNET_assert ((message) && (key));
1276
1277 padded_length = message->body.privacy.length;
1278
1279 if (padded_length < encryption_overhead)
1280 {
1282 "Message length too short to decrypt!\n");
1283
1284 return GNUNET_NO;
1285 }
1286
1288 encoded_length = (padded_length - encryption_overhead);
1289
1290 GNUNET_assert (padded_length == encoded_length + encryption_overhead);
1291
1292 result = GNUNET_NO;
1293 data = GNUNET_malloc (encoded_length);
1294
1295 if (GNUNET_OK !=
1297 (uint8_t*) "messenger",
1298 strlen ("messenger"),
1299 NULL, 0,
1300 (uint8_t*) message->body.privacy.data,
1301 padded_length,
1302 (uint8_t*) data,
1303 NULL))
1304 {
1305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting message failed!\n");
1306
1307 goto cleanup;
1308 }
1309
1310 {
1311 struct GNUNET_MESSENGER_ShortMessage shortened;
1312 if (GNUNET_YES != decode_short_message (&shortened,
1313 encoded_length,
1314 (char*) data))
1315 {
1317 "Decoding decrypted message failed!\n");
1318
1319 goto cleanup;
1320 }
1321
1322 unfold_short_message (&shortened, message);
1324 }
1325
1326cleanup:
1327 GNUNET_free (data);
1328 return result;
1329}
1330
1331
1334 const struct GNUNET_CRYPTO_PublicKey *key)
1335{
1336 struct GNUNET_MESSENGER_Message *transcript;
1337
1338 GNUNET_assert ((message) && (key));
1339
1340 if (GNUNET_YES == is_service_message (message))
1341 return NULL;
1342
1344
1345 if (! transcript)
1346 {
1347 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Transcribing message failed!\n");
1348 return NULL;
1349 }
1350
1351 GNUNET_memcpy (&(transcript->body.transcript.key), key,
1352 sizeof(transcript->body.transcript.key));
1353
1354 {
1355 struct GNUNET_MESSENGER_ShortMessage shortened;
1356 uint16_t data_length;
1357
1358 fold_short_message (message, &shortened);
1359
1360 data_length = get_short_message_size (&shortened, GNUNET_YES);
1361
1362 transcript->body.transcript.data = GNUNET_malloc (data_length);
1363 transcript->body.transcript.length = data_length;
1364
1365 encode_short_message (&shortened, data_length,
1366 transcript->body.transcript.data);
1367 }
1368
1369 return transcript;
1370}
1371
1372
1375{
1376 uint16_t data_length;
1377 struct GNUNET_MESSENGER_ShortMessage shortened;
1378
1379 GNUNET_assert (message);
1380
1382 return GNUNET_NO;
1383
1384 data_length = message->body.transcript.length;
1385
1386 if (GNUNET_YES != decode_short_message (&shortened,
1387 data_length,
1388 message->body.transcript.data))
1389 {
1391 "Decoding decrypted message failed!\n");
1392
1393 return GNUNET_NO;
1394 }
1395
1396 unfold_short_message (&shortened, message);
1397 return GNUNET_YES;
1398}
1399
1400
1401struct GNUNET_MQ_Envelope*
1403 struct GNUNET_HashCode *hash,
1406 const void *cls)
1407{
1408 struct GNUNET_MessageHeader *header;
1409 uint16_t length, padded_length;
1410 struct GNUNET_MQ_Envelope *env;
1411 char *buffer;
1412
1413 GNUNET_assert (message);
1414
1416 "Packing message kind=%u and sender: %s\n",
1417 message->header.kind, GNUNET_sh2s (&(message->header.sender_id)));
1418
1419 length = get_message_size (message, GNUNET_YES);
1420 padded_length = calc_padded_length (length);
1421
1423 {
1424 env = GNUNET_MQ_msg_extra (header, padded_length,
1426 buffer = (char*) &(header[1]);
1427 }
1428 else
1429 {
1430 env = NULL;
1431 buffer = GNUNET_malloc (padded_length);
1432 }
1433
1434 encode_message (message, padded_length, buffer, GNUNET_YES);
1435
1436 if (hash)
1437 {
1438 hash_message (message, length, buffer, hash);
1439
1440 if (sign)
1441 sign (cls, message, length, buffer, hash);
1442 }
1443
1445 GNUNET_free (buffer);
1446
1447 return env;
1448}
1449
1450
1453{
1454 GNUNET_assert (message);
1455
1456 switch (message->header.kind)
1457 {
1463 return GNUNET_YES;
1464 default:
1465 return GNUNET_NO;
1466 }
1467}
1468
1469
1472{
1473 GNUNET_assert (message);
1474
1475 if (GNUNET_YES == is_peer_message (message))
1476 return GNUNET_YES;
1477
1478 switch (message->header.kind)
1479 {
1481 return GNUNET_YES; // Reserved for connection handling only!
1483 return GNUNET_YES; // Reserved for member handling only!
1485 return GNUNET_YES; // Reserved for member handling only!
1487 return GNUNET_YES; // Reserved for member name handling only!
1489 return GNUNET_YES; // Reserved for member key handling only!
1491 return GNUNET_YES; // Reserved for connection handling only!
1493 return GNUNET_YES; // Reserved for member id handling only!
1495 return GNUNET_YES; // Reserved for connection handling only!
1497 return GNUNET_YES; // Reserved for peers only!
1499 return GNUNET_YES; // Requests should not apply individually! (inefficiently)
1501 return GNUNET_NO;
1503 return GNUNET_NO;
1505 return GNUNET_NO;
1507 return GNUNET_YES; // Prevent duplicate encryption breaking all access!
1509 return GNUNET_YES; // Deletion should not apply individually! (inefficiently)
1511 return GNUNET_YES; // Reserved for connection handling only!
1513 return GNUNET_NO;
1515 return GNUNET_NO;
1517 return GNUNET_NO;
1519 return GNUNET_YES; // Reserved for subscription handling only!
1521 return GNUNET_NO;
1522 default:
1523 return GNUNET_SYSERR;
1524 }
1525}
1526
1527
1530{
1531 GNUNET_assert (message);
1532
1533 if (GNUNET_YES == is_peer_message (message))
1534 return GNUNET_SYSERR; // Requires signature of peer rather than member!
1535
1536 switch (message->header.kind)
1537 {
1539 return GNUNET_SYSERR; // Reserved for connection handling only!
1541 return GNUNET_NO; // Use #GNUNET_MESSENGER_enter_room(...) instead!
1543 return GNUNET_NO; // Use #GNUNET_MESSENGER_close_room(...) instead!
1545 return GNUNET_YES;
1547 return GNUNET_NO; // Use #GNUNET_MESSENGER_set_key(...) instead!
1549 return GNUNET_SYSERR; // Use #GNUNET_MESSENGER_open_room(...) instead!
1551 return GNUNET_NO; // Reserved for member id handling only!
1553 return GNUNET_SYSERR; // Reserved for connection handling only!
1555 return GNUNET_SYSERR; // Reserved for peers only!
1557 return GNUNET_NO; // Use #GNUNET_MESSENGER_get_message(...) instead!
1559 return GNUNET_YES;
1561 return GNUNET_YES;
1563 return GNUNET_YES;
1565 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1567 return GNUNET_NO; // Use #GNUNET_MESSENGER_delete_message(...) instead!
1569 return GNUNET_SYSERR; // Reserved for connection handling only!
1571 return GNUNET_YES;
1573 return GNUNET_NO; // Use #GNUNET_MESSENGER_send_message(...) with a contact instead!
1575 return GNUNET_YES;
1577 return GNUNET_YES;
1579 return GNUNET_YES;
1580 default:
1581 return GNUNET_SYSERR;
1582 }
1583}
1584
1585
1586const struct GNUNET_ShortHashCode*
1588{
1589 GNUNET_assert (message);
1590
1591 switch (message->header.kind)
1592 {
1594 return &(message->body.subscribe.discourse);
1596 return &(message->body.talk.discourse);
1597 default:
1598 return NULL;
1599 }
1600}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static void cleanup(void *cls)
Disconnect and shutdown.
Definition: gnunet-did.c:130
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.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
static enum @44 mode
Should we do a PUT (mode = 0) or GET (mode = 1);.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_sign_by_peer_identity(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
Sign a given block with a specific purpose using the host's peer identity.
void GNUNET_CRYPTO_random_block(enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length)
Fill block with a random values.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_verify_peer_identity(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_PeerIdentity *identity)
Verify a given signature with a peer's identity.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
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
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.
Definition: crypto_hash.c:218
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_open_oneshot(const struct GNUNET_CRYPTO_EcdhePrivateKey *skR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, uint8_t *pt, unsigned long long *pt_len)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:958
ssize_t GNUNET_CRYPTO_read_signature_from_buffer(struct GNUNET_CRYPTO_Signature *sig, const void *buffer, size_t len)
Reads a GNUNET_CRYPTO_Signature from a compact buffer.
Definition: crypto_pkey.c:227
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85
#define GNUNET_log(kind,...)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_seal_oneshot(const struct GNUNET_CRYPTO_EcdhePublicKey *pkR, const uint8_t *info, size_t info_len, const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct, unsigned long long *ct_len)
RFC9180 HPKE encryption.
Definition: crypto_hpke.c:929
#define GNUNET_be32toh(x)
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_sk_to_x25519(const struct GNUNET_CRYPTO_PrivateKey *sk, struct GNUNET_CRYPTO_EcdhePrivateKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:1013
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
ssize_t GNUNET_CRYPTO_signature_get_length(const struct GNUNET_CRYPTO_Signature *sig)
Get the compacted length of a GNUNET_CRYPTO_Signature.
Definition: crypto_pkey.c:190
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_hpke_pk_to_x25519(const struct GNUNET_CRYPTO_PublicKey *pk, struct GNUNET_CRYPTO_EcdhePublicKey *x25519)
Convert a GNUnet identity key to a key sutiable for HPKE (X25519)
Definition: crypto_hpke.c:989
GNUNET_GenericReturnValue
Named constants for return values.
#define GNUNET_CRYPTO_sign(priv, ps, sig)
Sign a given block with GNUNET_CRYPTO_PrivateKey.
#define GNUNET_CRYPTO_signature_verify(purp, ps, sig, pub)
Verify a given signature with GNUNET_CRYPTO_PublicKey.
#define GNUNET_htobe32(x)
#define GNUNET_PACKED
gcc-ism to get packed structs.
#define GNUNET_CRYPTO_HPKE_SEAL_ONESHOT_OVERHEAD_BYTES
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
#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_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_TAG
The tag kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_SUBSCRIBE
The subscribe kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk 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_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete 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_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.
Definition: gnunet_mq_lib.h:61
#define GNUNET_MESSAGE_TYPE_CADET_CLI
Traffic (net-cat style) used by the Command Line Interface.
static void destroy_message_body(enum GNUNET_MESSENGER_MessageKind kind, struct GNUNET_MESSENGER_MessageBody *body)
#define decode_step(src, offset, dst)
#define encode_step_ext(dst, offset, src, size)
static uint16_t get_short_message_size(const struct GNUNET_MESSENGER_ShortMessage *message, enum GNUNET_GenericReturnValue include_body)
enum GNUNET_GenericReturnValue verify_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PublicKey *key)
Verifies the signature of a given message and its hash with a specific public key.
static uint16_t get_message_body_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
enum GNUNET_GenericReturnValue is_service_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message contains service critical information.
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
static uint16_t get_message_body_size(enum GNUNET_MESSENGER_MessageKind kind, const struct GNUNET_MESSENGER_MessageBody *body)
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
static void fold_short_message(const struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_ShortMessage *shortened)
#define decode_step_key(src, offset, dst, length)
static uint16_t calc_padded_length(uint16_t length)
enum GNUNET_GenericReturnValue filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message should be sent by a client.
#define decode_step_malloc(src, offset, dst, size, zero)
#define encode_step(dst, offset, src)
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 verify_message_by_peer(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_PeerIdentity *identity)
Verifies the signature of a given message and its hash with a specific peer's identity.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
struct GNUNET_MESSENGER_Message * create_message(enum GNUNET_MESSENGER_MessageKind kind)
Creates and allocates a new message with a specific kind.
struct GNUNET_MQ_Envelope * pack_message(struct GNUNET_MESSENGER_Message *message, struct GNUNET_HashCode *hash, const GNUNET_MESSENGER_SignFunction sign, enum GNUNET_MESSENGER_PackMode mode, const void *cls)
Encodes the message to pack it into a newly allocated envelope if mode is equal to GNUNET_MESSENGER_P...
#define decode_step_ext(src, offset, dst, size)
static void unfold_short_message(struct GNUNET_MESSENGER_ShortMessage *shortened, struct GNUNET_MESSENGER_Message *message)
enum GNUNET_GenericReturnValue decrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key)
Decrypts a private message using a given private key and replaces its body and kind with the inner en...
#define encode_step_signature(dst, offset, src, length)
static uint16_t calc_usual_padding()
static uint16_t decode_message_body(enum GNUNET_MESSENGER_MessageKind *kind, struct GNUNET_MESSENGER_MessageBody *body, uint16_t length, const char *buffer, uint16_t offset)
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.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
void sign_message_by_peer(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CONFIGURATION_Handle *cfg)
Signs the hash of a message with the peer identity of a given config and writes the signature into th...
enum GNUNET_GenericReturnValue read_transcript_message(struct GNUNET_MESSENGER_Message *message)
Read the original message from a transcript message and replaces its body and kind with the inner enc...
#define encode_step_key(dst, offset, src, length)
enum GNUNET_GenericReturnValue is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
#define member_size(type, member)
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
#define GNUNET_MESSENGER_MAX_MESSAGE_SIZE
GNUNET_MESSENGER_PackMode
@ GNUNET_MESSENGER_PACK_MODE_ENVELOPE
#define GNUNET_MESSENGER_PADDING_LEVEL0
#define GNUNET_MESSENGER_PADDING_MIN
void(* GNUNET_MESSENGER_SignFunction)(const void *cls, struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash)
#define GNUNET_MESSENGER_PADDING_LEVEL2
#define GNUNET_MESSENGER_PADDING_LEVEL1
#define GNUNET_SIGNATURE_PURPOSE_CHAT_MESSAGE
Signature of a chat message.
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
uint32_t type
Type of signature.
A 512-bit hashcode.
The unified body of a GNUNET_MESSENGER_Message.
struct GNUNET_MESSENGER_MessagePrivate privacy
struct GNUNET_MESSENGER_MessageConnection connection
struct GNUNET_MESSENGER_MessageSubscribe subscribe
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_MessageTranscript transcript
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_MessageMiss miss
struct GNUNET_MESSENGER_MessagePeer peer
struct GNUNET_MESSENGER_MessageJoin join
struct GNUNET_MESSENGER_MessageDelete deletion
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.
The header of a GNUNET_MESSENGER_Message.
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_CRYPTO_Signature signature
The signature of the senders private key.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
struct GNUNET_ShortHashCode id
The new id which will replace the senders id in a room.
uint32_t messenger_version
The version of GNUnet Messenger API.
struct GNUNET_HashCode 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_PublicKey key
The senders public key to verify its signatures.
struct GNUNET_CRYPTO_PublicKey key
The new public key which replaces the current senders public key.
struct GNUNET_HashCode previous
The hash of a second previous message.
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.
struct GNUNET_CRYPTO_EcdhePublicKey key
The ECDH key to decrypt the message.
char * data
The data of the encrypted message.
struct GNUNET_HashCode hash
The hash of the requested message.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribe.
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 * text
The containing text.
char * identifier
The identifier of a ticket.
uint16_t length
The length of the transcribed message.
struct GNUNET_HashCode hash
The hash of the original message.
struct GNUNET_CRYPTO_PublicKey key
The key from the recipient of the original message.
char * data
The data of the transcribed message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_MessageBody body
enum GNUNET_MESSENGER_MessageKind kind
Header for all communications.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.