gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-donau] 04/05: merge and add some json helpers


From: gnunet
Subject: [taler-donau] 04/05: merge and add some json helpers
Date: Sun, 07 Jan 2024 18:14:37 +0100

This is an automated email from the git hooks/post-receive script.

lukas-matyja pushed a commit to branch master
in repository donau.

commit 31c610a7d4cf814b425b4f8e2605c0378a9bc386
Merge: 76fa632 9839b09
Author: Matyja Lukas Adam <lukas.matyja@students.bfh.ch>
AuthorDate: Sun Jan 7 18:07:40 2024 +0100

    merge and add some json helpers

 contrib/gana                                       |    2 +-
 doc/.gitignore                                     |    1 +
 po/POTFILES.in                                     |    2 +-
 src/donau/Makefile.am                              |    7 +-
 src/donau/donau-httpd.c                            |   64 +-
 src/donau/donau-httpd_charity.h                    |   66 +
 src/donau/donau-httpd_db.c                         |   95 +-
 ...d_get-charity.c => donau-httpd_get-charities.c} |  105 +-
 src/donau/donau-httpd_get-charity.c                |   22 +-
 src/donau/donau-httpd_keys.c                       |  740 +++++++--
 src/donau/donau-httpd_keys.h                       |  121 +-
 src/donau/donau-httpd_metrics.c                    |  165 ++
 src/donau/donau-httpd_metrics.h                    |  136 ++
 src/donau/donau-httpd_post-charity.c               |  151 ++
 src/donaudb/0002-donation_units.sql                |    2 +-
 src/donaudb/0002-donau_charities.sql               |    3 +-
 src/donaudb/Makefile.am                            |   25 +-
 src/donaudb/pg_activate_signing_key.c              |    2 +-
 src/donaudb/pg_activate_signing_key.h              |    2 +-
 src/donaudb/pg_add_donation_unit_key.c             |    9 +-
 src/donaudb/pg_add_donation_unit_key.h             |    3 +-
 src/donaudb/pg_get_charities.c                     |  126 ++
 ...{pg_lookup_signing_key.h => pg_get_charities.h} |   26 +-
 src/donaudb/pg_get_donation_unit_info.c            |   67 -
 src/donaudb/pg_get_donation_unit_info.h            |   41 -
 src/donaudb/pg_helper.h                            |   65 +-
 src/donaudb/pg_insert_charity.c                    |   11 +-
 src/donaudb/pg_insert_charity.h                    |    4 +-
 src/donaudb/pg_insert_history_entry.c              |    3 +-
 src/donaudb/pg_insert_issued_receipt.c             |    6 +-
 src/donaudb/pg_insert_issued_receipt.h             |    3 +-
 src/donaudb/pg_insert_submitted_receipt.c          |    7 +-
 src/donaudb/pg_insert_submitted_receipt.h          |    7 +-
 src/donaudb/pg_lookup_charity.c                    |    9 +-
 src/donaudb/pg_lookup_charity.h                    |    4 +-
 ...nation_unit_key.c => pg_lookup_donation_unit.c} |    9 +-
 ...nation_unit_key.h => pg_lookup_donation_unit.h} |    0
 src/donaudb/pg_lookup_signing_key.c                |    2 +-
 src/donaudb/pg_lookup_signing_key.h                |    2 +-
 src/include/donau_crypto_lib.h                     |   14 +
 src/include/donau_json_lib.h                       |   43 +
 src/include/donau_service.h                        |   26 +-
 src/include/donaudb_plugin.h                       |  114 +-
 src/json/Makefile.am                               |    5 +-
 src/json/donau_json.c                              |  138 ++
 src/json/json.c                                    |  763 ++++++++-
 src/json/json_helper.c                             | 1621 ++++++++++++++++++++
 src/json/json_pack.c                               |  324 ++++
 src/lib/Makefile.am                                |    4 +-
 src/lib/donau_api_handle.c                         |    6 +-
 src/util/donau_signatures.c                        |    2 +-
 51 files changed, 4670 insertions(+), 505 deletions(-)

diff --cc src/include/donau_crypto_lib.h
index 66bfb45,468d218..7dafadc
--- a/src/include/donau_crypto_lib.h
+++ b/src/include/donau_crypto_lib.h
@@@ -117,36 -118,17 +118,49 @@@ struct DONAU_DonationUnitHash
    struct GNUNET_HashCode hash;
  };
  
 +/**
++<<<<<<< HEAD
 + * Compare two donation unit public keys.
 + *
 + * @param donation_unit1 first key
 + * @param donation_unit2 second key
 + * @return 0 if the keys are equal, otherwise -1 or 1
 + */
 +int
 +DONAU_donation_unit_pub_cmp (const struct DONAU_DonationUnitPublicKey 
*donation_unit1,
 +                     const struct DONAU_DonationUnitPublicKey 
*donation_unit2);
 +
 +/**
 + * Make a (deep) copy of the given @a donation_unit_src to
 + * @a donation_unit_dst.
 + *
 + * @param[out] donation_unit_dst target to copy to
 + * @param donation_unit_src public key to copy
 + */
 +void
 +DONAU_donation_unit_pub_deep_copy (struct DONAU_DonationUnitPublicKey 
*donation_unit_dst,
 +                             const struct DONAU_DonationUnitPublicKey 
*donation_unit_src);
 +
 +/**
 + * Free internals of @a donation_unit_pub, but not @a donation_unit_pub 
itself.
 + *
 + * @param[in] donation_unit_pub key to free
 + */
 +void
 +DONAU_donation_unit_pub_free (struct DONAU_DonationUnitPublicKey 
*donation_unit_pub);
 +
+ /**
+  * Hash used to represent a Donation Receipt
+  */
+ struct DONAU_DonationReceiptHashP
+ {
+   /**
+    * Actual hash value.
+    */
+   struct GNUNET_HashCode hash;
+ };
+ 
++
  /**
    * Donor's hashed and salted unique donation identifier.
    */
