paivana

HTTP paywall reverse proxy
Log | Files | Refs | README | LICENSE

commit 7b1a8c6bd79cc2c4065536c6339a912c7b2d318f
parent ba6d5c2a38a29e928e0878c2b8130b761040a0d0
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 19 Apr 2026 23:59:27 +0200

align cookie computation with spec

Diffstat:
Msrc/backend/paivana-httpd.c | 4++--
Msrc/backend/paivana-httpd_cookie.c | 23+++++++++++++++--------
Msrc/backend/paivana-httpd_cookie.h | 6+++++-
Msrc/backend/paivana-httpd_pay.c | 7+++----
4 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/src/backend/paivana-httpd.c b/src/backend/paivana-httpd.c @@ -38,8 +38,6 @@ #include "paivana_pd.h" -/* *********************** Globals **************************** */ - struct RequestContext { @@ -218,7 +216,9 @@ create_response (void *cls, ca_len = 0; break; } + /* FIXME: url vs. full path to the website? Which should we use? */ ok = PAIVANA_HTTPD_check_cookie (cookie, + url, ca_len, ca); if (! ok) diff --git a/src/backend/paivana-httpd_cookie.c b/src/backend/paivana-httpd_cookie.c @@ -40,22 +40,25 @@ struct GNUNET_HashCode paivana_secret; /** - * Compute access cookie hash for the given @a expiration and @a ca. + * Compute access cookie hash for the given @a cur_time, the + * @a website and @a ca. * - * @param expiration expiration time of the cookie + * @param cur_time current time used in the cookie + * @param website URL the cookie is valid for * @param ca_len number of bytes in @a ca - * @param ca client address + * @param ca client (IP) address * @param[out] c set to the cookie hash */ static void -compute_cookie_hash (struct GNUNET_TIME_Timestamp expiration, +compute_cookie_hash (struct GNUNET_TIME_Timestamp cur_time, + const char *website, size_t ca_len, const void *ca, struct GNUNET_HashCode *c) { struct GNUNET_TIME_AbsoluteNBO e; - e = GNUNET_TIME_absolute_hton (expiration.abs_time); + e = GNUNET_TIME_absolute_hton (cur_time.abs_time); GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_hkdf_gnunet ( c, /* result */ @@ -71,6 +74,7 @@ compute_cookie_hash (struct GNUNET_TIME_Timestamp expiration, bool PAIVANA_HTTPD_check_cookie (const char *cookie, + const char *website, size_t ca_len, const void *ca) { @@ -100,6 +104,7 @@ PAIVANA_HTTPD_check_cookie (const char *cookie, sizeof (c))) return false; compute_cookie_hash (a, + website, ca_len, ca, &h); @@ -110,7 +115,8 @@ PAIVANA_HTTPD_check_cookie (const char *cookie, char * -PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp expiration, +PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp cur_time, + const char *website, size_t ca_len, const void *ca) { @@ -119,7 +125,8 @@ PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp expiration, char cstr[128]; char *res; - compute_cookie_hash (expiration, + compute_cookie_hash (cur_time, + website, ca_len, ca, &h); @@ -131,7 +138,7 @@ PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp expiration, GNUNET_asprintf ( &res, "%llu-%s", - (unsigned long long) (expiration.abs_time.abs_value_us / 1000LLU / 1000LLU), + (unsigned long long) (cur_time.abs_time.abs_value_us / 1000LLU / 1000LLU), cstr); return res; } diff --git a/src/backend/paivana-httpd_cookie.h b/src/backend/paivana-httpd_cookie.h @@ -51,12 +51,14 @@ struct PAIVANA_Nonce * Check if the given cookie currently grants access. * * @param cookie the cookie + * @param website URL of the site the cookie is for * @param ca_len number of bytes in @a ca * @param ca client address * @return true if the cookie is OK */ bool PAIVANA_HTTPD_check_cookie (const char *cookie, + const char *website, size_t ca_len, const void *ca); @@ -64,12 +66,14 @@ PAIVANA_HTTPD_check_cookie (const char *cookie, * Compute access cookie hash for the given @a expiration and @a ca. * * @param expiration expiration time of the cookie + * @param website URL of the site the cookie is for * @param ca_len number of bytes in @a ca * @param ca client address * @param[out] c set to the cookie hash */ char * -PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp expiration, +PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp cur_time, + const char *website, size_t ca_len, const void *ca); diff --git a/src/backend/paivana-httpd_pay.c b/src/backend/paivana-httpd_pay.c @@ -168,8 +168,6 @@ order_status_cb (struct PayRequest *ph, const union MHD_ConnectionInfo *ci; const struct sockaddr *ca; socklen_t ca_len; - // FIXME: relationship of expiration to ph->cur_time? - struct GNUNET_TIME_Timestamp expiration; char *cookie; struct MHD_Response *resp; @@ -193,9 +191,10 @@ order_status_cb (struct PayRequest *ph, ca_len = 0; break; } - // FIXME: include website + nonce + cur_time somehow!! + // FIXME: check paivana_id / nonce matches! // => TALER_EC_PAIVANA_WRONG_ORDER with 409! - cookie = PAIVANA_HTTPD_compute_cookie (expiration, + cookie = PAIVANA_HTTPD_compute_cookie (ph->cur_time, + ph->website, ca_len, ca); resp = MHD_create_response_from_buffer (0,