exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit d334c478aad4a7b2de0e2e919a50af3b7bcacbf7
parent 1c72ccf6bdfeddb1444cc97c80ed2603cb402327
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun,  4 May 2025 11:48:50 +0200

presumably fix #9848, needs testing

Diffstat:
Msrc/kyclogic/Makefile.am | 2+-
Dsrc/kyclogic/taler-exchange-helper-measure-enable-deposits | 128-------------------------------------------------------------------------------
Asrc/kyclogic/taler-exchange-helper-measure-validate-accepted-tos | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+), 129 deletions(-)

diff --git a/src/kyclogic/Makefile.am b/src/kyclogic/Makefile.am @@ -20,7 +20,6 @@ bin_SCRIPTS = \ taler-exchange-helper-measure-challenger-postal-context-check \ taler-exchange-helper-measure-challenger-sms-context-check \ taler-exchange-helper-measure-defaults-but-investigate \ - taler-exchange-helper-measure-enable-deposits \ taler-exchange-helper-measure-freeze \ taler-exchange-helper-measure-inform-investigate \ taler-exchange-helper-measure-none \ @@ -34,6 +33,7 @@ bin_SCRIPTS = \ taler-exchange-helper-measure-test-form \ taler-exchange-helper-measure-test-oauth \ taler-exchange-helper-measure-update-from-context \ + taler-exchange-helper-measure-validate-accepted-tos \ taler-exchange-kyc-kycaid-converter.sh \ taler-exchange-kyc-persona-converter.sh \ taler-exchange-kyc-oauth2-test-converter.sh \ diff --git a/src/kyclogic/taler-exchange-helper-measure-enable-deposits b/src/kyclogic/taler-exchange-helper-measure-enable-deposits @@ -1,128 +0,0 @@ -#!/bin/bash -# -# This file is part of TALER -# Copyright (C) 2024 Taler Systems SA -# -# TALER is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 3, or (at your option) any later version. -# -# TALER 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 -# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> -# - -# Hard error reporting on. -set -eu - - - -# Exit, with error message (hard failure) -function exit_fail() { - echo " FAIL: " "$@" >&2 - EXIT_STATUS=1 - exit "$EXIT_STATUS" -} - -CONF="$HOME/.config/taler-exchange.conf" -VERBOSE=0 - -while getopts 'ac:hirvV' OPTION; -do - case "$OPTION" in - a) - # Terms of service status is required. - echo "ACCEPTED_TERMS_OF_SERVICE" - exit 0 - ;; - c) - # shellcheck disable=SC2034 - CONF="$OPTARG" - ;; - h) - echo "This is a KYC measure program that lifts restrictions on deposits after the terms of service were accepted. Expiration rules are set based on the context." - echo 'Supported options:' - echo ' -a -- show required attributes' - # shellcheck disable=SC2016 - echo ' -c $CONF -- set configuration' - echo ' -h -- print this help' - echo ' -i -- show required inputs' - echo ' -r -- show required context' - echo ' -v -- show version' - echo ' -V -- be verbose' - exit 0 - ;; - i) - # Need context and current_rules. - echo "context" - echo "current_rules" - exit 0 - ;; - r) - # What to do next? - echo "validity_years" - echo "successor_measure" - exit 0 - ;; - v) - echo "$0 v0.0.1" - exit 0 - ;; - V) - VERBOSE=1 - ;; - ?) - exit_fail "Unrecognized command line option" - ;; - esac -done - -if [ 1 = "$VERBOSE" ] -then - echo "Running $0" 1>&2 -fi - -# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput -# for the full JSON with possible inputs. - -# First, extract inputs we need -INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes,"context":.context}') - -# Get ToS acceptance confirmation. -TOS_ACCEPTED=$(echo "$INPUTS" | jq '.attributes.ACCEPTED_TERMS_OF_SERVICE // null') -# Get current rules. -CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null') -# Get context values. -VALIDITY_YEARS=$(echo "$INPUTS" | jq -r '.context.validity_years') -# Convert to seconds after epoch -EXPIRATION_STAMP=$((VALIDITY_YEARS * 365 * 24 * 60 * 60 + $(date +%s))) -# Convert to GNUnet-style JSON timestamp -EXPIRATION_TIME=$(jq -n --argjson es "$EXPIRATION_STAMP" '{"t_s":$es}') - -SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.context.successor_measure // .current_rules.successor_measure // null') - -# Validate accepted ToS version -if eval echo "$TOS_ACCEPTED" | grep "${EXCHANGE_AML_PROGRAM_TOPS_ENABLE_DEPOSITS_TOS_NAME}" > /dev/null -then - # Valid ToS acceptance - # Remove limitation from current rules. - NEW_RULES=$(echo "$CURRENT_RULES" | jq 'walk(if ( (type == "object") and (.operation_type == "deposit") and (.threshold == "${EXCHANGE_AML_PROGRAM_TOPS_ENABLE_DEPOSITS_THRESHOLD }}") ) then del(.) else . end)') -else - # Invalid ToS version - echo "Version of accepted ToS ${TOS_ACCEPTED} invalid." 1>&2 - NEW_RULES="$CURRENT_RULES" -fi - -# Finally, output the new rules. -# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome -# for the required output format. -jq -n \ - --argjson et "$EXPIRATION_TIME" \ - --argjson sm "$SUCCESSOR_MEASURE" \ - --argjson nr "$NEW_RULES" \ - '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":{}})}|del(..|nulls)' - -exit 0 diff --git a/src/kyclogic/taler-exchange-helper-measure-validate-accepted-tos b/src/kyclogic/taler-exchange-helper-measure-validate-accepted-tos @@ -0,0 +1,128 @@ +#!/bin/bash +# +# This file is part of TALER +# Copyright (C) 2024, 2025 Taler Systems SA +# +# TALER is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 3, or (at your option) any later version. +# +# TALER 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 +# TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> +# + +# Hard error reporting on. +set -eu + + + +# Exit, with error message (hard failure) +function exit_fail() { + echo " FAIL: " "$@" >&2 + EXIT_STATUS=1 + exit "$EXIT_STATUS" +} + +CONF="$HOME/.config/taler-exchange.conf" +VERBOSE=0 + +while getopts 'ac:hirvV' OPTION; +do + case "$OPTION" in + a) + # Terms of service status is required. + echo "ACCEPTED_TERMS_OF_SERVICE" + exit 0 + ;; + c) + # shellcheck disable=SC2034 + CONF="$OPTARG" + ;; + h) + echo "This is a KYC measure program that lifts restrictions after the terms of service were accepted. Expiration rules are set based on the context." + echo 'Supported options:' + echo ' -a -- show required attributes' + # shellcheck disable=SC2016 + echo ' -c $CONF -- set configuration' + echo ' -h -- print this help' + echo ' -i -- show required inputs' + echo ' -r -- show required context' + echo ' -v -- show version' + echo ' -V -- be verbose' + exit 0 + ;; + i) + # Need context and current_rules. + echo "context" + echo "current_rules" + exit 0 + ;; + r) + # What to do next? + echo "validity_years" + echo "successor_measure" + exit 0 + ;; + v) + echo "$0 v0.0.0" + exit 0 + ;; + V) + VERBOSE=1 + ;; + ?) + exit_fail "Unrecognized command line option" + ;; + esac +done + +if [ 1 = "$VERBOSE" ] +then + echo "Running $0" 1>&2 +fi + +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlProgramInput +# for the full JSON with possible inputs. + +# First, extract inputs we need +INPUTS=$(jq '{"current_rules":.current_rules,"attributes":.attributes,"context":.context}') + +# Get ToS acceptance confirmation. +TOS_ACCEPTED=$(echo "$INPUTS" | jq '.attributes.ACCEPTED_TERMS_OF_SERVICE // null') +# Get current rules. +CURRENT_RULES=$(echo "$INPUTS" | jq '.current_rules // null') +# Get context values. +VALIDITY_YEARS=$(echo "$INPUTS" | jq -r '.context.validity_years') +# Convert to seconds after epoch +EXPIRATION_STAMP=$((VALIDITY_YEARS * 365 * 24 * 60 * 60 + $(date +%s))) +# Convert to GNUnet-style JSON timestamp +EXPIRATION_TIME=$(jq -n --argjson es "$EXPIRATION_STAMP" '{"t_s":$es}') + +SUCCESSOR_MEASURE=$(echo "$INPUTS" | jq '.context.successor_measure // .current_rules.successor_measure // null') + +# Validate accepted ToS version +if eval echo "$TOS_ACCEPTED" | grep "${EXCHANGE_AML_PROGRAM_TOPS_ENABLE_DEPOSITS_TOS_NAME}" > /dev/null +then + # Valid ToS acceptance + # Remove limitation from current rules. + NEW_RULES=$(echo "$CURRENT_RULES" | jq '(.rules[] |= if (.measures[0]=="accept-tos") then del(.) else . end)') +else + # Invalid ToS version + echo "Version of accepted ToS ${TOS_ACCEPTED} invalid." 1>&2 + NEW_RULES="$CURRENT_RULES" +fi + +# Finally, output the new rules. +# See https://docs.taler.net/taler-kyc-manual.html#tsref-type-AmlOutcome +# for the required output format. +jq -n \ + --argjson et "$EXPIRATION_TIME" \ + --argjson sm "$SUCCESSOR_MEASURE" \ + --argjson nr "$NEW_RULES" \ + '{"new_rules":($nr+{"expiration_time":$et,"successor_measure":$sm,"custom_measures":{}})}|del(..|nulls)' + +exit 0