-fix idp
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Tue, 30 May 2017 11:50:07 +0000 (13:50 +0200)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Tue, 30 May 2017 11:50:07 +0000 (13:50 +0200)
src/credential/credential_api.c
src/credential/gnunet-credential.c
src/credential/plugin_rest_credential.c
src/identity-provider/gnunet-service-identity-provider.c
src/identity-provider/plugin_rest_identity_provider.c
src/include/gnunet_credential_service.h

index fd0c9e3d53bab989388e6f4a3a34286f55d8b042..ca54137add34139cc5fcc99ea8e6bc27666f76f0 100644 (file)
@@ -348,7 +348,7 @@ GNUNET_CREDENTIAL_disconnect (struct GNUNET_CREDENTIAL_Handle *handle)
  * @param lr the verify request to cancel
  */
 void
-GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr)
+GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *vr)
 {
   struct GNUNET_CREDENTIAL_Handle *handle = vr->credential_handle;
 
index 92804c97a7749cd7832843cc048f0150b816e9bd..4a6dc5ccdfaf9eb9d730d9cad3ea28dab498dfbd 100644 (file)
@@ -130,7 +130,7 @@ do_shutdown (void *cls)
 {
   if (NULL != verify_request)
   {
-    GNUNET_CREDENTIAL_verify_cancel (verify_request);
+    GNUNET_CREDENTIAL_request_cancel (verify_request);
     verify_request = NULL;
   }
   if (NULL != credential)
index 59022e794457f9e4a4c52ad6165ad96c9011d853..48d48fba0f17a10cc7684f657394bf67c69a6426 100644 (file)
@@ -177,7 +177,7 @@ cleanup_handle (struct RequestHandle *handle)
   if (NULL != handle->subject_attr)
     GNUNET_free (handle->subject_attr);
   if (NULL != handle->verify_request)
-    GNUNET_CREDENTIAL_verify_cancel (handle->verify_request);
+    GNUNET_CREDENTIAL_request_cancel (handle->verify_request);
   if (NULL != handle->credential)
     GNUNET_CREDENTIAL_disconnect (handle->credential);
   if (NULL != handle->id_op)
index f9e06fef9c0f9c876e4917aa10cf4940c0c0dabc..f4ea352d4bd6a48325a561e237b8825a1ffed7f6 100644 (file)
@@ -1015,6 +1015,10 @@ cleanup_issue_handle (struct IssueHandle *handle)
     ticket_destroy (handle->ticket);
   if (NULL != handle->label)
     GNUNET_free (handle->label);
+  if (NULL != handle->ns_it)
+    GNUNET_NAMESTORE_zone_iteration_stop (handle->ns_it);
+  if (NULL != handle->credential_request)
+    GNUNET_CREDENTIAL_request_cancel (handle->credential_request);
   GNUNET_free (handle);
 }
 
@@ -1484,160 +1488,6 @@ handle_exchange_message (void *cls,
 
 }
 
-
-static void
-find_existing_token_error (void *cls)
-{
-  struct IssueHandle *handle = cls;
-  cleanup_issue_handle (handle);
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error looking for existing token\n");
-  GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
-}
-
-
-static void
-find_existing_token_finished (void *cls)
-{
-  struct IssueHandle *handle = cls;
-  uint64_t rnd_key;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              ">>> No existing token found\n");
-  rnd_key =
-    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
-                              UINT64_MAX);
-  GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
-                                sizeof (uint64_t),
-                                &handle->label);
-  handle->ns_it = NULL;
-  handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
-                                                         &handle->iss_key,
-                                                         &attr_collect_error,
-                                                         handle,
-                                                         &attr_collect,
-                                                         handle,
-                                                         &attr_collect_finished,
-                                                         handle);
-}
-
-
-/**
- *
- * Look for existing token
- *
- * @param cls the identity entry
- * @param zone the identity
- * @param lbl the name of the record
- * @param rd_count number of records
- * @param rd record data
- *
- */
-static void
-find_existing_token (void *cls,
-                     const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone,
-                     const char *lbl,
-                     unsigned int rd_count,
-                     const struct GNUNET_GNSRECORD_Data *rd)
-{
-  struct IssueHandle *handle = cls;
-  const struct GNUNET_GNSRECORD_Data *token_metadata_record;
-  struct GNUNET_CRYPTO_EcdsaPublicKey *aud_key;
-  struct GNUNET_HashCode key;
-  int scope_count_token;
-  char *scope;
-  char *tmp_scopes;
-
-  //There should be only a single record for a token under a label
-  if (2 != rd_count)
-  {
-    GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
-    return;
-  }
-
-  if (rd[0].record_type == GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
-  {
-    token_metadata_record = &rd[0];
-  }
-  else
-  {
-    token_metadata_record = &rd[1];
-  }
-  if (token_metadata_record->record_type != GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA)
-  {
-    GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
-    return;
-  }
-  ecdhe_privkey = *((struct GNUNET_CRYPTO_EcdhePrivateKey *)token_metadata_record->data);
-  aud_key =
-    (struct GNUNET_CRYPTO_EcdsaPublicKey *)(token_metadata_record->data+sizeof(struct GNUNET_CRYPTO_EcdhePrivateKey));
-  tmp_scopes = GNUNET_strdup ((char*) aud_key+sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
-
-  if (0 != memcmp (aud_key, &handle->aud_key,
-                   sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))
-  {
-    char *tmp2 = GNUNET_STRINGS_data_to_string_alloc (aud_key,
-                                                      sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey));
-    //Audience does not match!
-    char *tmp = GNUNET_GNSRECORD_value_to_string (GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA,
-                                                  token_metadata_record->data,
-                                                  token_metadata_record->data_size);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Token does not match audience %s vs %s. Moving on\n",
-                tmp2,
-                tmp);
-    GNUNET_free (tmp_scopes);
-    GNUNET_free (tmp2);
-    GNUNET_free (tmp);
-    GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
-    return;
-  }
-
-  scope = strtok (tmp_scopes, ",");
-  scope_count_token = 0;
-  while (NULL != scope)
-  {
-    GNUNET_CRYPTO_hash (scope,
-                        strlen (scope),
-                        &key);
-
-    if ((NULL != handle->attr_map) &&
-        (GNUNET_YES != GNUNET_CONTAINER_multihashmap_contains (handle->attr_map, &key)))
-    {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Issued token does not include `%s'. Moving on\n", scope);
-      GNUNET_free (tmp_scopes);
-      GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
-      return;
-    }
-    scope_count_token++;
-    scope = strtok (NULL, ",");
-  }
-  GNUNET_free (tmp_scopes);
-  //All scopes in token are also in request. Now
-  //Check length
-  if ((NULL != handle->attr_map) &&
-      (GNUNET_CONTAINER_multihashmap_size (handle->attr_map) == scope_count_token))
-  {
-    //We have an existing token
-    handle->label = GNUNET_strdup (lbl);
-    handle->ns_it = NULL;
-    handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
-                                                           &handle->iss_key,
-                                                           &attr_collect_error,
-                                                           handle,
-                                                           &attr_collect,
-                                                           handle,
-                                                           &attr_collect_finished,
-                                                           handle);
-
-    return;
-  }
-  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-              "Nuber of attributes in token do not match request\n");
-  //No luck
-  GNUNET_NAMESTORE_zone_iterator_next (handle->ns_it);
-}
-
 /**
  * Checks an issue message
  *
@@ -1684,6 +1534,7 @@ handle_issue_message (void *cls,
   char *scopes_tmp;
   char *scope;
   const char *v_attrs;
+  uint64_t rnd_key;
   struct GNUNET_HashCode key;
   struct IssueHandle *issue_handle;
   struct VerifiedAttributeEntry *vattr_entry;
@@ -1733,14 +1584,20 @@ handle_issue_message (void *cls,
   issue_handle->scopes = GNUNET_strdup (scopes);
   issue_handle->token = token_create (&issue_handle->iss_pkey,
                                       &issue_handle->aud_key);
+  rnd_key =
+    GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_STRONG,
+                              UINT64_MAX);
+  GNUNET_STRINGS_base64_encode ((char*)&rnd_key,
+                                sizeof (uint64_t),
+                                &issue_handle->label);
 
   issue_handle->ns_it = GNUNET_NAMESTORE_zone_iteration_start (ns_handle,
-                                                               &im->iss_key,
-                                                               &find_existing_token_error,
+                                                               &issue_handle->iss_key,
+                                                               &attr_collect_error,
                                                                issue_handle,
-                                                               &find_existing_token,
+                                                               &attr_collect,
                                                                issue_handle,
-                                                               &find_existing_token_finished,
+                                                               &attr_collect_finished,
                                                                issue_handle);
 }
 
index 5ea7b28219f97903f1407f9f8ca6ada23114cb75..dfb935f5babc2e8b13bb90204300b03a5571f051 100644 (file)
@@ -402,6 +402,8 @@ token_creat_cont (void *cls,
   char *ticket_str;
   char *token_str;
   char *result_str;
+  
+  handle->idp_op = NULL;
 
   if (NULL == ticket)
   {
index 6c9b477ea625ba1e52f4c118e1ccbe451eb4b13f..67c2f2b4c64ac838fa3e893065e4df981f6ff110 100644 (file)
@@ -377,7 +377,7 @@ GNUNET_CREDENTIAL_credential_issue (
  * @param lr the lookup request to cancel
  */
 void
-GNUNET_CREDENTIAL_verify_cancel (struct GNUNET_CREDENTIAL_Request *vr);
+GNUNET_CREDENTIAL_request_cancel (struct GNUNET_CREDENTIAL_Request *vr);
 
 
 #if 0                           /* keep Emacsens' auto-indent happy */