LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_revoke_sign_key.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 47 0.0 %
Date: 2021-08-30 06:43:37 Functions: 0 5 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2014-2020 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3, or
       8             :   (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful, but
      11             :   WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :   GNU General Public License for more details.
      14             : 
      15             :   You should have received a copy of the GNU General Public
      16             :   License along with TALER; see the file COPYING.  If not, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file testing/testing_api_cmd_revoke_sign_key.c
      21             :  * @brief Implement the revoke test command.
      22             :  * @author Christian Grothoff
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_signatures.h"
      28             : #include "taler_testing_lib.h"
      29             : 
      30             : 
      31             : /**
      32             :  * State for a "revoke" CMD.
      33             :  */
      34             : struct RevokeState
      35             : {
      36             :   /**
      37             :    * Expected HTTP status code.
      38             :    */
      39             :   unsigned int expected_response_code;
      40             : 
      41             :   /**
      42             :    * Command that offers a signination to revoke.
      43             :    */
      44             :   const char *coin_reference;
      45             : 
      46             :   /**
      47             :    * The interpreter state.
      48             :    */
      49             :   struct TALER_TESTING_Interpreter *is;
      50             : 
      51             :   /**
      52             :    * Handle for the operation.
      53             :    */
      54             :   struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *kh;
      55             : 
      56             :   /**
      57             :    * Should we use a bogus signature?
      58             :    */
      59             :   bool bad_sig;
      60             : 
      61             : };
      62             : 
      63             : 
      64             : /**
      65             :  * Function called with information about the post revocation operation result.
      66             :  *
      67             :  * @param cls closure with a `struct RevokeState *`
      68             :  * @param hr HTTP response data
      69             :  */
      70             : static void
      71           0 : success_cb (
      72             :   void *cls,
      73             :   const struct TALER_EXCHANGE_HttpResponse *hr)
      74             : {
      75           0 :   struct RevokeState *rs = cls;
      76             : 
      77           0 :   rs->kh = NULL;
      78           0 :   if (rs->expected_response_code != hr->http_status)
      79             :   {
      80           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
      81             :                 "Unexpected response code %u to command %s in %s:%u\n",
      82             :                 hr->http_status,
      83             :                 rs->is->commands[rs->is->ip].label,
      84             :                 __FILE__,
      85             :                 __LINE__);
      86           0 :     json_dumpf (hr->reply,
      87             :                 stderr,
      88             :                 0);
      89           0 :     TALER_TESTING_interpreter_fail (rs->is);
      90           0 :     return;
      91             :   }
      92           0 :   TALER_TESTING_interpreter_next (rs->is);
      93             : }
      94             : 
      95             : 
      96             : /**
      97             :  * Cleanup the state.
      98             :  *
      99             :  * @param cls closure, must be a `struct RevokeState`.
     100             :  * @param cmd the command which is being cleaned up.
     101             :  */
     102             : static void
     103           0 : revoke_cleanup (void *cls,
     104             :                 const struct TALER_TESTING_Command *cmd)
     105             : {
     106           0 :   struct RevokeState *rs = cls;
     107             : 
     108           0 :   if (NULL != rs->kh)
     109             :   {
     110           0 :     TALER_EXCHANGE_management_revoke_signing_key_cancel (rs->kh);
     111           0 :     rs->kh = NULL;
     112             :   }
     113           0 :   GNUNET_free (rs);
     114           0 : }
     115             : 
     116             : 
     117             : /**
     118             :  * Offer internal data from a "revoke" CMD to other CMDs.
     119             :  *
     120             :  * @param cls closure
     121             :  * @param[out] ret result (could be anything)
     122             :  * @param trait name of the trait
     123             :  * @param index index number of the object to offer.
     124             :  * @return #GNUNET_OK on success
     125             :  */
     126             : static int
     127           0 : revoke_traits (void *cls,
     128             :                const void **ret,
     129             :                const char *trait,
     130             :                unsigned int index)
     131             : {
     132           0 :   struct RevokeState *rs = cls;
     133             :   struct TALER_TESTING_Trait traits[] = {
     134           0 :     TALER_TESTING_trait_end ()
     135             :   };
     136             : 
     137             :   (void) rs;
     138           0 :   return TALER_TESTING_get_trait (traits,
     139             :                                   ret,
     140             :                                   trait,
     141             :                                   index);
     142             : }
     143             : 
     144             : 
     145             : /**
     146             :  * Run the "revoke" command for a signing key.
     147             :  *
     148             :  * @param cls closure.
     149             :  * @param cmd the command to execute.
     150             :  * @param is the interpreter state.
     151             :  */
     152             : static void
     153           0 : revoke_run (void *cls,
     154             :             const struct TALER_TESTING_Command *cmd,
     155             :             struct TALER_TESTING_Interpreter *is)
     156             : {
     157           0 :   struct RevokeState *rs = cls;
     158             :   const struct TALER_TESTING_Command *coin_cmd;
     159             :   const struct TALER_ExchangePublicKeyP *exchange_pub;
     160             :   struct TALER_MasterSignatureP master_sig;
     161             : 
     162           0 :   rs->is = is;
     163             :   /* Get sign pub from trait */
     164           0 :   coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
     165             :                                                        rs->coin_reference);
     166             : 
     167           0 :   if (NULL == coin_cmd)
     168             :   {
     169           0 :     GNUNET_break (0);
     170           0 :     TALER_TESTING_interpreter_fail (is);
     171           0 :     return;
     172             :   }
     173           0 :   GNUNET_assert (GNUNET_OK ==
     174             :                  TALER_TESTING_get_trait_exchange_pub (coin_cmd,
     175             :                                                        0,
     176             :                                                        &exchange_pub));
     177           0 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     178             :               "Trying to revoke sign '%s..'\n",
     179             :               TALER_B2S (exchange_pub));
     180           0 :   if (rs->bad_sig)
     181             :   {
     182           0 :     memset (&master_sig,
     183             :             42,
     184             :             sizeof (master_sig));
     185             :   }
     186             :   else
     187             :   {
     188           0 :     TALER_exchange_offline_signkey_revoke_sign (exchange_pub,
     189           0 :                                                 &is->master_priv,
     190             :                                                 &master_sig);
     191             :   }
     192           0 :   rs->kh = TALER_EXCHANGE_management_revoke_signing_key (
     193             :     is->ctx,
     194           0 :     is->exchange_url,
     195             :     exchange_pub,
     196             :     &master_sig,
     197             :     &success_cb,
     198             :     rs);
     199           0 :   if (NULL == rs->kh)
     200             :   {
     201           0 :     GNUNET_break (0);
     202           0 :     TALER_TESTING_interpreter_fail (is);
     203           0 :     return;
     204             :   }
     205             : }
     206             : 
     207             : 
     208             : struct TALER_TESTING_Command
     209           0 : TALER_TESTING_cmd_revoke_sign_key (
     210             :   const char *label,
     211             :   unsigned int expected_response_code,
     212             :   bool bad_sig,
     213             :   const char *sign_ref)
     214             : {
     215             :   struct RevokeState *rs;
     216             : 
     217           0 :   rs = GNUNET_new (struct RevokeState);
     218           0 :   rs->expected_response_code = expected_response_code;
     219           0 :   rs->coin_reference = sign_ref;
     220           0 :   rs->bad_sig = bad_sig;
     221             :   {
     222           0 :     struct TALER_TESTING_Command cmd = {
     223             :       .cls = rs,
     224             :       .label = label,
     225             :       .run = &revoke_run,
     226             :       .cleanup = &revoke_cleanup,
     227             :       .traits = &revoke_traits
     228             :     };
     229             : 
     230           0 :     return cmd;
     231             :   }
     232             : }

Generated by: LCOV version 1.14