GNUnet 0.21.2
identity_plugin.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2015 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_rest_plugin.h"
30#include "gnunet_rest_lib.h"
31#include "../../service/identity/identity.h"
32#include "gnunet_util_lib.h"
33#include "microhttpd.h"
34#include <jansson.h>
35
39#define GNUNET_REST_API_NS_IDENTITY "/identity"
40
44#define GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey"
45
49#define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name"
50
54#define GNUNET_REST_API_NS_SIGN "/sign"
55
59#define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey"
60
64#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey"
65
69#define GNUNET_REST_IDENTITY_PARAM_NAME "name"
70
74#define GNUNET_REST_IDENTITY_PARAM_TYPE "type"
75
79#define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname"
80
84#define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name"
85
89#define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key"
90
94#define GNUNET_REST_ERROR_NO_DATA "No data"
95
99#define GNUNET_REST_ERROR_DATA_INVALID "Data invalid"
100
104#define ID_REST_STATE_INIT 0
105
109#define ID_REST_STATE_POST_INIT 1
110
115
119static char *allow_methods;
120
124static struct EgoEntry *ego_head;
125
129static struct EgoEntry *ego_tail;
130
134static int state;
135
140
144struct Plugin
145{
146 const struct GNUNET_CONFIGURATION_Handle *cfg;
147};
148
152struct EgoEntry
153{
157 struct EgoEntry *next;
158
162 struct EgoEntry *prev;
163
167 char *identifier;
168
173
177 struct GNUNET_IDENTITY_Ego *ego;
178};
179
183struct RequestHandle
184{
188 struct RequestHandle *next;
189
193 struct RequestHandle *prev;
194
198 const char *data;
199
203 char *name;
204
208 size_t data_size;
209
214
219
224
229
234
238 void *proc_cls;
239
243 char *url;
244
249};
250
255
260
265static void
266cleanup_handle (void *cls)
267{
268 struct RequestHandle *handle = cls;
269
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
271 if (NULL != handle->timeout_task)
272 {
273 GNUNET_SCHEDULER_cancel (handle->timeout_task);
274 handle->timeout_task = NULL;
275 }
276
277 if (NULL != handle->url)
278 GNUNET_free (handle->url);
279 if (NULL != handle->name)
280 GNUNET_free (handle->name);
283 handle);
285}
286
287
293static void
294do_error (void *cls)
295{
296 struct RequestHandle *handle = cls;
297 struct MHD_Response *resp;
298 json_t *json_error = json_object ();
299 char *response;
300 int response_code;
301
302 json_object_set_new (json_error, "error",
303 json_string (GNUNET_ErrorCode_get_hint (handle->ec)));
304 json_object_set_new (json_error, "error_code", json_integer (handle->ec));
305 response_code = GNUNET_ErrorCode_get_http_status (handle->ec);
306 if (0 == response_code)
307 response_code = MHD_HTTP_OK;
308 response = json_dumps (json_error, 0);
310 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
311 "Content-Type",
312 "application/json"));
313 handle->proc (handle->proc_cls, resp, response_code);
314 json_decref (json_error);
317}
318
319
329struct EgoEntry *
331{
332 struct EgoEntry *ego_entry;
333
334 if (NULL != pubkey)
335 {
336 for (ego_entry = ego_head; NULL != ego_entry;
337 ego_entry = ego_entry->next)
338 {
339 if (0 != strcasecmp (pubkey, ego_entry->keystring))
340 continue;
341 return ego_entry;
342 }
343 }
344 if (NULL != name)
345 {
346 for (ego_entry = ego_head; NULL != ego_entry;
347 ego_entry = ego_entry->next)
348 {
349 if (0 != strcasecmp (name, ego_entry->identifier))
350 continue;
351 return ego_entry;
352 }
353 }
354 return NULL;
355}
356
357
365void
367 const char *url,
368 void *cls)
369{
370 struct RequestHandle *handle = cls;
371 struct EgoEntry *ego_entry;
372 struct MHD_Response *resp;
373 struct GNUNET_HashCode key;
374 json_t *json_root;
375 json_t *json_ego;
376 char *result_str;
377 char *privkey_str;
378
379 json_root = json_array ();
380 // Return ego/egos
381 for (ego_entry = ego_head; NULL != ego_entry;
382 ego_entry = ego_entry->next)
383 {
384 json_ego = json_object ();
385 json_object_set_new (json_ego,
387 json_string (ego_entry->keystring));
388 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
389 if (GNUNET_YES ==
391 handle->rest_handle->url_param_map, &key))
392 {
395 json_object_set_new (json_ego,
397 json_string (privkey_str));
398 GNUNET_free (privkey_str);
399 }
400
401 json_object_set_new (json_ego,
403 json_string (ego_entry->identifier));
404 json_array_append (json_root, json_ego);
405 json_decref (json_ego);
406 }
407
408 result_str = json_dumps (json_root, 0);
409 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
410 resp = GNUNET_REST_create_response (result_str);
411 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
412 "Content-Type",
413 "application/json"));
414 json_decref (json_root);
415 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
416 GNUNET_free (result_str);
418}
419
420
427void
428ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
429{
430 struct MHD_Response *resp;
431 struct GNUNET_HashCode key;
432 json_t *json_ego;
433 char *result_str;
434 char *privkey_str;
435
436 json_ego = json_object ();
437 json_object_set_new (json_ego,
439 json_string (ego_entry->keystring));
440 json_object_set_new (json_ego,
442 json_string (ego_entry->identifier));
443 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
444 if (GNUNET_YES ==
446 handle->rest_handle->url_param_map, &key))
447 {
450 json_object_set_new (json_ego,
452 json_string (privkey_str));
453 GNUNET_free (privkey_str);
454 }
455
456 result_str = json_dumps (json_ego, 0);
457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
458 resp = GNUNET_REST_create_response (result_str);
459 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
460 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
461 "Content-Type",
462 "application/json"));
463 json_decref (json_ego);
464 GNUNET_free (result_str);
466}
467
468
476void
478 const char *url,
479 void *cls)
480{
481 struct RequestHandle *handle = cls;
482 struct EgoEntry *ego_entry;
483 char *keystring;
484
485 keystring = NULL;
486
487 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
488 {
491 return;
492 }
494 ego_entry = get_egoentry (handle, keystring, NULL);
495
496 if (NULL == ego_entry)
497 {
500 return;
501 }
502
503 ego_get_response (handle, ego_entry);
504}
505
506
514void
516 const char *url,
517 void *cls)
518{
519 struct RequestHandle *handle = cls;
520 struct EgoEntry *ego_entry;
521 char *egoname;
522
523 egoname = NULL;
524
525 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
526 {
529 return;
530 }
531 egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
532 ego_entry = get_egoentry (handle, NULL, egoname);
533
534 if (NULL == ego_entry)
535 {
538 return;
539 }
540
541 ego_get_response (handle, ego_entry);
542}
543
544
551static void
552do_finished (void *cls, enum GNUNET_ErrorCode ec)
553{
554 struct RequestHandle *handle = cls;
555 struct MHD_Response *resp;
556 int response_code;
557
558 handle->op = NULL;
559 handle->ec = ec;
560 if (GNUNET_EC_NONE != ec)
561 {
563 return;
564 }
565 if (GNUNET_EC_NONE == handle->ec)
566 response_code = MHD_HTTP_NO_CONTENT;
567 else
568 response_code = GNUNET_ErrorCode_get_http_status (ec);
569 resp = GNUNET_REST_create_response (NULL);
570 handle->proc (handle->proc_cls, resp, response_code);
572}
573
574
582static void
584 const struct GNUNET_CRYPTO_PrivateKey *pk,
585 enum GNUNET_ErrorCode ec)
586{
587 struct RequestHandle *handle = cls;
588
589 (void) pk;
591}
592
593
600void
602{
603 json_t *data_js;
604 json_error_t err;
605 char *newname;
606 char term_data[handle->data_size + 1];
607 int json_state;
608
609 // if no data
610 if (0 >= handle->data_size)
611 {
614 return;
615 }
616 // if not json
617 term_data[handle->data_size] = '\0';
618 GNUNET_memcpy (term_data, handle->data, handle->data_size);
619 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
620
621 if (NULL == data_js)
622 {
625 return;
626 }
627
628 newname = NULL;
629 // NEW NAME
630 json_state = 0;
631 json_state = json_unpack (data_js,
632 "{s:s!}",
634 &newname);
635 // Change name with pubkey or name identifier
636 if (0 != json_state)
637 {
640 json_decref (data_js);
641 return;
642 }
643
644 if (NULL == newname)
645 {
648 json_decref (data_js);
649 return;
650 }
651
652 if (0 >= strlen (newname))
653 {
656 json_decref (data_js);
657 return;
658 }
659
662 newname,
664 handle);
665 if (NULL == handle->op)
666 {
669 json_decref (data_js);
670 return;
671 }
672 json_decref (data_js);
673 return;
674}
675
676
684void
686 const char *url,
687 void *cls)
688{
689 struct RequestHandle *handle = cls;
690 struct EgoEntry *ego_entry;
691 char *keystring;
692
693 keystring = NULL;
694
695 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
696 {
699 return;
700 }
702 ego_entry = get_egoentry (handle, keystring, NULL);
703
704 if (NULL == ego_entry)
705 {
708 return;
709 }
710
711 ego_edit (handle, ego_entry);
712}
713
714
722void
724 const char *url,
725 void *cls)
726{
727 struct RequestHandle *handle = cls;
728 struct EgoEntry *ego_entry;
729 char *name;
730
731 name = NULL;
732
733 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
734 {
737 return;
738 }
739 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
740 ego_entry = get_egoentry (handle, NULL, name);
741
742 if (NULL == ego_entry)
743 {
746 return;
747 }
748
749 ego_edit (handle, ego_entry);
750}
751
752
760void
762 const char *url,
763 void *cls)
764{
765 struct RequestHandle *handle = cls;
766 json_t *data_js;
767 json_error_t err;
768 char *egoname;
769 char *egotype;
770 char *privkey;
772 struct GNUNET_CRYPTO_PrivateKey *pk_ptr;
773 int json_unpack_state;
774 char term_data[handle->data_size + 1];
775
776 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
777 {
779 return;
780 }
781
782 if (0 >= handle->data_size)
783 {
786 return;
787 }
788 term_data[handle->data_size] = '\0';
789 GNUNET_memcpy (term_data, handle->data, handle->data_size);
790 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
791 if (NULL == data_js)
792 {
795 json_decref (data_js);
796 return;
797 }
798 json_unpack_state = 0;
799 privkey = NULL;
800 json_unpack_state =
801 json_unpack (data_js, "{s:s, s?:s, s?:s}",
805 if (0 != json_unpack_state)
806 {
809 json_decref (data_js);
810 return;
811 }
813 if ((NULL != egotype) && (0 == strcasecmp (egotype, "EDDSA")))
815 if (NULL == egoname)
816 {
819 json_decref (data_js);
820 return;
821 }
822 if (0 >= strlen (egoname))
823 {
825 json_decref (data_js);
827 return;
828 }
830 handle->name = GNUNET_strdup (egoname);
831 if (NULL != privkey)
832 {
834 strlen (privkey),
835 &pk,
836 sizeof(struct
838 pk_ptr = &pk;
839 }
840 else
841 pk_ptr = NULL;
842 json_decref (data_js);
844 handle->name,
845 pk_ptr,
846 type,
848 handle);
849}
850
851
859void
861 const char *url,
862 void *cls)
863{
864 struct RequestHandle *handle = cls;
865 struct EgoEntry *ego_entry;
866 char *keystring;
867
868 keystring = NULL;
869
870 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
871 {
874 return;
875 }
877 ego_entry = get_egoentry (handle, keystring, NULL);
878
879 if (NULL == ego_entry)
880 {
883 return;
884 }
885
887 ego_entry->identifier,
889 handle);
890}
891
892
900void
902 const char *url,
903 void *cls)
904{
905 struct RequestHandle *handle = cls;
906 struct EgoEntry *ego_entry;
907 char *name;
908
909 name = NULL;
910
911 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
912 {
915 return;
916 }
917 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
918 ego_entry = get_egoentry (handle, NULL, name);
919
920 if (NULL == ego_entry)
921 {
924 return;
925 }
926
928 ego_entry->identifier,
930 handle);
931}
932
933
935{
936 void *data;
938};
939
940void
941ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
942{
943 struct RequestHandle *handle = ((struct ego_sign_data_cls *) cls)->handle;
944 unsigned char *data
945 = (unsigned char *) ((struct ego_sign_data_cls *) cls)->data; // data is url decoded
946 struct MHD_Response *resp;
948 char *sig_str;
949 char *result;
950
951 if (ego == NULL)
952 {
955 return;
956 }
957
958 if (ntohl (ego->pk.type) != GNUNET_PUBLIC_KEY_TYPE_EDDSA)
959 {
962 return;
963 }
964
966 (void *) data,
967 strlen ( (char*) data),
968 &sig))
969 {
972 return;
973 }
974
976 sizeof (struct GNUNET_CRYPTO_EddsaSignature),
977 &sig_str);
978
980 "{\"signature\": \"%s\"}",
981 sig_str);
982
984 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
985
986 free (data);
987 free (sig_str);
988 free (result);
989 free (cls);
991}
992
993
1000void
1002 const char *url,
1003 void *cls)
1004{
1005 // TODO: replace with precompiler #define
1006 const char *username_key = "user";
1007 const char *data_key = "data";
1008
1009 struct RequestHandle *handle = cls;
1010 struct GNUNET_HashCode cache_key_username;
1011 struct GNUNET_HashCode cache_key_data;
1012 char *username;
1013 char *data;
1014
1015 struct ego_sign_data_cls *cls2;
1016
1017 GNUNET_CRYPTO_hash (username_key, strlen (username_key), &cache_key_username);
1018 GNUNET_CRYPTO_hash (data_key, strlen (data_key), &cache_key_data);
1019
1021 handle->rest_handle->url_param_map,
1022 &cache_key_username)) ||
1024 handle->rest_handle->url_param_map,
1025 &cache_key_data)))
1026 {
1029 return;
1030 }
1031
1032 username = (char *) GNUNET_CONTAINER_multihashmap_get (
1033 handle->rest_handle->url_param_map,
1034 &cache_key_username);
1035
1037 handle->rest_handle->url_param_map,
1038 &cache_key_data);
1039
1040 cls2 = malloc (sizeof(struct ego_sign_data_cls));
1041 cls2->data = (void *) GNUNET_strdup (data);
1042 cls2->handle = handle;
1043
1045 username,
1047 cls2);
1048}
1049
1050
1058static void
1060 const char *url,
1061 void *cls)
1062{
1063 struct MHD_Response *resp;
1064 struct RequestHandle *handle = cls;
1065
1066 // For now, independent of path return all options
1067 resp = GNUNET_REST_create_response (NULL);
1068 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1069 "Access-Control-Allow-Methods",
1070 allow_methods));
1071 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1073 return;
1074}
1075
1076
1077static void
1078list_ego (void *cls,
1079 struct GNUNET_IDENTITY_Ego *ego,
1080 void **ctx,
1081 const char *identifier)
1082{
1083 struct EgoEntry *ego_entry;
1085
1086 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1087 {
1089 return;
1090 }
1091 if (NULL == ego)
1092 {
1094 "Called with NULL ego\n");
1095 return;
1096 }
1098 {
1099 ego_entry = GNUNET_new (struct EgoEntry);
1102 ego_entry->ego = ego;
1103 ego_entry->identifier = GNUNET_strdup (identifier);
1105 ego_tail,
1106 ego_entry);
1107 }
1108 /* Ego renamed or added */
1109 if (identifier != NULL)
1110 {
1111 for (ego_entry = ego_head; NULL != ego_entry;
1112 ego_entry = ego_entry->next)
1113 {
1114 if (ego_entry->ego == ego)
1115 {
1116 /* Rename */
1117 GNUNET_free (ego_entry->identifier);
1118 ego_entry->identifier = GNUNET_strdup (identifier);
1119 break;
1120 }
1121 }
1122 if (NULL == ego_entry)
1123 {
1124 /* Add */
1125 ego_entry = GNUNET_new (struct EgoEntry);
1128 ego_entry->ego = ego;
1129 ego_entry->identifier = GNUNET_strdup (identifier);
1131 ego_tail,
1132 ego_entry);
1133 }
1134 }
1135 else
1136 {
1137 /* Delete */
1138 for (ego_entry = ego_head; NULL != ego_entry;
1139 ego_entry = ego_entry->next)
1140 {
1141 if (ego_entry->ego == ego)
1142 break;
1143 }
1144 if (NULL == ego_entry)
1145 return; /* Not found */
1146
1148 ego_tail,
1149 ego_entry);
1150 GNUNET_free (ego_entry->identifier);
1151 GNUNET_free (ego_entry->keystring);
1152 GNUNET_free (ego_entry);
1153 return;
1154 }
1155
1156}
1157
1158
1172 struct GNUNET_REST_RequestHandle *rest_handle,
1174 void *proc_cls)
1175{
1176 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1178 static const struct GNUNET_REST_RequestHandler handlers[] =
1179 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY,
1180 &ego_get_pubkey },
1181 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name },
1182 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all },
1183 { MHD_HTTP_METHOD_PUT,
1185 &ego_edit_pubkey },
1186 { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name },
1187 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create },
1188 { MHD_HTTP_METHOD_DELETE,
1191 { MHD_HTTP_METHOD_DELETE,
1193 &ego_delete_name },
1194 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont },
1195 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_SIGN, &ego_sign_data},
1197
1198
1200 handle->proc_cls = proc_cls;
1201 handle->proc = proc;
1202 handle->rest_handle = rest_handle;
1203 handle->data = rest_handle->data;
1204 handle->data_size = rest_handle->data_size;
1205
1206 handle->url = GNUNET_strdup (rest_handle->url);
1207 if (handle->url[strlen (handle->url) - 1] == '/')
1208 handle->url[strlen (handle->url) - 1] = '\0';
1209 handle->timeout_task =
1213 handle);
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1215 if (GNUNET_NO ==
1216 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1217 {
1219 return GNUNET_NO;
1220 }
1221
1222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1223 return GNUNET_YES;
1224}
1225
1226
1233void *
1235{
1236 static struct Plugin plugin;
1237 struct GNUNET_REST_Plugin *api;
1238
1239 id_cfg = c;
1240 if (NULL != plugin.cfg)
1241 return NULL; /* can only initialize once! */
1242 memset (&plugin, 0, sizeof(struct Plugin));
1243 plugin.cfg = c;
1244 api = GNUNET_new (struct GNUNET_REST_Plugin);
1245 api->cls = &plugin;
1248 "%s, %s, %s, %s, %s",
1249 MHD_HTTP_METHOD_GET,
1250 MHD_HTTP_METHOD_POST,
1251 MHD_HTTP_METHOD_PUT,
1252 MHD_HTTP_METHOD_DELETE,
1253 MHD_HTTP_METHOD_OPTIONS);
1256
1257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1258 return api;
1259}
1260
1261
1268void
1270{
1271 struct Plugin *plugin = api->cls;
1272 struct EgoEntry *ego_entry;
1273 struct EgoEntry *ego_tmp;
1274
1275 plugin->cfg = NULL;
1276 while (NULL != requests_head)
1278 if (NULL != identity_handle)
1280
1281 for (ego_entry = ego_head; NULL != ego_entry;)
1282 {
1283 ego_tmp = ego_entry;
1284 ego_entry = ego_entry->next;
1285 GNUNET_free (ego_tmp->identifier);
1286 GNUNET_free (ego_tmp->keystring);
1287 GNUNET_free (ego_tmp);
1288 }
1289
1291 GNUNET_free (api);
1292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1293}
1294
1295
1296/* end of plugin_rest_identity.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static struct GNUNET_TESTING_PluginFunctions * plugin
Plugin to dynamically load a test case.
static struct MHD_Response * response
Our canonical response.
static char * data
The data to insert into the dht.
struct GNUNET_HashCode key
The key used in the DHT.
static char * egoname
Ego Attribute String.
Definition: gnunet-did.c:93
static struct GNUNET_FS_Handle * ctx
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static char * name
Name (label) of the records to list.
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
static uint32_t type
Type string converted to DNS type value.
static int result
Global testing status.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
Identity service; implements identity management for GNUnet.
API for helper library to parse/create REST.
GNUnet service REST plugin header.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_create(struct GNUNET_IDENTITY_Handle *id, const char *name, const struct GNUNET_CRYPTO_PrivateKey *privkey, enum GNUNET_CRYPTO_KeyType ktype, GNUNET_IDENTITY_CreateContinuation cont, void *cont_cls)
Create a new ego with the given name.
Definition: identity_api.c:561
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_rename(struct GNUNET_IDENTITY_Handle *id, const char *old_name, const char *new_name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Renames an existing ego.
Definition: identity_api.c:621
const struct GNUNET_CRYPTO_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:517
struct GNUNET_IDENTITY_Operation * GNUNET_IDENTITY_delete(struct GNUNET_IDENTITY_Handle *id, const char *name, GNUNET_IDENTITY_Continuation cb, void *cb_cls)
Delete an existing ego.
Definition: identity_api.c:674
struct GNUNET_IDENTITY_EgoLookup * GNUNET_IDENTITY_ego_lookup(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
Lookup an ego by name.
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:487
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:732
void GNUNET_IDENTITY_ego_get_public_key(struct GNUNET_IDENTITY_Ego *ego, struct GNUNET_CRYPTO_PublicKey *pk)
Get the identifier (public key) of an ego.
Definition: identity_api.c:529
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_raw(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, void *data, size_t size, struct GNUNET_CRYPTO_EddsaSignature *sig)
Definition: crypto_ecc.c:603
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:568
char * GNUNET_CRYPTO_private_key_to_string(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates a (Base32) string representation of the private key.
Definition: crypto_pkey.c:578
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_PUBLIC_KEY_TYPE_EDDSA
EDDSA identity.
@ GNUNET_PUBLIC_KEY_TYPE_ECDSA
The identity type.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
int GNUNET_REST_handle_request(struct GNUNET_REST_RequestHandle *conn, const struct GNUNET_REST_RequestHandler *handlers, struct GNUNET_REST_RequestHandlerError *err, void *cls)
Definition: rest.c:64
void(* GNUNET_REST_ResultProcessor)(void *cls, struct MHD_Response *resp, int status)
Iterator called on obtained result for a REST result.
#define GNUNET_REST_HANDLER_END
struct MHD_Response * GNUNET_REST_create_response(const char *data)
Create REST MHD response.
Definition: rest.c:44
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1305
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
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:789
size_t GNUNET_STRINGS_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1671
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:450
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
@ MHD_HTTP_NO_CONTENT
No Content [RFC7231, Section 6.3.5].
static struct EgoEntry * ego_tail
Ego list.
#define GNUNET_REST_IDENTITY_PARAM_NAME
Parameter name.
void REST_identity_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
struct EgoEntry * get_egoentry(struct RequestHandle *handle, char *pubkey, char *name)
Get EgoEntry from list with either a public key or a name If public key and name are not NULL,...
void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
void ego_sign_data(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
static void do_finished_create(void *cls, const struct GNUNET_CRYPTO_PrivateKey *pk, enum GNUNET_ErrorCode ec)
Processing finished, when creating an ego.
const struct GNUNET_CONFIGURATION_Handle * id_cfg
The configuration handle.
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
void ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request - responds with all identities.
void ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
void * REST_identity_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void do_finished(void *cls, enum GNUNET_ErrorCode ec)
Processing finished.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
void ego_edit_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with name.
#define ID_REST_STATE_INIT
State while collecting all egos.
#define GNUNET_REST_IDENTITY_PARAM_TYPE
Parameter type.
static struct RequestHandle * requests_head
DLL.
static void options_cont(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Respond to OPTIONS request.
enum GNUNET_GenericReturnValue REST_identity_process_request(void *plugin, struct GNUNET_REST_RequestHandle *rest_handle, GNUNET_REST_ResultProcessor proc, void *proc_cls)
Function processing the REST call.
#define GNUNET_REST_API_NS_SIGN
Identity Namespace with sign specifier.
static int state
The processing state.
static struct EgoEntry * ego_head
Ego list.
#define GNUNET_REST_API_NS_IDENTITY_NAME
Identity Namespace with public key specifier.
static void list_ego(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *identifier)
static char * allow_methods
HTTP methods allows for this plugin.
void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.
void ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
static struct RequestHandle * requests_tail
DLL.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
void ego_sign_data_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
#define ID_REST_STATE_POST_INIT
Done collecting egos.
#define GNUNET_REST_API_NS_IDENTITY_PUBKEY
Identity Namespace with public key specifier.
#define GNUNET_REST_IDENTITY_PARAM_PUBKEY
Parameter public key.
void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
static void do_error(void *cls)
Task run on errors.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
const char * GNUNET_ErrorCode_get_hint(enum GNUNET_ErrorCode ec)
Returns a hint for a given error code.
unsigned int GNUNET_ErrorCode_get_http_status(enum GNUNET_ErrorCode ec)
Return HTTP status for a given error code.
GNUNET_ErrorCode
Taler error codes.
@ GNUNET_EC_IDENTITY_INVALID
The given ego is invalid or malformed.
@ GNUNET_EC_UNKNOWN
Unknown and unspecified error.
@ GNUNET_EC_NONE
No error (success).
@ GNUNET_EC_IDENTITY_NOT_FOUND
Ego not found.
The default namestore ego.
char * identifier
Ego Identifier.
struct EgoEntry * prev
DLL.
char * keystring
Public key string.
struct EgoEntry * next
DLL.
struct GNUNET_IDENTITY_Ego * ego
The Ego.
void * cls
Closure for all of the callbacks.
an ECC signature using EdDSA.
A private key for an identity as per LSD0001.
uint32_t type
Type of public key.
struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key
AN EdDSA identtiy key.
An identity key as per LSD0001.
A 512-bit hashcode.
Handle for an ego.
Definition: identity.h:37
struct GNUNET_CRYPTO_PrivateKey pk
The identity key pair.
Definition: identity.h:51
Handle for the service.
Definition: identity_api.c:97
Handle for an operation with the identity service.
Definition: identity_api.c:41
struct returned by the initialization function of the plugin
char * name
Plugin name.
void * cls
The closure of the plugin.
const char * data
The POST data.
const char * url
The url as string.
size_t data_size
The POST data size.
void(* proc)(struct GNUNET_REST_RequestHandle *handle, const char *url, void *cls)
Namespace to handle.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for relative time used by GNUnet, in microseconds.
Handle for a plugin.
Definition: block.c:38
struct GNUNET_BLOCK_PluginFunctions * api
Plugin API.
Definition: block.c:47
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
The request handle.
Definition: config_plugin.c:46
enum GNUNET_ErrorCode ec
Error code.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
struct RequestHandle * prev
DLL.
Definition: config_plugin.c:55
size_t data_size
the length of the REST data
struct EgoEntry * ego_entry
IDENTITY Operation.
struct GNUNET_SCHEDULER_Task * timeout_task
ID of a task associated with the resolution process.
Definition: gns_plugin.c:122
void * proc_cls
The closure of the result processor.
Definition: config_plugin.c:70
GNUNET_REST_ResultProcessor proc
The plugin result processor.
Definition: config_plugin.c:65
struct RequestHandle * next
DLL.
Definition: config_plugin.c:50
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
Definition: config_plugin.c:60
char * name
Name to look up.
Definition: gns_plugin.c:102
char * url
The URL.
Definition: config_plugin.c:80
const char * data
The data from the REST request.
struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gns_plugin.c:117
struct RequestHandle * handle