donau-httpd_get-keys.h (5925B)
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_get-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 "donau-httpd.h" 26 27 #ifndef DONAU_HTTPD_GET_KEYS_H 28 #define DONAU_HTTPD_GET_KEYS_H 29 30 31 /** 32 * @brief All information about a donation unit key (which is used to 33 * sign donation receipts into existence). 34 */ 35 struct DH_DonationUnitKey 36 { 37 38 /** 39 * Hash code of the donation unit public key. 40 */ 41 struct DONAU_DonationUnitHashP h_donation_unit_pub; 42 43 /** 44 * Decoded donation unit public key (the hash of it is in 45 * @e issue, but we sometimes need the full public key as well). 46 */ 47 struct DONAU_DonationUnitPublicKey donation_unit_pub; 48 49 /** 50 * The validity year. 51 */ 52 uint64_t validity_year; 53 54 /** 55 * Value that the donation unit represents. 56 */ 57 struct TALER_Amount value; 58 59 /** 60 * Did we lose the private keys? 61 */ 62 bool lost; 63 64 }; 65 66 /** 67 * Information needed to create a blind signature. 68 */ 69 struct DH_BlindSignData 70 { 71 /** 72 * Hash of key to sign with. 73 */ 74 const struct DONAU_DonationUnitHashP *h_du_pub; 75 76 /** 77 * Blinded planchet to sign over. 78 */ 79 const struct DONAU_BlindedUniqueDonorIdentifier *budi; 80 }; 81 82 /** 83 * Sign the message in @a purpose with the doanu's signing key. 84 * 85 * The @a purpose data is the beginning of the data of which the signature is 86 * to be created. The `size` field in @a purpose must correctly indicate the 87 * number of bytes of the data structure, including its header. Use 88 * #DH_keys_donau_sign() instead of calling this function directly! 89 * 90 * @param purpose the message to sign 91 * @param[out] pub set to the current public signing key of the doanu 92 * @param[out] sig signature over purpose using current signing key 93 * @return #TALER_EC_NONE on success 94 */ 95 enum TALER_ErrorCode 96 DH_keys_donau_sign_ ( 97 const struct GNUNET_CRYPTO_SignaturePurpose *purpose, 98 struct DONAU_DonauPublicKeyP *pub, 99 struct DONAU_DonauSignatureP *sig); 100 101 /** 102 * @ingroup crypto 103 * @brief EdDSA sign a given block. 104 * 105 * The @a ps data must be a fixed-size struct for which the signature is to be 106 * created. The `size` field in @a ps->purpose must correctly indicate the 107 * number of bytes of the data structure, including its header. 108 * 109 * @param ps packed struct with what to sign, MUST begin with a purpose 110 * @param[out] pub where to store the public key to use for the signing 111 * @param[out] sig where to write the signature 112 * @return #TALER_EC_NONE on success 113 */ 114 #define DH_keys_donau_sign(ps,pub,sig) \ 115 ({ \ 116 /* check size is set correctly */ \ 117 GNUNET_assert (htonl ((ps)->purpose.size) == \ 118 sizeof (*ps)); \ 119 /* check 'ps' begins with the purpose */ \ 120 GNUNET_static_assert (((void*) (ps)) == \ 121 ((void*) &(ps)->purpose)); \ 122 DH_keys_donau_sign_ (&(ps)->purpose, \ 123 pub, \ 124 sig); \ 125 }) 126 127 /** 128 * Resumes all suspended /keys requests, we may now have key material 129 * (or are shutting down). 130 * 131 * @param do_shutdown are we shutting down? 132 */ 133 void 134 TEH_resume_keys_requests (bool do_shutdown); 135 136 137 /** 138 * Function to call to handle requests to "/keys" by sending 139 * back our current key material. 140 * 141 * @param rc request context 142 * @param args array of additional options (must be empty for this function) 143 * @return MHD result code 144 */ 145 enum MHD_Result 146 DH_handler_get_keys (struct DH_RequestContext *rc, 147 const char *const args[]); 148 149 150 /** 151 * Look up the issue for a donation unit public key. 152 * 153 * @param h_du_pub hash of donation unit public key 154 * @return the donation unit key issue, 155 * or NULL if @a h_du_pub could not be found 156 */ 157 struct DH_DonationUnitKey * 158 DH_keys_donation_unit_by_hash ( 159 const struct DONAU_DonationUnitHashP *h_du_pub); 160 161 162 /** 163 * Initialize keys subsystem. 164 * 165 * @return #GNUNET_OK on success 166 */ 167 enum GNUNET_GenericReturnValue 168 DH_keys_init (void); 169 170 171 /** 172 * Fully clean up keys subsystem. 173 */ 174 void 175 DH_keys_finished (void); 176 177 178 /** 179 * Request to sign @a budis. 180 * 181 * @param num_bkps length of @a budis array 182 * @param bkps array with data to blindly sign (and keys to sign with) 183 * @param[out] du_sigs array set to the blind signature on success; must be of length @a num_bkps 184 * @return #TALER_EC_NONE on success 185 */ 186 enum TALER_ErrorCode 187 DH_keys_donation_unit_batch_sign ( 188 unsigned int num_bkps, 189 const struct DONAU_BkpSignData bkps[num_bkps], 190 struct DONAU_BlindedDonationUnitSignature du_sigs[num_bkps]); 191 192 /** 193 * Request to derive CS @a r_pub using the donation_unit and nonce from @a cdd. 194 * 195 * @param h_donation_unit_pub hash to compute @a r_pub from 196 * @param nonce 197 * @param[out] r_pub where to write the result 198 * @return #TALER_EC_NONE on success 199 */ 200 enum TALER_ErrorCode 201 DH_keys_donation_unit_cs_r_pub ( 202 const struct DONAU_DonationUnitHashP *h_donation_unit_pub, 203 const struct GNUNET_CRYPTO_CsSessionNonce *nonce, 204 struct GNUNET_CRYPTO_CSPublicRPairP *r_pub); 205 206 #endif