LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_management_wire_disable.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 42 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_wire_disable.c
      18             :  * @brief Handle request to disable wire account.
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "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_json_lib.h"
      28             : #include "taler_mhd_lib.h"
      29             : #include "taler-exchange-httpd_management.h"
      30             : #include "taler-exchange-httpd_responses.h"
      31             : #include "taler-exchange-httpd_wire.h"
      32             : 
      33             : 
      34             : /**
      35             :  * Closure for the #del_wire transaction.
      36             :  */
      37             : struct DelWireContext
      38             : {
      39             :   /**
      40             :    * Master signature affirming the WIRE DEL operation
      41             :    * (includes timestamp).
      42             :    */
      43             :   struct TALER_MasterSignatureP master_sig;
      44             : 
      45             :   /**
      46             :    * Payto:// URI this is about.
      47             :    */
      48             :   const char *payto_uri;
      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 wire.  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 DelWireContext`
      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           0 : del_wire (void *cls,
      74             :           struct MHD_Connection *connection,
      75             :           MHD_RESULT *mhd_ret)
      76             : {
      77           0 :   struct DelWireContext *awc = cls;
      78             :   struct GNUNET_TIME_Timestamp last_date;
      79             :   enum GNUNET_DB_QueryStatus qs;
      80             : 
      81           0 :   qs = TEH_plugin->lookup_wire_timestamp (TEH_plugin->cls,
      82             :                                           awc->payto_uri,
      83             :                                           &last_date);
      84           0 :   if (qs < 0)
      85             :   {
      86           0 :     if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
      87           0 :       return qs;
      88           0 :     GNUNET_break (0);
      89           0 :     *mhd_ret = TALER_MHD_reply_with_error (connection,
      90             :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
      91             :                                            TALER_EC_GENERIC_DB_FETCH_FAILED,
      92             :                                            "lookup wire");
      93           0 :     return qs;
      94             :   }
      95           0 :   if (GNUNET_TIME_timestamp_cmp (last_date,
      96             :                                  >,
      97             :                                  awc->validity_end))
      98             :   {
      99           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     100             :       connection,
     101             :       MHD_HTTP_CONFLICT,
     102             :       TALER_EC_EXCHANGE_MANAGEMENT_WIRE_MORE_RECENT_PRESENT,
     103             :       NULL);
     104           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     105             :   }
     106           0 :   if (0 == qs)
     107             :   {
     108           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     109             :       connection,
     110             :       MHD_HTTP_NOT_FOUND,
     111             :       TALER_EC_EXCHANGE_MANAGEMENT_WIRE_NOT_FOUND,
     112             :       NULL);
     113           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     114             :   }
     115           0 :   qs = TEH_plugin->update_wire (TEH_plugin->cls,
     116             :                                 awc->payto_uri,
     117             :                                 awc->validity_end,
     118             :                                 false);
     119           0 :   if (qs < 0)
     120             :   {
     121           0 :     GNUNET_break (0);
     122           0 :     if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
     123           0 :       return qs;
     124           0 :     *mhd_ret = TALER_MHD_reply_with_error (connection,
     125             :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
     126             :                                            TALER_EC_GENERIC_DB_STORE_FAILED,
     127             :                                            "del wire");
     128           0 :     return qs;
     129             :   }
     130           0 :   return qs;
     131             : }
     132             : 
     133             : 
     134             : MHD_RESULT
     135           0 : TEH_handler_management_post_wire_disable (
     136             :   struct MHD_Connection *connection,
     137             :   const json_t *root)
     138             : {
     139             :   struct DelWireContext awc;
     140             :   struct GNUNET_JSON_Specification spec[] = {
     141           0 :     GNUNET_JSON_spec_fixed_auto ("master_sig_del",
     142             :                                  &awc.master_sig),
     143           0 :     GNUNET_JSON_spec_string ("payto_uri",
     144             :                              &awc.payto_uri),
     145           0 :     GNUNET_JSON_spec_timestamp ("validity_end",
     146             :                                 &awc.validity_end),
     147           0 :     GNUNET_JSON_spec_end ()
     148             :   };
     149             : 
     150             :   {
     151             :     enum GNUNET_GenericReturnValue res;
     152             : 
     153           0 :     res = TALER_MHD_parse_json_data (connection,
     154             :                                      root,
     155             :                                      spec);
     156           0 :     if (GNUNET_SYSERR == res)
     157           0 :       return MHD_NO; /* hard failure */
     158           0 :     if (GNUNET_NO == res)
     159           0 :       return MHD_YES; /* failure */
     160             :   }
     161           0 :   if (GNUNET_OK !=
     162           0 :       TALER_exchange_offline_wire_del_verify (
     163             :         awc.payto_uri,
     164             :         awc.validity_end,
     165             :         &TEH_master_public_key,
     166             :         &awc.master_sig))
     167             :   {
     168           0 :     GNUNET_break_op (0);
     169           0 :     return TALER_MHD_reply_with_error (
     170             :       connection,
     171             :       MHD_HTTP_FORBIDDEN,
     172             :       TALER_EC_EXCHANGE_MANAGEMENT_WIRE_DEL_SIGNATURE_INVALID,
     173             :       NULL);
     174             :   }
     175             : 
     176             :   {
     177             :     enum GNUNET_GenericReturnValue res;
     178             :     MHD_RESULT ret;
     179             : 
     180           0 :     res = TEH_DB_run_transaction (connection,
     181             :                                   "del wire",
     182             :                                   TEH_MT_REQUEST_OTHER,
     183             :                                   &ret,
     184             :                                   &del_wire,
     185             :                                   &awc);
     186           0 :     if (GNUNET_SYSERR == res)
     187           0 :       return ret;
     188             :   }
     189           0 :   TEH_wire_update_state ();
     190           0 :   return TALER_MHD_reply_static (
     191             :     connection,
     192             :     MHD_HTTP_NO_CONTENT,
     193             :     NULL,
     194             :     NULL,
     195             :     0);
     196             : }
     197             : 
     198             : 
     199             : /* end of taler-exchange-httpd_management_wire_disable.c */

Generated by: LCOV version 1.14