GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-credential.c File Reference

GNUnet Credential Service (main service) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "credential.h"
#include "credential_serialization.h"
#include "gnunet_credential_service.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include <gnunet_dnsparser_lib.h>
#include <gnunet_gns_service.h>
#include <gnunet_gnsrecord_lib.h>
#include <gnunet_identity_service.h>
#include <gnunet_namestore_service.h>
Include dependency graph for gnunet-service-credential.c:

Go to the source code of this file.

Data Structures

struct  DelegationChainEntry
 
struct  CredentialRecordEntry
 DLL for record. More...
 
struct  DelegationQueueEntry
 DLL used for delegations Used for OR delegations. More...
 
struct  DelegationSetQueueEntry
 DLL for delegation sets Used for AND delegation set. More...
 
struct  VerifyRequestHandle
 Handle to a lookup operation from api. More...
 

Macros

#define GNUNET_CREDENTIAL_MAX_LENGTH   255
 

Functions

static void cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
 
static void cleanup_handle (struct VerifyRequestHandle *vrh)
 
static void shutdown_task (void *cls)
 
static void send_lookup_response (struct VerifyRequestHandle *vrh)
 
static void backward_resolution (void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 
static void delegation_chain_resolution_start (void *cls)
 Result from GNS lookup. More...
 
static int check_verify (void *cls, const struct VerifyMessage *v_msg)
 
static void handle_verify (void *cls, const struct VerifyMessage *v_msg)
 
static void handle_cred_collection_error_cb (void *cls)
 
static void collect_next (void *cls)
 
static void handle_cred_collection_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 
static void handle_cred_collection_finished_cb (void *cls)
 
static void handle_collect (void *cls, const struct CollectMessage *c_msg)
 
static int check_collect (void *cls, const struct CollectMessage *c_msg)
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *handle)
 Process Credential requests. More...
 
 GNUNET_SERVICE_MAIN ("credential", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(verify, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, struct VerifyMessage, NULL), GNUNET_MQ_hd_var_size(collect, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, struct CollectMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static struct VerifyRequestHandlevrh_head
 Head of the DLL. More...
 
static struct VerifyRequestHandlevrh_tail
 Tail of the DLL. More...
 
static struct GNUNET_STATISTICS_Handlestatistics
 Handle to the statistics service. More...
 
static struct GNUNET_GNS_Handlegns
 Handle to GNS service. More...
 
static struct GNUNET_NAMESTORE_Handlenamestore
 Handle to namestore service. More...
 

Detailed Description

GNUnet Credential Service (main service)

Author
Martin Schanzenbach

Definition in file gnunet-service-credential.c.

Macro Definition Documentation

◆ GNUNET_CREDENTIAL_MAX_LENGTH

#define GNUNET_CREDENTIAL_MAX_LENGTH   255

Function Documentation

◆ cleanup_delegation_set()

static void cleanup_delegation_set ( struct DelegationSetQueueEntry ds_entry)
static

Definition at line 352 of file gnunet-service-credential.c.

References DelegationSetQueueEntry::attr_trailer, child, DelegationSetQueueEntry::delegation_chain_entry, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_free_non_null, GNUNET_GNS_lookup_cancel(), DelegationChainEntry::issuer_attribute, DelegationSetQueueEntry::issuer_attribute, DelegationSetQueueEntry::issuer_key, DelegationSetQueueEntry::lookup_attribute, DelegationSetQueueEntry::lookup_request, DelegationSetQueueEntry::queue_entries_head, DelegationSetQueueEntry::queue_entries_tail, DelegationQueueEntry::set_entries_head, DelegationQueueEntry::set_entries_tail, DelegationChainEntry::subject_attribute, and DelegationSetQueueEntry::unresolved_attribute_delegation.

Referenced by cleanup_handle().

353 {
354  struct DelegationQueueEntry *dq_entry;
356 
357  if (NULL == ds_entry)
358  return;
359 
360  for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry;
361  dq_entry = ds_entry->queue_entries_head)
362  {
364  ds_entry->queue_entries_tail,
365  dq_entry);
366  for (child = dq_entry->set_entries_head; NULL != child;
367  child = dq_entry->set_entries_head)
368  {
370  dq_entry->set_entries_tail,
371  child);
372  cleanup_delegation_set (child);
373  }
374  GNUNET_free (dq_entry);
375  }
376  GNUNET_free_non_null (ds_entry->issuer_key);
381  if (NULL != ds_entry->lookup_request)
382  {
384  ds_entry->lookup_request = NULL;
385  }
386  if (NULL != ds_entry->delegation_chain_entry)
387  {
391  }
392  GNUNET_free (ds_entry);
393 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct DelegationChainEntry * delegation_chain_entry
The delegation chain entry.
char * issuer_attribute
Issuer attribute delegated to.
char * issuer_attribute
The issued attribute.
DLL for delegation sets Used for AND delegation set.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_GNS_LookupRequest * lookup_request
GNS handle.
struct DelegationQueueEntry * queue_entries_head
Queue entries of this set.
struct DelegationQueueEntry * queue_entries_tail
Queue entries of this set.
char * attr_trailer
Trailing attribute context.
struct DelegationSetQueueEntry * set_entries_head
Sets under this Queue.
static struct GNUNET_OS_Process * child
The child process we spawn.
void * GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr)
Cancel pending lookup request.
Definition: gns_api.c:308
struct GNUNET_CRYPTO_EcdsaPublicKey * issuer_key
Issuer key.
char * subject_attribute
The delegated attribute.
static void cleanup_delegation_set(struct DelegationSetQueueEntry *ds_entry)
struct DelegationSetQueueEntry * set_entries_tail
Sets under this Queue.
char * unresolved_attribute_delegation
Still to resolve delegation as string.
#define GNUNET_free(ptr)
Wrapper around free.
DLL used for delegations Used for OR delegations.
char * lookup_attribute
The current attribute to look up.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanup_handle()

static void cleanup_handle ( struct VerifyRequestHandle vrh)
static

