summaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-06 16:52:39 +0200
committerMartin Schanzenbach <mschanzenbach@posteo.de>2020-08-06 16:52:39 +0200
commit079beb884ac4236f993736c664660c3892560c9b (patch)
tree44697c4f22dc0ec92c56da4c3e05c1d87ce6b608 /src/reclaim
parent6ab14a20690a499ad32e3f2ad448d64d4e6b65fc (diff)
-fix serialization
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/Makefile.am11
-rw-r--r--src/reclaim/gnunet-service-reclaim.c15
-rw-r--r--src/reclaim/gnunet-service-reclaim_tickets.c12
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c10
-rw-r--r--src/reclaim/reclaim_api.c5
-rw-r--r--src/reclaim/reclaim_attribute.c51
-rw-r--r--src/reclaim/reclaim_attribute.h20
-rw-r--r--src/reclaim/test_reclaim_attribute.c51
8 files changed, 130 insertions, 45 deletions
diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index a9829c47e..9b75c11aa 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -152,11 +152,20 @@ gnunet_reclaim_LDADD = \
$(top_builddir)/src/identity/libgnunetidentity.la \
$(GN_LIBINTL)
+test_reclaim_attribute_SOURCES = \
+ test_reclaim_attribute.c
+test_reclaim_attribute_LDADD = \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ libgnunetreclaim.la \
+ $(GN_LIBINTL)
+
check_SCRIPTS = \
test_reclaim_attribute.sh \
test_reclaim_issue.sh \
test_reclaim_consume.sh
-# test_reclaim_revoke.sh
+
+check_PROGRAMS = \
+ test_reclaim_attribute
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index 0cd8c10a5..84afd482e 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -732,6 +732,7 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
struct TicketIssueOperation *tio;
struct IdpClient *idp = cls;
struct GNUNET_RECLAIM_AttributeList *attrs;
+ struct GNUNET_RECLAIM_AttributeListEntry *le;
size_t attrs_len;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received ISSUE_TICKET message\n");
@@ -739,6 +740,10 @@ handle_issue_ticket_message (void *cls, const struct IssueTicketMessage *im)
attrs_len = ntohs (im->attr_len);
attrs = GNUNET_RECLAIM_attribute_list_deserialize ((char *) &im[1],
attrs_len);
+ for (le = attrs->list_head; NULL != le; le = le->next)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "List entry: %s\n", le->attribute->name);
+
tio->r_id = ntohl (im->id);
tio->client = idp;
GNUNET_CONTAINER_DLL_insert (idp->issue_op_head, idp->issue_op_tail, tio);
@@ -1053,8 +1058,9 @@ handle_attribute_store_message (void *cls,
data_len = ntohs (sam->attr_len);
ash = GNUNET_new (struct AttributeStoreHandle);
- ash->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1],
- data_len);
+ GNUNET_RECLAIM_attribute_deserialize ((char *) &sam[1],
+ data_len,
+ &ash->claim);
ash->r_id = ntohl (sam->id);
ash->identity = sam->identity;
@@ -1548,8 +1554,9 @@ handle_attribute_delete_message (void *cls,
data_len = ntohs (dam->attr_len);
adh = GNUNET_new (struct AttributeDeleteHandle);
- adh->claim = GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1],
- data_len);
+ GNUNET_RECLAIM_attribute_deserialize ((char *) &dam[1],
+ data_len,
+ &adh->claim);
adh->attest = NULL;
adh->r_id = ntohl (dam->id);
diff --git a/src/reclaim/gnunet-service-reclaim_tickets.c b/src/reclaim/gnunet-service-reclaim_tickets.c
index 7e6b07514..af01d8ec7 100644
--- a/src/reclaim/gnunet-service-reclaim_tickets.c
+++ b/src/reclaim/gnunet-service-reclaim_tickets.c
@@ -694,8 +694,9 @@ rvk_move_attr_cb (void *cls,
{
/** find a new place for this attribute **/
struct GNUNET_RECLAIM_Attribute *claim;
- claim = GNUNET_RECLAIM_attribute_deserialize (rd[i].data,
- rd[i].data_size);
+ GNUNET_RECLAIM_attribute_deserialize (rd[i].data,
+ rd[i].data_size,
+ &claim);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Attribute to update: Name=%s\n",
claim->name);
@@ -1029,8 +1030,8 @@ process_parallel_lookup_result (void *cls,
if (GNUNET_GNSRECORD_TYPE_RECLAIM_ATTRIBUTE == rd[i].record_type)
{
attr_le = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
- attr_le->attribute =
- GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size);
+ GNUNET_RECLAIM_attribute_deserialize (rd[i].data, rd[i].data_size,
+ &attr_le->attribute);
GNUNET_CONTAINER_DLL_insert (cth->attrs->list_head,
cth->attrs->list_tail,
attr_le);
@@ -1298,6 +1299,9 @@ issue_ticket (struct TicketIssueHandle *ih)
i = 0;
for (le = ih->attrs->list_head; NULL != le; le = le->next)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Adding list entry: %s\n", le->attribute->name);
+
attrs_record[i].data = &le->attribute->id;
attrs_record[i].data_size = sizeof(le->attribute->id);
attrs_record[i].expiration_time = ticket_refresh_interval.rel_value_us;
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 06e1b0061..3221c1cce 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -1041,10 +1041,15 @@ oidc_attest_collect_finished_cb (void *cls)
{
struct RequestHandle *handle = cls;
struct GNUNET_RECLAIM_AttributeList *merged_list;
+ struct GNUNET_RECLAIM_AttributeListEntry *le_m;
handle->attest_it = NULL;
merged_list = attribute_list_merge (handle->attr_idtoken_list,
handle->attr_userinfo_list);
+ for (le_m = merged_list->list_head; NULL != le_m; le_m = le_m->next)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "List Attibute in ticket to issue: %s\n",
+ le_m->attribute->name);
handle->idp_op = GNUNET_RECLAIM_ticket_issue (idp,
&handle->priv_key,
&handle->oidc->client_pkey,
@@ -2131,13 +2136,12 @@ consume_ticket (void *cls,
char *result_str;
handle->idp_op = NULL;
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attr: %s\n", attr->name);
if (NULL == identity)
{
result_str = OIDC_generate_userinfo (&handle->ticket.identity,
handle->attr_userinfo_list,
handle->attests_list);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Userinfo: %s\n", result_str);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Userinfo: %s\n", result_str);
resp = GNUNET_REST_create_response (result_str);
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result_str);
@@ -2156,6 +2160,8 @@ consume_ticket (void *cls,
GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head,
handle->attr_userinfo_list->list_tail,
ale);
+ if (NULL == attest)
+ return;
for (atle = handle->attests_list->list_head; NULL != atle; atle = atle->next)
{
if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&atle->attestation->id,
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index d73241a6f..b432b4f2a 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -747,7 +747,8 @@ handle_attribute_result (void *cls, const struct AttributeResultMessage *msg)
{
struct GNUNET_RECLAIM_Attribute *attr;
- attr = GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len);
+ GNUNET_RECLAIM_attribute_deserialize ((char *) &msg[1], attr_len,
+ &attr);
if (NULL != it)
{
if (NULL != it->proc)
@@ -1573,7 +1574,7 @@ GNUNET_RECLAIM_ticket_consume (
if (NULL != h->mq)
GNUNET_MQ_send_copy (h->mq, op->env);
else
- reconnect(h);
+ reconnect (h);
return op;
}
diff --git a/src/reclaim/reclaim_attribute.c b/src/reclaim/reclaim_attribute.c
index 05bdc1ac6..971bfce23 100644
--- a/src/reclaim/reclaim_attribute.c
+++ b/src/reclaim/reclaim_attribute.c
@@ -306,7 +306,6 @@ GNUNET_RECLAIM_attribute_list_serialize_get_size (
{
GNUNET_assert (NULL != ale->attribute);
len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute);
- len += sizeof(struct GNUNET_RECLAIM_AttributeListEntry);
}
return len;
}
@@ -355,27 +354,28 @@ GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size)
struct GNUNET_RECLAIM_AttributeListEntry *ale;
size_t attr_len;
const char *read_ptr;
+ size_t left = data_size;
al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
- if (data_size < sizeof(struct Attribute) + sizeof(struct
- GNUNET_RECLAIM_AttributeListEntry))
+ if (data_size < sizeof(struct Attribute))
return al;
read_ptr = data;
- while (((data + data_size) - read_ptr) >= sizeof(struct Attribute))
+ while (left >= sizeof(struct Attribute))
{
ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
- ale->attribute =
+ attr_len =
GNUNET_RECLAIM_attribute_deserialize (read_ptr,
- data_size - (read_ptr - data));
- if (NULL == ale->attribute)
+ left,
+ &ale->attribute);
+ if (-1 == attr_len)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to deserialize malformed attribute.\n");
GNUNET_free (ale);
return al;
}
+ left -= attr_len;
GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale);
- attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute);
read_ptr += attr_len;
}
return al;
@@ -503,17 +503,18 @@ GNUNET_RECLAIM_attribute_serialize (
*
* @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
*/
-struct GNUNET_RECLAIM_Attribute *
-GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size)
+ssize_t
+GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size,
+ struct GNUNET_RECLAIM_Attribute **attr)
{
- struct GNUNET_RECLAIM_Attribute *attr;
struct Attribute *attr_ser;
+ struct GNUNET_RECLAIM_Attribute *attribute;
size_t data_len;
size_t name_len;
char *write_ptr;
if (data_size < sizeof(struct Attribute))
- return NULL;
+ return -1;
attr_ser = (struct Attribute *) data;
data_len = ntohs (attr_ser->data_size);
@@ -522,25 +523,27 @@ GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Buffer too small to deserialize\n");
- return NULL;
+ return -1;
}
- attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute)
+ attribute = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute)
+ data_len + name_len + 1);
- attr->type = ntohs (attr_ser->attribute_type);
- attr->flag = ntohl (attr_ser->attribute_flag);
- attr->id = attr_ser->attribute_id;
- attr->attestation = attr_ser->attestation_id;
- attr->data_size = data_len;
+ attribute->type = ntohs (attr_ser->attribute_type);
+ attribute->flag = ntohl (attr_ser->attribute_flag);
+ attribute->id = attr_ser->attribute_id;
+ attribute->attestation = attr_ser->attestation_id;
+ attribute->data_size = data_len;
- write_ptr = (char *) &attr[1];
+ write_ptr = (char *) &attribute[1];
GNUNET_memcpy (write_ptr, &attr_ser[1], name_len);
write_ptr[name_len] = '\0';
- attr->name = write_ptr;
+ attribute->name = write_ptr;
write_ptr += name_len + 1;
- GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size);
- attr->data = write_ptr;
- return attr;
+ GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len,
+ attribute->data_size);
+ *attr = attribute;
+ attribute->data = write_ptr;
+ return sizeof(struct Attribute) + data_len + name_len;
}
diff --git a/src/reclaim/reclaim_attribute.h b/src/reclaim/reclaim_attribute.h
index e54b210b9..203c88a34 100644
--- a/src/reclaim/reclaim_attribute.h
+++ b/src/reclaim/reclaim_attribute.h
@@ -28,6 +28,8 @@
#include "gnunet_reclaim_service.h"
+GNUNET_NETWORK_STRUCT_BEGIN
+
/**
* Serialized claim
*/
@@ -36,12 +38,12 @@ struct Attribute
/**
* Attribute type
*/
- uint32_t attribute_type;
+ uint32_t attribute_type GNUNET_PACKED;
/**
* Attribute flag
*/
- uint32_t attribute_flag;
+ uint32_t attribute_flag GNUNET_PACKED;
/**
* Attribute ID
@@ -56,12 +58,12 @@ struct Attribute
/**
* Name length
*/
- uint32_t name_len;
+ uint32_t name_len GNUNET_PACKED;
/**
* Data size
*/
- uint32_t data_size;
+ uint32_t data_size GNUNET_PACKED;
// followed by data_size Attribute value data
};
@@ -74,12 +76,12 @@ struct Attestation
/**
* Attestation type
*/
- uint32_t attestation_type;
+ uint32_t attestation_type GNUNET_PACKED;
/**
* Attestation flag
*/
- uint32_t attestation_flag;
+ uint32_t attestation_flag GNUNET_PACKED;
/**
* Attestation ID
@@ -89,14 +91,16 @@ struct Attestation
/**
* Name length
*/
- uint32_t name_len;
+ uint32_t name_len GNUNET_PACKED;
/**
* Data size
*/
- uint32_t data_size;
+ uint32_t data_size GNUNET_PACKED;
// followed by data_size Attestation value data
};
+GNUNET_NETWORK_STRUCT_BEGIN
+
#endif
diff --git a/src/reclaim/test_reclaim_attribute.c b/src/reclaim/test_reclaim_attribute.c
new file mode 100644
index 000000000..f71d86b56
--- /dev/null
+++ b/src/reclaim/test_reclaim_attribute.c
@@ -0,0 +1,51 @@
+#include "platform.h"
+#include "gnunet_common.h"
+#include "gnunet_reclaim_lib.h"
+#include "gnunet_container_lib.h"
+
+int
+main (int argc, char *argv[])
+{
+ struct GNUNET_RECLAIM_AttributeList *al;
+ struct GNUNET_RECLAIM_AttributeList *al_two;
+ struct GNUNET_RECLAIM_AttributeListEntry *ale;
+ struct GNUNET_RECLAIM_Attribute *attr;
+ char attrname[100];
+ char attrdata[100];
+ size_t ser_len_claimed;
+ size_t ser_len_actual;
+ ssize_t deser_len;
+ char *ser_data;
+ int count = 0;
+
+ al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
+ for (int i = 0; i < 12; i++)
+ {
+ memset (attrname, 0, 100);
+ memset (attrdata, 0, 100);
+ sprintf (attrname, "attr%d", i);
+ sprintf (attrdata, "%d", i);
+ ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
+ ale->attribute = GNUNET_RECLAIM_attribute_new (attrname,
+ &GNUNET_RECLAIM_ID_ZERO,
+ GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,
+ attrdata,
+ strlen (attrdata));
+ GNUNET_CONTAINER_DLL_insert (al->list_head,
+ al->list_tail,
+ ale);
+ }
+ ser_len_claimed = GNUNET_RECLAIM_attribute_list_serialize_get_size (al);
+ ser_data = GNUNET_malloc (ser_len_claimed);
+ ser_len_actual = GNUNET_RECLAIM_attribute_list_serialize (al,
+ ser_data);
+ GNUNET_assert (ser_len_claimed == ser_len_actual);
+ al_two = GNUNET_RECLAIM_attribute_list_deserialize (ser_data,
+ ser_len_actual);
+ for (ale = al_two->list_head; NULL != ale; ale = ale->next)
+ count++;
+ GNUNET_assert (12 == count);
+ //GNUNET_assert (-1 != deser_len);
+ GNUNET_free (ser_data);
+ GNUNET_RECLAIM_attribute_list_destroy (al);
+}