From 24a0b84d503375bf66b5df932cd18631cc88cf8d Mon Sep 17 00:00:00 2001 From: "Schanzenbach, Martin" Date: Mon, 4 Dec 2017 17:39:36 +0100 Subject: [PATCH] -start jwt --- src/identity-attribute/Makefile.am | 3 +- .../jwt.c | 30 ++++++++++++------- src/include/gnunet_identity_attribute_lib.h | 14 +++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) rename src/{identity-provider => identity-attribute}/jwt.c (81%) diff --git a/src/identity-attribute/Makefile.am b/src/identity-attribute/Makefile.am index 583545344..b84ad3492 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 similarity index 81% rename from src/identity-provider/jwt.c rename to src/identity-attribute/jwt.c index c8bc67806..935e0a79d 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 @@ -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 a43b509da..4c765515b 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 -- 2.25.1