Definition at line 396 of file gnunet-service-credential.c.

References cleanup_delegation_set(), VerifyRequestHandle::cred_chain_head, VerifyRequestHandle::cred_chain_tail, CredentialRecordEntry::credential, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_GNS_lookup_cancel(), GNUNET_log, VerifyRequestHandle::issuer_attribute, VerifyRequestHandle::lookup_request, and VerifyRequestHandle::root_set.

Referenced by send_lookup_response(), and shutdown_task().

397 {
398  struct CredentialRecordEntry *cr_entry;
399 
400  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
401  if (NULL != vrh->lookup_request)
402  {
404  vrh->lookup_request = NULL;
405  }
408  for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head;
409  cr_entry = vrh->cred_chain_head)
410  {
412  vrh->cred_chain_tail,
413  cr_entry);
414  GNUNET_free_non_null (cr_entry->credential);
415  GNUNET_free (cr_entry);
416  }
417  GNUNET_free (vrh);
418 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
char * issuer_attribute
Issuer attribute.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_GNS_LookupRequest * lookup_request
GNS handle.
struct CredentialRecordEntry * cred_chain_head
Credential DLL.
struct CredentialRecordEntry * cred_chain_tail
Credential DLL.
#define GNUNET_log(kind,...)
void * GNUNET_GNS_lookup_cancel(struct GNUNET_GNS_LookupRequest *lr)
Cancel pending lookup request.
Definition: gns_api.c:308
static void cleanup_delegation_set(struct DelegationSetQueueEntry *ds_entry)
struct GNUNET_CREDENTIAL_Credential * credential
Payload.
struct DelegationSetQueueEntry * root_set
Root Delegation Set.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Definition at line 421 of file gnunet-service-credential.c.

