merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

merchant_api_common_mfa_challenge.c (3080B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2025-2026 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Lesser General Public License as published by the Free Software
      7   Foundation; either version 2.1, 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 Lesser General Public License for more details.
     12 
     13   You should have received a copy of the GNU Lesser General Public License along with
     14   TALER; see the file COPYING.LGPL.  If not, see
     15   <http://www.gnu.org/licenses/>
     16 */
     17 /**
     18  * @file merchant_api_common_mfa_challenge.c
     19  * @brief Shared parsing of HTTP 202 MFA challenge responses
     20  * @author Christian Grothoff
     21  */
     22 #include "taler/platform.h"
     23 #include "taler/taler_merchant_service.h"
     24 #include <gnunet/gnunet_json_lib.h>
     25 #include "merchant_api_common.h"
     26 
     27 
     28 enum GNUNET_GenericReturnValue
     29 TALER_MERCHANT_parse_mfa_challenge_response_ (
     30   const json_t *json,
     31   struct TALER_MERCHANT_MfaChallengeResponse *cr)
     32 {
     33   const json_t *challenges;
     34   struct GNUNET_JSON_Specification spec[] = {
     35     GNUNET_JSON_spec_bool ("combi_and",
     36                            &cr->combi_and),
     37     GNUNET_JSON_spec_array_const ("challenges",
     38                                   &challenges),
     39     GNUNET_JSON_spec_end ()
     40   };
     41 
     42   memset (cr,
     43           0,
     44           sizeof (*cr));
     45   if (GNUNET_OK !=
     46       GNUNET_JSON_parse (json,
     47                          spec,
     48                          NULL, NULL))
     49   {
     50     GNUNET_break_op (0);
     51     return GNUNET_SYSERR;
     52   }
     53   cr->challenges_length = (unsigned int) json_array_size (challenges);
     54   if (0 == cr->challenges_length)
     55   {
     56     GNUNET_break_op (0);
     57     return GNUNET_SYSERR;
     58   }
     59   cr->challenges = GNUNET_new_array (
     60     cr->challenges_length,
     61     struct TALER_MERCHANT_MfaChallengeEntry);
     62   for (unsigned int i = 0; i < cr->challenges_length; i++)
     63   {
     64     const json_t *jentry = json_array_get (challenges,
     65                                            i);
     66     struct TALER_MERCHANT_MfaChallengeEntry *entry = &cr->challenges[i];
     67     struct GNUNET_JSON_Specification espec[] = {
     68       GNUNET_JSON_spec_string ("tan_info",
     69                                &entry->tan_info),
     70       GNUNET_JSON_spec_string ("tan_channel",
     71                                &entry->tan_channel),
     72       GNUNET_JSON_spec_string ("challenge_id",
     73                                &entry->challenge_id),
     74       GNUNET_JSON_spec_end ()
     75     };
     76 
     77     if (GNUNET_OK !=
     78         GNUNET_JSON_parse (jentry,
     79                            espec,
     80                            NULL, NULL))
     81     {
     82       GNUNET_break_op (0);
     83       GNUNET_free (cr->challenges);
     84       cr->challenges_length = 0;
     85       return GNUNET_SYSERR;
     86     }
     87   }
     88   return GNUNET_OK;
     89 }
     90 
     91 
     92 void
     93 TALER_MERCHANT_mfa_challenge_response_free (
     94   struct TALER_MERCHANT_MfaChallengeResponse *cr)
     95 {
     96   GNUNET_free (cr->challenges);
     97   cr->challenges_length = 0;
     98 }
     99 
    100 
    101 /* end of merchant_api_common_mfa_challenge.c */