LCOV - code coverage report
Current view: top level - exchange - taler-exchange-httpd_test.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 0 152 0.0 %
Date: 2017-09-17 17:24:28 Functions: 0 9 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2015 GNUnet e.V.
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify it under the
       6             :   terms of the GNU Affero 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 Affero General Public License for more details.
      12             : 
      13             :   You should have received a copy of the GNU Affero General Public License along with
      14             :   TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             : */
      16             : /**
      17             :  * @file taler-exchange-httpd_test.c
      18             :  * @brief Handle /test requests; parses the POST and JSON and
      19             :  *        checks that the client is binary-compatible
      20             :  * @author Christian Grothoff
      21             :  */
      22             : #include "platform.h"
      23             : #include <gnunet/gnunet_util_lib.h>
      24             : #include <gnunet/gnunet_json_lib.h>
      25             : #include <jansson.h>
      26             : #include <microhttpd.h>
      27             : #include "taler_signatures.h"
      28             : #include "taler-exchange-httpd_test.h"
      29             : #include "taler-exchange-httpd_parsing.h"
      30             : #include "taler-exchange-httpd_responses.h"
      31             : 
      32             : 
      33             : /**
      34             :  * Private key the test module uses for signing.
      35             :  */
      36             : static struct GNUNET_CRYPTO_RsaPrivateKey *rsa_pk;
      37             : 
      38             : 
      39             : /**
      40             :  * Handle a "/test/base32" request.  Parses the JSON in the post, runs
      41             :  * the Crockford Base32 decoder on the "input" field in the JSON,
      42             :  * hashes the result and sends the hashed value back as a JSON
      43             :  * string with in Base32 Crockford encoding.  Thus, this API
      44             :  * allows testing the hashing and Crockford encoding/decoding
      45             :  * functions.
      46             :  *
      47             :  * @param rh context of the handler
      48             :  * @param connection the MHD connection to handle
      49             :  * @param[in,out] connection_cls the connection's closure (can be updated)
      50             :  * @param upload_data upload data
      51             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
      52             :  * @return MHD result code
      53             :  */
      54             : int
      55           0 : TEH_TEST_handler_test_base32 (struct TEH_RequestHandler *rh,
      56             :                               struct MHD_Connection *connection,
      57             :                               void **connection_cls,
      58             :                               const char *upload_data,
      59             :                               size_t *upload_data_size)
      60             : {
      61             :   json_t *json;
      62             :   int res;
      63             :   void *in_ptr;
      64             :   size_t in_ptr_size;
      65             :   struct GNUNET_HashCode hc;
      66           0 :   struct GNUNET_JSON_Specification spec[] = {
      67             :     GNUNET_JSON_spec_varsize ("input", &in_ptr, &in_ptr_size),
      68             :     GNUNET_JSON_spec_end ()
      69             :   };
      70             : 
      71           0 :   res = TEH_PARSE_post_json (connection,
      72             :                              connection_cls,
      73             :                              upload_data,
      74             :                              upload_data_size,
      75             :                              &json);
      76           0 :   if (GNUNET_SYSERR == res)
      77           0 :     return MHD_NO;
      78           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
      79           0 :     return MHD_YES;
      80           0 :   res = TEH_PARSE_json_data (connection,
      81             :                              json,
      82             :                              spec);
      83           0 :   if (GNUNET_YES != res)
      84           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
      85           0 :   GNUNET_CRYPTO_hash (in_ptr,
      86             :                       in_ptr_size,
      87             :                       &hc);
      88           0 :   GNUNET_JSON_parse_free (spec);
      89           0 :   json_decref (json);
      90           0 :   return TEH_RESPONSE_reply_json_pack (connection,
      91             :                                        MHD_HTTP_OK,
      92             :                                        "{s:o}",
      93             :                                        "output",
      94             :                                        GNUNET_JSON_from_data_auto (&hc));
      95             : }
      96             : 
      97             : 
      98             : /**
      99             :  * Handle a "/test/encrypt" request.  Parses the JSON in the post,
     100             :  * runs the Crockford Base32 decoder on the "input" field in the JSON,
     101             :  * and encrypts the result with a shared secret derived using the HKDF
     102             :  * function with salt "skey" and IV derived with salt "iv" of the
     103             :  * Crockford Base32-encoded "key_hash" field in the JSON.  The
     104             :  * symmetric encryption is the AES/Twofish double-encryption used in
     105             :  * Taler/GNUnet.  The resulting ciphertext is returned as a Crockford
     106             :  * Base32 encoded JSON string.
     107             :  *
     108             :  * @param rh context of the handler
     109             :  * @param connection the MHD connection to handle
     110             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     111             :  * @param upload_data upload data
     112             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     113             :  * @return MHD result code
     114             :  */
     115             : int
     116           0 : TEH_TEST_handler_test_encrypt (struct TEH_RequestHandler *rh,
     117             :                                struct MHD_Connection *connection,
     118             :                                void **connection_cls,
     119             :                                const char *upload_data,
     120             :                                size_t *upload_data_size)
     121             : {
     122             :   json_t *json;
     123             :   int res;
     124             :   struct GNUNET_HashCode key;
     125             :   struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
     126             :   struct GNUNET_CRYPTO_SymmetricSessionKey skey;
     127             :   void *in_ptr;
     128             :   size_t in_ptr_size;
     129           0 :   struct GNUNET_JSON_Specification spec[] = {
     130             :     GNUNET_JSON_spec_varsize ("input", &in_ptr, &in_ptr_size),
     131             :     GNUNET_JSON_spec_fixed_auto ("key_hash", &key),
     132             :     GNUNET_JSON_spec_end ()
     133             :   };
     134             :   char *out;
     135             : 
     136           0 :   res = TEH_PARSE_post_json (connection,
     137             :                              connection_cls,
     138             :                              upload_data,
     139             :                              upload_data_size,
     140             :                              &json);
     141           0 :   if (GNUNET_SYSERR == res)
     142           0 :     return MHD_NO;
     143           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     144           0 :     return MHD_YES;
     145           0 :   res = TEH_PARSE_json_data (connection,
     146             :                              json,
     147             :                              spec);
     148           0 :   json_decref (json);
     149           0 :   if (GNUNET_YES != res)
     150           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     151           0 :   GNUNET_assert (GNUNET_YES ==
     152             :                  GNUNET_CRYPTO_kdf (&skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
     153             :                                     "skey", strlen ("skey"),
     154             :                                     &key, sizeof (key),
     155             :                                     NULL, 0));
     156           0 :   GNUNET_assert (GNUNET_YES ==
     157             :                  GNUNET_CRYPTO_kdf (&iv, sizeof (struct GNUNET_CRYPTO_SymmetricInitializationVector),
     158             :                                     "iv", strlen ("iv"),
     159             :                                     &key, sizeof (key),
     160             :                                     NULL, 0));
     161           0 :   out = GNUNET_malloc (in_ptr_size);
     162           0 :   GNUNET_break (in_ptr_size ==
     163             :                 GNUNET_CRYPTO_symmetric_encrypt (in_ptr,
     164             :                                                  in_ptr_size,
     165             :                                                  &skey,
     166             :                                                  &iv,
     167             :                                                  out));
     168           0 :   json = GNUNET_JSON_from_data (out,
     169             :                                 in_ptr_size);
     170           0 :   GNUNET_free (out);
     171           0 :   GNUNET_JSON_parse_free (spec);
     172           0 :   return TEH_RESPONSE_reply_json_pack (connection,
     173             :                                        MHD_HTTP_OK,
     174             :                                        "{s:o}",
     175             :                                        "output",
     176             :                                        json);
     177             : }
     178             : 
     179             : 
     180             : /**
     181             :  * Handle a "/test/hkdf" request.  Parses the JSON in the post, runs
     182             :  * the Crockford Base32 decoder on the "input" field in the JSON,
     183             :  * computes `HKDF(input, "salty")` and sends the result back as a JSON
     184             :  * string with in Base32 Crockford encoding.  Thus, this API allows
     185             :  * testing the use of the (H)KDF.  Note that the test fixes the
     186             :  * input and output sizes and the salt (and the hash functions used
     187             :  * by the HKDF), so this is only useful to test the HKDF in the
     188             :  * same way it will be used within Taler/GNUnet.
     189             :  *
     190             :  * @param rh context of the handler
     191             :  * @param connection the MHD connection to handle
     192             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     193             :  * @param upload_data upload data
     194             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     195             :  * @return MHD result code
     196             :  */
     197             : int
     198           0 : TEH_TEST_handler_test_hkdf (struct TEH_RequestHandler *rh,
     199             :                             struct MHD_Connection *connection,
     200             :                             void **connection_cls,
     201             :                             const char *upload_data,
     202             :                             size_t *upload_data_size)
     203             : {
     204             :   json_t *json;
     205             :   int res;
     206             :   struct GNUNET_HashCode hc;
     207             :   void *in_ptr;
     208             :   size_t in_ptr_size;
     209           0 :   struct GNUNET_JSON_Specification spec[] = {
     210             :     GNUNET_JSON_spec_varsize ("input", &in_ptr, &in_ptr_size),
     211             :     GNUNET_JSON_spec_end ()
     212             :   };
     213             : 
     214           0 :   res = TEH_PARSE_post_json (connection,
     215             :                              connection_cls,
     216             :                              upload_data,
     217             :                              upload_data_size,
     218             :                              &json);
     219           0 :   if (GNUNET_SYSERR == res)
     220           0 :     return MHD_NO;
     221           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     222           0 :     return MHD_YES;
     223           0 :   res = TEH_PARSE_json_data (connection,
     224             :                              json,
     225             :                              spec);
     226           0 :   json_decref (json);
     227           0 :   if (GNUNET_YES != res)
     228           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     229           0 :   GNUNET_CRYPTO_kdf (&hc, sizeof (hc),
     230             :                      "salty", strlen ("salty"),
     231             :                      in_ptr,
     232             :                      in_ptr_size,
     233             :                      NULL, 0);
     234           0 :   GNUNET_JSON_parse_free (spec);
     235           0 :   json = GNUNET_JSON_from_data_auto (&hc);
     236           0 :   return TEH_RESPONSE_reply_json_pack (connection,
     237             :                                        MHD_HTTP_OK,
     238             :                                        "{s:o}",
     239             :                                        "output",
     240             :                                        json);
     241             : }
     242             : 
     243             : 
     244             : /**
     245             :  * Handle a "/test/ecdhe" request.  Parses the JSON in the post, which
     246             :  * must contain a "ecdhe_pub" with a public key and an "ecdhe_priv"
     247             :  * with a private key.  The reply is the resulting JSON is an object
     248             :  * with the field "ecdh_hash" containing a Crockford Base32-encoded
     249             :  * string representing the hash derived via ECDH of the two keys.
     250             :  *
     251             :  * @param rh context of the handler
     252             :  * @param connection the MHD connection to handle
     253             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     254             :  * @param upload_data upload data
     255             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     256             :  * @return MHD result code
     257             :   */
     258             : int
     259           0 : TEH_TEST_handler_test_ecdhe (struct TEH_RequestHandler *rh,
     260             :                              struct MHD_Connection *connection,
     261             :                              void **connection_cls,
     262             :                              const char *upload_data,
     263             :                              size_t *upload_data_size)
     264             : {
     265             :   json_t *json;
     266             :   int res;
     267             :   struct GNUNET_CRYPTO_EcdhePublicKey pub;
     268             :   struct GNUNET_CRYPTO_EcdhePrivateKey priv;
     269             :   struct GNUNET_HashCode hc;
     270           0 :   struct GNUNET_JSON_Specification spec[] = {
     271             :     GNUNET_JSON_spec_fixed_auto ("ecdhe_pub", &pub),
     272             :     GNUNET_JSON_spec_fixed_auto ("ecdhe_priv", &priv),
     273             :     GNUNET_JSON_spec_end ()
     274             :   };
     275             : 
     276           0 :   res = TEH_PARSE_post_json (connection,
     277             :                              connection_cls,
     278             :                              upload_data,
     279             :                              upload_data_size,
     280             :                              &json);
     281           0 :   if (GNUNET_SYSERR == res)
     282           0 :     return MHD_NO;
     283           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     284           0 :     return MHD_YES;
     285           0 :   res = TEH_PARSE_json_data (connection,
     286             :                              json,
     287             :                              spec);
     288           0 :   json_decref (json);
     289           0 :   if (GNUNET_YES != res)
     290           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     291           0 :   if (GNUNET_OK !=
     292           0 :       GNUNET_CRYPTO_ecc_ecdh (&priv,
     293             :                               &pub,
     294             :                               &hc))
     295             :   {
     296           0 :     GNUNET_JSON_parse_free (spec);
     297           0 :     return TEH_RESPONSE_reply_internal_error (connection,
     298             :                                               TALER_EC_TEST_ECDH_ERROR,
     299             :                                               "Failed to perform ECDH");
     300             :   }
     301           0 :   GNUNET_JSON_parse_free (spec);
     302           0 :   return TEH_RESPONSE_reply_json_pack (connection,
     303             :                                        MHD_HTTP_OK,
     304             :                                        "{s:o}",
     305             :                                        "ecdh_hash",
     306             :                                        GNUNET_JSON_from_data_auto (&hc));
     307             : }
     308             : 
     309             : 
     310             : /**
     311             :  * Handle a "/test/eddsa" request.  Parses the JSON in the post,
     312             :  * which must contain a "eddsa_pub" with a public key and an
     313             :  *"eddsa_sig" with the corresponding signature for a purpose
     314             :  * of #TALER_SIGNATURE_CLIENT_TEST_EDDSA.  If the signature is
     315             :  * valid, a reply with a #TALER_SIGNATURE_EXCHANGE_TEST_EDDSA is
     316             :  * returned using the same JSON format.
     317             :  *
     318             :  * @param rh context of the handler
     319             :  * @param connection the MHD connection to handle
     320             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     321             :  * @param upload_data upload data
     322             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     323             :  * @return MHD result code
     324             :   */
     325             : int
     326           0 : TEH_TEST_handler_test_eddsa (struct TEH_RequestHandler *rh,
     327             :                              struct MHD_Connection *connection,
     328             :                              void **connection_cls,
     329             :                              const char *upload_data,
     330             :                              size_t *upload_data_size)
     331             : {
     332             :   json_t *json;
     333             :   int res;
     334             :   struct GNUNET_CRYPTO_EddsaPublicKey pub;
     335             :   struct GNUNET_CRYPTO_EddsaSignature sig;
     336             :   struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
     337           0 :   struct GNUNET_JSON_Specification spec[] = {
     338             :     GNUNET_JSON_spec_fixed_auto ("eddsa_pub", &pub),
     339             :     GNUNET_JSON_spec_fixed_auto ("eddsa_sig", &sig),
     340             :     GNUNET_JSON_spec_end ()
     341             :   };
     342             :   struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
     343             : 
     344           0 :   res = TEH_PARSE_post_json (connection,
     345             :                              connection_cls,
     346             :                              upload_data,
     347             :                              upload_data_size,
     348             :                              &json);
     349           0 :   if (GNUNET_SYSERR == res)
     350           0 :     return MHD_NO;
     351           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     352           0 :     return MHD_YES;
     353           0 :   res = TEH_PARSE_json_data (connection,
     354             :                              json,
     355             :                              spec);
     356           0 :   json_decref (json);
     357           0 :   if (GNUNET_YES != res)
     358           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     359           0 :   purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
     360           0 :   purpose.purpose = htonl (TALER_SIGNATURE_CLIENT_TEST_EDDSA);
     361           0 :   if (GNUNET_OK !=
     362           0 :       GNUNET_CRYPTO_eddsa_verify (TALER_SIGNATURE_CLIENT_TEST_EDDSA,
     363             :                                   &purpose,
     364             :                                   &sig,
     365             :                                   &pub))
     366             :   {
     367           0 :     GNUNET_JSON_parse_free (spec);
     368           0 :     return TEH_RESPONSE_reply_signature_invalid (connection,
     369             :                                                  TALER_EC_TEST_EDDSA_INVALID,
     370             :                                                  "eddsa_sig");
     371             :   }
     372           0 :   GNUNET_JSON_parse_free (spec);
     373           0 :   pk = GNUNET_CRYPTO_eddsa_key_create ();
     374           0 :   purpose.purpose = htonl (TALER_SIGNATURE_EXCHANGE_TEST_EDDSA);
     375           0 :   if (GNUNET_OK !=
     376           0 :       GNUNET_CRYPTO_eddsa_sign (pk,
     377             :                                 &purpose,
     378             :                                 &sig))
     379             :   {
     380           0 :     GNUNET_free (pk);
     381           0 :     return TEH_RESPONSE_reply_internal_error (connection,
     382             :                                               TALER_EC_TEST_EDDSA_ERROR,
     383             :                                               "Failed to EdDSA-sign");
     384             :   }
     385           0 :   GNUNET_CRYPTO_eddsa_key_get_public (pk,
     386             :                                       &pub);
     387           0 :   GNUNET_free (pk);
     388           0 :   return TEH_RESPONSE_reply_json_pack (connection,
     389             :                                        MHD_HTTP_OK,
     390             :                                        "{s:o, s:o}",
     391             :                                        "eddsa_pub",
     392             :                                        GNUNET_JSON_from_data_auto (&pub),
     393             :                                        "eddsa_sig",
     394             :                                        GNUNET_JSON_from_data_auto (&sig));
     395             : }
     396             : 
     397             : 
     398             : /**
     399             :  * Handle a "/test/rsa/get" request.  Returns the RSA public key
     400             :  * ("rsa_pub") which is used for signing in "/test/rsa/sign".
     401             :  *
     402             :  * @param rh context of the handler
     403             :  * @param connection the MHD connection to handle
     404             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     405             :  * @param upload_data upload data
     406             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     407             :  * @return MHD result code
     408             :   */
     409             : int
     410           0 : TEH_TEST_handler_test_rsa_get (struct TEH_RequestHandler *rh,
     411             :                                struct MHD_Connection *connection,
     412             :                                void **connection_cls,
     413             :                                const char *upload_data,
     414             :                                size_t *upload_data_size)
     415             : {
     416             :   int res;
     417             :   struct GNUNET_CRYPTO_RsaPublicKey *pub;
     418             : 
     419           0 :   if (NULL == rsa_pk)
     420           0 :     rsa_pk = GNUNET_CRYPTO_rsa_private_key_create (1024);
     421           0 :   if (NULL == rsa_pk)
     422             :   {
     423           0 :     GNUNET_break (0);
     424           0 :     return TEH_RESPONSE_reply_internal_error (connection,
     425             :                                               TALER_EC_TEST_RSA_GEN_ERROR,
     426             :                                               "Failed to create RSA key");
     427             :   }
     428           0 :   pub = GNUNET_CRYPTO_rsa_private_key_get_public (rsa_pk);
     429           0 :   if (NULL == pub)
     430             :   {
     431           0 :     GNUNET_break (0);
     432           0 :     return TEH_RESPONSE_reply_internal_error (connection,
     433             :                                               TALER_EC_TEST_RSA_PUB_ERROR,
     434             :                                               "Failed to get public RSA key");
     435             :   }
     436           0 :   res = TEH_RESPONSE_reply_json_pack (connection,
     437             :                                       MHD_HTTP_OK,
     438             :                                       "{s:o}",
     439             :                                       "rsa_pub",
     440             :                                       GNUNET_JSON_from_rsa_public_key (pub));
     441           0 :   GNUNET_CRYPTO_rsa_public_key_free (pub);
     442           0 :   return res;
     443             : }
     444             : 
     445             : 
     446             : /**
     447             :  * Handle a "/test/rsa/sign" request.  Parses the JSON in the post, which
     448             :  * must contain an "blind_ev" blinded value.  A a blinded signature
     449             :  * ("rsa_blind_sig") is returned.
     450             :  *
     451             :  * @param rh context of the handler
     452             :  * @param connection the MHD connection to handle
     453             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     454             :  * @param upload_data upload data
     455             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     456             :  * @return MHD result code
     457             :   */
     458             : int
     459           0 : TEH_TEST_handler_test_rsa_sign (struct TEH_RequestHandler *rh,
     460             :                                 struct MHD_Connection *connection,
     461             :                                 void **connection_cls,
     462             :                                 const char *upload_data,
     463             :                                 size_t *upload_data_size)
     464             : {
     465             :   json_t *json;
     466             :   int res;
     467             :   struct GNUNET_CRYPTO_RsaSignature *sig;
     468             :   void *in_ptr;
     469             :   size_t in_ptr_size;
     470           0 :   struct GNUNET_JSON_Specification spec[] = {
     471             :     GNUNET_JSON_spec_varsize ("blind_ev", &in_ptr, &in_ptr_size),
     472             :     GNUNET_JSON_spec_end ()
     473             :   };
     474             : 
     475           0 :   res = TEH_PARSE_post_json (connection,
     476             :                              connection_cls,
     477             :                              upload_data,
     478             :                              upload_data_size,
     479             :                              &json);
     480           0 :   if (GNUNET_SYSERR == res)
     481           0 :     return MHD_NO;
     482           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     483           0 :     return MHD_YES;
     484           0 :   res = TEH_PARSE_json_data (connection,
     485             :                              json,
     486             :                              spec);
     487           0 :   json_decref (json);
     488           0 :   if (GNUNET_YES != res)
     489           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     490           0 :   if (NULL == rsa_pk)
     491           0 :     rsa_pk = GNUNET_CRYPTO_rsa_private_key_create (1024);
     492           0 :   if (NULL == rsa_pk)
     493             :   {
     494           0 :     GNUNET_break (0);
     495           0 :     GNUNET_JSON_parse_free (spec);
     496           0 :     return TEH_RESPONSE_reply_internal_error (connection,
     497             :                                               TALER_EC_TEST_RSA_GEN_ERROR,
     498             :                                               "Failed to create RSA key");
     499             :   }
     500           0 :   sig = GNUNET_CRYPTO_rsa_sign_blinded (rsa_pk,
     501             :                                         in_ptr,
     502             :                                         in_ptr_size);
     503           0 :   if (NULL == sig)
     504             :   {
     505           0 :     GNUNET_break (0);
     506           0 :     GNUNET_JSON_parse_free (spec);
     507           0 :     return TEH_RESPONSE_reply_internal_error (connection,
     508             :                                               TALER_EC_TEST_RSA_SIGN_ERROR,
     509             :                                               "Failed to RSA-sign");
     510             :   }
     511           0 :   GNUNET_JSON_parse_free (spec);
     512           0 :   res = TEH_RESPONSE_reply_json_pack (connection,
     513             :                                       MHD_HTTP_OK,
     514             :                                       "{s:o}",
     515             :                                       "rsa_blind_sig",
     516             :                                       GNUNET_JSON_from_rsa_signature (sig));
     517           0 :   GNUNET_CRYPTO_rsa_signature_free (sig);
     518           0 :   return res;
     519             : }
     520             : 
     521             : 
     522             : /**
     523             :  * Handle a "/test/transfer" request.  Parses the JSON in the post,
     524             :  * which must contain a "secret_enc" with the encrypted link secret,
     525             :  * a "trans_priv" with the transfer private key, a "coin_pub" with
     526             :  * a coin public key.  A reply with the decrypted "secret" is
     527             :  * returned.
     528             :  *
     529             :  * @param rh context of the handler
     530             :  * @param connection the MHD connection to handle
     531             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     532             :  * @param upload_data upload data
     533             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     534             :  * @return MHD result code
     535             :   */
     536             : int
     537           0 : TEH_TEST_handler_test_transfer (struct TEH_RequestHandler *rh,
     538             :                                 struct MHD_Connection *connection,
     539             :                                 void **connection_cls,
     540             :                                 const char *upload_data,
     541             :                                 size_t *upload_data_size)
     542             : {
     543             :   json_t *json;
     544             :   int res;
     545             :   struct TALER_TransferPrivateKeyP trans_priv;
     546             :   struct TALER_CoinSpendPublicKeyP coin_pub;
     547           0 :   struct GNUNET_JSON_Specification spec[] = {
     548             :     GNUNET_JSON_spec_fixed_auto ("trans_priv", &trans_priv),
     549             :     GNUNET_JSON_spec_fixed_auto ("coin_pub", &coin_pub),
     550             :     GNUNET_JSON_spec_end ()
     551             :   };
     552             :   struct TALER_TransferSecretP secret;
     553             : 
     554           0 :   res = TEH_PARSE_post_json (connection,
     555             :                              connection_cls,
     556             :                              upload_data,
     557             :                              upload_data_size,
     558             :                              &json);
     559           0 :   if (GNUNET_SYSERR == res)
     560           0 :     return MHD_NO;
     561           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     562           0 :     return MHD_YES;
     563           0 :   res = TEH_PARSE_json_data (connection,
     564             :                              json,
     565             :                              spec);
     566           0 :   json_decref (json);
     567           0 :   if (GNUNET_YES != res)
     568           0 :     return (GNUNET_NO == res) ? MHD_YES : MHD_NO;
     569           0 :   TALER_link_reveal_transfer_secret (&trans_priv,
     570             :                                      &coin_pub,
     571             :                                      &secret);
     572           0 :   return TEH_RESPONSE_reply_json_pack (connection,
     573             :                                        MHD_HTTP_OK,
     574             :                                        "{s:o}",
     575             :                                        "secret",
     576             :                                        GNUNET_JSON_from_data_auto (&secret));
     577             : }
     578             : 
     579             : 
     580             : /**
     581             :  * Handle a "/test" request.  Parses the JSON in the post.
     582             :  *
     583             :  * @param rh context of the handler
     584             :  * @param connection the MHD connection to handle
     585             :  * @param[in,out] connection_cls the connection's closure (can be updated)
     586             :  * @param upload_data upload data
     587             :  * @param[in,out] upload_data_size number of bytes (left) in @a upload_data
     588             :  * @return MHD result code
     589             :   */
     590             : int
     591           0 : TEH_TEST_handler_test (struct TEH_RequestHandler *rh,
     592             :                        struct MHD_Connection *connection,
     593             :                        void **connection_cls,
     594             :                        const char *upload_data,
     595             :                        size_t *upload_data_size)
     596             : {
     597             :   json_t *json;
     598             :   int res;
     599             : 
     600           0 :   res = TEH_PARSE_post_json (connection,
     601             :                              connection_cls,
     602             :                              upload_data,
     603             :                              upload_data_size,
     604             :                              &json);
     605           0 :   if (GNUNET_SYSERR == res)
     606           0 :     return MHD_NO;
     607           0 :   if ( (GNUNET_NO == res) || (NULL == json) )
     608           0 :     return MHD_YES;
     609             : 
     610           0 :   json_decref (json);
     611           0 :   return MHD_NO;
     612             : }
     613             : 
     614             : 
     615             : /* end of taler-exchange-httpd_test.c */

Generated by: LCOV version 1.13