exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_revoke_sign_key.c (6788B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2014-2023 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 "taler/taler_json_lib.h"
     25 #include <gnunet/gnunet_curl_lib.h>
     26 struct RevokeState;
     27 #define TALER_EXCHANGE_POST_MANAGEMENT_SIGNKEYS_REVOKE_RESULT_CLOSURE \
     28         struct RevokeState
     29 #include "taler/exchange/post-management-signkeys-EXCHANGE_PUB-revoke.h"
     30 #include "taler/taler_testing_lib.h"
     31 
     32 
     33 /**
     34  * State for a "revoke" CMD.
     35  */
     36 struct RevokeState
     37 {
     38   /**
     39    * Expected HTTP status code.
     40    */
     41   unsigned int expected_response_code;
     42 
     43   /**
     44    * Command that offers a signination to revoke.
     45    */
     46   const char *coin_reference;
     47 
     48   /**
     49    * The interpreter state.
     50    */
     51   struct TALER_TESTING_Interpreter *is;
     52 
     53   /**
     54    * Handle for the operation.
     55    */
     56   struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle *kh;
     57 
     58   /**
     59    * Should we use a bogus signature?
     60    */
     61   bool bad_sig;
     62 
     63 };
     64 
     65 
     66 /**
     67  * Function called with information about the post revocation operation result.
     68  *
     69  * @param rs closure with a `struct RevokeState *`
     70  * @param rsr response data
     71  */
     72 static void
     73 success_cb (
     74   struct RevokeState *rs,
     75   const struct TALER_EXCHANGE_PostManagementSignkeysRevokeResponse *rsr)
     76 {
     77   const struct TALER_EXCHANGE_HttpResponse *hr = &rsr->hr;
     78 
     79   rs->kh = NULL;
     80   if (rs->expected_response_code != hr->http_status)
     81   {
     82     TALER_TESTING_unexpected_status (rs->is,
     83                                      hr->http_status,
     84                                      rs->expected_response_code);
     85     return;
     86   }
     87   TALER_TESTING_interpreter_next (rs->is);
     88 }
     89 
     90 
     91 /**
     92  * Cleanup the state.
     93  *
     94  * @param cls closure, must be a `struct RevokeState`.
     95  * @param cmd the command which is being cleaned up.
     96  */
     97 static void
     98 revoke_cleanup (void *cls,
     99                 const struct TALER_TESTING_Command *cmd)
    100 {
    101   struct RevokeState *rs = cls;
    102 
    103   if (NULL != rs->kh)
    104   {
    105     TALER_EXCHANGE_post_management_signkeys_revoke_cancel (rs->kh);
    106     rs->kh = NULL;
    107   }
    108   GNUNET_free (rs);
    109 }
    110 
    111 
    112 /**
    113  * Offer internal data from a "revoke" CMD to other CMDs.
    114  *
    115  * @param cls closure
    116  * @param[out] ret result (could be anything)
    117  * @param trait name of the trait
    118  * @param index index number of the object to offer.
    119  * @return #GNUNET_OK on success
    120  */
    121 static int
    122 revoke_traits (void *cls,
    123                const void **ret,
    124                const char *trait,
    125                unsigned int index)
    126 {
    127   struct RevokeState *rs = cls;
    128   struct TALER_TESTING_Trait traits[] = {
    129     TALER_TESTING_trait_end ()
    130   };
    131 
    132   (void) rs;
    133   return TALER_TESTING_get_trait (traits,
    134                                   ret,
    135                                   trait,
    136                                   index);
    137 }
    138 
    139 
    140 /**
    141  * Run the "revoke" command for a signing key.
    142  *
    143  * @param cls closure.
    144  * @param cmd the command to execute.
    145  * @param is the interpreter state.
    146  */
    147 static void
    148 revoke_run (void *cls,
    149             const struct TALER_TESTING_Command *cmd,
    150             struct TALER_TESTING_Interpreter *is)
    151 {
    152   struct RevokeState *rs = cls;
    153   const struct TALER_TESTING_Command *coin_cmd;
    154   const struct TALER_ExchangePublicKeyP *exchange_pub;
    155   struct TALER_MasterSignatureP master_sig;
    156   const char *exchange_url;
    157 
    158   {
    159     const struct TALER_TESTING_Command *exchange_cmd;
    160 
    161     exchange_cmd = TALER_TESTING_interpreter_get_command (is,
    162                                                           "exchange");
    163     if (NULL == exchange_cmd)
    164     {
    165       GNUNET_break (0);
    166       TALER_TESTING_interpreter_fail (is);
    167       return;
    168     }
    169     GNUNET_assert (GNUNET_OK ==
    170                    TALER_TESTING_get_trait_exchange_url (exchange_cmd,
    171                                                          &exchange_url));
    172   }
    173   rs->is = is;
    174   /* Get sign pub from trait */
    175   coin_cmd = TALER_TESTING_interpreter_lookup_command (is,
    176                                                        rs->coin_reference);
    177 
    178   if (NULL == coin_cmd)
    179   {
    180     GNUNET_break (0);
    181     TALER_TESTING_interpreter_fail (is);
    182     return;
    183   }
    184   GNUNET_assert (GNUNET_OK ==
    185                  TALER_TESTING_get_trait_exchange_pub (coin_cmd,
    186                                                        0,
    187                                                        &exchange_pub));
    188   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
    189               "Trying to revoke sign '%s..'\n",
    190               TALER_B2S (exchange_pub));
    191   if (rs->bad_sig)
    192   {
    193     memset (&master_sig,
    194             42,
    195             sizeof (master_sig));
    196   }
    197   else
    198   {
    199     const struct TALER_TESTING_Command *exchange_cmd;
    200     const struct TALER_MasterPrivateKeyP *master_priv;
    201 
    202     exchange_cmd = TALER_TESTING_interpreter_get_command (is,
    203                                                           "exchange");
    204     if (NULL == exchange_cmd)
    205     {
    206       GNUNET_break (0);
    207       TALER_TESTING_interpreter_fail (is);
    208       return;
    209     }
    210     GNUNET_assert (GNUNET_OK ==
    211                    TALER_TESTING_get_trait_master_priv (exchange_cmd,
    212                                                         &master_priv));
    213     TALER_exchange_offline_signkey_revoke_sign (exchange_pub,
    214                                                 master_priv,
    215                                                 &master_sig);
    216   }
    217   rs->kh = TALER_EXCHANGE_post_management_signkeys_revoke_create (
    218     TALER_TESTING_interpreter_get_context (is),
    219     exchange_url,
    220     exchange_pub,
    221     &master_sig);
    222   if (NULL == rs->kh)
    223   {
    224     GNUNET_break (0);
    225     TALER_TESTING_interpreter_fail (is);
    226     return;
    227   }
    228   TALER_EXCHANGE_post_management_signkeys_revoke_start (rs->kh, &success_cb, rs)
    229   ;
    230 }
    231 
    232 
    233 struct TALER_TESTING_Command
    234 TALER_TESTING_cmd_revoke_sign_key (
    235   const char *label,
    236   unsigned int expected_response_code,
    237   bool bad_sig,
    238   const char *sign_ref)
    239 {
    240   struct RevokeState *rs;
    241 
    242   rs = GNUNET_new (struct RevokeState);
    243   rs->expected_response_code = expected_response_code;
    244   rs->coin_reference = sign_ref;
    245   rs->bad_sig = bad_sig;
    246   {
    247     struct TALER_TESTING_Command cmd = {
    248       .cls = rs,
    249       .label = label,
    250       .run = &revoke_run,
    251       .cleanup = &revoke_cleanup,
    252       .traits = &revoke_traits
    253     };
    254 
    255     return cmd;
    256   }
    257 }