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

Generated by: LCOV version 1.14