References cleanup_handle(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_GNS_disconnect(), GNUNET_log, GNUNET_NAMESTORE_disconnect(), GNUNET_NO, and GNUNET_STATISTICS_destroy().

Referenced by run().

422 {
423  struct VerifyRequestHandle *vrh;
424 
425  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
426 
427  while (NULL != (vrh = vrh_head))
428  {
429  // CREDENTIAL_resolver_lookup_cancel (clh->lookup);
431  cleanup_handle (vrh);
432  }
433 
434  if (NULL != gns)
435  {
437  gns = NULL;
438  }
439  if (NULL != namestore)
440  {
442  namestore = NULL;
443  }
444  if (NULL != statistics)
445  {
447  statistics = NULL;
448  }
449 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct VerifyRequestHandle * vrh_head
Head of the DLL.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static struct GNUNET_NAMESTORE_Handle * namestore
Handle to namestore service.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
void GNUNET_GNS_disconnect(struct GNUNET_GNS_Handle *handle)
Shutdown connection with the GNS service.
Definition: gns_api.c:284
static struct VerifyRequestHandle * vrh_tail
Tail of the DLL.
Handle to a lookup operation from api.
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
#define GNUNET_log(kind,...)
static void cleanup_handle(struct VerifyRequestHandle *vrh)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_lookup_response()

static void send_lookup_response ( struct VerifyRequestHandle vrh)
static

Remove all credentials not needed

Get serialized record data Append at the end of rmsg

Definition at line 453 of file gnunet-service-credential.c.

References DelegationChainResultMessage::c_count, cleanup_handle(), DelegationChainResultMessage::cred_found, CredentialRecordEntry::credential, DelegationChainResultMessage::d_count, env, GNUNET_CREDENTIAL_Credential::expiration, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CREDENTIAL_delegation_chain_get_size(), GNUNET_CREDENTIAL_delegation_chain_serialize(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SERVICE_client_get_mq(), GNUNET_STATISTICS_update(), GNUNET_YES, DelegationChainResultMessage::id, DelegationChainEntry::issuer_attribute, GNUNET_CREDENTIAL_Delegation::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_attribute, GNUNET_CREDENTIAL_Delegation::issuer_attribute_len, GNUNET_CREDENTIAL_Credential::issuer_attribute_len, DelegationChainEntry::issuer_key, GNUNET_CREDENTIAL_Delegation::issuer_key, GNUNET_CREDENTIAL_Credential::issuer_key, DelegationChainEntry::next, CredentialRecordEntry::next, CredentialRecordEntry::refcount, GNUNET_CREDENTIAL_Credential::signature, size, DelegationChainEntry::subject_attribute, GNUNET_CREDENTIAL_Delegation::subject_attribute, GNUNET_CREDENTIAL_Delegation::subject_attribute_len, DelegationChainEntry::subject_key, GNUNET_CREDENTIAL_Delegation::subject_key, and GNUNET_CREDENTIAL_Credential::subject_key.

Referenced by backward_resolution(), delegation_chain_resolution_start(), handle_collect(), handle_cred_collection_error_cb(), and handle_verify().

454 {
455  struct GNUNET_MQ_Envelope *env;
456  struct DelegationChainResultMessage *rmsg;
457  struct DelegationChainEntry *dce;
458  struct GNUNET_CREDENTIAL_Delegation dd[vrh->delegation_chain_size];
459  struct GNUNET_CREDENTIAL_Credential cred[vrh->cred_chain_size];
460  struct CredentialRecordEntry *cd;
461  struct CredentialRecordEntry *tmp;
462  size_t size;
463 
464  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
465  dce = vrh->delegation_chain_head;
466  for (uint32_t i = 0; i < vrh->delegation_chain_size; i++)
467  {
468  dd[i].issuer_key = dce->issuer_key;
469  dd[i].subject_key = dce->subject_key;
470  dd[i].issuer_attribute = dce->issuer_attribute;
471  dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
472  dd[i].subject_attribute_len = 0;
473  dd[i].subject_attribute = NULL;
474  if (NULL != dce->subject_attribute)
475  {
476  dd[i].subject_attribute = dce->subject_attribute;
477  dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
478  }
479  dce = dce->next;
480  }
481 
485  for (cd = vrh->cred_chain_head; NULL != cd;)
486  {
487  if (cd->refcount > 0)
488  {
489  cd = cd->next;
490  continue;
491  }
492  tmp = cd;
493  cd = cd->next;
495  vrh->cred_chain_tail,
496  tmp);
497  GNUNET_free (tmp->credential);
498  GNUNET_free (tmp);
499  vrh->cred_chain_size--;
500  }
501 
506  cd = vrh->cred_chain_head;
507  for (uint32_t i = 0; i < vrh->cred_chain_size; i++)
508  {
509  cred[i].issuer_key = cd->credential->issuer_key;
510  cred[i].subject_key = cd->credential->subject_key;
511  cred[i].issuer_attribute_len
512  = strlen (cd->credential->issuer_attribute) + 1;
513  cred[i].issuer_attribute = cd->credential->issuer_attribute;
514  cred[i].expiration = cd->credential->expiration;
515  cred[i].signature = cd->credential->signature;
516  cd = cd->next;
517  }
518  size
520  dd,
521  vrh->cred_chain_size,
522  cred);
523  env = GNUNET_MQ_msg_extra (rmsg,
524  size,
526  // Assign id so that client can find associated request
527  rmsg->id = vrh->request_id;
528  rmsg->d_count = htonl (vrh->delegation_chain_size);
529  rmsg->c_count = htonl (vrh->cred_chain_size);
530 
531  if (0 < vrh->cred_chain_size)
532  rmsg->cred_found = htonl (GNUNET_YES);
533  else
534  rmsg->cred_found = htonl (GNUNET_NO);
535 
536  GNUNET_assert (
537  -1
539  dd,
540  vrh->cred_chain_size,
541  cred,
542  size,
543  (char *) &rmsg[1]));
544 
547  cleanup_handle (vrh);
548 
550  "Completed verifications",
551  1,
552  GNUNET_NO);
553 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
uint32_t id
Unique identifier for this request (for key collisions).
Definition: credential.h:118
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
The subject.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2437
Message from CREDENTIAL service to client: new results.
Definition: credential.h:108
#define GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
char * issuer_attribute
The issued attribute.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct VerifyRequestHandle * vrh_head
Head of the DLL.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint32_t cred_chain_size
Credential DLL size.
struct DelegationChainEntry * next
DLL.
uint32_t request_id
request id
struct CredentialRecordEntry * next
DLL.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
static struct VerifyRequestHandle * vrh_tail
Tail of the DLL.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct DelegationChainEntry * delegation_chain_head
Children of this attribute.
uint32_t refcount
Number of references in delegation chains.
struct CredentialRecordEntry * cred_chain_head
Credential DLL.
static unsigned int size
Size of the "table".
Definition: peer.c:67
uint32_t delegation_chain_size
Size of delegation tree.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
struct CredentialRecordEntry * cred_chain_tail
Credential DLL.
const char * issuer_attribute
The attribute.
ssize_t GNUNET_CREDENTIAL_delegation_chain_serialize(unsigned int d_count, const struct GNUNET_CREDENTIAL_Delegation *dd, unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd, size_t dest_size, char *dest)
Serizalize the given delegation chain entries and credential.
uint32_t cred_found
Indicates if credential has been found at all.
Definition: credential.h:123
#define GNUNET_log(kind,...)
struct GNUNET_SERVICE_Client * client
Handle to the requesting client.
#define GNUNET_YES
Definition: gnunet_common.h:77
char * subject_attribute
The delegated attribute.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
static void cleanup_handle(struct VerifyRequestHandle *vrh)
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer.
size_t GNUNET_CREDENTIAL_delegation_chain_get_size(unsigned int d_count, const struct GNUNET_CREDENTIAL_Delegation *dd, unsigned int c_count, const struct GNUNET_CREDENTIAL_Credential *cd)
Calculate how many bytes we will need to serialize the given delegation chain and credential...
struct GNUNET_CREDENTIAL_Credential * credential
Payload.
uint32_t d_count
The number of delegations in the response.
Definition: credential.h:128
uint32_t c_count
The number of credentials in the response.
Definition: credential.h:133
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ backward_resolution()

static void backward_resolution ( void *  cls,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Check if this delegation already matches one of our credentials

Definition at line 557 of file gnunet-service-credential.c.

References DelegationSetQueueEntry::attr_trailer, VerifyRequestHandle::cred_chain_head, CredentialRecordEntry::credential, GNUNET_GNSRECORD_Data::data, DelegationSetQueueEntry::delegation_chain_entry, VerifyRequestHandle::delegation_chain_head, VerifyRequestHandle::delegation_chain_size, VerifyRequestHandle::delegation_chain_tail, GNUNET_asprintf(), GNUNET_CONTAINER_DLL_insert, GNUNET_CREDENTIAL_delegation_set_deserialize(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup(), GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_log, GNUNET_memcmp, GNUNET_memcpy, GNUNET_new, GNUNET_ntohll(), GNUNET_OK, GNUNET_strdup, DelegationSetQueueEntry::handle, DelegationChainEntry::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_attribute, DelegationChainEntry::issuer_key, GNUNET_CREDENTIAL_Credential::issuer_key, DelegationSetQueueEntry::issuer_key, DelegationSetQueueEntry::lookup_attribute, DelegationSetQueueEntry::lookup_request, CredentialRecordEntry::next, DelegationSetQueueEntry::parent_queue_entry, DelegationQueueEntry::parent_set, VerifyRequestHandle::pending_lookups, DelegationSetQueueEntry::queue_entries_head, DelegationSetQueueEntry::queue_entries_tail, CredentialRecordEntry::refcount, DelegationQueueEntry::required_solutions, send_lookup_response(), DelegationQueueEntry::set_entries_head, DelegationQueueEntry::set_entries_tail, DelegationChainEntry::subject_attribute, GNUNET_CREDENTIAL_DelegationSet::subject_attribute_len, DelegationChainEntry::subject_key, GNUNET_CREDENTIAL_DelegationSet::subject_key, and DelegationSetQueueEntry::unresolved_attribute_delegation.

Referenced by delegation_chain_resolution_start().

560 {
561  struct VerifyRequestHandle *vrh;
562  const struct GNUNET_CREDENTIAL_DelegationRecord *sets;
563  struct CredentialRecordEntry *cred_pointer;
564  struct DelegationSetQueueEntry *current_set;
565  struct DelegationSetQueueEntry *ds_entry;
566  struct DelegationSetQueueEntry *tmp_set;
567  struct DelegationQueueEntry *dq_entry;
568  char *expanded_attr;
569  char *lookup_attribute;
570 
571 
572  current_set = cls;
573  current_set->lookup_request = NULL;
574  vrh = current_set->handle;
575  vrh->pending_lookups--;
576  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count);
577 
578  // Each OR
579  for (uint32_t i = 0; i < rd_count; i++)
580  {
581  if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
582  continue;
583 
584  sets = rd[i].data;
585  struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)];
586  GNUNET_log (
588  "Found new attribute delegation with %d sets. Creating new Job...\n",
589  ntohl (sets->set_count));
590 
591  if (GNUNET_OK
593  GNUNET_ntohll (sets->data_size),
594  (const char *) &sets[1],
595  ntohl (sets->set_count),
596  set))
597  {
598  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
599  continue;
600  }
601  dq_entry = GNUNET_new (struct DelegationQueueEntry);
602  dq_entry->required_solutions = ntohl (sets->set_count);
603  dq_entry->parent_set = current_set;
605  current_set->queue_entries_tail,
606  dq_entry);
607  // Each AND
608  for (uint32_t j = 0; j < ntohl (sets->set_count); j++)
609  {
610  ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
611  if (NULL != current_set->attr_trailer)
612  {
613  if (0 == set[j].subject_attribute_len)
614  {
615  GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
616  }
617  else
618  {
619  GNUNET_asprintf (&expanded_attr,
620  "%s.%s",
621  set[j].subject_attribute,
622  current_set->attr_trailer);
623  }
624  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
625  ds_entry->unresolved_attribute_delegation = expanded_attr;
626  }
627  else
628  {
629  if (0 != set[j].subject_attribute_len)
630  {
632  "Not Expanding %s\n",
633  set[j].subject_attribute);
635  = GNUNET_strdup (set[j].subject_attribute);
636  }
637  }
638 
639  // Add a credential chain entry
640  ds_entry->delegation_chain_entry
641  = GNUNET_new (struct DelegationChainEntry);
642  ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
644  GNUNET_memcpy (ds_entry->issuer_key,
645  &set[j].subject_key,
646  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
647  if (0 < set[j].subject_attribute_len)
649  = GNUNET_strdup (set[j].subject_attribute);
650  ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
652  = GNUNET_strdup (current_set->lookup_attribute);
653 
654  ds_entry->parent_queue_entry = dq_entry; // current_delegation;
656  dq_entry->set_entries_tail,
657  ds_entry);
658 
659  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
663  for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
664  cred_pointer = cred_pointer->next)
665  {
666  if (0
667  != GNUNET_memcmp (&set->subject_key,
668  &cred_pointer->credential->issuer_key))
669  continue;
671  "Checking if %s matches %s\n",
673  cred_pointer->credential->issuer_attribute);
674 
675  if (0
676  != strcmp (ds_entry->unresolved_attribute_delegation,
677  cred_pointer->credential->issuer_attribute))
678  continue;
679 
680  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
681  cred_pointer->refcount++;
682  // Backtrack
683  for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
684  tmp_set = tmp_set->parent_queue_entry->parent_set)
685  {
687  if (NULL != tmp_set->delegation_chain_entry)
688  {
689  vrh->delegation_chain_size++;
692  tmp_set->delegation_chain_entry);
693  }
694  if (0 < tmp_set->parent_queue_entry->required_solutions)
695  break;
696  }
697 
698  if (NULL == tmp_set->parent_queue_entry)
699  {
700  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n");
701  // Found match
702  send_lookup_response (vrh);
703  return;
704  }
705  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n");
706  continue;
707  }
709  "Building new lookup request from %s\n",
711  // Continue with backward resolution
712  char
713  issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)
714  + 1];
715  strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
716  char *next_attr = strtok (issuer_attribute_name, ".");
717  if (NULL == next_attr)
718  {
720  "Failed to parse next attribute\n");
721  continue;
722  }
723  GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
724  GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
725  if (strlen (next_attr)
726  == strlen (ds_entry->unresolved_attribute_delegation))
727  {
728  ds_entry->attr_trailer = NULL;
729  }
730  else
731  {
732  next_attr += strlen (next_attr) + 1;
733  ds_entry->attr_trailer = GNUNET_strdup (next_attr);
734  }
735 
737  "Looking up %s\n",
738  ds_entry->lookup_attribute);
739  if (NULL != ds_entry->attr_trailer)
741  "%s still to go...\n",
742  ds_entry->attr_trailer);
743 
744  vrh->pending_lookups++;
745  ds_entry->handle = vrh;
746  ds_entry->lookup_request
748  lookup_attribute,
749  ds_entry->issuer_key, // issuer_key,
753  ds_entry);
754  GNUNET_free (lookup_attribute);
755  }
756  }
757 
758  if (0 == vrh->pending_lookups)
759  {
760  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
761  send_lookup_response (vrh);
762  return;
763  }
764 }
uint64_t pending_lookups
Pending lookups.
struct DelegationChainEntry * delegation_chain_tail
Children of this attribute.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
The subject.
struct DelegationChainEntry * delegation_chain_entry
The delegation chain entry.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
char * issuer_attribute
The issued attribute.
int GNUNET_CREDENTIAL_delegation_set_deserialize(size_t len, const char *src, unsigned int d_count, struct GNUNET_CREDENTIAL_DelegationSet *dsr)
Deserialize the given destination.
DLL for delegation sets Used for AND delegation set.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
struct GNUNET_GNS_LookupRequest * lookup_request
GNS handle.
uint32_t set_count
Number of delegation sets in this record.
struct DelegationQueueEntry * queue_entries_head
Queue entries of this set.
struct CredentialRecordEntry * next
DLL.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
const void * data
Binary value stored in the DNS record.
struct VerifyRequestHandle * handle
Verify handle.
static void send_lookup_response(struct VerifyRequestHandle *vrh)
const char * subject_attribute
The subject attribute.
struct DelegationChainEntry * delegation_chain_head
Children of this attribute.
uint32_t refcount
Number of references in delegation chains.
uint64_t data_size
Length of delegation sets.
struct CredentialRecordEntry * cred_chain_head
Credential DLL.
Handle to a lookup operation from api.
uint32_t delegation_chain_size
Size of delegation tree.
struct DelegationQueueEntry * queue_entries_tail
Queue entries of this set.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
char * attr_trailer
Trailing attribute context.
struct DelegationSetQueueEntry * set_entries_head
Sets under this Queue.
const char * issuer_attribute
The attribute.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EcdsaPublicKey * issuer_key
Issuer key.
static void backward_resolution(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
char * subject_attribute
The delegated attribute.
Defaults, look in cache, then in DHT.
uint32_t required_solutions
Required solutions.
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:336
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer.
The attribute delegation record.
struct GNUNET_CREDENTIAL_Credential * credential
Payload.
struct DelegationQueueEntry * parent_queue_entry
Parent QueueEntry.
struct DelegationSetQueueEntry * set_entries_tail
Sets under this Queue.
The attribute delegation record.
char * unresolved_attribute_delegation
Still to resolve delegation as string.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_free(ptr)
Wrapper around free.
DLL used for delegations Used for OR delegations.
struct DelegationSetQueueEntry * parent_set
Parent set.
char * lookup_attribute
The current attribute to look up.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ delegation_chain_resolution_start()

static void delegation_chain_resolution_start ( void *  cls)
static

Result from GNS lookup.

Parameters
clsthe closure (our client lookup handle)

Check for attributes from the issuer and follow the chain till you get the required subject's attributes

Definition at line 773 of file gnunet-service-credential.c.

References backward_resolution(), VerifyRequestHandle::cred_chain_head, VerifyRequestHandle::cred_chain_size, CredentialRecordEntry::credential, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_GNS_LO_DEFAULT, GNUNET_GNS_lookup(), GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_log, GNUNET_memcmp, GNUNET_memcpy, GNUNET_new, GNUNET_strdup, DelegationSetQueueEntry::handle, DelegationSetQueueEntry::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_attribute, VerifyRequestHandle::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_key, DelegationSetQueueEntry::issuer_key, VerifyRequestHandle::issuer_key, DelegationSetQueueEntry::lookup_attribute, DelegationSetQueueEntry::lookup_request, VerifyRequestHandle::lookup_request, CredentialRecordEntry::next, VerifyRequestHandle::pending_lookups, CredentialRecordEntry::refcount, VerifyRequestHandle::root_set, and send_lookup_response().

Referenced by handle_cred_collection_finished_cb(), and handle_verify().

774 {
775  struct VerifyRequestHandle *vrh = cls;
776  struct DelegationSetQueueEntry *ds_entry;
777  struct CredentialRecordEntry *cr_entry;
778 
779  vrh->lookup_request = NULL;
780 
781  if (0 == vrh->cred_chain_size)
782  {
783  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n");
784  send_lookup_response (vrh);
785  return;
786  }
787 
788  for (cr_entry = vrh->cred_chain_head; cr_entry != NULL;
789  cr_entry = cr_entry->next)
790  {
791  if (0
792  != GNUNET_memcmp (&cr_entry->credential->issuer_key,
793  &vrh->issuer_key))
794  continue;
795  if (0
796  != strcmp (cr_entry->credential->issuer_attribute,
797  vrh->issuer_attribute))
798  continue;
799  cr_entry->refcount++;
800  // Found match prematurely
801  send_lookup_response (vrh);
802  return;
803  }
804 
809  char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1];
810  strcpy (issuer_attribute_name, vrh->issuer_attribute);
812  "Looking up %s\n",
813  issuer_attribute_name);
814  ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
816  GNUNET_memcpy (ds_entry->issuer_key,
817  &vrh->issuer_key,
818  sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
820  ds_entry->handle = vrh;
822  vrh->root_set = ds_entry;
823  vrh->pending_lookups = 1;
824  // Start with backward resolution
825  ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
826  issuer_attribute_name,
827  &vrh->issuer_key, // issuer_key,
831  ds_entry);
832 }
uint64_t pending_lookups
Pending lookups.
char * issuer_attribute
Issuer attribute.
char * issuer_attribute
Issuer attribute delegated to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
DLL for delegation sets Used for AND delegation set.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint32_t cred_chain_size
Credential DLL size.
struct GNUNET_GNS_LookupRequest * lookup_request
GNS handle.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Issuer public key.
struct CredentialRecordEntry * next
DLL.
struct GNUNET_GNS_LookupRequest * lookup_request
GNS handle.
struct VerifyRequestHandle * handle
Verify handle.
static void send_lookup_response(struct VerifyRequestHandle *vrh)
uint32_t refcount
Number of references in delegation chains.
struct CredentialRecordEntry * cred_chain_head
Credential DLL.
Handle to a lookup operation from api.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const char * issuer_attribute
The attribute.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
#define GNUNET_GNSRECORD_TYPE_ATTRIBUTE
Record type for reverse lookups.
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EcdsaPublicKey * issuer_key
Issuer key.
static void backward_resolution(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Defaults, look in cache, then in DHT.
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:336
struct GNUNET_CREDENTIAL_Credential * credential
Payload.
struct DelegationSetQueueEntry * root_set
Root Delegation Set.
char * lookup_attribute
The current attribute to look up.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_verify()

static int check_verify ( void *  cls,
const struct VerifyMessage v_msg 
)
static

Definition at line 835 of file gnunet-service-credential.c.

References GNUNET_break, GNUNET_CREDENTIAL_MAX_LENGTH, GNUNET_OK, GNUNET_SYSERR, VerifyMessage::header, VerifyMessage::issuer_attribute_len, and GNUNET_MessageHeader::size.

836 {
837  size_t msg_size;
838  const char *attr;
839 
840  msg_size = ntohs (v_msg->header.size);
841  if (msg_size < sizeof(struct VerifyMessage))
842  {
843  GNUNET_break (0);
844  return GNUNET_SYSERR;
845  }
847  {
848  GNUNET_break (0);
849  return GNUNET_SYSERR;
850  }
851  attr = (const char *) &v_msg[1];
852 
853  if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)
854  {
855  GNUNET_break (0);
856  return GNUNET_SYSERR;
857  }
858  return GNUNET_OK;
859 }
Message from client to Credential service to verify attributes.
Definition: credential.h:69
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: credential.h:94
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY.
Definition: credential.h:74
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_CREDENTIAL_MAX_LENGTH

