aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/identity-token/Makefile.am1
-rw-r--r--src/identity-token/plugin_rest_identity_token.c258
-rw-r--r--src/namestore/plugin_rest_namestore.c103
3 files changed, 347 insertions, 15 deletions
diff --git a/src/identity-token/Makefile.am b/src/identity-token/Makefile.am
index 8ada7667f..235607b84 100644
--- a/src/identity-token/Makefile.am
+++ b/src/identity-token/Makefile.am
@@ -47,6 +47,7 @@ libgnunet_plugin_rest_identity_token_la_LIBADD = \
47 $(top_builddir)/src/identity/libgnunetidentity.la \ 47 $(top_builddir)/src/identity/libgnunetidentity.la \
48 $(top_builddir)/src/rest/libgnunetrest.la \ 48 $(top_builddir)/src/rest/libgnunetrest.la \
49 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 49 $(top_builddir)/src/namestore/libgnunetnamestore.la \
50 $(top_builddir)/src/gns/libgnunetgns.la \
50 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \ 51 $(top_builddir)/src/util/libgnunetutil.la $(XLIBS) \
51 $(LTLIBINTL) -ljansson -lmicrohttpd 52 $(LTLIBINTL) -ljansson -lmicrohttpd
52libgnunet_plugin_rest_identity_token_la_LDFLAGS = \ 53libgnunet_plugin_rest_identity_token_la_LDFLAGS = \
diff --git a/src/identity-token/plugin_rest_identity_token.c b/src/identity-token/plugin_rest_identity_token.c
index e37ab9e52..6b9106e14 100644
--- a/src/identity-token/plugin_rest_identity_token.c
+++ b/src/identity-token/plugin_rest_identity_token.c
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_rest_plugin.h" 28#include "gnunet_rest_plugin.h"
29#include "gnunet_identity_service.h" 29#include "gnunet_identity_service.h"
30#include "gnunet_gns_service.h"
30#include "gnunet_gnsrecord_lib.h" 31#include "gnunet_gnsrecord_lib.h"
31#include "gnunet_namestore_service.h" 32#include "gnunet_namestore_service.h"
32#include "gnunet_rest_lib.h" 33#include "gnunet_rest_lib.h"
@@ -37,18 +38,33 @@
37/** 38/**
38 * REST root namespace 39 * REST root namespace
39 */ 40 */
40#define GNUNET_REST_API_NS_IDENTITY_TOKEN "/token" 41#define GNUNET_REST_API_NS_IDENTITY_TOKEN "/gnuid"
41 42
42/** 43/**
43 * Issue namespace 44 * Issue namespace
44 */ 45 */
45#define GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE "/token/issue" 46#define GNUNET_REST_API_NS_IDENTITY_TOKEN_ISSUE "/gnuid/issue"
46 47
47/** 48/**
48 * Check namespace 49 * Check namespace
49 */ 50 */
50#define GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK "/token/check" 51#define GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK "/gnuid/check"
51 52
53/**
54 * OAuth2 namespace
55 */
56#define GNUNET_REST_API_NS_IDENTITY_OAUTH2_TOKEN "/gnuid/token"
57
58/**
59 * OAuth2 namespace
60 */
61#define GNUNET_REST_API_NS_IDENTITY_OAUTH2_AUTHORIZE "/gnuid/authorize"
62
63#define GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_CODE "code"
64
65#define GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_GRANT_TYPE_CODE "authorization_code"
66
67#define GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_GRANT_TYPE "grant_type"
52 68
53/** 69/**
54 * State while collecting all egos 70 * State while collecting all egos
@@ -194,6 +210,11 @@ struct RequestHandle
194 struct GNUNET_NAMESTORE_Handle *ns_handle; 210 struct GNUNET_NAMESTORE_Handle *ns_handle;
195 211
196 /** 212 /**
213 * Handle to GNS service
214 */
215 struct GNUNET_GNS_Handle *gns_handle;
216
217 /**
197 * NS iterator 218 * NS iterator
198 */ 219 */
199 struct GNUNET_NAMESTORE_ZoneIterator *ns_it; 220 struct GNUNET_NAMESTORE_ZoneIterator *ns_it;
@@ -212,6 +233,11 @@ struct RequestHandle
212 * ID of a task associated with the resolution process. 233 * ID of a task associated with the resolution process.
213 */ 234 */
214 struct GNUNET_SCHEDULER_Task * timeout_task; 235 struct GNUNET_SCHEDULER_Task * timeout_task;
236
237 /**
238 * GNS lookup
239 */
240 struct GNUNET_GNS_LookupRequest *lookup_request;
215 241
216 /** 242 /**
217 * The plugin result processor 243 * The plugin result processor
@@ -296,6 +322,8 @@ cleanup_handle (struct RequestHandle *handle)
296 GNUNET_SCHEDULER_cancel (handle->timeout_task); 322 GNUNET_SCHEDULER_cancel (handle->timeout_task);
297 if (NULL != handle->identity_handle) 323 if (NULL != handle->identity_handle)
298 GNUNET_IDENTITY_disconnect (handle->identity_handle); 324 GNUNET_IDENTITY_disconnect (handle->identity_handle);
325 if (NULL != handle->gns_handle)
326 GNUNET_GNS_disconnect (handle->gns_handle);
299 if (NULL != handle->ns_it) 327 if (NULL != handle->ns_it)
300 GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it); 328 GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it);
301 if (NULL != handle->ns_qe) 329 if (NULL != handle->ns_qe)
@@ -407,9 +435,10 @@ sign_and_return_token (void *cls,
407 char *token; 435 char *token;
408 char *exp_str; 436 char *exp_str;
409 char *renew_str; 437 char *renew_str;
438 char *rnd_str;
410 uint64_t time; 439 uint64_t time;
411 uint64_t exp_time; 440 uint64_t exp_time;
412 uint64_t lbl; 441 uint64_t lbl_key;
413 json_t *token_str; 442 json_t *token_str;
414 json_t *name_str; 443 json_t *name_str;
415 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key; 444 const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
@@ -421,11 +450,66 @@ sign_and_return_token (void *cls,
421 struct GNUNET_HashCode key; 450 struct GNUNET_HashCode key;
422 struct GNUNET_TIME_Relative etime_rel; 451 struct GNUNET_TIME_Relative etime_rel;
423 int renew_token = GNUNET_NO; 452 int renew_token = GNUNET_NO;
453/*
454 //Token audience
455 audience = NULL;
456 if ( GNUNET_YES !=
457 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
458 &key) )
459 {
460 handle->emsg = GNUNET_strdup ("Audience missing!\n");
461 GNUNET_SCHEDULER_add_now (&do_error, handle);
462 return;
463 }
464 audience = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
465 &key);
466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Audience to issue token for: %s\n", audience);
467 //Create label for audience
468 if (GNUNET_OK != GNUNET_CRYPTO_ecdsa_public_key_from_string (audience,
469 strlen (audience),
470 &aud_pkey))
471 {
472 handle->emsg = GNUNET_strdup ("Client PKEY invalid!\n");
473 GNUNET_SCHEDULER_add_now (&do_error, handle);
474 return;
475 }
424 476
477 new_privkey = GNUNET_CRYPTO_ecdhe_key_create();
478
479 GNUNET_CRYPTO_ecdh_ecdsa (new_privkey,
480 &aud_pkey,
481 &new_key_hash);
482
483 GNUNET_CRYPTO_ecdhe_key_get_public (new_privkey,
484 new_pubkey);
485 static const char ctx_key[] = "gnuid-aes-ctx-key";
486 GNUNET_CRYPTO_kdf (&skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
487 new_pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
488 ctx_key, strlen (ctx_key),
489 NULL, 0);
490 static const char ctx_iv[] = "gnuid-aes-ctx-iv";
491 GNUNET_CRYPTO_kdf (&iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector),
492 new_pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey),
493 ctx_iv, strlen (ctx_iv),
494 NULL, 0);
495*/
496 //TODO: Encrypt the label
425 time = GNUNET_TIME_absolute_get().abs_value_us; 497 time = GNUNET_TIME_absolute_get().abs_value_us;
426 lbl = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX); 498 lbl_key = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG, UINT64_MAX);
427 GNUNET_STRINGS_base64_encode ((char*)&lbl, sizeof (uint64_t), &lbl_str); 499 GNUNET_asprintf (&rnd_str,
500 "{\"nonce\": \"%uul\",\"identity\": \"%s\"}",
501 lbl_key, handle->ego_entry->keystring);
502 GNUNET_STRINGS_base64_encode (rnd_str, strlen (rnd_str), &lbl_str);
503 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_AUD_REQUEST,
504 strlen (GNUNET_REST_JSONAPI_IDENTITY_AUD_REQUEST),
505 &key);
506
507/*
508 GNUNET_CRYPTO_symmetric_encrypt (handle->ego_entry->keystring, strlen (handle->ego_entry->keystring),
509 &skey, &iv,
510 &block[1]);
428 511
512*/
429 GNUNET_CRYPTO_hash (GNUNET_IDENTITY_TOKEN_EXP_STRING, 513 GNUNET_CRYPTO_hash (GNUNET_IDENTITY_TOKEN_EXP_STRING,
430 strlen (GNUNET_IDENTITY_TOKEN_EXP_STRING), 514 strlen (GNUNET_IDENTITY_TOKEN_EXP_STRING),
431 &key); 515 &key);
@@ -436,9 +520,11 @@ sign_and_return_token (void *cls,
436 &key)) 520 &key))
437 { 521 {
438 exp_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map, 522 exp_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
439 &key); 523 &key);
440 } 524 }
441 525
526
527
442 if (NULL == exp_str) { 528 if (NULL == exp_str) {
443 handle->emsg = GNUNET_strdup ("No expiration given!\n"); 529 handle->emsg = GNUNET_strdup ("No expiration given!\n");
444 GNUNET_SCHEDULER_add_now (&do_error, handle); 530 GNUNET_SCHEDULER_add_now (&do_error, handle);
@@ -446,15 +532,15 @@ sign_and_return_token (void *cls,
446 } 532 }
447 533
448 if (GNUNET_OK != 534 if (GNUNET_OK !=
449 GNUNET_STRINGS_fancy_time_to_relative (exp_str, 535 GNUNET_STRINGS_fancy_time_to_relative (exp_str,
450 &etime_rel)) 536 &etime_rel))
451 { 537 {
452 handle->emsg = GNUNET_strdup ("Expiration invalid!\n"); 538 handle->emsg = GNUNET_strdup ("Expiration invalid!\n");
453 GNUNET_SCHEDULER_add_now (&do_error, handle); 539 GNUNET_SCHEDULER_add_now (&do_error, handle);
454 return; 540 return;
455 } 541 }
456 exp_time = time + etime_rel.rel_value_us; 542 exp_time = time + etime_rel.rel_value_us;
457 543
458 //Get renewal policy for token 544 //Get renewal policy for token
459 GNUNET_CRYPTO_hash (GNUNET_IDENTITY_TOKEN_RENEW_TOKEN, 545 GNUNET_CRYPTO_hash (GNUNET_IDENTITY_TOKEN_RENEW_TOKEN,
460 strlen (GNUNET_IDENTITY_TOKEN_RENEW_TOKEN), 546 strlen (GNUNET_IDENTITY_TOKEN_RENEW_TOKEN),
@@ -510,8 +596,9 @@ sign_and_return_token (void *cls,
510 &sig)) 596 &sig))
511 GNUNET_break(0); 597 GNUNET_break(0);
512 GNUNET_free (token); 598 GNUNET_free (token);
513 sig_str = GNUNET_STRINGS_data_to_string_alloc (&sig, 599 GNUNET_STRINGS_base64_encode ((const char*)&sig,
514 sizeof (struct GNUNET_CRYPTO_EcdsaSignature)); 600 sizeof (struct GNUNET_CRYPTO_EcdsaSignature),
601 &sig_str);
515 GNUNET_asprintf (&token, "%s.%s.%s", 602 GNUNET_asprintf (&token, "%s.%s.%s",
516 header_base64, payload_base64, sig_str); 603 header_base64, payload_base64, sig_str);
517 GNUNET_free (sig_str); 604 GNUNET_free (sig_str);
@@ -912,6 +999,152 @@ list_token_cont (struct RestConnectionDataHandle *con_handle,
912 999
913} 1000}
914 1001
1002static void
1003process_lookup_result (void *cls, uint32_t rd_count,
1004 const struct GNUNET_GNSRECORD_Data *rd)
1005{
1006 struct RequestHandle *handle = cls;
1007 json_t *root;
1008 struct MHD_Response *resp;
1009 char *result;
1010 char* token_str;
1011
1012 handle->lookup_request = NULL;
1013 if (1 != rd_count)
1014 {
1015 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1016 "Number of tokens %d != 1.",
1017 rd_count);
1018 handle->emsg = GNUNET_strdup ("Number of tokens != 1.");
1019 GNUNET_SCHEDULER_add_now (&do_error, handle);
1020 return;
1021 }
1022
1023 root = json_object();
1024 token_str =
1025 GNUNET_GNSRECORD_value_to_string (GNUNET_GNSRECORD_TYPE_ID_TOKEN,
1026 rd->data,
1027 rd->data_size);
1028 json_object_set_new (root, "access_token", json_string (token_str));
1029 json_object_set_new (root, "token_type", json_string ("gnuid"));
1030 GNUNET_free (token_str);
1031
1032 result = json_dumps (root, JSON_INDENT(1));
1033 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n", result);
1034 resp = GNUNET_REST_create_json_response (result);
1035 GNUNET_free (result);
1036 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
1037 cleanup_handle (handle);
1038 json_decref (root);
1039}
1040
1041static void
1042identity_master_cb (void *cls,
1043 struct GNUNET_IDENTITY_Ego *ego,
1044 void **ctx,
1045 const char *name)
1046{
1047 struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
1048 struct RequestHandle *handle = cls;
1049 struct GNUNET_HashCode key;
1050 json_t *root;
1051 json_t *pkey_json;
1052 json_error_t err_json;
1053 const char* pkey_str;
1054 char* code;
1055 char* code_decoded;
1056 char * lookup_query;
1057
1058 handle->op = NULL;
1059
1060 if (NULL == ego)
1061 {
1062 handle->emsg = GNUNET_strdup ("No GNS identity found.");
1063 GNUNET_SCHEDULER_add_now (&do_error, handle);
1064 return;
1065 }
1066
1067 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_CODE,
1068 strlen (GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_CODE),
1069 &key);
1070
1071 if ( GNUNET_NO ==
1072 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
1073 &key) )
1074 {
1075 handle->emsg = GNUNET_strdup ("No code given.");
1076 GNUNET_SCHEDULER_add_now (&do_error, handle);
1077 return;
1078 }
1079 code = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
1080 &key);
1081 GNUNET_STRINGS_base64_decode (code,
1082 strlen (code),
1083 &code_decoded);
1084 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1085 "%s\n", code_decoded);
1086 root = json_loads (code_decoded, JSON_DECODE_ANY, &err_json);
1087 if (!root)
1088 {
1089 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1090 "%s\n", err_json.text);
1091 }
1092 pkey_json = json_object_get (root, "identity");
1093 pkey_str = json_string_value (pkey_json);
1094 GNUNET_CRYPTO_ecdsa_public_key_from_string (pkey_str,
1095 strlen (pkey_str),
1096 &pkey);
1097 json_decref (root);
1098 handle->gns_handle = GNUNET_GNS_connect (cfg);
1099 GNUNET_asprintf (&lookup_query, "%s.gnu", code);
1100
1101 handle->lookup_request = GNUNET_GNS_lookup (handle->gns_handle,
1102 lookup_query,
1103 &pkey,
1104 GNUNET_GNSRECORD_TYPE_ID_TOKEN,
1105 GNUNET_GNS_LO_LOCAL_MASTER,
1106 NULL,
1107 &process_lookup_result,
1108 handle);
1109 GNUNET_free (lookup_query);
1110}
1111
1112/**
1113 * Respond to OAuth2 /token request
1114 *
1115 * @param con_handle the connection handle
1116 * @param url the url
1117 * @param cls the RequestHandle
1118 */
1119static void
1120oauth_token_cont (struct RestConnectionDataHandle *con_handle,
1121 const char* url,
1122 void *cls)
1123{
1124 struct RequestHandle *handle = cls;
1125 char* grant_type;
1126 struct GNUNET_HashCode key;
1127
1128 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_GRANT_TYPE,
1129 strlen (GNUNET_REST_JSONAPI_IDENTITY_OAUTH2_GRANT_TYPE),
1130 &key);
1131
1132 if ( GNUNET_YES ==
1133 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
1134 &key) )
1135 {
1136 grant_type = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
1137 &key);
1138 }
1139
1140 if (0 == strcmp ("authorization_code", grant_type)) {
1141 //Get token from GNS
1142 handle->op = GNUNET_IDENTITY_get (handle->identity_handle,
1143 "gns-master",
1144 &identity_master_cb,
1145 handle);
1146 }
1147}
915 1148
916/** 1149/**
917 * Respond to OPTIONS request 1150 * Respond to OPTIONS request
@@ -951,6 +1184,7 @@ init_cont (struct RequestHandle *handle)
951 //{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK, &check_token_cont}, 1184 //{MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_TOKEN_CHECK, &check_token_cont},
952 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN, &list_token_cont}, 1185 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_IDENTITY_TOKEN, &list_token_cont},
953 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_TOKEN, &options_cont}, 1186 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_IDENTITY_TOKEN, &options_cont},
1187 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_IDENTITY_OAUTH2_TOKEN, &oauth_token_cont},
954 GNUNET_REST_HANDLER_END 1188 GNUNET_REST_HANDLER_END
955 }; 1189 };
956 1190
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c
index 6ae3e7967..42a9f6356 100644
--- a/src/namestore/plugin_rest_namestore.c
+++ b/src/namestore/plugin_rest_namestore.c
@@ -34,8 +34,14 @@
34 34
35#define GNUNET_REST_API_NS_NAMESTORE "/names" 35#define GNUNET_REST_API_NS_NAMESTORE "/names"
36 36
37#define GNUNET_REST_API_NS_NAMESTORE_ZKEY "/names/zkey"
38
37#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record" 39#define GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO "record"
38 40
41#define GNUNET_REST_JSONAPI_NAMESTORE_NAME "name"
42
43#define GNUNET_REST_JSONAPI_NAMESTORE_REVINFO "revinfo"
44
39#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO 45#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO
40 46
41#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type" 47#define GNUNET_REST_JSONAPI_NAMESTORE_RECORD_TYPE "record_type"
@@ -48,6 +54,8 @@
48 54
49#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey" 55#define GNUNET_REST_JSONAPI_NAMESTORE_PKEY "pkey"
50 56
57#define GNUNET_REST_JSONAPI_NAMESTORE_ZKEY "zkey"
58
51#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration" 59#define GNUNET_REST_JSONAPI_NAMESTORE_EXPIRATION "expiration"
52 60
53#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego" 61#define GNUNET_REST_JSONAPI_NAMESTORE_EGO "ego"
@@ -160,6 +168,11 @@ struct RequestHandle
160 char *value; 168 char *value;
161 169
162 /** 170 /**
171 * Zkey string
172 */
173 const char* zkey_str;
174
175 /**
163 * record type 176 * record type
164 */ 177 */
165 uint32_t type; 178 uint32_t type;
@@ -174,12 +187,17 @@ struct RequestHandle
174 */ 187 */
175 unsigned int rd_count; 188 unsigned int rd_count;
176 189
177 /** 190 /**
178 * NAMESTORE Operation 191 * NAMESTORE Operation
179 */ 192 */
180 struct GNUNET_NAMESTORE_QueueEntry *add_qe; 193 struct GNUNET_NAMESTORE_QueueEntry *add_qe;
181 194
182 /** 195 /**
196 * NAMESTORE Operation
197 */
198 struct GNUNET_NAMESTORE_QueueEntry *reverse_qe;
199
200 /**
183 * Desired timeout for the lookup (default is no timeout). 201 * Desired timeout for the lookup (default is no timeout).
184 */ 202 */
185 struct GNUNET_TIME_Relative timeout; 203 struct GNUNET_TIME_Relative timeout;
@@ -213,7 +231,7 @@ struct RequestHandle
213 * the length of the REST data 231 * the length of the REST data
214 */ 232 */
215 size_t data_size; 233 size_t data_size;
216 234
217 /** 235 /**
218 * Cfg 236 * Cfg
219 */ 237 */
@@ -416,7 +434,7 @@ namestore_list_response (void *cls,
416 json_array_append (result_array, record_obj); 434 json_array_append (result_array, record_obj);
417 json_decref (record_obj); 435 json_decref (record_obj);
418 } 436 }
419 437
420 if (0 < json_array_size(result_array)) 438 if (0 < json_array_size(result_array))
421 { 439 {
422 json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO, 440 json_resource = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_TYPEINFO,
@@ -774,9 +792,87 @@ namestore_create_cont (struct RestConnectionDataHandle *con,
774 &create_new_record_cont, handle ); 792 &create_new_record_cont, handle );
775} 793}
776 794
795static void
796namestore_zkey_response (void *cls,
797 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
798 const char *label,
799 unsigned int rd_count,
800 const struct GNUNET_GNSRECORD_Data *rd)
801{
802 struct RequestHandle *handle = cls;
803 struct MHD_Response *resp;
804 struct JsonApiObject *json_obj;
805 struct JsonApiResource *json_res;
806 json_t *name_json;
807 char* result;
808
809 handle->reverse_qe = NULL;
810 json_obj = GNUNET_REST_jsonapi_object_new ();
811 if (NULL != label)
812 {
813 name_json = json_string (label);
814 json_res = GNUNET_REST_jsonapi_resource_new (GNUNET_REST_JSONAPI_NAMESTORE_REVINFO,
815 handle->zkey_str);
816 GNUNET_REST_jsonapi_resource_add_attr (json_res,
817 GNUNET_REST_JSONAPI_NAMESTORE_NAME,
818 name_json);
819 GNUNET_REST_jsonapi_object_resource_add (json_obj, json_res);
820 json_decref (name_json);
821 }
822 //Handle response
823 if (GNUNET_SYSERR == GNUNET_REST_jsonapi_data_serialize (json_obj, &result))
824 {
825 GNUNET_REST_jsonapi_object_delete (json_obj);
826 GNUNET_SCHEDULER_add_now (&do_error, handle);
827 return;
828 }
829 resp = GNUNET_REST_create_json_response (result);
830 handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
831 GNUNET_free (result);
832 GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
833 return;
777 834
835}
778 836
837static void
838namestore_zkey_cont (struct RestConnectionDataHandle *con,
839 const char *url,
840 void *cls)
841{
842 struct RequestHandle *handle = cls;
843 struct GNUNET_HashCode key;
844 struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
779 845
846 GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY,
847 strlen (GNUNET_REST_JSONAPI_NAMESTORE_ZKEY),
848 &key);
849 if ( GNUNET_NO ==
850 GNUNET_CONTAINER_multihashmap_contains (handle->conndata_handle->url_param_map,
851 &key) )
852 {
853 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
854 "No zkey given %s\n", handle->url);
855 GNUNET_SCHEDULER_add_now (&do_error, handle);
856 return;
857 }
858 handle->zkey_str = GNUNET_CONTAINER_multihashmap_get (handle->conndata_handle->url_param_map,
859 &key);
860 if (GNUNET_OK !=
861 GNUNET_CRYPTO_ecdsa_public_key_from_string (handle->zkey_str,
862 strlen (handle->zkey_str),
863 &pubkey))
864 {
865 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
866 "Zkey invalid %s\n", handle->zkey_str);
867 GNUNET_SCHEDULER_add_now (&do_error, handle);
868 return;
869 }
870 handle->reverse_qe = GNUNET_NAMESTORE_zone_to_name (handle->ns_handle,
871 &handle->zone_pkey,
872 &pubkey,
873 &namestore_zkey_response,
874 handle);
875}
780 876
781static void 877static void
782namestore_info_cont (struct RestConnectionDataHandle *con, 878namestore_info_cont (struct RestConnectionDataHandle *con,
@@ -837,6 +933,7 @@ testservice_task (void *cls,
837{ 933{
838 struct RequestHandle *handle = cls; 934 struct RequestHandle *handle = cls;
839 static const struct GNUNET_REST_RestConnectionHandler handlers[] = { 935 static const struct GNUNET_REST_RestConnectionHandler handlers[] = {
936 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE_ZKEY, &namestore_zkey_cont}, //reverse
840 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list 937 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_NAMESTORE, &namestore_info_cont}, //list
841 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create 938 {MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_NAMESTORE, &namestore_create_cont}, //create
842 // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH 939 // {MHD_HTTP_METHOD_PUT, GNUNET_REST_API_NS_NAMESTORE, &namestore_edit_cont}, //update. TODO this shoul be PATCH