GNUnet 0.22.2
json_helper.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2014-2022 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#include "platform.h"
28#include "gnunet_json_lib.h"
29#include "gnunet_common.h"
30
31
34{
36 .parser = NULL,
37 .cleaner = NULL,
38 .cls = NULL
39 };
40
41 return ret;
42}
43
44
52string_to_cipher (const char *cipher_s)
53{
54 if ((0 == strcasecmp (cipher_s,
55 "RSA")) ||
56 (0 == strcasecmp (cipher_s,
57 "RSA+age_restricted")))
59 if ((0 == strcasecmp (cipher_s,
60 "CS")) ||
61 (0 == strcasecmp (cipher_s,
62 "CS+age_restricted")))
65}
66
67
78 json_t *root,
79 struct GNUNET_JSON_Specification *spec)
80{
81 const char *enc;
82 size_t len;
83
84 if (NULL == (enc = json_string_value (root)))
85 {
87 return GNUNET_SYSERR;
88 }
89 len = strlen (enc);
90 if (len >= SIZE_MAX / 5)
91 {
93 return GNUNET_SYSERR;
94 }
95 if (((len * 5) / 8) != spec->ptr_size)
96 {
99 "Field `%s' has wrong length\n",
100 spec->field);
101 return GNUNET_SYSERR;
102 }
103 if (GNUNET_OK !=
105 len,
106 spec->ptr,
107 spec->ptr_size))
108 {
109 GNUNET_break_op (0);
110 return GNUNET_SYSERR;
111 }
112 return GNUNET_OK;
113}
114
115
118 void *obj,
119 size_t size)
120{
122 .parser = &parse_fixed_data,
123 .cleaner = NULL,
124 .cls = NULL,
125 .field = name,
126 .ptr = obj,
127 .ptr_size = size,
128 .size_ptr = NULL
129 };
130
131 return ret;
132}
133
134
145 json_t *root,
146 struct GNUNET_JSON_Specification *spec)
147{
148 const char *enc;
149 unsigned int len;
150 void *output;
151 size_t olen;
152
153 if (NULL == (enc = json_string_value (root)))
154 {
155 GNUNET_break_op (0);
156 return GNUNET_SYSERR;
157 }
158 len = strlen (enc);
159 output = NULL;
161 len,
162 &output);
163 if (olen != spec->ptr_size)
164 {
165 GNUNET_break_op (0);
167 "Field `%s' has wrong length\n",
168 spec->field);
169 GNUNET_free (output);
170 return GNUNET_SYSERR;
171 }
172 memcpy (spec->ptr,
173 output,
174 olen);
175 GNUNET_free (output);
176 return GNUNET_OK;
177}
178
179
182 void *obj,
183 size_t size)
184{
186 .parser = &parse_fixed64_data,
187 .cleaner = NULL,
188 .cls = NULL,
189 .field = name,
190 .ptr = obj,
191 .ptr_size = size,
192 .size_ptr = NULL
193 };
194
195 return ret;
196}
197
198
209 json_t *root,
210 struct GNUNET_JSON_Specification *spec)
211{
212 const char *str;
213 size_t size;
214 void *data;
215
216 str = json_string_value (root);
217 if (NULL == str)
218 {
219 GNUNET_break_op (0);
220 return GNUNET_SYSERR;
221 }
222 if (GNUNET_OK !=
224 strlen (str),
225 &data,
226 &size))
227 {
228 GNUNET_break_op (0);
229 return GNUNET_SYSERR;
230 }
231 *(void **) spec->ptr = data;
232 *spec->size_ptr = size;
233 return GNUNET_OK;
234}
235
236
243static void
245 struct GNUNET_JSON_Specification *spec)
246{
247 (void) cls;
248 if (0 != *spec->size_ptr)
249 {
250 GNUNET_free (*(void **) spec->ptr);
251 *(void **) spec->ptr = NULL;
252 *spec->size_ptr = 0;
253 }
254}
255
256
259 void **obj,
260 size_t *size)
261{
263 .parser = &parse_variable_data,
264 .cleaner = &clean_variable_data,
265 .cls = NULL,
266 .field = name,
267 .ptr = obj,
268 .ptr_size = 0,
269 .size_ptr = size
270 };
271
272 *obj = NULL;
273 *size = 0;
274 return ret;
275}
276
277
288 json_t *root,
289 struct GNUNET_JSON_Specification *spec)
290{
291 const char *str;
292
293 (void) cls;
294 str = json_string_value (root);
295 if (NULL == str)
296 {
297 GNUNET_break_op (0);
298 return GNUNET_SYSERR;
299 }
300 *(const char **) spec->ptr = str;
301 return GNUNET_OK;
302}
303
304
307 const char **strptr)
308{
310 .parser = &parse_string,
311 .field = name,
312 .ptr = strptr
313 };
314
315 *strptr = NULL;
316 return ret;
317}
318
319
330 json_t *root,
331 struct GNUNET_JSON_Specification *spec)
332{
333 if (! (json_is_object (root) || json_is_array (root)))
334 {
335 GNUNET_break_op (0);
336 return GNUNET_SYSERR;
337 }
338 json_incref (root);
339 *(json_t **) spec->ptr = root;
340 return GNUNET_OK;
341}
342
343
350static void
352 struct GNUNET_JSON_Specification *spec)
353{
354 json_t **ptr = (json_t **) spec->ptr;
355
356 if (NULL != *ptr)
357 {
358 json_decref (*ptr);
359 *ptr = NULL;
360 }
361}
362
363
366 json_t **jsonp)
367{
369 .parser = &parse_json,
370 .cleaner = &clean_json,
371 .cls = NULL,
372 .field = name,
373 .ptr = jsonp,
374 .ptr_size = 0,
375 .size_ptr = NULL
376 };
377
378 *jsonp = NULL;
379 return ret;
380}
381
382
393 json_t *root,
394 struct GNUNET_JSON_Specification *spec)
395{
396 if (NULL == root)
397 return GNUNET_OK;
398 if (! json_is_object (root))
399 {
400 GNUNET_break_op (0);
401 return GNUNET_SYSERR;
402 }
403 *(const json_t **) spec->ptr = (const json_t *) root;
404 return GNUNET_OK;
405}
406
407
410 const json_t **jsonp)
411{
413 .parser = &parse_object_const,
414 .cls = NULL,
415 .field = name,
416 .ptr = jsonp,
417 .ptr_size = 0,
418 .size_ptr = NULL
419 };
420
421 *jsonp = NULL;
422 return ret;
423}
424
425
436 json_t *root,
437 struct GNUNET_JSON_Specification *spec)
438{
439 if (NULL == root)
440 return GNUNET_OK;
441 if (! json_is_array (root))
442 {
443 GNUNET_break_op (0);
444 return GNUNET_SYSERR;
445 }
446 *(const json_t **) spec->ptr = (const json_t *) root;
447 return GNUNET_OK;
448}
449
450
453 const json_t **jsonp)
454{
456 .parser = &parse_array_const,
457 .cls = NULL,
458 .field = name,
459 .ptr = jsonp,
460 .ptr_size = 0,
461 .size_ptr = NULL
462 };
463
464 *jsonp = NULL;
465 return ret;
466}
467
468
479 json_t *root,
480 struct GNUNET_JSON_Specification *spec)
481{
482 bool *b = spec->ptr;
483
484 if (json_true () == root)
485 {
486 *b = true;
487 return GNUNET_OK;
488 }
489 if (json_false () == root)
490 {
491 *b = false;
492 return GNUNET_OK;
493 }
494 GNUNET_break_op (0);
495 return GNUNET_SYSERR;
496}
497
498
501 bool *b)
502{
504 .parser = &parse_bool,
505 .cleaner = NULL,
506 .cls = NULL,
507 .field = name,
508 .ptr = b,
509 .ptr_size = sizeof(bool),
510 .size_ptr = NULL
511 };
512
513 return ret;
514}
515
516
527 json_t *root,
528 struct GNUNET_JSON_Specification *spec)
529{
530 double *f = spec->ptr;
531
532 if (! json_is_real (root))
533 {
534 GNUNET_break_op (0);
535 return GNUNET_SYSERR;
536 }
537 *f = json_real_value (root);
538 return GNUNET_OK;
539}
540
541
544 double *f)
545{
547 .parser = &parse_double,
548 .cleaner = NULL,
549 .cls = NULL,
550 .field = name,
551 .ptr = f,
552 .ptr_size = sizeof(double),
553 .size_ptr = NULL
554 };
555
556 return ret;
557}
558
559
570 json_t *root,
571 struct GNUNET_JSON_Specification *spec)
572{
573 json_int_t val;
574 uint8_t *up = spec->ptr;
575
576 if (! json_is_integer (root))
577 {
578 GNUNET_break_op (0);
579 return GNUNET_SYSERR;
580 }
581 val = json_integer_value (root);
582 if ((0 > val) || (val > UINT8_MAX))
583 {
584 GNUNET_break_op (0);
585 return GNUNET_SYSERR;
586 }
587 *up = (uint8_t) val;
588 return GNUNET_OK;
589}
590
591
594 uint8_t *u8)
595{
597 .parser = &parse_u8,
598 .cleaner = NULL,
599 .cls = NULL,
600 .field = name,
601 .ptr = u8,
602 .ptr_size = sizeof(uint8_t),
603 .size_ptr = NULL
604 };
605
606 return ret;
607}
608
609
620 json_t *root,
621 struct GNUNET_JSON_Specification *spec)
622{
623 json_int_t val;
624 uint16_t *up = spec->ptr;
625
626 if (! json_is_integer (root))
627 {
628 GNUNET_break_op (0);
629 return GNUNET_SYSERR;
630 }
631 val = json_integer_value (root);
632 if ((0 > val) || (val > UINT16_MAX))
633 {
634 GNUNET_break_op (0);
635 return GNUNET_SYSERR;
636 }
637 *up = (uint16_t) val;
638 return GNUNET_OK;
639}
640
641
644 uint16_t *u16)
645{
647 .parser = &parse_u16,
648 .cleaner = NULL,
649 .cls = NULL,
650 .field = name,
651 .ptr = u16,
652 .ptr_size = sizeof(uint16_t),
653 .size_ptr = NULL
654 };
655
656 return ret;
657}
658
659
670 json_t *root,
671 struct GNUNET_JSON_Specification *spec)
672{
673 json_int_t val;
674 uint32_t *up = spec->ptr;
675
676 if (! json_is_integer (root))
677 {
678 GNUNET_break_op (0);
679 return GNUNET_SYSERR;
680 }
681 val = json_integer_value (root);
682 if ((0 > val) || (val > UINT32_MAX))
683 {
684 GNUNET_break_op (0);
685 return GNUNET_SYSERR;
686 }
687 *up = (uint32_t) val;
688 return GNUNET_OK;
689}
690
691
694 uint32_t *u32)
695{
697 .parser = &parse_u32,
698 .cleaner = NULL,
699 .cls = NULL,
700 .field = name,
701 .ptr = u32,
702 .ptr_size = sizeof(uint32_t),
703 .size_ptr = NULL
704 };
705
706 return ret;
707}
708
709
720 json_t *root,
721 struct GNUNET_JSON_Specification *spec)
722{
723 json_int_t val;
724 uint64_t *up = spec->ptr;
725
726 if (! json_is_integer (root))
727 {
728 GNUNET_break_op (0);
729 return GNUNET_SYSERR;
730 }
731 val = json_integer_value (root);
732 *up = (uint64_t) val;
733 return GNUNET_OK;
734}
735
736
739 uint64_t *u64)
740{
742 .parser = &parse_u64,
743 .cleaner = NULL,
744 .cls = NULL,
745 .field = name,
746 .ptr = u64,
747 .ptr_size = sizeof(uint64_t),
748 .size_ptr = NULL
749 };
750
751 return ret;
752}
753
754
765 json_t *root,
766 struct GNUNET_JSON_Specification *spec)
767{
768 json_int_t val;
769 int64_t *up = spec->ptr;
770
771 if (! json_is_integer (root))
772 {
773 GNUNET_break_op (0);
774 return GNUNET_SYSERR;
775 }
776 val = json_integer_value (root);
777 *up = (int64_t) val;
778 return GNUNET_OK;
779}
780
781
784 int64_t *i64)
785{
787 .parser = &parse_i64,
788 .cleaner = NULL,
789 .cls = NULL,
790 .field = name,
791 .ptr = i64,
792 .ptr_size = sizeof(int64_t),
793 .size_ptr = NULL
794 };
795
796 return ret;
797}
798
799
800/* ************ GNUnet-specific parser specifications ******************* */
801
812 json_t *root,
813 struct GNUNET_JSON_Specification *spec)
814{
815 struct GNUNET_TIME_Timestamp *ts = spec->ptr;
816 json_t *json_t_s;
817 unsigned long long int tval;
818
819 if (! json_is_object (root))
820 {
821 GNUNET_break_op (0);
822 return GNUNET_SYSERR;
823 }
824 json_t_s = json_object_get (root,
825 "t_s");
826 if (json_is_integer (json_t_s))
827 {
828 tval = json_integer_value (json_t_s);
829 /* Time is in seconds in JSON, but in microseconds in GNUNET_TIME_Absolute */
831 = tval * GNUNET_TIME_UNIT_SECONDS.rel_value_us;
832 if (ts->abs_time.abs_value_us
833 / GNUNET_TIME_UNIT_SECONDS.rel_value_us
834 != tval)
835 {
836 /* Integer overflow */
837 GNUNET_break_op (0);
838 return GNUNET_SYSERR;
839 }
840 return GNUNET_OK;
841 }
842 if (json_is_string (json_t_s))
843 {
844 const char *val;
845
846 val = json_string_value (json_t_s);
847 if ((0 == strcasecmp (val,
848 "never")))
849 {
851 return GNUNET_OK;
852 }
853 GNUNET_break_op (0);
854 return GNUNET_SYSERR;
855 }
856 GNUNET_break_op (0);
857 return GNUNET_SYSERR;
858}
859
860
863 struct GNUNET_TIME_Timestamp *t)
864{
866 .parser = &parse_timestamp,
867 .field = name,
868 .ptr = t,
869 .ptr_size = sizeof(struct GNUNET_TIME_Timestamp)
870 };
871
872 return ret;
873}
874
875
886 json_t *root,
887 struct GNUNET_JSON_Specification *spec)
888{
889 struct GNUNET_TIME_TimestampNBO *ts = spec->ptr;
890 struct GNUNET_TIME_Timestamp a;
891 struct GNUNET_JSON_Specification ispec;
892
893 ispec = *spec;
894 ispec.parser = &parse_timestamp;
895 ispec.ptr = &a;
896 if (GNUNET_OK !=
897 parse_timestamp (NULL,
898 root,
899 &ispec))
900 return GNUNET_SYSERR;
902 return GNUNET_OK;
903}
904
905
908 struct GNUNET_TIME_TimestampNBO *at)
909{
911 .parser = &parse_timestamp_nbo,
912 .field = name,
913 .ptr = at,
914 .ptr_size = sizeof(struct GNUNET_TIME_TimestampNBO)
915 };
916
917 return ret;
918}
919
920
930parse_rel_time (void *cls,
931 json_t *root,
932 struct GNUNET_JSON_Specification *spec)
933{
934 struct GNUNET_TIME_Relative *rel = spec->ptr;
935 json_t *json_d_us;
936 unsigned long long int tval;
937
938 if (! json_is_object (root))
939 {
940 GNUNET_break_op (0);
941 return GNUNET_SYSERR;
942 }
943 json_d_us = json_object_get (root,
944 "d_us");
945 if (json_is_integer (json_d_us))
946 {
947 tval = json_integer_value (json_d_us);
948 if (tval >= (1LLU << 53))
949 {
950 /* value is larger than allowed */
951 GNUNET_break_op (0);
952 return GNUNET_SYSERR;
953 }
954 rel->rel_value_us = tval;
955 return GNUNET_OK;
956 }
957 if (json_is_string (json_d_us))
958 {
959 const char *val;
960
961 val = json_string_value (json_d_us);
962 if ((0 == strcasecmp (val,
963 "forever")))
964 {
966 return GNUNET_OK;
967 }
968 GNUNET_break_op (0);
969 return GNUNET_SYSERR;
970 }
971 GNUNET_break_op (0);
972 return GNUNET_SYSERR;
973}
974
975
978 struct GNUNET_TIME_Relative *rt)
979{
981 .parser = &parse_rel_time,
982 .field = name,
983 .ptr = rt,
984 .ptr_size = sizeof(struct GNUNET_TIME_Relative)
985 };
986
987 return ret;
988}
989
990
1001 json_t *root,
1002 struct GNUNET_JSON_Specification *spec)
1003{
1004 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1005 const char *enc;
1006 char *buf;
1007 size_t len;
1008 size_t buf_len;
1009
1010 if (NULL == (enc = json_string_value (root)))
1011 {
1012 GNUNET_break_op (0);
1013 return GNUNET_SYSERR;
1014 }
1015 len = strlen (enc);
1016 buf_len = (len * 5) / 8;
1017 buf = GNUNET_malloc (buf_len);
1018 if (GNUNET_OK !=
1020 len,
1021 buf,
1022 buf_len))
1023 {
1024 GNUNET_break_op (0);
1025 GNUNET_free (buf);
1026 return GNUNET_SYSERR;
1027 }
1028 if (NULL == (*pk = GNUNET_CRYPTO_rsa_public_key_decode (buf,
1029 buf_len)))
1030 {
1031 GNUNET_break_op (0);
1032 GNUNET_free (buf);
1033 return GNUNET_SYSERR;
1034 }
1035 GNUNET_free (buf);
1036 return GNUNET_OK;
1037}
1038
1039
1046static void
1048 struct GNUNET_JSON_Specification *spec)
1049{
1050 struct GNUNET_CRYPTO_RsaPublicKey **pk = spec->ptr;
1051
1052 if (NULL != *pk)
1053 {
1055 *pk = NULL;
1056 }
1057}
1058
1059
1063{
1065 .parser = &parse_rsa_public_key,
1066 .cleaner = &clean_rsa_public_key,
1067 .field = name,
1068 .ptr = pk
1069 };
1070
1071 *pk = NULL;
1072 return ret;
1073}
1074
1075
1084static enum GNUNET_GenericReturnValue
1086 json_t *root,
1087 struct GNUNET_JSON_Specification *spec)
1088{
1089 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1090 size_t size;
1091 const char *str;
1092 int res;
1093 void *buf;
1094
1095 str = json_string_value (root);
1096 if (NULL == str)
1097 {
1098 GNUNET_break_op (0);
1099 return GNUNET_SYSERR;
1100 }
1101 size = (strlen (str) * 5) / 8;
1102 buf = GNUNET_malloc (size);
1104 strlen (str),
1105 buf,
1106 size);
1107 if (GNUNET_OK != res)
1108 {
1109 GNUNET_free (buf);
1110 GNUNET_break_op (0);
1111 return GNUNET_SYSERR;
1112 }
1113 if (NULL == (*sig = GNUNET_CRYPTO_rsa_signature_decode (buf,
1114 size)))
1115 {
1116 GNUNET_break_op (0);
1117 GNUNET_free (buf);
1118 return GNUNET_SYSERR;
1119 }
1120 GNUNET_free (buf);
1121 return GNUNET_OK;
1122}
1123
1124
1131static void
1133 struct GNUNET_JSON_Specification *spec)
1134{
1135 struct GNUNET_CRYPTO_RsaSignature **sig = spec->ptr;
1136
1137 if (NULL != *sig)
1138 {
1140 *sig = NULL;
1141 }
1142}
1143
1144
1147 struct GNUNET_CRYPTO_RsaSignature **sig)
1148{
1150 .parser = &parse_rsa_signature,
1151 .cleaner = &clean_rsa_signature,
1152 .cls = NULL,
1153 .field = name,
1154 .ptr = sig,
1155 .ptr_size = 0,
1156 .size_ptr = NULL
1157 };
1158
1159 *sig = NULL;
1160 return ret;
1161}
1162
1163
1172static enum GNUNET_GenericReturnValue
1174 json_t *root,
1175 struct GNUNET_JSON_Specification *spec)
1176{
1177 int *bp = spec->ptr;
1178
1179 if (! json_is_boolean (root))
1180 {
1181 GNUNET_break_op (0);
1182 return GNUNET_SYSERR;
1183 }
1184 *bp = json_boolean_value (root) ? GNUNET_YES : GNUNET_NO;
1185 return GNUNET_OK;
1186}
1187
1188
1191 int *boolean)
1192{
1194 .parser = &parse_boolean,
1195 .cleaner = NULL,
1196 .cls = NULL,
1197 .field = name,
1198 .ptr = boolean,
1199 .ptr_size = sizeof(int),
1200 .size_ptr = NULL
1201 };
1202
1203 return ret;
1204}
1205
1206
1215static enum GNUNET_GenericReturnValue
1217 json_t *root,
1218 struct GNUNET_JSON_Specification *spec)
1219{
1220 struct GNUNET_CRYPTO_BlindedMessage **target = spec->ptr;
1221 struct GNUNET_CRYPTO_BlindedMessage *blinded_message;
1222 const char *cipher;
1223 struct GNUNET_JSON_Specification dspec[] = {
1224 GNUNET_JSON_spec_string ("cipher",
1225 &cipher),
1227 };
1228 const char *emsg;
1229 unsigned int eline;
1230
1231 (void) cls;
1232 if (GNUNET_OK !=
1233 GNUNET_JSON_parse (root,
1234 dspec,
1235 &emsg,
1236 &eline))
1237 {
1238 GNUNET_break_op (0);
1239 return GNUNET_SYSERR;
1240 }
1241 blinded_message = GNUNET_new (struct GNUNET_CRYPTO_BlindedMessage);
1242 blinded_message->rc = 1;
1243 blinded_message->cipher = string_to_cipher (cipher);
1244 switch (blinded_message->cipher)
1245 {
1247 break;
1249 {
1250 struct GNUNET_JSON_Specification ispec[] = {
1252 /* TODO: Change this field name to something
1253 more generic / pass in as argument. */
1254 "rsa_blinded_planchet",
1255 &blinded_message->details.rsa_blinded_message.blinded_msg,
1256 &blinded_message->details.rsa_blinded_message.blinded_msg_size),
1258 };
1259
1260 if (GNUNET_OK !=
1261 GNUNET_JSON_parse (root,
1262 ispec,
1263 &emsg,
1264 &eline))
1265 {
1266 GNUNET_break_op (0);
1267 GNUNET_free (blinded_message);
1268 return GNUNET_SYSERR;
1269 }
1270 *target = blinded_message;
1271 return GNUNET_OK;
1272 }
1274 {
1275 struct GNUNET_JSON_Specification ispec[] = {
1277 "cs_nonce",
1278 &blinded_message->details.cs_blinded_message.nonce),
1280 "cs_blinded_c0",
1281 &blinded_message->details.cs_blinded_message.c[0]),
1283 "cs_blinded_c1",
1284 &blinded_message->details.cs_blinded_message.c[1]),
1286 };
1287
1288 if (GNUNET_OK !=
1289 GNUNET_JSON_parse (root,
1290 ispec,
1291 &emsg,
1292 &eline))
1293 {
1294 GNUNET_break_op (0);
1295 GNUNET_free (blinded_message);
1296 return GNUNET_SYSERR;
1297 }
1298 *target = blinded_message;
1299 return GNUNET_OK;
1300 }
1301 }
1302 GNUNET_break_op (0);
1303 GNUNET_free (blinded_message);
1304 return GNUNET_SYSERR;
1305}
1306
1307
1314static void
1316 struct GNUNET_JSON_Specification *spec)
1317{
1318 struct GNUNET_CRYPTO_BlindedMessage **blinded_message = spec->ptr;
1319
1320 (void) cls;
1321 if (NULL != blinded_message)
1322 {
1323 GNUNET_CRYPTO_blinded_message_decref (*blinded_message);
1324 *blinded_message = NULL;
1325 }
1326}
1327
1328
1332{
1334 .parser = &parse_blinded_message,
1335 .cleaner = &clean_blinded_message,
1336 .cls = NULL,
1337 .field = name,
1338 .ptr = msg,
1339 .ptr_size = 0,
1340 .size_ptr = NULL
1341 };
1342
1343 *msg = NULL;
1344 return ret;
1345}
1346
1347
1356static enum GNUNET_GenericReturnValue
1358 json_t *root,
1359 struct GNUNET_JSON_Specification *spec)
1360{
1361 struct GNUNET_CRYPTO_BlindedSignature **target = spec->ptr;
1362 struct GNUNET_CRYPTO_BlindedSignature *blinded_sig;
1363 const char *cipher;
1364 struct GNUNET_JSON_Specification dspec[] = {
1365 GNUNET_JSON_spec_string ("cipher",
1366 &cipher),
1368 };
1369 const char *emsg;
1370 unsigned int eline;
1371
1372 (void) cls;
1373 if (GNUNET_OK !=
1374 GNUNET_JSON_parse (root,
1375 dspec,
1376 &emsg,
1377 &eline))
1378 {
1379 GNUNET_break_op (0);
1380 return GNUNET_SYSERR;
1381 }
1382 blinded_sig = GNUNET_new (struct GNUNET_CRYPTO_BlindedSignature);
1383 blinded_sig->cipher = string_to_cipher (cipher);
1384 blinded_sig->rc = 1;
1385 switch (blinded_sig->cipher)
1386 {
1388 break;
1390 {
1391 struct GNUNET_JSON_Specification ispec[] = {
1393 "blinded_rsa_signature",
1394 &blinded_sig->details.blinded_rsa_signature),
1396 };
1397
1398 if (GNUNET_OK !=
1399 GNUNET_JSON_parse (root,
1400 ispec,
1401 &emsg,
1402 &eline))
1403 {
1404 GNUNET_break_op (0);
1405 GNUNET_free (blinded_sig);
1406 return GNUNET_SYSERR;
1407 }
1408 *target = blinded_sig;
1409 return GNUNET_OK;
1410 }
1412 {
1413 struct GNUNET_JSON_Specification ispec[] = {
1415 &blinded_sig->details.blinded_cs_answer.b),
1417 &blinded_sig->details.blinded_cs_answer.
1418 s_scalar),
1420 };
1421
1422 if (GNUNET_OK !=
1423 GNUNET_JSON_parse (root,
1424 ispec,
1425 &emsg,
1426 &eline))
1427 {
1428 GNUNET_break_op (0);
1429 GNUNET_free (blinded_sig);
1430 return GNUNET_SYSERR;
1431 }
1432 *target = blinded_sig;
1433 return GNUNET_OK;
1434 }
1435 }
1436 GNUNET_break_op (0);
1437 GNUNET_free (blinded_sig);
1438 return GNUNET_SYSERR;
1439}
1440
1441
1448static void
1450 struct GNUNET_JSON_Specification *spec)
1451{
1452 struct GNUNET_CRYPTO_BlindedSignature **b_sig = spec->ptr;
1453
1454 (void) cls;
1455
1456 if (NULL != *b_sig)
1457 {
1459 *b_sig = NULL;
1460 }
1461}
1462
1463
1467 b_sig)
1468{
1470 .parser = &parse_blinded_sig,
1471 .cleaner = &clean_blinded_sig,
1472 .field = field,
1473 .ptr = b_sig
1474 };
1475
1476 *b_sig = NULL;
1477 return ret;
1478}
1479
1480
1489static enum GNUNET_GenericReturnValue
1491 json_t *root,
1492 struct GNUNET_JSON_Specification *spec)
1493{
1494 struct GNUNET_CRYPTO_UnblindedSignature **target = spec->ptr;
1495 struct GNUNET_CRYPTO_UnblindedSignature *unblinded_sig;
1496 const char *cipher;
1497 struct GNUNET_JSON_Specification dspec[] = {
1498 GNUNET_JSON_spec_string ("cipher",
1499 &cipher),
1501 };
1502 const char *emsg;
1503 unsigned int eline;
1504
1505 (void) cls;
1506 if (GNUNET_OK !=
1507 GNUNET_JSON_parse (root,
1508 dspec,
1509 &emsg,
1510 &eline))
1511 {
1512 GNUNET_break_op (0);
1513 return GNUNET_SYSERR;
1514 }
1515 unblinded_sig = GNUNET_new (struct GNUNET_CRYPTO_UnblindedSignature);
1516 unblinded_sig->cipher = string_to_cipher (cipher);
1517 unblinded_sig->rc = 1;
1518 switch (unblinded_sig->cipher)
1519 {
1521 break;
1523 {
1524 struct GNUNET_JSON_Specification ispec[] = {
1526 "rsa_signature",
1527 &unblinded_sig->details.rsa_signature),
1529 };
1530
1531 if (GNUNET_OK !=
1532 GNUNET_JSON_parse (root,
1533 ispec,
1534 &emsg,
1535 &eline))
1536 {
1537 GNUNET_break_op (0);
1538 GNUNET_free (unblinded_sig);
1539 return GNUNET_SYSERR;
1540 }
1541 *target = unblinded_sig;
1542 return GNUNET_OK;
1543 }
1545 {
1546 struct GNUNET_JSON_Specification ispec[] = {
1547 GNUNET_JSON_spec_fixed_auto ("cs_signature_r",
1548 &unblinded_sig->details.cs_signature.
1549 r_point),
1550 GNUNET_JSON_spec_fixed_auto ("cs_signature_s",
1551 &unblinded_sig->details.cs_signature.
1552 s_scalar),
1554 };
1555
1556 if (GNUNET_OK !=
1557 GNUNET_JSON_parse (root,
1558 ispec,
1559 &emsg,
1560 &eline))
1561 {
1562 GNUNET_break_op (0);
1563 GNUNET_free (unblinded_sig);
1564 return GNUNET_SYSERR;
1565 }
1566 *target = unblinded_sig;
1567 return GNUNET_OK;
1568 }
1569 }
1570 GNUNET_break_op (0);
1571 GNUNET_free (unblinded_sig);
1572 return GNUNET_SYSERR;
1573}
1574
1575
1582static void
1584 struct GNUNET_JSON_Specification *spec)
1585{
1586 struct GNUNET_CRYPTO_UnblindedSignature **ub_sig = spec->ptr;
1587
1588 (void) cls;
1589 if (NULL != *ub_sig)
1590 {
1592 *ub_sig = NULL;
1593 }
1594}
1595
1596
1600 ub_sig)
1601{
1603 .parser = &parse_unblinded_sig,
1604 .cleaner = &clean_unblinded_sig,
1605 .field = field,
1606 .ptr = ub_sig
1607 };
1608
1609 *ub_sig = NULL;
1610 return ret;
1611}
1612
1613
1614/* end of json_helper.c */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static int ret
Final status code.
Definition: gnunet-arm.c:93
static char * data
The data to insert into the dht.
static OpusEncoder * enc
OPUS encoder.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static char * res
Currently read line or NULL on EOF.
static struct GNUNET_SCHEDULER_Task * t
Main task.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
functions to parse JSON objects into GNUnet objects
#define GNUNET_JSON_spec_fixed_auto(name, obj)
Fixed size object (in network byte order, encoded using Crockford Base32hex encoding).
enum GNUNET_GenericReturnValue GNUNET_JSON_parse(const json_t *root, struct GNUNET_JSON_Specification *spec, const char **error_json_name, unsigned int *error_line)
Navigate and parse data in a JSON tree.
Definition: json.c:32
void GNUNET_CRYPTO_blinded_message_decref(struct GNUNET_CRYPTO_BlindedMessage *bm)
Decrement reference counter of a bm, and free it if it reaches zero.
#define GNUNET_log(kind,...)
void GNUNET_CRYPTO_rsa_signature_free(struct GNUNET_CRYPTO_RsaSignature *sig)
Free memory occupied by signature.
Definition: crypto_rsa.c:1015
struct GNUNET_CRYPTO_RsaSignature * GNUNET_CRYPTO_rsa_signature_decode(const void *buf, size_t buf_size)
Decode the signature from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:1063
GNUNET_CRYPTO_BlindSignatureAlgorithm
Types of public keys used for blind signatures.
struct GNUNET_CRYPTO_RsaPublicKey * GNUNET_CRYPTO_rsa_public_key_decode(const char *buf, size_t len)
Decode the public key from the data-format back to the "normal", internal format.
Definition: crypto_rsa.c:423
void GNUNET_CRYPTO_rsa_public_key_free(struct GNUNET_CRYPTO_RsaPublicKey *key)
Free memory occupied by the public key.
Definition: crypto_rsa.c:268
void GNUNET_CRYPTO_unblinded_sig_decref(struct GNUNET_CRYPTO_UnblindedSignature *ub_sig)
Decrement reference counter of a ub_sig, and free it if it reaches zero.
void GNUNET_CRYPTO_blinded_sig_decref(struct GNUNET_CRYPTO_BlindedSignature *blind_sig)
Decrement reference counter of a blind_sig, and free it if it reaches zero.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_CRYPTO_BSA_INVALID
Invalid type of signature.
@ GNUNET_CRYPTO_BSA_CS
Clause Blind Schnorr signature.
@ GNUNET_CRYPTO_BSA_RSA
RSA blind signature.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_WARNING
#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.
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data_alloc(const char *enc, size_t enclen, void **out, size_t *out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:878
enum GNUNET_GenericReturnValue GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:812
size_t GNUNET_STRINGS_base64_decode(const char *data, size_t len, void **output)
Decode from Base64.
Definition: strings.c:1701
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_TimestampNBO GNUNET_TIME_timestamp_hton(struct GNUNET_TIME_Timestamp t)
Convert timestamp to network byte order.
Definition: time.c:91
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_JSON_Specification GNUNET_JSON_spec_object_const(const char *name, const json_t **jsonp)
JSON object, reference counter not incremented.
Definition: json_helper.c:409
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_message(const char *name, struct GNUNET_CRYPTO_BlindedMessage **msg)
Specification for parsing a blinded message.
Definition: json_helper.c:1330
static enum GNUNET_GenericReturnValue parse_u32(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint32_t.
Definition: json_helper.c:669
static void clean_unblinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing unblinded signature.
Definition: json_helper.c:1583
static enum GNUNET_GenericReturnValue parse_blinded_sig(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a blinded signature.
Definition: json_helper.c:1357
struct GNUNET_JSON_Specification GNUNET_JSON_spec_varsize(const char *name, void **obj, size_t *size)
Variable size object (in network byte order, encoded using Crockford Base32hex encoding).
Definition: json_helper.c:258
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed(const char *name, void *obj, size_t size)
Variable size object (in network byte order, encoded using Crockford Base32hex encoding).
Definition: json_helper.c:117
static enum GNUNET_GenericReturnValue parse_u16(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint16_t.
Definition: json_helper.c:619
struct GNUNET_JSON_Specification GNUNET_JSON_spec_end()
End of a parser specification.
Definition: json_helper.c:33
static enum GNUNET_GenericReturnValue parse_i64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a int64_t.
Definition: json_helper.c:764
static enum GNUNET_GenericReturnValue parse_blinded_message(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a blinded message.
Definition: json_helper.c:1216
static enum GNUNET_GenericReturnValue parse_rsa_signature(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA signature.
Definition: json_helper.c:1085
static enum GNUNET_GenericReturnValue parse_double(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a double.
Definition: json_helper.c:526
struct GNUNET_JSON_Specification GNUNET_JSON_spec_json(const char *name, json_t **jsonp)
JSON object or array.
Definition: json_helper.c:365
static enum GNUNET_GenericReturnValue parse_unblinded_sig(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to unblinded signature.
Definition: json_helper.c:1490
static void clean_rsa_public_key(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA public key.
Definition: json_helper.c:1047
struct GNUNET_JSON_Specification GNUNET_JSON_spec_blinded_signature(const char *field, struct GNUNET_CRYPTO_BlindedSignature **b_sig)
Specification for parsing a blinded signature.
Definition: json_helper.c:1465
static void clean_rsa_signature(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing RSA signature.
Definition: json_helper.c:1132
struct GNUNET_JSON_Specification GNUNET_JSON_spec_boolean(const char *name, int *boolean)
Boolean (true mapped to GNUNET_YES, false mapped to GNUNET_NO).
Definition: json_helper.c:1190
static enum GNUNET_GenericReturnValue parse_timestamp(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a timestamp.
Definition: json_helper.c:811
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_public_key(const char *name, struct GNUNET_CRYPTO_RsaPublicKey **pk)
Specification for parsing an RSA public key.
Definition: json_helper.c:1061
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint16(const char *name, uint16_t *u16)
16-bit integer.
Definition: json_helper.c:643
static enum GNUNET_GenericReturnValue parse_u8(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint8_t.
Definition: json_helper.c:569
static enum GNUNET_GenericReturnValue parse_timestamp_nbo(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to absolute time.
Definition: json_helper.c:885
static void clean_blinded_message(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded message.
Definition: json_helper.c:1315
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp_nbo(const char *name, struct GNUNET_TIME_TimestampNBO *at)
Timestamp in network byte order.
Definition: json_helper.c:907
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint32(const char *name, uint32_t *u32)
32-bit integer.
Definition: json_helper.c:693
static enum GNUNET_GenericReturnValue parse_string(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to string.
Definition: json_helper.c:287
struct GNUNET_JSON_Specification GNUNET_JSON_spec_string(const char *name, const char **strptr)
The expected field stores a string.
Definition: json_helper.c:306
struct GNUNET_JSON_Specification GNUNET_JSON_spec_double(const char *name, double *f)
double.
Definition: json_helper.c:543
static enum GNUNET_GenericReturnValue parse_object_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:392
struct GNUNET_JSON_Specification GNUNET_JSON_spec_int64(const char *name, int64_t *i64)
64-bit signed integer.
Definition: json_helper.c:783
static enum GNUNET_GenericReturnValue parse_boolean(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to an int as a boolean.
Definition: json_helper.c:1173
static enum GNUNET_CRYPTO_BlindSignatureAlgorithm string_to_cipher(const char *cipher_s)
Convert string value to numeric cipher value.
Definition: json_helper.c:52
struct GNUNET_JSON_Specification GNUNET_JSON_spec_rsa_signature(const char *name, struct GNUNET_CRYPTO_RsaSignature **sig)
Specification for parsing an RSA signature.
Definition: json_helper.c:1146
static enum GNUNET_GenericReturnValue parse_fixed64_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:144
static void clean_blinded_sig(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing blinded sig.
Definition: json_helper.c:1449
static void clean_json(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing JSON object.
Definition: json_helper.c:351
struct GNUNET_JSON_Specification GNUNET_JSON_spec_timestamp(const char *name, struct GNUNET_TIME_Timestamp *t)
Timestamp.
Definition: json_helper.c:862
static enum GNUNET_GenericReturnValue parse_array_const(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON to a JSON array.
Definition: json_helper.c:435
struct GNUNET_JSON_Specification GNUNET_JSON_spec_unblinded_signature(const char *field, struct GNUNET_CRYPTO_UnblindedSignature **ub_sig)
Specification for parsing an unblinded signature.
Definition: json_helper.c:1598
static enum GNUNET_GenericReturnValue parse_fixed_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to fixed size data.
Definition: json_helper.c:77
struct GNUNET_JSON_Specification GNUNET_JSON_spec_array_const(const char *name, const json_t **jsonp)
JSON array, reference counter not incremented.
Definition: json_helper.c:452
struct GNUNET_JSON_Specification GNUNET_JSON_spec_fixed64(const char *name, void *obj, size_t size)
Variable size object (in network byte order, encoded using base64 encoding).
Definition: json_helper.c:181
static enum GNUNET_GenericReturnValue parse_u64(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a uint64_t.
Definition: json_helper.c:719
static enum GNUNET_GenericReturnValue parse_bool(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a bool.
Definition: json_helper.c:478
struct GNUNET_JSON_Specification GNUNET_JSON_spec_bool(const char *name, bool *b)
boolean.
Definition: json_helper.c:500
struct GNUNET_JSON_Specification GNUNET_JSON_spec_relative_time(const char *name, struct GNUNET_TIME_Relative *rt)
Relative time.
Definition: json_helper.c:977
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint8(const char *name, uint8_t *u8)
8-bit integer.
Definition: json_helper.c:593
struct GNUNET_JSON_Specification GNUNET_JSON_spec_uint64(const char *name, uint64_t *u64)
64-bit integer.
Definition: json_helper.c:738
static enum GNUNET_GenericReturnValue parse_rel_time(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to relative time.
Definition: json_helper.c:930
static enum GNUNET_GenericReturnValue parse_json(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to a JSON object.
Definition: json_helper.c:329
static enum GNUNET_GenericReturnValue parse_rsa_public_key(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to RSA public key.
Definition: json_helper.c:1000
static void clean_variable_data(void *cls, struct GNUNET_JSON_Specification *spec)
Cleanup data left from parsing variable size data.
Definition: json_helper.c:244
static enum GNUNET_GenericReturnValue parse_variable_data(void *cls, json_t *root, struct GNUNET_JSON_Specification *spec)
Parse given JSON object to variable size data.
Definition: json_helper.c:208
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define SIZE_MAX
Definition: platform.h:208
Blinded message ready for blind signing.
unsigned int rc
Reference counter.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the sign blinded message.
struct GNUNET_CRYPTO_CsBlindedMessage cs_blinded_message
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedMessage::@18 details
Details, depending on cipher.
struct GNUNET_CRYPTO_RsaBlindedMessage rsa_blinded_message
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
Type for blinded signatures.
unsigned int rc
Reference counter.
struct GNUNET_CRYPTO_CsBlindSignature blinded_cs_answer
If we use GNUNET_CRYPTO_BSA_CS in cipher.
union GNUNET_CRYPTO_BlindedSignature::@15 details
Details, depending on cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
struct GNUNET_CRYPTO_RsaSignature * blinded_rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int b
To make ROS problem harder, the signer chooses an unpredictable b and only calculates signature of c_...
struct GNUNET_CRYPTO_CsC c[2]
The Clause Schnorr c_0 and c_1 containing the blinded message.
struct GNUNET_CRYPTO_CsSessionNonce nonce
Nonce used in initial request.
size_t blinded_msg_size
Size of the blinded_msg to be signed.
void * blinded_msg
Blinded message to be signed Note: is malloc()'ed!
The public information of an RSA key pair.
Definition: crypto_rsa.c:53
an RSA signature
Definition: crypto_rsa.c:65
Type of (unblinded) signatures.
struct GNUNET_CRYPTO_RsaSignature * rsa_signature
If we use GNUNET_CRYPTO_BSA_RSA in cipher.
unsigned int rc
Reference counter.
union GNUNET_CRYPTO_UnblindedSignature::@14 details
Details, depending on cipher.
struct GNUNET_CRYPTO_CsSignature cs_signature
If we use GNUNET_CRYPTO_BSA_CS in cipher.
enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher
Type of the signature.
Entry in parser specification for GNUNET_JSON_parse().
void * ptr
Pointer, details specific to the parser.
const char * field
Name of the field to parse, use NULL to get the JSON of the main object instead of the JSON of an ind...
size_t ptr_size
Number of bytes available in ptr.
size_t * size_ptr
Where should we store the final size of ptr.
void * cls
Closure for parser and cleaner.
GNUNET_JSON_Parser parser
Function for how to parse this type of entry.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Time for timestamps used by GNUnet, in seconds and in network byte order.
Time for timestamps used by GNUnet, in microseconds rounded to seconds.
struct GNUNET_TIME_Absolute abs_time
The actual value.