aboutsummaryrefslogtreecommitdiff
path: root/src/credential/credential_api.c
diff options
context:
space:
mode:
authorAndreas Ebner <pansy007@googlemail.com>2019-08-06 16:17:33 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-10-07 12:17:28 +0200
commit33525da20575ba0149d1c6bcaac74e52d4e0ddd7 (patch)
tree91966b82a290b9b9d34c9d6e1c10f13d1b8156ed /src/credential/credential_api.c
parent15b0d71a635f02f5e0291a695d35a65698fdea05 (diff)
downloadgnunet-33525da20575ba0149d1c6bcaac74e52d4e0ddd7.tar.gz
gnunet-33525da20575ba0149d1c6bcaac74e52d4e0ddd7.zip
Removed GNUNET_CREDENTIAL_Credential, new cmdline parameters, formatting:
- removed all files and functions related to GNUNET_CREDENTIAL_Credential, has been replaced by GNUNET_CREDENTIAL_Delegate - renamed cmline parameter 'credential' - added cmline parameter for backward/forward search and a related enum - added cmline parameter to store private delegates - only private delegates are used as start/end of the search algorithm (set to vrh in collect) - run valgrind: no memory exceptions - run clang-format
Diffstat (limited to 'src/credential/credential_api.c')
-rw-r--r--src/credential/credential_api.c189
1 files changed, 81 insertions, 108 deletions
diff --git a/src/credential/credential_api.c b/src/credential/credential_api.c
index 4fe32465a..7c3b35464 100644
--- a/src/credential/credential_api.c
+++ b/src/credential/credential_api.c
@@ -35,7 +35,7 @@
35#include "gnunet_identity_service.h" 35#include "gnunet_identity_service.h"
36 36
37 37
38#define LOG(kind,...) GNUNET_log_from (kind, "credential-api",__VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "credential-api", __VA_ARGS__)
39 39
40/** 40/**
41 * Handle to a verify request 41 * Handle to a verify request
@@ -77,7 +77,6 @@ struct GNUNET_CREDENTIAL_Request
77 * request id 77 * request id
78 */ 78 */
79 uint32_t r_id; 79 uint32_t r_id;
80
81}; 80};
82 81
83 82
@@ -121,7 +120,6 @@ struct GNUNET_CREDENTIAL_Handle
121 * Request Id generator. Incremented by one for each request. 120 * Request Id generator. Incremented by one for each request.
122 */ 121 */
123 uint32_t r_id_gen; 122 uint32_t r_id_gen;
124
125}; 123};
126 124
127 125
@@ -159,12 +157,12 @@ force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
159{ 157{
160 GNUNET_MQ_destroy (handle->mq); 158 GNUNET_MQ_destroy (handle->mq);
161 handle->mq = NULL; 159 handle->mq = NULL;
162 handle->reconnect_backoff 160 handle->reconnect_backoff =
163 = GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff); 161 GNUNET_TIME_STD_BACKOFF (handle->reconnect_backoff);
164 handle->reconnect_task 162 handle->reconnect_task =
165 = GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff, 163 GNUNET_SCHEDULER_add_delayed (handle->reconnect_backoff,
166 &reconnect_task, 164 &reconnect_task,
167 handle); 165 handle);
168} 166}
169 167
170 168
@@ -177,8 +175,7 @@ force_reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
177 * @param error error code 175 * @param error error code
178 */ 176 */
179static void 177static void
180mq_error_handler (void *cls, 178mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
181 enum GNUNET_MQ_Error error)
182{ 179{
183 struct GNUNET_CREDENTIAL_Handle *handle = cls; 180 struct GNUNET_CREDENTIAL_Handle *handle = cls;
184 181
@@ -192,8 +189,7 @@ mq_error_handler (void *cls,
192 * @param vr_msg the incoming message 189 * @param vr_msg the incoming message
193 */ 190 */
194static int 191static int
195check_result (void *cls, 192check_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
196 const struct DelegationChainResultMessage *vr_msg)
197{ 193{
198 //TODO 194 //TODO
199 return GNUNET_OK; 195 return GNUNET_OK;
@@ -207,8 +203,7 @@ check_result (void *cls,
207 * @param vr_msg the incoming message 203 * @param vr_msg the incoming message
208 */ 204 */
209static void 205static void
210handle_result (void *cls, 206handle_result (void *cls, const struct DelegationChainResultMessage *vr_msg)
211 const struct DelegationChainResultMessage *vr_msg)
212{ 207{
213 struct GNUNET_CREDENTIAL_Handle *handle = cls; 208 struct GNUNET_CREDENTIAL_Handle *handle = cls;
214 uint32_t r_id = ntohl (vr_msg->id); 209 uint32_t r_id = ntohl (vr_msg->id);
@@ -230,31 +225,25 @@ handle_result (void *cls,
230 return; 225 return;
231 proc = vr->verify_proc; 226 proc = vr->verify_proc;
232 proc_cls = vr->proc_cls; 227 proc_cls = vr->proc_cls;
233 GNUNET_CONTAINER_DLL_remove (handle->request_head, 228 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, vr);
234 handle->request_tail,
235 vr);
236 GNUNET_MQ_discard (vr->env); 229 GNUNET_MQ_discard (vr->env);
237 GNUNET_free (vr); 230 GNUNET_free (vr);
238 GNUNET_assert (GNUNET_OK == 231 GNUNET_assert (
239 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen, 232 GNUNET_OK ==
240 (const char*) &vr_msg[1], 233 GNUNET_CREDENTIAL_delegation_chain_deserialize (mlen,
241 d_count, 234 (const char *) &vr_msg[1],
242 d_chain, 235 d_count,
243 c_count, 236 d_chain,
244 dels)); 237 c_count,
238 dels));
245 if (GNUNET_NO == ntohl (vr_msg->del_found)) 239 if (GNUNET_NO == ntohl (vr_msg->del_found))
246 { 240 {
247 proc (proc_cls, 241 proc (proc_cls, 0, NULL, 0,
248 0,
249 NULL,
250 0,
251 NULL); // TODO 242 NULL); // TODO
252 } else { 243 }
253 proc (proc_cls, 244 else
254 d_count, 245 {
255 d_chain, 246 proc (proc_cls, d_count, d_chain, c_count, dels);
256 c_count,
257 dels);
258 } 247 }
259} 248}
260 249
@@ -267,22 +256,20 @@ handle_result (void *cls,
267static void 256static void
268reconnect (struct GNUNET_CREDENTIAL_Handle *handle) 257reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
269{ 258{
270 struct GNUNET_MQ_MessageHandler handlers[] = { 259 struct GNUNET_MQ_MessageHandler handlers[] =
271 GNUNET_MQ_hd_var_size (result, 260 {GNUNET_MQ_hd_var_size (result,
272 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, 261 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT,
273 struct DelegationChainResultMessage, 262 struct DelegationChainResultMessage,
274 handle), 263 handle),
275 GNUNET_MQ_hd_var_size (result, 264 GNUNET_MQ_hd_var_size (result,
276 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT, 265 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT_RESULT,
277 struct DelegationChainResultMessage, 266 struct DelegationChainResultMessage,
278 handle), 267 handle),
279 GNUNET_MQ_handler_end () 268 GNUNET_MQ_handler_end ()};
280 };
281 struct GNUNET_CREDENTIAL_Request *vr; 269 struct GNUNET_CREDENTIAL_Request *vr;
282 270
283 GNUNET_assert (NULL == handle->mq); 271 GNUNET_assert (NULL == handle->mq);
284 LOG (GNUNET_ERROR_TYPE_DEBUG, 272 LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect to CREDENTIAL\n");
285 "Trying to connect to CREDENTIAL\n");
286 handle->mq = GNUNET_CLIENT_connect (handle->cfg, 273 handle->mq = GNUNET_CLIENT_connect (handle->cfg,
287 "credential", 274 "credential",
288 handlers, 275 handlers,
@@ -291,8 +278,7 @@ reconnect (struct GNUNET_CREDENTIAL_Handle *handle)
291 if (NULL == handle->mq) 278 if (NULL == handle->mq)
292 return; 279 return;
293 for (vr = handle->request_head; NULL != vr; vr = vr->next) 280 for (vr = handle->request_head; NULL != vr; vr = vr->next)
294 GNUNET_MQ_send_copy (handle->mq, 281 GNUNET_MQ_send_copy (handle->mq, vr->env);
295 vr->env);
296} 282}
297 283
298 284
@@ -352,9 +338,7 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
352{ 338{
353 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle; 339 struct GNUNET_CREDENTIAL_Handle *handle = lr->credential_handle;
354 340
355 GNUNET_CONTAINER_DLL_remove (handle->request_head, 341 GNUNET_CONTAINER_DLL_remove (handle->request_head, handle->request_tail, lr);
356 handle->request_tail,
357 lr);
358 GNUNET_MQ_discard (lr->env); 342 GNUNET_MQ_discard (lr->env);
359 GNUNET_free (lr); 343 GNUNET_free (lr);
360} 344}
@@ -373,13 +357,15 @@ GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *lr)
373 * @param proc_cls closure for processor 357 * @param proc_cls closure for processor
374 * @return handle to the queued request 358 * @return handle to the queued request
375 */ 359 */
376struct GNUNET_CREDENTIAL_Request* 360struct GNUNET_CREDENTIAL_Request *
377GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle, 361GNUNET_CREDENTIAL_collect (
378 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 362 struct GNUNET_CREDENTIAL_Handle *handle,
379 const char *issuer_attribute, 363 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
380 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key, 364 const char *issuer_attribute,
381 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 365 const struct GNUNET_CRYPTO_EcdsaPrivateKey *subject_key,
382 void *proc_cls) 366 enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction,
367 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
368 void *proc_cls)
383{ 369{
384 /* IPC to shorten credential names, return shorten_handle */ 370 /* IPC to shorten credential names, return shorten_handle */
385 struct CollectMessage *c_msg; 371 struct CollectMessage *c_msg;
@@ -407,25 +393,18 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
407 vr->verify_proc = proc; 393 vr->verify_proc = proc;
408 vr->proc_cls = proc_cls; 394 vr->proc_cls = proc_cls;
409 vr->r_id = handle->r_id_gen++; 395 vr->r_id = handle->r_id_gen++;
410 vr->env = GNUNET_MQ_msg_extra (c_msg, 396 vr->env =
411 nlen, 397 GNUNET_MQ_msg_extra (c_msg, nlen, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
412 GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT);
413 c_msg->id = htonl (vr->r_id); 398 c_msg->id = htonl (vr->r_id);
414 c_msg->subject_key = *subject_key; 399 c_msg->subject_key = *subject_key;
415 c_msg->issuer_key = *issuer_key; 400 c_msg->issuer_key = *issuer_key;
416 c_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); 401 c_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
417 c_msg->resolution_algo = htons(Backward); 402 c_msg->resolution_algo = htons (direction);
418 //c_msg->resolution_algo = htons(Forward); 403
419 404 GNUNET_memcpy (&c_msg[1], issuer_attribute, strlen (issuer_attribute));
420 GNUNET_memcpy (&c_msg[1], 405 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
421 issuer_attribute,
422 strlen (issuer_attribute));
423 GNUNET_CONTAINER_DLL_insert (handle->request_head,
424 handle->request_tail,
425 vr);
426 if (NULL != handle->mq) 406 if (NULL != handle->mq)
427 GNUNET_MQ_send_copy (handle->mq, 407 GNUNET_MQ_send_copy (handle->mq, vr->env);
428 vr->env);
429 return vr; 408 return vr;
430} 409}
431/** 410/**
@@ -446,15 +425,17 @@ GNUNET_CREDENTIAL_collect (struct GNUNET_CREDENTIAL_Handle *handle,
446 * @param proc_cls closure for processor 425 * @param proc_cls closure for processor
447 * @return handle to the queued request 426 * @return handle to the queued request
448 */ 427 */
449struct GNUNET_CREDENTIAL_Request* 428struct GNUNET_CREDENTIAL_Request *
450GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle, 429GNUNET_CREDENTIAL_verify (
451 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key, 430 struct GNUNET_CREDENTIAL_Handle *handle,
452 const char *issuer_attribute, 431 const struct GNUNET_CRYPTO_EcdsaPublicKey *issuer_key,
453 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key, 432 const char *issuer_attribute,
454 uint32_t delegate_count, 433 const struct GNUNET_CRYPTO_EcdsaPublicKey *subject_key,
455 const struct GNUNET_CREDENTIAL_Delegate *delegates, 434 uint32_t delegate_count,
456 GNUNET_CREDENTIAL_CredentialResultProcessor proc, 435 const struct GNUNET_CREDENTIAL_Delegate *delegates,
457 void *proc_cls) 436 enum GNUNET_CREDENTIAL_AlgoDirectionFlags direction,
437 GNUNET_CREDENTIAL_CredentialResultProcessor proc,
438 void *proc_cls)
458{ 439{
459 /* IPC to shorten credential names, return shorten_handle */ 440 /* IPC to shorten credential names, return shorten_handle */
460 struct VerifyMessage *v_msg; 441 struct VerifyMessage *v_msg;
@@ -468,8 +449,7 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
468 return NULL; 449 return NULL;
469 } 450 }
470 451
471 clen = GNUNET_CREDENTIAL_delegates_get_size (delegate_count, 452 clen = GNUNET_CREDENTIAL_delegates_get_size (delegate_count, delegates);
472 delegates);
473 453
474 //DEBUG LOG 454 //DEBUG LOG
475 LOG (GNUNET_ERROR_TYPE_DEBUG, 455 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -486,31 +466,24 @@ GNUNET_CREDENTIAL_verify (struct GNUNET_CREDENTIAL_Handle *handle,
486 vr->verify_proc = proc; 466 vr->verify_proc = proc;
487 vr->proc_cls = proc_cls; 467 vr->proc_cls = proc_cls;
488 vr->r_id = handle->r_id_gen++; 468 vr->r_id = handle->r_id_gen++;
489 vr->env = GNUNET_MQ_msg_extra (v_msg, 469 vr->env =
490 nlen, 470 GNUNET_MQ_msg_extra (v_msg, nlen, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
491 GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY);
492 v_msg->id = htonl (vr->r_id); 471 v_msg->id = htonl (vr->r_id);
493 v_msg->subject_key = *subject_key; 472 v_msg->subject_key = *subject_key;
494 v_msg->d_count = htonl(delegate_count); 473 v_msg->d_count = htonl (delegate_count);
495 v_msg->issuer_key = *issuer_key; 474 v_msg->issuer_key = *issuer_key;
496 v_msg->issuer_attribute_len = htons(strlen(issuer_attribute)); 475 v_msg->issuer_attribute_len = htons (strlen (issuer_attribute));
497 v_msg->resolution_algo = htons(Backward); 476 v_msg->resolution_algo = htons (direction);
498 //v_msg->resolution_algo = htons(Forward); 477
499 478 GNUNET_memcpy (&v_msg[1], issuer_attribute, strlen (issuer_attribute));
500 GNUNET_memcpy (&v_msg[1],
501 issuer_attribute,
502 strlen (issuer_attribute));
503 GNUNET_CREDENTIAL_delegates_serialize (delegate_count, 479 GNUNET_CREDENTIAL_delegates_serialize (delegate_count,
504 delegates, 480 delegates,
505 clen, 481 clen,
506 ((char*)&v_msg[1]) 482 ((char *) &v_msg[1]) +
507 + strlen (issuer_attribute) + 1); 483 strlen (issuer_attribute) + 1);
508 GNUNET_CONTAINER_DLL_insert (handle->request_head, 484 GNUNET_CONTAINER_DLL_insert (handle->request_head, handle->request_tail, vr);
509 handle->request_tail,
510 vr);
511 if (NULL != handle->mq) 485 if (NULL != handle->mq)
512 GNUNET_MQ_send_copy (handle->mq, 486 GNUNET_MQ_send_copy (handle->mq, vr->env);
513 vr->env);
514 return vr; 487 return vr;
515} 488}
516 489