summaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/gnunet-service-reclaim.c4
-rw-r--r--src/reclaim/oidc_helper.c532
-rw-r--r--src/reclaim/oidc_helper.h39
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c823
-rw-r--r--src/reclaim/plugin_rest_reclaim.c296
-rw-r--r--src/reclaim/reclaim_api.c2
6 files changed, 962 insertions, 734 deletions
diff --git a/src/reclaim/gnunet-service-reclaim.c b/src/reclaim/gnunet-service-reclaim.c
index d4d44c3fc..0cd8c10a5 100644
--- a/src/reclaim/gnunet-service-reclaim.c
+++ b/src/reclaim/gnunet-service-reclaim.c
@@ -850,8 +850,8 @@ consume_result_cb (void *cls,
struct ConsumeTicketResultMessage *crm;
struct GNUNET_MQ_Envelope *env;
char *data_tmp;
- size_t attrs_len;
- size_t attests_len;
+ size_t attrs_len = 0;
+ size_t attests_len = 0;
if (GNUNET_OK != success)
{
diff --git a/src/reclaim/oidc_helper.c b/src/reclaim/oidc_helper.c
index ad2839200..9b5938c43 100644
--- a/src/reclaim/oidc_helper.c
+++ b/src/reclaim/oidc_helper.c
@@ -47,9 +47,9 @@ struct OIDC_Parameters
struct GNUNET_RECLAIM_Ticket ticket;
/**
- * The nonce
+ * The nonce length
*/
- uint32_t nonce GNUNET_PACKED;
+ uint32_t nonce_len GNUNET_PACKED;
/**
* The length of the PKCE code_challenge
@@ -69,6 +69,51 @@ struct OIDC_Parameters
GNUNET_NETWORK_STRUCT_END
+/**
+ * Standard claims represented by the "profile" scope in OIDC
+ */
+static char OIDC_profile_claims[14][32] = {
+ "name", "family_name", "given_name", "middle_name", "nickname",
+ "preferred_username", "profile", "picture", "website", "gender", "birthdate",
+ "zoneinfo", "locale", "updated_at"
+};
+
+/**
+ * Standard claims represented by the "email" scope in OIDC
+ */
+static char OIDC_email_claims[2][16] = {
+ "email", "email_verified"
+};
+
+/**
+ * Standard claims represented by the "phone" scope in OIDC
+ */
+static char OIDC_phone_claims[2][32] = {
+ "phone_number", "phone_number_verified"
+};
+
+/**
+ * Standard claims represented by the "address" scope in OIDC
+ */
+static char OIDC_address_claims[5][32] = {
+ "street_address", "locality", "region", "postal_code", "country"
+};
+
+static enum GNUNET_GenericReturnValue
+is_claim_in_address_scope (const char *claim)
+{
+ int i;
+ for (i = 0; i < 5; i++)
+ {
+ if (0 == strcmp (claim, OIDC_address_claims[i]))
+ {
+ return GNUNET_YES;
+ }
+ }
+ return GNUNET_NO;
+}
+
+
static char *
create_jwt_header (void)
{
@@ -109,49 +154,22 @@ fix_base64 (char *str)
replace_char (str, '/', '_');
}
-
-/**
- * Create a JWT from attributes
- *
- * @param aud_key the public of the audience
- * @param sub_key the public key of the subject
- * @param attrs the attribute list
- * @param expiration_time the validity of the token
- * @param secret_key the key used to sign the JWT
- * @return a new base64-encoded JWT string.
- */
-char *
-OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
- struct GNUNET_RECLAIM_AttributeList *attrs,
- struct GNUNET_RECLAIM_AttestationList *attests,
- const struct GNUNET_TIME_Relative *expiration_time,
- const char *nonce,
- const char *secret_key)
+static json_t*
+generate_userinfo_json(const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
+ struct GNUNET_RECLAIM_AttributeList *attrs,
+ struct GNUNET_RECLAIM_AttestationList *attests)
{
struct GNUNET_RECLAIM_AttributeListEntry *le;
struct GNUNET_RECLAIM_AttestationListEntry *ale;
- struct GNUNET_HashCode signature;
- struct GNUNET_TIME_Absolute exp_time;
- struct GNUNET_TIME_Absolute time_now;
- char *audience;
char *subject;
- char *header;
- char *body_str;
- char *aggr_names_str;
- char *aggr_sources_str;
char *source_name;
- char *result;
- char *header_base64;
- char *body_base64;
- char *signature_target;
- char *signature_base64;
char *attr_val_str;
char *attest_val_str;
json_t *body;
json_t *aggr_names;
json_t *aggr_sources;
json_t *aggr_sources_jwt;
+ json_t *addr_claim = NULL;
int num_attestations = 0;
for (le = attrs->list_head; NULL != le; le = le->next)
{
@@ -159,22 +177,10 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
num_attestations++;
}
- // iat REQUIRED time now
- time_now = GNUNET_TIME_absolute_get ();
- // exp REQUIRED time expired from config
- exp_time = GNUNET_TIME_absolute_add (time_now, *expiration_time);
- // auth_time only if max_age
- // nonce only if nonce
- // OPTIONAL acr,amr,azp
subject =
GNUNET_STRINGS_data_to_string_alloc (sub_key,
sizeof(struct
GNUNET_CRYPTO_EcdsaPublicKey));
- audience =
- GNUNET_STRINGS_data_to_string_alloc (aud_key,
- sizeof(struct
- GNUNET_CRYPTO_EcdsaPublicKey));
- header = create_jwt_header ();
body = json_object ();
aggr_names = json_object ();
aggr_sources = json_object ();
@@ -185,26 +191,7 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
json_object_set_new (body, "iss", json_string (SERVER_ADDRESS));
// sub REQUIRED public key identity, not exceed 255 ASCII length
json_object_set_new (body, "sub", json_string (subject));
- // aud REQUIRED public key client_id must be there
- json_object_set_new (body, "aud", json_string (audience));
- // iat
- json_object_set_new (body,
- "iat",
- json_integer (time_now.abs_value_us / (1000 * 1000)));
- // exp
- json_object_set_new (body,
- "exp",
- json_integer (exp_time.abs_value_us / (1000 * 1000)));
- // nbf
- json_object_set_new (body,
- "nbf",
- json_integer (time_now.abs_value_us / (1000 * 1000)));
- // nonce
- if (NULL != nonce)
- json_object_set_new (body, "nonce", json_string (nonce));
attest_val_str = NULL;
- aggr_names_str = NULL;
- aggr_sources_str = NULL;
source_name = NULL;
int i = 0;
for (ale = attests->list_head; NULL != ale; ale = ale->next)
@@ -236,8 +223,26 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
GNUNET_RECLAIM_attribute_value_to_string (le->attribute->type,
le->attribute->data,
le->attribute->data_size);
- json_object_set_new (body, le->attribute->name,
- json_string (attr_val_str));
+ /**
+ * There is this wierd quirk that the individual address claim(s) must be
+ * inside a JSON object of the "address" claim.
+ * FIXME: Possibly include formatted claim here
+ */
+ if (GNUNET_YES == is_claim_in_address_scope (le->attribute->name))
+ {
+ if (NULL == addr_claim)
+ {
+ addr_claim = json_object ();
+ }
+ json_object_set_new (addr_claim, le->attribute->name,
+ json_string (attr_val_str));
+
+ }
+ else
+ {
+ json_object_set_new (body, le->attribute->name,
+ json_string (attr_val_str));
+ }
GNUNET_free (attr_val_str);
}
else
@@ -262,21 +267,113 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
GNUNET_free (source_name);
}
}
+ if (NULL != addr_claim)
+ json_object_set_new (body, "address", addr_claim);
if (NULL != attest_val_str)
GNUNET_free (attest_val_str);
if (0 != i)
{
- aggr_names_str = json_dumps (aggr_names, JSON_INDENT (0) | JSON_COMPACT);
- aggr_sources_str = json_dumps (aggr_sources, JSON_INDENT (0)
- | JSON_COMPACT);
- json_object_set_new (body, "_claim_names", json_string (aggr_names_str));
- json_object_set_new (body, "_claim_sources", json_string (
- aggr_sources_str));
+ json_object_set_new (body, "_claim_names", aggr_names);
+ json_object_set_new (body, "_claim_sources", aggr_sources);
}
- json_decref (aggr_names);
- json_decref (aggr_sources);
+ return body;
+}
+
+/**
+ * Generate userinfo JSON as string
+ *
+ * @param sub_key the subject (user)
+ * @param attrs user attribute list
+ * @param attests user attribute attestation list (may be empty)
+ * @return Userinfo JSON
+ */
+char *
+OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
+ struct GNUNET_RECLAIM_AttributeList *attrs,
+ struct GNUNET_RECLAIM_AttestationList *attests)
+{
+ char *body_str;
+ json_t* body = generate_userinfo_json (sub_key,
+ attrs,
+ attests);
+ body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT);
+ json_decref (body);
+ return body_str;
+}
+
+
+/**
+ * Create a JWT from attributes
+ *
+ * @param aud_key the public of the audience
+ * @param sub_key the public key of the subject
+ * @param attrs the attribute list
+ * @param expiration_time the validity of the token
+ * @param secret_key the key used to sign the JWT
+ * @return a new base64-encoded JWT string.
+ */
+char *
+OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
+ const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
+ struct GNUNET_RECLAIM_AttributeList *attrs,
+ struct GNUNET_RECLAIM_AttestationList *attests,
+ const struct GNUNET_TIME_Relative *expiration_time,
+ const char *nonce,
+ const char *secret_key)
+{
+ struct GNUNET_HashCode signature;
+ struct GNUNET_TIME_Absolute exp_time;
+ struct GNUNET_TIME_Absolute time_now;
+ char *audience;
+ char *subject;
+ char *header;
+ char *body_str;
+ char *result;
+ char *header_base64;
+ char *body_base64;
+ char *signature_target;
+ char *signature_base64;
+ json_t *body;
+
+ body = generate_userinfo_json (sub_key,
+ attrs,
+ attests);
+ // iat REQUIRED time now
+ time_now = GNUNET_TIME_absolute_get ();
+ // exp REQUIRED time expired from config
+ exp_time = GNUNET_TIME_absolute_add (time_now, *expiration_time);
+ // auth_time only if max_age
+ // nonce only if nonce
+ // OPTIONAL acr,amr,azp
+ subject =
+ GNUNET_STRINGS_data_to_string_alloc (sub_key,
+ sizeof(struct
+ GNUNET_CRYPTO_EcdsaPublicKey));
+ audience =
+ GNUNET_STRINGS_data_to_string_alloc (aud_key,
+ sizeof(struct
+ GNUNET_CRYPTO_EcdsaPublicKey));
+ header = create_jwt_header ();
+
+ // aud REQUIRED public key client_id must be there
+ json_object_set_new (body, "aud", json_string (audience));
+ // iat
+ json_object_set_new (body,
+ "iat",
+ json_integer (time_now.abs_value_us / (1000 * 1000)));
+ // exp
+ json_object_set_new (body,
+ "exp",
+ json_integer (exp_time.abs_value_us / (1000 * 1000)));
+ // nbf
+ json_object_set_new (body,
+ "nbf",
+ json_integer (time_now.abs_value_us / (1000 * 1000)));
+ // nonce
+ if (NULL != nonce)
+ json_object_set_new (body, "nonce", json_string (nonce));
body_str = json_dumps (body, JSON_INDENT (0) | JSON_COMPACT);
json_decref (body);
@@ -315,10 +412,6 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
GNUNET_free (signature_target);
GNUNET_free (header);
GNUNET_free (body_str);
- if (NULL != aggr_sources_str)
- GNUNET_free (aggr_sources_str);
- if (NULL != aggr_names_str)
- GNUNET_free (aggr_names_str);
GNUNET_free (signature_base64);
GNUNET_free (body_base64);
GNUNET_free (header_base64);
@@ -326,89 +419,6 @@ OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
}
-static void
-derive_aes_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
- struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
- struct GNUNET_HashCode *key_material)
-{
- static const char ctx_key[] = "reclaim-aes-ctx-key";
- static const char ctx_iv[] = "reclaim-aes-ctx-iv";
-
- GNUNET_CRYPTO_kdf (key,
- sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey),
- ctx_key,
- strlen (ctx_key),
- key_material,
- sizeof(struct GNUNET_HashCode),
- NULL);
- GNUNET_CRYPTO_kdf (iv,
- sizeof(
- struct GNUNET_CRYPTO_SymmetricInitializationVector),
- ctx_iv,
- strlen (ctx_iv),
- key_material,
- sizeof(struct GNUNET_HashCode),
- NULL);
-}
-
-
-static void
-calculate_key_priv (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
- struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
- const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
- const struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_pub)
-{
- struct GNUNET_HashCode key_material;
-
- GNUNET_CRYPTO_ecdsa_ecdh (ecdsa_priv, ecdh_pub, &key_material);
- derive_aes_key (key, iv, &key_material);
-}
-
-
-static void
-calculate_key_pub (struct GNUNET_CRYPTO_SymmetricSessionKey *key,
- struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
- const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub,
- const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv)
-{
- struct GNUNET_HashCode key_material;
-
- GNUNET_CRYPTO_ecdh_ecdsa (ecdh_priv, ecdsa_pub, &key_material);
- derive_aes_key (key, iv, &key_material);
-}
-
-
-static void
-decrypt_payload (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
- const struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_pub,
- const char *ct,
- size_t ct_len,
- char *buf)
-{
- struct GNUNET_CRYPTO_SymmetricSessionKey key;
- struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
-
- calculate_key_priv (&key, &iv, ecdsa_priv, ecdh_pub);
- GNUNET_break (GNUNET_CRYPTO_symmetric_decrypt (ct, ct_len, &key, &iv, buf));
-}
-
-
-static void
-encrypt_payload (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub,
- const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdh_priv,
- const char *payload,
- size_t payload_len,
- char *buf)
-{
- struct GNUNET_CRYPTO_SymmetricSessionKey key;
- struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
-
- calculate_key_pub (&key, &iv, ecdsa_pub, ecdh_priv);
- GNUNET_break (
- GNUNET_CRYPTO_symmetric_encrypt (payload, payload_len, &key, &iv, buf));
-}
-
-
/**
* Builds an OIDC authorization code including
* a reclaim ticket and nonce
@@ -439,34 +449,21 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
size_t attr_list_len = 0;
size_t attests_list_len = 0;
size_t code_challenge_len = 0;
- uint32_t nonce;
- uint32_t nonce_tmp;
+ uint32_t nonce_len = 0;
struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
- struct GNUNET_CRYPTO_EcdhePrivateKey ecdh_priv;
- struct GNUNET_CRYPTO_EcdhePublicKey ecdh_pub;
/** PLAINTEXT **/
// Assign ticket
memset (&params, 0, sizeof(params));
params.ticket = *ticket;
// Assign nonce
- nonce = 0;
payload_len = sizeof(struct OIDC_Parameters);
if ((NULL != nonce_str) && (strcmp ("", nonce_str) != 0))
{
- if ((1 != sscanf (nonce_str, "%u", &nonce)) || (nonce > UINT32_MAX))
- {
- GNUNET_break (0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid nonce %s\n", nonce_str);
- return NULL;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Got nonce: %u from %s\n",
- nonce,
- nonce_str);
+ nonce_len = strlen (nonce_str);
+ payload_len += nonce_len;
}
- nonce_tmp = htonl (nonce);
- params.nonce = nonce_tmp;
+ params.nonce_len = htonl (nonce_len);
// Assign code challenge
if (NULL != code_challenge)
code_challenge_len = strlen (code_challenge);
@@ -506,6 +503,11 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
memcpy (tmp, code_challenge, code_challenge_len);
tmp += code_challenge_len;
}
+ if (0 < nonce_len)
+ {
+ memcpy (tmp, nonce_str, nonce_len);
+ tmp += nonce_len;
+ }
if (0 < attr_list_len)
GNUNET_RECLAIM_attribute_list_serialize (attrs, tmp);
if (0 < attests_list_len)
@@ -513,36 +515,24 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
/** END **/
- /** ENCRYPT **/
// Get length
code_payload_len = sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
- + sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)
+ payload_len + sizeof(struct
GNUNET_CRYPTO_EcdsaSignature);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Length of data to encode: %lu\n",
code_payload_len);
- // Generate ECDH key
- GNUNET_CRYPTO_ecdhe_key_create (&ecdh_priv);
- GNUNET_CRYPTO_ecdhe_key_get_public (&ecdh_priv, &ecdh_pub);
// Initialize code payload
code_payload = GNUNET_malloc (code_payload_len);
GNUNET_assert (NULL != code_payload);
purpose = (struct GNUNET_CRYPTO_EccSignaturePurpose *) code_payload;
purpose->size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
- + sizeof(ecdh_pub) + payload_len);
+ + payload_len);
purpose->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_RECLAIM_CODE_SIGN);
// Store pubkey
buf_ptr = (char *) &purpose[1];
- memcpy (buf_ptr, &ecdh_pub, sizeof(ecdh_pub));
- buf_ptr += sizeof(ecdh_pub);
- // Encrypt plaintext and store
- encrypt_payload (&ticket->audience,
- &ecdh_priv,
- payload,
- payload_len,
- buf_ptr);
+ memcpy (buf_ptr, payload, payload_len);
GNUNET_free (payload);
buf_ptr += payload_len;
// Sign and store signature
@@ -570,14 +560,16 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
*
* @param audience the expected audience of the code
* @param code the string representation of the code
- * @param code_verfier PKCE code verifier
+ * @param code_verfier PKCE code verifier. Optional, must be provided
+ * if used in request.
* @param ticket where to store the ticket
* @param attrs the attributes in the code
- * @param nonce where to store the nonce
+ * @param attests the attestations in the code (if any)
+ * @param nonce_str where to store the nonce (if contained)
* @return GNUNET_OK if successful, else GNUNET_SYSERR
*/
int
-OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
+OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *audience,
const char *code,
const char *code_verifier,
struct GNUNET_RECLAIM_Ticket *ticket,
@@ -595,14 +587,12 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
char *code_verifier_hash;
struct GNUNET_CRYPTO_EccSignaturePurpose *purpose;
struct GNUNET_CRYPTO_EcdsaSignature *signature;
- struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_pub;
- struct GNUNET_CRYPTO_EcdhePublicKey *ecdh_pub;
uint32_t code_challenge_len;
uint32_t attrs_ser_len;
uint32_t attests_ser_len;
size_t plaintext_len;
size_t code_payload_len;
- uint32_t nonce = 0;
+ uint32_t nonce_len = 0;
struct OIDC_Parameters *params;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to decode `%s'\n", code);
@@ -611,7 +601,6 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
GNUNET_STRINGS_base64url_decode (code, strlen (code),
(void **) &code_payload);
if (code_payload_len < sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
- + sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)
+ sizeof(struct OIDC_Parameters)
+ sizeof(struct GNUNET_CRYPTO_EcdsaSignature))
{
@@ -624,16 +613,8 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
plaintext_len = code_payload_len;
plaintext_len -= sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose);
ptr = (char *) &purpose[1];
- // Public ECDH key
- ecdh_pub = (struct GNUNET_CRYPTO_EcdhePublicKey *) ptr;
- ptr += sizeof(struct GNUNET_CRYPTO_EcdhePublicKey);
- plaintext_len -= sizeof(struct GNUNET_CRYPTO_EcdhePublicKey);
-
- // Decrypt ciphertext
plaintext_len -= sizeof(struct GNUNET_CRYPTO_EcdsaSignature);
- plaintext = GNUNET_malloc (plaintext_len);
- decrypt_payload (ecdsa_priv, ecdh_pub, ptr, plaintext_len, plaintext);
- // ptr = plaintext;
+ plaintext = ptr;
ptr += plaintext_len;
signature = (struct GNUNET_CRYPTO_EcdsaSignature *) ptr;
params = (struct OIDC_Parameters *) plaintext;
@@ -658,11 +639,10 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
// encode code verifier
GNUNET_STRINGS_base64url_encode (code_verifier_hash, 256 / 8,
&expected_code_challenge);
- code_challenge = (char *) &params[1];
+ code_challenge = ((char *) &params[1]);
GNUNET_free (code_verifier_hash);
- if ((strlen (expected_code_challenge) != code_challenge_len) ||
- (0 !=
- strncmp (expected_code_challenge, code_challenge, code_challenge_len)))
+ if (0 !=
+ strncmp (expected_code_challenge, code_challenge, code_challenge_len))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Invalid code verifier! Expected: %s, Got: %.*s\n",
@@ -675,17 +655,23 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
}
GNUNET_free (expected_code_challenge);
}
+ nonce_len = ntohl (params->nonce_len);
+ if (0 != nonce_len)
+ {
+ *nonce_str = GNUNET_strndup (code_challenge + code_challenge_len,
+ nonce_len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got nonce: %s\n", *nonce_str);
+ }
+
// Ticket
memcpy (ticket, &params->ticket, sizeof(params->ticket));
- // Nonce
- nonce = ntohl (params->nonce); // ntohl (*((uint32_t *) ptr));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got nonce: %u\n", nonce);
// Signature
- GNUNET_CRYPTO_ecdsa_key_get_public (ecdsa_priv, &ecdsa_pub);
- if (0 != GNUNET_memcmp (&ecdsa_pub, &ticket->audience))
+ // GNUNET_CRYPTO_ecdsa_key_get_public (ecdsa_priv, &ecdsa_pub);
+ if (0 != GNUNET_memcmp (audience, &ticket->audience))
{
GNUNET_free (code_payload);
- GNUNET_free (plaintext);
+ if (NULL != *nonce_str)
+ GNUNET_free (*nonce_str);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Audience in ticket does not match client!\n");
return GNUNET_SYSERR;
@@ -697,12 +683,13 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
&ticket->identity))
{
GNUNET_free (code_payload);
- GNUNET_free (plaintext);
+ if (NULL != *nonce_str)
+ GNUNET_free (*nonce_str);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Signature of AuthZ code invalid!\n");
return GNUNET_SYSERR;
}
// Attributes
- attrs_ser = ((char *) &params[1]) + code_challenge_len;
+ attrs_ser = ((char *) &params[1]) + code_challenge_len + nonce_len;
attrs_ser_len = ntohl (params->attr_list_len);
*attrs = GNUNET_RECLAIM_attribute_list_deserialize (attrs_ser, attrs_ser_len);
attests_ser = ((char*) attrs_ser) + attrs_ser_len;
@@ -710,11 +697,7 @@ OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
*attests = GNUNET_RECLAIM_attestation_list_deserialize (attests_ser,
attests_ser_len);
- *nonce_str = NULL;
- if (nonce != 0)
- GNUNET_asprintf (nonce_str, "%u", nonce);
GNUNET_free (code_payload);
- GNUNET_free (plaintext);
return GNUNET_OK;
}
@@ -757,15 +740,102 @@ OIDC_build_token_response (const char *access_token,
* Generate a new access token
*/
char *
-OIDC_access_token_new ()
+OIDC_access_token_new (const struct GNUNET_RECLAIM_Ticket *ticket)
{
char *access_token;
- uint64_t random_number;
- random_number =
- GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
- GNUNET_STRINGS_base64_encode (&random_number,
- sizeof(uint64_t),
+ GNUNET_STRINGS_base64_encode (ticket,
+ sizeof(*ticket),
&access_token);
return access_token;
}
+
+
+/**
+ * Parse an access token
+ */
+int
+OIDC_access_token_parse (const char *token,
+ struct GNUNET_RECLAIM_Ticket **ticket)
+{
+ if (sizeof (struct GNUNET_RECLAIM_Ticket) !=
+ GNUNET_STRINGS_base64_decode (token,
+ strlen (token),
+ (void**) ticket))
+ return GNUNET_SYSERR;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Checks if a claim is implicitly requested through standard
+ * scope(s)
+ *
+ * @param scopes the scopes which have been requested
+ * @param attr the attribute name to check
+ * @return GNUNET_YES if attribute is implcitly requested
+ */
+enum GNUNET_GenericReturnValue
+OIDC_check_scopes_for_claim_request (const char*scopes,
+ const char*attr)
+{
+ char *scope_variables;
+ char *scope_variable;
+ char delimiter[] = " ";
+ int i;
+
+ scope_variables = GNUNET_strdup (scopes);
+ scope_variable = strtok (scope_variables, delimiter);
+ while (NULL != scope_variable)
+ {
+ if (0 == strcmp ("profile", scope_variable))
+ {
+ for (i = 0; i < 14; i++)
+ {
+ if (0 == strcmp (attr, OIDC_profile_claims[i]))
+ {
+ GNUNET_free (scope_variables);
+ return GNUNET_YES;
+ }
+ }
+ }
+ else if (0 == strcmp ("address", scope_variable))
+ {
+ for (i = 0; i < 5; i++)
+ {
+ if (0 == strcmp (attr, OIDC_address_claims[i]))
+ {
+ GNUNET_free (scope_variables);
+ return GNUNET_YES;
+ }
+ }
+ }
+ else if (0 == strcmp ("email", scope_variable))
+ {
+ for (i = 0; i < 2; i++)
+ {
+ if (0 == strcmp (attr, OIDC_email_claims[i]))
+ {
+ GNUNET_free (scope_variables);
+ return GNUNET_YES;
+ }
+ }
+ }
+ else if (0 == strcmp ("phone", scope_variable))
+ {
+ for (i = 0; i < 2; i++)
+ {
+ if (0 == strcmp (attr, OIDC_phone_claims[i]))
+ {
+ GNUNET_free (scope_variables);
+ return GNUNET_YES;
+ }
+ }
+
+ }
+ scope_variable = strtok (NULL, delimiter);
+ }
+ GNUNET_free (scope_variables);
+ return GNUNET_NO;
+
+}
diff --git a/src/reclaim/oidc_helper.h b/src/reclaim/oidc_helper.h
index 2c533357e..e713dab62 100644
--- a/src/reclaim/oidc_helper.h
+++ b/src/reclaim/oidc_helper.h
@@ -49,7 +49,7 @@
* @return a new base64-encoded JWT string.
*/
char*
-OIDC_id_token_new (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
+OIDC_generate_id_token (const struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key,
const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
struct GNUNET_RECLAIM_AttributeList *attrs,
struct GNUNET_RECLAIM_AttestationList *attests,
@@ -90,7 +90,7 @@ OIDC_build_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *issuer,
* @return GNUNET_OK if successful, else GNUNET_SYSERR
*/
int
-OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPrivateKey *ecdsa_priv,
+OIDC_parse_authz_code (const struct GNUNET_CRYPTO_EcdsaPublicKey *ecdsa_pub,
const char *code,
const char *code_verifier,
struct GNUNET_RECLAIM_Ticket *ticket,
@@ -117,7 +117,40 @@ OIDC_build_token_response (const char *access_token,
* Generate a new access token
*/
char*
-OIDC_access_token_new ();
+OIDC_access_token_new (const struct GNUNET_RECLAIM_Ticket *ticket);
+/**
+ * Parse an access token
+ */
+int
+OIDC_access_token_parse (const char* token,
+ struct GNUNET_RECLAIM_Ticket **ticket);
+
+
+/**
+ * Checks if a claim is implicitly requested through standard
+ * scope(s)
+ *
+ * @param scopes the scopes which have been requested
+ * @param attr the attribute name to check
+ * @return GNUNET_YES if attribute is implcitly requested
+ */
+enum GNUNET_GenericReturnValue
+OIDC_check_scopes_for_claim_request (const char*scopes,
+ const char*attr);
+
+
+/**
+ * Generate userinfo JSON as string
+ *
+ * @param sub_key the subject (user)
+ * @param attrs user attribute list
+ * @param attests user attribute attestation list (may be empty)
+ * @return Userinfo JSON
+ */
+char *
+OIDC_generate_userinfo (const struct GNUNET_CRYPTO_EcdsaPublicKey *sub_key,
+ struct GNUNET_RECLAIM_AttributeList *attrs,
+ struct GNUNET_RECLAIM_AttestationList *attests);
#endif
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 36ae937c1..06e1b0061 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -28,6 +28,8 @@
#include <inttypes.h>
#include <jansson.h>
+#include "gnunet_buffer_lib.h"
+#include "gnunet_strings_lib.h"
#include "gnunet_gns_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_identity_service.h"
@@ -39,12 +41,18 @@
#include "gnunet_signatures.h"
#include "microhttpd.h"
#include "oidc_helper.h"
+
/**
* REST root namespace
*/
#define GNUNET_REST_API_NS_OIDC "/openid"
/**
+ * OIDC config
+ */
+#define GNUNET_REST_API_NS_OIDC_CONFIG "/.well-known/openid-configuration"
+
+/**
* Authorize endpoint
*/
#define GNUNET_REST_API_NS_AUTHORIZE "/openid/authorize"
@@ -237,12 +245,6 @@ static char *OIDC_ignored_parameter_array[] = { "display",
struct GNUNET_CONTAINER_MultiHashMap *OIDC_cookie_jar_map;
/**
- * Hash map that links the issued access token to the corresponding ticket and
- * ego
- */
-struct GNUNET_CONTAINER_MultiHashMap *OIDC_access_token_map;
-
-/**
* The configuration handle
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -253,6 +255,36 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
static char *allow_methods;
/**
+ * Ego list
+ */
+static struct EgoEntry *ego_head;
+
+/**
+ * Ego list
+ */
+static struct EgoEntry *ego_tail;
+
+/**
+ * The processing state
+ */
+static int state;
+
+/**
+ * Handle to Identity service.
+ */
+static struct GNUNET_IDENTITY_Handle *identity_handle;
+
+/**
+ * GNS handle
+ */
+static struct GNUNET_GNS_Handle *gns_handle;
+
+/**
+ * Identity Provider
+ */
+static struct GNUNET_RECLAIM_Handle *idp;
+
+/**
* @brief struct returned by the initialization function of the plugin
*/
struct Plugin
@@ -325,10 +357,6 @@ struct OIDC_Variables
*/
char *code_verifier;
- /**
- * The response JSON
- */
- json_t *response;
};
/**
@@ -365,15 +393,6 @@ struct EgoEntry
struct RequestHandle
{
- /**
- * Ego list
- */
- struct EgoEntry *ego_head;
-
- /**
- * Ego list
- */
- struct EgoEntry *ego_tail;
/**
* Selected ego
@@ -391,39 +410,14 @@ struct RequestHandle
struct OIDC_Variables *oidc;
/**
- * The processing state
- */
- int state;
-
- /**
- * Handle to Identity service.
- */
- struct GNUNET_IDENTITY_Handle *identity_handle;
-
- /**
- * Rest connection
- */
- struct GNUNET_REST_RequestHandle *rest_handle;
-
- /**
- * GNS handle
- */
- struct GNUNET_GNS_Handle *gns_handle;
-
- /**
* GNS lookup op
*/
struct GNUNET_GNS_LookupRequest *gns_op;
/**
- * Handle to NAMESTORE
- */
- struct GNUNET_NAMESTORE_Handle *namestore_handle;
-
- /**
- * Iterator for NAMESTORE
+ * Rest connection
*/
- struct GNUNET_NAMESTORE_ZoneIterator *namestore_handle_it;
+ struct GNUNET_REST_RequestHandle *rest_handle;
/**
* Attribute claim list for id_token
@@ -446,10 +440,6 @@ struct RequestHandle
*/
struct GNUNET_IDENTITY_Operation *op;
- /**
- * Identity Provider
- */
- struct GNUNET_RECLAIM_Handle *idp;
/**
* Idp Operation
@@ -531,8 +521,14 @@ struct RequestHandle
* Reponse code
*/
int response_code;
+
+ /**
+ * Public client
+ */
+ int public_client;
};
+
/**
* Cleanup lookup handle
* @param handle Handle to clean up
@@ -540,13 +536,10 @@ struct RequestHandle
static void
cleanup_handle (struct RequestHandle *handle)
{
- struct EgoEntry *ego_entry;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
if (NULL != handle->timeout_task)
GNUNET_SCHEDULER_cancel (handle->timeout_task);
- if (NULL != handle->identity_handle)
- GNUNET_IDENTITY_disconnect (handle->identity_handle);
if (NULL != handle->attr_it)
GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
if (NULL != handle->attest_it)
@@ -555,8 +548,6 @@ cleanup_handle (struct RequestHandle *handle)
GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
if (NULL != handle->idp_op)
GNUNET_RECLAIM_cancel (handle->idp_op);
- if (NULL != handle->idp)
- GNUNET_RECLAIM_disconnect (handle->idp);
GNUNET_free (handle->url);
GNUNET_free (handle->tld);
GNUNET_free (handle->redirect_prefix);
@@ -565,11 +556,6 @@ cleanup_handle (struct RequestHandle *handle)
GNUNET_free (handle->edesc);
if (NULL != handle->gns_op)
GNUNET_GNS_lookup_cancel (handle->gns_op);
- if (NULL != handle->gns_handle)
- GNUNET_GNS_disconnect (handle->gns_handle);
-
- if (NULL != handle->namestore_handle)
- GNUNET_NAMESTORE_disconnect (handle->namestore_handle);
if (NULL != handle->oidc)
{
GNUNET_free (handle->oidc->client_id);
@@ -579,7 +565,6 @@ cleanup_handle (struct RequestHandle *handle)
GNUNET_free (handle->oidc->response_type);
GNUNET_free (handle->oidc->scope);
GNUNET_free (handle->oidc->state);
- json_decref (handle->oidc->response);
GNUNET_free (handle->oidc);
}
if (NULL!=handle->attr_idtoken_list)
@@ -589,15 +574,6 @@ cleanup_handle (struct RequestHandle *handle)
if (NULL!=handle->attests_list)
GNUNET_RECLAIM_attestation_list_destroy (handle->attests_list);
- while (NULL != (ego_entry = handle->ego_head))
- {
- GNUNET_CONTAINER_DLL_remove (handle->ego_head,
- handle->ego_tail,
- ego_entry);
- GNUNET_free (ego_entry->identifier);
- GNUNET_free (ego_entry->keystring);
- GNUNET_free (ego_entry);
- }
GNUNET_free (handle);
}
@@ -655,6 +631,8 @@ do_userinfo_error (void *cls)
struct MHD_Response *resp;
char *error;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error: %s\n", handle->edesc);
GNUNET_asprintf (&error,
"error=\"%s\", error_description=\"%s\"",
handle->emsg,
@@ -710,27 +688,6 @@ do_timeout (void *cls)
/**
- * Return attributes for claim
- *
- * @param cls the request handle
- */
-static void
-return_userinfo_response (void *cls)
-{
- char *result_str;
- struct RequestHandle *handle = cls;
- struct MHD_Response *resp;
-
- result_str = json_dumps (handle->oidc->response, 0);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"ID-Token: %s\n",result_str);
- resp = GNUNET_REST_create_response (result_str);
- handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
- GNUNET_free (result_str);
- cleanup_handle (handle);
-}
-
-
-/**
* Respond to OPTIONS request
*
* @param con_handle the connection handle
@@ -854,7 +811,9 @@ login_redirect (void *cls)
{
char *login_base_url;
char *new_redirect;
+ char *tmp;
struct MHD_Response *resp;
+ struct GNUNET_Buffer buf = { 0 };
struct RequestHandle *handle = cls;
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -862,27 +821,68 @@ login_redirect (void *cls)
"address",
&login_base_url))
{
- GNUNET_asprintf (&new_redirect,
- "%s?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
- login_base_url,
- OIDC_RESPONSE_TYPE_KEY,
- handle->oidc->response_type,
- OIDC_CLIENT_ID_KEY,
- handle->oidc->client_id,
- OIDC_REDIRECT_URI_KEY,
- handle->oidc->redirect_uri,
- OIDC_SCOPE_KEY,
- handle->oidc->scope,
- OIDC_STATE_KEY,
- (NULL != handle->oidc->state) ? handle->oidc->state : "",
- OIDC_CODE_CHALLENGE_KEY,
- (NULL != handle->oidc->code_challenge) ?
- handle->oidc->code_challenge : "",
- OIDC_NONCE_KEY,
- (NULL != handle->oidc->nonce) ? handle->oidc->nonce : "",
- OIDC_CLAIMS_KEY,
- (NULL != handle->oidc->claims) ? handle->oidc->claims :
- "");
+ GNUNET_buffer_write_str (&buf, login_base_url);
+ GNUNET_buffer_write_fstr (&buf,
+ "?%s=%s",
+ OIDC_RESPONSE_TYPE_KEY,
+ handle->oidc->response_type);
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_CLIENT_ID_KEY,
+ handle->oidc->client_id);
+ GNUNET_STRINGS_urlencode (handle->oidc->redirect_uri,
+ strlen (handle->oidc->redirect_uri),
+ &tmp);
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_REDIRECT_URI_KEY,
+ tmp);
+ GNUNET_free (tmp);
+ GNUNET_STRINGS_urlencode (handle->oidc->scope,
+ strlen (handle->oidc->scope),
+ &tmp);
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_SCOPE_KEY,
+ tmp);
+ GNUNET_free (tmp);
+ if (NULL != handle->oidc->state)
+ {
+ GNUNET_STRINGS_urlencode (handle->oidc->state,
+ strlen (handle->oidc->state),
+ &tmp);
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_STATE_KEY,
+ handle->oidc->state);
+ GNUNET_free (tmp);
+ }
+ if (NULL != handle->oidc->code_challenge)
+ {
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_CODE_CHALLENGE_KEY,
+ handle->oidc->code_challenge);
+ }
+ if (NULL != handle->oidc->nonce)
+ {
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_NONCE_KEY,
+ handle->oidc->nonce);
+ }
+ if (NULL != handle->oidc->claims)
+ {
+ GNUNET_STRINGS_urlencode (handle->oidc->claims,
+ strlen (handle->oidc->claims),
+ &tmp);
+ GNUNET_buffer_write_fstr (&buf,
+ "&%s=%s",
+ OIDC_CLAIMS_KEY,
+ tmp);
+ GNUNET_free (tmp);
+ }
+ new_redirect = GNUNET_buffer_reap_str (&buf);
resp = GNUNET_REST_create_response ("");
MHD_add_response_header (resp, "Location", new_redirect);
GNUNET_free (login_base_url);
@@ -954,6 +954,8 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
handle->redirect_prefix,
handle->tld,
handle->redirect_suffix,
+ (NULL == strchr (handle->redirect_suffix, '?') ? "?" :
+ "&"),
handle->oidc->response_type,
code_string,
handle->oidc->state);
@@ -961,8 +963,10 @@ oidc_ticket_issue_cb (void *cls, const struct GNUNET_RECLAIM_Ticket *ticket)
else
{
GNUNET_asprintf (&redirect_uri,
- "%s?%s=%s&state=%s",
+ "%s%s%s=%s&state=%s",
handle->oidc->redirect_uri,
+ (NULL == strchr (handle->oidc->redirect_uri, '?') ? "?" :
+ "&"),
handle->oidc->response_type,
code_string,
handle->oidc->state);
@@ -1041,7 +1045,7 @@ oidc_attest_collect_finished_cb (void *cls)
handle->attest_it = NULL;
merged_list = attribute_list_merge (handle->attr_idtoken_list,
handle->attr_userinfo_list);
- handle->idp_op = GNUNET_RECLAIM_ticket_issue (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_ticket_issue (idp,
&handle->priv_key,
&handle->oidc->client_pkey,
merged_list,
@@ -1108,7 +1112,7 @@ oidc_attr_collect_finished_cb (void *cls)
}
handle->attests_list = GNUNET_new (struct GNUNET_RECLAIM_AttestationList);
handle->attest_it =
- GNUNET_RECLAIM_get_attestations_start (handle->idp,
+ GNUNET_RECLAIM_get_attestations_start (idp,
&handle->priv_key,
&oidc_iteration_error,
handle,
@@ -1125,9 +1129,6 @@ attr_in_claims_request (struct RequestHandle *handle,
const char *attr_name,
const char *claims_parameter)
{
- char *scope_variables;
- char *scope_variable;
- char delimiter[] = " ";
int ret = GNUNET_NO;
json_t *root;
json_error_t error;
@@ -1135,19 +1136,12 @@ attr_in_claims_request (struct RequestHandle *handle,
const char *key;
json_t *value;
- scope_variables = GNUNET_strdup (handle->oidc->scope);
- scope_variable = strtok (scope_variables, delimiter);
- while (NULL != scope_variable)
- {
- if (0 == strcmp (attr_name, scope_variable))
- break;
- scope_variable = strtok (NULL, delimiter);
- }
- if (NULL != scope_variable)
- ret = GNUNET_YES;
- GNUNET_free (scope_variables);
+ /** Check if attribute is requested through standard scope **/
+ if (GNUNET_YES == OIDC_check_scopes_for_claim_request (handle->oidc->scope,
+ attr_name))
+ return GNUNET_YES;
- /** Try claims parameter if no in scope */
+ /** Try claims parameter if not in scope */
if ((NULL != handle->oidc->claims) &&
(GNUNET_YES != ret))
{
@@ -1274,7 +1268,7 @@ code_redirect (void *cls)
return;
}
// iterate over egos and compare their public key
- for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry;
+ for (handle->ego_entry = ego_head; NULL != handle->ego_entry;
handle->ego_entry = handle->ego_entry->next)
{
GNUNET_IDENTITY_ego_get_public_key (handle->ego_entry->ego, &ego_pkey);
@@ -1282,13 +1276,12 @@ code_redirect (void *cls)
{
handle->priv_key =
*GNUNET_IDENTITY_ego_get_private_key (handle->ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
handle->attr_idtoken_list =
GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
handle->attr_userinfo_list =
GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
handle->attr_it =
- GNUNET_RECLAIM_get_attributes_start (handle->idp,
+ GNUNET_RECLAIM_get_attributes_start (idp,
&handle->priv_key,
&oidc_iteration_error,
handle,
@@ -1433,7 +1426,7 @@ client_redirect (void *cls)
/* Lookup client redirect uri to verify request */
handle->gns_op =
- GNUNET_GNS_lookup (handle->gns_handle,
+ GNUNET_GNS_lookup (gns_handle,
GNUNET_GNS_EMPTY_LABEL_AT,
&handle->oidc->client_pkey,
GNUNET_GNSRECORD_TYPE_RECLAIM_OIDC_REDIRECT,
@@ -1448,6 +1441,7 @@ get_url_parameter_copy (const struct RequestHandle *handle, const char *key)
{
struct GNUNET_HashCode hc;
char *value;
+ char *res;
GNUNET_CRYPTO_hash (key, strlen (key), &hc);
if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
@@ -1458,7 +1452,8 @@ get_url_parameter_copy (const struct RequestHandle *handle, const char *key)
GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map, &hc);
if (NULL == value)
return NULL;
- return GNUNET_strdup (value);
+ GNUNET_STRINGS_urldecode (value, strlen (value), &res);
+ return res;
}
@@ -1657,14 +1652,14 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
// If we know this identity, translated the corresponding TLD
// TODO: We might want to have a reverse lookup functionality for TLDs?
- for (tmp_ego = handle->ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next)
+ for (tmp_ego = ego_head; NULL != tmp_ego; tmp_ego = tmp_ego->next)
{
priv_key = GNUNET_IDENTITY_ego_get_private_key (tmp_ego->ego);
GNUNET_CRYPTO_ecdsa_key_get_public (priv_key, &pkey);
if (0 == GNUNET_memcmp (&pkey, &handle->oidc->client_pkey))
{
handle->tld = GNUNET_strdup (tmp_ego->identifier);
- handle->ego_entry = handle->ego_tail;
+ handle->ego_entry = ego_tail;
}
}
handle->oidc->scope = get_url_parameter_copy (handle, OIDC_SCOPE_KEY);
@@ -1749,16 +1744,16 @@ login_cont (struct GNUNET_REST_RequestHandle *con_handle,
static int
-check_authorization (struct RequestHandle *handle,
- struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
+parse_credentials_basic_auth (struct RequestHandle *handle,
+ char **client_id,
+ char **client_secret)
{
struct GNUNET_HashCode cache_key;
char *authorization;
char *credentials;
char *basic_authorization;
- char *client_id;
+ char *client_id_tmp;
char *pass;
- char *expected_pass;
GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
strlen (OIDC_AUTHORIZATION_HEADER_KEY),
@@ -1766,12 +1761,7 @@ check_authorization (struct RequestHandle *handle,
if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
->header_param_map,
&cache_key))
- {
- handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
- handle->edesc = GNUNET_strdup ("missing authorization");
- handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
- }
authorization =
GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->header_param_map,
&cache_key);
@@ -1779,44 +1769,117 @@ check_authorization (struct RequestHandle *handle,
// split header in "Basic" and [content]
credentials = strtok (authorization, " ");
if ((NULL == credentials) || (0 != strcmp ("Basic", credentials)))
- {
- handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
- handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
- }
credentials = strtok (NULL, " ");
if (NULL == credentials)
- {
- handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
- handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
- }
GNUNET_STRINGS_base64_decode (credentials,
strlen (credentials),
(void **) &basic_authorization);
if (NULL == basic_authorization)
- {
- handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
- handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
- }
- client_id = strtok (basic_authorization, ":");
- if (NULL == client_id)
+ client_id_tmp = strtok (basic_authorization, ":");
+ if (NULL == client_id_tmp)
{
GNUNET_free (basic_authorization);
- handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
- handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
}
pass = strtok (NULL, ":");
if (NULL == pass)
{
GNUNET_free (basic_authorization);
- handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
- handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
}
+ *client_id = strdup (client_id_tmp);
+ *client_secret = strdup (pass);
+ GNUNET_free (basic_authorization);
+ return GNUNET_OK;
+}
+
+
+static int
+parse_credentials_post_body (struct RequestHandle *handle,
+ char **client_id,
+ char **client_secret)
+{
+ struct GNUNET_HashCode cache_key;
+ char *client_id_tmp;
+ char *pass;
+
+ GNUNET_CRYPTO_hash ("client_id",
+ strlen ("client_id"),
+ &cache_key);
+ if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
+ ->url_param_map,
+ &cache_key))
+ return GNUNET_SYSERR;
+ client_id_tmp = GNUNET_CONTAINER_multihashmap_get (
+ handle->rest_handle->url_param_map,
+ &cache_key);
+ if (NULL == client_id_tmp)
+ return GNUNET_SYSERR;
+ *client_id = strdup (client_id_tmp);
+ GNUNET_CRYPTO_hash ("client_secret",
+ strlen ("client_secret"),
+ &cache_key);
+ if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->rest_handle
+ ->url_param_map,
+ &cache_key))
+ return GNUNET_SYSERR;
+ pass = GNUNET_CONTAINER_multihashmap_get (handle->rest_handle->url_param_map,
+ &cache_key);
+ if (NULL == pass)
+ return GNUNET_SYSERR;
+ *client_secret = strdup (pass);
+ return GNUNET_OK;
+}
+
+
+static int
+check_authorization (struct RequestHandle *handle,
+ struct GNUNET_CRYPTO_EcdsaPublicKey *cid)
+{
+ char *expected_pass;
+ char *received_cid;
+ char *received_cpw;
+ char *pkce_cv;
+
+ if (GNUNET_OK == parse_credentials_basic_auth (handle,
+ &received_cid,
+ &received_cpw))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received client credentials in HTTP AuthZ header\n");
+ }
+ else if (GNUNET_OK == parse_credentials_post_body (handle,
+ &received_cid,
+ &received_cpw))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received client credentials in POST body\n");
+ }
+ else
+ {
+ /** Allow public clients with PKCE **/
+ pkce_cv = get_url_parameter_copy (handle, OIDC_CODE_VERIFIER_KEY);
+ if (NULL == pkce_cv)
+ {
+ handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
+ handle->response_code = MHD_HTTP_UNAUTHORIZED;
+ return GNUNET_SYSERR;
+ }
+ handle->public_client = GNUNET_YES;
+ GNUNET_free (pkce_cv);
+ received_cid = get_url_parameter_copy (handle, OIDC_CLIENT_ID_KEY);
+ GNUNET_STRINGS_string_to_data (received_cid,
+ strlen (received_cid),
+ cid,
+ sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
+ GNUNET_free (received_cid);
+ return GNUNET_OK;
+
+ }
// check client password
if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg,
@@ -1824,9 +1887,8 @@ check_authorization (struct RequestHandle *handle,
"OIDC_CLIENT_SECRET",
&expected_pass))
{
- if (0 != strcmp (expected_pass, pass))
+ if (0 != strcmp (expected_pass, received_cpw))
{
- GNUNET_free (basic_authorization);
GNUNET_free (expected_pass);
handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
handle->response_code = MHD_HTTP_UNAUTHORIZED;
@@ -1836,33 +1898,33 @@ check_authorization (struct RequestHandle *handle,
}
else
{
- GNUNET_free (basic_authorization);
handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_SERVER_ERROR);
handle->edesc = GNUNET_strdup ("gnunet configuration failed");
handle->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
return GNUNET_SYSERR;
}
-
// check client_id
- for (handle->ego_entry = handle->ego_head; NULL != handle->ego_entry;
+ for (handle->ego_entry = ego_head; NULL != handle->ego_entry;
handle->ego_entry = handle->ego_entry->next)
{
- if (0 == strcmp (handle->ego_entry->keystring, client_id))
+ if (0 == strcmp (handle->ego_entry->keystring, received_cid))
break;
}
if (NULL == handle->ego_entry)
{
- GNUNET_free (basic_authorization);
+ GNUNET_free (received_cpw);
+ GNUNET_free (received_cid);
handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_CLIENT);
handle->response_code = MHD_HTTP_UNAUTHORIZED;
return GNUNET_SYSERR;
}
- GNUNET_STRINGS_string_to_data (client_id,
- strlen (client_id),
+ GNUNET_STRINGS_string_to_data (received_cid,
+ strlen (received_cid),
cid,
sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
- GNUNET_free (basic_authorization);
+ GNUNET_free (received_cpw);
+ GNUNET_free (received_cid);
return GNUNET_OK;
}
@@ -1874,7 +1936,7 @@ find_ego (struct RequestHandle *handle,
struct EgoEntry *ego_entry;
struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
{
GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &pub_key);
@@ -1885,26 +1947,6 @@ find_ego (struct RequestHandle *handle,
}
-static void
-persist_access_token (const struct RequestHandle *handle,
- const char *access_token,
- const struct GNUNET_RECLAIM_Ticket *ticket)
-{
- struct GNUNET_HashCode hc;
- struct GNUNET_RECLAIM_Ticket *ticketbuf;
-
- GNUNET_CRYPTO_hash (access_token, strlen (access_token), &hc);
- ticketbuf = GNUNET_new (struct GNUNET_RECLAIM_Ticket);
- *ticketbuf = *ticket;
- GNUNET_assert (GNUNET_SYSERR !=
- GNUNET_CONTAINER_multihashmap_put (
- OIDC_access_token_map,
- &hc,
- ticketbuf,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-}
-
-
/**
* Responds to token url-encoded POST request
*
@@ -2008,7 +2050,7 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
}
// decode code
- if (GNUNET_OK != OIDC_parse_authz_code (privkey, code, code_verifier, &ticket,
+ if (GNUNET_OK != OIDC_parse_authz_code (&cid, code, code_verifier, &ticket,
&cl, &al, &nonce))
{
handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_REQUEST);
@@ -2046,20 +2088,19 @@ token_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
- id_token = OIDC_id_token_new (&ticket.audience,
- &ticket.identity,
- cl,
- al,
- &expiration_time,
- (NULL != nonce) ? nonce : NULL,
- jwt_secret);
- access_token = OIDC_access_token_new ();
+ id_token = OIDC_generate_id_token (&ticket.audience,
+ &ticket.identity,
+ cl,
+ al,
+ &expiration_time,
+ (NULL != nonce) ? nonce : NULL,
+ jwt_secret);
+ access_token = OIDC_access_token_new (&ticket);
OIDC_build_token_response (access_token,
id_token,
&expiration_time,
&json_response);
- persist_access_token (handle, access_token, &ticket);
resp = GNUNET_REST_create_response (json_response);
MHD_add_response_header (resp, "Cache-Control", "no-store");
MHD_add_response_header (resp, "Pragma", "no-cache");
@@ -2084,83 +2125,56 @@ consume_ticket (void *cls,
const struct GNUNET_RECLAIM_Attestation *attest)
{
struct RequestHandle *handle = cls;
+ struct GNUNET_RECLAIM_AttributeListEntry *ale;
+ struct GNUNET_RECLAIM_AttestationListEntry *atle;
+ struct MHD_Response *resp;
+ char *result_str;
handle->idp_op = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Attr: %s\n", attr->name);
if (NULL == identity)
{
- GNUNET_SCHEDULER_add_now (&return_userinfo_response, handle);
+ 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);
+ resp = GNUNET_REST_create_response (result_str);
+ handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ GNUNET_free (result_str);
+ cleanup_handle (handle);
return;
}
- if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attr->attestation))
+ ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry);
+ ale->attribute = GNUNET_RECLAIM_attribute_new (attr->name,
+ &attr->attestation,
+ attr->type,
+ attr->data,
+ attr->data_size);
+ ale->attribute->id = attr->id;
+ ale->attribute->flag = attr->flag;
+ ale->attribute->attestation = attr->attestation;
+ GNUNET_CONTAINER_DLL_insert (handle->attr_userinfo_list->list_head,
+ handle->attr_userinfo_list->list_tail,
+ ale);
+ for (atle = handle->attests_list->list_head; NULL != atle; atle = atle->next)
+ {
+ if (GNUNET_NO == GNUNET_RECLAIM_id_is_equal (&atle->attestation->id,
+ &attest->id))
+ continue;
+ break; /** already in list **/
+ }
+ if (NULL == atle)
{
- char *tmp_value;
- json_t *value;
- tmp_value = GNUNET_RECLAIM_attribute_value_to_string (attr->type,
- attr->data,
- attr->data_size);
- value = json_string (tmp_value);
- json_object_set_new (handle->oidc->response, attr->name, value);
- GNUNET_free (tmp_value);
- return;
+ /** Attestation matches for attribute, add **/
+ atle = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry);
+ atle->attestation = GNUNET_RECLAIM_attestation_new (attest->name,
+ attest->type,
+ attest->data,
+ attest->data_size);
+ GNUNET_CONTAINER_DLL_insert (handle->attests_list->list_head,
+ handle->attests_list->list_tail,
+ atle);
}
- json_t *claim_sources;
- json_t *claim_sources_jwt;
- json_t *claim_names;
- char *attest_val_str;
- claim_sources = json_object_get (handle->oidc->response,"_claim_sources");
- claim_names = json_object_get (handle->oidc->response,"_claim_names");
- attest_val_str =
- GNUNET_RECLAIM_attestation_value_to_string (attest->type,
- attest->data,
- attest->data_size);
- if ((NULL == claim_sources) && (NULL == claim_names) )
- {
- claim_sources = json_object ();
- claim_names = json_object ();
- }
- char *source_name;
- int i = 0;
- GNUNET_asprintf (&source_name, "src%d", i);
- while (NULL != (claim_sources_jwt = json_object_get (claim_sources,
- source_name)))
- {
- if (0 == strcmp (json_string_value (json_object_get (claim_sources_jwt,
- "JWT")),
- attest_val_str))
- {
- // Adapt only the claim names
- json_object_set_new (claim_names, attr->data,
- json_string (source_name));
- json_object_set (handle->oidc->response,
- "_claim_names", claim_names);
- break;
- }
- i++;
- GNUNET_free (source_name);
- GNUNET_asprintf (&source_name, "src%d", i);
- }
-
- // Create new one
- if (NULL == claim_sources_jwt)
- {
- claim_sources_jwt = json_object ();
- // Set the JWT for names
- json_object_set_new (claim_names, attr->data,
- json_string (source_name));
- // Set the JWT for the inner source
- json_object_set_new (claim_sources_jwt, "JWT",
- json_string (attest_val_str));
- // Set the JWT for the source
- json_object_set_new (claim_sources, source_name, claim_sources_jwt);
- // Set as claims
- json_object_set (handle->oidc->response, "_claim_names", claim_names);
- json_object_set (handle->oidc->response, "_claim_sources",claim_sources);
- }
-
- json_decref (claim_sources);
- json_decref (claim_names);
- json_decref (claim_sources_jwt);
- GNUNET_free (attest_val_str);
}
@@ -2178,15 +2192,16 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
{
// TODO expiration time
struct RequestHandle *handle = cls;
+ struct GNUNET_RECLAIM_Ticket *ticket;
char delimiter[] = " ";
struct GNUNET_HashCode cache_key;
char *authorization;
char *authorization_type;
char *authorization_access_token;
- struct GNUNET_RECLAIM_Ticket *ticket;
- const struct EgoEntry *ego_entry;
+ const struct EgoEntry *aud_ego;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Getting userinfo\n");
GNUNET_CRYPTO_hash (OIDC_AUTHORIZATION_HEADER_KEY,
strlen (OIDC_AUTHORIZATION_HEADER_KEY),
&cache_key);
@@ -2228,25 +2243,22 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
- GNUNET_CRYPTO_hash (authorization_access_token,
- strlen (authorization_access_token),
- &cache_key);
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multihashmap_contains (OIDC_access_token_map,
- &cache_key))
+ if (GNUNET_OK != OIDC_access_token_parse (authorization_access_token,
+ &ticket))
{
handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
- handle->edesc = GNUNET_strdup ("The access token expired");
+ handle->edesc = GNUNET_strdup ("The access token is invalid");
handle->response_code = MHD_HTTP_UNAUTHORIZED;
GNUNET_SCHEDULER_add_now (&do_userinfo_error, handle);
GNUNET_free (authorization);
return;
+
}
- ticket =
- GNUNET_CONTAINER_multihashmap_get (OIDC_access_token_map, &cache_key);
GNUNET_assert (NULL != ticket);
- ego_entry = find_ego (handle, &ticket->audience);
- if (NULL == ego_entry)
+ handle->ticket = *ticket;
+ GNUNET_free (ticket);
+ aud_ego = find_ego (handle, &handle->ticket.audience);
+ if (NULL == aud_ego)
{
handle->emsg = GNUNET_strdup (OIDC_ERROR_KEY_INVALID_TOKEN);
handle->edesc = GNUNET_strdup ("The access token expired");
@@ -2255,53 +2267,23 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
GNUNET_free (authorization);
return;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Consuming ticket\n");
+ privkey = GNUNET_IDENTITY_ego_get_private_key (aud_ego->ego);
+ handle->attr_userinfo_list =
+ GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
+ handle->attests_list =
+ GNUNET_new (struct GNUNET_RECLAIM_AttestationList);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
- handle->oidc->response = json_object ();
- json_object_set_new (handle->oidc->response,
- "sub",
- json_string (ego_entry->keystring));
- privkey = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
privkey,
- ticket,
- consume_ticket,
+ &handle->ticket,
+ &consume_ticket,
handle);
GNUNET_free (authorization);
}
/**
- * Handle rest request
- *
- * @param handle the request handle
- */
-static void
-init_cont (struct RequestHandle *handle)
-{
- struct GNUNET_REST_RequestHandlerError err;
- static const struct GNUNET_REST_RequestHandler handlers[] =
- { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint },
- { MHD_HTTP_METHOD_POST,
- GNUNET_REST_API_NS_AUTHORIZE,
- &authorize_endpoint }, // url-encoded
- { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont },
- { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint },
- { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
- { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
- { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont },
- GNUNET_REST_HANDLER_END };
-
- if (GNUNET_NO ==
- GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
- {
- handle->response_code = err.error_code;
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- }
-}
-
-
-/**
* If listing is enabled, prints information about the egos.
*
* This function is initially called for all egos and then again
@@ -2340,18 +2322,16 @@ list_ego (void *cls,
void **ctx,
const char *identifier)
{
- struct RequestHandle *handle = cls;
struct EgoEntry *ego_entry;
struct GNUNET_CRYPTO_EcdsaPublicKey pk;
- if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
+ if ((NULL == ego) && (ID_REST_STATE_INIT == state))
{
- handle->state = ID_REST_STATE_POST_INIT;
- init_cont (handle);
+ state = ID_REST_STATE_POST_INIT;
return;
}
GNUNET_assert (NULL != ego);
- if (ID_REST_STATE_INIT == handle->state)
+ if (ID_REST_STATE_INIT == state)
{
ego_entry = GNUNET_new (struct EgoEntry);
@@ -2359,15 +2339,15 @@ list_ego (void *cls,
ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
ego_entry->ego = ego;
ego_entry->identifier = GNUNET_strdup (identifier);
- GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head,
- handle->ego_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (ego_head,
+ ego_tail,
ego_entry);
return;
}
/* Ego renamed or added */
if (identifier != NULL)
{
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
{
if (ego_entry->ego == ego)
@@ -2386,15 +2366,15 @@ list_ego (void *cls,
ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
ego_entry->ego = ego;
ego_entry->identifier = GNUNET_strdup (identifier);
- GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head,
- handle->ego_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (ego_head,
+ ego_tail,
ego_entry);
}
}
else
{
/* Delete */
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
{
if (ego_entry->ego == ego)
@@ -2403,8 +2383,8 @@ list_ego (void *cls,
if (NULL == ego_entry)
return; /* Not found */
- GNUNET_CONTAINER_DLL_remove (handle->ego_head,
- handle->ego_tail,
+ GNUNET_CONTAINER_DLL_remove (ego_head,
+ ego_tail,
ego_entry);
GNUNET_free (ego_entry->identifier);
GNUNET_free (ego_entry->keystring);
@@ -2415,36 +2395,153 @@ list_ego (void *cls,
static void
+oidc_config_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
+ const char *url,
+ void *cls)
+{
+ json_t *oidc_config;
+ json_t *auth_methods;
+ json_t *sig_algs;
+ json_t *scopes;
+ json_t *response_types;
+ json_t *sub_types;
+ json_t *claim_types;
+ char *oidc_config_str;
+ struct MHD_Response *resp;
+ struct RequestHandle *handle = cls;
+
+ oidc_config = json_object ();
+ // FIXME get from config?
+ json_object_set_new (oidc_config,
+ "issuer", json_string ("http://localhost:7776"));
+ json_object_set_new (oidc_config,
+ "authorization_endpoint",
+ json_string ("https://api.reclaim/openid/authorize"));
+ json_object_set_new (oidc_config,
+ "token_endpoint",
+ json_string ("http://localhost:7776/openid/token"));
+ auth_methods = json_array ();
+ json_array_append_new (auth_methods,
+ json_string ("client_secret_basic"));
+ json_array_append_new (auth_methods,
+ json_string ("client_secret_post"));
+ json_object_set_new (oidc_config,
+ "token_endpoint_auth_methods_supported",
+ auth_methods);
+ sig_algs = json_array ();
+ json_array_append_new (sig_algs,
+ json_string ("HS512"));
+ json_object_set_new (oidc_config,
+ "id_token_signing_alg_values_supported",
+ sig_algs);
+ json_object_set_new (oidc_config,
+ "userinfo_endpoint",
+ json_string ("http://localhost:7776/openid/userinfo"));
+ scopes = json_array ();
+ json_array_append_new (scopes,
+ json_string ("openid"));
+ json_array_append_new (scopes,
+ json_string ("profile"));
+ json_object_set_new (oidc_config,
+ "scopes_supported",
+ scopes);
+ response_types = json_array ();
+ json_array_append_new (response_types,
+ json_string ("code"));
+ json_object_set_new (oidc_config,
+ "response_types_supported",
+ response_types);
+ sub_types = json_array ();
+ json_array_append_new (sub_types,
+ json_string ("public")); /* no pairwise suppport */
+ json_object_set_new (oidc_config,
+ "subject_types_supported",
+ sub_types);
+ claim_types = json_array ();
+ json_array_append_new (claim_types,
+ json_string ("normal"));
+ json_array_append_new (claim_types,
+ json_string ("aggregated"));
+ json_object_set_new (oidc_config,
+ "claim_types_supported",
+ claim_types);
+ json_object_set_new (oidc_config,
+ "claims_parameter_supported",
+ json_boolean (1));
+ oidc_config_str = json_dumps (oidc_config, JSON_INDENT (1));
+ resp = GNUNET_REST_create_response (oidc_config_str);
+ handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ GNUNET_free (oidc_config_str);
+ cleanup_handle (handle);
+}
+
+
+/**
+ * Respond to OPTIONS request
+ *
+ * @param con_handle the connection handle
+ * @param url the url
+ * @param cls the RequestHandle
+ */
+static void
+oidc_config_cors (struct GNUNET_REST_RequestHandle *con_handle,
+ const char *url,
+ void *cls)
+{
+ struct MHD_Response *resp;
+ struct RequestHandle *handle = cls;
+
+ // For now, independent of path return all options
+ resp = GNUNET_REST_create_response (NULL);
+ MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
+ MHD_add_response_header (resp, "Access-Control-Allow-Origin", "*");
+ handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
+ cleanup_handle (handle);
+ return;
+}
+
+
+static enum GNUNET_GenericReturnValue
rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
GNUNET_REST_ResultProcessor proc,
void *proc_cls)
{
struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
+ struct GNUNET_REST_RequestHandlerError err;
+ static const struct GNUNET_REST_RequestHandler handlers[] =
+ { { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint },
+ { MHD_HTTP_METHOD_POST,
+ GNUNET_REST_API_NS_AUTHORIZE, &authorize_endpoint }, // url-encoded
+ { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_LOGIN, &login_cont },
+ { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_TOKEN, &token_endpoint },
+ { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
+ { MHD_HTTP_METHOD_POST, GNUNET_REST_API_NS_USERINFO, &userinfo_endpoint },
+ { MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_OIDC_CONFIG,
+ &oidc_config_endpoint },
+ { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC_CONFIG,
+ &oidc_config_cors },
+ { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_OIDC, &options_cont },
+ GNUNET_REST_HANDLER_END };
handle->oidc = GNUNET_new (struct OIDC_Variables);
if (NULL == OIDC_cookie_jar_map)
OIDC_cookie_jar_map = GNUNET_CONTAINER_multihashmap_create (10,
GNUNET_NO);
- if (NULL == OIDC_access_token_map)
- OIDC_access_token_map =
- GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
handle->response_code = 0;
handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
handle->proc_cls = proc_cls;
handle->proc = proc;
- handle->state = ID_REST_STATE_INIT;
handle->rest_handle = rest_handle;
-
handle->url = GNUNET_strdup (rest_handle->url);
if (handle->url[strlen (handle->url) - 1] == '/')
handle->url[strlen (handle->url) - 1] = '\0';
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
- handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle);
- handle->gns_handle = GNUNET_GNS_connect (cfg);
- handle->namestore_handle = GNUNET_NAMESTORE_connect (cfg);
+ if (GNUNET_NO ==
+ GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
+ return GNUNET_NO;
+
handle->timeout_task =
GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
+ return GNUNET_YES;
}
@@ -2469,6 +2566,11 @@ libgnunet_plugin_rest_openid_connect_init (void *cls)
api->cls = &plugin;
api->name = GNUNET_REST_API_NS_OIDC;
api->process_request = &rest_identity_process_request;
+ identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
+ gns_handle = GNUNET_GNS_connect (cfg);
+ idp = GNUNET_RECLAIM_connect (cfg);
+
+ state = ID_REST_STATE_INIT;
GNUNET_asprintf (&allow_methods,
"%s, %s, %s, %s, %s",
MHD_HTTP_METHOD_GET,
@@ -2494,6 +2596,7 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
{
struct GNUNET_REST_Plugin *api = cls;
struct Plugin *plugin = api->cls;
+ struct EgoEntry *ego_entry;
plugin->cfg = NULL;
@@ -2508,15 +2611,23 @@ libgnunet_plugin_rest_openid_connect_done (void *cls)
GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
GNUNET_CONTAINER_multihashmap_destroy (OIDC_cookie_jar_map);
- hashmap_it =
- GNUNET_CONTAINER_multihashmap_iterator_create (OIDC_access_token_map);
- while (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_iterator_next (hashmap_it, NULL,
- value))
- GNUNET_free (value);
- GNUNET_CONTAINER_multihashmap_destroy (OIDC_access_token_map);
GNUNET_CONTAINER_multihashmap_iterator_destroy (hashmap_it);
GNUNET_free (allow_methods);
+ if (NULL != gns_handle)
+ GNUNET_GNS_disconnect (gns_handle);
+ if (NULL != identity_handle)
+ GNUNET_IDENTITY_disconnect (identity_handle);
+ if (NULL != idp)
+ GNUNET_RECLAIM_disconnect (idp);
+ while (NULL != (ego_entry = ego_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (ego_head,
+ ego_tail,
+ ego_entry);
+ GNUNET_free (ego_entry->identifier);
+ GNUNET_free (ego_entry->keystring);
+ GNUNET_free (ego_entry);
+ }
GNUNET_free (api);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"OpenID Connect REST plugin is finished\n");
diff --git a/src/reclaim/plugin_rest_reclaim.c b/src/reclaim/plugin_rest_reclaim.c
index 10ee2f801..c2d14825e 100644
--- a/src/reclaim/plugin_rest_reclaim.c
+++ b/src/reclaim/plugin_rest_reclaim.c
@@ -88,6 +88,31 @@ const struct GNUNET_CONFIGURATION_Handle *cfg;
static char *allow_methods;
/**
+ * Ego list
+ */
+static struct EgoEntry *ego_head;
+
+/**
+ * Ego list
+ */
+static struct EgoEntry *ego_tail;
+
+/**
+ * The processing state
+ */
+static int state;
+
+/**
+ * Handle to Identity service.
+ */
+static struct GNUNET_IDENTITY_Handle *identity_handle;
+
+/**
+ * Identity Provider
+ */
+static struct GNUNET_RECLAIM_Handle *idp;
+
+/**
* @brief struct returned by the initialization function of the plugin
*/
struct Plugin
@@ -129,15 +154,6 @@ struct EgoEntry
struct RequestHandle
{
- /**
- * Ego list
- */
- struct EgoEntry *ego_head;
-
- /**
- * Ego list
- */
- struct EgoEntry *ego_tail;
/**
* Selected ego
@@ -150,16 +166,6 @@ struct RequestHandle
struct GNUNET_CRYPTO_EcdsaPrivateKey priv_key;
/**
- * The processing state
- */
- int state;
-
- /**
- * Handle to Identity service.
- */
- struct GNUNET_IDENTITY_Handle *identity_handle;
-
- /**
* Rest connection
*/
struct GNUNET_REST_RequestHandle *rest_handle;
@@ -175,11 +181,6 @@ struct RequestHandle
struct GNUNET_IDENTITY_Operation *op;
/**
- * Identity Provider
- */
- struct GNUNET_RECLAIM_Handle *idp;
-
- /**
* Idp Operation
*/
struct GNUNET_RECLAIM_Operation *idp_op;
@@ -194,7 +195,6 @@ struct RequestHandle
*/
struct GNUNET_RECLAIM_AttestationIterator *attest_it;
-
/**
* Ticket iterator
*/
@@ -251,51 +251,31 @@ struct RequestHandle
* @param handle Handle to clean up
*/
static void
-cleanup_handle (struct RequestHandle *handle)
+cleanup_handle (void *cls)
{
- struct EgoEntry *ego_entry;
- struct EgoEntry *ego_tmp;
+ struct RequestHandle *handle = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cleaning up\n");
if (NULL != handle->resp_object)
json_decref (handle->resp_object);
if (NULL != handle->timeout_task)
GNUNET_SCHEDULER_cancel (handle->timeout_task);
- if (NULL != handle->identity_handle)
- GNUNET_IDENTITY_disconnect (handle->identity_handle);
if (NULL != handle->attr_it)
GNUNET_RECLAIM_get_attributes_stop (handle->attr_it);
if (NULL != handle->attest_it)
GNUNET_RECLAIM_get_attestations_stop (handle->attest_it);
if (NULL != handle->ticket_it)
GNUNET_RECLAIM_ticket_iteration_stop (handle->ticket_it);
- if (NULL != handle->idp)
- GNUNET_RECLAIM_disconnect (handle->idp);
if (NULL != handle->url)
GNUNET_free (handle->url);
if (NULL != handle->emsg)
GNUNET_free (handle->emsg);
if (NULL != handle->attr_list)
GNUNET_RECLAIM_attribute_list_destroy (handle->attr_list);
- for (ego_entry = handle->ego_head; NULL != ego_entry;)
- {
- ego_tmp = ego_entry;
- ego_entry = ego_entry->next;
- GNUNET_free (ego_tmp->identifier);
- GNUNET_free (ego_tmp->keystring);
- GNUNET_free (ego_tmp);
- }
GNUNET_free (handle);
}
-static void
-cleanup_handle_delayed (void *cls)
-{
- cleanup_handle (cls);
-}
-
-
/**
* Task run on error, sends error message. Cleans up everything.
*
@@ -316,7 +296,7 @@ do_error (void *cls)
resp = GNUNET_REST_create_response (json_error);
MHD_add_response_header (resp, "Content-Type", "application/json");
handle->proc (handle->proc_cls, resp, handle->response_code);
- GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+ GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
GNUNET_free (json_error);
}
@@ -339,9 +319,7 @@ do_timeout (void *cls)
static void
collect_error_cb (void *cls)
{
- struct RequestHandle *handle = cls;
-
- do_error (handle);
+ do_error (cls);
}
@@ -353,13 +331,14 @@ finished_cont (void *cls, int32_t success, const char *emsg)
resp = GNUNET_REST_create_response (emsg);
MHD_add_response_header (resp, "Content-Type", "application/json");
+ MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
if (GNUNET_OK != success)
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
- GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+ GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
}
@@ -370,13 +349,14 @@ delete_finished_cb (void *cls, int32_t success, const char *emsg)
struct MHD_Response *resp;
resp = GNUNET_REST_create_response (emsg);
+ MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
if (GNUNET_OK != success)
{
GNUNET_SCHEDULER_add_now (&do_error, handle);
return;
}
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
- GNUNET_SCHEDULER_add_now (&cleanup_handle_delayed, handle);
+ GNUNET_SCHEDULER_add_now (&cleanup_handle, handle);
}
@@ -395,6 +375,7 @@ return_response (void *cls)
result_str = json_dumps (handle->resp_object, 0);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result %s\n", result_str);
resp = GNUNET_REST_create_response (result_str);
+ MHD_add_response_header (resp, "Access-Control-Allow-Methods", allow_methods);
handle->proc (handle->proc_cls, resp, MHD_HTTP_OK);
GNUNET_free (result_str);
cleanup_handle (handle);
@@ -485,7 +466,7 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
identity = handle->url + strlen (
GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1;
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -523,9 +504,8 @@ add_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
*/
if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
GNUNET_RECLAIM_id_generate (&attribute->id);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
exp = GNUNET_TIME_UNIT_HOURS;
- handle->idp_op = GNUNET_RECLAIM_attestation_store (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_attestation_store (idp,
identity_priv,
attribute,
&exp,
@@ -644,7 +624,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
identity = handle->url + strlen (
GNUNET_REST_API_NS_RECLAIM_ATTESTATION) + 1;
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -659,8 +639,7 @@ list_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
- handle->attest_it = GNUNET_RECLAIM_get_attestations_start (handle->idp,
+ handle->attest_it = GNUNET_RECLAIM_get_attestations_start (idp,
priv_key,
&collect_error_cb,
handle,
@@ -713,7 +692,7 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -727,11 +706,10 @@ delete_attestation_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attestation));
GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
attr.name = "";
- handle->idp_op = GNUNET_RECLAIM_attestation_delete (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_attestation_delete (idp,
priv_key,
&attr,
&delete_finished_cb,
@@ -768,7 +746,7 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
}
identity = handle->url + strlen (GNUNET_REST_API_NS_IDENTITY_TICKETS) + 1;
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -782,9 +760,8 @@ list_tickets_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
handle->ticket_it =
- GNUNET_RECLAIM_ticket_iteration_start (handle->idp,
+ GNUNET_RECLAIM_ticket_iteration_start (idp,
priv_key,
&collect_error_cb,
handle,
@@ -823,7 +800,7 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
}
identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -862,9 +839,8 @@ add_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
*/
if (GNUNET_YES == GNUNET_RECLAIM_id_is_zero (&attribute->id))
GNUNET_RECLAIM_id_generate (&attribute->id);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
exp = GNUNET_TIME_UNIT_HOURS;
- handle->idp_op = GNUNET_RECLAIM_attribute_store (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_attribute_store (idp,
identity_priv,
attribute,
&exp,
@@ -1012,7 +988,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
}
identity = handle->url + strlen (GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES) + 1;
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -1027,8 +1003,7 @@ list_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
- handle->attr_it = GNUNET_RECLAIM_get_attributes_start (handle->idp,
+ handle->attr_it = GNUNET_RECLAIM_get_attributes_start (idp,
priv_key,
&collect_error_cb,
handle,
@@ -1078,7 +1053,7 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
if (0 == strcmp (identity, ego_entry->identifier))
break;
@@ -1092,11 +1067,10 @@ delete_attribute_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
priv_key = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
memset (&attr, 0, sizeof(struct GNUNET_RECLAIM_Attribute));
GNUNET_STRINGS_string_to_data (id, strlen (id), &attr.id, sizeof(attr.id));
attr.name = "";
- handle->idp_op = GNUNET_RECLAIM_attribute_delete (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_attribute_delete (idp,
priv_key,
&attr,
&delete_finished_cb,
@@ -1152,7 +1126,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
return;
}
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
{
GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
@@ -1169,8 +1143,7 @@ revoke_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
}
identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
- handle->idp = GNUNET_RECLAIM_connect (cfg);
- handle->idp_op = GNUNET_RECLAIM_ticket_revoke (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_ticket_revoke (idp,
identity_priv,
ticket,
&finished_cont,
@@ -1256,7 +1229,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
json_decref (data_json);
return;
}
- for (ego_entry = handle->ego_head; NULL != ego_entry;
+ for (ego_entry = ego_head; NULL != ego_entry;
ego_entry = ego_entry->next)
{
GNUNET_IDENTITY_ego_get_public_key (ego_entry->ego, &tmp_pk);
@@ -1273,8 +1246,7 @@ consume_ticket_cont (struct GNUNET_REST_RequestHandle *con_handle,
}
identity_priv = GNUNET_IDENTITY_ego_get_private_key (ego_entry->ego);
handle->resp_object = json_object ();
- handle->idp = GNUNET_RECLAIM_connect (cfg);
- handle->idp_op = GNUNET_RECLAIM_ticket_consume (handle->idp,
+ handle->idp_op = GNUNET_RECLAIM_ticket_consume (idp,
identity_priv,
ticket,
&consume_cont,
@@ -1308,55 +1280,6 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
/**
- * Handle rest request
- *
- * @param handle the request handle
- */
-static void
-init_cont (struct RequestHandle *handle)
-{
- struct GNUNET_REST_RequestHandlerError err;
- static const struct GNUNET_REST_RequestHandler handlers[] =
- { { MHD_HTTP_METHOD_GET,
- GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
- &list_attribute_cont },
- { MHD_HTTP_METHOD_POST,
- GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
- &add_attribute_cont },
- { MHD_HTTP_METHOD_DELETE,
- GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES,
- &delete_attribute_cont },
- { MHD_HTTP_METHOD_GET,
- GNUNET_REST_API_NS_RECLAIM_ATTESTATION,
- &list_attestation_cont },
- { MHD_HTTP_METHOD_POST,
- GNUNET_REST_API_NS_RECLAIM_ATTESTATION,
- &add_attestation_cont },
- { MHD_HTTP_METHOD_DELETE,
- GNUNET_REST_API_NS_RECLAIM_ATTESTATION,
- &delete_attestation_cont },
- { MHD_HTTP_METHOD_GET,
- GNUNET_REST_API_NS_IDENTITY_TICKETS,
- &list_tickets_cont },
- { MHD_HTTP_METHOD_POST,
- GNUNET_REST_API_NS_IDENTITY_REVOKE,
- &revoke_ticket_cont },
- { MHD_HTTP_METHOD_POST,
- GNUNET_REST_API_NS_IDENTITY_CONSUME,
- &consume_ticket_cont },
- { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
- GNUNET_REST_HANDLER_END };
-
- if (GNUNET_NO ==
- GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
- {
- handle->response_code = err.error_code;
- GNUNET_SCHEDULER_add_now (&do_error, handle);
- }
-}
-
-
-/**
* If listing is enabled, prints information about the egos.
*
* This function is initially called for all egos and then again
@@ -1395,52 +1318,126 @@ list_ego (void *cls,
void **ctx,
const char *identifier)
{
- struct RequestHandle *handle = cls;
struct EgoEntry *ego_entry;
struct GNUNET_CRYPTO_EcdsaPublicKey pk;
- if ((NULL == ego) && (ID_REST_STATE_INIT == handle->state))
+ if ((NULL == ego) && (ID_REST_STATE_INIT == state))
{
- handle->state = ID_REST_STATE_POST_INIT;
- init_cont (handle);
+ state = ID_REST_STATE_POST_INIT;
return;
}
- if (ID_REST_STATE_INIT == handle->state)
+ if (ID_REST_STATE_INIT == state)
{
ego_entry = GNUNET_new (struct EgoEntry);
GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
ego_entry->ego = ego;
ego_entry->identifier = GNUNET_strdup (identifier);
- GNUNET_CONTAINER_DLL_insert_tail (handle->ego_head,
- handle->ego_tail,
+ GNUNET_CONTAINER_DLL_insert_tail (ego_head,
+ ego_tail,
ego_entry);
}
+ /* Ego renamed or added */
+ if (identifier != NULL)
+ {
+ for (ego_entry = ego_head; NULL != ego_entry;
+ ego_entry = ego_entry->next)
+ {
+ if (ego_entry->ego == ego)
+ {
+ /* Rename */
+ GNUNET_free (ego_entry->identifier);
+ ego_entry->identifier = GNUNET_strdup (identifier);
+ break;
+ }
+ }
+ if (NULL == ego_entry)
+ {
+ /* Add */
+ ego_entry = GNUNET_new (struct EgoEntry);
+ GNUNET_IDENTITY_ego_get_public_key (ego, &pk);
+ ego_entry->keystring = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pk);
+ ego_entry->ego = ego;
+ ego_entry->identifier = GNUNET_strdup (identifier);
+ GNUNET_CONTAINER_DLL_insert_tail (ego_head,
+ ego_tail,
+ ego_entry);
+ }
+ }
+ else
+ {
+ /* Delete */
+ for (ego_entry = ego_head; NULL != ego_entry;
+ ego_entry = ego_entry->next)
+ {
+ if (ego_entry->ego == ego)
+ break;
+ }
+ if (NULL == ego_entry)
+ return; /* Not found */
+
+ GNUNET_CONTAINER_DLL_remove (ego_head,
+ ego_tail,
+ ego_entry);
+ GNUNET_free (ego_entry->identifier);
+ GNUNET_free (ego_entry->keystring);
+ GNUNET_free (ego_entry);
+ return;
+ }
+
}
-static void
+static enum GNUNET_GenericReturnValue
rest_identity_process_request (struct GNUNET_REST_RequestHandle *rest_handle,
GNUNET_REST_ResultProcessor proc,
void *proc_cls)
{
struct RequestHandle *handle = GNUNET_new (struct RequestHandle);
+ struct GNUNET_REST_RequestHandlerError err;
+ static const struct GNUNET_REST_RequestHandler handlers[] =
+ { { MHD_HTTP_METHOD_GET,
+ GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &list_attribute_cont },
+ { MHD_HTTP_METHOD_POST,
+ GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &add_attribute_cont },
+ { MHD_HTTP_METHOD_DELETE,
+ GNUNET_REST_API_NS_RECLAIM_ATTRIBUTES, &delete_attribute_cont },
+ { MHD_HTTP_METHOD_GET,
+ GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &list_attestation_cont },
+ { MHD_HTTP_METHOD_POST,
+ GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &add_attestation_cont },
+ { MHD_HTTP_METHOD_DELETE,
+ GNUNET_REST_API_NS_RECLAIM_ATTESTATION, &delete_attestation_cont },
+ { MHD_HTTP_METHOD_GET,
+ GNUNET_REST_API_NS_IDENTITY_TICKETS, &list_tickets_cont },
+ { MHD_HTTP_METHOD_POST,
+ GNUNET_REST_API_NS_IDENTITY_REVOKE, &revoke_ticket_cont },
+ { MHD_HTTP_METHOD_POST,
+ GNUNET_REST_API_NS_IDENTITY_CONSUME, &consume_ticket_cont },
+ { MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_RECLAIM, &options_cont },
+ GNUNET_REST_HANDLER_END
+ };
handle->response_code = 0;
handle->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
handle->proc_cls = proc_cls;
handle->proc = proc;
- handle->state = ID_REST_STATE_INIT;
+ state = ID_REST_STATE_INIT;
handle->rest_handle = rest_handle;
handle->url = GNUNET_strdup (rest_handle->url);
if (handle->url[strlen (handle->url) - 1] == '/')
handle->url[strlen (handle->url) - 1] = '\0';
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting...\n");
- handle->identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, handle);
+ if (GNUNET_NO ==
+ GNUNET_REST_handle_request (handle->rest_handle, handlers, &err, handle))
+ {
+ cleanup_handle (handle);
+ return GNUNET_NO;
+ }
+
handle->timeout_task =
GNUNET_SCHEDULER_add_delayed (handle->timeout, &do_timeout, handle);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected\n");
+ return GNUNET_YES;
}
@@ -1472,7 +1469,8 @@ libgnunet_plugin_rest_reclaim_init (void *cls)
MHD_HTTP_METHOD_PUT,
MHD_HTTP_METHOD_DELETE,
MHD_HTTP_METHOD_OPTIONS);
-
+ identity_handle = GNUNET_IDENTITY_connect (cfg, &list_ego, NULL);
+ idp = GNUNET_RECLAIM_connect (cfg);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_ ("Identity Provider REST API initialized\n"));
return api;
@@ -1490,8 +1488,22 @@ libgnunet_plugin_rest_reclaim_done (void *cls)
{
struct GNUNET_REST_Plugin *api = cls;
struct Plugin *plugin = api->cls;
+ struct EgoEntry *ego_entry;
+ struct EgoEntry *ego_tmp;
plugin->cfg = NULL;
+ if (NULL != idp)
+ GNUNET_RECLAIM_disconnect (idp);
+ if (NULL != identity_handle)
+ GNUNET_IDENTITY_disconnect (identity_handle);
+ for (ego_entry = ego_head; NULL != ego_entry;)
+ {
+ ego_tmp = ego_entry;
+ ego_entry = ego_entry->next;
+ GNUNET_free (ego_tmp->identifier);
+ GNUNET_free (ego_tmp->keystring);
+ GNUNET_free (ego_tmp);
+ }
GNUNET_free (allow_methods);
GNUNET_free (api);
diff --git a/src/reclaim/reclaim_api.c b/src/reclaim/reclaim_api.c
index ff549fa71..d73241a6f 100644
--- a/src/reclaim/reclaim_api.c
+++ b/src/reclaim/reclaim_api.c
@@ -1572,6 +1572,8 @@ GNUNET_RECLAIM_ticket_consume (
ctm->ticket = *ticket;
if (NULL != h->mq)
GNUNET_MQ_send_copy (h->mq, op->env);
+ else
+ reconnect(h);
return op;
}