summaryrefslogtreecommitdiff
path: root/src/credential
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-15 20:04:06 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-15 20:04:06 +0200
commit8341c4666b341e2dae0b84f15da02e09dc7fd9e9 (patch)
tree3e093ec9add413cfc3bd64bc8cc131ffd4fbc67e /src/credential
parenta61f1f4e3e755f3d9f2118201522b8130c2c5dea (diff)
CREDENTIAL: Fix build with new APIs
Diffstat (limited to 'src/credential')
-rw-r--r--src/credential/credential_misc.h13
-rw-r--r--src/credential/gnunet-service-credential.c581
-rw-r--r--src/credential/plugin_gnsrecord_credential.c329
-rw-r--r--src/credential/test_credential_lookup.conf2
-rwxr-xr-xsrc/credential/test_credential_verify_and.sh10
5 files changed, 373 insertions, 562 deletions
diff --git a/src/credential/credential_misc.h b/src/credential/credential_misc.h
index fbcd70c32..b06ee98cf 100644
--- a/src/credential/credential_misc.h
+++ b/src/credential/credential_misc.h
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -24,12 +24,13 @@
#ifndef CREDENTIAL_MISC_H
#define CREDENTIAL_MISC_H
+#include "gnunet_credential_service.h"
+char *
+GNUNET_CREDENTIAL_credential_to_string (
+ const struct GNUNET_CREDENTIAL_Credential *cred);
-char*
-GNUNET_CREDENTIAL_credential_to_string (const struct GNUNET_CREDENTIAL_Credential *cred);
-
-struct GNUNET_CREDENTIAL_Credential*
-GNUNET_CREDENTIAL_credential_from_string (const char* str);
+struct GNUNET_CREDENTIAL_Credential *
+GNUNET_CREDENTIAL_credential_from_string (const char *str);
#endif
diff --git a/src/credential/gnunet-service-credential.c b/src/credential/gnunet-service-credential.c
index 56c29b8b4..4a3002fa1 100644
--- a/src/credential/gnunet-service-credential.c
+++ b/src/credential/gnunet-service-credential.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -23,19 +23,20 @@
* @author Martin Schanzenbach
*/
#include "platform.h"
+
#include "gnunet_util_lib.h"
-#include "gnunet_credential_service.h"
-#include "gnunet_statistics_service.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_identity_service.h>
+#include <gnunet_gns_service.h>
#include <gnunet_gnsrecord_lib.h>
+#include <gnunet_identity_service.h>
#include <gnunet_namestore_service.h>
-#include <gnunet_gns_service.h>
#define GNUNET_CREDENTIAL_MAX_LENGTH 255
@@ -157,7 +158,7 @@ struct DelegationSetQueueEntry
*/
struct DelegationSetQueueEntry *prev;
- /**
+ /**
* GNS handle
*/
struct GNUNET_GNS_LookupRequest *lookup_request;
@@ -216,7 +217,6 @@ struct DelegationSetQueueEntry
* The delegation chain entry
*/
struct DelegationChainEntry *delegation_chain_entry;
-
};
@@ -320,7 +320,6 @@ struct VerifyRequestHandle
* Collect task
*/
struct GNUNET_SCHEDULER_Task *collect_next_task;
-
};
@@ -359,20 +358,14 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
if (NULL == ds_entry)
return;
- for (dq_entry = ds_entry->queue_entries_head;
- NULL != dq_entry;
- dq_entry = ds_entry->queue_entries_head)
- {
+ for (dq_entry = ds_entry->queue_entries_head; NULL != dq_entry;
+ dq_entry = ds_entry->queue_entries_head) {
GNUNET_CONTAINER_DLL_remove (ds_entry->queue_entries_head,
- ds_entry->queue_entries_tail,
- dq_entry);
- for (child = dq_entry->set_entries_head;
- NULL != child;
- child = dq_entry->set_entries_head)
- {
+ ds_entry->queue_entries_tail, dq_entry);
+ for (child = dq_entry->set_entries_head; NULL != child;
+ child = dq_entry->set_entries_head) {
GNUNET_CONTAINER_DLL_remove (dq_entry->set_entries_head,
- dq_entry->set_entries_tail,
- child);
+ dq_entry->set_entries_tail, child);
cleanup_delegation_set (child);
}
GNUNET_free (dq_entry);
@@ -382,13 +375,11 @@ cleanup_delegation_set (struct DelegationSetQueueEntry *ds_entry)
GNUNET_free_non_null (ds_entry->issuer_attribute);
GNUNET_free_non_null (ds_entry->unresolved_attribute_delegation);
GNUNET_free_non_null (ds_entry->attr_trailer);
- if (NULL != ds_entry->lookup_request)
- {
+ if (NULL != ds_entry->lookup_request) {
GNUNET_GNS_lookup_cancel (ds_entry->lookup_request);
ds_entry->lookup_request = NULL;
}
- if (NULL != ds_entry->delegation_chain_entry)
- {
+ if (NULL != ds_entry->delegation_chain_entry) {
GNUNET_free_non_null (ds_entry->delegation_chain_entry->subject_attribute);
GNUNET_free_non_null (ds_entry->delegation_chain_entry->issuer_attribute);
GNUNET_free (ds_entry->delegation_chain_entry);
@@ -400,21 +391,16 @@ static void
cleanup_handle (struct VerifyRequestHandle *vrh)
{
struct CredentialRecordEntry *cr_entry;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Cleaning up...\n");
- if (NULL != vrh->lookup_request)
- {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up...\n");
+ if (NULL != vrh->lookup_request) {
GNUNET_GNS_lookup_cancel (vrh->lookup_request);
vrh->lookup_request = NULL;
}
cleanup_delegation_set (vrh->root_set);
GNUNET_free_non_null (vrh->issuer_attribute);
- for (cr_entry = vrh->cred_chain_head;
- NULL != vrh->cred_chain_head;
- cr_entry = vrh->cred_chain_head)
- {
- GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
- vrh->cred_chain_tail,
+ for (cr_entry = vrh->cred_chain_head; NULL != vrh->cred_chain_head;
+ cr_entry = vrh->cred_chain_head) {
+ GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, vrh->cred_chain_tail,
cr_entry);
GNUNET_free_non_null (cr_entry->credential);
GNUNET_free (cr_entry);
@@ -427,39 +413,29 @@ shutdown_task (void *cls)
{
struct VerifyRequestHandle *vrh;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Shutting down!\n");
-
- while (NULL != (vrh = vrh_head))
- {
- //CREDENTIAL_resolver_lookup_cancel (clh->lookup);
- GNUNET_CONTAINER_DLL_remove (vrh_head,
- vrh_tail,
- vrh);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down!\n");
+
+ while (NULL != (vrh = vrh_head)) {
+ // CREDENTIAL_resolver_lookup_cancel (clh->lookup);
+ GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
cleanup_handle (vrh);
}
- if (NULL != gns)
- {
+ if (NULL != gns) {
GNUNET_GNS_disconnect (gns);
gns = NULL;
}
- if (NULL != namestore)
- {
+ if (NULL != namestore) {
GNUNET_NAMESTORE_disconnect (namestore);
namestore = NULL;
}
- if (NULL != statistics)
- {
- GNUNET_STATISTICS_destroy (statistics,
- GNUNET_NO);
+ if (NULL != statistics) {
+ GNUNET_STATISTICS_destroy (statistics, GNUNET_NO);
statistics = NULL;
}
-
}
-
static void
send_lookup_response (struct VerifyRequestHandle *vrh)
{
@@ -472,21 +448,18 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
struct CredentialRecordEntry *tmp;
size_t size;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending response\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending response\n");
dce = vrh->delegation_chain_head;
- for (uint32_t i=0;i<vrh->delegation_chain_size;i++)
- {
+ for (uint32_t i = 0; i < vrh->delegation_chain_size; i++) {
dd[i].issuer_key = dce->issuer_key;
dd[i].subject_key = dce->subject_key;
dd[i].issuer_attribute = dce->issuer_attribute;
- dd[i].issuer_attribute_len = strlen (dce->issuer_attribute)+1;
+ dd[i].issuer_attribute_len = strlen (dce->issuer_attribute) + 1;
dd[i].subject_attribute_len = 0;
dd[i].subject_attribute = NULL;
- if (NULL != dce->subject_attribute)
- {
+ if (NULL != dce->subject_attribute) {
dd[i].subject_attribute = dce->subject_attribute;
- dd[i].subject_attribute_len = strlen(dce->subject_attribute)+1;
+ dd[i].subject_attribute_len = strlen (dce->subject_attribute) + 1;
}
dce = dce->next;
}
@@ -494,17 +467,14 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
/**
* Remove all credentials not needed
*/
- for (cd = vrh->cred_chain_head; NULL != cd;)
- {
- if (cd->refcount > 0)
- {
+ for (cd = vrh->cred_chain_head; NULL != cd;) {
+ if (cd->refcount > 0) {
cd = cd->next;
continue;
}
tmp = cd;
cd = cd->next;
- GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head,
- vrh->cred_chain_tail,
+ GNUNET_CONTAINER_DLL_remove (vrh->cred_chain_head, vrh->cred_chain_tail,
tmp);
GNUNET_free (tmp->credential);
GNUNET_free (tmp);
@@ -516,24 +486,21 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
* Append at the end of rmsg
*/
cd = vrh->cred_chain_head;
- for (uint32_t i=0;i<vrh->cred_chain_size;i++)
- {
+ for (uint32_t i = 0; i < vrh->cred_chain_size; i++) {
cred[i].issuer_key = cd->credential->issuer_key;
cred[i].subject_key = cd->credential->subject_key;
- cred[i].issuer_attribute_len = strlen(cd->credential->issuer_attribute)+1;
+ cred[i].issuer_attribute_len =
+ strlen (cd->credential->issuer_attribute) + 1;
cred[i].issuer_attribute = cd->credential->issuer_attribute;
cred[i].expiration = cd->credential->expiration;
cred[i].signature = cd->credential->signature;
cd = cd->next;
}
- size = GNUNET_CREDENTIAL_delegation_chain_get_size (vrh->delegation_chain_size,
- dd,
- vrh->cred_chain_size,
- cred);
- env = GNUNET_MQ_msg_extra (rmsg,
- size,
+ size = GNUNET_CREDENTIAL_delegation_chain_get_size (
+ vrh->delegation_chain_size, dd, vrh->cred_chain_size, cred);
+ env = GNUNET_MQ_msg_extra (rmsg, size,
GNUNET_MESSAGE_TYPE_CREDENTIAL_VERIFY_RESULT);
- //Assign id so that client can find associated request
+ // Assign id so that client can find associated request
rmsg->id = vrh->request_id;
rmsg->d_count = htonl (vrh->delegation_chain_size);
rmsg->c_count = htonl (vrh->cred_chain_size);
@@ -543,28 +510,21 @@ send_lookup_response (struct VerifyRequestHandle *vrh)
else
rmsg->cred_found = htonl (GNUNET_NO);
- GNUNET_assert (-1 !=
- GNUNET_CREDENTIAL_delegation_chain_serialize (vrh->delegation_chain_size,
- dd,
- vrh->cred_chain_size,
- cred,
- size,
- (char*)&rmsg[1]));
+ GNUNET_assert (-1 != GNUNET_CREDENTIAL_delegation_chain_serialize (
+ vrh->delegation_chain_size, dd, vrh->cred_chain_size,
+ cred, size, (char *)&rmsg[1]));
- GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq(vrh->client),
- env);
+ GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (vrh->client), env);
GNUNET_CONTAINER_DLL_remove (vrh_head, vrh_tail, vrh);
- cleanup_handle(vrh);
+ cleanup_handle (vrh);
- GNUNET_STATISTICS_update (statistics,
- "Completed verifications", 1,
+ GNUNET_STATISTICS_update (statistics, "Completed verifications", 1,
GNUNET_NO);
}
static void
-backward_resolution (void* cls,
- uint32_t rd_count,
+backward_resolution (void *cls, uint32_t rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
@@ -583,97 +543,83 @@ backward_resolution (void* cls,
current_set->lookup_request = NULL;
vrh = current_set->handle;
vrh->pending_lookups--;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got %d attrs\n", rd_count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got %d attrs\n", rd_count);
// Each OR
- for (uint32_t i=0; i < rd_count; i++)
- {
+ for (uint32_t i = 0; i < rd_count; i++) {
if (GNUNET_GNSRECORD_TYPE_ATTRIBUTE != rd[i].record_type)
continue;
sets = rd[i].data;
- struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets->set_count)];
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found new attribute delegation with %d sets. Creating new Job...\n",
- ntohl (sets->set_count));
-
- if (GNUNET_OK !=GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll(sets->data_size),
- (const char*)&sets[1],
- ntohl(sets->set_count),
- set))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to deserialize!\n");
+ struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets->set_count)];
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_DEBUG,
+ "Found new attribute delegation with %d sets. Creating new Job...\n",
+ ntohl (sets->set_count));
+
+ if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (
+ GNUNET_ntohll (sets->data_size),
+ (const char *)&sets[1], ntohl (sets->set_count),
+ set)) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to deserialize!\n");
continue;
}
dq_entry = GNUNET_new (struct DelegationQueueEntry);
- dq_entry->required_solutions = ntohl(sets->set_count);
+ dq_entry->required_solutions = ntohl (sets->set_count);
dq_entry->parent_set = current_set;
GNUNET_CONTAINER_DLL_insert (current_set->queue_entries_head,
- current_set->queue_entries_tail,
- dq_entry);
+ current_set->queue_entries_tail, dq_entry);
// Each AND
- for (uint32_t j=0; j<ntohl(sets->set_count); j++)
- {
+ for (uint32_t j = 0; j < ntohl (sets->set_count); j++) {
ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
- if (NULL != current_set->attr_trailer)
- {
- if (0 == set[j].subject_attribute_len)
- {
- GNUNET_asprintf (&expanded_attr,
- "%s",
- current_set->attr_trailer);
+ if (NULL != current_set->attr_trailer) {
+ if (0 == set[j].subject_attribute_len) {
+ GNUNET_asprintf (&expanded_attr, "%s", current_set->attr_trailer);
} else {
- GNUNET_asprintf (&expanded_attr,
- "%s.%s",
- set[j].subject_attribute,
+ GNUNET_asprintf (&expanded_attr, "%s.%s", set[j].subject_attribute,
current_set->attr_trailer);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Expanded to %s\n", expanded_attr);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Expanded to %s\n", expanded_attr);
ds_entry->unresolved_attribute_delegation = expanded_attr;
} else {
- if (0 != set[j].subject_attribute_len)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not Expanding %s\n", set[j].subject_attribute);
- ds_entry->unresolved_attribute_delegation = GNUNET_strdup (set[j].subject_attribute);
+ if (0 != set[j].subject_attribute_len) {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not Expanding %s\n",
+ set[j].subject_attribute);
+ ds_entry->unresolved_attribute_delegation =
+ GNUNET_strdup (set[j].subject_attribute);
}
}
- //Add a credential chain entry
- ds_entry->delegation_chain_entry = GNUNET_new (struct DelegationChainEntry);
+ // Add a credential chain entry
+ ds_entry->delegation_chain_entry =
+ GNUNET_new (struct DelegationChainEntry);
ds_entry->delegation_chain_entry->subject_key = set[j].subject_key;
ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
- GNUNET_memcpy (ds_entry->issuer_key,
- &set[j].subject_key,
+ GNUNET_memcpy (ds_entry->issuer_key, &set[j].subject_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
if (0 < set[j].subject_attribute_len)
- ds_entry->delegation_chain_entry->subject_attribute = GNUNET_strdup (set[j].subject_attribute);
+ ds_entry->delegation_chain_entry->subject_attribute =
+ GNUNET_strdup (set[j].subject_attribute);
ds_entry->delegation_chain_entry->issuer_key = *current_set->issuer_key;
- ds_entry->delegation_chain_entry->issuer_attribute = GNUNET_strdup (current_set->lookup_attribute);
+ ds_entry->delegation_chain_entry->issuer_attribute =
+ GNUNET_strdup (current_set->lookup_attribute);
- ds_entry->parent_queue_entry = dq_entry; //current_delegation;
+ ds_entry->parent_queue_entry = dq_entry; // current_delegation;
GNUNET_CONTAINER_DLL_insert (dq_entry->set_entries_head,
- dq_entry->set_entries_tail,
- ds_entry);
+ dq_entry->set_entries_tail, ds_entry);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking for cred match\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking for cred match\n");
/**
* Check if this delegation already matches one of our credentials
*/
- for(cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
- cred_pointer = cred_pointer->next)
- {
- if(0 != memcmp (&set->subject_key,
- &cred_pointer->credential->issuer_key,
- sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)))
+ for (cred_pointer = vrh->cred_chain_head; cred_pointer != NULL;
+ cred_pointer = cred_pointer->next) {
+ if (0 != memcmp (&set->subject_key,
+ &cred_pointer->credential->issuer_key,
+ sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
continue;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking if %s matches %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Checking if %s matches %s\n",
ds_entry->unresolved_attribute_delegation,
cred_pointer->credential->issuer_attribute);
@@ -681,17 +627,13 @@ backward_resolution (void* cls,
cred_pointer->credential->issuer_attribute))
continue;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Found issuer\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found issuer\n");
cred_pointer->refcount++;
- //Backtrack
- for (tmp_set = ds_entry;
- NULL != tmp_set->parent_queue_entry;
- tmp_set = tmp_set->parent_queue_entry->parent_set)
- {
+ // Backtrack
+ for (tmp_set = ds_entry; NULL != tmp_set->parent_queue_entry;
+ tmp_set = tmp_set->parent_queue_entry->parent_set) {
tmp_set->parent_queue_entry->required_solutions--;
- if (NULL != tmp_set->delegation_chain_entry)
- {
+ if (NULL != tmp_set->delegation_chain_entry) {
vrh->delegation_chain_size++;
GNUNET_CONTAINER_DLL_insert (vrh->delegation_chain_head,
vrh->delegation_chain_tail,
@@ -701,73 +643,59 @@ backward_resolution (void* cls,
break;
}
- if (NULL == tmp_set->parent_queue_entry)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All solutions found\n");
- //Found match
+ if (NULL == tmp_set->parent_queue_entry) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "All solutions found\n");
+ // Found match
send_lookup_response (vrh);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not all solutions found yet.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Not all solutions found yet.\n");
continue;
-
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Building new lookup request from %s\n",
ds_entry->unresolved_attribute_delegation);
- //Continue with backward resolution
- char issuer_attribute_name[strlen (ds_entry->unresolved_attribute_delegation)+1];
- strcpy (issuer_attribute_name,
- ds_entry->unresolved_attribute_delegation);
+ // Continue with backward resolution
+ char issuer_attribute_name
+ [strlen (ds_entry->unresolved_attribute_delegation) + 1];
+ strcpy (issuer_attribute_name, ds_entry->unresolved_attribute_delegation);
char *next_attr = strtok (issuer_attribute_name, ".");
- if (NULL == next_attr)
- {
+ if (NULL == next_attr) {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to parse next attribute\n");
continue;
}
- GNUNET_asprintf (&lookup_attribute,
- "%s.gnu",
- next_attr);
- GNUNET_asprintf (&ds_entry->lookup_attribute,
- "%s",
- next_attr);
- if (strlen (next_attr) == strlen (ds_entry->unresolved_attribute_delegation))
- {
+ GNUNET_asprintf (&lookup_attribute, "%s", next_attr);
+ GNUNET_asprintf (&ds_entry->lookup_attribute, "%s", next_attr);
+ if (strlen (next_attr) ==
+ strlen (ds_entry->unresolved_attribute_delegation)) {
ds_entry->attr_trailer = NULL;
} else {
next_attr += strlen (next_attr) + 1;
ds_entry->attr_trailer = GNUNET_strdup (next_attr);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looking up %s\n", ds_entry->lookup_attribute);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up %s\n",
+ ds_entry->lookup_attribute);
if (NULL != ds_entry->attr_trailer)
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s still to go...\n", ds_entry->attr_trailer);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s still to go...\n",
+ ds_entry->attr_trailer);
vrh->pending_lookups++;
ds_entry->handle = vrh;
- ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
- lookup_attribute,
- ds_entry->issuer_key, //issuer_key,
- GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
- GNUNET_GNS_LO_DEFAULT,
- &backward_resolution,
- ds_entry);
+ ds_entry->lookup_request = GNUNET_GNS_lookup (
+ gns, lookup_attribute,
+ ds_entry->issuer_key, // issuer_key,
+ GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT,
+ &backward_resolution, ds_entry);
GNUNET_free (lookup_attribute);
}
}
- if(0 == vrh->pending_lookups)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "We are all out of attributes...\n");
+ if (0 == vrh->pending_lookups) {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "We are all out of attributes...\n");
send_lookup_response (vrh);
return;
-
}
}
@@ -778,89 +706,76 @@ backward_resolution (void* cls,
* @param cls the closure (our client lookup handle)
*/
static void
-delegation_chain_resolution_start (void* cls)
+delegation_chain_resolution_start (void *cls)
{
struct VerifyRequestHandle *vrh = cls;
struct DelegationSetQueueEntry *ds_entry;
struct CredentialRecordEntry *cr_entry;
vrh->lookup_request = NULL;
- if (0 == vrh->cred_chain_size)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No credentials found\n");
+ if (0 == vrh->cred_chain_size) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No credentials found\n");
send_lookup_response (vrh);
return;
}
- for (cr_entry = vrh->cred_chain_head; cr_entry != NULL; cr_entry = cr_entry->next)
- {
- if (0 != memcmp (&cr_entry->credential->issuer_key,
- &vrh->issuer_key,
+ for (cr_entry = vrh->cred_chain_head; cr_entry != NULL;
+ cr_entry = cr_entry->next) {
+ if (0 != memcmp (&cr_entry->credential->issuer_key, &vrh->issuer_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
continue;
- if (0 != strcmp (cr_entry->credential->issuer_attribute, vrh->issuer_attribute))
+ if (0 !=
+ strcmp (cr_entry->credential->issuer_attribute, vrh->issuer_attribute))
continue;
cr_entry->refcount++;
- //Found match prematurely
+ // Found match prematurely
send_lookup_response (vrh);
return;
-
}
/**
* Check for attributes from the issuer and follow the chain
* till you get the required subject's attributes
*/
- char issuer_attribute_name[strlen (vrh->issuer_attribute) + strlen (".gnu") + 1];
- strcpy (issuer_attribute_name,
- vrh->issuer_attribute);
- strcpy (issuer_attribute_name + strlen (vrh->issuer_attribute),
- ".gnu");
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Looking up %s\n", issuer_attribute_name);
+ char issuer_attribute_name[strlen (vrh->issuer_attribute) + 1];
+ strcpy (issuer_attribute_name, vrh->issuer_attribute);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up %s\n",
+ issuer_attribute_name);
ds_entry = GNUNET_new (struct DelegationSetQueueEntry);
ds_entry->issuer_key = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPublicKey);
- GNUNET_memcpy (ds_entry->issuer_key,
- &vrh->issuer_key,
+ GNUNET_memcpy (ds_entry->issuer_key, &vrh->issuer_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
ds_entry->issuer_attribute = GNUNET_strdup (vrh->issuer_attribute);
ds_entry->handle = vrh;
ds_entry->lookup_attribute = GNUNET_strdup (vrh->issuer_attribute);
vrh->root_set = ds_entry;
vrh->pending_lookups = 1;
- //Start with backward resolution
- ds_entry->lookup_request = GNUNET_GNS_lookup (gns,
- issuer_attribute_name,
- &vrh->issuer_key, //issuer_key,
- GNUNET_GNSRECORD_TYPE_ATTRIBUTE,
- GNUNET_GNS_LO_DEFAULT,
- &backward_resolution,
- ds_entry);
+ // Start with backward resolution
+ ds_entry->lookup_request =
+ GNUNET_GNS_lookup (gns, issuer_attribute_name,
+ &vrh->issuer_key, // issuer_key,
+ GNUNET_GNSRECORD_TYPE_ATTRIBUTE, GNUNET_GNS_LO_DEFAULT,
+ &backward_resolution, ds_entry);
}
static int
-check_verify (void *cls,
- const struct VerifyMessage *v_msg)
+check_verify (void *cls, const struct VerifyMessage *v_msg)
{
size_t msg_size;
- const char* attr;
+ const char *attr;
msg_size = ntohs (v_msg->header.size);
- if (msg_size < sizeof (struct VerifyMessage))
- {
+ if (msg_size < sizeof (struct VerifyMessage)) {
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
- {
+ if (ntohs (v_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) {
GNUNET_break (0);
return GNUNET_SYSERR;
}
- attr = (const char *) &v_msg[1];
+ attr = (const char *)&v_msg[1];
- if ( strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)
- {
+ if (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) {
GNUNET_break (0);
return GNUNET_SYSERR;
}
@@ -868,8 +783,7 @@ check_verify (void *cls,
}
static void
-handle_verify (void *cls,
- const struct VerifyMessage *v_msg)
+handle_verify (void *cls, const struct VerifyMessage *v_msg)
{
struct VerifyRequestHandle *vrh;
struct GNUNET_SERVICE_Client *client = cls;
@@ -882,13 +796,10 @@ handle_verify (void *cls,
char *credential_data;
const char *utf_in;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received VERIFY message\n");
- utf_in = (const char *) &v_msg[1];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received VERIFY message\n");
+ utf_in = (const char *)&v_msg[1];
GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
- GNUNET_memcpy (issuer_attribute,
- attr,
- ntohs (v_msg->issuer_attribute_len));
+ GNUNET_memcpy (issuer_attribute, attr, ntohs (v_msg->issuer_attribute_len));
issuer_attribute[ntohs (v_msg->issuer_attribute_len)] = '\0';
vrh = GNUNET_new (struct VerifyRequestHandle);
GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
@@ -897,10 +808,9 @@ handle_verify (void *cls,
vrh->issuer_key = v_msg->issuer_key;
vrh->subject_key = v_msg->subject_key;
vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
- if (0 == strlen (issuer_attribute))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No issuer attribute provided!\n");
+ GNUNET_SERVICE_client_continue (vrh->client);
+ if (0 == strlen (issuer_attribute)) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
send_lookup_response (vrh);
return;
}
@@ -908,43 +818,36 @@ handle_verify (void *cls,
* First, collect credentials
* TODO: cleanup!
*/
- credentials_count = ntohl(v_msg->c_count);
- credential_data_size = ntohs (v_msg->header.size)
- - sizeof (struct VerifyMessage)
- - ntohs (v_msg->issuer_attribute_len)
- - 1;
+ credentials_count = ntohl (v_msg->c_count);
+ credential_data_size = ntohs (v_msg->header.size) -
+ sizeof (struct VerifyMessage) -
+ ntohs (v_msg->issuer_attribute_len) - 1;
struct GNUNET_CREDENTIAL_Credential credentials[credentials_count];
- credential_data = (char*)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1;
- if (GNUNET_OK != GNUNET_CREDENTIAL_credentials_deserialize (credential_data_size,
- credential_data,
- credentials_count,
- credentials))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Cannot deserialize credentials!\n");
+ credential_data = (char *)&v_msg[1] + ntohs (v_msg->issuer_attribute_len) + 1;
+ if (GNUNET_OK != GNUNET_CREDENTIAL_credentials_deserialize (
+ credential_data_size, credential_data, credentials_count,
+ credentials)) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot deserialize credentials!\n");
send_lookup_response (vrh);
return;
}
- for (uint32_t i=0;i<credentials_count;i++) {
+ for (uint32_t i = 0; i < credentials_count; i++) {
cr_entry = GNUNET_new (struct CredentialRecordEntry);
- cr_entry->credential = GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) +
- credentials[i].issuer_attribute_len);
- GNUNET_memcpy (cr_entry->credential,
- &credentials[i],
+ cr_entry->credential =
+ GNUNET_malloc (sizeof (struct GNUNET_CREDENTIAL_Credential) +
+ credentials[i].issuer_attribute_len);
+ GNUNET_memcpy (cr_entry->credential, &credentials[i],
sizeof (struct GNUNET_CREDENTIAL_Credential));
- GNUNET_memcpy (&cr_entry->credential[1],
- credentials[i].issuer_attribute,
+ GNUNET_memcpy (&cr_entry->credential[1], credentials[i].issuer_attribute,
credentials[i].issuer_attribute_len);
- cr_entry->credential->issuer_attribute = (char*)&cr_entry->credential[1];
+ cr_entry->credential->issuer_attribute = (char *)&cr_entry->credential[1];
GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
- vrh->cred_chain_tail,
- cr_entry);
+ vrh->cred_chain_tail, cr_entry);
vrh->cred_chain_size++;
}
delegation_chain_resolution_start (vrh);
-
}
static void
@@ -963,16 +866,14 @@ collect_next (void *cls)
struct VerifyRequestHandle *vrh = cls;
vrh->collect_next_task = NULL;
GNUNET_assert (NULL != vrh->cred_collection_iter);
- GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter,
- 1);
+ GNUNET_NAMESTORE_zone_iterator_next (vrh->cred_collection_iter, 1);
}
static void
handle_cred_collection_cb (void *cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
- const char *label,
- unsigned int rd_count,
+ const char *label, unsigned int rd_count,
const struct GNUNET_GNSRECORD_Data *rd)
{
struct VerifyRequestHandle *vrh = cls;
@@ -981,43 +882,36 @@ handle_cred_collection_cb (void *cls,
int cred_record_count;
cred_record_count = 0;
- for (uint32_t i=0; i < rd_count; i++)
- {
+ for (uint32_t i = 0; i < rd_count; i++) {
if (GNUNET_GNSRECORD_TYPE_CREDENTIAL != rd[i].record_type)
continue;
cred_record_count++;
- crd = GNUNET_CREDENTIAL_credential_deserialize (rd[i].data,
- rd[i].data_size);
- if (NULL == crd)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Invalid credential found\n");
+ crd =
+ GNUNET_CREDENTIAL_credential_deserialize (rd[i].data, rd[i].data_size);
+ if (NULL == crd) {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credential found\n");
continue;
}
cr_entry = GNUNET_new (struct CredentialRecordEntry);
cr_entry->credential = crd;
GNUNET_CONTAINER_DLL_insert_tail (vrh->cred_chain_head,
- vrh->cred_chain_tail,
- cr_entry);
+ vrh->cred_chain_tail, cr_entry);
vrh->cred_chain_size++;
}
- vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next,
- vrh);
+ vrh->collect_next_task = GNUNET_SCHEDULER_add_now (&collect_next, vrh);
}
static void
handle_cred_collection_finished_cb (void *cls)
{
struct VerifyRequestHandle *vrh = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Done collecting credentials.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Done collecting credentials.\n");
vrh->cred_collection_iter = NULL;
delegation_chain_resolution_start (vrh);
}
static void
-handle_collect (void *cls,
- const struct CollectMessage *c_msg)
+handle_collect (void *cls, const struct CollectMessage *c_msg)
{
char attr[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
char issuer_attribute[GNUNET_CREDENTIAL_MAX_LENGTH + 1];
@@ -1026,71 +920,57 @@ handle_collect (void *cls,
char *attrptr = attr;
const char *utf_in;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received COLLECT message\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received COLLECT message\n");
- utf_in = (const char *) &c_msg[1];
+ utf_in = (const char *)&c_msg[1];
GNUNET_STRINGS_utf8_tolower (utf_in, attrptr);
- GNUNET_memcpy (issuer_attribute,
- attr,
- ntohs (c_msg->issuer_attribute_len));
+ GNUNET_memcpy (issuer_attribute, attr, ntohs (c_msg->issuer_attribute_len));
issuer_attribute[ntohs (c_msg->issuer_attribute_len)] = '\0';
vrh = GNUNET_new (struct VerifyRequestHandle);
GNUNET_CONTAINER_DLL_insert (vrh_head, vrh_tail, vrh);
vrh->client = client;
vrh->request_id = c_msg->id;
vrh->issuer_key = c_msg->issuer_key;
- GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key,
- &vrh->subject_key);
+ GNUNET_CRYPTO_ecdsa_key_get_public (&c_msg->subject_key, &vrh->subject_key);
vrh->issuer_attribute = GNUNET_strdup (issuer_attribute);
- if (0 == strlen (issuer_attribute))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No issuer attribute provided!\n");
+ if (0 == strlen (issuer_attribute)) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No issuer attribute provided!\n");
send_lookup_response (vrh);
return;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Getting credentials for subject\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting credentials for subject\n");
/**
* First, get attribute from subject
*/
- vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start (namestore,
- &c_msg->subject_key,
- &handle_cred_collection_error_cb,
- vrh,
- &handle_cred_collection_cb,
- vrh,
- &handle_cred_collection_finished_cb,
- vrh);
+ vrh->cred_collection_iter = GNUNET_NAMESTORE_zone_iteration_start (
+ namestore, &c_msg->subject_key, &handle_cred_collection_error_cb, vrh,
+ &handle_cred_collection_cb, vrh, &handle_cred_collection_finished_cb,
+ vrh);
+ GNUNET_SERVICE_client_continue (vrh->client);
}
static int
-check_collect (void *cls,
- const struct CollectMessage *c_msg)
+check_collect (void *cls, const struct CollectMessage *c_msg)
{
size_t msg_size;
- const char* attr;
+ const char *attr;
msg_size = ntohs (c_msg->header.size);
- if (msg_size < sizeof (struct CollectMessage))
- {
+ if (msg_size < sizeof (struct CollectMessage)) {
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH)
- {
+ if (ntohs (c_msg->issuer_attribute_len) > GNUNET_CREDENTIAL_MAX_LENGTH) {
GNUNET_break (0);
return GNUNET_SYSERR;
}
- attr = (const char *) &c_msg[1];
+ attr = (const char *)&c_msg[1];
- if ( ('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) ||
- (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH) )
- {
+ if (('\0' != attr[msg_size - sizeof (struct CollectMessage) - 1]) ||
+ (strlen (attr) > GNUNET_CREDENTIAL_MAX_LENGTH)) {
GNUNET_break (0);
return GNUNET_SYSERR;
}
@@ -1098,23 +978,17 @@ check_collect (void *cls,
}
static void
-client_disconnect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
+client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client,
void *app_ctx)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected\n",
- client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p disconnected\n", client);
}
static void *
-client_connect_cb (void *cls,
- struct GNUNET_SERVICE_Client *client,
+client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client,
struct GNUNET_MQ_Handle *mq)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client %p connected\n",
- client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", client);
return client;
}
@@ -1126,22 +1000,17 @@ client_connect_cb (void *cls,
* @param handle service handle
*/
static void
-run (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *c,
+run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c,
struct GNUNET_SERVICE_Handle *handle)
{
gns = GNUNET_GNS_connect (c);
- if (NULL == gns)
- {
- fprintf (stderr,
- _("Failed to connect to GNS\n"));
+ if (NULL == gns) {
+ fprintf (stderr, _ ("Failed to connect to GNS\n"));
}
namestore = GNUNET_NAMESTORE_connect (c);
- if (NULL == namestore)
- {
- fprintf (stderr,
- _("Failed to connect to namestore\n"));
+ if (NULL == namestore) {
+ fprintf (stderr, _ ("Failed to connect to namestore\n"));
}
statistics = GNUNET_STATISTICS_create ("credential", c);
@@ -1152,21 +1021,13 @@ run (void *cls,
/**
* Define "main" method using service macro
*/
-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());
+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 ());
/* end of gnunet-service-credential.c */
diff --git a/src/credential/plugin_gnsrecord_credential.c b/src/credential/plugin_gnsrecord_credential.c
index 1e1c0ff92..c03f2b3e4 100644
--- a/src/credential/plugin_gnsrecord_credential.c
+++ b/src/credential/plugin_gnsrecord_credential.c
@@ -11,7 +11,7 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -23,16 +23,16 @@
* @brief gnsrecord plugin to provide the API for CREDENTIAL records
* @author Martin Schanzenbach
*/
-
#include "platform.h"
+
#include "gnunet_util_lib.h"
-#include "gnunet_gnsrecord_lib.h"
+
+#include "credential_misc.h"
+#include "credential_serialization.h"
#include "gnunet_credential_service.h"
+#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gnsrecord_plugin.h"
#include "gnunet_signatures.h"
-#include "credential_serialization.h"
-#include "credential_misc.h"
-
/**
* Convert the 'value' of a record to a string.
*
@@ -43,18 +43,14 @@
* @return NULL on error, otherwise human-readable representation of the value
*/
static char *
-credential_value_to_string (void *cls,
- uint32_t type,
- const void *data,
- size_t data_size)
+credential_value_to_string (void *cls, uint32_t type, const void *data,
+ size_t data_size)
{
const char *cdata;
- switch (type)
- {
- case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
- {
+ switch (type) {
+ case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
struct GNUNET_CREDENTIAL_DelegationRecord sets;
char *attr_str;
char *subject_pkey;
@@ -62,49 +58,33 @@ credential_value_to_string (void *cls,
int i;
if (data_size < sizeof (struct GNUNET_CREDENTIAL_DelegationRecord))
return NULL; /* malformed */
- GNUNET_memcpy (&sets,
- data,
- sizeof (sets));
+ GNUNET_memcpy (&sets, data, sizeof (sets));
cdata = data;
- struct GNUNET_CREDENTIAL_DelegationSet set[ntohl(sets.set_count)];
- if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (GNUNET_ntohll (sets.data_size),
- &cdata[sizeof (sets)],
- ntohl (sets.set_count),
- set))
+ struct GNUNET_CREDENTIAL_DelegationSet set[ntohl (sets.set_count)];
+ if (GNUNET_OK != GNUNET_CREDENTIAL_delegation_set_deserialize (
+ GNUNET_ntohll (sets.data_size), &cdata[sizeof (sets)],
+ ntohl (sets.set_count), set))
return NULL;
- for (i=0;i<ntohl(sets.set_count);i++)
- {
- subject_pkey = GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%d len attr\n", set[i].subject_attribute_len);
- if (0 == set[i].subject_attribute_len)
- {
- if (0 == i)
- {
- GNUNET_asprintf (&attr_str,
- "%s",
- subject_pkey);
+ for (i = 0; i < ntohl (sets.set_count); i++) {
+ subject_pkey =
+ GNUNET_CRYPTO_ecdsa_public_key_to_string (&set[i].subject_key);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d len attr\n",
+ set[i].subject_attribute_len);
+ if (0 == set[i].subject_attribute_len) {
+ if (0 == i) {
+ GNUNET_asprintf (&attr_str, "%s", subject_pkey);
} else {
- GNUNET_asprintf (&tmp_str,
- "%s,%s",
- attr_str,
- subject_pkey);
+ GNUNET_asprintf (&tmp_str, "%s,%s", attr_str, subject_pkey);
GNUNET_free (attr_str);
attr_str = tmp_str;
}
} else {
- if (0 == i)
- {
- GNUNET_asprintf (&attr_str,
- "%s %s",
- subject_pkey,
+ if (0 == i) {
+ GNUNET_asprintf (&attr_str, "%s %s", subject_pkey,
set[i].subject_attribute);
} else {
- GNUNET_asprintf (&tmp_str,
- "%s,%s %s",
- attr_str,
- subject_pkey,
+ GNUNET_asprintf (&tmp_str, "%s,%s %s", attr_str, subject_pkey,
set[i].subject_attribute);
GNUNET_free (attr_str);
attr_str = tmp_str;
@@ -113,24 +93,21 @@ credential_value_to_string (void *cls,
GNUNET_free (subject_pkey);
}
return attr_str;
- }
- case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
- {
- struct GNUNET_CREDENTIAL_Credential *cred;
- char *cred_str;
-
- cred = GNUNET_CREDENTIAL_credential_deserialize (data,
- data_size);
- cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
- GNUNET_free (cred);
- return cred_str;
- }
- case GNUNET_GNSRECORD_TYPE_POLICY:
- {
- return GNUNET_strndup (data,data_size);
- }
- default:
- return NULL;
+ }
+ case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
+ struct GNUNET_CREDENTIAL_Credential *cred;
+ char *cred_str;
+
+ cred = GNUNET_CREDENTIAL_credential_deserialize (data, data_size);
+ cred_str = GNUNET_CREDENTIAL_credential_to_string (cred);
+ GNUNET_free (cred);
+ return cred_str;
+ }
+ case GNUNET_GNSRECORD_TYPE_POLICY: {
+ return GNUNET_strndup (data, data_size);
+ }
+ default:
+ return NULL;
}
}
@@ -147,123 +124,99 @@ credential_value_to_string (void *cls,
* @return #GNUNET_OK on success
*/
static int
-credential_string_to_value (void *cls,
- uint32_t type,
- const char *s,
- void **data,
- size_t *data_size)
+credential_string_to_value (void *cls, uint32_t type, const char *s,
+ void **data, size_t *data_size)
{
if (NULL == s)
return GNUNET_SYSERR;
- switch (type)
- {
- case GNUNET_GNSRECORD_TYPE_ATTRIBUTE:
- {
- struct GNUNET_CREDENTIAL_DelegationRecord *sets;
- char attr_str[253 + 1];
- char subject_pkey[52 + 1];
- char *token;
- char *tmp_str;
- int matches = 0;
- int entries;
- size_t tmp_data_size;
- int i;
-
- tmp_str = GNUNET_strdup (s);
- token = strtok (tmp_str, ",");
- entries = 0;
- tmp_data_size = 0;
- *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord);
- while (NULL != token)
- {
- matches = SSCANF (token,
- "%s %s",
- subject_pkey,
- attr_str);
- if (0 == matches)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("Unable to parse ATTR record string `%s'\n"),
- s);
- GNUNET_free (tmp_str);
- return GNUNET_SYSERR;
- }
- if (1 == matches) {
- tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet);
- } else if (2 == matches) {
- tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet) + strlen (attr_str) + 1;
- }
- entries++;
- token = strtok (NULL, ",");
- }
- GNUNET_free (tmp_str);
- tmp_str = GNUNET_strdup (s);
- token = strtok (tmp_str, ",");
- if (NULL == token)
- {
- GNUNET_free (tmp_str);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Malformed string %s\n", s);
- return GNUNET_SYSERR;
- }
- struct GNUNET_CREDENTIAL_DelegationSet set[entries];
- for (i=0;i<entries;i++)
- {
- matches = SSCANF (token,
- "%s %s",
- subject_pkey,
- attr_str);
- GNUNET_CRYPTO_ecdsa_public_key_from_string (subject_pkey,
- strlen (subject_pkey),
- &set[i].subject_key);
- if (2 == matches) {
- set[i].subject_attribute_len = strlen (attr_str) + 1;
- set[i].subject_attribute = GNUNET_strdup (attr_str);
- }
- token = strtok (NULL , ",");
- }
- tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries,
- set);
-
- if (-1 == tmp_data_size)
- {
- GNUNET_free (tmp_str);
- return GNUNET_SYSERR;
- }
- *data_size += tmp_data_size;
- *data = sets = GNUNET_malloc (*data_size);
- GNUNET_CREDENTIAL_delegation_set_serialize (entries,
- set,
- tmp_data_size,
- (char*)&sets[1]);
- for (i=0;i<entries;i++)
- {
- if (0 != set[i].subject_attribute_len)
- GNUNET_free ((char*)set[i].subject_attribute);
- }
- sets->set_count = htonl (entries);
- sets->data_size = GNUNET_htonll (tmp_data_size);
+ switch (type) {
+ case GNUNET_GNSRECORD_TYPE_ATTRIBUTE: {
+ struct GNUNET_CREDENTIAL_DelegationRecord *sets;
+ char attr_str[253 + 1];
+ char subject_pkey[52 + 1];
+ char *token;
+ char *tmp_str;
+ int matches = 0;
+ int entries;
+ size_t tmp_data_size;
+ int i;
+ tmp_str = GNUNET_strdup (s);
+ token = strtok (tmp_str, ",");
+ entries = 0;
+ tmp_data_size = 0;
+ *data_size = sizeof (struct GNUNET_CREDENTIAL_DelegationRecord);
+ while (NULL != token) {
+ matches = SSCANF (token, "%s %s", subject_pkey, attr_str);
+ if (0 == matches) {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Unable to parse ATTR record string `%s'\n"), s);
GNUNET_free (tmp_str);
- return GNUNET_OK;
+ return GNUNET_SYSERR;
}
- case GNUNET_GNSRECORD_TYPE_CREDENTIAL:
- {
- struct GNUNET_CREDENTIAL_Credential *cred;
- cred = GNUNET_CREDENTIAL_credential_from_string (s);
-
- *data_size = GNUNET_CREDENTIAL_credential_serialize (cred,
- (char**)data);
- return GNUNET_OK;
+ if (1 == matches) {
+ tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet);
+ } else if (2 == matches) {
+ tmp_data_size += sizeof (struct GNUNET_CREDENTIAL_DelegationRecordSet) +
+ strlen (attr_str) + 1;
}
- case GNUNET_GNSRECORD_TYPE_POLICY:
- {
- *data_size = strlen (s);
- *data = GNUNET_strdup (s);
- return GNUNET_OK;
+ entries++;
+ token = strtok (NULL, ",");
+ }
+ GNUNET_free (tmp_str);
+ tmp_str = GNUNET_strdup (s);
+ token = strtok (tmp_str, ",");
+ if (NULL == token) {
+ GNUNET_free (tmp_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed string %s\n", s);
+ return GNUNET_SYSERR;
+ }
+ struct GNUNET_CREDENTIAL_DelegationSet set[entries];
+ memset (set, 0, sizeof (struct GNUNET_CREDENTIAL_DelegationSet) * entries);
+ for (i = 0; i < entries; i++) {
+ matches = SSCANF (token, "%s %s", subject_pkey, attr_str);
+ GNUNET_CRYPTO_ecdsa_public_key_from_string (
+ subject_pkey, strlen (subject_pkey), &set[i].subject_key);
+ if (2 == matches) {
+ set[i].subject_attribute_len = strlen (attr_str) + 1;
+ set[i].subject_attribute = GNUNET_strdup (attr_str);
}
- default:
+ token = strtok (NULL, ",");
+ }
+ tmp_data_size = GNUNET_CREDENTIAL_delegation_set_get_size (entries, set);
+
+ if (-1 == tmp_data_size) {
+ GNUNET_free (tmp_str);
return GNUNET_SYSERR;
+ }
+ *data_size += tmp_data_size;
+ *data = sets = GNUNET_malloc (*data_size);
+ GNUNET_CREDENTIAL_delegation_set_serialize (entries, set, tmp_data_size,
+ (char *)&sets[1]);
+ for (i = 0; i < entries; i++) {
+ if (0 != set[i].subject_attribute_len)
+ GNUNET_free ((char *)set[i].subject_attribute);
+ }
+ sets->set_count = htonl (entries);
+ sets->data_size = GNUNET_htonll (tmp_data_size);
+
+ GNUNET_free (tmp_str);
+ return GNUNET_OK;
+ }
+ case GNUNET_GNSRECORD_TYPE_CREDENTIAL: {
+ struct GNUNET_CREDENTIAL_Credential *cred;
+ cred = GNUNET_CREDENTIAL_credential_from_string (s);
+
+ *data_size = GNUNET_CREDENTIAL_credential_serialize (cred, (char **)data);
+ return GNUNET_OK;
+ }
+ case GNUNET_GNSRECORD_TYPE_POLICY: {
+ *data_size = strlen (s);
+ *data = GNUNET_strdup (s);
+ return GNUNET_OK;
+ }
+ default:
+ return GNUNET_SYSERR;
}
}
@@ -272,15 +225,14 @@ credential_string_to_value (void *cls,
* Mapping of record type numbers to human-readable
* record type names.
*/
-static struct {
+static struct
+{
const char *name;
uint32_t number;
-} name_map[] = {
- { "CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL },
- { "ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE },
- { "POLICY", GNUNET_GNSRECORD_TYPE_POLICY },
- { NULL, UINT32_MAX }
-};
+} name_map[] = {{"CRED", GNUNET_GNSRECORD_TYPE_CREDENTIAL},
+ {"ATTR", GNUNET_GNSRECORD_TYPE_ATTRIBUTE},
+ {"POLICY", GNUNET_GNSRECORD_TYPE_POLICY},
+ {NULL, UINT32_MAX}};
/**
@@ -291,14 +243,13 @@ static struct {
* @return corresponding number, UINT32_MAX on error
*/
static uint32_t
-credential_typename_to_number (void *cls,
- const char *gns_typename)
+credential_typename_to_number (void *cls, const char *gns_typename)
{
unsigned int i;
- i=0;
- while ( (name_map[i].name != NULL) &&
- (0 != strcasecmp (gns_typename, name_map[i].name)) )
+ i = 0;
+ while ((name_map[i].name != NULL) &&
+ (0 != strcasecmp (gns_typename, name_map[i].name)))
i++;
return name_map[i].number;
}
@@ -312,14 +263,12 @@ credential_typename_to_number (void *cls,
* @return corresponding typestring, NULL on error
*/
static const char *
-credential_number_to_typename (void *cls,
- uint32_t type)
+credential_number_to_typename (void *cls, uint32_t type)
{
unsigned int i;
- i=0;
- while ( (name_map[i].name != NULL) &&
- (type != name_map[i].number) )
+ i = 0;
+ while ((name_map[i].name != NULL) && (type != name_map[i].number))
i++;
return name_map[i].name;
}
diff --git a/src/credential/test_credential_lookup.conf b/src/credential/test_credential_lookup.conf
index 39f68c944..cebe71b04 100644
--- a/src/credential/test_credential_lookup.conf
+++ b/src/credential/test_credential_lookup.conf
@@ -11,7 +11,7 @@ PLUGINS =
[credential]
START_ON_DEMAND = YES
-PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/credlog
+#PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/credlog
[rest]
PREFIX = valgrind --leak-check=full --track-origins=yes --log-file=$GNUNET_TMP/restlog
diff --git a/src/credential/test_credential_verify_and.sh b/src/credential/test_credential_verify_and.sh
index 7e8dc1392..fa0ab34e1 100755
--- a/src/credential/test_credential_verify_and.sh
+++ b/src/credential/test_credential_verify_and.sh
@@ -17,9 +17,8 @@ rm -rf `gnunet-config -c test_credential_lookup.conf -s PATHS -o GNUNET_HOME -f`
# (1) Service.user -> GNU.project.member
# (2) GNU.project -> GNUnet
-# (3) GNUnet.member -> GNUnet.developer
-# (4) GNUnet.member -> GNUnet.user
-# (5) GNUnet.developer -> Alice
+# (3) GNUnet.member -> GNUnet.developer and GNUnet.user
+# (4) GNUnet.developer -> Alice
which timeout > /dev/null 2>&1 && DO_TIMEOUT="timeout 30"
@@ -40,14 +39,15 @@ MEMBER_ATTR="member"
DEVELOPER_ATTR="developer"
DEV_ATTR="developer"
TEST_CREDENTIAL="mygnunetcreds"
-
+set -x
# (1) A service assigns the attribute "user" to all entities that have been assigned "member" by entities that werde assigned "project" from GNU
gnunet-namestore -p -z service -a -n $USER_ATTR -t ATTR -V "$GNU_KEY $GNU_PROJECT_ATTR.$MEMBER_ATTR" -e 5m -c test_credential_lookup.conf
# (2) GNU recognized GNUnet as a GNU project and delegates the "project" attribute
gnunet-namestore -p -z gnu -a -n $GNU_PROJECT_ATTR -t ATTR -V "$GNUNET_KEY" -e 5m -c test_credential_lookup.conf
-# (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also assigned "developer" or "user"
+# (3+4) GNUnet assigns the attribute "member" to all entities gnunet has also
+# assigned "developer" and "user"
gnunet-namestore -p -z gnunet -a -n $MEMBER_ATTR -t ATTR -V "$GNUNET_KEY $DEVELOPER_ATTR,$GNUNET_KEY $USER_ATTR" -e 5m -c test_credential_lookup.conf
# (5) GNUnet issues Alice the credential "developer"