Line data Source code
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 0 : 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 0 : GNUNET_JSON_spec_bool ("combi_and",
36 : &cr->combi_and),
37 0 : GNUNET_JSON_spec_array_const ("challenges",
38 : &challenges),
39 0 : GNUNET_JSON_spec_end ()
40 : };
41 :
42 0 : memset (cr,
43 : 0,
44 : sizeof (*cr));
45 0 : if (GNUNET_OK !=
46 0 : GNUNET_JSON_parse (json,
47 : spec,
48 : NULL, NULL))
49 : {
50 0 : GNUNET_break_op (0);
51 0 : return GNUNET_SYSERR;
52 : }
53 0 : cr->challenges_length = (unsigned int) json_array_size (challenges);
54 0 : if (0 == cr->challenges_length)
55 : {
56 0 : GNUNET_break_op (0);
57 0 : return GNUNET_SYSERR;
58 : }
59 0 : cr->challenges = GNUNET_new_array (
60 : cr->challenges_length,
61 : struct TALER_MERCHANT_MfaChallengeEntry);
62 0 : for (unsigned int i = 0; i < cr->challenges_length; i++)
63 : {
64 0 : const json_t *jentry = json_array_get (challenges,
65 : i);
66 0 : struct TALER_MERCHANT_MfaChallengeEntry *entry = &cr->challenges[i];
67 : struct GNUNET_JSON_Specification espec[] = {
68 0 : GNUNET_JSON_spec_string ("tan_info",
69 : &entry->tan_info),
70 0 : GNUNET_JSON_spec_string ("tan_channel",
71 : &entry->tan_channel),
72 0 : GNUNET_JSON_spec_string ("challenge_id",
73 : &entry->challenge_id),
74 0 : GNUNET_JSON_spec_end ()
75 : };
76 :
77 0 : if (GNUNET_OK !=
78 0 : GNUNET_JSON_parse (jentry,
79 : espec,
80 : NULL, NULL))
81 : {
82 0 : GNUNET_break_op (0);
83 0 : GNUNET_free (cr->challenges);
84 0 : cr->challenges_length = 0;
85 0 : return GNUNET_SYSERR;
86 : }
87 : }
88 0 : return GNUNET_OK;
89 : }
90 :
91 :
92 : void
93 0 : TALER_MERCHANT_mfa_challenge_response_free (
94 : struct TALER_MERCHANT_MfaChallengeResponse *cr)
95 : {
96 0 : GNUNET_free (cr->challenges);
97 0 : cr->challenges_length = 0;
98 0 : }
99 :
100 :
101 : /* end of merchant_api_common_mfa_challenge.c */
|