taler-exchange-httpd_management_auditors_AP_disable.c (6128B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2020 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 taler-exchange-httpd_management_auditors_AP_disable.c 18 * @brief Handle request to disable auditor. 19 * @author Christian Grothoff 20 */ 21 #include "taler/platform.h" 22 #include <gnunet/gnunet_util_lib.h> 23 #include <gnunet/gnunet_json_lib.h> 24 #include <jansson.h> 25 #include <microhttpd.h> 26 #include <pthread.h> 27 #include "taler/taler_json_lib.h" 28 #include "taler/taler_mhd_lib.h" 29 #include "taler-exchange-httpd_management.h" 30 #include "taler-exchange-httpd_responses.h" 31 #include "taler-exchange-httpd_keys.h" 32 33 34 /** 35 * Closure for the #del_auditor transaction. 36 */ 37 struct DelAuditorContext 38 { 39 40 /** 41 * Auditor public key this is about. 42 */ 43 struct TALER_AuditorPublicKeyP auditor_pub; 44 45 /** 46 * Auditor URL this is about. 47 */ 48 const char *auditor_url; 49 50 /** 51 * Timestamp for checking against replay attacks. 52 */ 53 struct GNUNET_TIME_Timestamp validity_end; 54 55 }; 56 57 58 /** 59 * Function implementing database transaction to del an auditor. Runs the 60 * transaction logic; IF it returns a non-error code, the transaction logic 61 * MUST NOT queue a MHD response. IF it returns an hard error, the 62 * transaction logic MUST queue a MHD response and set @a mhd_ret. IF it 63 * returns the soft error code, the function MAY be called again to retry and 64 * MUST not queue a MHD response. 65 * 66 * @param cls closure with a `struct DelAuditorContext` 67 * @param connection MHD request which triggered the transaction 68 * @param[out] mhd_ret set to MHD response status for @a connection, 69 * if transaction failed (!) 70 * @return transaction status 71 */ 72 static enum GNUNET_DB_QueryStatus 73 del_auditor (void *cls, 74 struct MHD_Connection *connection, 75 MHD_RESULT *mhd_ret) 76 { 77 struct DelAuditorContext *dac = cls; 78 struct GNUNET_TIME_Timestamp last_date; 79 enum GNUNET_DB_QueryStatus qs; 80 81 qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls, 82 &dac->auditor_pub, 83 &last_date); 84 if (qs < 0) 85 { 86 if (GNUNET_DB_STATUS_SOFT_ERROR == qs) 87 return qs; 88 GNUNET_break (0); 89 *mhd_ret = TALER_MHD_reply_with_error (connection, 90 MHD_HTTP_INTERNAL_SERVER_ERROR, 91 TALER_EC_GENERIC_DB_FETCH_FAILED, 92 "lookup auditor"); 93 return qs; 94 } 95 if (GNUNET_TIME_timestamp_cmp (last_date, 96 >, 97 dac->validity_end)) 98 { 99 *mhd_ret = TALER_MHD_reply_with_error ( 100 connection, 101 MHD_HTTP_CONFLICT, 102 TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_MORE_RECENT_PRESENT, 103 NULL); 104 return GNUNET_DB_STATUS_HARD_ERROR; 105 } 106 if (0 == qs) 107 { 108 *mhd_ret = TALER_MHD_reply_with_error ( 109 connection, 110 MHD_HTTP_NOT_FOUND, 111 TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_NOT_FOUND, 112 NULL); 113 return GNUNET_DB_STATUS_HARD_ERROR; 114 } 115 qs = TEH_plugin->update_auditor (TEH_plugin->cls, 116 &dac->auditor_pub, 117 "", /* auditor URL */ 118 "", /* auditor name */ 119 dac->validity_end, 120 false); 121 if (qs < 0) 122 { 123 GNUNET_break (0); 124 if (GNUNET_DB_STATUS_SOFT_ERROR == qs) 125 return qs; 126 *mhd_ret = TALER_MHD_reply_with_error (connection, 127 MHD_HTTP_INTERNAL_SERVER_ERROR, 128 TALER_EC_GENERIC_DB_STORE_FAILED, 129 "del auditor"); 130 return qs; 131 } 132 TEH_keys_update_states (); 133 return qs; 134 } 135 136 137 MHD_RESULT 138 TEH_handler_management_auditors_AP_disable ( 139 struct MHD_Connection *connection, 140 const struct TALER_AuditorPublicKeyP *auditor_pub, 141 const json_t *root) 142 { 143 struct TALER_MasterSignatureP master_sig; 144 struct DelAuditorContext dac = { 145 .auditor_pub = *auditor_pub 146 }; 147 struct GNUNET_JSON_Specification spec[] = { 148 GNUNET_JSON_spec_fixed_auto ("master_sig", 149 &master_sig), 150 GNUNET_JSON_spec_timestamp ("validity_end", 151 &dac.validity_end), 152 GNUNET_JSON_spec_end () 153 }; 154 MHD_RESULT res; 155 enum GNUNET_GenericReturnValue ret; 156 157 ret = TALER_MHD_parse_json_data (connection, 158 root, 159 spec); 160 if (GNUNET_SYSERR == ret) 161 return MHD_NO; /* hard failure */ 162 if (GNUNET_NO == ret) 163 return MHD_YES; /* failure */ 164 if (GNUNET_OK != 165 TALER_exchange_offline_auditor_del_verify ( 166 auditor_pub, 167 dac.validity_end, 168 &TEH_master_public_key, 169 &master_sig)) 170 { 171 GNUNET_break_op (0); 172 return TALER_MHD_reply_with_error ( 173 connection, 174 MHD_HTTP_FORBIDDEN, 175 TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_DEL_SIGNATURE_INVALID, 176 NULL); 177 } 178 179 ret = TEH_DB_run_transaction (connection, 180 "del auditor", 181 TEH_MT_REQUEST_OTHER, 182 &res, 183 &del_auditor, 184 &dac); 185 if (GNUNET_SYSERR == ret) 186 return res; 187 return TALER_MHD_reply_static ( 188 connection, 189 MHD_HTTP_NO_CONTENT, 190 NULL, 191 NULL, 192 0); 193 } 194 195 196 /* end of taler-exchange-httpd_management_auditors_AP_disable.c */