summaryrefslogtreecommitdiff
path: root/src/credential/gnunet-service-credential.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/credential/gnunet-service-credential.c')
-rw-r--r--src/credential/gnunet-service-credential.c227
1 files changed, 125 insertions, 102 deletions
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index de0592637..114041be1 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -45,17 +45,17 @@
/**
* DLL for record
*/
-struct CredentialRecordEntry
+struct AttributeRecordEntry
{
/**
* DLL
*/
- struct CredentialRecordEntry *next;
+ struct AttributeRecordEntry *next;
/**
* DLL
*/
- struct CredentialRecordEntry *prev;
+ struct AttributeRecordEntry *prev;
/**
@@ -67,18 +67,18 @@ struct CredentialRecordEntry
/**
* Handle to a lookup operation from api
*/
-struct ClientLookupHandle
+struct VerifyRequestHandle
{
/**
* We keep these in a DLL.
*/
- struct ClientLookupHandle *next;
+ struct VerifyRequestHandle *next;
/**
* We keep these in a DLL.
*/
- struct ClientLookupHandle *prev;
+ struct VerifyRequestHandle *prev;
/**
* Handle to the requesting client
@@ -91,19 +91,24 @@ struct ClientLookupHandle
struct GNUNET_GNS_LookupRequest *lookup_request;
/**
- * Authority public key
+ * Issuer public key
*/
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key;
/**
- * Credential Chain
+ * Subject public key
*/
- struct CredentialRecordEntry *cred_chain_head;
+ struct GNUNET_CRYPTO_EcdsaPublicKey subject_key;
/**
- * Credential Chain
+ * Attribute Chain
*/
- struct CredentialRecordEntry *cred_chain_tail;
+ struct AttributeRecordEntry *attr_chain_head;
+
+ /**
+ * Attribute Chain
+ */
+ struct AttributeRecordEntry *attr_chain_tail;
/**
* request id
@@ -116,12 +121,12 @@ struct ClientLookupHandle
/**
* Head of the DLL.
*/
-static struct ClientLookupHandle *clh_head;
+static struct VerifyRequestHandle *vrh_head;
/**
* Tail of the DLL.
*/
-static struct ClientLookupHandle *clh_tail;
+static struct VerifyRequestHandle *vrh_tail;
/**
* Handle to the statistics service
@@ -144,17 +149,17 @@ static struct GNUNET_GNS_Handle *gns;
static void
shutdown_task (void *cls)
{
- struct ClientLookupHandle *clh;
+ struct VerifyRequestHandle *vrh;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Shutting down!\n");
- while (NULL != (clh = clh_head))
+ while (NULL != (vrh = vrh_head))
{
//CREDENTIAL_resolver_lookup_cancel (clh->lookup);
- GNUNET_CONTAINER_DLL_remove (clh_head,
- clh_tail,
- clh);
- GNUNET_free (clh);
+ GNUNET_CONTAINER_DLL_remove (vrh_head,
+ vrh_tail,
+ vrh);
+ GNUNET_free (vrh);
}
@@ -168,28 +173,38 @@ shutdown_task (void *cls)
}
/**
- * Checks a #GNUNET_MESSAGE_TYPE_CREDENTIAL_LOOKUP message
+ * Checks a #GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY message
*
* @param cls client sending the message
- * @param l_msg message of type `struct LookupMessage`
- * @return #GNUNET_OK if @a l_msg is well-formed
+ * @param v_msg message of type `struct VerifyMessage`
+ * @return #GNUNET_OK if @a v_msg is well-formed
*/
static int
-check_lookup (void *cls,
- const struct LookupMessage *l_msg)
+check_verify (void *cls,
+ const struct VerifyMessage *v_msg)
{
size_t msg_size;
- const char* cred;
+ size_t attr_len;
+ const char* s_attr;
+ const char* i_attr;
- msg_size = ntohs (l_msg->header.size);
- if (msg_size < sizeof (struct LookupMessage))
+ msg_size = ntohs (v_msg->header.size);
+ if (msg_size < sizeof (struct VerifyMessage))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ i_attr = (const char *) &v_msg[1];
+ if ( ('\0' != i_attr[v_msg->header.size - sizeof (struct VerifyMessage) - 1]) ||
+ (strlen (i_attr) > GNUNET_CREDENTIAL_MAX_LENGTH) )
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
- cred = (const char *) &l_msg[1];
- if ( ('\0' != cred[l_msg->header.size - sizeof (struct LookupMessage) - 1]) ||
- (strlen (cred) > GNUNET_CREDENTIAL_MAX_LENGTH) )
+ attr_len = strlen (i_attr);
+ s_attr = ((const char *) &v_msg[1]) + attr_len + 1;
+ if ( ('\0' != s_attr[v_msg->header.size - sizeof (struct VerifyMessage) - 1]) ||
+ (strlen (s_attr) > GNUNET_CREDENTIAL_MAX_LENGTH) )
{
GNUNET_break (0);
return GNUNET_SYSERR;
@@ -199,7 +214,7 @@ check_lookup (void *cls,
/**
- * Reply to client with the result from our lookup.
+ * Result from GNS lookup.
*
* @param cls the closure (our client lookup handle)
* @param rd_count the number of records in @a rd
@@ -210,139 +225,147 @@ send_lookup_response (void* cls,
uint32_t rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
- struct ClientLookupHandle *clh = cls;
+ struct VerifyRequestHandle *vrh = cls;
size_t len;
int i;
- int cred_record_count;
+ int attr_record_count;
struct GNUNET_MQ_Envelope *env;
- struct LookupResultMessage *rmsg;
- const struct GNUNET_CREDENTIAL_RecordData *crd;
- struct CredentialRecordEntry *cr_entry;
+ struct VerifyResultMessage *rmsg;
+ const struct GNUNET_CREDENTIAL_RecordData *ard;
+ struct AttributeRecordEntry *ar_entry;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending LOOKUP_RESULT message with %u results\n",
- (unsigned int) rd_count);
-
- cred_record_count = 0;
+ attr_record_count = 0;
for (i=0; i < rd_count; i++)
{
- if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
+ if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
continue;
- cred_record_count++;
- crd = rd[i].data;
+ attr_record_count++;
+ ard = rd[i].data;
/**
- * TODO: Check for:
- * - First time we come here subject must be subject prvided by client
- * - After that is has to be the prev issuer
- * - Terminate condition: issuer is clh->authority_key
- *
- * In any case:
- * Append crd to result list of RecordData
+ * TODO:
+ * Check if we have already found our credential here
+ * If so return success
+ * Else
+ * Save all found attributes/issues and prepare forward
+ * resolution of issuer attribute
*/
- cr_entry = GNUNET_new (struct CredentialRecordEntry);
- cr_entry->record_data = *crd;
- GNUNET_CONTAINER_DLL_insert_tail (clh->cred_chain_head,
- clh->cred_chain_tail,
- cr_entry);
+ ar_entry = GNUNET_new (struct AttributeRecordEntry);
+ ar_entry->record_data = *ard;
+ GNUNET_CONTAINER_DLL_insert_tail (vrh->attr_chain_head,
+ vrh->attr_chain_tail,
+ ar_entry);
}
/**
* Get serialized record data size
*/
- len = cred_record_count * sizeof (struct GNUNET_CREDENTIAL_RecordData);
-
+ len = attr_record_count * sizeof (struct GNUNET_CREDENTIAL_RecordData);
+
/**
* Prepare a lookup result response message for the client
*/
env = GNUNET_MQ_msg_extra (rmsg,
len,
- GNUNET_MESSAGE_TYPE_CREDENTIAL_LOOKUP_RESULT);
+ GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT);
//Assign id so that client can find associated request
- rmsg->id = clh->request_id;
- rmsg->cd_count = htonl (cred_record_count);
-
+ rmsg->id = vrh->request_id;
+ rmsg->ad_count = htonl (attr_record_count);
+
/**
* Get serialized record data
* Append at the end of rmsg
*/
i = 0;
struct GNUNET_CREDENTIAL_RecordData *tmp_record = (struct GNUNET_CREDENTIAL_RecordData*) &rmsg[1];
- for (cr_entry = clh->cred_chain_head; NULL != cr_entry; cr_entry = cr_entry->next)
+ for (ar_entry = vrh->attr_chain_head; NULL != ar_entry; ar_entry = ar_entry->next)
{
memcpy (tmp_record,
- &cr_entry->record_data,
+ &ar_entry->record_data,
sizeof (struct GNUNET_CREDENTIAL_RecordData));
tmp_record++;
}
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(clh->client),
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client),
env);
- GNUNET_CONTAINER_DLL_remove (clh_head, clh_tail, clh);
-
+ GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
+
/**
* TODO:
* - Free DLL
* - Refactor into cleanup_handle() function for this
*/
- GNUNET_free (clh);
+ GNUNET_free (vrh);
GNUNET_STATISTICS_update (statistics,
- "Completed lookups", 1,
+ "Completed verifications", 1,
GNUNET_NO);
GNUNET_STATISTICS_update (statistics,
- "Records resolved",
+ "Attributes resolved",
rd_count,
GNUNET_NO);
}
/**
- * Handle lookup requests from client
+ * Handle attribute verification requests from client
*
* @param cls the closure
* @param client the client
* @param message the message
*/
static void
-handle_lookup (void *cls,
- const struct LookupMessage *l_msg)
+handle_verify (void *cls,
+ const struct VerifyMessage *v_msg)
{
- char credential[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
- struct ClientLookupHandle *clh;
+ char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
+ char subject_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
+ size_t issuer_attribute_len;
+ struct VerifyRequestHandle *vrh;
struct GNUNET_SERVICE_Client *client = cls;
- char *credentialptr = credential;
+ char *attrptr = issuer_attribute;
const char *utf_in;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received LOOKUP message\n");
-
- utf_in = (const char *) &l_msg[1];
- GNUNET_STRINGS_utf8_tolower (utf_in, credentialptr);
- clh = GNUNET_new (struct ClientLookupHandle);
- GNUNET_CONTAINER_DLL_insert (clh_head, clh_tail, clh);
- clh->client = client;
- clh->request_id = l_msg->id;
- clh->issuer_key = l_msg->issuer_key;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending LOOKUP_RESULT message with >%u results\n",
- 0);
-
- if (NULL == credential)
+ "Received VERIFY message\n");
+
+ utf_in = (const char *) &v_msg[1];
+ GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
+ issuer_attribute_len = strlen (utf_in);
+ utf_in = (const char *) (&v_msg[1] + issuer_attribute_len + 1);
+ attrptr = subject_attribute;
+ GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
+ vrh = GNUNET_new (struct VerifyRequestHandle);
+ GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
+ vrh->client = client;
+ vrh->request_id = v_msg->id;
+ vrh->issuer_key = v_msg->issuer_key;
+ vrh->subject_key = v_msg->subject_key;
+
+ if (NULL == subject_attribute)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No credential provided\n");
- send_lookup_response (clh, 0, NULL);
+ "No subject attribute provided!\n");
+ send_lookup_response (vrh, 0, NULL);
return;
}
- clh->lookup_request = GNUNET_GNS_lookup (gns,
- credential,
- &l_msg->subject_key, //subject_pkey,
- GNUNET_GNSRECORD_TYPE_CREDENTIAL,
- GNUNET_GNS_LO_DEFAULT, //TODO configurable? credential.conf
+ if (NULL == issuer_attribute)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "No issuer attribute provided!\n");
+ send_lookup_response (vrh, 0, NULL);
+ return;
+ }
+ /**
+ * First, get attribute from subject
+ */
+ vrh->lookup_request = GNUNET_GNS_lookup (gns,
+ subject_attribute,
+ &v_msg->subject_key, //subject_pkey,
+ GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
+ GNUNET_GNS_LO_DEFAULT,
NULL, //shorten_key, always NULL
&send_lookup_response,
- clh);
+ vrh);
}
@@ -416,9 +439,9 @@ GNUNET_SERVICE_MAIN
&client_connect_cb,
&client_disconnect_cb,
NULL,
- GNUNET_MQ_hd_var_size (lookup,
- GNUNET_MESSAGE_TYPE_CREDENTIAL_LOOKUP,
- struct LookupMessage,
+ GNUNET_MQ_hd_var_size (verify,
+ GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY,
+ struct VerifyMessage,
NULL),
GNUNET_MQ_handler_end());