◆ handle_verify()

static void handle_verify ( void *  cls,
const struct VerifyMessage v_msg 
)
static

First, collect credentials TODO: cleanup!

Definition at line 862 of file gnunet-service-credential.c.

References VerifyMessage::c_count, VerifyRequestHandle::client, VerifyRequestHandle::cred_chain_head, VerifyRequestHandle::cred_chain_size, VerifyRequestHandle::cred_chain_tail, CredentialRecordEntry::credential, delegation_chain_resolution_start(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CREDENTIAL_credentials_deserialize(), GNUNET_CREDENTIAL_MAX_LENGTH, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_strdup, GNUNET_STRINGS_utf8_tolower(), VerifyMessage::header, VerifyMessage::id, DelegationChainEntry::issuer_attribute, GNUNET_CREDENTIAL_Credential::issuer_attribute, VerifyRequestHandle::issuer_attribute, VerifyMessage::issuer_attribute_len, GNUNET_CREDENTIAL_Credential::issuer_attribute_len, VerifyMessage::issuer_key, VerifyRequestHandle::issuer_key, VerifyRequestHandle::request_id, send_lookup_response(), GNUNET_MessageHeader::size, VerifyMessage::subject_key, and VerifyRequestHandle::subject_key.

863 {
864  struct VerifyRequestHandle *vrh;
865  struct GNUNET_SERVICE_Client *client = cls;
866  struct CredentialRecordEntry *cr_entry;
867  uint32_t credentials_count;
868  uint32_t credential_data_size;
869  char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
870  char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
871  char *attrptr = attr;
872  char *credential_data;
873  const char *utf_in;
874 
875  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
876  utf_in = (const char *) &v_msg[1];
877  GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
878  GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
879  issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
880  vrh = GNUNET_new (struct VerifyRequestHandle);
882  vrh->client = client;
883  vrh->request_id = v_msg->id;
884  vrh->issuer_key = v_msg->issuer_key;
885  vrh->subject_key = v_msg->subject_key;
886  vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
888  if (0 == strlen (issuer_attribute))
889  {
890  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
891  send_lookup_response (vrh);
892  return;
893  }
898  credentials_count = ntohl (v_msg->c_count);
899  credential_data_size = ntohs (v_msg->header.size)
900  - sizeof(struct VerifyMessage)
901  - ntohs (v_msg->issuer_attribute_len) - 1;
902  struct GNUNET_CREDENTIAL_Credential credentials[credentials_count];
903  memset (credentials,
904  0,
905  sizeof(struct GNUNET_CREDENTIAL_Credential) * credentials_count);
906  credential_data = (char *) &v_msg[1] + ntohs (v_msg->issuer_attribute_len)
907  + 1;
908  if (GNUNET_OK
909  != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size,
910  credential_data,
911  credentials_count,
912  credentials))
913  {
914  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n");
915  send_lookup_response (vrh);
916  return;
917  }
918 
919  for (uint32_t i = 0; i < credentials_count; i++)
920  {
921  cr_entry = GNUNET_new (struct CredentialRecordEntry);
922  cr_entry->credential
924  + credentials[i].issuer_attribute_len + 1);
925  GNUNET_memcpy (cr_entry->credential,
926  &credentials[i],
927  sizeof(struct GNUNET_CREDENTIAL_Credential));
928  GNUNET_memcpy (&cr_entry->credential[1],
929  credentials[i].issuer_attribute,
930  credentials[i].issuer_attribute_len);
932  = credentials[i].issuer_attribute_len;
933  cr_entry->credential->issuer_attribute = (char *) &cr_entry->credential[1];
935  vrh->cred_chain_tail,
936  cr_entry);
937  vrh->cred_chain_size++;
938  }
939 
941 }
Message from client to Credential service to verify attributes.
Definition: credential.h:69
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_CREDENTIAL_credentials_deserialize(size_t len, const char *src, unsigned int c_count, struct GNUNET_CREDENTIAL_Credential *cd)
Deserialize the given destination.
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: credential.h:94
uint32_t id
Unique identifier for this request (for key collisions).
Definition: credential.h:99
char * issuer_attribute
Issuer attribute.
static void delegation_chain_resolution_start(void *cls)
Result from GNS lookup.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Subject public key.
Definition: credential.h:79
static struct VerifyRequestHandle * vrh_head
Head of the DLL.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
uint32_t cred_chain_size
Credential DLL size.
Handle to a client that is connected to a service.
Definition: service.c:250
uint32_t request_id
request id
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Issuer public key.
static struct VerifyRequestHandle * vrh_tail
Tail of the DLL.
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY.
Definition: credential.h:74
static void send_lookup_response(struct VerifyRequestHandle *vrh)
struct CredentialRecordEntry * cred_chain_head
Credential DLL.
Handle to a lookup operation from api.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
uint32_t c_count
Number of credentials.
Definition: credential.h:89
struct CredentialRecordEntry * cred_chain_tail
Credential DLL.
const char * issuer_attribute
The attribute.
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Subject public key.
struct GNUNET_SERVICE_Client * client
Handle to the requesting client.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Trust anchor.
Definition: credential.h:84
#define GNUNET_CREDENTIAL_MAX_LENGTH
struct GNUNET_CREDENTIAL_Credential * credential
Payload.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
#define GNUNET_malloc(size)
Wrapper around malloc.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:553
uint32_t issuer_attribute_len
Length of the attribute.
Here is the call graph for this function:

