summaryrefslogtreecommitdiff
path: root/src/include/anastasis_json.h
blob: 9e8d9242cfad4e728bff0126eb554f8f0a8d4e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
/*
  This file is part of Anastasis
  Copyright (C) 2020 Taler Systems SA

  Anastasis is free software; you can redistribute it and/or modify it under the
  terms of the GNU Lesser General Public License as published by the Free Software
  Foundation; either version 3, or (at your option) any later version.

  Anastasis 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
  Anastasis; see the file COPYING.GPL.  If not, see <http://www.gnu.org/licenses/>
*/
/**
 * @file lib/anastasis_json.h
 * @brief anastasis de-/serialization api
 * @author Christian Grothoff
 * @author Dominik Meister
 * @author Dennis Neufeld
 */
#ifndef ANASTASIS_JSON_H
#define ANASTASIS_JSON_H

#include <jansson.h>
#include <gnunet/gnunet_util_lib.h>
#include "anastasis_error_codes.h"

/**
 * Enumeration of possible backup process status.
 */
enum ANASTASIS_BackupStatus
{
  ANASTASIS_BS_INITIAL,
  ANASTASIS_BS_SELECT_CONTINENT,
  ANASTASIS_BS_SELECT_COUNTRY,
  ANASTASIS_BS_ENTER_USER_ATTRIBUTES,
  ANASTASIS_BS_ADD_AUTHENTICATION_METHOD,
  ANASTASIS_BS_ADD_POLICY,
  ANASTASIS_BS_PAY
};

/**
 * Enumeration of possible recovery process status.
 */
enum ANASTASIS_RecoveryStatus
{
  ANASTASIS_RS_INITIAL,
  ANASTASIS_RS_SELECT_CONTINENT,
  ANASTASIS_RS_SELECT_COUNTRY,
  ANASTASIS_RS_ENTER_USER_ATTRIBUTES,
  ANASTASIS_RS_SOLVE_CHALLENGE
};

// A state for the backup process.
struct ANASTASIS_BackupState
{
  enum ANASTASIS_BackupStatus status;

  union
  {

    struct
    {
      // empty!
    } select_continent;

    struct
    {
      const char *continent;
    } select_country;

    struct
    {
      const char *continent;
      const char *country;
      const char *currency;       // derived or per manual override!
      json_t *user_attributes;
    } enter_attributes;

    struct
    {
      const char *continent;
      const char *country;
      const char *currency;
      json_t *user_attributes;

      struct AuthenticationDetails
      {
        enum AuthenticationMethod
        {
          SMS,
          VIDEO,
          SECQUEST,
          EMAIL,
          SNAILMAIL
        };
        char *provider_url;
        union Truth
        {

          struct
          {
            char *phone_number;
          } sms;

          struct
          {
            char *question;
            char *answer;             // FIXME: Reasonable to store answer in clear text here?
          } secquest;

          struct
          {
            char *mailaddress;
          } email;

          struct
          {
            char *full_name;
            char *street;             // street name + number
            char *postal_code;
            char *city;
            char *country;
          } snailmail;

          struct
          {
            char *path_to_picture;
          } video;
        } truth;
      }*ad;       // array
      size_t ad_length;
    } add_authentication;
    struct
    {
      const char *continent;
      const char *country;
      const char *currency;
      json_t *user_attributes;

      struct AuthenticationDetails
      {
        enum AuthenticationMethod
        {
          SMS,
          VIDEO,
          SECQUEST,
          EMAIL,
          SNAILMAIL
        };
        char *provider_url;
        union Truth
        {

          struct
          {
            char *phone_number;
          } sms;

          struct
          {
            char *question;
            char *answer;             // FIXME: Reasonable to store answer in clear text here?
          } secquest;

          struct
          {
            char *mailaddress;
          } email;

          struct
          {
            char *full_name;
            char *street;             // street name + number
            char *postal_code;
            char *city;
            char *country;
          } snailmail;

          struct
          {
            char *path_to_picture;
          } video;
        } truth;
      }*ad;       // array
      size_t ad_length;

      struct PolicyDetails
      {
        struct AuthenticationDetails *ad;         // array
      }*pd;       // array
      size_t pd_length;
    } add_policy;
    // FIXME: add_payment
  } details;
};


// A state for the recovery process.
struct ANASTASIS_RecoveryState
{
  enum ANASTASIS_RecoveryStatus status;

  struct
  {
    // empty!
  } select_continent;

  struct
  {
    const char *continent;
  } select_country;

  struct
  {
    const char *continent;
    const char *country;
    const char *currency;         // derived or per manual override!
    json_t *user_attributes;
  } enter_attributes;

  struct
  {
    const char *continent;
    const char *country;
    const char *currency;
    json_t *user_attributes;

    struct ChallengeDetails
    {
      enum AuthenticationMethod
      {
        SMS,
        VIDEO,
        SECQUEST,
        EMAIL,
        SNAILMAIL
      };
      char *provider_url;
      union Challenge
      {

        struct
        {
          char *phone_number;
          char *code;
        } sms;

        struct
        {
          char *question;
          char *answer;             // FIXME: Reasonable to store answer in clear text here?
        } secquest;

