uint32_t
GNUNET_RECLAIM_attestation_typename_to_number (const char *typename);
+/**
+ * Convert an attestation type name to the corresponding number
+ *
+ * @param typename name to convert
+ * @return corresponding number, UINT32_MAX on error
+ */
+struct GNUNET_RECLAIM_AttributeList*
+GNUNET_RECLAIM_attestation_get_attributes (const struct GNUNET_RECLAIM_Attestation *attest);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
void *cls,
uint32_t type);
+/**
+ * Function called to convert a type number (i.e. 1) to the
+ * corresponding type string
+ *
+ * @param cls closure
+ * @param type number of a type to convert
+ * @return corresponding typestring, NULL on error
+ */
+typedef struct GNUNET_RECLAIM_AttributeList *(*GNUNET_RECLAIM_AttestationGetAttributesFunction) (
+ void *cls,
+ const struct GNUNET_RECLAIM_Attestation *attest);
+
/**
*/
GNUNET_RECLAIM_AttestationNumberToTypenameFunction number_to_typename;
+ /**
+ * Attesation attributes.
+ */
+ GNUNET_RECLAIM_AttestationGetAttributesFunction get_attributes;
+
+
};
*
* @param cls The callback closure
* @param identity The identity authoritative over the attributes
- * @param attr The attribute
+ * @param attestation The attestation
+ * @param attributes the parsed attributes
*/
typedef void (*GNUNET_RECLAIM_AttestationResult) (
void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
- const struct GNUNET_RECLAIM_Attestation *attestation);
+ const struct GNUNET_RECLAIM_Attestation *attestation,
+ const struct GNUNET_RECLAIM_AttributeList *attributes);
/**
plugin_reclaim_attestation_jwt.c
libgnunet_plugin_reclaim_attestation_jwt_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
+ libgnunetreclaimattribute.la \
+ -ljansson\
$(LTLIBINTL)
libgnunet_plugin_reclaim_attestation_jwt_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
#include "gnunet_util_lib.h"
#include "gnunet_reclaim_plugin.h"
#include <inttypes.h>
-
+#include <jansson.h>
/**
* Convert the 'value' of an attestation to a string.
return jwt_attest_name_map[i].name;
}
+/**
+ * Parse a JWT and return the respective claim value as Attribute
+ *
+ * @param attest the jwt attestation
+ * @param claim the name of the claim in the JWT
+ *
+ * @return a GNUNET_RECLAIM_Attribute, containing the new value
+ */
+struct GNUNET_RECLAIM_AttributeList *
+jwt_parse_attributes (void *cls,
+ const struct GNUNET_RECLAIM_Attestation *attest)
+{
+ char *jwt_string;
+ struct GNUNET_RECLAIM_AttributeList *attrs;
+ char delim[] = ".";
+ char *val_str = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
+ char *decoded_jwt;
+ json_t *json_val;
+ json_error_t *json_err = NULL;
+
+ if (GNUNET_RECLAIM_ATTESTATION_TYPE_JWT != attest->type)
+ return NULL;
+ attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
+
+ jwt_string = GNUNET_strdup (attest->data);
+ const char *jwt_body = strtok (jwt_string, delim);
+ jwt_body = strtok (NULL, delim);
+ GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
+ (void **) &decoded_jwt);
+ json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
+ const char *key;
+ json_t *value;
+ json_object_foreach (json_val, key, value) {
+ val_str = json_dumps (value, JSON_ENCODE_ANY);
+ GNUNET_RECLAIM_attribute_list_add (attrs,
+ key,
+ NULL,
+ GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,//FIXME
+ val_str,
+ strlen (val_str));
+ GNUNET_free (val_str);
+ }
+ GNUNET_free (jwt_string);
+ //FIXME needed??
+ return attrs;
+}
+
+
+
/**
* Entry point for the plugin.
api->string_to_value = &jwt_string_to_value;
api->typename_to_number = &jwt_typename_to_number;
api->number_to_typename = &jwt_number_to_typename;
+ api->get_attributes = &jwt_parse_attributes;
return api;
}
attestation->data = write_ptr;
return attestation;
}
+
+struct GNUNET_RECLAIM_AttributeList*
+GNUNET_RECLAIM_attestation_get_attributes (const struct GNUNET_RECLAIM_Attestation *attest)
+{
+ unsigned int i;
+ struct Plugin *plugin;
+ struct GNUNET_RECLAIM_AttributeList *ret;
+ init ();
+ for (i = 0; i < num_plugins; i++)
+ {
+ plugin = attest_plugins[i];
+ if (NULL !=
+ (ret = plugin->api->get_attributes (plugin->api->cls,
+ attest)))
+ return ret;
+ }
+ return NULL;
+}
attr->data_size);
attr_type = GNUNET_RECLAIM_attribute_number_to_typename (attr->type);
id = GNUNET_STRINGS_data_to_string_alloc (&attr->id, sizeof(attr->id));
- fprintf (stdout,
- "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
- attr->name,
- attr_str,
- attr_type,
- attr->flag,
- id);
+ if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation))
+ {
+ fprintf (stdout,
+ "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
+ attr->name,
+ attr_str,
+ attr_type,
+ attr->flag,
+ id);
+ }
+ else
+ {
+ fprintf (stdout,
+ "Name: %s; Value: %s (%s); Flag %u; ID: %s\n",
+ attr->name,
+ attr_str,
+ attr_type,
+ attr->flag,
+ id);
+
+ }
GNUNET_free (id);
}
GNUNET_RECLAIM_get_attributes_next (attr_iterator);
static void
attest_iter_cb (void *cls,
const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
- const struct GNUNET_RECLAIM_Attestation *attest)
+ const struct GNUNET_RECLAIM_Attestation *attest,
+ const struct GNUNET_RECLAIM_AttributeList *attrs)
{
char *attest_str;
char *id;
{
struct Iterator *ai = cls;
struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_RECLAIM_AttributeList *attrs;
+ struct GNUNET_RECLAIM_Attestation *att;
char *data_tmp;
+ char *attrs_size;
if ((rd_count != 1) ||
(GNUNET_GNSRECORD_TYPE_RECLAIM_ATTESTATION != rd->record_type))
GNUNET_NAMESTORE_zone_iterator_next (ai->ns_it, 1);
return;
}
+ att = GNUNET_RECLAIM_attestation_deserialize (rd->data,
+ rd->data_size);
+ attrs = GNUNET_RECLAIM_attestation_get_attributes (att);
+ attrs_size = GNUNET_RECLAIM_attribute_list_serialize_get_size (attrs);
struct AttestationResultMessage *arm;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found attestation under: %s\n",
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending ATTESTATION_RESULT message\n");
env = GNUNET_MQ_msg_extra (arm,
- rd->data_size,
+ rd->data_size + attrs_size,
GNUNET_MESSAGE_TYPE_RECLAIM_ATTESTATION_RESULT);
arm->id = htonl (ai->request_id);
arm->attestation_len = htons (rd->data_size);
GNUNET_CRYPTO_ecdsa_key_get_public (zone, &arm->identity);
data_tmp = (char *) &arm[1];
GNUNET_memcpy (data_tmp, rd->data, rd->data_size);
+ data_tmp += rd->data_size;
+ GNUNET_RECLAIM_attribute_list_serialize (attrs,
+ data_tmp);
+
GNUNET_MQ_send (ai->client->mq, env);
}
static void
oidc_attest_collect (void *cls,
const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
- const struct GNUNET_RECLAIM_Attestation *attest)
+ const struct GNUNET_RECLAIM_Attestation *attest,
+ const struct GNUNET_RECLAIM_AttributeList *attrs)
{
struct RequestHandle *handle = cls;
struct GNUNET_RECLAIM_AttributeListEntry *le;
static void
attest_collect (void *cls,
const struct GNUNET_CRYPTO_EcdsaPublicKey *identity,
- const struct GNUNET_RECLAIM_Attestation *attest)
+ const struct GNUNET_RECLAIM_Attestation *attest,
+ const struct GNUNET_RECLAIM_AttributeList *attrs)
{
struct RequestHandle *handle = cls;
json_t *attr_obj;
*/
uint16_t attestation_len GNUNET_PACKED;
+ /**
+ * Length of serialized attribute data
+ */
+ uint16_t attributes_len GNUNET_PACKED;
+
/**
* always zero (for alignment)
*/
static struct GNUNET_CRYPTO_EcdsaPrivateKey identity_dummy;
struct GNUNET_RECLAIM_Handle *h = cls;
struct GNUNET_RECLAIM_AttestationIterator *it;
+ struct GNUNET_RECLAIM_AttributeList *attrs;
struct GNUNET_RECLAIM_Operation *op;
size_t att_len;
+ size_t attrs_len;
uint32_t r_id = ntohl (msg->id);
att_len = ntohs (msg->attestation_len);
+ attrs_len = ntohs (msg->attributes_len);
LOG (GNUNET_ERROR_TYPE_DEBUG, "Processing attestation result.\n");
if (NULL != op)
{
if (NULL != op->at_cb)
- op->at_cb (op->cls, NULL, NULL);
+ op->at_cb (op->cls, NULL, NULL, NULL);
GNUNET_CONTAINER_DLL_remove (h->op_head, h->op_tail, op);
free_op (op);
}
{
struct GNUNET_RECLAIM_Attestation *att;
att = GNUNET_RECLAIM_attestation_deserialize ((char *) &msg[1], att_len);
+ char *read_ptr = ((char *) &msg[1]) + att_len;
+ attrs = GNUNET_RECLAIM_attribute_list_deserialize (read_ptr, attrs_len);
if (NULL != it)
{
if (NULL != it->proc)
- it->proc (it->proc_cls, &msg->identity, att);
+ it->proc (it->proc_cls, &msg->identity, att, attrs);
}
else if (NULL != op)
{
if (NULL != op->at_cb)
- op->at_cb (op->cls, &msg->identity, att);
+ op->at_cb (op->cls, &msg->identity, att, attrs);
}
GNUNET_free (att);
+ GNUNET_RECLAIM_attribute_list_destroy (attrs);
return;
}
GNUNET_assert (0);