commit 79b95dc36829e5e99a9bd30082eb1f7836bd059f
parent 26758b7a397aa9872e50beb949d87d4f030bf86f
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 6 May 2023 19:33:20 +0200
-implement common logic
Diffstat:
1 file changed, 47 insertions(+), 15 deletions(-)
diff --git a/src/challenger/challenger-httpd_common.c b/src/challenger/challenger-httpd_common.c
@@ -62,9 +62,37 @@ CH_compute_code (const struct CHALLENGER_ValidationNonceP *nonce,
const char *address,
const char *client_redirect_url)
{
- // FIXME: compute HKDF over inputs here!!!
- GNUNET_break (0); // FIXME: insecure!
- return "access-granted";
+ char *code;
+ char *ns;
+ char *hs;
+ struct GNUNET_ShortHashCode h;
+
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CRYPTO_kdf (&h,
+ sizeof (h),
+ nonce,
+ sizeof (nonce),
+ client_secret,
+ strlen (client_secret),
+ client_scope,
+ strlen (client_scope),
+ address,
+ strlen (address),
+ client_redirect_url,
+ strlen (client_redirect_url),
+ NULL,
+ 0));
+ ns = GNUNET_STRINGS_data_to_string_alloc (&nonce,
+ sizeof (nonce));
+ hs = GNUNET_STRINGS_data_to_string_alloc (&h,
+ sizeof (h));
+ GNUNET_asprintf (&code,
+ "%s-%s",
+ ns,
+ hs);
+ GNUNET_free (ns);
+ GNUNET_free (hs);
+ return code;
}
@@ -72,17 +100,21 @@ enum GNUNET_GenericReturnValue
CH_code_to_nonce (const char *code,
struct CHALLENGER_ValidationNonceP *nonce)
{
- GNUNET_break (0); // FIXME: not implemented
- return GNUNET_SYSERR;
-}
-
+ const char *dash = strchr (code, '-');
-char *
-CH_compute_token (const struct CHALLENGER_ValidationNonceP *nonce,
- const char *client_secret,
- const char *client_redirect_url)
-{
- // FIXME: compute HKDF over inputs here!!!
- GNUNET_break (0); // FIXME: insecure!
- return "grant-token";
+ if (NULL == dash)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK !=
+ GNUNET_STRINGS_string_to_data (code,
+ dash - code,
+ nonce,
+ sizeof (*nonce)))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
}