aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/identity-attribute/Makefile.am3
-rw-r--r--src/identity-attribute/jwt.c (renamed from src/identity-provider/jwt.c)30
-rw-r--r--src/include/gnunet_identity_attribute_lib.h14
3 files changed, 35 insertions, 12 deletions
diff --git a/src/identity-attribute/Makefile.am b/src/identity-attribute/Makefile.am
index 5835453443..b84ad34926 100644
--- a/src/identity-attribute/Makefile.am
+++ b/src/identity-attribute/Makefile.am
@@ -20,7 +20,8 @@ lib_LTLIBRARIES = \
libgnunetidentityattribute.la
libgnunetidentityattribute_la_SOURCES = \
- identity_attribute.c
+ identity_attribute.c \
+ jwt.c
libgnunetidentityattribute_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
$(GN_LIBINTL)
diff --git a/src/identity-provider/jwt.c b/src/identity-attribute/jwt.c
index c8bc67806b..935e0a79d1 100644
--- a/src/identity-provider/jwt.c
+++ b/src/identity-attribute/jwt.c
@@ -26,7 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_signatures.h"
-#include "identity_attribute.h"
+#include "gnunet_identity_attribute_lib.h"
#include <jansson.h>
@@ -55,18 +55,20 @@ create_jwt_header(void)
}
/**
- * Create a JWT from a ticket and attributes
+ * Create a JWT from attributes
*
- * @param ticket the ticket
+ * @param sub_key the public of the subject
* @param attrs the attribute list
+ * @param priv_key the key used to sign the JWT
* @return a new base64-encoded JWT string.
*/
char*
-jwt_create (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
- const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key)
+GNUNET_IDENTITY_ATTRIBUTE_jwt_create_from_list (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
+ const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key)
{
- struct GNUNET_IDENTITY_PROVIDER_AttributeListEntry *le;
+ struct GNUNET_IDENTITY_ATTRIBUTE_ClaimListEntry *le;
+ struct GNUNET_CRYPTO_EcdsaPublicKey iss_key;
struct GNUNET_CRYPTO_EcdsaSignature signature;
struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
char* audience;
@@ -79,12 +81,14 @@ jwt_create (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
char* body_base64;
char* signature_target;
char* signature_base64;
+ char* attr_val_str;
json_t* body;
+ GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &iss_key);
/* TODO maybe we should use a local identity here */
- issuer = GNUNET_STRINGS_data_to_string_alloc (&ticket->identity,
+ issuer = GNUNET_STRINGS_data_to_string_alloc (&iss_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
- audience = GNUNET_STRINGS_data_to_string_alloc (&ticket->audience,
+ audience = GNUNET_STRINGS_data_to_string_alloc (sub_key,
sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
header = create_jwt_header ();
body = json_object ();
@@ -103,9 +107,13 @@ jwt_create (const struct GNUNET_IDENTITY_PROVIDER_Ticket *ticket,
* calls the Attribute plugins to create a
* json representation for its value
*/
+ attr_val_str = GNUNET_IDENTITY_ATTRIBUTE_value_to_string (le->claim->type,
+ le->claim->data,
+ le->claim->data_size);
json_object_set_new (body,
- le->attribute->name,
- json_string (le->attribute->data));
+ le->claim->name,
+ json_string (attr_val_str));
+ GNUNET_free (attr_val_str);
}
body_str = json_dumps (body, JSON_INDENT(0));
json_decref (body);
diff --git a/src/include/gnunet_identity_attribute_lib.h b/src/include/gnunet_identity_attribute_lib.h
index a43b509da4..4c765515b7 100644
--- a/src/include/gnunet_identity_attribute_lib.h
+++ b/src/include/gnunet_identity_attribute_lib.h
@@ -260,6 +260,20 @@ GNUNET_IDENTITY_ATTRIBUTE_value_to_string (uint32_t type,
const char*
GNUNET_IDENTITY_ATTRIBUTE_number_to_typename (uint32_t type);
+
+/**
+ * Create a JWT from attributes
+ *
+ * @param sub_key the public of the subject
+ * @param attrs the attribute list
+ * @param priv_key the key used to sign the JWT
+ * @return a new base64-encoded JWT string.
+ */
+char*
+GNUNET_IDENTITY_ATTRIBUTE_jwt_create_from_list (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
+ const struct GNUNET_IDENTITY_ATTRIBUTE_ClaimList *attrs,
+ const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv_key);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif