donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

donau-httpd_post-csr-issue.c (3546B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2024 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify
      6   it under the terms of the GNU Affero General Public License as
      7   published by the Free Software Foundation; either version 3,
      8   or (at your option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty
     12   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     13   See the GNU Affero General Public License for more details.
     14 
     15   You should have received a copy of the GNU Affero General
     16   Public License along with TALER; see the file COPYING.  If not,
     17   see <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file donau-httpd_post-csr-issue.c
     21  * @brief Handle /csr requests
     22  * @author Johannes Casaburi
     23  */
     24 #include <donau_config.h>
     25 #include <gnunet/gnunet_util_lib.h>
     26 #include <jansson.h>
     27 #include <microhttpd.h>
     28 #include <taler/taler_json_lib.h>
     29 #include <taler/taler_mhd_lib.h>
     30 #include <taler/taler_signatures.h>
     31 #include "donau-httpd_get-keys.h"
     32 #include "donau-httpd_post-csr-issue.h"
     33 
     34 
     35 /**
     36  * Maximum number of csr records we return per request.
     37  */
     38 #define MAX_RECORDS 1024
     39 
     40 
     41 enum MHD_Result
     42 DH_handler_post_csr_issue (struct DH_RequestContext *rc,
     43                            const json_t *root,
     44                            const char *const args[])
     45 {
     46   struct GNUNET_CRYPTO_CsSessionNonce nonce;
     47   struct DONAU_DonationUnitHashP du_pub_hash;
     48   struct GNUNET_CRYPTO_BlindingInputValues ewv = {
     49     .cipher = GNUNET_CRYPTO_BSA_CS
     50   };
     51   struct GNUNET_JSON_Specification spec[] = {
     52     GNUNET_JSON_spec_fixed_auto ("nonce",
     53                                  &nonce),
     54     GNUNET_JSON_spec_fixed_auto ("du_pub_hash",
     55                                  &du_pub_hash),
     56     GNUNET_JSON_spec_end ()
     57   };
     58   struct DH_DonationUnitKey *dk;
     59 
     60   (void) args;
     61   {
     62     enum GNUNET_GenericReturnValue res;
     63 
     64     res = TALER_MHD_parse_json_data (rc->connection,
     65                                      root,
     66                                      spec);
     67     if (GNUNET_OK != res)
     68       return (GNUNET_SYSERR == res) ? MHD_NO : MHD_YES;
     69   }
     70 
     71   {
     72     dk = DH_keys_donation_unit_by_hash (&du_pub_hash);
     73     if (NULL == dk)
     74     {
     75       GNUNET_break (0);
     76       return TALER_MHD_reply_with_error (
     77         rc->connection,
     78         MHD_HTTP_NOT_FOUND,
     79         TALER_EC_DONAU_GENERIC_DONATION_UNIT_UNKNOWN,
     80         NULL);
     81     }
     82     if (GNUNET_CRYPTO_BSA_CS !=
     83         dk->donation_unit_pub.bsign_pub_key->cipher)
     84     {
     85       /* donation_unit is valid but not for CS */
     86       GNUNET_break (0);
     87       return TALER_MHD_reply_with_error (
     88         rc->connection,
     89         MHD_HTTP_BAD_REQUEST,
     90         TALER_EC_DONAU_GENERIC_INVALID_DENOMINATION_CIPHER_FOR_OPERATION,
     91         NULL);
     92     }
     93   }
     94 
     95   /* derive r_pub */
     96   {
     97     enum TALER_ErrorCode ec;
     98 
     99     ec = DH_keys_donation_unit_cs_r_pub (&du_pub_hash,
    100                                          &nonce,
    101                                          &ewv.details.cs_values);
    102     if (TALER_EC_NONE != ec)
    103     {
    104       GNUNET_break (0);
    105       return TALER_MHD_reply_with_ec (rc->connection,
    106                                       ec,
    107                                       NULL);
    108     }
    109   }
    110   {
    111     struct TALER_ExchangeBlindingValues exw = {
    112       .blinding_inputs = &ewv
    113     };
    114 
    115     return TALER_MHD_REPLY_JSON_PACK (
    116       rc->connection,
    117       MHD_HTTP_CREATED,
    118       TALER_JSON_pack_exchange_blinding_values ("r_pubs",
    119                                                 &exw));
    120   }
    121 }
    122 
    123 
    124 /* end of donau-httpd_post-csr-issue.c */