add tld handling from config
authorSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 29 Sep 2018 08:39:02 +0000 (10:39 +0200)
committerSchanzenbach, Martin <mschanzenbach@posteo.de>
Sat, 29 Sep 2018 08:39:02 +0000 (10:39 +0200)
src/rest-plugins/plugin_rest_openid_connect.c

index 2bb60efce63ff1bf91d84be7ef31564f50b68508..2bcf576fb2847e9a88dd3cfe6c2162ee828c6e44 100644 (file)
@@ -1204,6 +1204,33 @@ build_authz_response (void *cls)
   GNUNET_SCHEDULER_add_now(&login_redirection,handle);
 }
 
+/**
+ * Iterate over tlds in config
+ */
+static void
+tld_iter (void *cls,
+          const char *section,
+          const char *option,
+          const char *value)
+{
+  struct RequestHandle *handle = cls;
+  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
+
+  if (GNUNET_OK !=
+      GNUNET_CRYPTO_ecdsa_public_key_from_string (value,
+                                                  strlen (value),
+                                                  &pkey))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Skipping non key %s\n",
+                value);
+    return;
+  }
+  if ( 0 == memcmp (&pkey, &handle->oidc->client_pkey,
+                    sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)) )
+    handle->tld = GNUNET_strdup (option+1);
+}
+
 /**
  * Responds to authorization GET and url-encoded POST request
  *
@@ -1287,7 +1314,14 @@ authorize_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
       handle->tld = GNUNET_strdup (tmp_ego->identifier);
       handle->ego_entry = handle->ego_tail;
     }
-  } 
+  }
+  if (NULL == handle->tld)
+    GNUNET_CONFIGURATION_iterate_section_values (cfg,
+                                                 "gns",
+                                                 tld_iter,
+                                                 handle);
+  if (NULL == handle->tld)
+    handle->tld = GNUNET_strdup (tmp_ego->keystring);
   GNUNET_SCHEDULER_add_now (&build_authz_response, handle);
 }