LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_management_auditors_AP_disable.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 30 44 68.2 %
Date: 2021-08-30 06:43:37 Functions: 2 2 100.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_auditors_AP_disable.c
      18             :  * @brief Handle request to disable auditor.
      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_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_Absolute 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           3 : del_auditor (void *cls,
      74             :              struct MHD_Connection *connection,
      75             :              MHD_RESULT *mhd_ret)
      76             : {
      77           3 :   struct DelAuditorContext *dac = cls;
      78             :   struct GNUNET_TIME_Absolute last_date;
      79             :   enum GNUNET_DB_QueryStatus qs;
      80             : 
      81           3 :   qs = TEH_plugin->lookup_auditor_timestamp (TEH_plugin->cls,
      82           3 :                                              &dac->auditor_pub,
      83             :                                              &last_date);
      84           3 :   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 auditor");
      93           0 :     return qs;
      94             :   }
      95           3 :   if (last_date.abs_value_us > dac->validity_end.abs_value_us)
      96             :   {
      97           0 :     *mhd_ret = TALER_MHD_reply_with_error (
      98             :       connection,
      99             :       MHD_HTTP_CONFLICT,
     100             :       TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_MORE_RECENT_PRESENT,
     101             :       NULL);
     102           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     103             :   }
     104           3 :   if (0 == qs)
     105             :   {
     106           1 :     *mhd_ret = TALER_MHD_reply_with_error (
     107             :       connection,
     108             :       MHD_HTTP_NOT_FOUND,
     109             :       TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_NOT_FOUND,
     110             :       NULL);
     111           1 :     return GNUNET_DB_STATUS_HARD_ERROR;
     112             :   }
     113           2 :   qs = TEH_plugin->update_auditor (TEH_plugin->cls,
     114           2 :                                    &dac->auditor_pub,
     115             :                                    "", /* auditor URL */
     116             :                                    "", /* auditor name */
     117             :                                    dac->validity_end,
     118             :                                    false);
     119           2 :   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 auditor");
     128           0 :     return qs;
     129             :   }
     130           2 :   TEH_keys_update_states ();
     131           2 :   return qs;
     132             : }
     133             : 
     134             : 
     135             : MHD_RESULT
     136           4 : TEH_handler_management_auditors_AP_disable (
     137             :   struct MHD_Connection *connection,
     138             :   const struct TALER_AuditorPublicKeyP *auditor_pub,
     139             :   const json_t *root)
     140             : {
     141             :   struct TALER_MasterSignatureP master_sig;
     142           4 :   struct DelAuditorContext dac = {
     143             :     .auditor_pub = *auditor_pub
     144             :   };
     145             :   struct GNUNET_JSON_Specification spec[] = {
     146           4 :     GNUNET_JSON_spec_fixed_auto ("master_sig",
     147             :                                  &master_sig),
     148           4 :     TALER_JSON_spec_absolute_time ("validity_end",
     149             :                                    &dac.validity_end),
     150           4 :     GNUNET_JSON_spec_end ()
     151             :   };
     152             :   MHD_RESULT res;
     153             :   enum GNUNET_GenericReturnValue ret;
     154             : 
     155           4 :   ret = TALER_MHD_parse_json_data (connection,
     156             :                                    root,
     157             :                                    spec);
     158           4 :   if (GNUNET_SYSERR == ret)
     159           0 :     return MHD_NO;   /* hard failure */
     160           4 :   if (GNUNET_NO == ret)
     161           0 :     return MHD_YES;   /* failure */
     162           4 :   if (GNUNET_OK !=
     163           4 :       TALER_exchange_offline_auditor_del_verify (
     164             :         auditor_pub,
     165             :         dac.validity_end,
     166             :         &TEH_master_public_key,
     167             :         &master_sig))
     168             :   {
     169           1 :     GNUNET_break_op (0);
     170           1 :     return TALER_MHD_reply_with_error (
     171             :       connection,
     172             :       MHD_HTTP_FORBIDDEN,
     173             :       TALER_EC_EXCHANGE_MANAGEMENT_AUDITOR_DEL_SIGNATURE_INVALID,
     174             :       NULL);
     175             :   }
     176             : 
     177           3 :   ret = TEH_DB_run_transaction (connection,
     178             :                                 "del auditor",
     179             :                                 &res,
     180             :                                 &del_auditor,
     181             :                                 &dac);
     182           3 :   if (GNUNET_SYSERR == ret)
     183           1 :     return res;
     184           2 :   return TALER_MHD_reply_static (
     185             :     connection,
     186             :     MHD_HTTP_NO_CONTENT,
     187             :     NULL,
     188             :     NULL,
     189             :     0);
     190             : }
     191             : 
     192             : 
     193             : /* end of taler-exchange-httpd_management_auditors_AP_disable.c */

Generated by: LCOV version 1.14