#include "gnunet_signatures.h"
#include "identity_provider.h"
#include "identity_token.h"
+#include <inttypes.h>
/**
* First pass state
/**
* Timeout task
*/
-static struct GNUNET_SCHEDULER_Task * timeout_task;
-
+static struct GNUNET_SCHEDULER_Task *timeout_task;
/**
* Update task
*/
-static struct GNUNET_SCHEDULER_Task * update_task;
+static struct GNUNET_SCHEDULER_Task *update_task;
/**
* Timeout for next update pass
* LookupRequest
*/
struct GNUNET_GNS_LookupRequest *lookup_request;
-
+
/**
* Audience Key
*/
* removes deleted attributes and expiration times.
*
* @param cls the ego entry
- * @param tc task context
*/
static void
-handle_token_update (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+handle_token_update (void *cls)
{
char *token_metadata;
char *write_ptr;
if (0 == strcmp (attr->name, "exp"))
{
sscanf (attr->val_head->value,
- "%lu",
+ "%"SCNu64,
&token_exp.abs_value_us);
} else if (0 == strcmp (attr->name, "nbf")) {
sscanf (attr->val_head->value,
- "%lu",
+ "%"SCNu64,
&token_nbf.abs_value_us);
}
}
attr->name,
attr->val_head->value);
}
- else
+ else
{
GNUNET_CRYPTO_hash (attr->name,
strlen (attr->name),
&key_hash);
//Check if attr still exists. omit of not
- if (GNUNET_NO !=
+ if (GNUNET_NO !=
GNUNET_CONTAINER_multihashmap_contains (ego_entry->attr_map,
&key_hash))
{
token_record,
&store_token_cont,
ego_entry);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, ">>> Updating Token w/ %s\n", new_token);
token_destroy (new_token);
token_destroy (token);
GNUNET_free (new_ecdhe_privkey);
scopes = NULL;
}
+
static void
-update_identities(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+update_identities(void *cls);
+
/**
*
* @param cls NULL
* @param key the key
* @param value the json_t attribute value
- * @return GNUNET_YES
+ * @return #GNUNET_YES
*/
static int
clear_ego_attrs (void *cls,
return GNUNET_YES;
}
+
/**
*
* Update all ID_TOKEN records for an identity and store them
* @param lbl the name of the record
* @param rd_count number of records
* @param rd record data
- *
*/
static void
token_collect (void *cls,
GNUNET_CONTAINER_multihashmap_clear (ego_entry->attr_map);
update_task = GNUNET_SCHEDULER_add_now (&update_identities,
ego_entry->next);
- return;
+ return;
}
//There should be only a single record for a token under a label
{
token_metadata_record = &rd[0];
token_record = &rd[1];
- } else {
+ }
+ else
+ {
token_record = &rd[0];
token_metadata_record = &rd[1];
}
aud_key,
&token);
- label = GNUNET_strdup (lbl);
+ label = GNUNET_strdup (lbl);
rd_exp = token_record->expiration_time;
- GNUNET_SCHEDULER_add_now (&handle_token_update, ego_entry);
+ GNUNET_SCHEDULER_add_now (&handle_token_update,
+ ego_entry);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
">>> Updating Attributes finished\n");
ego_entry->attributes_dirty = GNUNET_NO;
- update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_entry);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_entry);
return;
}
* dirty, first update the attributes.
*
* @param cls the ego to update
- * param tc task context
- *
*/
static void
-update_identities(void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+update_identities(void *cls)
{
struct EgoEntry *next_ego = cls;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key;
if (min_rel_exp.rel_value_us < MIN_WAIT_TIME.rel_value_us)
min_rel_exp = MIN_WAIT_TIME;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- ">>> Finished. Rescheduling in %d\n",
+ ">>> Finished. Rescheduling in %lu\n",
min_rel_exp.rel_value_us);
ns_it = NULL;
//finished -> reschedule
}
-
/**
* Function called initially to start update task
*/
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO, ">>> Starting Service\n");
//Initially iterate all itenties and refresh all tokens
- update_task = GNUNET_SCHEDULER_add_now (&update_identities, ego_head);
+ update_task = GNUNET_SCHEDULER_add_now (&update_identities,
+ ego_head);
}
+
/**
* Initial ego collection function.
*
* @param tc task context
*/
static void
-do_shutdown (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Shutting down...\n");
static struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage*
create_exchange_result_message (const char* token,
- const char* label)
+ const char* label,
+ uint64_t ticket_nonce)
{
struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage *erm;
uint16_t token_len = strlen (token) + 1;
- erm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage)
+ erm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage)
+ token_len);
erm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_EXCHANGE_RESULT);
- erm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage)
+ erm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_ExchangeResultMessage)
+ token_len);
+ erm->ticket_nonce = htonl (ticket_nonce);
memcpy (&erm[1], token, token_len);
return erm;
}
struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
char *tmp_str;
- irm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage)
+ irm = GNUNET_malloc (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage)
+ strlen (label) + 1
+ strlen (ticket) + 1
+ strlen (token) + 1);
irm->header.type = htons (GNUNET_MESSAGE_TYPE_IDENTITY_PROVIDER_ISSUE_RESULT);
- irm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage)
+ irm->header.size = htons (sizeof (struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage)
+ strlen (label) + 1
+ strlen (ticket) + 1
+ strlen (token) + 1);
struct GNUNET_IDENTITY_PROVIDER_IssueResultMessage *irm;
char *ticket_str;
char *token_str;
+
handle->ns_qe = NULL;
if (GNUNET_SYSERR == success)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s\n",
"Error serializing ticket\n");
cleanup_issue_handle (handle);
- GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
if (GNUNET_OK != token_to_string (handle->token,
"Error serializing token\n");
GNUNET_free (ticket_str);
cleanup_issue_handle (handle);
- GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
return;
}
- irm = create_issue_result_message (handle->label, ticket_str, token_str);
+ irm = create_issue_result_message (handle->label,
+ ticket_str,
+ token_str);
GNUNET_SERVER_notification_context_unicast (nc,
handle->client,
&irm->header,
GNUNET_free (token_str);
}
+
/**
* Build a GNUid token for identity
+ *
+ * FIXME: doxygen is very wrong here!
+ *
* @param handle the handle
* @param ego_entry the ego to build the token for
* @param name name of the ego
* @return identifier string of token (label)
*/
static void
-sign_and_return_token (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+sign_and_return_token (void *cls)
{
struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey;
uint64_t exp_time;
size_t token_metadata_len;
- //Remote nonce
+ //Remote nonce
nonce_str = NULL;
- GNUNET_asprintf (&nonce_str, "%d", handle->nonce);
+ GNUNET_asprintf (&nonce_str, "%lu", handle->nonce);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request nonce: %s\n", nonce_str);
GNUNET_CRYPTO_ecdsa_key_get_public (&handle->iss_key,
&pub_key);
- handle->ticket = ticket_create (nonce_str,
+ handle->ticket = ticket_create (handle->nonce,
&pub_key,
handle->label,
&handle->aud_key);
token_add_attr_int (handle->token, "exp", exp_time);
token_add_attr (handle->token, "nonce", nonce_str);
- //Token in a serialized encrypted format
+ //Token in a serialized encrypted format
GNUNET_assert (token_serialize (handle->token,
&handle->iss_key,
&ecdhe_privkey,
static void
cleanup_exchange_handle (struct ExchangeHandle *handle)
{
- if (NULL != handle->ticket)
+ if (NULL != handle->ticket)
ticket_destroy (handle->ticket);
if (NULL != handle->token)
token_destroy (handle->token);
return;
}
- record_str =
+ record_str =
GNUNET_GNSRECORD_value_to_string (GNUNET_GNSRECORD_TYPE_ID_TOKEN,
rd->data,
rd->data_size);
&token_str));
erm = create_exchange_result_message (token_str,
- handle->label);
+ handle->label,
+ handle->ticket->payload->nonce);
GNUNET_SERVER_notification_context_unicast (nc,
handle->client,
&erm->header,
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
">>> No existing token found\n");
//Label
- rnd_key =
+ rnd_key =
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
UINT64_MAX);
GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
&handle->iss_key,
&attr_collect,
handle);
- return;
+ return;
}
//There should be only a single record for a token under a label
return;
}
ecdhe_privkey = *((struct GNUNET_CRYPTO_EcdhePrivateKey *)token_metadata_record->data);
- aud_key =
+ aud_key =
(struct GNUNET_CRYPTO_EcdsaPublicKey *)(token_metadata_record->data+sizeof(struct GNUNET_CRYPTO_EcdhePrivateKey));
tmp_scopes = GNUNET_strdup ((char*) aud_key+sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
}
im = (const struct GNUNET_IDENTITY_PROVIDER_IssueMessage *) message;
scopes = (const char *) &im[1];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received ISSUE of `%s' from client\n",
- scope);
issue_handle = GNUNET_malloc (sizeof (struct IssueHandle));
issue_handle->attr_map = GNUNET_CONTAINER_multihashmap_create (5,
GNUNET_NO);
+ /* FIXME: check that scopes is 0-termianted, Out-of-bounds access
+ possible here!!! */
scopes_tmp = GNUNET_strdup (scopes);
scope = strtok(scopes_tmp, ",");
for (; NULL != scope; scope = strtok (NULL, ","))
* @param c configuration
*/
static void
-run (void *cls,
+run (void *cls,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
&list_ego,
NULL);
- if (GNUNET_OK ==
+ if (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_time (cfg,
"identity-provider",
"TOKEN_EXPIRATION_INTERVAL",
token_expiration_interval = DEFAULT_TOKEN_EXPIRATION_INTERVAL;
}
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &do_shutdown, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
}
/**
- *
* The main function
*
* @param argc number of arguments from the cli
* @param argv command line arguments
* @return 0 ok, 1 on error
- *
*/
int
main (int argc, char *const *argv)
&run, NULL)) ? 0 : 1;
}
-/* end of gnunet-rest-server.c */
+/* end of gnunet-service-identity-provider.c */