From 83f0cd871092dcd547eee18c2b67ec10ac1828ff Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 31 Jan 2021 13:12:04 +0100 Subject: implement import of auth_token into merchant DB when configuring instances (#6731) --- src/backend/taler-merchant-httpd.c | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'src/backend/taler-merchant-httpd.c') diff --git a/src/backend/taler-merchant-httpd.c b/src/backend/taler-merchant-httpd.c index bf1c4db3..6e6318d2 100644 --- a/src/backend/taler-merchant-httpd.c +++ b/src/backend/taler-merchant-httpd.c @@ -172,6 +172,53 @@ struct ResumeData }; +int +TMH_check_auth (const char *token, + const struct GNUNET_ShortHashCode *salt, + const struct GNUNET_HashCode *hash) +{ + struct GNUNET_HashCode val; + + GNUNET_assert (GNUNET_YES == + GNUNET_CRYPTO_kdf (&val, + sizeof (val), + salt, + sizeof (*salt), + token, + strlen (token), + "merchant-instance-auth", + strlen ("merchant-instance-auth"), + NULL, + 0)); + return (0 == GNUNET_memcmp (&val, + hash)) + ? GNUNET_OK + : GNUNET_SYSERR; +} + + +void +TMH_compute_auth (const char *token, + struct GNUNET_ShortHashCode *salt, + struct GNUNET_HashCode *hash) +{ + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + salt, + sizeof (*salt)); + GNUNET_assert (GNUNET_YES == + GNUNET_CRYPTO_kdf (hash, + sizeof (*hash), + salt, + sizeof (*salt), + token, + strlen (token), + "merchant-instance-auth", + strlen ("merchant-instance-auth"), + NULL, + 0)); +} + + /** * Decrement reference counter of @a mi, and free if it hits zero. * -- cgit v1.2.3