From 1b67c9c5424c96ff4e30d12b8d58cec315f000a1 Mon Sep 17 00:00:00 2001 From: Martin Schanzenbach Date: Thu, 7 Jan 2016 21:10:24 +0000 Subject: [PATCH] - Finish refactoring --- src/Makefile.am | 2 +- .../Makefile.am | 0 .../gnunet-identity-token.c | 0 .../gnunet-service-identity-token.c | 0 .../identity-token.c | 0 .../identity-token.conf | 0 .../plugin_rest_identity_token.c | 0 src/identity/plugin_gnsrecord_identity.c | 83 +++++++++++++++++-- .../gnunet_identity_provider_lib.h} | 0 src/include/gnunet_signatures.h | 4 +- src/rest/gnunet-rest-server.c | 11 +-- 11 files changed, 80 insertions(+), 20 deletions(-) rename src/{identity-token => identity-provider}/Makefile.am (100%) rename src/{identity-token => identity-provider}/gnunet-identity-token.c (100%) rename src/{identity-token => identity-provider}/gnunet-service-identity-token.c (100%) rename src/{identity-token => identity-provider}/identity-token.c (100%) rename src/{identity-token => identity-provider}/identity-token.conf (100%) rename src/{identity-token => identity-provider}/plugin_rest_identity_token.c (100%) rename src/{identity-token/identity-token.h => include/gnunet_identity_provider_lib.h} (100%) diff --git a/src/Makefile.am b/src/Makefile.am index 76997918f..6e0fa5c4b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -28,7 +28,7 @@ if HAVE_EXPERIMENTAL endif if HAVE_REST - EXP_DIR += identity-token + EXP_DIR += identity-provider endif if BUILD_PULSE_HELPERS diff --git a/src/identity-token/Makefile.am b/src/identity-provider/Makefile.am similarity index 100% rename from src/identity-token/Makefile.am rename to src/identity-provider/Makefile.am diff --git a/src/identity-token/gnunet-identity-token.c b/src/identity-provider/gnunet-identity-token.c similarity index 100% rename from src/identity-token/gnunet-identity-token.c rename to src/identity-provider/gnunet-identity-token.c diff --git a/src/identity-token/gnunet-service-identity-token.c b/src/identity-provider/gnunet-service-identity-token.c similarity index 100% rename from src/identity-token/gnunet-service-identity-token.c rename to src/identity-provider/gnunet-service-identity-token.c diff --git a/src/identity-token/identity-token.c b/src/identity-provider/identity-token.c similarity index 100% rename from src/identity-token/identity-token.c rename to src/identity-provider/identity-token.c diff --git a/src/identity-token/identity-token.conf b/src/identity-provider/identity-token.conf similarity index 100% rename from src/identity-token/identity-token.conf rename to src/identity-provider/identity-token.conf diff --git a/src/identity-token/plugin_rest_identity_token.c b/src/identity-provider/plugin_rest_identity_token.c similarity index 100% rename from src/identity-token/plugin_rest_identity_token.c rename to src/identity-provider/plugin_rest_identity_token.c diff --git a/src/identity/plugin_gnsrecord_identity.c b/src/identity/plugin_gnsrecord_identity.c index a23629b41..fd689490a 100644 --- a/src/identity/plugin_gnsrecord_identity.c +++ b/src/identity/plugin_gnsrecord_identity.c @@ -44,11 +44,31 @@ value_to_string (void *cls, const void *data, size_t data_size) { + const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; + const struct GNUNET_CRYPTO_EcdsaPublicKey *audience_pubkey; + const char *scopes; + char *ecdhe_str; + char *aud_str; + char *result; + switch (type) { case GNUNET_GNSRECORD_TYPE_ID_ATTR: case GNUNET_GNSRECORD_TYPE_ID_TOKEN: return GNUNET_strndup (data, data_size); + case GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA: + ecdhe_privkey = data; + audience_pubkey = data+sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey); + scopes = (char*) audience_pubkey+(sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); + ecdhe_str = GNUNET_STRINGS_data_to_string_alloc (ecdhe_privkey, + sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); + aud_str = GNUNET_STRINGS_data_to_string_alloc (audience_pubkey, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); + GNUNET_asprintf (&result, + "%s;%s;%s", + ecdhe_str, aud_str, scopes); + return result; + default: return NULL; } @@ -73,6 +93,12 @@ string_to_value (void *cls, void **data, size_t *data_size) { + char* ecdhe_str; + char* aud_keystr; + char* write_ptr; + char* tmp_tok; + char* str; + if (NULL == s) return GNUNET_SYSERR; switch (type) @@ -82,6 +108,46 @@ string_to_value (void *cls, *data = GNUNET_strdup (s); *data_size = strlen (s); return GNUNET_OK; + case GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA: + tmp_tok = GNUNET_strdup (s); + ecdhe_str = strtok (tmp_tok, ";"); + if (NULL == ecdhe_str) + { + GNUNET_free (tmp_tok); + return GNUNET_SYSERR; + } + aud_keystr = strtok (NULL, ";"); + if (NULL == aud_keystr) + { + GNUNET_free (tmp_tok); + return GNUNET_SYSERR; + } + str = strtok (NULL, ";"); + if (NULL == str) + { + GNUNET_free (tmp_tok); + return GNUNET_SYSERR; + } + *data_size = strlen (str) + 1 + +sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey) + +sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); + *data = GNUNET_malloc (*data_size); + + write_ptr = *data; + GNUNET_STRINGS_string_to_data (ecdhe_str, + strlen (ecdhe_str), + write_ptr, + sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); + write_ptr += sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey); + GNUNET_STRINGS_string_to_data (aud_keystr, + strlen (aud_keystr), + write_ptr, + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); + write_ptr += sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); + memcpy (write_ptr, str, strlen (str) + 1); //with 0-Terminator + GNUNET_free (tmp_tok); + return GNUNET_OK; + default: return GNUNET_SYSERR; } @@ -92,14 +158,15 @@ string_to_value (void *cls, * Mapping of record type numbers to human-readable * record type names. */ -static struct { - const char *name; - uint32_t number; -} name_map[] = { - { "ID_ATTR", GNUNET_GNSRECORD_TYPE_ID_ATTR }, - { "ID_TOKEN", GNUNET_GNSRECORD_TYPE_ID_TOKEN }, - { NULL, UINT32_MAX } -}; + static struct { + const char *name; + uint32_t number; + } name_map[] = { + { "ID_ATTR", GNUNET_GNSRECORD_TYPE_ID_ATTR }, + { "ID_TOKEN", GNUNET_GNSRECORD_TYPE_ID_TOKEN }, + { "ID_TOKEN_METADATA", GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA }, + { NULL, UINT32_MAX } + }; /** diff --git a/src/identity-token/identity-token.h b/src/include/gnunet_identity_provider_lib.h similarity index 100% rename from src/identity-token/identity-token.h rename to src/include/gnunet_identity_provider_lib.h diff --git a/src/include/gnunet_signatures.h b/src/include/gnunet_signatures.h index dd6afbec5..95d570b54 100644 --- a/src/include/gnunet_signatures.h +++ b/src/include/gnunet_signatures.h @@ -182,9 +182,9 @@ extern "C" #define GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN 26 /** - * Signature for a GNUid Token Reference + * Signature for a GNUid Ticket */ -#define GNUNET_SIGNATURE_PURPOSE_GNUID_TOKEN_CODE 27 +#define GNUNET_SIGNATURE_PURPOSE_GNUID_TICKET 27 #if 0 /* keep Emacsens' auto-indent happy */ { diff --git a/src/rest/gnunet-rest-server.c b/src/rest/gnunet-rest-server.c index ba18c5dfa..0e7213b64 100644 --- a/src/rest/gnunet-rest-server.c +++ b/src/rest/gnunet-rest-server.c @@ -464,15 +464,8 @@ schedule_httpd () } if (NULL != httpd_task) GNUNET_SCHEDULER_cancel (httpd_task); - if ( (MHD_YES != haveto) && - (-1 == max)) - { - /* daemon is idle, kill after timeout */ - httpd_task = GNUNET_SCHEDULER_add_delayed (MHD_CACHE_TIMEOUT, - &kill_httpd_task, - NULL); - } - else + if ( (MHD_YES == haveto) || + (-1 != max)) { httpd_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, -- 2.25.1