donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

donau-httpd_keys.h (5928B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2023-2024 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11   A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file donau-httpd_keys.h
     18  * @brief management of our various keys
     19  * @author Christian Grothoff
     20  */
     21 #include <donau_config.h>
     22 #include <taler/taler_json_lib.h>
     23 #include <taler/taler_mhd_lib.h>
     24 #include "donau_util.h"
     25 #include "donaudb_plugin.h"
     26 #include "donau-httpd.h"
     27 
     28 #ifndef DONAU_HTTPD_KEYS_H
     29 #define DONAU_HTTPD_KEYS_H
     30 
     31 
     32 /**
     33  * @brief All information about a donation unit key (which is used to
     34  * sign donation receipts into existence).
     35  */
     36 struct DH_DonationUnitKey
     37 {
     38 
     39   /**
     40    * Hash code of the donation unit public key.
     41    */
     42   struct DONAU_DonationUnitHashP h_donation_unit_pub;
     43 
     44   /**
     45    * Decoded donation unit public key (the hash of it is in
     46    * @e issue, but we sometimes need the full public key as well).
     47    */
     48   struct DONAU_DonationUnitPublicKey donation_unit_pub;
     49 
     50   /**
     51    * The validity year.
     52    */
     53   uint64_t validity_year;
     54 
     55   /**
     56    * Value that the donation unit represents.
     57    */
     58   struct TALER_Amount value;
     59 
     60   /**
     61    * Did we lose the private keys?
     62    */
     63   bool lost;
     64 
     65 };
     66 
     67 /**
     68  * Information needed to create a blind signature.
     69  */
     70 struct DH_BlindSignData
     71 {
     72   /**
     73    * Hash of key to sign with.
     74    */
     75   const struct DONAU_DonationUnitHashP *h_du_pub;
     76 
     77   /**
     78    * Blinded planchet to sign over.
     79    */
     80   const struct DONAU_BlindedUniqueDonorIdentifier *budi;
     81 };
     82 
     83 /**
     84  * Sign the message in @a purpose with the doanu's signing key.
     85  *
     86  * The @a purpose data is the beginning of the data of which the signature is
     87  * to be created. The `size` field in @a purpose must correctly indicate the
     88  * number of bytes of the data structure, including its header.  Use
     89  * #DH_keys_doanu_sign() instead of calling this function directly!
     90  *
     91  * @param purpose the message to sign
     92  * @param[out] pub set to the current public signing key of the doanu
     93  * @param[out] sig signature over purpose using current signing key
     94  * @return #TALER_EC_NONE on success
     95  */
     96 enum TALER_ErrorCode
     97 DH_keys_donau_sign_ (
     98   const struct GNUNET_CRYPTO_SignaturePurpose *purpose,
     99   struct DONAU_DonauPublicKeyP *pub,
    100   struct DONAU_DonauSignatureP *sig);
    101 
    102 /**
    103  * @ingroup crypto
    104  * @brief EdDSA sign a given block.
    105  *
    106  * The @a ps data must be a fixed-size struct for which the signature is to be
    107  * created. The `size` field in @a ps->purpose must correctly indicate the
    108  * number of bytes of the data structure, including its header.
    109  *
    110  * @param ps packed struct with what to sign, MUST begin with a purpose
    111  * @param[out] pub where to store the public key to use for the signing
    112  * @param[out] sig where to write the signature
    113  * @return #TALER_EC_NONE on success
    114  */
    115 #define DH_keys_donau_sign(ps,pub,sig) \
    116         ({                                                  \
    117     /* check size is set correctly */                 \
    118     GNUNET_assert (htonl ((ps)->purpose.size) ==      \
    119                    sizeof (*ps));                     \
    120     /* check 'ps' begins with the purpose */          \
    121     GNUNET_static_assert (((void*) (ps)) ==           \
    122                           ((void*) &(ps)->purpose));  \
    123     DH_keys_donau_sign_ (&(ps)->purpose,              \
    124                          pub,                         \
    125                          sig);                        \
    126   })
    127 
    128 /**
    129  * Resumes all suspended /keys requests, we may now have key material
    130  * (or are shutting down).
    131  *
    132  * @param do_shutdown are we shutting down?
    133  */
    134 void
    135 TEH_resume_keys_requests (bool do_shutdown);
    136 
    137 
    138 /**
    139  * Function to call to handle requests to "/keys" by sending
    140  * back our current key material.
    141  *
    142  * @param rc request context
    143  * @param args array of additional options (must be empty for this function)
    144  * @return MHD result code
    145  */
    146 MHD_RESULT
    147 DH_handler_keys (struct DH_RequestContext *rc,
    148                  const char *const args[]);
    149 
    150 
    151 /**
    152  * Look up the issue for a donation unit public key.
    153  *
    154  * @param h_du_pub hash of donation unit public key
    155  * @return the donation unit key issue,
    156  *         or NULL if @a h_du_pub could not be found
    157  */
    158 struct DH_DonationUnitKey *
    159 DH_keys_donation_unit_by_hash (
    160   const struct DONAU_DonationUnitHashP *h_du_pub);
    161 
    162 
    163 /**
    164  * Initialize keys subsystem.
    165  *
    166  * @return #GNUNET_OK on success
    167  */
    168 enum GNUNET_GenericReturnValue
    169 DH_keys_init (void);
    170 
    171 
    172 /**
    173  * Fully clean up keys subsystem.
    174  */
    175 void
    176 DH_keys_finished (void);
    177 
    178 
    179 /**
    180  * Request to sign @a budis.
    181  *
    182  * @param num_bkps length of @a budis array
    183  * @param bkps array with data to blindly sign (and keys to sign with)
    184  * @param[out] du_sigs array set to the blind signature on success; must be of length @a num_bkps
    185  * @return #TALER_EC_NONE on success
    186  */
    187 enum TALER_ErrorCode
    188 DH_keys_donation_unit_batch_sign (
    189   unsigned int num_bkps,
    190   const struct DONAU_BkpSignData bkps[num_bkps],
    191   struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]);
    192 
    193 /**
    194  * Request to derive CS @a r_pub using the donation_unit and nonce from @a cdd.
    195  *
    196  * @param h_donation_unit_pub hash to compute @a r_pub from
    197  * @param nonce
    198  * @param[out] r_pub where to write the result
    199  * @return #TALER_EC_NONE on success
    200  */
    201 enum TALER_ErrorCode
    202 DH_keys_donation_unit_cs_r_pub (
    203   const struct DONAU_DonationUnitHashP *h_donation_unit_pub,
    204   const struct GNUNET_CRYPTO_CsSessionNonce *nonce,
    205   struct GNUNET_CRYPTO_CSPublicRPairP *r_pub);
    206 
    207 #endif