diff --cc src/include/donau_json_lib.h
index 0000000,0000000..9dcafe6
new file mode 100644
--- /dev/null
+++ b/src/include/donau_json_lib.h
@@@ -1,0 -1,0 +1,43 @@@
++/*
++  This file is part of TALER
++  Copyright (C) 2024 Taler Systems SA
++
++  TALER is free software; you can redistribute it and/or modify it under the
++  terms of the GNU General Public License as published by the Free Software
++  Foundation; either version 3, or (at your option) any later version.
++
++  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
++  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
++  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
++
++  You should have received a copy of the GNU General Public License along with
++  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
++*/
++/**
++ * @file include/donau_json_lib.h
++ * @brief helper functions for JSON processing using libjansson
++ * @author Lukas Matyja
++ */
++#ifndef TALER_JSON_LIB_H_
++#define TALER_JSON_LIB_H_
++
++#include <jansson.h>
++#include <gnunet/gnunet_json_lib.h>
++#include <gnunet/gnunet_curl_lib.h>
++#include "taler/taler_util.h"
++#include "taler/taler_error_codes.h"
++
++/**
++ * Generate a parser specification for a donation unit public key of a given
++ * cipher.
++ *
++ * @param field name of the field
++ * @param cipher which cipher type to parse for
++ * @param[out] pk key to fill
++ * @return corresponding field spec
++ */
++struct GNUNET_JSON_Specification
++DONAU_JSON_spec_donation_unit_pub_cipher (
++  const char *field,
++  enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
++  struct DONAU_DonationUnitPublicKey *pk);
diff --cc src/include/donau_service.h
index 82878ca,086dd1c..9853241
--- a/src/include/donau_service.h
+++ b/src/include/donau_service.h
@@@ -373,18 -368,18 +373,18 @@@ DONAU_keys_decref (struct DONAU_Keys *k
  
  /**
   * Test if the given @a pub is a current signing key from the donau
-- * according to @a keys.
++ * according to @a keys. (->  // always current, revocation not yet supported)
   *
   * @param keys the donau's key set
   * @param pub claimed online signing key for the donau
   * @param year given year
   * @return #GNUNET_OK if @a pub is (according to /keys and @a year) the 
corresponding signing key
   */
 -enum GNUNET_GenericReturnValue
 -DONAU_test_signing_key (
 -  const struct DONAU_Keys *keys,
 -  const unsigned int year,
 -  const struct DONAU_DonauPublicKeyP *pub);
 +// enum GNUNET_GenericReturnValue
- // DONAU_test_signing_key (               // always current revocation not 
yet supported
++// DONAU_test_signing_key (
 +//   const struct DONAU_Keys *keys,
 +//   const unsigned int year,
- //   const struct DONAU_EddsaPublicKeyP *pub);
++//   const struct DONAU_DonauPublicKeyP *pub);
  
  
  /**
diff --cc src/json/donau_json.c
index 0000000,0000000..e14f707
new file mode 100644
--- /dev/null
+++ b/src/json/donau_json.c
@@@ -1,0 -1,0 +1,138 @@@
++/*
++  This file is part of TALER
++  Copyright (C) 2024 Taler Systems SA
++
++  TALER is free software; you can redistribute it and/or modify it under the
++  terms of the GNU General Public License as published by the Free Software
++  Foundation; either version 3, or (at your option) any later version.
++
++  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
++  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
++  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
++
++  You should have received a copy of the GNU General Public License along with
++  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
++*/
++/**
++ * @file json/donau_json.c
++ * @brief helper functions for JSON processing using libjansson
++ * @author Lukas Matyja
++ */
++#include "taler/platform.h"
++#include <gnunet/gnunet_util_lib.h>
++#include "taler/taler_util.h"
++#include "taler/taler_json_lib.h"
++#include <unistr.h>
++#include "donau_json_lib.h"
++#include "donau_util.h"
++
++/**
++ * Parse given JSON object partially into a donation unit public key.
++ *
++ * Depending on the cipher in cls, it parses the corresponding public key 
type.
++ *
++ * @param cls closure, enum GNUNET_CRYPTO_BlindSignatureAlgorithm
++ * @param root the json object representing data
++ * @param[out] spec where to write the data
++ * @return #GNUNET_OK upon successful parsing; #GNUNET_SYSERR upon error
++ */
++static enum GNUNET_GenericReturnValue
++parse_donation_unit_pub_cipher (void *cls,
++                        json_t *root,
++                        struct GNUNET_JSON_Specification *spec)
++{
++  struct DONAU_DonationUnitPublicKey *donation_unit_pub = spec->ptr;
++  enum GNUNET_CRYPTO_BlindSignatureAlgorithm cipher =
++    (enum GNUNET_CRYPTO_BlindSignatureAlgorithm) (long) cls;
++  struct GNUNET_CRYPTO_BlindSignPublicKey *bsign_pub;
++  const char *emsg;
++  unsigned int eline;
++
++  bsign_pub = GNUNET_new (struct GNUNET_CRYPTO_BlindSignPublicKey);
++  bsign_pub->cipher = cipher;
++  bsign_pub->rc = 1;
++  switch (cipher)
++  {
++  case GNUNET_CRYPTO_BSA_INVALID:
++    break;
++  case GNUNET_CRYPTO_BSA_RSA:
++    {
++      struct GNUNET_JSON_Specification ispec[] = {
++        GNUNET_JSON_spec_rsa_public_key (
++          "rsa_pub",
++          &bsign_pub->details.rsa_public_key),
++        GNUNET_JSON_spec_end ()
++      };
++
++      if (GNUNET_OK !=
++          GNUNET_JSON_parse (root,
++                             ispec,
++                             &emsg,
++                             &eline))
++      {
++        GNUNET_break_op (0);
++        GNUNET_free (bsign_pub);
++        return GNUNET_SYSERR;
++      }
++      donation_unit_pub->bsign_pub_key = bsign_pub;
++      return GNUNET_OK;
++    }
++  case GNUNET_CRYPTO_BSA_CS:
++    {
++      struct GNUNET_JSON_Specification ispec[] = {
++        GNUNET_JSON_spec_fixed ("cs_pub",
++                                &bsign_pub->details.cs_public_key,
++                                sizeof (bsign_pub->details.cs_public_key)),
++        GNUNET_JSON_spec_end ()
++      };
++
++      if (GNUNET_OK !=
++          GNUNET_JSON_parse (root,
++                             ispec,
++                             &emsg,
++                             &eline))
++      {
++        GNUNET_break_op (0);
++        GNUNET_free (bsign_pub);
++        return GNUNET_SYSERR;
++      }
++      donation_unit_pub->bsign_pub_key = bsign_pub;
++      return GNUNET_OK;
++    }
++  }
++  GNUNET_break_op (0);
++  GNUNET_free (bsign_pub);
++  return GNUNET_SYSERR;
++}
++
++/**
++ * Cleanup data left from parsing donation unit public key.
++ *
++ * @param cls closure, NULL
++ * @param[out] spec where to free the data
++ */
++static void
++clean_donation_unit_pub (void *cls,
++                 struct GNUNET_JSON_Specification *spec)
++{
++  struct DONAU_DonationUnitPublicKey *donation_unit_pub = spec->ptr;
++
++  (void) cls;
++  DONAU_donation_unit_pub_free (donation_unit_pub);
++}
++
++struct GNUNET_JSON_Specification
++DONAU_JSON_spec_donation_unit_pub_cipher (const char *field,
++                                          enum 
GNUNET_CRYPTO_BlindSignatureAlgorithm cipher,
++                                          struct DONAU_DonationUnitPublicKey 
*pk)
++{
++  struct GNUNET_JSON_Specification ret = {
++    .parser = &parse_donation_unit_pub_cipher,
++    .cleaner = &clean_donation_unit_pub,
++    .field = field,
++    .cls = (void *) cipher,
++    .ptr = pk
++  };
++
++  return ret;
++}
diff --cc src/lib/donau_api_handle.c
index d8f2d99,ae563bd..cd6ef60
--- a/src/lib/donau_api_handle.c
+++ b/src/lib/donau_api_handle.c
@@@ -383,28 -499,24 +383,28 @@@ decode_keys_json (const json_t *resp_ob
          };
          bool found = false;
  
 -        EXITIF (GNUNET_SYSERR == //was partially
 -                parse_json_donation_unit_key (&dk,
 -                                               group.cipher,
 -                                               check_sig,
 -                                               denom_key_obj,
 -                                               &key_data->master_pub,
 -                                               check_sig ? &hash_xor : NULL));
 -
 -        /* Build the running xor of the SHA512-hash of the public keys for 
the group */
 -        GNUNET_CRYPTO_hash_xor (&dk.h_key.hash,
 -                                &group_hash_xor,
 -                                &group_hash_xor);
 +        struct GNUNET_JSON_Specification kspec[] = {
-           TALER_JSON_spec_denom_pub_cipher (NULL, // TODO write new JSON 
function
-                                             group.cipher,
-                                             &dk->key),
++          DONAU_JSON_spec_donation_unit_pub_cipher (NULL,
++                                                    group.cipher,
++                                                    &dk->key),
 +          GNUNET_JSON_spec_end ()
 +        };
 +
 +        if (GNUNET_OK !=
 +            GNUNET_JSON_parse (donation_unit_key_obj,
 +                              kspec,
 +                              NULL, NULL))
 +        {
 +          GNUNET_break_op (0);
 +          EXITIF(1);
 +        }
 +
          for (unsigned int j = 0;
 -             j<key_data->num_denom_keys;
 +             j<key_data->num_donation_unit_keys;
               j++)
          {
 -          if (0 == GNUNET_CRYPTO_bsign_pub_cmp (&dk,
 -                                                &key_data->denom_keys[j]))
 +          if (0 == donation_units_cmp (&dk.key,
 +                                                
&key_data->donation_unit_keys[j]))
            {
              found = true;
              break;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]