challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

authorize_start.c (4271B)


      1 /*
      2    This file is part of Challenger
      3    Copyright (C) 2023 Taler Systems SA
      4 
      5    Challenger is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    Challenger 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 General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    Challenger; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file src/challengerdb/authorize_start.c
     18  * @brief Implementation of the authorize_start function for Postgres
     19  * @author Christian Grothoff
     20  * @author Bohdan Potuzhnyi
     21  * @author Vlada Svirsh
     22  */
     23 #include "platform.h"
     24 #include <taler/taler_error_codes.h>
     25 #include <taler/taler_dbevents.h>
     26 #include <taler/taler_pq_lib.h>
     27 #include "authorize_start.h"
     28 #include "pg_helper.h"
     29 
     30 
     31 enum GNUNET_DB_QueryStatus
     32 CHALLENGERDB_authorize_start (struct CHALLENGERDB_PostgresContext *ctx,
     33                        const struct CHALLENGER_ValidationNonceP *nonce,
     34                        uint64_t client_id,
     35                        const char *client_scope,
     36                        const char *client_state,
     37                        const char *client_redirect_uri,
     38                        const char *code_challenge,
     39                        uint32_t code_challenge_method,
     40                        json_t **last_address,
     41                        uint32_t *address_attempts_left,
     42                        uint32_t *pin_transmissions_left,
     43                        uint32_t *auth_attempts_left,
     44                        bool *solved,
     45                        struct GNUNET_TIME_Absolute *last_tx_time)
     46 {
     47   struct GNUNET_PQ_QueryParam params[] = {
     48     GNUNET_PQ_query_param_auto_from_type (nonce),
     49     GNUNET_PQ_query_param_uint64 (&client_id),
     50     NULL != client_scope
     51     ? GNUNET_PQ_query_param_string (client_scope)
     52     : GNUNET_PQ_query_param_null (),
     53     GNUNET_PQ_query_param_string (client_state),
     54     NULL != client_redirect_uri
     55     ? GNUNET_PQ_query_param_string (client_redirect_uri)
     56     : GNUNET_PQ_query_param_null (),
     57     NULL != code_challenge
     58     ? GNUNET_PQ_query_param_string (code_challenge)
     59     : GNUNET_PQ_query_param_null (),
     60     GNUNET_PQ_query_param_uint32 (&code_challenge_method),
     61     GNUNET_PQ_query_param_end
     62   };
     63   struct GNUNET_PQ_ResultSpec rs[] = {
     64     GNUNET_PQ_result_spec_allow_null (
     65       TALER_PQ_result_spec_json ("address",
     66                                  last_address),
     67       NULL),
     68     GNUNET_PQ_result_spec_uint32 ("address_attempts_left",
     69                                   address_attempts_left),
     70     GNUNET_PQ_result_spec_uint32 ("pin_transmissions_left",
     71                                   pin_transmissions_left),
     72     GNUNET_PQ_result_spec_uint32 ("auth_attempts_left",
     73                                   auth_attempts_left),
     74     GNUNET_PQ_result_spec_bool ("solved",
     75                                 solved),
     76     GNUNET_PQ_result_spec_absolute_time ("last_tx_time",
     77                                          last_tx_time),
     78     GNUNET_PQ_result_spec_end
     79   };
     80 
     81   *last_address = NULL;
     82   PREPARE (ctx,
     83            "authorize_start_validation",
     84            "UPDATE validations SET"
     85            "  client_scope=$3"
     86            " ,client_state=$4"
     87            " ,client_redirect_uri=$5::VARCHAR"
     88            " ,code_challenge=$6"
     89            " ,code_challenge_method=$7"
     90            " WHERE nonce=$1"
     91            "   AND client_serial_id=$2"
     92            "   AND ($5::VARCHAR=COALESCE(client_redirect_uri,$5::VARCHAR))"
     93            " RETURNING"
     94            "   address"
     95            "  ,address_attempts_left"
     96            "  ,pin_transmissions_left"
     97            "  ,GREATEST(0, auth_attempts_left) AS auth_attempts_left"
     98            "  ,auth_attempts_left = -1 AS solved"
     99            "  ,last_tx_time;");
    100   return GNUNET_PQ_eval_prepared_singleton_select (ctx->conn,
    101                                                    "authorize_start_validation",
    102                                                    params,
    103                                                    rs);
    104 }