LCOV - code coverage report
Current view: top level - util - crypto_helper_rsa.c (source / functions) Hit Total Coverage
Test: GNU Taler exchange coverage report Lines: 176 298 59.1 %
Date: 2022-08-25 06:15:09 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2020, 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 <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file util/crypto_helper_rsa.c
      18             :  * @brief utility functions for running out-of-process private key operations
      19             :  * @author Christian Grothoff
      20             :  */
      21             : #include "platform.h"
      22             : #include "taler_util.h"
      23             : #include "taler_signatures.h"
      24             : #include "taler-exchange-secmod-rsa.h"
      25             : #include <poll.h>
      26             : #include "crypto_helper_common.h"
      27             : 
      28             : 
      29             : struct TALER_CRYPTO_RsaDenominationHelper
      30             : {
      31             :   /**
      32             :    * Function to call with updates to available key material.
      33             :    */
      34             :   TALER_CRYPTO_RsaDenominationKeyStatusCallback dkc;
      35             : 
      36             :   /**
      37             :    * Closure for @e dkc
      38             :    */
      39             :   void *dkc_cls;
      40             : 
      41             :   /**
      42             :    * Socket address of the denomination helper process.
      43             :    * Used to reconnect if the connection breaks.
      44             :    */
      45             :   struct sockaddr_un sa;
      46             : 
      47             :   /**
      48             :    * The UNIX domain socket, -1 if we are currently not connected.
      49             :    */
      50             :   int sock;
      51             : 
      52             :   /**
      53             :    * Have we ever been sync'ed?
      54             :    */
      55             :   bool synced;
      56             : };
      57             : 
      58             : 
      59             : /**
      60             :  * Disconnect from the helper process.  Updates
      61             :  * @e sock field in @a dh.
      62             :  *
      63             :  * @param[in,out] dh handle to tear down connection of
      64             :  */
      65             : static void
      66           9 : do_disconnect (struct TALER_CRYPTO_RsaDenominationHelper *dh)
      67             : {
      68           9 :   GNUNET_break (0 == close (dh->sock));
      69           9 :   dh->sock = -1;
      70           9 :   dh->synced = false;
      71           9 : }
      72             : 
      73             : 
      74             : /**
      75             :  * Try to connect to the helper process.  Updates
      76             :  * @e sock field in @a dh.
      77             :  *
      78             :  * @param[in,out] dh handle to establish connection for
      79             :  * @return #GNUNET_OK on success
      80             :  */
      81             : static enum GNUNET_GenericReturnValue
      82         943 : try_connect (struct TALER_CRYPTO_RsaDenominationHelper *dh)
      83             : {
      84         943 :   if (-1 != dh->sock)
      85         934 :     return GNUNET_OK;
      86           9 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      87             :               "Establishing connection!\n");
      88           9 :   dh->sock = socket (AF_UNIX,
      89             :                      SOCK_STREAM,
      90             :                      0);
      91           9 :   if (-1 == dh->sock)
      92             :   {
      93           0 :     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
      94             :                          "socket");
      95           0 :     return GNUNET_SYSERR;
      96             :   }
      97           9 :   if (0 !=
      98           9 :       connect (dh->sock,
      99           9 :                (const struct sockaddr *) &dh->sa,
     100             :                sizeof (dh->sa)))
     101             :   {
     102           0 :     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
     103             :                               "connect",
     104             :                               dh->sa.sun_path);
     105           0 :     do_disconnect (dh);
     106           0 :     return GNUNET_SYSERR;
     107             :   }
     108           9 :   TALER_CRYPTO_helper_rsa_poll (dh);
     109           9 :   return GNUNET_OK;
     110             : }
     111             : 
     112             : 
     113             : struct TALER_CRYPTO_RsaDenominationHelper *
     114           9 : TALER_CRYPTO_helper_rsa_connect (
     115             :   const struct GNUNET_CONFIGURATION_Handle *cfg,
     116             :   TALER_CRYPTO_RsaDenominationKeyStatusCallback dkc,
     117             :   void *dkc_cls)
     118             : {
     119             :   struct TALER_CRYPTO_RsaDenominationHelper *dh;
     120             :   char *unixpath;
     121             : 
     122           9 :   if (GNUNET_OK !=
     123           9 :       GNUNET_CONFIGURATION_get_value_filename (cfg,
     124             :                                                "taler-exchange-secmod-rsa",
     125             :                                                "UNIXPATH",
     126             :                                                &unixpath))
     127             :   {
     128           0 :     GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
     129             :                                "taler-exchange-secmod-rsa",
     130             :                                "UNIXPATH");
     131           0 :     return NULL;
     132             :   }
     133             :   /* we use >= here because we want the sun_path to always
     134             :      be 0-terminated */
     135           9 :   if (strlen (unixpath) >= sizeof (dh->sa.sun_path))
     136             :   {
     137           0 :     GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
     138             :                                "taler-exchange-secmod-rsa",
     139             :                                "UNIXPATH",
     140             :                                "path too long");
     141           0 :     GNUNET_free (unixpath);
     142           0 :     return NULL;
     143             :   }
     144           9 :   dh = GNUNET_new (struct TALER_CRYPTO_RsaDenominationHelper);
     145           9 :   dh->dkc = dkc;
     146           9 :   dh->dkc_cls = dkc_cls;
     147           9 :   dh->sa.sun_family = AF_UNIX;
     148           9 :   strncpy (dh->sa.sun_path,
     149             :            unixpath,
     150             :            sizeof (dh->sa.sun_path) - 1);
     151           9 :   GNUNET_free (unixpath);
     152           9 :   dh->sock = -1;
     153           9 :   if (GNUNET_OK !=
     154           9 :       try_connect (dh))
     155             :   {
     156           0 :     TALER_CRYPTO_helper_rsa_disconnect (dh);
     157           0 :     return NULL;
     158             :   }
     159           9 :   return dh;
     160             : }
     161             : 
     162             : 
     163             : /**
     164             :  * Handle a #TALER_HELPER_RSA_MT_AVAIL message from the helper.
     165             :  *
     166             :  * @param dh helper context
     167             :  * @param hdr message that we received
     168             :  * @return #GNUNET_OK on success
     169             :  */
     170             : static enum GNUNET_GenericReturnValue
     171          81 : handle_mt_avail (struct TALER_CRYPTO_RsaDenominationHelper *dh,
     172             :                  const struct GNUNET_MessageHeader *hdr)
     173             : {
     174          81 :   const struct TALER_CRYPTO_RsaKeyAvailableNotification *kan
     175             :     = (const struct TALER_CRYPTO_RsaKeyAvailableNotification *) hdr;
     176          81 :   const char *buf = (const char *) &kan[1];
     177             :   const char *section_name;
     178             :   uint16_t ps;
     179             :   uint16_t snl;
     180             : 
     181          81 :   if (sizeof (*kan) > ntohs (hdr->size))
     182             :   {
     183           0 :     GNUNET_break_op (0);
     184           0 :     return GNUNET_SYSERR;
     185             :   }
     186          81 :   ps = ntohs (kan->pub_size);
     187          81 :   snl = ntohs (kan->section_name_len);
     188          81 :   if (ntohs (hdr->size) != sizeof (*kan) + ps + snl)
     189             :   {
     190           0 :     GNUNET_break_op (0);
     191           0 :     return GNUNET_SYSERR;
     192             :   }
     193          81 :   if (0 == snl)
     194             :   {
     195           0 :     GNUNET_break_op (0);
     196           0 :     return GNUNET_SYSERR;
     197             :   }
     198          81 :   section_name = &buf[ps];
     199          81 :   if ('\0' != section_name[snl - 1])
     200             :   {
     201           0 :     GNUNET_break_op (0);
     202           0 :     return GNUNET_SYSERR;
     203             :   }
     204             : 
     205             :   {
     206             :     struct TALER_DenominationPublicKey denom_pub;
     207             :     struct TALER_RsaPubHashP h_rsa;
     208             : 
     209          81 :     denom_pub.cipher = TALER_DENOMINATION_RSA;
     210             :     denom_pub.details.rsa_public_key
     211         162 :       = GNUNET_CRYPTO_rsa_public_key_decode (buf,
     212          81 :                                              ntohs (kan->pub_size));
     213          81 :     if (NULL == denom_pub.details.rsa_public_key)
     214             :     {
     215           0 :       GNUNET_break_op (0);
     216           0 :       return GNUNET_SYSERR;
     217             :     }
     218          81 :     GNUNET_CRYPTO_rsa_public_key_hash (denom_pub.details.rsa_public_key,
     219             :                                        &h_rsa.hash);
     220          81 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     221             :                 "Received RSA key %s (%s)\n",
     222             :                 GNUNET_h2s (&h_rsa.hash),
     223             :                 section_name);
     224          81 :     if (GNUNET_OK !=
     225          81 :         TALER_exchange_secmod_rsa_verify (
     226             :           &h_rsa,
     227             :           section_name,
     228             :           GNUNET_TIME_timestamp_ntoh (kan->anchor_time),
     229             :           GNUNET_TIME_relative_ntoh (kan->duration_withdraw),
     230             :           &kan->secm_pub,
     231             :           &kan->secm_sig))
     232             :     {
     233           0 :       GNUNET_break_op (0);
     234           0 :       TALER_denom_pub_free (&denom_pub);
     235           0 :       return GNUNET_SYSERR;
     236             :     }
     237          81 :     dh->dkc (dh->dkc_cls,
     238             :              section_name,
     239             :              GNUNET_TIME_timestamp_ntoh (kan->anchor_time),
     240             :              GNUNET_TIME_relative_ntoh (kan->duration_withdraw),
     241             :              &h_rsa,
     242             :              &denom_pub,
     243             :              &kan->secm_pub,
     244             :              &kan->secm_sig);
     245          81 :     TALER_denom_pub_free (&denom_pub);
     246             :   }
     247          81 :   return GNUNET_OK;
     248             : }
     249             : 
     250             : 
     251             : /**
     252             :  * Handle a #TALER_HELPER_RSA_MT_PURGE message from the helper.
     253             :  *
     254             :  * @param dh helper context
     255             :  * @param hdr message that we received
     256             :  * @return #GNUNET_OK on success
     257             :  */
     258             : static enum GNUNET_GenericReturnValue
     259           3 : handle_mt_purge (struct TALER_CRYPTO_RsaDenominationHelper *dh,
     260             :                  const struct GNUNET_MessageHeader *hdr)
     261             : {
     262           3 :   const struct TALER_CRYPTO_RsaKeyPurgeNotification *pn
     263             :     = (const struct TALER_CRYPTO_RsaKeyPurgeNotification *) hdr;
     264             : 
     265           3 :   if (sizeof (*pn) != ntohs (hdr->size))
     266             :   {
     267           0 :     GNUNET_break_op (0);
     268           0 :     return GNUNET_SYSERR;
     269             :   }
     270           3 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     271             :               "Received revocation of denomination key %s\n",
     272             :               GNUNET_h2s (&pn->h_rsa.hash));
     273           3 :   dh->dkc (dh->dkc_cls,
     274             :            NULL,
     275           3 :            GNUNET_TIME_UNIT_ZERO_TS,
     276           3 :            GNUNET_TIME_UNIT_ZERO,
     277             :            &pn->h_rsa,
     278             :            NULL,
     279             :            NULL,
     280             :            NULL);
     281           3 :   return GNUNET_OK;
     282             : }
     283             : 
     284             : 
     285             : void
     286          24 : TALER_CRYPTO_helper_rsa_poll (struct TALER_CRYPTO_RsaDenominationHelper *dh)
     287             : {
     288             :   char buf[UINT16_MAX];
     289          24 :   size_t off = 0;
     290          24 :   unsigned int retry_limit = 3;
     291          24 :   const struct GNUNET_MessageHeader *hdr
     292             :     = (const struct GNUNET_MessageHeader *) buf;
     293             : 
     294          24 :   if (GNUNET_OK !=
     295          24 :       try_connect (dh))
     296           0 :     return; /* give up */
     297             :   while (1)
     298          12 :   {
     299             :     uint16_t msize;
     300             :     ssize_t ret;
     301             : 
     302          36 :     ret = recv (dh->sock,
     303             :                 buf + off,
     304             :                 sizeof (buf) - off,
     305          36 :                 (dh->synced && (0 == off))
     306             :                 ? MSG_DONTWAIT
     307             :                 : 0);
     308          36 :     if (ret < 0)
     309             :     {
     310          24 :       if (EINTR == errno)
     311           0 :         continue;
     312          24 :       if (EAGAIN == errno)
     313             :       {
     314          24 :         GNUNET_assert (dh->synced);
     315          24 :         GNUNET_assert (0 == off);
     316          24 :         break;
     317             :       }
     318           0 :       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
     319             :                            "recv");
     320           0 :       do_disconnect (dh);
     321           0 :       if (0 == retry_limit)
     322           0 :         return; /* give up */
     323           0 :       if (GNUNET_OK !=
     324           0 :           try_connect (dh))
     325           0 :         return; /* give up */
     326           0 :       retry_limit--;
     327           0 :       continue;
     328             :     }
     329          12 :     if (0 == ret)
     330             :     {
     331           0 :       GNUNET_break (0 == off);
     332           0 :       return;
     333             :     }
     334          12 :     off += ret;
     335         105 : more:
     336         105 :     if (off < sizeof (struct GNUNET_MessageHeader))
     337          12 :       continue;
     338          93 :     msize = ntohs (hdr->size);
     339          93 :     if (off < msize)
     340           0 :       continue;
     341          93 :     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     342             :                 "Received message of type %u and length %u\n",
     343             :                 (unsigned int) ntohs (hdr->type),
     344             :                 (unsigned int) msize);
     345          93 :     switch (ntohs (hdr->type))
     346             :     {
     347          81 :     case TALER_HELPER_RSA_MT_AVAIL:
     348          81 :       if (GNUNET_OK !=
     349          81 :           handle_mt_avail (dh,
     350             :                            hdr))
     351             :       {
     352           0 :         GNUNET_break_op (0);
     353           0 :         do_disconnect (dh);
     354           0 :         return;
     355             :       }
     356          81 :       break;
     357           3 :     case TALER_HELPER_RSA_MT_PURGE:
     358           3 :       if (GNUNET_OK !=
     359           3 :           handle_mt_purge (dh,
     360             :                            hdr))
     361             :       {
     362           0 :         GNUNET_break_op (0);
     363           0 :         do_disconnect (dh);
     364           0 :         return;
     365             :       }
     366           3 :       break;
     367           9 :     case TALER_HELPER_RSA_SYNCED:
     368           9 :       GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     369             :                   "Now synchronized with RSA helper\n");
     370           9 :       dh->synced = true;
     371           9 :       break;
     372           0 :     default:
     373           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     374             :                   "Received unexpected message of type %d (len: %u)\n",
     375             :                   (unsigned int) ntohs (hdr->type),
     376             :                   (unsigned int) msize);
     377           0 :       GNUNET_break_op (0);
     378           0 :       do_disconnect (dh);
     379           0 :       return;
     380             :     }
     381          93 :     memmove (buf,
     382          93 :              &buf[msize],
     383             :              off - msize);
     384          93 :     off -= msize;
     385          93 :     goto more;
     386             :   }
     387             : }
     388             : 
     389             : 
     390             : enum TALER_ErrorCode
     391         907 : TALER_CRYPTO_helper_rsa_sign (
     392             :   struct TALER_CRYPTO_RsaDenominationHelper *dh,
     393             :   const struct TALER_CRYPTO_RsaSignRequest *rsr,
     394             :   struct TALER_BlindedDenominationSignature *bs)
     395             : {
     396         907 :   enum TALER_ErrorCode ec = TALER_EC_INVALID;
     397             : 
     398         907 :   bs->cipher = TALER_DENOMINATION_INVALID;
     399         907 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     400             :               "Starting signature process\n");
     401         907 :   if (GNUNET_OK !=
     402         907 :       try_connect (dh))
     403             :   {
     404           0 :     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     405             :                 "Failed to connect to helper\n");
     406           0 :     return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
     407             :   }
     408             : 
     409         907 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     410             :               "Requesting signature\n");
     411         907 :   {
     412         907 :     char buf[sizeof (struct TALER_CRYPTO_SignRequest) + rsr->msg_size];
     413         907 :     struct TALER_CRYPTO_SignRequest *sr
     414             :       = (struct TALER_CRYPTO_SignRequest *) buf;
     415             : 
     416         907 :     sr->header.size = htons (sizeof (buf));
     417         907 :     sr->header.type = htons (TALER_HELPER_RSA_MT_REQ_SIGN);
     418         907 :     sr->reserved = htonl (0);
     419         907 :     sr->h_rsa = *rsr->h_rsa;
     420         907 :     memcpy (&sr[1],
     421             :             rsr->msg,
     422             :             rsr->msg_size);
     423         907 :     if (GNUNET_OK !=
     424         907 :         TALER_crypto_helper_send_all (dh->sock,
     425             :                                       buf,
     426             :                                       sizeof (buf)))
     427             :     {
     428           0 :       GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
     429             :                            "send");
     430           0 :       do_disconnect (dh);
     431           0 :       return TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
     432             :     }
     433             :   }
     434             : 
     435         907 :   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     436             :               "Awaiting reply\n");
     437             :   {
     438             :     char buf[UINT16_MAX];
     439         907 :     size_t off = 0;
     440         907 :     const struct GNUNET_MessageHeader *hdr
     441             :       = (const struct GNUNET_MessageHeader *) buf;
     442         907 :     bool finished = false;
     443             : 
     444             :     while (1)
     445         907 :     {
     446             :       uint16_t msize;
     447             :       ssize_t ret;
     448             : 
     449        2721 :       ret = recv (dh->sock,
     450        1814 :                   &buf[off],
     451             :                   sizeof (buf) - off,
     452         907 :                   (finished && (0 == off))
     453             :                   ? MSG_DONTWAIT
     454             :                   : 0);
     455        1814 :       if (ret < 0)
     456             :       {
     457         907 :         if (EINTR == errno)
     458           0 :           continue;
     459         907 :         if (EAGAIN == errno)
     460             :         {
     461         907 :           GNUNET_assert (finished);
     462         907 :           GNUNET_assert (0 == off);
     463         907 :           return ec;
     464             :         }
     465           0 :         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
     466             :                              "recv");
     467           0 :         do_disconnect (dh);
     468           0 :         ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_UNAVAILABLE;
     469           0 :         break;
     470             :       }
     471         907 :       if (0 == ret)
     472             :       {
     473           0 :         GNUNET_break (0 == off);
     474           0 :         if (! finished)
     475           0 :           ec = TALER_EC_EXCHANGE_SIGNKEY_HELPER_BUG;
     476           0 :         return ec;
     477             :       }
     478         907 :       off += ret;
     479        1814 : more:
     480        1814 :       if (off < sizeof (struct GNUNET_MessageHeader))
     481         907 :         continue;
     482         907 :       msize = ntohs (hdr->size);
     483         907 :       if (off < msize)
     484           0 :         continue;
     485         907 :       switch (ntohs (hdr->type))
     486             :       {
     487         901 :       case TALER_HELPER_RSA_MT_RES_SIGNATURE:
     488         901 :         if (msize < sizeof (struct TALER_CRYPTO_SignResponse))
     489             :         {
     490           0 :           GNUNET_break_op (0);
     491           0 :           do_disconnect (dh);
     492           0 :           ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     493           0 :           goto end;
     494             :         }
     495         901 :         if (finished)
     496             :         {
     497           0 :           GNUNET_break_op (0);
     498           0 :           do_disconnect (dh);
     499           0 :           ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     500           0 :           goto end;
     501             :         }
     502             :         {
     503         901 :           const struct TALER_CRYPTO_SignResponse *sr =
     504             :             (const struct TALER_CRYPTO_SignResponse *) buf;
     505             :           struct GNUNET_CRYPTO_RsaSignature *rsa_signature;
     506             : 
     507         901 :           rsa_signature = GNUNET_CRYPTO_rsa_signature_decode (
     508         901 :             &sr[1],
     509             :             msize - sizeof (*sr));
     510         901 :           if (NULL == rsa_signature)
     511             :           {
     512           0 :             GNUNET_break_op (0);
     513           0 :             do_disconnect (dh);
     514           0 :             ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     515           0 :             goto end;
     516             :           }
     517         901 :           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     518             :                       "Received signature\n");
     519         901 :           ec = TALER_EC_NONE;
     520         901 :           finished = true;
     521         901 :           bs->cipher = TALER_DENOMINATION_RSA;
     522         901 :           bs->details.blinded_rsa_signature = rsa_signature;
     523         901 :           break;
     524             :         }
     525           6 :       case TALER_HELPER_RSA_MT_RES_SIGN_FAILURE:
     526           6 :         if (msize != sizeof (struct TALER_CRYPTO_SignFailure))
     527             :         {
     528           0 :           GNUNET_break_op (0);
     529           0 :           do_disconnect (dh);
     530           0 :           ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     531           0 :           goto end;
     532             :         }
     533             :         {
     534           6 :           const struct TALER_CRYPTO_SignFailure *sf =
     535             :             (const struct TALER_CRYPTO_SignFailure *) buf;
     536             : 
     537           6 :           ec = (enum TALER_ErrorCode) ntohl (sf->ec);
     538           6 :           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     539             :                       "Signing failed!\n");
     540           6 :           finished = true;
     541           6 :           break;
     542             :         }
     543           0 :       case TALER_HELPER_RSA_MT_AVAIL:
     544           0 :         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     545             :                     "Received new key!\n");
     546           0 :         if (GNUNET_OK !=
     547           0 :             handle_mt_avail (dh,
     548             :                              hdr))
     549             :         {
     550           0 :           GNUNET_break_op (0);
     551           0 :           do_disconnect (dh);
     552           0 :           ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     553           0 :           goto end;
     554             :         }
     555           0 :         break; /* while(1) loop ensures we recvfrom() again */
     556           0 :       case TALER_HELPER_RSA_MT_PURGE:
     557           0 :         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     558             :                     "Received revocation!\n");
     559           0 :         if (GNUNET_OK !=
     560           0 :             handle_mt_purge (dh,
     561             :                              hdr))
     562             :         {
     563           0 :           GNUNET_break_op (0);
     564           0 :           do_disconnect (dh);
     565           0 :           ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     566           0 :           goto end;
     567             :         }
     568           0 :         break; /* while(1) loop ensures we recvfrom() again */
     569           0 :       case TALER_HELPER_RSA_SYNCED:
     570           0 :         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
     571             :                     "Synchronized add odd time with RSA helper!\n");
     572           0 :         dh->synced = true;
     573           0 :         break;
     574           0 :       default:
     575           0 :         GNUNET_break_op (0);
     576           0 :         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     577             :                     "Received unexpected message of type %u\n",
     578             :                     ntohs (hdr->type));
     579           0 :         do_disconnect (dh);
     580           0 :         ec = TALER_EC_EXCHANGE_DENOMINATION_HELPER_BUG;
     581           0 :         goto end;
     582             :       }
     583         907 :       memmove (buf,
     584         907 :                &buf[msize],
     585             :                off - msize);
     586         907 :       off -= msize;
     587         907 :       goto more;
     588             :     } /* while(1) */
     589           0 : end:
     590           0 :     if (finished)
     591           0 :       TALER_blinded_denom_sig_free (bs);
     592           0 :     return ec;
     593             :   }
     594             : }
     595             : 
     596             : 
     597             : enum TALER_ErrorCode
     598           0 : TALER_CRYPTO_helper_rsa_batch_sign (
     599             :   struct TALER_CRYPTO_RsaDenominationHelper *dh,
     600             :   const struct TALER_CRYPTO_RsaSignRequest *rsrs,
     601             :   unsigned int rsrs_length,
     602             :   struct TALER_BlindedDenominationSignature *bss)
     603             : {
     604           0 :   GNUNET_break (0);
     605           0 :   return -1; /* FIXME #7272: NOT IMPLEMENTED! */
     606             : }
     607             : 
     608             : 
     609             : void
     610           3 : TALER_CRYPTO_helper_rsa_revoke (
     611             :   struct TALER_CRYPTO_RsaDenominationHelper *dh,
     612             :   const struct TALER_RsaPubHashP *h_rsa)
     613             : {
     614           3 :   struct TALER_CRYPTO_RevokeRequest rr = {
     615           3 :     .header.size = htons (sizeof (rr)),
     616           3 :     .header.type = htons (TALER_HELPER_RSA_MT_REQ_REVOKE),
     617             :     .h_rsa = *h_rsa
     618             :   };
     619             : 
     620           3 :   if (GNUNET_OK !=
     621           3 :       try_connect (dh))
     622           0 :     return; /* give up */
     623           3 :   if (GNUNET_OK !=
     624           3 :       TALER_crypto_helper_send_all (dh->sock,
     625             :                                     &rr,
     626             :                                     sizeof (rr)))
     627             :   {
     628           0 :     GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
     629             :                          "send");
     630           0 :     do_disconnect (dh);
     631           0 :     return;
     632             :   }
     633           3 :   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
     634             :               "Requested revocation of denomination key %s\n",
     635             :               GNUNET_h2s (&h_rsa->hash));
     636             : }
     637             : 
     638             : 
     639             : void
     640           9 : TALER_CRYPTO_helper_rsa_disconnect (
     641             :   struct TALER_CRYPTO_RsaDenominationHelper *dh)
     642             : {
     643           9 :   if (-1 != dh->sock)
     644           9 :     do_disconnect (dh);
     645           9 :   GNUNET_free (dh);
     646           9 : }
     647             : 
     648             : 
     649             : /* end of crypto_helper_denom.c */

Generated by: LCOV version 1.14