summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2022-04-11 17:06:39 +0200
committerTristan Schwieren <tristan.schwieren@tum.de>2022-04-11 17:06:39 +0200
commit4034e9e342c02665b768452948eef5e852f719ad (patch)
tree7cf784cca3871947fb338c2c59564617f9a562e3
parent1e15a2f6487ab616cec7e62356d7e8a2dcb33144 (diff)
-not working file write/read
-rw-r--r--src/reclaim/plugin_rest_openid_connect.c57
1 files changed, 53 insertions, 4 deletions
diff --git a/src/reclaim/plugin_rest_openid_connect.c b/src/reclaim/plugin_rest_openid_connect.c
index 230d0d638..1d8ae4681 100644
--- a/src/reclaim/plugin_rest_openid_connect.c
+++ b/src/reclaim/plugin_rest_openid_connect.c
@@ -309,6 +309,11 @@ struct Plugin
};
/**
+ * @brief The RSA key used by the oidc enpoint
+ */
+json_t oidc_rsa_key;
+
+/**
* OIDC needed variables
*/
struct OIDC_Variables
@@ -2481,6 +2486,42 @@ userinfo_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
}
/**
+ * Read a jwk from file. Parses the file an created the
+ * respective json_t key in memeory
+ * TODO: change description
+ * Return -1 if file does not exist or does not contain a valid JWK RSA key
+ *
+ * @param filename name of the file to parse
+ * @param jwk parsed jwk
+ * @return #GNUNET_OK to continue
+ */
+static int
+read_jwk_from_file(const char *filename,
+ json_t *jwk)
+{
+ json_error_t *error;
+
+ jwk = json_load_file(filename, JSON_DECODE_ANY, error);
+
+ // Check if valid key
+
+ if(NULL != error) {
+ printf("%s", error);
+ return GNUNET_ERROR_TYPE_ERROR;
+ }
+
+ return GNUNET_OK;
+}
+
+static int
+write_jwk_to_file(const char *filename,
+ json_t *jwk)
+{
+
+ return GNUNET_OK;
+}
+
+/**
* Responds to /jwks.json
*
* @param con_handle the connection handle
@@ -2493,15 +2534,19 @@ jwks_endpoint (struct GNUNET_REST_RequestHandle *con_handle,
void *cls)
{
// TODO: Set json application type header
- json_t *jwks;
+ json_t *jwk;
char *jwk_str;
struct MHD_Response *resp;
struct RequestHandle *handle = cls;
// Generate RSA key
- json_t *jwk = json_pack("{s:s,s:i}", "kty", "RSA", "bits", 2048);
- jose_jwk_gen(NULL, jwk);
- jose_jwk_pub(NULL, jwk);
+ // jwk = json_pack("{s:s,s:i}", "kty", "RSA", "bits", 2048);
+ // jose_jwk_gen(NULL, jwk);
+ // jose_jwk_pub(NULL, jwk);
+
+ // Read from file
+ const char *filename = "/home/tristan/rsa.json";
+ read_jwk_from_file(filename, jwk);
jwk_str = json_dumps (jwk, JSON_INDENT (1));
resp = GNUNET_REST_create_response (jwk_str);
@@ -2831,6 +2876,10 @@ libgnunet_plugin_rest_openid_connect_init (void *cls)
MHD_HTTP_METHOD_DELETE,
MHD_HTTP_METHOD_OPTIONS);
+ // TODO: Check if config file with rss key exists
+ // TODO: If not: generate new key and save in in file
+ // TODO: READ config file and save key
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
_ ("OpenID Connect REST API initialized\n"));
return api;