◆ handle_cred_collection_error_cb()

static void handle_cred_collection_error_cb ( void *  cls)
static

Definition at line 944 of file gnunet-service-credential.c.

References VerifyRequestHandle::cred_collection_iter, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and send_lookup_response().

Referenced by handle_collect().

945 {
946  struct VerifyRequestHandle *vrh = cls;
947 
949  "Got disconnected from namestore database.\n");
950  vrh->cred_collection_iter = NULL;
951  send_lookup_response (vrh);
952 }
struct GNUNET_NAMESTORE_ZoneIterator * cred_collection_iter
Credential iterator.
static void send_lookup_response(struct VerifyRequestHandle *vrh)
Handle to a lookup operation from api.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ collect_next()

static void collect_next ( void *  cls)
static

Definition at line 955 of file gnunet-service-credential.c.

References VerifyRequestHandle::collect_next_task, VerifyRequestHandle::cred_collection_iter, GNUNET_assert, and GNUNET_NAMESTORE_zone_iterator_next().

Referenced by handle_cred_collection_cb().

956 {
957  struct VerifyRequestHandle *vrh = cls;
958 
959  vrh->collect_next_task = NULL;
960  GNUNET_assert (NULL != vrh->cred_collection_iter);
962 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record...
struct GNUNET_NAMESTORE_ZoneIterator * cred_collection_iter
Credential iterator.
struct GNUNET_SCHEDULER_Task * collect_next_task
Collect task.
Handle to a lookup operation from api.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_cred_collection_cb()

static void handle_cred_collection_cb ( void *  cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey key,
const char *  label,
unsigned int  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Definition at line 966 of file gnunet-service-credential.c.

References collect_next(), VerifyRequestHandle::collect_next_task, VerifyRequestHandle::cred_chain_head, VerifyRequestHandle::cred_chain_size, VerifyRequestHandle::cred_chain_tail, CredentialRecordEntry::credential, data, data_size, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CREDENTIAL_credential_deserialize(), GNUNET_ERROR_TYPE_WARNING, GNUNET_GNSRECORD_TYPE_CREDENTIAL, GNUNET_log, GNUNET_new, and GNUNET_SCHEDULER_add_now().

Referenced by handle_collect().

971 {
972  struct VerifyRequestHandle *vrh = cls;
973  struct GNUNET_CREDENTIAL_Credential *crd;
974  struct CredentialRecordEntry *cr_entry;
975  int cred_record_count;
976 
977  cred_record_count = 0;
978  for (uint32_t i = 0; i < rd_count; i++)
979  {
980  if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
981  continue;
982  cred_record_count++;
983  crd
985  if (NULL == crd)
986  {
987  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n");
988  continue;
989  }
990  cr_entry = GNUNET_new (struct CredentialRecordEntry);
991  cr_entry->credential = crd;
993  vrh->cred_chain_tail,
994  cr_entry);
995  vrh->cred_chain_size++;
996  }
998 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t cred_chain_size
Credential DLL size.
#define GNUNET_GNSRECORD_TYPE_CREDENTIAL
65546 reserved
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1280
struct GNUNET_SCHEDULER_Task * collect_next_task
Collect task.
static void collect_next(void *cls)
struct GNUNET_CREDENTIAL_Credential * GNUNET_CREDENTIAL_credential_deserialize(const char *data, size_t data_size)
struct CredentialRecordEntry * cred_chain_head
Credential DLL.
Handle to a lookup operation from api.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
struct CredentialRecordEntry * cred_chain_tail
Credential DLL.
#define GNUNET_log(kind,...)
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
struct GNUNET_CREDENTIAL_Credential * credential
Payload.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_cred_collection_finished_cb()

static void handle_cred_collection_finished_cb ( void *  cls)
static

Definition at line 1001 of file gnunet-service-credential.c.

References VerifyRequestHandle::cred_collection_iter, delegation_chain_resolution_start(), GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.

Referenced by handle_collect().

1002 {
1003  struct VerifyRequestHandle *vrh = cls;
1004 
1005  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n");
1006  vrh->cred_collection_iter = NULL;
1008 }
static void delegation_chain_resolution_start(void *cls)
Result from GNS lookup.
struct GNUNET_NAMESTORE_ZoneIterator * cred_collection_iter
Credential iterator.
Handle to a lookup operation from api.
#define GNUNET_log(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_collect()

static void handle_collect ( void *  cls,
const struct CollectMessage c_msg 
)
static

First, get attribute from subject

Definition at line 1011 of file gnunet-service-credential.c.

References VerifyRequestHandle::client, VerifyRequestHandle::cred_collection_iter, GNUNET_CONTAINER_DLL_insert, GNUNET_CREDENTIAL_MAX_LENGTH, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_memcpy, GNUNET_NAMESTORE_zone_iteration_start(), GNUNET_new, GNUNET_SERVICE_client_continue(), GNUNET_strdup, GNUNET_STRINGS_utf8_tolower(), handle_cred_collection_cb(), handle_cred_collection_error_cb(), handle_cred_collection_finished_cb(), CollectMessage::id, DelegationChainEntry::issuer_attribute, VerifyRequestHandle::issuer_attribute, CollectMessage::issuer_attribute_len, CollectMessage::issuer_key, VerifyRequestHandle::issuer_key, VerifyRequestHandle::request_id, send_lookup_response(), CollectMessage::subject_key, and VerifyRequestHandle::subject_key.

1012 {
1013  char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
1015  struct VerifyRequestHandle *vrh;
1016  struct GNUNET_SERVICE_Client *client = cls;
1017  char *attrptr = attr;
1018  const char *utf_in;
1019 
1020  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
1021 
1022  utf_in = (const char *) &c_msg[1];
1023  GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
1024 
1025  GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
1026  issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
1027  vrh = GNUNET_new (struct VerifyRequestHandle);
1029  vrh->client = client;
1030  vrh->request_id = c_msg->id;
1031  vrh->issuer_key = c_msg->issuer_key;
1033  vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
1034 
1035  if (0 == strlen (issuer_attribute))
1036  {
1037  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
1038  send_lookup_response (vrh);
1039  return;
1040  }
1041  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n");
1046  namestore,
1047  &c_msg->subject_key,
1049  vrh,
1051  vrh,
1053  vrh);
1055 }
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
char * issuer_attribute
Issuer attribute.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Trust anchor.
Definition: credential.h:50
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static struct VerifyRequestHandle * vrh_head
Head of the DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
static struct GNUNET_NAMESTORE_Handle * namestore
Handle to namestore service.
Handle to a client that is connected to a service.
Definition: service.c:250
uint32_t request_id
request id
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Issuer public key.
static struct VerifyRequestHandle * vrh_tail
Tail of the DLL.
struct GNUNET_NAMESTORE_ZoneIterator * cred_collection_iter
Credential iterator.
static void send_lookup_response(struct VerifyRequestHandle *vrh)
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:239
Handle to a lookup operation from api.
uint32_t id
Unique identifier for this request (for key collisions).
Definition: credential.h:60
struct GNUNET_CRYPTO_EcdsaPrivateKey subject_key
Subject public key.
Definition: credential.h:45
static void handle_cred_collection_finished_cb(void *cls)
#define GNUNET_log(kind,...)
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Subject public key.
struct GNUNET_SERVICE_Client * client
Handle to the requesting client.
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: credential.h:55
static void handle_cred_collection_error_cb(void *cls)
#define GNUNET_CREDENTIAL_MAX_LENGTH
static void handle_cred_collection_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:553
Here is the call graph for this function:

◆ check_collect()

static int check_collect ( void *  cls,
const struct CollectMessage c_msg 
)
static

Definition at line 1059 of file gnunet-service-credential.c.

References GNUNET_break, GNUNET_CREDENTIAL_MAX_LENGTH, GNUNET_OK, GNUNET_SYSERR, CollectMessage::header, CollectMessage::issuer_attribute_len, and GNUNET_MessageHeader::size.

1060 {
1061  size_t msg_size;
1062  const char *attr;
1063 
1064  msg_size = ntohs (c_msg->header.size);
1065  if (msg_size < sizeof(struct CollectMessage))
1066  {
1067  GNUNET_break (0);
1068  return GNUNET_SYSERR;
1069  }
1071  {
1072  GNUNET_break (0);
1073  return GNUNET_SYSERR;
1074  }
1075  attr = (const char *) &c_msg[1];
1076 
1077  if (('\0' != attr[msg_size - sizeof(struct CollectMessage) - 1])
1078  || (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH))
1079  {
1080  GNUNET_break (0);
1081  return GNUNET_SYSERR;
1082  }
1083  return GNUNET_OK;
1084 }
Message from client to Credential service to collect credentials.
Definition: credential.h:35
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY.
Definition: credential.h:40
uint16_t issuer_attribute_len
Length of the issuer attribute.
Definition: credential.h:55
#define GNUNET_CREDENTIAL_MAX_LENGTH

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_ctx 
)
static

