diff options
Diffstat (limited to 'src/credential/plugin_rest_credential.c')
-rw-r--r-- | src/credential/plugin_rest_credential.c | 1408 |
1 files changed, 714 insertions, 694 deletions
diff --git a/src/credential/plugin_rest_credential.c b/src/credential/plugin_rest_credential.c index 51c1f8b8c..513ddfff9 100644 --- a/src/credential/plugin_rest_credential.c +++ b/src/credential/plugin_rest_credential.c | |||
@@ -62,13 +62,15 @@ | |||
62 | /** | 62 | /** |
63 | * @brief struct returned by the initialization function of the plugin | 63 | * @brief struct returned by the initialization function of the plugin |
64 | */ | 64 | */ |
65 | struct Plugin { | 65 | struct Plugin |
66 | { | ||
66 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 67 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
67 | }; | 68 | }; |
68 | 69 | ||
69 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 70 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
70 | 71 | ||
71 | struct RequestHandle { | 72 | struct RequestHandle |
73 | { | ||
72 | /** | 74 | /** |
73 | * Handle to Credential service. | 75 | * Handle to Credential service. |
74 | */ | 76 | */ |
@@ -107,7 +109,7 @@ struct RequestHandle { | |||
107 | /** | 109 | /** |
108 | * ID of a task associated with the resolution process. | 110 | * ID of a task associated with the resolution process. |
109 | */ | 111 | */ |
110 | struct GNUNET_SCHEDULER_Task * timeout_task; | 112 | struct GNUNET_SCHEDULER_Task *timeout_task; |
111 | 113 | ||
112 | /** | 114 | /** |
113 | * The root of the received JSON or NULL | 115 | * The root of the received JSON or NULL |
@@ -162,44 +164,44 @@ struct RequestHandle { | |||
162 | * @param handle Handle to clean up | 164 | * @param handle Handle to clean up |
163 | */ | 165 | */ |
164 | static void | 166 | static void |
165 | cleanup_handle(struct RequestHandle *handle) | 167 | cleanup_handle (struct RequestHandle *handle) |
166 | { | 168 | { |
167 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
168 | "Cleaning up\n"); | 170 | "Cleaning up\n"); |
169 | if (NULL != handle->json_root) | 171 | if (NULL != handle->json_root) |
170 | json_decref(handle->json_root); | 172 | json_decref (handle->json_root); |
171 | 173 | ||
172 | if (NULL != handle->issuer_attr) | 174 | if (NULL != handle->issuer_attr) |
173 | GNUNET_free(handle->issuer_attr); | 175 | GNUNET_free (handle->issuer_attr); |
174 | if (NULL != handle->subject_attr) | 176 | if (NULL != handle->subject_attr) |
175 | GNUNET_free(handle->subject_attr); | 177 | GNUNET_free (handle->subject_attr); |
176 | if (NULL != handle->verify_request) | 178 | if (NULL != handle->verify_request) |
177 | GNUNET_CREDENTIAL_request_cancel(handle->verify_request); | 179 | GNUNET_CREDENTIAL_request_cancel (handle->verify_request); |
178 | if (NULL != handle->credential) | 180 | if (NULL != handle->credential) |
179 | GNUNET_CREDENTIAL_disconnect(handle->credential); | 181 | GNUNET_CREDENTIAL_disconnect (handle->credential); |
180 | if (NULL != handle->id_op) | 182 | if (NULL != handle->id_op) |
181 | GNUNET_IDENTITY_cancel(handle->id_op); | 183 | GNUNET_IDENTITY_cancel (handle->id_op); |
182 | if (NULL != handle->ego_lookup) | 184 | if (NULL != handle->ego_lookup) |
183 | GNUNET_IDENTITY_ego_lookup_cancel(handle->ego_lookup); | 185 | GNUNET_IDENTITY_ego_lookup_cancel (handle->ego_lookup); |
184 | if (NULL != handle->identity) | 186 | if (NULL != handle->identity) |
185 | GNUNET_IDENTITY_disconnect(handle->identity); | 187 | GNUNET_IDENTITY_disconnect (handle->identity); |
186 | if (NULL != handle->timeout_task) | 188 | if (NULL != handle->timeout_task) |
187 | { | 189 | { |
188 | GNUNET_SCHEDULER_cancel(handle->timeout_task); | 190 | GNUNET_SCHEDULER_cancel (handle->timeout_task); |
189 | } | 191 | } |
190 | GNUNET_free(handle); | 192 | GNUNET_free (handle); |
191 | } | 193 | } |
192 | 194 | ||
193 | 195 | ||
194 | static void | 196 | static void |
195 | do_error(void *cls) | 197 | do_error (void *cls) |
196 | { | 198 | { |
197 | struct RequestHandle *handle = cls; | 199 | struct RequestHandle *handle = cls; |
198 | struct MHD_Response *resp; | 200 | struct MHD_Response *resp; |
199 | 201 | ||
200 | resp = GNUNET_REST_create_response(NULL); | 202 | resp = GNUNET_REST_create_response (NULL); |
201 | handle->proc(handle->proc_cls, resp, handle->response_code); | 203 | handle->proc (handle->proc_cls, resp, handle->response_code); |
202 | cleanup_handle(handle); | 204 | cleanup_handle (handle); |
203 | } | 205 | } |
204 | 206 | ||
205 | /** | 207 | /** |
@@ -209,41 +211,46 @@ do_error(void *cls) | |||
209 | * @return JSON, NULL if failed | 211 | * @return JSON, NULL if failed |
210 | */ | 212 | */ |
211 | static json_t* | 213 | static json_t* |
212 | attribute_delegation_to_json(struct GNUNET_CREDENTIAL_Delegation *delegation_chain_entry) | 214 | attribute_delegation_to_json (struct |
215 | GNUNET_CREDENTIAL_Delegation * | ||
216 | delegation_chain_entry) | ||
213 | { | 217 | { |
214 | char *subject; | 218 | char *subject; |
215 | char *issuer; | 219 | char *issuer; |
216 | json_t *attr_obj; | 220 | json_t *attr_obj; |
217 | 221 | ||
218 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&delegation_chain_entry->issuer_key); | 222 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string ( |
223 | &delegation_chain_entry->issuer_key); | ||
219 | if (NULL == issuer) | 224 | if (NULL == issuer) |
220 | { | 225 | { |
221 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 226 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
222 | "Issuer in delegation malformed\n"); | 227 | "Issuer in delegation malformed\n"); |
223 | return NULL; | 228 | return NULL; |
224 | } | 229 | } |
225 | subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&delegation_chain_entry->subject_key); | 230 | subject = GNUNET_CRYPTO_ecdsa_public_key_to_string ( |
231 | &delegation_chain_entry->subject_key); | ||
226 | if (NULL == subject) | 232 | if (NULL == subject) |
227 | { | 233 | { |
228 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
229 | "Subject in credential malformed\n"); | 235 | "Subject in credential malformed\n"); |
230 | GNUNET_free(issuer); | 236 | GNUNET_free (issuer); |
231 | return NULL; | 237 | return NULL; |
232 | } | 238 | } |
233 | attr_obj = json_object(); | 239 | attr_obj = json_object (); |
234 | 240 | ||
235 | json_object_set_new(attr_obj, "issuer", json_string(issuer)); | 241 | json_object_set_new (attr_obj, "issuer", json_string (issuer)); |
236 | json_object_set_new(attr_obj, "issuer_attribute", | 242 | json_object_set_new (attr_obj, "issuer_attribute", |
237 | json_string(delegation_chain_entry->issuer_attribute)); | 243 | json_string (delegation_chain_entry->issuer_attribute)); |
238 | 244 | ||
239 | json_object_set_new(attr_obj, "subject", json_string(subject)); | 245 | json_object_set_new (attr_obj, "subject", json_string (subject)); |
240 | if (0 < delegation_chain_entry->subject_attribute_len) | 246 | if (0 < delegation_chain_entry->subject_attribute_len) |
241 | { | 247 | { |
242 | json_object_set_new(attr_obj, "subject_attribute", | 248 | json_object_set_new (attr_obj, "subject_attribute", |
243 | json_string(delegation_chain_entry->subject_attribute)); | 249 | json_string ( |
244 | } | 250 | delegation_chain_entry->subject_attribute)); |
245 | GNUNET_free(issuer); | 251 | } |
246 | GNUNET_free(subject); | 252 | GNUNET_free (issuer); |
253 | GNUNET_free (subject); | ||
247 | return attr_obj; | 254 | return attr_obj; |
248 | } | 255 | } |
249 | 256 | ||
@@ -254,7 +261,7 @@ attribute_delegation_to_json(struct GNUNET_CREDENTIAL_Delegation *delegation_cha | |||
254 | * @return the resulting credential, NULL if failed | 261 | * @return the resulting credential, NULL if failed |
255 | */ | 262 | */ |
256 | static struct GNUNET_CREDENTIAL_Credential* | 263 | static struct GNUNET_CREDENTIAL_Credential* |
257 | json_to_credential(json_t *res) | 264 | json_to_credential (json_t *res) |
258 | { | 265 | { |
259 | struct GNUNET_CREDENTIAL_Credential *cred; | 266 | struct GNUNET_CREDENTIAL_Credential *cred; |
260 | json_t *tmp; | 267 | json_t *tmp; |
@@ -262,58 +269,58 @@ json_to_credential(json_t *res) | |||
262 | const char *signature; | 269 | const char *signature; |
263 | char *sig; | 270 | char *sig; |
264 | 271 | ||
265 | tmp = json_object_get(res, "attribute"); | 272 | tmp = json_object_get (res, "attribute"); |
266 | if (0 == json_is_string(tmp)) | 273 | if (0 == json_is_string (tmp)) |
267 | { | 274 | { |
268 | return NULL; | 275 | return NULL; |
269 | } | 276 | } |
270 | attribute = json_string_value(tmp); | 277 | attribute = json_string_value (tmp); |
271 | cred = GNUNET_malloc(sizeof(struct GNUNET_CREDENTIAL_Credential) | 278 | cred = GNUNET_malloc (sizeof(struct GNUNET_CREDENTIAL_Credential) |
272 | + strlen(attribute)); | 279 | + strlen (attribute)); |
273 | cred->issuer_attribute = attribute; | 280 | cred->issuer_attribute = attribute; |
274 | cred->issuer_attribute_len = strlen(attribute); | 281 | cred->issuer_attribute_len = strlen (attribute); |
275 | tmp = json_object_get(res, "issuer"); | 282 | tmp = json_object_get (res, "issuer"); |
276 | if (0 == json_is_string(tmp)) | 283 | if (0 == json_is_string (tmp)) |
277 | { | 284 | { |
278 | GNUNET_free(cred); | 285 | GNUNET_free (cred); |
279 | return NULL; | 286 | return NULL; |
280 | } | 287 | } |
281 | 288 | ||
282 | GNUNET_CRYPTO_ecdsa_public_key_from_string(json_string_value(tmp), | 289 | GNUNET_CRYPTO_ecdsa_public_key_from_string (json_string_value (tmp), |
283 | strlen(json_string_value(tmp)), | 290 | strlen (json_string_value (tmp)), |
284 | &cred->issuer_key); | 291 | &cred->issuer_key); |
285 | tmp = json_object_get(res, "subject"); | 292 | tmp = json_object_get (res, "subject"); |
286 | if (0 == json_is_string(tmp)) | 293 | if (0 == json_is_string (tmp)) |
287 | { | 294 | { |
288 | GNUNET_free(cred); | 295 | GNUNET_free (cred); |
289 | return NULL; | 296 | return NULL; |
290 | } | 297 | } |
291 | GNUNET_CRYPTO_ecdsa_public_key_from_string(json_string_value(tmp), | 298 | GNUNET_CRYPTO_ecdsa_public_key_from_string (json_string_value (tmp), |
292 | strlen(json_string_value(tmp)), | 299 | strlen (json_string_value (tmp)), |
293 | &cred->subject_key); | 300 | &cred->subject_key); |
294 | 301 | ||
295 | tmp = json_object_get(res, "signature"); | 302 | tmp = json_object_get (res, "signature"); |
296 | if (0 == json_is_string(tmp)) | 303 | if (0 == json_is_string (tmp)) |
297 | { | 304 | { |
298 | GNUNET_free(cred); | 305 | GNUNET_free (cred); |
299 | return NULL; | 306 | return NULL; |
300 | } | 307 | } |
301 | signature = json_string_value(tmp); | 308 | signature = json_string_value (tmp); |
302 | GNUNET_STRINGS_base64_decode(signature, | 309 | GNUNET_STRINGS_base64_decode (signature, |
303 | strlen(signature), | 310 | strlen (signature), |
304 | (char**)&sig); | 311 | (char**) &sig); |
305 | GNUNET_memcpy(&cred->signature, | 312 | GNUNET_memcpy (&cred->signature, |
306 | sig, | 313 | sig, |
307 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); | 314 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature)); |
308 | GNUNET_free(sig); | 315 | GNUNET_free (sig); |
309 | 316 | ||
310 | tmp = json_object_get(res, "expiration"); | 317 | tmp = json_object_get (res, "expiration"); |
311 | if (0 == json_is_integer(tmp)) | 318 | if (0 == json_is_integer (tmp)) |
312 | { | 319 | { |
313 | GNUNET_free(cred); | 320 | GNUNET_free (cred); |
314 | return NULL; | 321 | return NULL; |
315 | } | 322 | } |
316 | cred->expiration.abs_value_us = json_integer_value(tmp); | 323 | cred->expiration.abs_value_us = json_integer_value (tmp); |
317 | return cred; | 324 | return cred; |
318 | } | 325 | } |
319 | 326 | ||
@@ -325,7 +332,7 @@ json_to_credential(json_t *res) | |||
325 | * @return the resulting json, NULL if failed | 332 | * @return the resulting json, NULL if failed |
326 | */ | 333 | */ |
327 | static json_t* | 334 | static json_t* |
328 | credential_to_json(struct GNUNET_CREDENTIAL_Credential *cred) | 335 | credential_to_json (struct GNUNET_CREDENTIAL_Credential *cred) |
329 | { | 336 | { |
330 | char *issuer; | 337 | char *issuer; |
331 | char *subject; | 338 | char *subject; |
@@ -333,46 +340,47 @@ credential_to_json(struct GNUNET_CREDENTIAL_Credential *cred) | |||
333 | char attribute[cred->issuer_attribute_len + 1]; | 340 | char attribute[cred->issuer_attribute_len + 1]; |
334 | json_t *cred_obj; | 341 | json_t *cred_obj; |
335 | 342 | ||
336 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key); | 343 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); |
337 | if (NULL == issuer) | 344 | if (NULL == issuer) |
338 | { | 345 | { |
339 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 346 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
340 | "Issuer in credential malformed\n"); | 347 | "Issuer in credential malformed\n"); |
341 | return NULL; | 348 | return NULL; |
342 | } | 349 | } |
343 | subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key); | 350 | subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); |
344 | if (NULL == subject) | 351 | if (NULL == subject) |
345 | { | 352 | { |
346 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
347 | "Subject in credential malformed\n"); | 354 | "Subject in credential malformed\n"); |
348 | GNUNET_free(issuer); | 355 | GNUNET_free (issuer); |
349 | return NULL; | 356 | return NULL; |
350 | } | 357 | } |
351 | GNUNET_STRINGS_base64_encode((char*)&cred->signature, | 358 | GNUNET_STRINGS_base64_encode ((char*) &cred->signature, |
352 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), | 359 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), |
353 | &signature); | 360 | &signature); |
354 | GNUNET_memcpy(attribute, | 361 | GNUNET_memcpy (attribute, |
355 | cred->issuer_attribute, | 362 | cred->issuer_attribute, |
356 | cred->issuer_attribute_len); | 363 | cred->issuer_attribute_len); |
357 | attribute[cred->issuer_attribute_len] = '\0'; | 364 | attribute[cred->issuer_attribute_len] = '\0'; |
358 | cred_obj = json_object(); | 365 | cred_obj = json_object (); |
359 | json_object_set_new(cred_obj, "issuer", json_string(issuer)); | 366 | json_object_set_new (cred_obj, "issuer", json_string (issuer)); |
360 | json_object_set_new(cred_obj, "subject", json_string(subject)); | 367 | json_object_set_new (cred_obj, "subject", json_string (subject)); |
361 | json_object_set_new(cred_obj, "attribute", json_string(attribute)); | 368 | json_object_set_new (cred_obj, "attribute", json_string (attribute)); |
362 | json_object_set_new(cred_obj, "signature", json_string(signature)); | 369 | json_object_set_new (cred_obj, "signature", json_string (signature)); |
363 | json_object_set_new(cred_obj, "expiration", json_integer(cred->expiration.abs_value_us)); | 370 | json_object_set_new (cred_obj, "expiration", json_integer ( |
364 | GNUNET_free(issuer); | 371 | cred->expiration.abs_value_us)); |
365 | GNUNET_free(subject); | 372 | GNUNET_free (issuer); |
366 | GNUNET_free(signature); | 373 | GNUNET_free (subject); |
374 | GNUNET_free (signature); | ||
367 | return cred_obj; | 375 | return cred_obj; |
368 | } | 376 | } |
369 | 377 | ||
370 | static void | 378 | static void |
371 | handle_collect_response(void *cls, | 379 | handle_collect_response (void *cls, |
372 | unsigned int d_count, | 380 | unsigned int d_count, |
373 | struct GNUNET_CREDENTIAL_Delegation *delegation_chain, | 381 | struct GNUNET_CREDENTIAL_Delegation *delegation_chain, |
374 | unsigned int c_count, | 382 | unsigned int c_count, |
375 | struct GNUNET_CREDENTIAL_Credential *cred) | 383 | struct GNUNET_CREDENTIAL_Credential *cred) |
376 | { | 384 | { |
377 | struct RequestHandle *handle = cls; | 385 | struct RequestHandle *handle = cls; |
378 | struct MHD_Response *resp; | 386 | struct MHD_Response *resp; |
@@ -387,54 +395,55 @@ handle_collect_response(void *cls, | |||
387 | 395 | ||
388 | handle->verify_request = NULL; | 396 | handle->verify_request = NULL; |
389 | if (NULL == cred) | 397 | if (NULL == cred) |
390 | { | 398 | { |
391 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 399 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
392 | "Verify failed.\n"); | 400 | "Verify failed.\n"); |
393 | handle->response_code = MHD_HTTP_NOT_FOUND; | 401 | handle->response_code = MHD_HTTP_NOT_FOUND; |
394 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 402 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
395 | return; | 403 | return; |
396 | } | 404 | } |
397 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&handle->issuer_key); | 405 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&handle->issuer_key); |
398 | if (NULL == issuer) | 406 | if (NULL == issuer) |
399 | { | 407 | { |
400 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
401 | "Issuer in delegation malformed\n"); | 409 | "Issuer in delegation malformed\n"); |
402 | return; | 410 | return; |
403 | } | 411 | } |
404 | GNUNET_asprintf(&id, | 412 | GNUNET_asprintf (&id, |
405 | "%s.%s", | 413 | "%s.%s", |
406 | issuer, | 414 | issuer, |
407 | handle->issuer_attr); | 415 | handle->issuer_attr); |
408 | GNUNET_free(issuer); | 416 | GNUNET_free (issuer); |
409 | json_document = GNUNET_JSONAPI_document_new(); | 417 | json_document = GNUNET_JSONAPI_document_new (); |
410 | json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, | 418 | json_resource = GNUNET_JSONAPI_resource_new ( |
411 | id); | 419 | GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, |
412 | GNUNET_free(id); | 420 | id); |
413 | cred_array = json_array(); | 421 | GNUNET_free (id); |
422 | cred_array = json_array (); | ||
414 | for (i = 0; i < c_count; i++) | 423 | for (i = 0; i < c_count; i++) |
415 | { | 424 | { |
416 | cred_obj = credential_to_json(&cred[i]); | 425 | cred_obj = credential_to_json (&cred[i]); |
417 | json_array_append_new(cred_array, cred_obj); | 426 | json_array_append_new (cred_array, cred_obj); |
418 | } | 427 | } |
419 | GNUNET_JSONAPI_resource_add_attr(json_resource, | 428 | GNUNET_JSONAPI_resource_add_attr (json_resource, |
420 | GNUNET_REST_JSONAPI_CREDENTIAL, | 429 | GNUNET_REST_JSONAPI_CREDENTIAL, |
421 | cred_array); | 430 | cred_array); |
422 | GNUNET_JSONAPI_document_resource_add(json_document, json_resource); | 431 | GNUNET_JSONAPI_document_resource_add (json_document, json_resource); |
423 | GNUNET_JSONAPI_document_serialize(json_document, &result); | 432 | GNUNET_JSONAPI_document_serialize (json_document, &result); |
424 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
425 | "Result %s\n", | 434 | "Result %s\n", |
426 | result); | 435 | result); |
427 | json_decref(cred_array); | 436 | json_decref (cred_array); |
428 | GNUNET_JSONAPI_document_delete(json_document); | 437 | GNUNET_JSONAPI_document_delete (json_document); |
429 | resp = GNUNET_REST_create_response(result); | 438 | resp = GNUNET_REST_create_response (result); |
430 | GNUNET_free(result); | 439 | GNUNET_free (result); |
431 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 440 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
432 | cleanup_handle(handle); | 441 | cleanup_handle (handle); |
433 | } | 442 | } |
434 | 443 | ||
435 | static void | 444 | static void |
436 | subject_ego_lookup(void *cls, | 445 | subject_ego_lookup (void *cls, |
437 | const struct GNUNET_IDENTITY_Ego *ego) | 446 | const struct GNUNET_IDENTITY_Ego *ego) |
438 | { | 447 | { |
439 | struct RequestHandle *handle = cls; | 448 | struct RequestHandle *handle = cls; |
440 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *sub_key; | 449 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *sub_key; |
@@ -442,29 +451,29 @@ subject_ego_lookup(void *cls, | |||
442 | handle->ego_lookup = NULL; | 451 | handle->ego_lookup = NULL; |
443 | 452 | ||
444 | if (NULL == ego) | 453 | if (NULL == ego) |
445 | { | 454 | { |
446 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 455 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
447 | "Subject not found\n"); | 456 | "Subject not found\n"); |
448 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 457 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
449 | return; | 458 | return; |
450 | } | 459 | } |
451 | sub_key = GNUNET_IDENTITY_ego_get_private_key(ego); | 460 | sub_key = GNUNET_IDENTITY_ego_get_private_key (ego); |
452 | handle->verify_request = GNUNET_CREDENTIAL_collect(handle->credential, | 461 | handle->verify_request = GNUNET_CREDENTIAL_collect (handle->credential, |
453 | &handle->issuer_key, | 462 | &handle->issuer_key, |
454 | handle->issuer_attr, | 463 | handle->issuer_attr, |
455 | sub_key, | 464 | sub_key, |
456 | &handle_collect_response, | 465 | &handle_collect_response, |
457 | handle); | 466 | handle); |
458 | } | 467 | } |
459 | 468 | ||
460 | 469 | ||
461 | 470 | ||
462 | static void | 471 | static void |
463 | handle_verify_response(void *cls, | 472 | handle_verify_response (void *cls, |
464 | unsigned int d_count, | 473 | unsigned int d_count, |
465 | struct GNUNET_CREDENTIAL_Delegation *delegation_chain, | 474 | struct GNUNET_CREDENTIAL_Delegation *delegation_chain, |
466 | unsigned int c_count, | 475 | unsigned int c_count, |
467 | struct GNUNET_CREDENTIAL_Credential *cred) | 476 | struct GNUNET_CREDENTIAL_Credential *cred) |
468 | { | 477 | { |
469 | struct RequestHandle *handle = cls; | 478 | struct RequestHandle *handle = cls; |
470 | struct MHD_Response *resp; | 479 | struct MHD_Response *resp; |
@@ -481,165 +490,166 @@ handle_verify_response(void *cls, | |||
481 | 490 | ||
482 | handle->verify_request = NULL; | 491 | handle->verify_request = NULL; |
483 | if (NULL == cred) | 492 | if (NULL == cred) |
484 | { | 493 | { |
485 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 494 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
486 | "Verify failed.\n"); | 495 | "Verify failed.\n"); |
487 | handle->response_code = MHD_HTTP_NOT_FOUND; | 496 | handle->response_code = MHD_HTTP_NOT_FOUND; |
488 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 497 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
489 | return; | 498 | return; |
490 | } | 499 | } |
491 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&handle->issuer_key); | 500 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&handle->issuer_key); |
492 | if (NULL == issuer) | 501 | if (NULL == issuer) |
493 | { | 502 | { |
494 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 503 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
495 | "Issuer in delegation malformed\n"); | 504 | "Issuer in delegation malformed\n"); |
496 | return; | 505 | return; |
497 | } | 506 | } |
498 | GNUNET_asprintf(&id, | 507 | GNUNET_asprintf (&id, |
499 | "%s.%s", | 508 | "%s.%s", |
500 | issuer, | 509 | issuer, |
501 | handle->issuer_attr); | 510 | handle->issuer_attr); |
502 | GNUNET_free(issuer); | 511 | GNUNET_free (issuer); |
503 | json_document = GNUNET_JSONAPI_document_new(); | 512 | json_document = GNUNET_JSONAPI_document_new (); |
504 | json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, | 513 | json_resource = GNUNET_JSONAPI_resource_new ( |
505 | id); | 514 | GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, |
506 | GNUNET_free(id); | 515 | id); |
507 | attr_array = json_array(); | 516 | GNUNET_free (id); |
517 | attr_array = json_array (); | ||
508 | for (i = 0; i < d_count; i++) | 518 | for (i = 0; i < d_count; i++) |
509 | { | 519 | { |
510 | attr_obj = attribute_delegation_to_json(&delegation_chain[i]); | 520 | attr_obj = attribute_delegation_to_json (&delegation_chain[i]); |
511 | json_array_append_new(attr_array, attr_obj); | 521 | json_array_append_new (attr_array, attr_obj); |
512 | } | 522 | } |
513 | cred_array = json_array(); | 523 | cred_array = json_array (); |
514 | for (i = 0; i < c_count; i++) | 524 | for (i = 0; i < c_count; i++) |
515 | { | 525 | { |
516 | cred_obj = credential_to_json(&cred[i]); | 526 | cred_obj = credential_to_json (&cred[i]); |
517 | json_array_append_new(cred_array, cred_obj); | 527 | json_array_append_new (cred_array, cred_obj); |
518 | } | 528 | } |
519 | GNUNET_JSONAPI_resource_add_attr(json_resource, | 529 | GNUNET_JSONAPI_resource_add_attr (json_resource, |
520 | GNUNET_REST_JSONAPI_CREDENTIAL, | 530 | GNUNET_REST_JSONAPI_CREDENTIAL, |
521 | cred_array); | 531 | cred_array); |
522 | GNUNET_JSONAPI_resource_add_attr(json_resource, | 532 | GNUNET_JSONAPI_resource_add_attr (json_resource, |
523 | GNUNET_REST_JSONAPI_DELEGATIONS, | 533 | GNUNET_REST_JSONAPI_DELEGATIONS, |
524 | attr_array); | 534 | attr_array); |
525 | GNUNET_JSONAPI_document_resource_add(json_document, json_resource); | 535 | GNUNET_JSONAPI_document_resource_add (json_document, json_resource); |
526 | GNUNET_JSONAPI_document_serialize(json_document, &result); | 536 | GNUNET_JSONAPI_document_serialize (json_document, &result); |
527 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 537 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
528 | "Result %s\n", | 538 | "Result %s\n", |
529 | result); | 539 | result); |
530 | json_decref(attr_array); | 540 | json_decref (attr_array); |
531 | json_decref(cred_array); | 541 | json_decref (cred_array); |
532 | GNUNET_JSONAPI_document_delete(json_document); | 542 | GNUNET_JSONAPI_document_delete (json_document); |
533 | resp = GNUNET_REST_create_response(result); | 543 | resp = GNUNET_REST_create_response (result); |
534 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 544 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
535 | GNUNET_free(result); | 545 | GNUNET_free (result); |
536 | cleanup_handle(handle); | 546 | cleanup_handle (handle); |
537 | } | 547 | } |
538 | 548 | ||
539 | static void | 549 | static void |
540 | collect_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle, | 550 | collect_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, |
541 | const char* url, | 551 | const char*url, |
542 | void *cls) | 552 | void *cls) |
543 | { | 553 | { |
544 | struct RequestHandle *handle = cls; | 554 | struct RequestHandle *handle = cls; |
545 | struct GNUNET_HashCode key; | 555 | struct GNUNET_HashCode key; |
546 | char *tmp; | 556 | char *tmp; |
547 | char *entity_attr; | 557 | char *entity_attr; |
548 | 558 | ||
549 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 559 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
550 | "Connecting...\n"); | 560 | "Connecting...\n"); |
551 | handle->credential = GNUNET_CREDENTIAL_connect(cfg); | 561 | handle->credential = GNUNET_CREDENTIAL_connect (cfg); |
552 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout, | 562 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, |
553 | &do_error, handle); | 563 | &do_error, handle); |
554 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 564 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
555 | "Connected\n"); | 565 | "Connected\n"); |
556 | if (NULL == handle->credential) | 566 | if (NULL == handle->credential) |
557 | { | 567 | { |
558 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 568 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
559 | "Connecting to CREDENTIAL failed\n"); | 569 | "Connecting to CREDENTIAL failed\n"); |
560 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 570 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
561 | return; | 571 | return; |
562 | } | 572 | } |
563 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, | 573 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, |
564 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), | 574 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), |
565 | &key); | 575 | &key); |
566 | if (GNUNET_NO == | 576 | if (GNUNET_NO == |
567 | GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map, | 577 | GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, |
568 | &key)) | 578 | &key)) |
569 | { | 579 | { |
570 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 580 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
571 | "Missing issuer attribute\n"); | 581 | "Missing issuer attribute\n"); |
572 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 582 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
573 | return; | 583 | return; |
574 | } | 584 | } |
575 | tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map, | 585 | tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, |
576 | &key); | 586 | &key); |
577 | entity_attr = GNUNET_strdup(tmp); | 587 | entity_attr = GNUNET_strdup (tmp); |
578 | tmp = strtok(entity_attr, "."); | 588 | tmp = strtok (entity_attr, "."); |
579 | if (NULL == tmp) | 589 | if (NULL == tmp) |
580 | { | 590 | { |
581 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 591 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
582 | "Malformed issuer or attribute\n"); | 592 | "Malformed issuer or attribute\n"); |
583 | GNUNET_free(entity_attr); | 593 | GNUNET_free (entity_attr); |
584 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 594 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
585 | return; | 595 | return; |
586 | } | 596 | } |
587 | if (GNUNET_OK != | 597 | if (GNUNET_OK != |
588 | GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp, | 598 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, |
589 | strlen(tmp), | 599 | strlen (tmp), |
590 | &handle->issuer_key)) | 600 | &handle->issuer_key)) |
591 | { | 601 | { |
592 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 602 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
593 | "Malformed issuer key\n"); | 603 | "Malformed issuer key\n"); |
594 | GNUNET_free(entity_attr); | 604 | GNUNET_free (entity_attr); |
595 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 605 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
596 | return; | 606 | return; |
597 | } | 607 | } |
598 | tmp = strtok(NULL, "."); //Issuer attribute | 608 | tmp = strtok (NULL, "."); // Issuer attribute |
599 | if (NULL == tmp) | 609 | if (NULL == tmp) |
600 | { | 610 | { |
601 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 611 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
602 | "Malformed attribute\n"); | 612 | "Malformed attribute\n"); |
603 | GNUNET_free(entity_attr); | 613 | GNUNET_free (entity_attr); |
604 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 614 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
605 | return; | 615 | return; |
606 | } | 616 | } |
607 | handle->issuer_attr = GNUNET_strdup(tmp); | 617 | handle->issuer_attr = GNUNET_strdup (tmp); |
608 | GNUNET_free(entity_attr); | 618 | GNUNET_free (entity_attr); |
609 | 619 | ||
610 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO, | 620 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO, |
611 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO), | 621 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_EGO), |
612 | &key); | 622 | &key); |
613 | if (GNUNET_NO == | 623 | if (GNUNET_NO == |
614 | GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map, | 624 | GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, |
615 | &key)) | 625 | &key)) |
616 | { | 626 | { |
617 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 627 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
618 | "Missing subject\n"); | 628 | "Missing subject\n"); |
619 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 629 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
620 | return; | 630 | return; |
621 | } | 631 | } |
622 | tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map, | 632 | tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, |
623 | &key); | 633 | &key); |
624 | if (NULL == tmp) | 634 | if (NULL == tmp) |
625 | { | 635 | { |
626 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 636 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
627 | "Malformed subject\n"); | 637 | "Malformed subject\n"); |
628 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 638 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
629 | return; | 639 | return; |
630 | } | 640 | } |
631 | handle->ego_lookup = GNUNET_IDENTITY_ego_lookup(cfg, | 641 | handle->ego_lookup = GNUNET_IDENTITY_ego_lookup (cfg, |
632 | tmp, | 642 | tmp, |
633 | &subject_ego_lookup, | 643 | &subject_ego_lookup, |
634 | handle); | 644 | handle); |
635 | } | 645 | } |
636 | 646 | ||
637 | 647 | ||
638 | 648 | ||
639 | static void | 649 | static void |
640 | verify_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle, | 650 | verify_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, |
641 | const char* url, | 651 | const char*url, |
642 | void *cls) | 652 | void *cls) |
643 | { | 653 | { |
644 | struct RequestHandle *handle = cls; | 654 | struct RequestHandle *handle = cls; |
645 | struct GNUNET_HashCode key; | 655 | struct GNUNET_HashCode key; |
@@ -655,186 +665,186 @@ verify_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle, | |||
655 | json_t *data_js; | 665 | json_t *data_js; |
656 | json_error_t err; | 666 | json_error_t err; |
657 | 667 | ||
658 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 668 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
659 | "Connecting...\n"); | 669 | "Connecting...\n"); |
660 | handle->credential = GNUNET_CREDENTIAL_connect(cfg); | 670 | handle->credential = GNUNET_CREDENTIAL_connect (cfg); |
661 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout, | 671 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, |
662 | &do_error, handle); | 672 | &do_error, handle); |
663 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 673 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
664 | "Connected\n"); | 674 | "Connected\n"); |
665 | if (NULL == handle->credential) | 675 | if (NULL == handle->credential) |
666 | { | 676 | { |
667 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 677 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
668 | "Connecting to CREDENTIAL failed\n"); | 678 | "Connecting to CREDENTIAL failed\n"); |
669 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 679 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
670 | return; | 680 | return; |
671 | } | 681 | } |
672 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, | 682 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, |
673 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), | 683 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), |
674 | &key); | 684 | &key); |
675 | if (GNUNET_NO == | 685 | if (GNUNET_NO == |
676 | GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map, | 686 | GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, |
677 | &key)) | 687 | &key)) |
678 | { | 688 | { |
679 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 689 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
680 | "Missing issuer attribute\n"); | 690 | "Missing issuer attribute\n"); |
681 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 691 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
682 | return; | 692 | return; |
683 | } | 693 | } |
684 | tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map, | 694 | tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, |
685 | &key); | 695 | &key); |
686 | entity_attr = GNUNET_strdup(tmp); | 696 | entity_attr = GNUNET_strdup (tmp); |
687 | tmp = strtok(entity_attr, "."); | 697 | tmp = strtok (entity_attr, "."); |
688 | if (NULL == tmp) | 698 | if (NULL == tmp) |
689 | { | 699 | { |
690 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 700 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
691 | "Malformed issuer or attribute\n"); | 701 | "Malformed issuer or attribute\n"); |
692 | GNUNET_free(entity_attr); | 702 | GNUNET_free (entity_attr); |
693 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 703 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
694 | return; | 704 | return; |
695 | } | 705 | } |
696 | if (GNUNET_OK != | 706 | if (GNUNET_OK != |
697 | GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp, | 707 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, |
698 | strlen(tmp), | 708 | strlen (tmp), |
699 | &handle->issuer_key)) | 709 | &handle->issuer_key)) |
700 | { | 710 | { |
701 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 711 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
702 | "Malformed issuer key\n"); | 712 | "Malformed issuer key\n"); |
703 | GNUNET_free(entity_attr); | 713 | GNUNET_free (entity_attr); |
704 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 714 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
705 | return; | 715 | return; |
706 | } | 716 | } |
707 | tmp = strtok(NULL, "."); //Issuer attribute | 717 | tmp = strtok (NULL, "."); // Issuer attribute |
708 | if (NULL == tmp) | 718 | if (NULL == tmp) |
709 | { | 719 | { |
710 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 720 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
711 | "Malformed attribute\n"); | 721 | "Malformed attribute\n"); |
712 | GNUNET_free(entity_attr); | 722 | GNUNET_free (entity_attr); |
713 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 723 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
714 | return; | 724 | return; |
715 | } | 725 | } |
716 | handle->issuer_attr = GNUNET_strdup(tmp); | 726 | handle->issuer_attr = GNUNET_strdup (tmp); |
717 | GNUNET_free(entity_attr); | 727 | GNUNET_free (entity_attr); |
718 | 728 | ||
719 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, | 729 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, |
720 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), | 730 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), |
721 | &key); | 731 | &key); |
722 | if (GNUNET_NO == | 732 | if (GNUNET_NO == |
723 | GNUNET_CONTAINER_multihashmap_contains(conndata_handle->url_param_map, | 733 | GNUNET_CONTAINER_multihashmap_contains (conndata_handle->url_param_map, |
724 | &key)) | 734 | &key)) |
725 | { | 735 | { |
726 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 736 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
727 | "Missing subject key\n"); | 737 | "Missing subject key\n"); |
728 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 738 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
729 | return; | 739 | return; |
730 | } | 740 | } |
731 | tmp = GNUNET_CONTAINER_multihashmap_get(conndata_handle->url_param_map, | 741 | tmp = GNUNET_CONTAINER_multihashmap_get (conndata_handle->url_param_map, |
732 | &key); | 742 | &key); |
733 | if (NULL == tmp) | 743 | if (NULL == tmp) |
734 | { | 744 | { |
735 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 745 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
736 | "Malformed subject\n"); | 746 | "Malformed subject\n"); |
737 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 747 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
738 | return; | 748 | return; |
739 | } | 749 | } |
740 | if (GNUNET_OK != | 750 | if (GNUNET_OK != |
741 | GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp, | 751 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, |
742 | strlen(tmp), | 752 | strlen (tmp), |
743 | &handle->subject_key)) | 753 | &handle->subject_key)) |
744 | { | 754 | { |
745 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 755 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
746 | "Malformed subject key\n"); | 756 | "Malformed subject key\n"); |
747 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 757 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
748 | return; | 758 | return; |
749 | } | 759 | } |
750 | 760 | ||
751 | if (0 >= handle->rest_handle->data_size) | 761 | if (0 >= handle->rest_handle->data_size) |
752 | { | 762 | { |
753 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 763 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
754 | "Missing credentials\n"); | 764 | "Missing credentials\n"); |
755 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 765 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
756 | return; | 766 | return; |
757 | } | 767 | } |
758 | 768 | ||
759 | struct GNUNET_JSON_Specification docspec[] = { | 769 | struct GNUNET_JSON_Specification docspec[] = { |
760 | GNUNET_JSON_spec_jsonapi_document(&json_obj), | 770 | GNUNET_JSON_spec_jsonapi_document (&json_obj), |
761 | GNUNET_JSON_spec_end() | 771 | GNUNET_JSON_spec_end () |
762 | }; | 772 | }; |
763 | char term_data[handle->rest_handle->data_size + 1]; | 773 | char term_data[handle->rest_handle->data_size + 1]; |
764 | term_data[handle->rest_handle->data_size] = '\0'; | 774 | term_data[handle->rest_handle->data_size] = '\0'; |
765 | credential_count = 0; | 775 | credential_count = 0; |
766 | GNUNET_memcpy(term_data, | 776 | GNUNET_memcpy (term_data, |
767 | handle->rest_handle->data, | 777 | handle->rest_handle->data, |
768 | handle->rest_handle->data_size); | 778 | handle->rest_handle->data_size); |
769 | data_js = json_loads(term_data, | 779 | data_js = json_loads (term_data, |
770 | JSON_DECODE_ANY, | 780 | JSON_DECODE_ANY, |
771 | &err); | 781 | &err); |
772 | GNUNET_assert(GNUNET_OK == GNUNET_JSON_parse(data_js, docspec, | 782 | GNUNET_assert (GNUNET_OK == GNUNET_JSON_parse (data_js, docspec, |
773 | NULL, NULL)); | 783 | NULL, NULL)); |
774 | json_decref(data_js); | 784 | json_decref (data_js); |
775 | if (NULL == json_obj) | 785 | if (NULL == json_obj) |
776 | { | 786 | { |
777 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 787 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
778 | "Unable to parse JSONAPI Object from %s\n", | 788 | "Unable to parse JSONAPI Object from %s\n", |
779 | term_data); | 789 | term_data); |
780 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 790 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
781 | return; | 791 | return; |
782 | } | 792 | } |
783 | 793 | ||
784 | resource_count = GNUNET_JSONAPI_document_resource_count(json_obj); | 794 | resource_count = GNUNET_JSONAPI_document_resource_count (json_obj); |
785 | GNUNET_assert(1 == resource_count); | 795 | GNUNET_assert (1 == resource_count); |
786 | res = (GNUNET_JSONAPI_document_get_resource(json_obj, 0)); | 796 | res = (GNUNET_JSONAPI_document_get_resource (json_obj, 0)); |
787 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type(res, | 797 | if (GNUNET_NO == GNUNET_JSONAPI_resource_check_type (res, |
788 | GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO)) | 798 | GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO)) |
789 | { | 799 | { |
790 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 800 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
791 | "Resource not a credential!\n"); | 801 | "Resource not a credential!\n"); |
792 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 802 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
793 | "Unable to parse JSONAPI Object from %s\n", | 803 | "Unable to parse JSONAPI Object from %s\n", |
794 | term_data); | 804 | term_data); |
795 | GNUNET_JSONAPI_document_delete(json_obj); | 805 | GNUNET_JSONAPI_document_delete (json_obj); |
796 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 806 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
797 | return; | 807 | return; |
798 | } | 808 | } |
799 | cred_json = GNUNET_JSONAPI_resource_read_attr(res, | 809 | cred_json = GNUNET_JSONAPI_resource_read_attr (res, |
800 | GNUNET_REST_JSONAPI_CREDENTIAL); | 810 | GNUNET_REST_JSONAPI_CREDENTIAL); |
801 | 811 | ||
802 | GNUNET_assert(json_is_array(cred_json)); | 812 | GNUNET_assert (json_is_array (cred_json)); |
803 | 813 | ||
804 | credential_count = json_array_size(cred_json); | 814 | credential_count = json_array_size (cred_json); |
805 | 815 | ||
806 | struct GNUNET_CREDENTIAL_Credential credentials[credential_count]; | 816 | struct GNUNET_CREDENTIAL_Credential credentials[credential_count]; |
807 | for (i = 0; i < credential_count; i++) | 817 | for (i = 0; i < credential_count; i++) |
818 | { | ||
819 | cred = json_to_credential (json_array_get (cred_json, i)); | ||
820 | if (NULL == cred) | ||
808 | { | 821 | { |
809 | cred = json_to_credential(json_array_get(cred_json, i)); | 822 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
810 | if (NULL == cred) | 823 | "Unable to parse credential!\n"); |
811 | { | 824 | continue; |
812 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
813 | "Unable to parse credential!\n"); | ||
814 | continue; | ||
815 | } | ||
816 | GNUNET_memcpy(&credentials[i], | ||
817 | cred, | ||
818 | sizeof(struct GNUNET_CREDENTIAL_Credential)); | ||
819 | credentials[i].issuer_attribute = GNUNET_strdup(cred->issuer_attribute); | ||
820 | GNUNET_free(cred); | ||
821 | } | 825 | } |
822 | GNUNET_JSONAPI_document_delete(json_obj); | 826 | GNUNET_memcpy (&credentials[i], |
823 | handle->verify_request = GNUNET_CREDENTIAL_verify(handle->credential, | 827 | cred, |
824 | &handle->issuer_key, | 828 | sizeof(struct GNUNET_CREDENTIAL_Credential)); |
825 | handle->issuer_attr, | 829 | credentials[i].issuer_attribute = GNUNET_strdup (cred->issuer_attribute); |
826 | &handle->subject_key, | 830 | GNUNET_free (cred); |
827 | credential_count, | 831 | } |
828 | credentials, | 832 | GNUNET_JSONAPI_document_delete (json_obj); |
829 | &handle_verify_response, | 833 | handle->verify_request = GNUNET_CREDENTIAL_verify (handle->credential, |
830 | handle); | 834 | &handle->issuer_key, |
835 | handle->issuer_attr, | ||
836 | &handle->subject_key, | ||
837 | credential_count, | ||
838 | credentials, | ||
839 | &handle_verify_response, | ||
840 | handle); | ||
831 | for (i = 0; i < credential_count; i++) | 841 | for (i = 0; i < credential_count; i++) |
832 | GNUNET_free((char*)credentials[i].issuer_attribute); | 842 | GNUNET_free ((char*) credentials[i].issuer_attribute); |
833 | } | 843 | } |
834 | 844 | ||
835 | void | 845 | void |
836 | send_cred_response(struct RequestHandle *handle, | 846 | send_cred_response (struct RequestHandle *handle, |
837 | struct GNUNET_CREDENTIAL_Credential *cred) | 847 | struct GNUNET_CREDENTIAL_Credential *cred) |
838 | { | 848 | { |
839 | struct MHD_Response *resp; | 849 | struct MHD_Response *resp; |
840 | struct GNUNET_JSONAPI_Document *json_document; | 850 | struct GNUNET_JSONAPI_Document *json_document; |
@@ -846,64 +856,66 @@ send_cred_response(struct RequestHandle *handle, | |||
846 | char *signature; | 856 | char *signature; |
847 | char *id; | 857 | char *id; |
848 | 858 | ||
849 | GNUNET_assert(NULL != cred); | 859 | GNUNET_assert (NULL != cred); |
850 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->issuer_key); | 860 | issuer = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->issuer_key); |
851 | if (NULL == issuer) | 861 | if (NULL == issuer) |
852 | { | 862 | { |
853 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 863 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
854 | "Subject malformed\n"); | 864 | "Subject malformed\n"); |
855 | GNUNET_free(issuer); | 865 | GNUNET_free (issuer); |
856 | return; | 866 | return; |
857 | } | 867 | } |
858 | GNUNET_asprintf(&id, | 868 | GNUNET_asprintf (&id, |
859 | "%s.%s", | 869 | "%s.%s", |
860 | issuer, | 870 | issuer, |
861 | (char*)&cred[1]); | 871 | (char*) &cred[1]); |
862 | subject = GNUNET_CRYPTO_ecdsa_public_key_to_string(&cred->subject_key); | 872 | subject = GNUNET_CRYPTO_ecdsa_public_key_to_string (&cred->subject_key); |
863 | if (NULL == subject) | 873 | if (NULL == subject) |
864 | { | 874 | { |
865 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 875 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
866 | "Subject malformed\n"); | 876 | "Subject malformed\n"); |
867 | GNUNET_free(id); | 877 | GNUNET_free (id); |
868 | GNUNET_free(issuer); | 878 | GNUNET_free (issuer); |
869 | return; | 879 | return; |
870 | } | 880 | } |
871 | GNUNET_STRINGS_base64_encode((char*)&cred->signature, | 881 | GNUNET_STRINGS_base64_encode ((char*) &cred->signature, |
872 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), | 882 | sizeof(struct GNUNET_CRYPTO_EcdsaSignature), |
873 | &signature); | 883 | &signature); |
874 | json_document = GNUNET_JSONAPI_document_new(); | 884 | json_document = GNUNET_JSONAPI_document_new (); |
875 | json_resource = GNUNET_JSONAPI_resource_new(GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, | 885 | json_resource = GNUNET_JSONAPI_resource_new ( |
876 | id); | 886 | GNUNET_REST_JSONAPI_CREDENTIAL_TYPEINFO, |
877 | GNUNET_free(id); | 887 | id); |
878 | cred_obj = json_object(); | 888 | GNUNET_free (id); |
879 | json_object_set_new(cred_obj, "issuer", json_string(issuer)); | 889 | cred_obj = json_object (); |
880 | json_object_set_new(cred_obj, "subject", json_string(subject)); | 890 | json_object_set_new (cred_obj, "issuer", json_string (issuer)); |
881 | json_object_set_new(cred_obj, "expiration", json_integer(cred->expiration.abs_value_us)); | 891 | json_object_set_new (cred_obj, "subject", json_string (subject)); |
882 | json_object_set_new(cred_obj, "signature", json_string(signature)); | 892 | json_object_set_new (cred_obj, "expiration", json_integer ( |
883 | GNUNET_JSONAPI_resource_add_attr(json_resource, | 893 | cred->expiration.abs_value_us)); |
884 | GNUNET_REST_JSONAPI_CREDENTIAL, | 894 | json_object_set_new (cred_obj, "signature", json_string (signature)); |
885 | cred_obj); | 895 | GNUNET_JSONAPI_resource_add_attr (json_resource, |
886 | GNUNET_JSONAPI_document_resource_add(json_document, json_resource); | 896 | GNUNET_REST_JSONAPI_CREDENTIAL, |
887 | GNUNET_JSONAPI_document_serialize(json_document, &result); | 897 | cred_obj); |
888 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 898 | GNUNET_JSONAPI_document_resource_add (json_document, json_resource); |
889 | "Result %s\n", | 899 | GNUNET_JSONAPI_document_serialize (json_document, &result); |
890 | result); | 900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
891 | json_decref(cred_obj); | 901 | "Result %s\n", |
892 | GNUNET_JSONAPI_document_delete(json_document); | 902 | result); |
893 | resp = GNUNET_REST_create_response(result); | 903 | json_decref (cred_obj); |
894 | handle->proc(handle->proc_cls, resp, MHD_HTTP_OK); | 904 | GNUNET_JSONAPI_document_delete (json_document); |
895 | GNUNET_free(result); | 905 | resp = GNUNET_REST_create_response (result); |
896 | GNUNET_free(signature); | 906 | handle->proc (handle->proc_cls, resp, MHD_HTTP_OK); |
897 | GNUNET_free(issuer); | 907 | GNUNET_free (result); |
898 | GNUNET_free(subject); | 908 | GNUNET_free (signature); |
899 | cleanup_handle(handle); | 909 | GNUNET_free (issuer); |
910 | GNUNET_free (subject); | ||
911 | cleanup_handle (handle); | ||
900 | } | 912 | } |
901 | 913 | ||
902 | void | 914 | void |
903 | get_cred_issuer_cb(void *cls, | 915 | get_cred_issuer_cb (void *cls, |
904 | struct GNUNET_IDENTITY_Ego *ego, | 916 | struct GNUNET_IDENTITY_Ego *ego, |
905 | void **ctx, | 917 | void **ctx, |
906 | const char *name) | 918 | const char *name) |
907 | { | 919 | { |
908 | struct RequestHandle *handle = cls; | 920 | struct RequestHandle *handle = cls; |
909 | struct GNUNET_TIME_Absolute etime_abs; | 921 | struct GNUNET_TIME_Absolute etime_abs; |
@@ -911,173 +923,178 @@ get_cred_issuer_cb(void *cls, | |||
911 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer_key; | 923 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer_key; |
912 | struct GNUNET_HashCode key; | 924 | struct GNUNET_HashCode key; |
913 | struct GNUNET_CREDENTIAL_Credential *cred; | 925 | struct GNUNET_CREDENTIAL_Credential *cred; |
914 | char* expiration_str; | 926 | char*expiration_str; |
915 | char* tmp; | 927 | char*tmp; |
916 | 928 | ||
917 | handle->id_op = NULL; | 929 | handle->id_op = NULL; |
918 | 930 | ||
919 | if (NULL == name) | 931 | if (NULL == name) |
920 | { | 932 | { |
921 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 933 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
922 | "Issuer not configured!\n"); | 934 | "Issuer not configured!\n"); |
923 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 935 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
924 | return; | 936 | return; |
925 | } | 937 | } |
926 | 938 | ||
927 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 939 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
928 | "Connecting to credential service...\n"); | 940 | "Connecting to credential service...\n"); |
929 | handle->credential = GNUNET_CREDENTIAL_connect(cfg); | 941 | handle->credential = GNUNET_CREDENTIAL_connect (cfg); |
930 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 942 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
931 | "Connected\n"); | 943 | "Connected\n"); |
932 | if (NULL == handle->credential) | 944 | if (NULL == handle->credential) |
933 | { | 945 | { |
934 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 946 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
935 | "Connecting to CREDENTIAL failed\n"); | 947 | "Connecting to CREDENTIAL failed\n"); |
936 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 948 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
937 | return; | 949 | return; |
938 | } | 950 | } |
939 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION, | 951 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION, |
940 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION), | 952 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_EXPIRATION), |
941 | &key); | 953 | &key); |
942 | if (GNUNET_NO == | 954 | if (GNUNET_NO == |
943 | GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map, | 955 | GNUNET_CONTAINER_multihashmap_contains ( |
944 | &key)) | 956 | handle->rest_handle->url_param_map, |
945 | { | 957 | &key)) |
946 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 958 | { |
947 | "Missing expiration\n"); | 959 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
948 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 960 | "Missing expiration\n"); |
949 | return; | 961 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
950 | } | 962 | return; |
951 | expiration_str = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map, | 963 | } |
952 | &key); | 964 | expiration_str = GNUNET_CONTAINER_multihashmap_get ( |
965 | handle->rest_handle->url_param_map, | ||
966 | &key); | ||
953 | if (NULL == expiration_str) | 967 | if (NULL == expiration_str) |
954 | { | 968 | { |
955 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 969 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
956 | "Expiration malformed\n"); | 970 | "Expiration malformed\n"); |
957 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 971 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
958 | return; | 972 | return; |
959 | } | 973 | } |
960 | 974 | ||
961 | if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative(expiration_str, | 975 | if (GNUNET_OK == GNUNET_STRINGS_fancy_time_to_relative (expiration_str, |
962 | &etime_rel)) | 976 | &etime_rel)) |
963 | { | 977 | { |
964 | etime_abs = GNUNET_TIME_relative_to_absolute(etime_rel); | 978 | etime_abs = GNUNET_TIME_relative_to_absolute (etime_rel); |
965 | } | 979 | } |
966 | else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute(expiration_str, | 980 | else if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_absolute (expiration_str, |
967 | &etime_abs)) | 981 | &etime_abs)) |
968 | { | 982 | { |
969 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 983 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
970 | "Malformed expiration: %s\n", expiration_str); | 984 | "Malformed expiration: %s\n", expiration_str); |
971 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 985 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
972 | return; | 986 | return; |
973 | } | 987 | } |
974 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, | 988 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR, |
975 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), | 989 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_ISSUER_ATTR), |
976 | &key); | 990 | &key); |
977 | if (GNUNET_NO == | 991 | if (GNUNET_NO == |
978 | GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map, | 992 | GNUNET_CONTAINER_multihashmap_contains ( |
979 | &key)) | 993 | handle->rest_handle->url_param_map, |
980 | { | 994 | &key)) |
981 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 995 | { |
982 | "Missing issuer attribute\n"); | 996 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
983 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 997 | "Missing issuer attribute\n"); |
984 | return; | 998 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
985 | } | 999 | return; |
986 | handle->issuer_attr = GNUNET_strdup(GNUNET_CONTAINER_multihashmap_get | 1000 | } |
987 | (handle->rest_handle->url_param_map, | 1001 | handle->issuer_attr = GNUNET_strdup (GNUNET_CONTAINER_multihashmap_get |
988 | &key)); | 1002 | (handle->rest_handle->url_param_map, |
989 | GNUNET_CRYPTO_hash(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, | 1003 | &key)); |
990 | strlen(GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), | 1004 | GNUNET_CRYPTO_hash (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY, |
991 | &key); | 1005 | strlen (GNUNET_REST_JSONAPI_CREDENTIAL_SUBJECT_KEY), |
1006 | &key); | ||
992 | if (GNUNET_NO == | 1007 | if (GNUNET_NO == |
993 | GNUNET_CONTAINER_multihashmap_contains(handle->rest_handle->url_param_map, | 1008 | GNUNET_CONTAINER_multihashmap_contains ( |
994 | &key)) | 1009 | handle->rest_handle->url_param_map, |
995 | { | 1010 | &key)) |
996 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1011 | { |
997 | "Missing subject\n"); | 1012 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
998 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 1013 | "Missing subject\n"); |
999 | return; | 1014 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1000 | } | 1015 | return; |
1001 | tmp = GNUNET_CONTAINER_multihashmap_get(handle->rest_handle->url_param_map, | 1016 | } |
1002 | &key); | 1017 | tmp = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, |
1018 | &key); | ||
1003 | if (NULL == tmp) | 1019 | if (NULL == tmp) |
1004 | { | 1020 | { |
1005 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1021 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1006 | "Malformed subject\n"); | 1022 | "Malformed subject\n"); |
1007 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 1023 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1008 | return; | 1024 | return; |
1009 | } | 1025 | } |
1010 | if (GNUNET_OK != | 1026 | if (GNUNET_OK != |
1011 | GNUNET_CRYPTO_ecdsa_public_key_from_string(tmp, | 1027 | GNUNET_CRYPTO_ecdsa_public_key_from_string (tmp, |
1012 | strlen(tmp), | 1028 | strlen (tmp), |
1013 | &handle->subject_key)) | 1029 | &handle->subject_key)) |
1014 | { | 1030 | { |
1015 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1031 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1016 | "Malformed subject key\n"); | 1032 | "Malformed subject key\n"); |
1017 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 1033 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1018 | return; | 1034 | return; |
1019 | } | 1035 | } |
1020 | issuer_key = GNUNET_IDENTITY_ego_get_private_key(ego); | 1036 | issuer_key = GNUNET_IDENTITY_ego_get_private_key (ego); |
1021 | cred = GNUNET_CREDENTIAL_credential_issue(issuer_key, | 1037 | cred = GNUNET_CREDENTIAL_credential_issue (issuer_key, |
1022 | &handle->subject_key, | 1038 | &handle->subject_key, |
1023 | handle->issuer_attr, | 1039 | handle->issuer_attr, |
1024 | &etime_abs); | 1040 | &etime_abs); |
1025 | if (NULL == cred) | 1041 | if (NULL == cred) |
1026 | { | 1042 | { |
1027 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1043 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1028 | "Failed to create credential\n"); | 1044 | "Failed to create credential\n"); |
1029 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 1045 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1030 | return; | 1046 | return; |
1031 | } | 1047 | } |
1032 | send_cred_response(handle, cred); | 1048 | send_cred_response (handle, cred); |
1033 | } | 1049 | } |
1034 | 1050 | ||
1035 | 1051 | ||
1036 | static void | 1052 | static void |
1037 | issue_cred_cont(struct GNUNET_REST_RequestHandle *conndata_handle, | 1053 | issue_cred_cont (struct GNUNET_REST_RequestHandle *conndata_handle, |
1038 | const char* url, | 1054 | const char*url, |
1039 | void *cls) | 1055 | void *cls) |
1040 | { | 1056 | { |
1041 | struct RequestHandle *handle = cls; | 1057 | struct RequestHandle *handle = cls; |
1042 | 1058 | ||
1043 | handle->identity = GNUNET_IDENTITY_connect(cfg, | 1059 | handle->identity = GNUNET_IDENTITY_connect (cfg, |
1044 | NULL, | 1060 | NULL, |
1045 | NULL); | 1061 | NULL); |
1046 | handle->id_op = GNUNET_IDENTITY_get(handle->identity, | 1062 | handle->id_op = GNUNET_IDENTITY_get (handle->identity, |
1047 | "credential-issuer", | 1063 | "credential-issuer", |
1048 | &get_cred_issuer_cb, | 1064 | &get_cred_issuer_cb, |
1049 | handle); | 1065 | handle); |
1050 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed(handle->timeout, | 1066 | handle->timeout_task = GNUNET_SCHEDULER_add_delayed (handle->timeout, |
1051 | &do_error, | 1067 | &do_error, |
1052 | handle); | 1068 | handle); |
1053 | } | 1069 | } |
1054 | 1070 | ||
1055 | static void | 1071 | static void |
1056 | options_cont(struct GNUNET_REST_RequestHandle *con_handle, | 1072 | options_cont (struct GNUNET_REST_RequestHandle *con_handle, |
1057 | const char* url, | 1073 | const char*url, |
1058 | void *cls) | 1074 | void *cls) |
1059 | { | 1075 | { |
1060 | struct MHD_Response *resp; | 1076 | struct MHD_Response *resp; |
1061 | struct RequestHandle *handle = cls; | 1077 | struct RequestHandle *handle = cls; |
1062 | 1078 | ||
1063 | //For GNS, independent of path return all options | 1079 | // For GNS, independent of path return all options |
1064 | resp = GNUNET_REST_create_response(NULL); | 1080 | resp = GNUNET_REST_create_response (NULL); |
1065 | MHD_add_response_header(resp, | 1081 | MHD_add_response_header (resp, |
1066 | "Access-Control-Allow-Methods", | 1082 | "Access-Control-Allow-Methods", |
1067 | MHD_HTTP_METHOD_GET); | 1083 | MHD_HTTP_METHOD_GET); |
1068 | handle->proc(handle->proc_cls, | 1084 | handle->proc (handle->proc_cls, |
1069 | resp, | 1085 | resp, |
1070 | MHD_HTTP_OK); | 1086 | MHD_HTTP_OK); |
1071 | cleanup_handle(handle); | 1087 | cleanup_handle (handle); |
1072 | } | 1088 | } |
1073 | 1089 | ||
1074 | 1090 | ||
1075 | static void | 1091 | static void |
1076 | rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, | 1092 | rest_credential_process_request (struct |
1077 | GNUNET_REST_ResultProcessor proc, | 1093 | GNUNET_REST_RequestHandle *conndata_handle, |
1078 | void *proc_cls) | 1094 | GNUNET_REST_ResultProcessor proc, |
1095 | void *proc_cls) | ||
1079 | { | 1096 | { |
1080 | struct RequestHandle *handle = GNUNET_new(struct RequestHandle); | 1097 | struct RequestHandle *handle = GNUNET_new (struct RequestHandle); |
1081 | struct GNUNET_REST_RequestHandlerError err; | 1098 | struct GNUNET_REST_RequestHandlerError err; |
1082 | 1099 | ||
1083 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1100 | handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
@@ -1086,21 +1103,24 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl | |||
1086 | handle->rest_handle = conndata_handle; | 1103 | handle->rest_handle = conndata_handle; |
1087 | 1104 | ||
1088 | static const struct GNUNET_REST_RequestHandler handlers[] = { | 1105 | static const struct GNUNET_REST_RequestHandler handlers[] = { |
1089 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_CREDENTIAL_VERIFY, &verify_cred_cont }, | 1106 | { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_CREDENTIAL_VERIFY, |
1090 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_COLLECT, &collect_cred_cont }, | 1107 | &verify_cred_cont }, |
1091 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_ISSUE, &issue_cred_cont }, | 1108 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_COLLECT, |
1109 | &collect_cred_cont }, | ||
1110 | { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_CREDENTIAL_ISSUE, | ||
1111 | &issue_cred_cont }, | ||
1092 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CREDENTIAL, &options_cont }, | 1112 | { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_CREDENTIAL, &options_cont }, |
1093 | GNUNET_REST_HANDLER_END | 1113 | GNUNET_REST_HANDLER_END |
1094 | }; | 1114 | }; |
1095 | 1115 | ||
1096 | if (GNUNET_NO == GNUNET_JSONAPI_handle_request(conndata_handle, | 1116 | if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle, |
1097 | handlers, | 1117 | handlers, |
1098 | &err, | 1118 | &err, |
1099 | handle)) | 1119 | handle)) |
1100 | { | 1120 | { |
1101 | handle->response_code = err.error_code; | 1121 | handle->response_code = err.error_code; |
1102 | GNUNET_SCHEDULER_add_now(&do_error, handle); | 1122 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
1103 | } | 1123 | } |
1104 | } | 1124 | } |
1105 | 1125 | ||
1106 | 1126 | ||
@@ -1111,7 +1131,7 @@ rest_credential_process_request(struct GNUNET_REST_RequestHandle *conndata_handl | |||
1111 | * @return NULL on error, otherwise the plugin context | 1131 | * @return NULL on error, otherwise the plugin context |
1112 | */ | 1132 | */ |
1113 | void * | 1133 | void * |
1114 | libgnunet_plugin_rest_credential_init(void *cls) | 1134 | libgnunet_plugin_rest_credential_init (void *cls) |
1115 | { | 1135 | { |
1116 | static struct Plugin plugin; | 1136 | static struct Plugin plugin; |
1117 | 1137 | ||
@@ -1120,14 +1140,14 @@ libgnunet_plugin_rest_credential_init(void *cls) | |||
1120 | 1140 | ||
1121 | if (NULL != plugin.cfg) | 1141 | if (NULL != plugin.cfg) |
1122 | return NULL; /* can only initialize once! */ | 1142 | return NULL; /* can only initialize once! */ |
1123 | memset(&plugin, 0, sizeof(struct Plugin)); | 1143 | memset (&plugin, 0, sizeof(struct Plugin)); |
1124 | plugin.cfg = cfg; | 1144 | plugin.cfg = cfg; |
1125 | api = GNUNET_new(struct GNUNET_REST_Plugin); | 1145 | api = GNUNET_new (struct GNUNET_REST_Plugin); |
1126 | api->cls = &plugin; | 1146 | api->cls = &plugin; |
1127 | api->name = GNUNET_REST_API_NS_CREDENTIAL; | 1147 | api->name = GNUNET_REST_API_NS_CREDENTIAL; |
1128 | api->process_request = &rest_credential_process_request; | 1148 | api->process_request = &rest_credential_process_request; |
1129 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1149 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1130 | _("GNS REST API initialized\n")); | 1150 | _ ("GNS REST API initialized\n")); |
1131 | return api; | 1151 | return api; |
1132 | } | 1152 | } |
1133 | 1153 | ||
@@ -1139,15 +1159,15 @@ libgnunet_plugin_rest_credential_init(void *cls) | |||
1139 | * @return always NULL | 1159 | * @return always NULL |
1140 | */ | 1160 | */ |
1141 | void * | 1161 | void * |
1142 | libgnunet_plugin_rest_credential_done(void *cls) | 1162 | libgnunet_plugin_rest_credential_done (void *cls) |
1143 | { | 1163 | { |
1144 | struct GNUNET_REST_Plugin *api = cls; | 1164 | struct GNUNET_REST_Plugin *api = cls; |
1145 | struct Plugin *plugin = api->cls; | 1165 | struct Plugin *plugin = api->cls; |
1146 | 1166 | ||
1147 | plugin->cfg = NULL; | 1167 | plugin->cfg = NULL; |
1148 | GNUNET_free(api); | 1168 | GNUNET_free (api); |
1149 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1150 | "GNS REST plugin is finished\n"); | 1170 | "GNS REST plugin is finished\n"); |
1151 | return NULL; | 1171 | return NULL; |
1152 | } | 1172 | } |
1153 | 1173 | ||