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 62 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_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 TALER_DenominationHashP *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           0 :       GNUNET_h2s (&awc->h_denom_pub->hash));
     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 :   TEH_METRICS_num_verifications[TEH_MT_SIGNATURE_EDDSA]++;
     144           0 :   if (GNUNET_OK !=
     145           0 :       TALER_auditor_denom_validity_verify (
     146             :         auditor_url,
     147             :         awc->h_denom_pub,
     148             :         &TEH_master_public_key,
     149             :         meta.start,
     150             :         meta.expire_withdraw,
     151             :         meta.expire_deposit,
     152             :         meta.expire_legal,
     153             :         &meta.value,
     154             :         &meta.fees,
     155             :         awc->auditor_pub,
     156           0 :         &awc->auditor_sig))
     157             :   {
     158           0 :     GNUNET_free (auditor_url);
     159             :     /* signature invalid */
     160           0 :     GNUNET_break_op (0);
     161           0 :     *mhd_ret = TALER_MHD_reply_with_error (
     162             :       connection,
     163             :       MHD_HTTP_FORBIDDEN,
     164             :       TALER_EC_EXCHANGE_AUDITORS_AUDITOR_SIGNATURE_INVALID,
     165             :       NULL);
     166           0 :     return GNUNET_DB_STATUS_HARD_ERROR;
     167             :   }
     168           0 :   GNUNET_free (auditor_url);
     169             : 
     170           0 :   qs = TEH_plugin->insert_auditor_denom_sig (TEH_plugin->cls,
     171             :                                              awc->h_denom_pub,
     172             :                                              awc->auditor_pub,
     173           0 :                                              &awc->auditor_sig);
     174           0 :   if (qs < 0)
     175             :   {
     176           0 :     GNUNET_break (0);
     177           0 :     if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
     178           0 :       return qs;
     179           0 :     *mhd_ret = TALER_MHD_reply_with_error (connection,
     180             :                                            MHD_HTTP_INTERNAL_SERVER_ERROR,
     181             :                                            TALER_EC_GENERIC_DB_STORE_FAILED,
     182             :                                            "add auditor signature");
     183           0 :     return qs;
     184             :   }
     185           0 :   return qs;
     186             : }
     187             : 
     188             : 
     189             : MHD_RESULT
     190           0 : TEH_handler_auditors (
     191             :   struct MHD_Connection *connection,
     192             :   const struct TALER_AuditorPublicKeyP *auditor_pub,
     193             :   const struct TALER_DenominationHashP *h_denom_pub,
     194             :   const json_t *root)
     195             : {
     196           0 :   struct AddAuditorDenomContext awc = {
     197             :     .auditor_pub = auditor_pub,
     198             :     .h_denom_pub = h_denom_pub
     199             :   };
     200             :   struct GNUNET_JSON_Specification spec[] = {
     201           0 :     GNUNET_JSON_spec_fixed_auto ("auditor_sig",
     202             :                                  &awc.auditor_sig),
     203           0 :     GNUNET_JSON_spec_end ()
     204             :   };
     205             :   MHD_RESULT res;
     206             :   enum GNUNET_GenericReturnValue ret;
     207             : 
     208           0 :   ret = TALER_MHD_parse_json_data (connection,
     209             :                                    root,
     210             :                                    spec);
     211           0 :   if (GNUNET_SYSERR == ret)
     212           0 :     return MHD_NO;   /* hard failure */
     213           0 :   if (GNUNET_NO == ret)
     214           0 :     return MHD_YES;   /* failure */
     215           0 :   ret = TEH_DB_run_transaction (connection,
     216             :                                 "add auditor denom sig",
     217             :                                 TEH_MT_REQUEST_OTHER,
     218             :                                 &res,
     219             :                                 &add_auditor_denom_sig,
     220             :                                 &awc);
     221           0 :   if (GNUNET_SYSERR == ret)
     222           0 :     return res;
     223           0 :   return TALER_MHD_reply_static (
     224             :     connection,
     225             :     MHD_HTTP_NO_CONTENT,
     226             :     NULL,
     227             :     NULL,
     228             :     0);
     229             : }
     230             : 
     231             : 
     232             : /* end of taler-exchange-httpd_auditors.c */

Generated by: LCOV version 1.14