        struct
        {
          char *mailaddress;
          char *code;
        } email;

        struct
        {
          char *full_name;
          char *street;             // street name + number
          char *postal_code;
          char *city;
          char *country;
          char *code;
        } snailmail;

        struct
        {
          char *path_to_picture;
          char *code;
        } video;
      } truth;
    }*cd;         // array
    size_t cd_length;
  } solve_challenge;
};

/**
 * Definition of actions on ANASTASIS_BackupState.
 */
struct ANASTASIS_BackupAction
{
  enum action
  {
    ANASTASIS_BA_GET_SELECT_CONTINENT,
    ANASTASIS_BA_GET_SELECT_COUNTRY,
    ANASTASIS_BA_GET_ENTER_USER_ATTRIBUTES,
    ANASTASIS_BA_GET_ADD_AUTHENTICATION_METHOD,
    ANASTASIS_BA_GET_ADD_POLICY,
    ANASTASIS_BA_GET_PAY,
    ANASTASIS_BA_SET_SELECT_CONTINENT,
    ANASTASIS_BA_SET_SELECT_COUNTRY,
    ANASTASIS_BA_SET_ENTER_USER_ATTRIBUTES,
    ANASTASIS_BA_SET_ADD_AUTHENTICATION_METHOD,
    ANASTASIS_BA_SET_ADD_POLICY,
    ANASTASIS_BA_SET_PAY
  };
};

/**
 * Definition of actions on ANASTASIS_RecoveryState.
 */
struct ANASTASIS_RecoveryAction
{
  enum action
  {
    ANASTASIS_RS_GET_SELECT_CONTINENT,
    ANASTASIS_RS_GET_SELECT_COUNTRY,
    ANASTASIS_RS_GET_ENTER_USER_ATTRIBUTES,
    ANASTASIS_RS_GET_SOLVE_CHALLENGE,
    ANASTASIS_RS_SET_SELECT_CONTINENT,
    ANASTASIS_RS_SET_SELECT_COUNTRY,
    ANASTASIS_RS_SET_ENTER_USER_ATTRIBUTES,
    ANASTASIS_RS_SET_SOLVE_CHALLENGE
  };
};


/**
 * Signature of the callback bassed to #ANASTASIS_apply_anastasis_backup_action
 * for asynchronous actions on a #ANASTASIS_BackupState.
 *
 * @param cls closure
 * @param new_bs the new #ANASTASIS_BackupState
 * @param error error code
 */
typedef void
(*ANASTASIS_BackupApplyActionCallback)(
  void *cls,
  const struct ANASTASIS_BackupState *new_bs,
  enum TALER_ErrorCode error);


/**
 * Signature of the callback bassed to #ANASTASIS_apply_anastasis_recovery_action
 * for asynchronous actions on a #ANASTASIS_RecoveryState.
 *
 * @param cls closure
 * @param new_bs the new #ANASTASIS_RecoveryState
 * @param error error code
 */
typedef void
(*ANASTASIS_RecoveryApplyActionCallback)(
  void *cls,
  const struct ANASTASIS_RecoveryState *new_rs,
  enum TALER_ErrorCode error);


/**
 * Returns an initial ANASTASIS_BackupState.
 *
 * @return initial ANASTASIS_BackupState
 */
struct ANASTASIS_BackupState *
ANASTASIS_get_initial_backup_state ();


/**
 * Returns an initial ANASTASIS_RecoveryState.
 *
 * @return initial ANASTASIS_RecoveryState
 */
struct ANASTASIS_RecoveryState *
ANASTASIS_get_initial_recovery_state ();


/**
 * Operates on a backup state depending on given #ANASTASIS_BackupState
 * and #ANASTASIS_BackupAction. The new #ANASTASIS_BackupState is returned
 * by a callback function.
 * This function can do network access to talk to anastasis service providers.
 *
 * @param ctx url context for the event loop
 * @param bs the previous *ANASTASIS_BackupState
 * @param ba the action to do on #ANASTASIS_BackupState
 * @param cb callback function to call with the action
 */
void
ANASTASIS_apply_anastasis_backup_action (
  struct GNUNET_CURL_Context *ctx,
  struct ANASTASIS_BackupState *bs,
  struct ANASTASIS_BackupAction *ba,
  ANASTASIS_BackupApplyActionCallback cb);


/**
 * Operates on a recovery state depending on given #ANASTASIS_RecoveryState
 * and #ANASTASIS_RecoveryAction. The new #ANASTASIS_RecoveryState is returned
 * by a callback function.
 * This function can do network access to talk to anastasis service providers.
 *
 * @param ctx url context for the event loop
 * @param bs the previous *ANASTASIS_RecoveryState
 * @param ba the action to do on #ANASTASIS_RecoveryState
 * @param cb callback function to call with the action
 */
void
ANASTASIS_apply_anastasis_recovery_action (
  struct GNUNET_CURL_Context *ctx,
  struct ANASTASIS_RecoveryState *rs,
  struct ANASTASIS_RecoveryAction *ra,
  ANASTASIS_RecoveryApplyActionCallback cb);

#endif  /* _ANASTASIS_JSON_H */