donau-httpd_csr.c (3519B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2024 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU Affero General Public License as 7 published by the Free Software Foundation; either version 3, 8 or (at your option) any later version. 9 10 TALER 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. 13 See the GNU Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General 16 Public License along with TALER; see the file COPYING. If not, 17 see <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file donau-httpd_csr.c 21 * @brief Handle /csr requests 22 * @author Johannes Casaburi 23 */ 24 #include <donau_config.h> 25 #include <gnunet/gnunet_util_lib.h> 26 #include <jansson.h> 27 #include <microhttpd.h> 28 #include <pthread.h> 29 #include <taler/taler_json_lib.h> 30 #include <taler/taler_mhd_lib.h> 31 #include <taler/taler_signatures.h> 32 #include "donaudb_plugin.h" 33 #include "donau-httpd_keys.h" 34 #include "donau-httpd_csr.h" 35 36 37 /** 38 * Maximum number of csr records we return per request. 39 */ 40 #define MAX_RECORDS 1024 41 42 43 MHD_RESULT 44 DH_handler_csr_issue (struct DH_RequestContext *rc, 45 const json_t *root, 46 const char *const args[]) 47 { 48 struct GNUNET_CRYPTO_CsSessionNonce nonce; 49 struct DONAU_DonationUnitHashP du_pub_hash; 50 struct GNUNET_CRYPTO_BlindingInputValues ewv = { 51 .cipher = GNUNET_CRYPTO_BSA_CS 52 }; 53 struct GNUNET_JSON_Specification spec[] = { 54 GNUNET_JSON_spec_fixed_auto ("nonce", 55 &nonce), 56 GNUNET_JSON_spec_fixed_auto ("du_pub_hash", 57 &du_pub_hash), 58 GNUNET_JSON_spec_end () 59 }; 60 struct DH_DonationUnitKey *dk; 61 62 (void) args; 63 { 64 enum GNUNET_GenericReturnValue res; 65 66 res = TALER_MHD_parse_json_data (rc->connection, 67 root, 68 spec); 69 if (GNUNET_OK != res) 70 return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES; 71 } 72 73 { 74 dk = DH_keys_donation_unit_by_hash (&du_pub_hash); 75 if (NULL == dk) 76 { 77 GNUNET_break (0); 78 return TALER_MHD_reply_with_error ( 79 rc->connection, 80 MHD_HTTP_INTERNAL_SERVER_ERROR, 81 TALER_EC_DONAU_GENERIC_KEYS_MISSING, 82 NULL); 83 } 84 if (GNUNET_CRYPTO_BSA_CS != 85 dk->donation_unit_pub.bsign_pub_key->cipher) 86 { 87 /* donation_unit is valid but not for CS */ 88 GNUNET_break (0); 89 return TALER_MHD_reply_with_error ( 90 rc->connection, 91 MHD_HTTP_INTERNAL_SERVER_ERROR, 92 TALER_EC_DONAU_GENERIC_KEYS_MISSING, 93 NULL); 94 } 95 } 96 97 /* derive r_pub */ 98 { 99 enum TALER_ErrorCode ec; 100 101 ec = DH_keys_donation_unit_cs_r_pub (&du_pub_hash, 102 &nonce, 103 &ewv.details.cs_values); 104 if (TALER_EC_NONE != ec) 105 { 106 GNUNET_break (0); 107 return TALER_MHD_reply_with_ec (rc->connection, 108 ec, 109 NULL); 110 } 111 } 112 { 113 struct TALER_ExchangeBlindingValues exw = { 114 .blinding_inputs = &ewv 115 }; 116 117 return TALER_MHD_REPLY_JSON_PACK ( 118 rc->connection, 119 MHD_HTTP_CREATED, 120 TALER_JSON_pack_exchange_blinding_values ("ewv", 121 &exw)); 122 } 123 } 124 125 126 /* end of donau-httpd_csr.c */