LCOV - code coverage report
Current view: top level - lib - exchange_api_post-management-signkeys-EXCHANGE_PUB-revoke.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 75 0
Test Date: 2026-04-14 15:39:31 Functions: 0.0 % 4 0

            Line data    Source code
       1              : /*
       2              :   This file is part of TALER
       3              :   Copyright (C) 2015-2026 Taler Systems SA
       4              : 
       5              :   TALER is free software; you can redistribute it and/or modify it under the
       6              :   terms of the GNU 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 General Public License for more details.
      12              : 
      13              :   You should have received a copy of the GNU General Public License along with
      14              :   TALER; see the file COPYING.  If not, see
      15              :   <http://www.gnu.org/licenses/>
      16              : */
      17              : /**
      18              :  * @file lib/exchange_api_post-management-signkeys-EXCHANGE_PUB-revoke.c
      19              :  * @brief functions to revoke an exchange online signing key
      20              :  * @author Christian Grothoff
      21              :  */
      22              : #include "taler/taler_json_lib.h"
      23              : #include <gnunet/gnunet_curl_lib.h>
      24              : #include <microhttpd.h>
      25              : #include "taler/exchange/post-management-signkeys-EXCHANGE_PUB-revoke.h"
      26              : #include "exchange_api_curl_defaults.h"
      27              : #include "taler/taler_curl_lib.h"
      28              : 
      29              : 
      30              : struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle
      31              : {
      32              : 
      33              :   /**
      34              :    * The base URL for this request.
      35              :    */
      36              :   char *base_url;
      37              : 
      38              :   /**
      39              :    * The full URL for this request, set during _start.
      40              :    */
      41              :   char *url;
      42              : 
      43              :   /**
      44              :    * Minor context that holds body and headers.
      45              :    */
      46              :   struct TALER_CURL_PostContext post_ctx;
      47              : 
      48              :   /**
      49              :    * Handle for the request.
      50              :    */
      51              :   struct GNUNET_CURL_Job *job;
      52              : 
      53              :   /**
      54              :    * Function to call with the result.
      55              :    */
      56              :   TALER_EXCHANGE_PostManagementSignkeysRevokeCallback cb;
      57              : 
      58              :   /**
      59              :    * Closure for @a cb.
      60              :    */
      61              :   TALER_EXCHANGE_POST_MANAGEMENT_SIGNKEYS_REVOKE_RESULT_CLOSURE *cb_cls;
      62              : 
      63              :   /**
      64              :    * Reference to the execution context.
      65              :    */
      66              :   struct GNUNET_CURL_Context *ctx;
      67              : 
      68              :   /**
      69              :    * The public signing key that was revoked.
      70              :    */
      71              :   struct TALER_ExchangePublicKeyP exchange_pub;
      72              : 
      73              :   /**
      74              :    * Signature affirming the revocation.
      75              :    */
      76              :   struct TALER_MasterSignatureP master_sig;
      77              : 
      78              : };
      79              : 
      80              : 
      81              : /**
      82              :  * Function called when we're done processing the
      83              :  * HTTP POST /management/signkeys/$EXCHANGE_PUB/revoke request.
      84              :  *
      85              :  * @param cls the `struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle`
      86              :  * @param response_code HTTP response code, 0 on error
      87              :  * @param response response body, NULL if not in JSON
      88              :  */
      89              : static void
      90            0 : handle_signkeys_revoke_finished (void *cls,
      91              :                                  long response_code,
      92              :                                  const void *response)
      93              : {
      94            0 :   struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle *pmsrh = cls;
      95            0 :   const json_t *json = response;
      96            0 :   struct TALER_EXCHANGE_PostManagementSignkeysRevokeResponse res = {
      97            0 :     .hr.http_status = (unsigned int) response_code,
      98              :     .hr.reply = json
      99              :   };
     100              : 
     101            0 :   pmsrh->job = NULL;
     102            0 :   switch (response_code)
     103              :   {
     104            0 :   case 0:
     105              :     /* no reply */
     106            0 :     res.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
     107            0 :     res.hr.hint = "server offline?";
     108            0 :     break;
     109            0 :   case MHD_HTTP_NO_CONTENT:
     110            0 :     break;
     111            0 :   case MHD_HTTP_FORBIDDEN:
     112            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     113            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     114            0 :     break;
     115            0 :   default:
     116              :     /* unexpected response code */
     117            0 :     GNUNET_break_op (0);
     118            0 :     res.hr.ec = TALER_JSON_get_error_code (json);
     119            0 :     res.hr.hint = TALER_JSON_get_error_hint (json);
     120            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     121              :                 "Unexpected response code %u/%d for exchange management revoke signkey\n",
     122              :                 (unsigned int) response_code,
     123              :                 (int) res.hr.ec);
     124            0 :     break;
     125              :   }
     126            0 :   if (NULL != pmsrh->cb)
     127              :   {
     128            0 :     pmsrh->cb (pmsrh->cb_cls,
     129              :                &res);
     130            0 :     pmsrh->cb = NULL;
     131              :   }
     132            0 :   TALER_EXCHANGE_post_management_signkeys_revoke_cancel (pmsrh);
     133            0 : }
     134              : 
     135              : 
     136              : struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle *
     137            0 : TALER_EXCHANGE_post_management_signkeys_revoke_create (
     138              :   struct GNUNET_CURL_Context *ctx,
     139              :   const char *url,
     140              :   const struct TALER_ExchangePublicKeyP *exchange_pub,
     141              :   const struct TALER_MasterSignatureP *master_sig)
     142              : {
     143              :   struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle *pmsrh;
     144              : 
     145            0 :   pmsrh = GNUNET_new (
     146              :     struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle);
     147            0 :   pmsrh->ctx = ctx;
     148            0 :   pmsrh->base_url = GNUNET_strdup (url);
     149            0 :   pmsrh->exchange_pub = *exchange_pub;
     150            0 :   pmsrh->master_sig = *master_sig;
     151            0 :   return pmsrh;
     152              : }
     153              : 
     154              : 
     155              : enum TALER_ErrorCode
     156            0 : TALER_EXCHANGE_post_management_signkeys_revoke_start (
     157              :   struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle *pmsrh,
     158              :   TALER_EXCHANGE_PostManagementSignkeysRevokeCallback cb,
     159              :   TALER_EXCHANGE_POST_MANAGEMENT_SIGNKEYS_REVOKE_RESULT_CLOSURE *cb_cls)
     160              : {
     161              :   CURL *eh;
     162              :   json_t *body;
     163              : 
     164            0 :   pmsrh->cb = cb;
     165            0 :   pmsrh->cb_cls = cb_cls;
     166              :   {
     167              :     char epub_str[sizeof (pmsrh->exchange_pub) * 2];
     168              :     char arg_str[sizeof (epub_str) + 64];
     169              :     char *end;
     170              : 
     171            0 :     end = GNUNET_STRINGS_data_to_string (&pmsrh->exchange_pub,
     172              :                                          sizeof (pmsrh->exchange_pub),
     173              :                                          epub_str,
     174              :                                          sizeof (epub_str));
     175            0 :     *end = '\0';
     176            0 :     GNUNET_snprintf (arg_str,
     177              :                      sizeof (arg_str),
     178              :                      "management/signkeys/%s/revoke",
     179              :                      epub_str);
     180            0 :     pmsrh->url = TALER_url_join (pmsrh->base_url,
     181              :                                  arg_str,
     182              :                                  NULL);
     183              :   }
     184            0 :   if (NULL == pmsrh->url)
     185              :   {
     186            0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     187              :                 "Could not construct request URL.\n");
     188            0 :     return TALER_EC_GENERIC_CONFIGURATION_INVALID;
     189              :   }
     190            0 :   body = GNUNET_JSON_PACK (
     191              :     GNUNET_JSON_pack_data_auto ("master_sig",
     192              :                                 &pmsrh->master_sig));
     193            0 :   eh = TALER_EXCHANGE_curl_easy_get_ (pmsrh->url);
     194            0 :   if ( (NULL == eh) ||
     195              :        (GNUNET_OK !=
     196            0 :         TALER_curl_easy_post (&pmsrh->post_ctx,
     197              :                               eh,
     198              :                               body)) )
     199              :   {
     200            0 :     GNUNET_break (0);
     201            0 :     if (NULL != eh)
     202            0 :       curl_easy_cleanup (eh);
     203            0 :     json_decref (body);
     204            0 :     GNUNET_free (pmsrh->url);
     205            0 :     pmsrh->url = NULL;
     206            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     207              :   }
     208            0 :   json_decref (body);
     209            0 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     210              :               "Requesting URL '%s'\n",
     211              :               pmsrh->url);
     212            0 :   pmsrh->job = GNUNET_CURL_job_add2 (pmsrh->ctx,
     213              :                                      eh,
     214            0 :                                      pmsrh->post_ctx.headers,
     215              :                                      &handle_signkeys_revoke_finished,
     216              :                                      pmsrh);
     217            0 :   if (NULL == pmsrh->job)
     218              :   {
     219            0 :     TALER_curl_easy_post_finished (&pmsrh->post_ctx);
     220            0 :     GNUNET_free (pmsrh->url);
     221            0 :     pmsrh->url = NULL;
     222            0 :     return TALER_EC_GENERIC_INTERNAL_INVARIANT_FAILURE;
     223              :   }
     224            0 :   return TALER_EC_NONE;
     225              : }
     226              : 
     227              : 
     228              : void
     229            0 : TALER_EXCHANGE_post_management_signkeys_revoke_cancel (
     230              :   struct TALER_EXCHANGE_PostManagementSignkeysRevokeHandle *pmsrh)
     231              : {
     232            0 :   if (NULL != pmsrh->job)
     233              :   {
     234            0 :     GNUNET_CURL_job_cancel (pmsrh->job);
     235            0 :     pmsrh->job = NULL;
     236              :   }
     237            0 :   TALER_curl_easy_post_finished (&pmsrh->post_ctx);
     238            0 :   GNUNET_free (pmsrh->url);
     239            0 :   GNUNET_free (pmsrh->base_url);
     240            0 :   GNUNET_free (pmsrh);
     241            0 : }
     242              : 
     243              : 
     244              : /* end of exchange_api_post-management-signkeys-EXCHANGE_PUB-revoke.c */
        

Generated by: LCOV version 2.0-1