diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-10-06 19:31:46 +0200 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2017-10-06 19:31:46 +0200 |
commit | 8b22f677adfde6212410c5abb2aff27988cc997c (patch) | |
tree | d8b6e2bbb48edf875de4ca5284b48261bdab94a2 /src | |
parent | 371458b9ed084c6d510a03c9ea27cb8162f0e87a (diff) | |
download | gnunet-8b22f677adfde6212410c5abb2aff27988cc997c.tar.gz gnunet-8b22f677adfde6212410c5abb2aff27988cc997c.zip |
-readd new rest plugin
Diffstat (limited to 'src')
-rw-r--r-- | src/identity-provider/Makefile.am | 16 | ||||
-rw-r--r-- | src/identity-provider/plugin_rest_identity_provider.c | 632 | ||||
-rw-r--r-- | src/identity-provider/test_idp.conf | 2 | ||||
-rwxr-xr-x | src/identity-provider/test_idp_issue.sh | 2 |
4 files changed, 651 insertions, 1 deletions
diff --git a/src/identity-provider/Makefile.am b/src/identity-provider/Makefile.am index 0aabc2143..64a54457d 100644 --- a/src/identity-provider/Makefile.am +++ b/src/identity-provider/Makefile.am | |||
@@ -26,7 +26,8 @@ pkgcfg_DATA = \ | |||
26 | lib_LTLIBRARIES = \ | 26 | lib_LTLIBRARIES = \ |
27 | libgnunetidentityprovider.la | 27 | libgnunetidentityprovider.la |
28 | plugin_LTLIBRARIES = \ | 28 | plugin_LTLIBRARIES = \ |
29 | libgnunet_plugin_gnsrecord_identity_provider.la \ | 29 | libgnunet_plugin_rest_identity_provider.la \ |
30 | libgnunet_plugin_gnsrecord_identity_provider.la \ | ||
30 | $(SQLITE_PLUGIN) | 31 | $(SQLITE_PLUGIN) |
31 | 32 | ||
32 | bin_PROGRAMS = \ | 33 | bin_PROGRAMS = \ |
@@ -82,6 +83,19 @@ libgnunetidentityprovider_la_LDFLAGS = \ | |||
82 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 83 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
83 | -version-info 0:0:0 | 84 | -version-info 0:0:0 |
84 | 85 | ||
86 | libgnunet_plugin_rest_identity_provider_la_SOURCES = \ | ||
87 | plugin_rest_identity_provider.c | ||
88 | libgnunet_plugin_rest_identity_provider_la_LIBADD = \ | ||
89 | $(top_builddir)/src/identity/libgnunetidentity.la \ | ||
90 | libgnunetidentityprovider.la \ | ||
91 | $(top_builddir)/src/rest/libgnunetrest.la \ | ||
92 | $(top_builddir)/src/jsonapi/libgnunetjsonapi.la \ | ||
93 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ | ||
94 | $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ | ||
95 | $(LTLIBINTL) -ljansson -lmicrohttpd | ||
96 | libgnunet_plugin_rest_identity_provider_la_LDFLAGS = \ | ||
97 | $(GN_PLUGIN_LDFLAGS) | ||
98 | |||
85 | gnunet_idp_SOURCES = \ | 99 | gnunet_idp_SOURCES = \ |
86 | gnunet-idp.c | 100 | gnunet-idp.c |
87 | gnunet_idp_LDADD = \ | 101 | gnunet_idp_LDADD = \ |
diff --git a/src/identity-provider/plugin_rest_identity_provider.c b/src/identity-provider/plugin_rest_identity_provider.c new file mode 100644 index 000000000..b8fb3d1cb --- /dev/null +++ b/src/identity-provider/plugin_rest_identity_provider.c | |||
@@ -0,0 +1,632 @@ | |||
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 | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @author Martin Schanzenbach | ||
22 | * @file identity/plugin_rest_identity.c | ||
23 | * @brief GNUnet Namestore REST plugin | ||
24 | * | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_rest_plugin.h" | ||
29 | #include "gnunet_identity_service.h" | ||
30 | #include "gnunet_gns_service.h" | ||
31 | #include "gnunet_gnsrecord_lib.h" | ||
32 | #include "gnunet_namestore_service.h" | ||
33 | #include "gnunet_rest_lib.h" | ||
34 | #include "gnunet_jsonapi_lib.h" | ||
35 | #include "gnunet_jsonapi_util.h" | ||
36 | #include "microhttpd.h" | ||
37 | #include <jansson.h> | ||
38 | #include <inttypes.h> | ||
39 | #include "gnunet_signatures.h" | ||
40 | #include "gnunet_identity_provider_service.h" | ||
41 | |||
42 | /** | ||
43 | * REST root namespace | ||
44 | */ | ||
45 | #define GNUNET_REST_API_NS_IDENTITY_PROVIDER "/idp" | ||
46 | |||
47 | /** | ||
48 | * Attribute namespace | ||
49 | */ | ||
50 | #define GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES "/idp/attributes" | ||
51 | |||
52 | /** | ||
53 | * Attribute key | ||
54 | */ | ||
55 | #define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE "attribute" | ||
56 | |||
57 | /** | ||
58 | * Value key | ||
59 | */ | ||
60 | #define GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE_VALUE "value" | ||
61 | |||
62 | /** | ||
63 | * State while collecting all egos | ||
64 | */ | ||
65 | #define ID_REST_STATE_INIT 0 | ||
66 | |||
67 | /** | ||
68 | * Done collecting egos | ||
69 | */ | ||
70 | #define ID_REST_STATE_POST_INIT 1 | ||
71 | |||
72 | |||
73 | /** | ||
74 | * The configuration handle | ||
75 | */ | ||
76 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
77 | |||
78 | /** | ||
79 | * HTTP methods allows for this plugin | ||
80 | */ | ||
81 | static char* allow_methods; | ||
82 | |||
83 | /** | ||
84 | * @brief struct returned by the initialization function of the plugin | ||
85 | */ | ||
86 | struct Plugin | ||
87 | { | ||
88 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
89 | }; | ||
90 | |||
91 | /** | ||
92 | * The ego list | ||
93 | */ | ||
94 | struct EgoEntry | ||
95 | { | ||
96 | /** | ||
97 | * DLL | ||
98 | */ | ||
99 | struct EgoEntry *next; | ||
100 | |||
101 | /** | ||
102 | * DLL | ||
103 | */ | ||
104 | struct EgoEntry *prev; | ||
105 | |||
106 | /** | ||
107 | * Ego Identifier | ||
108 | */ | ||
109 | char *identifier; | ||
110 | |||
111 | /** | ||
112 | * Public key string | ||
113 | */ | ||
114 | char *keystring; | ||
115 | |||
116 | /** | ||
117 | * The Ego | ||
118 | */ | ||
119 | struct GNUNET_IDENTITY_Ego *ego; | ||
120 | }; | ||
121 | |||
122 | |||
123 | struct RequestHandle | ||
124 | { | ||
125 | /** | ||
126 | * Ego list | ||
127 | */ | ||
128 | struct EgoEntry *ego_head; | ||
129 | |||
130 | /** | ||
131 | * Ego list | ||
132 | */ | ||
133 | struct EgoEntry *ego_tail; | ||
134 | |||
135 | /** | ||
136 | * Selected ego | ||
137 | */ | ||
138 | struct EgoEntry *ego_entry; | ||
139 | |||
140 | /** | ||
141 | * Ptr to current ego private key | ||
142 | */ | ||
143 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
144 | |||
145 | /** | ||
146 | * Handle to the rest connection | ||
147 | */ | ||
148 | struct GNUNET_REST_RequestHandle *conndata_handle; | ||
149 | |||
150 | /** | ||
151 | * The processing state | ||
152 | */ | ||
153 | int state; | ||
154 | |||
155 | /** | ||
156 | * Handle to Identity service. | ||
157 | */ | ||
158 | struct GNUNET_IDENTITY_Handle *identity_handle; | ||
159 | |||
160 | /** | ||
161 | * IDENTITY Operation | ||
162 | */ | ||
163 | struct GNUNET_IDENTITY_Operation *op; | ||
164 | |||
165 | /** | ||
166 | * Identity Provider | ||
167 | */ | ||
168 | struct GNUNET_IDENTITY_PROVIDER_Handle *idp; | ||
169 | |||
170 | /** | ||
171 | * Idp Operation | ||
172 | */ | ||
173 | struct GNUNET_IDENTITY_PROVIDER_Operation *idp_op; | ||
174 | |||
175 | /** | ||
176 | * Attribute iterator | ||
177 | */ | ||
178 | struct GNUNET_IDENTITY_PROVIDER_AttributeIterator *attr_it; | ||
179 | |||
180 | /** | ||
181 | * Desired timeout for the lookup (default is no timeout). | ||
182 | */ | ||
183 | struct GNUNET_TIME_Relative timeout; | ||
184 | |||
185 | /** | ||
186 | * ID of a task associated with the resolution process. | ||
187 | */ | ||
188 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
189 | |||
190 | /** | ||
191 | * The plugin result processor | ||
192 | */ | ||
193 | GNUNET_REST_ResultProcessor proc; | ||
194 | |||
195 | /** | ||
196 | * The closure of the result processor | ||
197 | */ | ||
198 | void *proc_cls; | ||
199 | |||
200 | /** | ||
201 | * The url | ||
202 | */ | ||
203 | char *url; | ||
204 | |||
205 | /** | ||
206 | * Error response message | ||
207 | */ | ||
208 | char *emsg; | ||
209 | |||
210 | /** | ||
211 | * Reponse code | ||
212 | */ | ||
213 | int response_code; | ||
214 | |||
215 | /** | ||
216 | * Response object | ||
217 | */ | ||
218 | struct GNUNET_JSONAPI_Document *resp_object; | ||
219 | |||
220 | /** | ||
221 | * Resource object | ||
222 | */ | ||
223 | struct GNUNET_JSONAPI_Resource *json_resource; | ||
224 | |||
225 | }; | ||
226 | |||
227 | |||
228 | |||
229 | /** | ||
230 | * Cleanup lookup handle | ||
231 | * @param handle Handle to clean up | ||
232 | */ | ||
233 | static void | ||
234 | cleanup_handle (struct RequestHandle *handle) | ||
235 | { | ||
236 | struct EgoEntry *ego_entry; | ||
237 | struct EgoEntry *ego_tmp; | ||
238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
239 | "Cleaning up\n"); | ||
240 | if (NULL != handle->resp_object) | ||
241 | GNUNET_JSONAPI_document_delete (handle->resp_object); | ||
242 | if (NULL != handle->timeout_task) | ||
243 | GNUNET_SCHEDULER_cancel (handle->timeout_task); | ||
244 | if (NULL != handle->identity_handle) | ||
245 | GNUNET_IDENTITY_disconnect (handle->identity_handle); | ||
246 | if (NULL != handle->idp) | ||
247 | GNUNET_IDENTITY_PROVIDER_disconnect (handle->idp); | ||
248 | if (NULL != handle->attr_it) | ||
249 | GNUNET_IDENTITY_PROVIDER_get_attributes_stop (handle->attr_it); | ||
250 | if (NULL != handle->url) | ||
251 | GNUNET_free (handle->url); | ||
252 | if (NULL != handle->emsg) | ||
253 | GNUNET_free (handle->emsg); | ||
254 | for (ego_entry = handle->ego_head; | ||
255 | NULL != ego_entry;) | ||
256 | { | ||
257 | ego_tmp = ego_entry; | ||
258 | ego_entry = ego_entry->next; | ||
259 | GNUNET_free (ego_tmp->identifier); | ||
260 | GNUNET_free (ego_tmp->keystring); | ||
261 | GNUNET_free (ego_tmp); | ||
262 | } | ||
263 | GNUNET_free (handle); | ||
264 | } | ||
265 | |||
266 | /** | ||
267 | * Task run on error, sends error message. Cleans up everything. | ||
268 | * | ||
269 | * @param cls the `struct RequestHandle` | ||
270 | */ | ||
271 | static void | ||
272 | do_error (void *cls) | ||
273 | { | ||
274 | struct RequestHandle *handle = cls; | ||
275 | struct MHD_Response *resp; | ||
276 | char *json_error; | ||
277 | |||
278 | GNUNET_asprintf (&json_error, | ||
279 | "{Error while processing request: %s}", | ||
280 | handle->emsg); | ||
281 | resp = GNUNET_REST_create_response (json_error); | ||
282 | handle->proc (handle->proc_cls, resp, handle->response_code); | ||
283 | cleanup_handle (handle); | ||
284 | GNUNET_free (json_error); | ||
285 | } | ||
286 | |||
287 | /** | ||
288 | * Task run on timeout, sends error message. Cleans up everything. | ||
289 | * | ||
290 | * @param cls the `struct RequestHandle` | ||
291 | */ | ||
292 | static void | ||
293 | do_timeout (void *cls) | ||
294 | { | ||
295 | struct RequestHandle *handle = cls; | ||
296 | |||
297 | handle->timeout_task = NULL; | ||
298 | do_error (handle); | ||
299 | } | ||
300 | |||
301 | |||
302 | static void | ||
303 | attr_collect_error_cb (void *cls) | ||
304 | { | ||
305 | struct RequestHandle *handle = cls; | ||
306 | |||
307 | do_error (handle); | ||
308 | } | ||
309 | |||
310 | /** | ||
311 | * Return attributes for identity | ||
312 | * | ||
313 | * @param cls the request handle | ||
314 | */ | ||
315 | static void | ||
316 | return_attr_list (void *cls) | ||
317 | { | ||
318 | char* result_str; | ||
319 | struct RequestHandle *handle = cls; | ||
320 | struct MHD_Response *resp; | ||
321 | |||
322 | GNUNET_JSONAPI_document_serialize (handle->resp_object, &result_str); | ||
323 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str); | ||
324 | resp = GNUNET_REST_create_response (result_str); | ||
325 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
326 | GNUNET_free (result_str); | ||
327 | cleanup_handle (handle); | ||
328 | } | ||
329 | |||
330 | |||
331 | static void | ||
332 | attr_collect_finished_cb (void *cls) | ||
333 | { | ||
334 | struct RequestHandle *handle = cls; | ||
335 | //Done | ||
336 | handle->attr_it = NULL; | ||
337 | GNUNET_SCHEDULER_add_now (&return_attr_list, handle); | ||
338 | } | ||
339 | |||
340 | /** | ||
341 | * Collect all attributes for an ego | ||
342 | * | ||
343 | */ | ||
344 | static void | ||
345 | attr_collect (void *cls, | ||
346 | const struct GNUNET_CRYPTO_EcdsaPublicKey *identity, | ||
347 | const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr) | ||
348 | { | ||
349 | struct RequestHandle *handle = cls; | ||
350 | json_t *value; | ||
351 | |||
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding attribute: %s\n", | ||
353 | attr->name); | ||
354 | value = json_string (attr->data); | ||
355 | GNUNET_JSONAPI_resource_add_attr (handle->json_resource, | ||
356 | attr->name, | ||
357 | value); | ||
358 | json_decref (value); | ||
359 | GNUNET_IDENTITY_PROVIDER_get_attributes_next (handle->attr_it); | ||
360 | } | ||
361 | |||
362 | |||
363 | |||
364 | /** | ||
365 | * List attributes for identity request | ||
366 | * | ||
367 | * @param con_handle the connection handle | ||
368 | * @param url the url | ||
369 | * @param cls the RequestHandle | ||
370 | */ | ||
371 | static void | ||
372 | list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
373 | const char* url, | ||
374 | void *cls) | ||
375 | { | ||
376 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; | ||
377 | struct RequestHandle *handle = cls; | ||
378 | struct EgoEntry *ego_entry; | ||
379 | char *identity; | ||
380 | |||
381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting attributes for %s.\n", | ||
382 | handle->url); | ||
383 | if ( strlen (GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES) >= | ||
384 | strlen (handle->url)) | ||
385 | { | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No identity given.\n"); | ||
387 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
388 | return; | ||
389 | } | ||
390 | identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES) + 1; | ||
391 | |||
392 | for (ego_entry = handle->ego_head; | ||
393 | NULL != ego_entry; | ||
394 | ego_entry = ego_entry->next) | ||
395 | if (0 == strcmp (identity, ego_entry->identifier)) | ||
396 | break; | ||
397 | handle->resp_object = GNUNET_JSONAPI_document_new (); | ||
398 | |||
399 | handle->json_resource = GNUNET_JSONAPI_resource_new (GNUNET_REST_JSONAPI_IDENTITY_ATTRIBUTE, | ||
400 | identity); | ||
401 | GNUNET_JSONAPI_document_resource_add (handle->resp_object, handle->json_resource); | ||
402 | |||
403 | if (NULL == ego_entry) | ||
404 | { | ||
405 | //Done | ||
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Ego %s not found.\n", | ||
407 | identity); | ||
408 | GNUNET_SCHEDULER_add_now (&return_attr_list, handle); | ||
409 | return; | ||
410 | } | ||
411 | priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego); | ||
412 | handle->idp = GNUNET_IDENTITY_PROVIDER_connect (cfg); | ||
413 | handle->attr_it = GNUNET_IDENTITY_PROVIDER_get_attributes_start (handle->idp, | ||
414 | priv_key, | ||
415 | &attr_collect_error_cb, | ||
416 | handle, | ||
417 | &attr_collect, | ||
418 | handle, | ||
419 | &attr_collect_finished_cb, | ||
420 | handle); | ||
421 | } | ||
422 | |||
423 | |||
424 | /** | ||
425 | * Respond to OPTIONS request | ||
426 | * | ||
427 | * @param con_handle the connection handle | ||
428 | * @param url the url | ||
429 | * @param cls the RequestHandle | ||
430 | */ | ||
431 | static void | ||
432 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, | ||
433 | const char* url, | ||
434 | void *cls) | ||
435 | { | ||
436 | struct MHD_Response *resp; | ||
437 | struct RequestHandle *handle = cls; | ||
438 | |||
439 | //For now, independent of path return all options | ||
440 | resp = GNUNET_REST_create_response (NULL); | ||
441 | MHD_add_response_header (resp, | ||
442 | "Access-Control-Allow-Methods", | ||
443 | allow_methods); | ||
444 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); | ||
445 | cleanup_handle (handle); | ||
446 | return; | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * Handle rest request | ||
451 | * | ||
452 | * @param handle the request handle | ||
453 | */ | ||
454 | static void | ||
455 | init_cont (struct RequestHandle *handle) | ||
456 | { | ||
457 | struct GNUNET_REST_RequestHandlerError err; | ||
458 | static const struct GNUNET_REST_RequestHandler handlers[] = { | ||
459 | {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_ATTRIBUTES, &list_attribute_cont}, | ||
460 | {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_PROVIDER, | ||
461 | &options_cont}, | ||
462 | GNUNET_REST_HANDLER_END | ||
463 | }; | ||
464 | |||
465 | if (GNUNET_NO == GNUNET_REST_handle_request (handle->conndata_handle, | ||
466 | handlers, | ||
467 | &err, | ||
468 | handle)) | ||
469 | { | ||
470 | handle->response_code = err.error_code; | ||
471 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
472 | } | ||
473 | } | ||
474 | |||
475 | /** | ||
476 | * If listing is enabled, prints information about the egos. | ||
477 | * | ||
478 | * This function is initially called for all egos and then again | ||
479 | * whenever a ego's identifier changes or if it is deleted. At the | ||
480 | * end of the initial pass over all egos, the function is once called | ||
481 | * with 'NULL' for 'ego'. That does NOT mean that the callback won't | ||
482 | * be invoked in the future or that there was an error. | ||
483 | * | ||
484 | * When used with 'GNUNET_IDENTITY_create' or 'GNUNET_IDENTITY_get', | ||
485 | * this function is only called ONCE, and 'NULL' being passed in | ||
486 | * 'ego' does indicate an error (i.e. name is taken or no default | ||
487 | * value is known). If 'ego' is non-NULL and if '*ctx' | ||
488 | * is set in those callbacks, the value WILL be passed to a subsequent | ||
489 | * call to the identity callback of 'GNUNET_IDENTITY_connect' (if | ||
490 | * that one was not NULL). | ||
491 | * | ||
492 | * When an identity is renamed, this function is called with the | ||
493 | * (known) ego but the NEW identifier. | ||
494 | * | ||
495 | * When an identity is deleted, this function is called with the | ||
496 | * (known) ego and "NULL" for the 'identifier'. In this case, | ||
497 | * the 'ego' is henceforth invalid (and the 'ctx' should also be | ||
498 | * cleaned up). | ||
499 | * | ||
500 | * @param cls closure | ||
501 | * @param ego ego handle | ||
502 | * @param ctx context for application to store data for this ego | ||
503 | * (during the lifetime of this process, initially NULL) | ||
504 | * @param identifier identifier assigned by the user for this ego, | ||
505 | * NULL if the user just deleted the ego and it | ||
506 | * must thus no longer be used | ||
507 | */ | ||
508 | static void | ||
509 | list_ego (void *cls, | ||
510 | struct GNUNET_IDENTITY_Ego *ego, | ||
511 | void **ctx, | ||
512 | const char *identifier) | ||
513 | { | ||
514 | struct RequestHandle *handle = cls; | ||
515 | struct EgoEntry *ego_entry; | ||
516 | struct GNUNET_CRYPTO_EcdsaPublicKey pk; | ||
517 | |||
518 | if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state)) | ||
519 | { | ||
520 | handle->state = ID_REST_STATE_POST_INIT; | ||
521 | init_cont (handle); | ||
522 | return; | ||
523 | } | ||
524 | if (ID_REST_STATE_INIT == handle->state) { | ||
525 | ego_entry = GNUNET_new (struct EgoEntry); | ||
526 | GNUNET_IDENTITY_ego_get_public_key (ego, &pk); | ||
527 | ego_entry->keystring = | ||
528 | GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk); | ||
529 | ego_entry->ego = ego; | ||
530 | ego_entry->identifier = GNUNET_strdup (identifier); | ||
531 | GNUNET_CONTAINER_DLL_insert_tail(handle->ego_head,handle->ego_tail, ego_entry); | ||
532 | } | ||
533 | |||
534 | } | ||
535 | |||
536 | /** | ||
537 | * Function processing the REST call | ||
538 | * | ||
539 | * @param method HTTP method | ||
540 | * @param url URL of the HTTP request | ||
541 | * @param data body of the HTTP request (optional) | ||
542 | * @param data_size length of the body | ||
543 | * @param proc callback function for the result | ||
544 | * @param proc_cls closure for callback function | ||
545 | * @return GNUNET_OK if request accepted | ||
546 | */ | ||
547 | static void | ||
548 | rest_identity_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, | ||
549 | GNUNET_REST_ResultProcessor proc, | ||
550 | void *proc_cls) | ||
551 | { | ||
552 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); | ||
553 | |||
554 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | ||
555 | handle->proc_cls = proc_cls; | ||
556 | handle->proc = proc; | ||
557 | handle->state = ID_REST_STATE_INIT; | ||
558 | handle->conndata_handle = conndata_handle; | ||
559 | |||
560 | |||
561 | handle->url = GNUNET_strdup (conndata_handle->url); | ||
562 | if (handle->url[strlen (handle->url)-1] == '/') | ||
563 | handle->url[strlen (handle->url)-1] = '\0'; | ||
564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
565 | "Connecting...\n"); | ||
566 | handle->identity_handle = GNUNET_IDENTITY_connect (cfg, | ||
567 | &list_ego, | ||
568 | handle); | ||
569 | handle->timeout_task = | ||
570 | GNUNET_SCHEDULER_add_delayed (handle->timeout, | ||
571 | &do_timeout, | ||
572 | handle); | ||
573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
574 | "Connected\n"); | ||
575 | } | ||
576 | |||
577 | /** | ||
578 | * Entry point for the plugin. | ||
579 | * | ||
580 | * @param cls Config info | ||
581 | * @return NULL on error, otherwise the plugin context | ||
582 | */ | ||
583 | void * | ||
584 | libgnunet_plugin_rest_identity_provider_init (void *cls) | ||
585 | { | ||
586 | static struct Plugin plugin; | ||
587 | struct GNUNET_REST_Plugin *api; | ||
588 | |||
589 | cfg = cls; | ||
590 | if (NULL != plugin.cfg) | ||
591 | return NULL; /* can only initialize once! */ | ||
592 | memset (&plugin, 0, sizeof (struct Plugin)); | ||
593 | plugin.cfg = cfg; | ||
594 | api = GNUNET_new (struct GNUNET_REST_Plugin); | ||
595 | api->cls = &plugin; | ||
596 | api->name = GNUNET_REST_API_NS_IDENTITY_PROVIDER; | ||
597 | api->process_request = &rest_identity_process_request; | ||
598 | GNUNET_asprintf (&allow_methods, | ||
599 | "%s, %s, %s, %s, %s", | ||
600 | MHD_HTTP_METHOD_GET, | ||
601 | MHD_HTTP_METHOD_POST, | ||
602 | MHD_HTTP_METHOD_PUT, | ||
603 | MHD_HTTP_METHOD_DELETE, | ||
604 | MHD_HTTP_METHOD_OPTIONS); | ||
605 | |||
606 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
607 | _("Identity Provider REST API initialized\n")); | ||
608 | return api; | ||
609 | } | ||
610 | |||
611 | |||
612 | /** | ||
613 | * Exit point from the plugin. | ||
614 | * | ||
615 | * @param cls the plugin context (as returned by "init") | ||
616 | * @return always NULL | ||
617 | */ | ||
618 | void * | ||
619 | libgnunet_plugin_rest_identity_provider_done (void *cls) | ||
620 | { | ||
621 | struct GNUNET_REST_Plugin *api = cls; | ||
622 | struct Plugin *plugin = api->cls; | ||
623 | |||
624 | plugin->cfg = NULL; | ||
625 | GNUNET_free_non_null (allow_methods); | ||
626 | GNUNET_free (api); | ||
627 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
628 | "Identity Provider REST plugin is finished\n"); | ||
629 | return NULL; | ||
630 | } | ||
631 | |||
632 | /* end of plugin_rest_identity_provider.c */ | ||
diff --git a/src/identity-provider/test_idp.conf b/src/identity-provider/test_idp.conf index a457bbe8f..9669bef7e 100644 --- a/src/identity-provider/test_idp.conf +++ b/src/identity-provider/test_idp.conf | |||
@@ -27,3 +27,5 @@ RECORD_PUT_INTERVAL = 1 h | |||
27 | ZONE_PUBLISH_TIME_WINDOW = 1 h | 27 | ZONE_PUBLISH_TIME_WINDOW = 1 h |
28 | DNS_ROOT=PD67SGHF3E0447TU9HADIVU9OM7V4QHTOG0EBU69TFRI2LG63DR0 | 28 | DNS_ROOT=PD67SGHF3E0447TU9HADIVU9OM7V4QHTOG0EBU69TFRI2LG63DR0 |
29 | 29 | ||
30 | [rest] | ||
31 | PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=/tmp/rest | ||
diff --git a/src/identity-provider/test_idp_issue.sh b/src/identity-provider/test_idp_issue.sh index f2f48057d..8cd1297d3 100755 --- a/src/identity-provider/test_idp_issue.sh +++ b/src/identity-provider/test_idp_issue.sh | |||
@@ -24,6 +24,7 @@ which timeout &> /dev/null && DO_TIMEOUT="timeout 30" | |||
24 | 24 | ||
25 | TEST_ATTR="test" | 25 | TEST_ATTR="test" |
26 | gnunet-arm -s -c test_idp.conf | 26 | gnunet-arm -s -c test_idp.conf |
27 | gnunet-arm -i rest -c test_idp.conf | ||
27 | gnunet-identity -C testego -c test_idp.conf | 28 | gnunet-identity -C testego -c test_idp.conf |
28 | gnunet-identity -C rpego -c test_idp.conf | 29 | gnunet-identity -C rpego -c test_idp.conf |
29 | SUBJECT_KEY=$(gnunet-identity -d -c test_idp.conf | grep rpego | awk '{print $3}') | 30 | SUBJECT_KEY=$(gnunet-identity -d -c test_idp.conf | grep rpego | awk '{print $3}') |
@@ -32,6 +33,7 @@ gnunet-idp -e testego -a email -V john@doe.gnu -c test_idp.conf | |||
32 | gnunet-idp -e testego -a name -V John -c test_idp.conf | 33 | gnunet-idp -e testego -a name -V John -c test_idp.conf |
33 | #gnunet-idp -e testego -D -c test_idp.conf | 34 | #gnunet-idp -e testego -D -c test_idp.conf |
34 | TICKET=$(gnunet-idp -e testego -i "email,name" -r $SUBJECT_KEY -c test_idp.conf | awk '{print $1}') | 35 | TICKET=$(gnunet-idp -e testego -i "email,name" -r $SUBJECT_KEY -c test_idp.conf | awk '{print $1}') |
36 | curl http://localhost:7776/idp/attributes/testego | ||
35 | #echo "Consuming $TICKET" | 37 | #echo "Consuming $TICKET" |
36 | gnunet-idp -e rpego -C $TICKET -c test_idp.conf | 38 | gnunet-idp -e rpego -C $TICKET -c test_idp.conf |
37 | gnunet-arm -e -c test_idp.conf | 39 | gnunet-arm -e -c test_idp.conf |