From 563b30bbfb6869679f74bdd731367210d19e3c47 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 11 Aug 2015 16:53:04 +0200 Subject: [PATCH] finishing taler-mint-sepa --- src/mint-tools/Makefile.am | 2 +- src/mint-tools/taler-mint-sepa.c | 53 +++++++++++++++++++++++++++++++- src/mint/taler-mint-httpd_wire.c | 13 ++++++-- 3 files changed, 63 insertions(+), 5 deletions(-) diff --git a/src/mint-tools/Makefile.am b/src/mint-tools/Makefile.am index b76d9b68c..a1b1302de 100644 --- a/src/mint-tools/Makefile.am +++ b/src/mint-tools/Makefile.am @@ -30,7 +30,7 @@ taler_mint_sepa_SOURCES = \ taler_mint_sepa_LDADD = \ $(LIBGCRYPT_LIBS) \ $(top_builddir)/src/util/libtalerutil.la \ - -lgnunetutil $(XLIB) + -lgnunetutil -ljansson $(XLIB) taler_mint_sepa_LDFLAGS = $(POSTGRESQL_LDFLAGS) taler_mint_keycheck_SOURCES = \ diff --git a/src/mint-tools/taler-mint-sepa.c b/src/mint-tools/taler-mint-sepa.c index 9c7060b58..ffd2200f7 100644 --- a/src/mint-tools/taler-mint-sepa.c +++ b/src/mint-tools/taler-mint-sepa.c @@ -19,7 +19,10 @@ * @author Christian Grothoff */ #include +#include #include "taler_crypto_lib.h" +#include "taler_signatures.h" + /** * Filename of the master private key. @@ -79,6 +82,11 @@ main (int argc, GNUNET_GETOPT_OPTION_END }; struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv; + struct TALER_MasterWireSepaDetailsPS wsd; + struct TALER_MasterSignatureP sig; + struct GNUNET_HashContext *hc; + json_t *reply; + char *json_str; GNUNET_assert (GNUNET_OK == GNUNET_log_setup ("taler-mint-sepa", @@ -103,8 +111,51 @@ main (int argc, masterkeyfile); return 1; } - /* FIXME: do real work! */ + + /* Compute message to sign */ + hc = GNUNET_CRYPTO_hash_context_start (); + GNUNET_CRYPTO_hash_context_read (hc, + sepa_name, + strlen (sepa_name) + 1); + GNUNET_CRYPTO_hash_context_read (hc, + iban, + strlen (iban) + 1); + GNUNET_CRYPTO_hash_context_read (hc, + bic, + strlen (bic) + 1); + wsd.purpose.size = htonl (sizeof (wsd)); + wsd.purpose.purpose = htonl (TALER_SIGNATURE_MASTER_SEPA_DETAILS); + GNUNET_CRYPTO_hash_context_finish (hc, + &wsd.h_sepa_details); + GNUNET_CRYPTO_eddsa_sign (eddsa_priv, + &wsd.purpose, + &sig.eddsa_signature); GNUNET_free (eddsa_priv); + + /* build JSON message */ + reply = json_pack ("{s:s, s:s, s:s, s:o}", + "receiver_name", sepa_name, + "iban", iban, + "bic", bic, + "sig", TALER_json_from_data (&sig, + sizeof (sig))); + GNUNET_assert (NULL != reply); + + /* dump result to stdout */ + json_str = json_dumps (reply, JSON_INDENT(2)); + GNUNET_assert (NULL != json_str); + + if (NULL != output_filename) + { + fclose (stdout); + stdout = fopen (output_filename, + "w+"); + } + fprintf (stdout, + "%s", + json_str); + fflush (stdout); + free (json_str); return 0; } diff --git a/src/mint/taler-mint-httpd_wire.c b/src/mint/taler-mint-httpd_wire.c index cf177f8bc..ee3b4ff0b 100644 --- a/src/mint/taler-mint-httpd_wire.c +++ b/src/mint/taler-mint-httpd_wire.c @@ -22,7 +22,7 @@ #include "taler-mint-httpd_keystate.h" #include "taler-mint-httpd_responses.h" #include "taler-mint-httpd_wire.h" - +#include /** * Handle a "/wire" request. @@ -44,6 +44,7 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh, struct TALER_MintWireSupportMethodsPS wsm; struct TALER_MintPublicKeyP pub; struct TALER_MintSignatureP sig; + json_t *methods; wsm.purpose.size = htonl (sizeof (wsm)); wsm.purpose.purpose = htonl (TALER_SIGNATURE_MINT_WIRE_TYPES); @@ -53,11 +54,17 @@ TMH_WIRE_handler_wire (struct TMH_RequestHandler *rh, TMH_KS_sign (&wsm.purpose, &pub, &sig); - /* FIXME: check against spec! */ + methods = json_array (); + /* NOTE: for now, we only support *ONE* wire format per + mint instance; if we supply multiple, we need to + add the strings for each type separately here -- and + hash the 0-terminated strings above differently as well... */ + json_array_append_new (methods, + json_string (TMH_expected_wire_format)); return TMH_RESPONSE_reply_json_pack (connection, MHD_HTTP_OK, "{s:s, s:o, s:o}", - "wire", TMH_expected_wire_format, + "methods", methods, "sig", TALER_json_from_data (&sig, sizeof (sig)), "pub", TALER_json_from_data (&pub,