Definition at line 1087 of file gnunet-service-credential.c.

References GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.

Referenced by run().

1090 {
1091  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
1092 }
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Definition at line 1095 of file gnunet-service-credential.c.

References GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.

Referenced by run().

1098 {
1099  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
1100  return client;
1101 }
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle handle 
)
static

Process Credential requests.

Parameters
clsclosure
cconfiguration to use
handleservice handle

Definition at line 1111 of file gnunet-service-credential.c.

References _, client_connect_cb(), client_disconnect_cb(), collect, GNUNET_GNS_connect(), GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NAMESTORE_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, GNUNET_STATISTICS_create(), shutdown_task(), and verify.

1114 {
1115  gns = GNUNET_GNS_connect (c);
1116  if (NULL == gns)
1117  {
1118  fprintf (stderr, _ ("Failed to connect to GNS\n"));
1119  }
1121  if (NULL == namestore)
1122  {
1123  fprintf (stderr, _ ("Failed to connect to namestore\n"));
1124  }
1125 
1126  statistics = GNUNET_STATISTICS_create ("credential", c);
1128 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static void shutdown_task(void *cls)
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_NAMESTORE_Handle * namestore
Handle to namestore service.
struct GNUNET_GNS_Handle * GNUNET_GNS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the GNS service.
Definition: gns_api.c:262
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
static struct GNUNET_GNS_Handle * gns
Handle to GNS service.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( "credential"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_var_size(verify, GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY, struct VerifyMessage, NULL)  ,
GNUNET_MQ_hd_var_size(collect, GNUNET_MESSAGE_TYPE_CREDENTIAL_COLLECT, struct CollectMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ vrh_head

struct VerifyRequestHandle* vrh_head
static

Head of the DLL.

Definition at line 328 of file gnunet-service-credential.c.

◆ vrh_tail

struct VerifyRequestHandle* vrh_tail
static

Tail of the DLL.

Definition at line 333 of file gnunet-service-credential.c.

◆ statistics

struct GNUNET_STATISTICS_Handle* statistics
static

Handle to the statistics service.

Definition at line 338 of file gnunet-service-credential.c.

◆ gns

struct GNUNET_GNS_Handle* gns
static

Handle to GNS service.

Definition at line 343 of file gnunet-service-credential.c.

◆ namestore

struct GNUNET_NAMESTORE_Handle* namestore
static

Handle to namestore service.

Definition at line 349 of file gnunet-service-credential.c.