paivana

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

paivana-httpd_cookie.h (3435B)


      1 /*
      2      This file is part of GNUnet.
      3      Copyright (C) 2026 Taler Systems SA
      4 
      5      Paivana is free software; you can redistribute it and/or
      6      modify it under the terms of the GNU Affero General Public License
      7      as published by the Free Software Foundation; either version
      8      3, or (at your option) any later version.
      9 
     10      Paivana is distributed in the hope that it will be useful,
     11      but WITHOUT ANY WARRANTY; without even the implied warranty
     12      of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13      the GNU Affero General Public License for more details.
     14 
     15      You should have received a copy of the GNU Affero General Public
     16      License along with Paivana; see the file COPYING.  If not,
     17      write to the Free Software Foundation, Inc., 51 Franklin
     18      Street, Fifth Floor, Boston, MA 02110-1301, USA.
     19 */
     20 
     21 /**
     22  * @author Christian Grothoff
     23  * @file paivana-httpd_cookie.h
     24  *
     25  * @brief cookie generation and verification logic
     26  */
     27 #ifndef PAIVANA_HTTPD_COOKIE_H
     28 #define PAIVANA_HTTPD_COOKIE_H
     29 
     30 #include <gnunet/gnunet_util_lib.h>
     31 
     32 /**
     33  * Name of the cookie in which we hand the access token to the
     34  * client.  It is a credential for *paivana*, not for the site we
     35  * proxy, and thus must never be relayed upstream.
     36  */
     37 #define PAIVANA_COOKIE_NAME "Paivana-Cookie"
     38 
     39 /**
     40  * Secret for the cookie generation.
     41  */
     42 extern struct GNUNET_HashCode paivana_secret;
     43 
     44 
     45 /**
     46  * Nonce generated client-side in Paivana protocol.
     47  */
     48 struct PAIVANA_Nonce
     49 {
     50   /**
     51    * Some 128-bit value.
     52    */
     53   uint32_t val[4];
     54 };
     55 
     56 
     57 /**
     58  * Check if the given cookie currently grants access.
     59  *
     60  * @param cookie the cookie
     61  * @param website URL of the site the cookie is for
     62  * @param ca_len number of bytes in @a ca
     63  * @param ca client address
     64  * @return true if the cookie is OK
     65  */
     66 bool
     67 PAIVANA_HTTPD_check_cookie (const char *cookie,
     68                             const char *website,
     69                             size_t ca_len,
     70                             const void *ca);
     71 
     72 /**
     73  * Compute the `Set-Cookie` line granting access to @a website until
     74  * @a expiration for a client at @a ca.
     75  *
     76  * The `Path` attribute is scoped to @a website (unless
     77  * #PH_global_cookie), percent-encoded so that it path-matches the
     78  * request URI the browser will send (RFC 6265 section 5.1.4), and
     79  * falls back to "/" for a path that RFC 6265 section 4.1.1 cannot
     80  * express.  `Secure` follows #PH_base_url where that is configured.
     81  *
     82  * @param expiration expiration time of the cookie
     83  * @param website URL of the site the cookie is for
     84  * @param ca_len number of bytes in @a ca
     85  * @param ca client address
     86  * @return the value for the `Set-Cookie` header; the caller must free
     87  */
     88 char *
     89 PAIVANA_HTTPD_compute_cookie (struct GNUNET_TIME_Timestamp expiration,
     90                               const char *website,
     91                               size_t ca_len,
     92                               const void *ca);
     93 
     94 
     95 /**
     96  * Compute the Paivana ID for the given @a expiration,
     97  * @a website and @a nonce.
     98  *
     99  * @param expiration end of access, as chosen by the client and bounded
    100  *        by the contract's `max_pickup_time`
    101  * @param website website to be accessed
    102  * @param nonce client-selected nonce
    103  * @return corresponding Paivana ID.
    104  */
    105 char *
    106 PAIVANA_HTTPD_compute_paivana_id (struct GNUNET_TIME_Timestamp expiration,
    107                                   const char *website,
    108                                   const struct PAIVANA_Nonce *nonce);
    109 
    110 
    111 #endif