GNUnet 0.22.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#include "identity_plugin.h"
36
40#define GNUNET_REST_API_NS_IDENTITY "/identity"
41
45#define GNUNET_REST_API_NS_IDENTITY_PUBKEY "/identity/pubkey"
46
50#define GNUNET_REST_API_NS_IDENTITY_NAME "/identity/name"
51
55#define GNUNET_REST_API_NS_SIGN "/sign"
56
60#define GNUNET_REST_IDENTITY_PARAM_PUBKEY "pubkey"
61
65#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY "privkey"
66
70#define GNUNET_REST_IDENTITY_PARAM_NAME "name"
71
75#define GNUNET_REST_IDENTITY_PARAM_TYPE "type"
76
80#define GNUNET_REST_IDENTITY_PARAM_NEWNAME "newname"
81
85#define GNUNET_REST_IDENTITY_MISSING_NAME "Missing identity name"
86
90#define GNUNET_REST_IDENTITY_MISSING_PUBKEY "Missing identity public key"
91
95#define GNUNET_REST_ERROR_NO_DATA "No data"
96
100#define GNUNET_REST_ERROR_DATA_INVALID "Data invalid"
101
105#define ID_REST_STATE_INIT 0
106
110#define ID_REST_STATE_POST_INIT 1
111
116
120static char *allow_methods;
121
125static struct EgoEntry *ego_head;
126
130static struct EgoEntry *ego_tail;
131
135static int state;
136
141
145struct Plugin
146{
147 const struct GNUNET_CONFIGURATION_Handle *cfg;
148};
149
153struct EgoEntry
154{
158 struct EgoEntry *next;
159
163 struct EgoEntry *prev;
164
168 char *identifier;
169
174
178 struct GNUNET_IDENTITY_Ego *ego;
179};
180
184struct RequestHandle
185{
189 struct RequestHandle *next;
190
194 struct RequestHandle *prev;
195
199 const char *data;
200
204 char *name;
205
209 size_t data_size;
210
215
220
225
230
235
239 void *proc_cls;
240
244 char *url;
245
250
256 unsigned int success_code;
257};
258
263
268
273static void
274cleanup_handle (void *cls)
275{
276 struct RequestHandle *handle = cls;
277
278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
279 if (NULL != handle->timeout_task)
280 {
281 GNUNET_SCHEDULER_cancel (handle->timeout_task);
282 handle->timeout_task = NULL;
283 }
284
285 if (NULL != handle->url)
286 GNUNET_free (handle->url);
287 if (NULL != handle->name)
288 GNUNET_free (handle->name);
291 handle);
293}
294
295
301static void
302do_error (void *cls)
303{
304 struct RequestHandle *handle = cls;
305 struct MHD_Response *resp;
306 json_t *json_error = json_object ();
307 char *response;
308 int response_code;
309
310 json_object_set_new (json_error, "error",
311 json_string (GNUNET_ErrorCode_get_hint (handle->ec)));
312 json_object_set_new (json_error, "error_code", json_integer (handle->ec));
313 response_code = GNUNET_ErrorCode_get_http_status (handle->ec);
314 if (0 == response_code)
315 response_code = MHD_HTTP_OK;
316 response = json_dumps (json_error, 0);
318 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
319 "Content-Type",
320 "application/json"));
321 handle->proc (handle->proc_cls, resp, response_code);
322 json_decref (json_error);
325}
326
327
337static struct EgoEntry *
339{
340 struct EgoEntry *ego_entry;
341
342 if (NULL != pubkey)
343 {
344 for (ego_entry = ego_head; NULL != ego_entry;
345 ego_entry = ego_entry->next)
346 {
347 if (0 != strcasecmp (pubkey, ego_entry->keystring))
348 continue;
349 return ego_entry;
350 }
351 }
352 if (NULL != name)
353 {
354 for (ego_entry = ego_head; NULL != ego_entry;
355 ego_entry = ego_entry->next)
356 {
357 if (0 != strcasecmp (name, ego_entry->identifier))
358 continue;
359 return ego_entry;
360 }
361 }
362 return NULL;
363}
364
365
373static void
375 const char *url,
376 void *cls)
377{
378 struct RequestHandle *handle = cls;
379 struct EgoEntry *ego_entry;
380 struct MHD_Response *resp;
381 struct GNUNET_HashCode key;
382 json_t *json_root;
383 json_t *json_ego;
384 char *result_str;
385 char *privkey_str;
386
387 json_root = json_array ();
388 // Return ego/egos
389 for (ego_entry = ego_head; NULL != ego_entry;
390 ego_entry = ego_entry->next)
391 {
392 json_ego = json_object ();
393 json_object_set_new (json_ego,
395 json_string (ego_entry->keystring));
396 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
397 if (GNUNET_YES ==
399 handle->rest_handle->url_param_map, &key))
400 {
403 json_object_set_new (json_ego,
405 json_string (privkey_str));
406 GNUNET_free (privkey_str);
407 }
408
409 json_object_set_new (json_ego,
411 json_string (ego_entry->identifier));
412 json_array_append (json_root, json_ego);
413 json_decref (json_ego);
414 }
415
416 result_str = json_dumps (json_root, 0);
417 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
418 resp = GNUNET_REST_create_response (result_str);
419 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
420 "Content-Type",
421 "application/json"));
422 json_decref (json_root);
423 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
424 GNUNET_free (result_str);
426}
427
428
435static void
436ego_get_response (struct RequestHandle *handle, struct EgoEntry *ego_entry)
437{
438 struct MHD_Response *resp;
439 struct GNUNET_HashCode key;
440 json_t *json_ego;
441 char *result_str;
442 char *privkey_str;
443
444 json_ego = json_object ();
445 json_object_set_new (json_ego,
447 json_string (ego_entry->keystring));
448 json_object_set_new (json_ego,
450 json_string (ego_entry->identifier));
451 GNUNET_CRYPTO_hash ("private", strlen ("private"), &key);
452 if (GNUNET_YES ==
454 handle->rest_handle->url_param_map, &key))
455 {
458 json_object_set_new (json_ego,
460 json_string (privkey_str));
461 GNUNET_free (privkey_str);
462 }
463
464 result_str = json_dumps (json_ego, 0);
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
466 resp = GNUNET_REST_create_response (result_str);
467 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
468 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
469 "Content-Type",
470 "application/json"));
471 json_decref (json_ego);
472 GNUNET_free (result_str);
474}
475
476
484static void
486 const char *url,
487 void *cls)
488{
489 struct RequestHandle *handle = cls;
490 struct EgoEntry *ego_entry;
491 char *keystring;
492
493 keystring = NULL;
494
495 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
496 {
499 return;
500 }
502 ego_entry = get_egoentry (handle, keystring, NULL);
503
504 if (NULL == ego_entry)
505 {
508 return;
509 }
510
511 ego_get_response (handle, ego_entry);
512}
513
514
522static void
524 const char *url,
525 void *cls)
526{
527 struct RequestHandle *handle = cls;
528 struct EgoEntry *ego_entry;
529 char *egoname;
530
531 egoname = NULL;
532
533 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
534 {
537 return;
538 }
539 egoname = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
540 ego_entry = get_egoentry (handle, NULL, egoname);
541
542 if (NULL == ego_entry)
543 {
546 return;
547 }
548
549 ego_get_response (handle, ego_entry);
550}
551
552
559static void
560do_finished (void *cls, enum GNUNET_ErrorCode ec)
561{
562 struct RequestHandle *handle = cls;
563 struct MHD_Response *resp;
564 int response_code;
565
566 handle->op = NULL;
567 handle->ec = ec;
568 if (GNUNET_EC_NONE != handle->ec)
569 {
571 return;
572 }
573
574 if (0 != handle->success_code)
575 response_code = handle->success_code;
576 else
577 response_code = MHD_HTTP_OK;
578
579 resp = GNUNET_REST_create_response (NULL);
580 handle->proc (handle->proc_cls, resp, response_code);
582}
583
584
592static void
594 const struct GNUNET_CRYPTO_PrivateKey *pk,
595 enum GNUNET_ErrorCode ec)
596{
597 struct RequestHandle *handle = cls;
598
599 (void) pk;
601}
602
603
610static void
612{
613 json_t *data_js;
614 json_error_t err;
615 char *newname;
616 char term_data[handle->data_size + 1];
617 int json_state;
618
619 // if no data
620 if (0 >= handle->data_size)
621 {
624 return;
625 }
626 // if not json
627 term_data[handle->data_size] = '\0';
628 GNUNET_memcpy (term_data, handle->data, handle->data_size);
629 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
630
631 if (NULL == data_js)
632 {
635 return;
636 }
637
638 newname = NULL;
639 // NEW NAME
640 json_state = 0;
641 json_state = json_unpack (data_js,
642 "{s:s!}",
644 &newname);
645 // Change name with pubkey or name identifier
646 if (0 != json_state)
647 {
650 json_decref (data_js);
651 return;
652 }
653
654 if (NULL == newname)
655 {
658 json_decref (data_js);
659 return;
660 }
661
662 if (0 >= strlen (newname))
663 {
666 json_decref (data_js);
667 return;
668 }
669
670 handle->success_code = MHD_HTTP_NO_CONTENT;
673 newname,
675 handle);
676 if (NULL == handle->op)
677 {
680 json_decref (data_js);
681 return;
682 }
683 json_decref (data_js);
684 return;
685}
686
687
695static void
697 const char *url,
698 void *cls)
699{
700 struct RequestHandle *handle = cls;
701 struct EgoEntry *ego_entry;
702 char *keystring;
703
704 keystring = NULL;
705
706 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
707 {
710 return;
711 }
713 ego_entry = get_egoentry (handle, keystring, NULL);
714
715 if (NULL == ego_entry)
716 {
719 return;
720 }
721
722 ego_edit (handle, ego_entry);
723}
724
725
733static void
735 const char *url,
736 void *cls)
737{
738 struct RequestHandle *handle = cls;
739 struct EgoEntry *ego_entry;
740 char *name;
741
742 name = NULL;
743
744 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
745 {
748 return;
749 }
750 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
751 ego_entry = get_egoentry (handle, NULL, name);
752
753 if (NULL == ego_entry)
754 {
757 return;
758 }
759
760 ego_edit (handle, ego_entry);
761}
762
763
771static void
773 const char *url,
774 void *cls)
775{
776 struct RequestHandle *handle = cls;
777 json_t *data_js;
778 json_error_t err;
779 char *egoname;
780 char *egotype;
781 char *privkey;
783 struct GNUNET_CRYPTO_PrivateKey *pk_ptr;
784 int json_unpack_state;
785 int type;
786 char term_data[handle->data_size + 1];
787
788 if (strlen (GNUNET_REST_API_NS_IDENTITY) != strlen (handle->url))
789 {
791 return;
792 }
793
794 if (0 >= handle->data_size)
795 {
798 return;
799 }
800 term_data[handle->data_size] = '\0';
801 GNUNET_memcpy (term_data, handle->data, handle->data_size);
802 data_js = json_loads (term_data, JSON_DECODE_ANY, &err);
803 if (NULL == data_js)
804 {
807 json_decref (data_js);
808 return;
809 }
810 json_unpack_state = 0;
811 privkey = NULL;
812 json_unpack_state =
813 json_unpack (data_js, "{s:s, s?:s, s?:s}",
817 if (0 != json_unpack_state)
818 {
821 json_decref (data_js);
822 return;
823 }
825 if ((NULL != egotype) && (0 == strcasecmp (egotype, "EDDSA")))
827 if (NULL == egoname)
828 {
831 json_decref (data_js);
832 return;
833 }
834 if (0 >= strlen (egoname))
835 {
837 json_decref (data_js);
839 return;
840 }
842 handle->name = GNUNET_strdup (egoname);
843 if (NULL != privkey)
844 {
846 strlen (privkey),
847 &pk,
848 sizeof(struct
850 pk_ptr = &pk;
851 }
852 else
853 pk_ptr = NULL;
854 json_decref (data_js);
855 handle->success_code = MHD_HTTP_CREATED;
857 handle->name,
858 pk_ptr,
859 type,
861 handle);
862}
863
864
872static void
874 const char *url,
875 void *cls)
876{
877 struct RequestHandle *handle = cls;
878 struct EgoEntry *ego_entry;
879 char *keystring;
880
881 keystring = NULL;
882
883 if (strlen (GNUNET_REST_API_NS_IDENTITY_PUBKEY) >= strlen (handle->url))
884 {
887 return;
888 }
890 ego_entry = get_egoentry (handle, keystring, NULL);
891
892 if (NULL == ego_entry)
893 {
896 return;
897 }
898
899 handle->success_code = MHD_HTTP_NO_CONTENT;
901 ego_entry->identifier,
903 handle);
904}
905
906
914static void
916 const char *url,
917 void *cls)
918{
919 struct RequestHandle *handle = cls;
920 struct EgoEntry *ego_entry;
921 char *name;
922
923 name = NULL;
924
925 if (strlen (GNUNET_REST_API_NS_IDENTITY_NAME) >= strlen (handle->url))
926 {
929 return;
930 }
931 name = &handle->url[strlen (GNUNET_REST_API_NS_IDENTITY_NAME) + 1];
932 ego_entry = get_egoentry (handle, NULL, name);
933
934 if (NULL == ego_entry)
935 {
938 return;
939 }
940
941 handle->success_code = MHD_HTTP_NO_CONTENT;
943 ego_entry->identifier,
945 handle);
946}
947
948
950{
951 void *data;
953};
954
955static void
956ego_sign_data_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
957{
958 struct RequestHandle *handle = ((struct ego_sign_data_cls *) cls)->handle;
959 unsigned char *data
960 = (unsigned char *) ((struct ego_sign_data_cls *) cls)->data; // data is url decoded
961 struct MHD_Response *resp;
963 char *sig_str;
964 char *result;
965
966 if (ego == NULL)
967 {
970 return;
971 }
972
973 if (ntohl (ego->pk.type) != GNUNET_PUBLIC_KEY_TYPE_EDDSA)
974 {
977 return;
978 }
979
981 (void *) data,
982 strlen ( (char*) data),
983 &sig))
984 {
987 return;
988 }
989
991 sizeof (struct GNUNET_CRYPTO_EddsaSignature),
992 &sig_str);
993
995 "{\"signature\": \"%s\"}",
996 sig_str);
997
999 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1000
1001 free (data);
1002 free (sig_str);
1003 free (result);
1004 free (cls);
1006}
1007
1008
1015static void
1017 const char *url,
1018 void *cls)
1019{
1020 // TODO: replace with precompiler #define
1021 const char *username_key = "user";
1022 const char *data_key = "data";
1023
1024 struct RequestHandle *handle = cls;
1025 struct GNUNET_HashCode cache_key_username;
1026 struct GNUNET_HashCode cache_key_data;
1027 char *username;
1028 char *data;
1029
1030 struct ego_sign_data_cls *cls2;
1031
1032 GNUNET_CRYPTO_hash (username_key, strlen (username_key), &cache_key_username);
1033 GNUNET_CRYPTO_hash (data_key, strlen (data_key), &cache_key_data);
1034
1036 handle->rest_handle->url_param_map,
1037 &cache_key_username)) ||
1039 handle->rest_handle->url_param_map,
1040 &cache_key_data)))
1041 {
1044 return;
1045 }
1046
1047 username = (char *) GNUNET_CONTAINER_multihashmap_get (
1048 handle->rest_handle->url_param_map,
1049 &cache_key_username);
1050
1052 handle->rest_handle->url_param_map,
1053 &cache_key_data);
1054
1055 cls2 = malloc (sizeof(struct ego_sign_data_cls));
1056 cls2->data = (void *) GNUNET_strdup (data);
1057 cls2->handle = handle;
1058
1060 username,
1062 cls2);
1063}
1064
1065
1073static void
1075 const char *url,
1076 void *cls)
1077{
1078 struct MHD_Response *resp;
1079 struct RequestHandle *handle = cls;
1080
1081 // For now, independent of path return all options
1082 resp = GNUNET_REST_create_response (NULL);
1083 GNUNET_assert (MHD_NO != MHD_add_response_header (resp,
1084 "Access-Control-Allow-Methods",
1085 allow_methods));
1086 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1088 return;
1089}
1090
1091
1092static void
1093list_ego (void *cls,
1094 struct GNUNET_IDENTITY_Ego *ego,
1095 void **ctx,
1096 const char *identifier)
1097{
1098 struct EgoEntry *ego_entry;
1100
1101 if ((NULL == ego) && (ID_REST_STATE_INIT == state))
1102 {
1104 return;
1105 }
1106 if (NULL == ego)
1107 {
1109 "Called with NULL ego\n");
1110 return;
1111 }
1113 {
1114 ego_entry = GNUNET_new (struct EgoEntry);
1117 ego_entry->ego = ego;
1118 ego_entry->identifier = GNUNET_strdup (identifier);
1120 ego_tail,
1121 ego_entry);
1122 }
1123 /* Ego renamed or added */
1124 if (identifier != NULL)
1125 {
1126 for (ego_entry = ego_head; NULL != ego_entry;
1127 ego_entry = ego_entry->next)
1128 {
1129 if (ego_entry->ego == ego)
1130 {
1131 /* Rename */
1132 GNUNET_free (ego_entry->identifier);
1133 ego_entry->identifier = GNUNET_strdup (identifier);
1134 break;
1135 }
1136 }
1137 if (NULL == ego_entry)
1138 {
1139 /* Add */
1140 ego_entry = GNUNET_new (struct EgoEntry);
1143 ego_entry->ego = ego;
1144 ego_entry->identifier = GNUNET_strdup (identifier);
1146 ego_tail,
1147 ego_entry);
1148 }
1149 }
1150 else
1151 {
1152 /* Delete */
1153 for (ego_entry = ego_head; NULL != ego_entry;
1154 ego_entry = ego_entry->next)
1155 {
1156 if (ego_entry->ego == ego)
1157 break;
1158 }
1159 if (NULL == ego_entry)
1160 return; /* Not found */
1161
1163 ego_tail,
1164 ego_entry);
1165 GNUNET_free (ego_entry->identifier);
1166 GNUNET_free (ego_entry->keystring);
1167 GNUNET_free (ego_entry);
1168 return;
1169 }
1170
1171}
1172
1173
1187 struct GNUNET_REST_RequestHandle *rest_handle,
1189 void *proc_cls)
1190{
1191 struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
1193 static const struct GNUNET_REST_RequestHandler handlers[] =
1194 { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_PUBKEY,
1195 &ego_get_pubkey },
1196 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_get_name },
1197 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY, &ego_get_all },
1198 { MHD_HTTP_METHOD_PUT,
1200 &ego_edit_pubkey },
1201 { MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_IDENTITY_NAME, &ego_edit_name },
1202 { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY, &ego_create },
1203 { MHD_HTTP_METHOD_DELETE,
1206 { MHD_HTTP_METHOD_DELETE,
1208 &ego_delete_name },
1209 { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY, &options_cont },
1210 { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_SIGN, &ego_sign_data},
1212
1213
1215 handle->proc_cls = proc_cls;
1216 handle->proc = proc;
1217 handle->rest_handle = rest_handle;
1218 handle->data = rest_handle->data;
1219 handle->data_size = rest_handle->data_size;
1220
1221 handle->url = GNUNET_strdup (rest_handle->url);
1222 if (handle->url[strlen (handle->url) - 1] == '/')
1223 handle->url[strlen (handle->url) - 1] = '\0';
1224 handle->timeout_task =
1228 handle);
1229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
1230 if (GNUNET_NO ==
1231 GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
1232 {
1234 return GNUNET_NO;
1235 }
1236
1237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
1238 return GNUNET_YES;
1239}
1240
1241
1248void *
1250{
1251 static struct Plugin plugin;
1252 struct GNUNET_REST_Plugin *api;
1253
1254 id_cfg = c;
1255 if (NULL != plugin.cfg)
1256 return NULL; /* can only initialize once! */
1257 memset (&plugin, 0, sizeof(struct Plugin));
1258 plugin.cfg = c;
1259 api = GNUNET_new (struct GNUNET_REST_Plugin);
1260 api->cls = &plugin;
1263 "%s, %s, %s, %s, %s",
1264 MHD_HTTP_METHOD_GET,
1265 MHD_HTTP_METHOD_POST,
1266 MHD_HTTP_METHOD_PUT,
1267 MHD_HTTP_METHOD_DELETE,
1268 MHD_HTTP_METHOD_OPTIONS);
1271
1272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _ ("Identity REST API initialized\n"));
1273 return api;
1274}
1275
1276
1283void
1285{
1286 struct Plugin *plugin = api->cls;
1287 struct EgoEntry *ego_entry;
1288 struct EgoEntry *ego_tmp;
1289
1290 plugin->cfg = NULL;
1291 while (NULL != requests_head)
1293 if (NULL != identity_handle)
1295
1296 for (ego_entry = ego_head; NULL != ego_entry;)
1297 {
1298 ego_tmp = ego_entry;
1299 ego_entry = ego_entry->next;
1300 GNUNET_free (ego_tmp->identifier);
1301 GNUNET_free (ego_tmp->keystring);
1302 GNUNET_free (ego_tmp);
1303 }
1304
1306 GNUNET_free (api);
1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Identity REST plugin is finished\n");
1308}
1309
1310
1311/* 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:92
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:604
#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:379
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:389
#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:980
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:1304
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:1277
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_base64url_encode(const void *in, size_t len, char **output)
Encode into Base64url.
Definition: strings.c:1648
enum GNUNET_GenericReturnValue GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:459
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
@ MHD_HTTP_OK
OK [RFC7231, Section 6.3.1].
@ MHD_HTTP_CREATED
Created [RFC7231, Section 6.3.2].
@ 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.
static void ego_sign_data(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
void REST_identity_done(struct GNUNET_REST_Plugin *api)
Exit point from the plugin.
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.
static void ego_edit_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity PUT request with public key.
static void ego_get_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a name.
#define GNUNET_REST_API_NS_IDENTITY
Identity Namespace.
void * REST_identity_init(const struct GNUNET_CONFIGURATION_Handle *c)
Entry point for the plugin.
static void ego_create(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity POST request.
static void do_finished(void *cls, enum GNUNET_ErrorCode ec)
Processing finished.
static void ego_delete_name(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with name.
#define GNUNET_REST_IDENTITY_PARAM_PRIVKEY
Parameter private key.
static void ego_edit(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Processing edit ego with EgoEntry ego_entry.
static void ego_get_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request with a public key.
#define ID_REST_STATE_INIT
State while collecting all egos.
#define GNUNET_REST_IDENTITY_PARAM_TYPE
Parameter type.
static void ego_get_all(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity GET request - responds with all identities.
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 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,...
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 void ego_get_response(struct RequestHandle *handle, struct EgoEntry *ego_entry)
Responds with the ego_entry identity.
static char * allow_methods
HTTP methods allows for this plugin.
static struct RequestHandle * requests_tail
DLL.
#define GNUNET_REST_IDENTITY_PARAM_NEWNAME
Parameter new name.
static struct GNUNET_IDENTITY_Handle * identity_handle
Handle to Identity service.
static void ego_sign_data_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego)
static 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_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.
static void do_error(void *cls)
Task run on errors.
static void cleanup_handle(void *cls)
Cleanup lookup handle.
static void ego_delete_pubkey(struct GNUNET_REST_RequestHandle *con_handle, const char *url, void *cls)
Handle identity DELETE request with public key.
#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
void * cls
The closure of the plugin.
const char * name
Plugin name.
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:47
enum GNUNET_ErrorCode ec
Error code.
struct GNUNET_IDENTITY_Operation * op
IDENTITY Operation.
struct RequestHandle * prev
DLL.
Definition: config_plugin.c:56
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:71
GNUNET_REST_ResultProcessor proc
The plugin result processor.
Definition: config_plugin.c:66
struct RequestHandle * next
DLL.
Definition: config_plugin.c:51
struct GNUNET_REST_RequestHandle * rest_handle
Handle to rest request.
Definition: config_plugin.c:61
char * name
Name to look up.
Definition: gns_plugin.c:102
char * url
The URL.
Definition: config_plugin.c:81
unsigned int success_code
Success http status code.
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