LCOV - code coverage report
Current view: top level - lib - exchange_api_management_revoke_signing_key.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 0 67 0.0 %
Date: 2022-08-25 06:15:09 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2015-2021 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_management_revoke_signing_key.c
      19             :  * @brief functions to revoke an exchange online signing key
      20             :  * @author Christian Grothoff
      21             :  */
      22             : #include "platform.h"
      23             : #include "taler_json_lib.h"
      24             : #include <gnunet/gnunet_curl_lib.h>
      25             : #include "taler_exchange_service.h"
      26             : #include "exchange_api_curl_defaults.h"
      27             : #include "taler_signatures.h"
      28             : #include "taler_curl_lib.h"
      29             : #include "taler_json_lib.h"
      30             : 
      31             : 
      32             : struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle
      33             : {
      34             : 
      35             :   /**
      36             :    * The url for this request.
      37             :    */
      38             :   char *url;
      39             : 
      40             :   /**
      41             :    * Minor context that holds body and headers.
      42             :    */
      43             :   struct TALER_CURL_PostContext post_ctx;
      44             : 
      45             :   /**
      46             :    * Handle for the request.
      47             :    */
      48             :   struct GNUNET_CURL_Job *job;
      49             : 
      50             :   /**
      51             :    * Function to call with the result.
      52             :    */
      53             :   TALER_EXCHANGE_ManagementRevokeSigningKeyCallback cb;
      54             : 
      55             :   /**
      56             :    * Closure for @a cb.
      57             :    */
      58             :   void *cb_cls;
      59             : 
      60             :   /**
      61             :    * Reference to the execution context.
      62             :    */
      63             :   struct GNUNET_CURL_Context *ctx;
      64             : };
      65             : 
      66             : 
      67             : /**
      68             :  * Function called when we're done processing the
      69             :  * HTTP /management/signkeys/%s/revoke request.
      70             :  *
      71             :  * @param cls the `struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *`
      72             :  * @param response_code HTTP response code, 0 on error
      73             :  * @param response response body, NULL if not in JSON
      74             :  */
      75             : static void
      76           0 : handle_revoke_signing_finished (void *cls,
      77             :                                 long response_code,
      78             :                                 const void *response)
      79             : {
      80           0 :   struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *rh = cls;
      81           0 :   const json_t *json = response;
      82           0 :   struct TALER_EXCHANGE_HttpResponse hr = {
      83           0 :     .http_status = (unsigned int) response_code,
      84             :     .reply = json
      85             :   };
      86             : 
      87           0 :   rh->job = NULL;
      88           0 :   switch (response_code)
      89             :   {
      90           0 :   case 0:
      91             :     /* no reply */
      92           0 :     hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
      93           0 :     hr.hint = "server offline?";
      94           0 :     break;
      95           0 :   case MHD_HTTP_NO_CONTENT:
      96           0 :     break;
      97           0 :   case MHD_HTTP_FORBIDDEN:
      98           0 :     hr.ec = TALER_JSON_get_error_code (json);
      99           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     100           0 :     break;
     101           0 :   default:
     102             :     /* unexpected response code */
     103           0 :     GNUNET_break_op (0);
     104           0 :     hr.ec = TALER_JSON_get_error_code (json);
     105           0 :     hr.hint = TALER_JSON_get_error_hint (json);
     106           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     107             :                 "Unexpected response code %u/%d for exchange management revoke signkey\n",
     108             :                 (unsigned int) response_code,
     109             :                 (int) hr.ec);
     110           0 :     break;
     111             :   }
     112           0 :   if (NULL != rh->cb)
     113             :   {
     114           0 :     rh->cb (rh->cb_cls,
     115             :             &hr);
     116           0 :     rh->cb = NULL;
     117             :   }
     118           0 :   TALER_EXCHANGE_management_revoke_signing_key_cancel (rh);
     119           0 : }
     120             : 
     121             : 
     122             : struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *
     123           0 : TALER_EXCHANGE_management_revoke_signing_key (
     124             :   struct GNUNET_CURL_Context *ctx,
     125             :   const char *url,
     126             :   const struct TALER_ExchangePublicKeyP *exchange_pub,
     127             :   const struct TALER_MasterSignatureP *master_sig,
     128             :   TALER_EXCHANGE_ManagementRevokeSigningKeyCallback cb,
     129             :   void *cb_cls)
     130             : {
     131             :   struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *rh;
     132             :   CURL *eh;
     133             :   json_t *body;
     134             : 
     135           0 :   rh = GNUNET_new (struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle);
     136           0 :   rh->cb = cb;
     137           0 :   rh->cb_cls = cb_cls;
     138           0 :   rh->ctx = ctx;
     139             :   {
     140             :     char epub_str[sizeof (*exchange_pub) * 2];
     141             :     char arg_str[sizeof (epub_str) + 64];
     142             :     char *end;
     143             : 
     144           0 :     end = GNUNET_STRINGS_data_to_string (exchange_pub,
     145             :                                          sizeof (*exchange_pub),
     146             :                                          epub_str,
     147             :                                          sizeof (epub_str));
     148           0 :     *end = '\0';
     149           0 :     GNUNET_snprintf (arg_str,
     150             :                      sizeof (arg_str),
     151             :                      "management/signkeys/%s/revoke",
     152             :                      epub_str);
     153           0 :     rh->url = TALER_url_join (url,
     154             :                               arg_str,
     155             :                               NULL);
     156             :   }
     157           0 :   if (NULL == rh->url)
     158             :   {
     159           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     160             :                 "Could not construct request URL.\n");
     161           0 :     GNUNET_free (rh);
     162           0 :     return NULL;
     163             :   }
     164           0 :   body = GNUNET_JSON_PACK (
     165             :     GNUNET_JSON_pack_data_auto ("master_sig",
     166             :                                 master_sig));
     167           0 :   eh = TALER_EXCHANGE_curl_easy_get_ (rh->url);
     168           0 :   if ( (NULL == eh) ||
     169             :        (GNUNET_OK !=
     170           0 :         TALER_curl_easy_post (&rh->post_ctx,
     171             :                               eh,
     172             :                               body)) )
     173             :   {
     174           0 :     GNUNET_break (0);
     175           0 :     if (NULL != eh)
     176           0 :       curl_easy_cleanup (eh);
     177           0 :     json_decref (body);
     178           0 :     GNUNET_free (rh->url);
     179           0 :     return NULL;
     180             :   }
     181           0 :   json_decref (body);
     182           0 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     183             :               "Requesting URL '%s'\n",
     184             :               rh->url);
     185           0 :   rh->job = GNUNET_CURL_job_add2 (ctx,
     186             :                                   eh,
     187           0 :                                   rh->post_ctx.headers,
     188             :                                   &handle_revoke_signing_finished,
     189             :                                   rh);
     190           0 :   if (NULL == rh->job)
     191             :   {
     192           0 :     TALER_EXCHANGE_management_revoke_signing_key_cancel (rh);
     193           0 :     return NULL;
     194             :   }
     195           0 :   return rh;
     196             : }
     197             : 
     198             : 
     199             : void
     200           0 : TALER_EXCHANGE_management_revoke_signing_key_cancel (
     201             :   struct TALER_EXCHANGE_ManagementRevokeSigningKeyHandle *rh)
     202             : {
     203           0 :   if (NULL != rh->job)
     204             :   {
     205           0 :     GNUNET_CURL_job_cancel (rh->job);
     206           0 :     rh->job = NULL;
     207             :   }
     208           0 :   TALER_curl_easy_post_finished (&rh->post_ctx);
     209           0 :   GNUNET_free (rh->url);
     210           0 :   GNUNET_free (rh);
     211           0 : }

Generated by: LCOV version 1.14