LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_auditors.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 60 0.0 %
Date: 2021-08-30 06:43:37 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_auditors.c
      18             :  * @brief Handle request to add auditor signature on a denomination.
      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_signatures.h"
      30             : #include "taler-exchange-httpd_auditors.h"
      31             : #include "taler-exchange-httpd_responses.h"
      32             : 
      33             : 
      34             : /**
      35             :  * Closure for the #add_auditor_denom_sig transaction.
      36             :  */
      37             : struct AddAuditorDenomContext
      38             : {
      39             :   /**
      40             :    * Auditor's signature affirming the AUDITORS XXX operation
      41             :    * (includes timestamp).
      42             :    */
      43             :   struct TALER_AuditorSignatureP auditor_sig;
      44             : 
      45             :   /**
      46             :    * Denomination this is about.
      47             :    */
      48             :   const struct GNUNET_HashCode *h_denom_pub;
      49             : 
      50             :   /**
      51             :    * Auditor this is about.
      52             :    */
      53             :   const struct TALER_AuditorPublicKeyP *auditor_pub;
      54             : 
      55             : };
      56             : 
      57             : 
      58             : /**
      59             :  * Function implementing database transaction to add an auditors.  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 AddAuditorDenomContext`
      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 : add_auditor_denom_sig (void *cls,
      74             :                        struct MHD_Connection *connection,
      75             :                        MHD_RESULT *mhd_ret)
      76             : {
      77           0 :   struct AddAuditorDenomContext *awc = cls;
      78             :   struct TALER_EXCHANGEDB_DenominationKeyMetaData meta;
      79             :   enum GNUNET_DB_QueryStatus qs;
      80             :   char *auditor_url;
      81             :   bool enabled;
      82             : 
      83           0 :   qs = TEH_plugin->lookup_denomination_key (
      84           0 :     TEH_plugin->cls,
      85             :     awc->h_denom_pub,
      86             :     &meta);
      87           0 :   if (qs < 0)
      88             :   {
      89           0 :     if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
      90           0 :       return qs;
      91           0 :     GNUNET_break (0);
      92           0 :     *mhd_ret = TALER_MHD_reply_with_error (connection,
      93             :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
      94             :                                            TALER_EC_GENERIC_DB_FETCH_FAILED,
      95             :                                            "lookup denomination key");
      96           0 :     return qs;
      97             :   }
      98           0 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
      99             :   {
     100           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     101             :       connection,
     102             :       MHD_HTTP_NOT_FOUND,
     103             :       TALER_EC_EXCHANGE_GENERIC_DENOMINATION_KEY_UNKNOWN,
     104             :       GNUNET_h2s (awc->h_denom_pub));
     105           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     106             :   }
     107             : 
     108           0 :   qs = TEH_plugin->lookup_auditor_status (
     109           0 :     TEH_plugin->cls,
     110             :     awc->auditor_pub,
     111             :     &auditor_url,
     112             :     &enabled);
     113           0 :   if (qs < 0)
     114             :   {
     115           0 :     if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
     116           0 :       return qs;
     117           0 :     GNUNET_break (0);
     118           0 :     *mhd_ret = TALER_MHD_reply_with_error (connection,
     119             :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
     120             :                                            TALER_EC_GENERIC_DB_FETCH_FAILED,
     121             :                                            "lookup auditor");
     122           0 :     return qs;
     123             :   }
     124           0 :   if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs)
     125             :   {
     126           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     127             :       connection,
     128             :       MHD_HTTP_PRECONDITION_FAILED,
     129             :       TALER_EC_EXCHANGE_AUDITORS_AUDITOR_UNKNOWN,
     130           0 :       TALER_B2S (awc->auditor_pub));
     131           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     132             :   }
     133           0 :   if (! enabled)
     134             :   {
     135           0 :     GNUNET_free (auditor_url);
     136           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     137             :       connection,
     138             :       MHD_HTTP_GONE,
     139             :       TALER_EC_EXCHANGE_AUDITORS_AUDITOR_INACTIVE,
     140           0 :       TALER_B2S (awc->auditor_pub));
     141           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     142             :   }
     143           0 :   if (GNUNET_OK !=
     144           0 :       TALER_auditor_denom_validity_verify (
     145             :         auditor_url,
     146             :         awc->h_denom_pub,
     147             :         &TEH_master_public_key,
     148             :         meta.start,
     149             :         meta.expire_withdraw,
     150             :         meta.expire_deposit,
     151             :         meta.expire_legal,
     152             :         &meta.value,
     153             :         &meta.fee_withdraw,
     154             :         &meta.fee_deposit,
     155             :         &meta.fee_refresh,
     156             :         &meta.fee_refund,
     157             :         awc->auditor_pub,
     158           0 :         &awc->auditor_sig))
     159             :   {
     160           0 :     GNUNET_free (auditor_url);
     161             :     /* signature invalid */
     162           0 :     GNUNET_break_op (0);
     163           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     164             :       connection,
     165             :       MHD_HTTP_FORBIDDEN,
     166             :       TALER_EC_EXCHANGE_AUDITORS_AUDITOR_SIGNATURE_INVALID,
     167             :       NULL);
     168           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     169             :   }
     170           0 :   GNUNET_free (auditor_url);
     171             : 
     172           0 :   qs = TEH_plugin->insert_auditor_denom_sig (TEH_plugin->cls,
     173             :                                              awc->h_denom_pub,
     174             :                                              awc->auditor_pub,
     175           0 :                                              &awc->auditor_sig);
     176           0 :   if (qs < 0)
     177             :   {
     178           0 :     GNUNET_break (0);
     179           0 :     if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
     180           0 :       return qs;
     181           0 :     *mhd_ret = TALER_MHD_reply_with_error (connection,
     182             :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
     183             :                                            TALER_EC_GENERIC_DB_STORE_FAILED,
     184             :                                            "add auditor signature");
     185           0 :     return qs;
     186             :   }
     187           0 :   return qs;
     188             : }
     189             : 
     190             : 
     191             : MHD_RESULT
     192           0 : TEH_handler_auditors (
     193             :   struct MHD_Connection *connection,
     194             :   const struct TALER_AuditorPublicKeyP *auditor_pub,
     195             :   const struct GNUNET_HashCode *h_denom_pub,
     196             :   const json_t *root)
     197             : {
     198           0 :   struct AddAuditorDenomContext awc = {
     199             :     .auditor_pub = auditor_pub,
     200             :     .h_denom_pub = h_denom_pub
     201             :   };
     202             :   struct GNUNET_JSON_Specification spec[] = {
     203           0 :     GNUNET_JSON_spec_fixed_auto ("auditor_sig",
     204             :                                  &awc.auditor_sig),
     205           0 :     GNUNET_JSON_spec_end ()
     206             :   };
     207             :   MHD_RESULT res;
     208             :   enum GNUNET_GenericReturnValue ret;
     209             : 
     210           0 :   ret = TALER_MHD_parse_json_data (connection,
     211             :                                    root,
     212             :                                    spec);
     213           0 :   if (GNUNET_SYSERR == ret)
     214           0 :     return MHD_NO;   /* hard failure */
     215           0 :   if (GNUNET_NO == ret)
     216           0 :     return MHD_YES;   /* failure */
     217           0 :   ret = TEH_DB_run_transaction (connection,
     218             :                                 "add auditor denom sig",
     219             :                                 &res,
     220             :                                 &add_auditor_denom_sig,
     221             :                                 &awc);
     222           0 :   if (GNUNET_SYSERR == ret)
     223           0 :     return res;
     224           0 :   return TALER_MHD_reply_static (
     225             :     connection,
     226             :     MHD_HTTP_NO_CONTENT,
     227             :     NULL,
     228             :     NULL,
     229             :     0);
     230             : }
     231             : 
     232             : 
     233             : /* end of taler-exchange-httpd_auditors.c */

Generated by: LCOV version 1.14