LCOV - code coverage report
Current view: top level - testing - test_exchange_api_revocation.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 82 82
Test Date: 2026-11-18 17:34:04 Functions: 100.0 % 3 3

            Line data    Source code
       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/test_exchange_api_revocation.c
      21              :  * @brief testcase to test key revocation handling via the exchange's HTTP API interface
      22              :  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
      23              :  * @author Christian Grothoff
      24              :  * @author Marcello Stanisci
      25              :  */
      26              : #include "taler/taler_util.h"
      27              : #include "taler/taler_json_lib.h"
      28              : #include <gnunet/gnunet_util_lib.h>
      29              : #include <gnunet/gnunet_testing_lib.h>
      30              : #include <microhttpd.h>
      31              : #include "taler/taler_bank_service.h"
      32              : #include "taler/taler_testing_lib.h"
      33              : 
      34              : /**
      35              :  * Configuration file we use.  One (big) configuration is used
      36              :  * for the various components for this test.
      37              :  */
      38              : static char *config_file;
      39              : 
      40              : /**
      41              :  * Special case: Clause-Schnorr derives the coin key from /csr values,
      42              :  * so reusing a coin key for another denomination does not work.
      43              :  */
      44              : static bool uses_cs;
      45              : 
      46              : /**
      47              :  * Our credentials.
      48              :  */
      49              : static struct TALER_TESTING_Credentials cred;
      50              : 
      51              : 
      52              : /**
      53              :  * Execute the taler-exchange-wirewatch command with
      54              :  * our configuration file.
      55              :  *
      56              :  * @param label label to use for the command.
      57              :  */
      58              : static struct TALER_TESTING_Command
      59           10 : CMD_EXEC_WIREWATCH (const char *label)
      60              : {
      61           10 :   return TALER_TESTING_cmd_exec_wirewatch2 (label,
      62              :                                             config_file,
      63              :                                             "exchange-account-2");
      64              : }
      65              : 
      66              : 
      67              : /**
      68              :  * Main function that will tell the interpreter what commands to
      69              :  * run.
      70              :  *
      71              :  * @param cls closure
      72              :  */
      73              : static void
      74            2 : run (void *cls,
      75              :      struct TALER_TESTING_Interpreter *is)
      76              : {
      77              :   struct TALER_TESTING_Command revocation[] = {
      78            2 :     TALER_TESTING_cmd_run_fakebank ("run-fakebank",
      79            2 :                                     cred.cfg,
      80              :                                     "exchange-account-2"),
      81            2 :     TALER_TESTING_cmd_system_start ("start-taler",
      82              :                                     config_file,
      83              :                                     "-e",
      84              :                                     NULL),
      85            2 :     TALER_TESTING_cmd_get_exchange ("get-exchange",
      86            2 :                                     cred.cfg,
      87              :                                     NULL,
      88              :                                     true,
      89              :                                     true),
      90              :     /**
      91              :      * Fill reserve with EUR:10.02, as withdraw fee is 1 ct per
      92              :      * config.
      93              :      */
      94            2 :     TALER_TESTING_cmd_admin_add_incoming ("create-reserve-1",
      95              :                                           "EUR:10.02",
      96              :                                           &cred.ba,
      97              :                                           cred.user42_payto),
      98            2 :     TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-1",
      99              :                                                  "EUR:10.02",
     100              :                                                  cred.user42_payto,
     101              :                                                  cred.exchange_payto,
     102              :                                                  "create-reserve-1"),
     103              :     /**
     104              :      * Run wire-watch to trigger the reserve creation.
     105              :      */
     106            2 :     CMD_EXEC_WIREWATCH ("wirewatch-4"),
     107              :     /* Withdraw a 5 EUR coin, at fee of 1 ct */
     108            2 :     TALER_TESTING_cmd_withdraw_amount ("withdraw-revocation-coin-1",
     109              :                                        "create-reserve-1",
     110              :                                        "EUR:5",
     111              :                                        0, /* age restriction off */
     112              :                                        MHD_HTTP_OK),
     113              :     /* Withdraw another 5 EUR coin, at fee of 1 ct */
     114            2 :     TALER_TESTING_cmd_withdraw_amount ("withdraw-revocation-coin-2",
     115              :                                        "create-reserve-1",
     116              :                                        "EUR:5",
     117              :                                        0, /* age restriction off */
     118              :                                        MHD_HTTP_OK),
     119              :     /* Try to partially spend (deposit) 1 EUR of the 5 EUR coin (in full)
     120              :      * (merchant would receive EUR:0.99 due to 1 ct deposit fee) *///
     121            2 :     TALER_TESTING_cmd_set_var (
     122              :       "account-priv",
     123              :       TALER_TESTING_cmd_deposit (
     124              :         "deposit-partial-fail-kyc",
     125              :         "withdraw-revocation-coin-1",
     126              :         0,
     127              :         cred.user42_payto,
     128              :         "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
     129            2 :         GNUNET_TIME_UNIT_ZERO,
     130              :         "EUR:1",
     131              :         MHD_HTTP_UNAVAILABLE_FOR_LEGAL_REASONS)),
     132            2 :     TALER_TESTING_cmd_admin_add_kycauth (
     133              :       "kyc-auth-transfer",
     134              :       "EUR:0.01",
     135              :       &cred.ba,
     136              :       cred.user42_payto,
     137              :       "deposit-partial-fail-kyc"),
     138            2 :     CMD_EXEC_WIREWATCH (
     139              :       "import-kyc-account-withdraw"),
     140            2 :     TALER_TESTING_cmd_deposit (
     141              :       "deposit-partial",
     142              :       "withdraw-revocation-coin-1",
     143              :       0,
     144              :       cred.user42_payto,
     145              :       "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:2\"}]}",
     146            2 :       GNUNET_TIME_UNIT_ZERO,
     147              :       "EUR:1",
     148              :       MHD_HTTP_OK),
     149              :     /* Deposit another coin in full */
     150            2 :     TALER_TESTING_cmd_deposit (
     151              :       "deposit-full",
     152              :       "withdraw-revocation-coin-2",
     153              :       0,
     154              :       cred.user42_payto,
     155              :       "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:5\"}]}",
     156            2 :       GNUNET_TIME_UNIT_ZERO,
     157              :       "EUR:5",
     158              :       MHD_HTTP_OK),
     159              :     /* A coin key known under EUR:1, also withdrawn under EUR:5 (which is
     160              :        revoked below), for the zombie path of /melt. */
     161            2 :     TALER_TESTING_cmd_admin_add_incoming ("create-reserve-zombie",
     162              :                                           "EUR:6.02",
     163              :                                           &cred.ba,
     164              :                                           cred.user42_payto),
     165            2 :     TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-zombie",
     166              :                                                  "EUR:6.02",
     167              :                                                  cred.user42_payto,
     168              :                                                  cred.exchange_payto,
     169              :                                                  "create-reserve-zombie"),
     170            2 :     CMD_EXEC_WIREWATCH ("wirewatch-zombie"),
     171            2 :     TALER_TESTING_cmd_withdraw_amount ("withdraw-zombie-coin-5",
     172              :                                        "create-reserve-zombie",
     173              :                                        "EUR:5",
     174              :                                        0, /* age restriction off */
     175              :                                        MHD_HTTP_OK),
     176            2 :     TALER_TESTING_cmd_withdraw_amount_reuse_key ("withdraw-zombie-coin-1",
     177              :                                                  "create-reserve-zombie",
     178              :                                                  "EUR:1",
     179              :                                                  0, /* age restriction off */
     180              :                                                  "withdraw-zombie-coin-5",
     181              :                                                  MHD_HTTP_OK),
     182            2 :     TALER_TESTING_cmd_deposit (
     183              :       "deposit-zombie-coin-1",
     184              :       "withdraw-zombie-coin-1",
     185              :       0,
     186              :       cred.user42_payto,
     187              :       "{\"items\":[{\"name\":\"zombie ice cream\",\"value\":\"EUR:1\"}]}",
     188            2 :       GNUNET_TIME_UNIT_ZERO,
     189              :       "EUR:1",
     190              :       MHD_HTTP_OK),
     191              :     /**
     192              :      * Melt SOME of the rest of the coin's value
     193              :      * (EUR:3.17 = 3x EUR:1.03 + 7x EUR:0.13)
     194              :      */
     195            2 :     TALER_TESTING_cmd_melt ("refresh-melt-1",
     196              :                             "withdraw-revocation-coin-1",
     197              :                             MHD_HTTP_OK,
     198              :                             NULL),
     199              :     /**
     200              :      * Complete (successful) melt operation, and withdraw the coins
     201              :      */
     202            2 :     TALER_TESTING_cmd_melt_reveal ("refresh-reveal-1",
     203              :                                    "refresh-melt-1",
     204              :                                    MHD_HTTP_OK),
     205              :     /* Try to recoup before it's allowed */
     206            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-not-allowed",
     207              :                                       MHD_HTTP_GONE,
     208              :                                       "refresh-reveal-1#0",
     209              :                                       "refresh-melt-1",
     210              :                                       "EUR:0.1"),
     211              :     /* Make refreshed coin invalid */
     212            2 :     TALER_TESTING_cmd_revoke ("revoke-2-EUR:5",
     213              :                               MHD_HTTP_OK,
     214              :                               "refresh-melt-1",
     215              :                               config_file),
     216              :     /* Also make fully spent coin invalid (should be same denom) */
     217            2 :     TALER_TESTING_cmd_revoke ("revoke-2-EUR:5",
     218              :                               MHD_HTTP_OK,
     219              :                               "withdraw-revocation-coin-2",
     220              :                               config_file),
     221              :     /* The coin key is known under EUR:1, so melting it as an EUR:5 coin
     222              :        takes the zombie path, which must prove the conflict.  With CS,
     223              :        the key was not reused, and the coin of a revoked denomination is
     224              :        unknown. */
     225            2 :     TALER_TESTING_cmd_melt ("melt-zombie-conflict",
     226              :                             "withdraw-zombie-coin-5",
     227              :                             uses_cs
     228            2 :                             ? MHD_HTTP_GONE
     229              :                             : MHD_HTTP_CONFLICT,
     230              :                             NULL),
     231              :     /* Refund fully spent coin (which should fail) */
     232            2 :     TALER_TESTING_cmd_recoup ("recoup-fully-spent",
     233              :                               MHD_HTTP_CONFLICT,
     234              :                               "withdraw-revocation-coin-2",
     235              :                               "EUR:0.1"),
     236              :     /* Refund coin to original coin */
     237            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1a",
     238              :                                       MHD_HTTP_OK,
     239              :                                       "refresh-reveal-1#0",
     240              :                                       "refresh-melt-1",
     241              :                                       "EUR:1"),
     242            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1b",
     243              :                                       MHD_HTTP_OK,
     244              :                                       "refresh-reveal-1#1",
     245              :                                       "refresh-melt-1",
     246              :                                       "EUR:1"),
     247            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
     248              :                                       MHD_HTTP_OK,
     249              :                                       "refresh-reveal-1#2",
     250              :                                       "refresh-melt-1",
     251              :                                       "EUR:1"),
     252              :     /* Repeat recoup to test idempotency */
     253            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
     254              :                                       MHD_HTTP_OK,
     255              :                                       "refresh-reveal-1#2",
     256              :                                       "refresh-melt-1",
     257              :                                       "EUR:1"),
     258            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
     259              :                                       MHD_HTTP_OK,
     260              :                                       "refresh-reveal-1#2",
     261              :                                       "refresh-melt-1",
     262              :                                       "EUR:1"),
     263            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
     264              :                                       MHD_HTTP_OK,
     265              :                                       "refresh-reveal-1#2",
     266              :                                       "refresh-melt-1",
     267              :                                       "EUR:1"),
     268            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-1c",
     269              :                                       MHD_HTTP_OK,
     270              :                                       "refresh-reveal-1#2",
     271              :                                       "refresh-melt-1",
     272              :                                       "EUR:1"),
     273              :     /* Now we have EUR:3.83 EUR back after 3x EUR:1 in recoups */
     274              :     /* Melt original coin AGAIN, but only create one 0.1 EUR coin;
     275              :        This costs EUR:0.03 in refresh and EUR:01 in withdraw fees,
     276              :        leaving EUR:3.69. */
     277            2 :     TALER_TESTING_cmd_melt ("refresh-melt-2",
     278              :                             "withdraw-revocation-coin-1",
     279              :                             MHD_HTTP_OK,
     280              :                             "EUR:0.1",
     281              :                             NULL),
     282              :     /**
     283              :      * Complete (successful) melt operation, and withdraw the coins
     284              :      */
     285            2 :     TALER_TESTING_cmd_melt_reveal ("refresh-reveal-2",
     286              :                                    "refresh-melt-2",
     287              :                                    MHD_HTTP_OK),
     288              :     /* Revokes refreshed EUR:0.1 coin  */
     289            2 :     TALER_TESTING_cmd_revoke ("revoke-3-EUR:0.1",
     290              :                               MHD_HTTP_OK,
     291              :                               "refresh-reveal-2",
     292              :                               config_file),
     293              :     /* Revoke also original coin denomination */
     294            2 :     TALER_TESTING_cmd_revoke ("revoke-4-EUR:5",
     295              :                               MHD_HTTP_OK,
     296              :                               "withdraw-revocation-coin-1",
     297              :                               config_file),
     298              :     /* Refund coin EUR:0.1 to original coin, creating zombie! */
     299            2 :     TALER_TESTING_cmd_recoup_refresh ("recoup-2",
     300              :                                       MHD_HTTP_OK,
     301              :                                       "refresh-reveal-2",
     302              :                                       "refresh-melt-2",
     303              :                                       "EUR:0.1"),
     304              :     /* Due to recoup, original coin is now at EUR:3.79 */
     305              :     /* Refund original (now zombie) coin to reserve */
     306            2 :     TALER_TESTING_cmd_recoup ("recoup-3",
     307              :                               MHD_HTTP_OK,
     308              :                               "withdraw-revocation-coin-1",
     309              :                               "EUR:3.79"),
     310              :     /* Check the money is back with the reserve */
     311            2 :     TALER_TESTING_cmd_status ("recoup-reserve-status-1",
     312              :                               "create-reserve-1",
     313              :                               "EUR:3.79",
     314              :                               MHD_HTTP_OK),
     315              :     /* Batch recoup: three coins from one withdraw operation, two of
     316              :        them recouped in one request; the histories must show it. */
     317            2 :     TALER_TESTING_cmd_admin_add_incoming ("create-reserve-2",
     318              :                                           "EUR:30.04",
     319              :                                           &cred.ba,
     320              :                                           cred.user42_payto),
     321            2 :     TALER_TESTING_cmd_check_bank_admin_transfer ("check-create-reserve-2",
     322              :                                                  "EUR:30.04",
     323              :                                                  cred.user42_payto,
     324              :                                                  cred.exchange_payto,
     325              :                                                  "create-reserve-2"),
     326            2 :     CMD_EXEC_WIREWATCH ("wirewatch-5"),
     327            2 :     TALER_TESTING_cmd_batch_withdraw ("batch-withdraw-revocation",
     328              :                                       "create-reserve-2",
     329              :                                       MHD_HTTP_OK,
     330              :                                       "EUR:10",
     331              :                                       "EUR:10",
     332              :                                       "EUR:10",
     333              :                                       NULL),
     334            2 :     TALER_TESTING_cmd_revoke ("revoke-5-EUR:10",
     335              :                               MHD_HTTP_OK,
     336              :                               "batch-withdraw-revocation",
     337              :                               config_file),
     338            2 :     TALER_TESTING_cmd_recoup_batch ("recoup-batch",
     339              :                                     MHD_HTTP_OK,
     340              :                                     "batch-withdraw-revocation",
     341              :                                     "0,2",
     342              :                                     "EUR:10"),
     343            2 :     TALER_TESTING_cmd_coin_history ("coin-history-recouped",
     344              :                                     "batch-withdraw-revocation#0",
     345              :                                     "EUR:0",
     346              :                                     MHD_HTTP_OK),
     347              :     /* the coin that was not recouped is still unknown to the exchange */
     348            2 :     TALER_TESTING_cmd_coin_history ("coin-history-not-recouped",
     349              :                                     "batch-withdraw-revocation#1",
     350              :                                     "EUR:10",
     351              :                                     MHD_HTTP_NOT_FOUND),
     352            2 :     TALER_TESTING_cmd_reserve_history ("reserve-history-recoup",
     353              :                                        "create-reserve-2",
     354              :                                        "EUR:20.01",
     355              :                                        MHD_HTTP_OK),
     356              :     /* replaying the request is idempotent (last, as the history
     357              :        checks above would otherwise expect its entries twice) */
     358            2 :     TALER_TESTING_cmd_recoup_batch ("recoup-batch-again",
     359              :                                     MHD_HTTP_OK,
     360              :                                     "batch-withdraw-revocation",
     361              :                                     "0,2",
     362              :                                     "EUR:10"),
     363              :     /* Revocation of an online signing key: get a coin to spend after
     364              :        the revocation (age-restricted, as the plain denominations of
     365              :        all these values were revoked above) ... */
     366            2 :     TALER_TESTING_cmd_admin_add_incoming ("create-reserve-3",
     367              :                                           "EUR:1.01",
     368              :                                           &cred.ba,
     369              :                                           cred.user42_payto),
     370            2 :     CMD_EXEC_WIREWATCH ("wirewatch-6"),
     371            2 :     TALER_TESTING_cmd_withdraw_amount ("withdraw-signkey-revocation",
     372              :                                        "create-reserve-3",
     373              :                                        "EUR:1",
     374              :                                        13, /* age restriction */
     375              :                                        MHD_HTTP_OK),
     376              :     /* ... revoke the key that signed "deposit-full", which the exchange
     377              :        must refuse with a bad master signature ... */
     378            2 :     TALER_TESTING_cmd_revoke_sign_key ("revoke-signkey-bad-sig",
     379              :                                        MHD_HTTP_FORBIDDEN,
     380              :                                        true,
     381              :                                        "deposit-full"),
     382            2 :     TALER_TESTING_cmd_revoke_sign_key ("revoke-signkey",
     383              :                                        MHD_HTTP_NO_CONTENT,
     384              :                                        false,
     385              :                                        "deposit-full"),
     386              :     /* ... sign the replacement key the security module created ... */
     387            2 :     TALER_TESTING_cmd_exec_offline_sign_keys ("sign-replacement-signkey",
     388              :                                               config_file),
     389              :     /* ... then /keys must no longer offer the revoked key, so that
     390              :        clients reject replies signed with it ... */
     391            2 :     TALER_TESTING_cmd_get_exchange ("get-exchange-after-signkey-revocation",
     392            2 :                                     cred.cfg,
     393              :                                     NULL,
     394              :                                     true,
     395              :                                     true),
     396            2 :     TALER_TESTING_cmd_check_signkey_revoked (
     397              :       "check-signkey-revoked",
     398              :       "deposit-full",
     399              :       "get-exchange",
     400              :       "get-exchange-after-signkey-revocation"),
     401              :     /* ... and the exchange must sign with the replacement key, which
     402              :        the client accepts. */
     403            2 :     TALER_TESTING_cmd_deposit (
     404              :       "deposit-after-signkey-revocation",
     405              :       "withdraw-signkey-revocation",
     406              :       0,
     407              :       cred.user42_payto,
     408              :       "{\"items\":[{\"name\":\"ice cream\",\"value\":\"EUR:1\"}]}",
     409            2 :       GNUNET_TIME_UNIT_ZERO,
     410              :       "EUR:1",
     411              :       MHD_HTTP_OK),
     412            2 :     TALER_TESTING_cmd_end ()
     413              :   };
     414              : 
     415              :   (void) cls;
     416            2 :   TALER_TESTING_run (is,
     417              :                      revocation);
     418            2 : }
     419              : 
     420              : 
     421              : int
     422            2 : main (int argc,
     423              :       char *const *argv)
     424              : {
     425              :   (void) argc;
     426              :   {
     427              :     char *cipher;
     428              : 
     429            2 :     cipher = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]);
     430            2 :     GNUNET_assert (NULL != cipher);
     431            2 :     uses_cs = (0 == strcmp (cipher,
     432            2 :                             "cs"));
     433            2 :     GNUNET_asprintf (&config_file,
     434              :                      "test_exchange_api-%s.conf",
     435              :                      cipher);
     436            2 :     GNUNET_free (cipher);
     437              :   }
     438            2 :   return TALER_TESTING_main (argv,
     439              :                              "INFO",
     440              :                              config_file,
     441              :                              "exchange-account-2",
     442              :                              TALER_TESTING_BS_FAKEBANK,
     443              :                              &cred,
     444              :                              &run,
     445              :                              NULL);
     446              : }
     447              : 
     448              : 
     449              : /* end of test_exchange_api_revocation.c */
        

Generated by: LCOV version 2.0-1