frosix

Multiparty signature service (experimental)
Log | Files | Refs | README | LICENSE

frosix-httpd_seed.c (1980B)


      1 /*
      2   This file is part of Frosix
      3   Copyright (C) 2022, 2023 Joel Urech
      4 
      5   Frosix is free software; you can redistribute it and/or modify it under the
      6   terms of the GNU Affero General Public License as published by the Free Software
      7   Foundation; either version 3, or (at your option) any later version.
      8 
      9   Frosix 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 Affero General Public License for more details.
     12 
     13   You should have received a copy of the GNU Affero General Public License along with
     14   Frosix; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15 */
     16 /**
     17  * @file backend/frosix-httpd_get.c
     18  * @brief functions to handle incoming requests on /seed
     19  * @author Joel Urech
     20  */
     21 #include "frosix-httpd_seed.h"
     22 #include "frosix-httpd.h"
     23 #include <sodium.h>
     24 
     25 struct FROSIX_RndBytes
     26 {
     27   uint8_t bytes[FROSIX_SEED_SIZE];
     28 };
     29 
     30 /**
     31  * @brief Wraps libsodium to get rnd bytes.
     32  * The amount of bytes is defined in the global FROSIX_SEED_SIZE
     33  *
     34  * @param[out] rnd_bytes Pointer to the struct to fill with rnd bytes.
     35 */
     36 static void
     37 get_rnd_bytes (struct FROSIX_RndBytes *rnd_bytes)
     38 {
     39   randombytes_buf (rnd_bytes->bytes, FROSIX_SEED_SIZE);
     40 }
     41 
     42 
     43 MHD_RESULT
     44 FH_seed_get (struct FH_RequestHandler *rh,
     45              struct MHD_Connection *connection)
     46 {
     47   struct MHD_Response *resp;
     48   MHD_RESULT ret;
     49   struct FROSIX_RndBytes *rnd_bytes;
     50 
     51   rnd_bytes = calloc (1, FROSIX_SEED_SIZE);
     52   if (NULL == rnd_bytes)
     53     return MHD_NO;
     54 
     55   get_rnd_bytes (rnd_bytes);
     56 
     57   resp = MHD_create_response_from_buffer (FROSIX_SEED_SIZE,
     58                                           rnd_bytes,
     59                                           MHD_RESPMEM_MUST_FREE);
     60 
     61   TALER_MHD_add_global_headers (resp);
     62   ret = MHD_queue_response (connection,
     63                             MHD_HTTP_OK,
     64                             resp);
     65   MHD_destroy_response (resp);
     66   return ret;
     67 }