commit 6c0f65e7e2cd57c810fee186c002bdcdf285ebb9
parent 2dee4146e911b3e8b51e06384a695bbd94f3c45d
Author: Florian Dold <dold@taler.net>
Date: Sun, 9 Aug 2026 19:35:00 +0200
Handle Challenger JSON addresses in mock MFA helpers
Diffstat:
4 files changed, 40 insertions(+), 14 deletions(-)
diff --git a/roles/challenger/files/usr/local/bin/mock-mfa-email b/roles/challenger/files/usr/local/bin/mock-mfa-email
@@ -1,27 +1,40 @@
#!/bin/sh
# Development-only email challenger delivery helper. Challenger provides the
-# email address as $1 and the MFA message on standard input.
+# address as a JSON object in $1 and the MFA message on standard input.
set -eu
if [ "$#" -ne 1 ]; then
- echo "usage: mock-mfa-email EMAIL_ADDRESS" >&2
+ echo "usage: mock-mfa-email ADDRESS_JSON" >&2
exit 64
fi
+# Challenger passes the complete address object to AUTH_COMMAND, for example
+# {"CONTACT_EMAIL":"test-01@taler.net"}, rather than just the field value.
+# Invalid input is left to the real helper so this wrapper does not change its
+# normal error handling.
+if ! email_address=$(
+ printf '%s\n' "$1" |
+ jq -er \
+ 'if type == "object" and ((.CONTACT_EMAIL | type) == "string") then .CONTACT_EMAIL else empty end' \
+ 2>/dev/null
+); then
+ exec challenger-send-email "$@"
+fi
+
# Keep real deliveries real. Only the reserved staging email addresses
# documented for MyTOPS development testing are captured locally.
-case "$1" in
+case "$email_address" in
test-[0-9][0-9]@taler.net)
;;
*)
- exec /usr/bin/challenger-send-email "$@"
+ exec challenger-send-email "$@"
;;
esac
message_dir=/var/www/mock-mfa
# Keep email-address filenames readable while preventing a supplied address
# from escaping the message directory.
-filename=$(LC_ALL=C printf '%s' "$1" | tr -c '[:alnum:]@+._-' '_')
+filename=$(LC_ALL=C printf '%s' "$email_address" | tr -c '[:alnum:]@+._-' '_')
# Files must be readable by nginx through the challenger-mock-mfa group. Write
# atomically so the web server never exposes a partially-written MFA message.
diff --git a/roles/challenger/files/usr/local/bin/mock-mfa-sms b/roles/challenger/files/usr/local/bin/mock-mfa-sms
@@ -1,27 +1,40 @@
#!/bin/sh
# Development-only SMS challenger delivery helper. Challenger provides the
-# phone number as $1 and the MFA message on standard input.
+# address as a JSON object in $1 and the MFA message on standard input.
set -eu
if [ "$#" -ne 1 ]; then
- echo "usage: mock-mfa-sms PHONE_NUMBER" >&2
+ echo "usage: mock-mfa-sms ADDRESS_JSON" >&2
exit 64
fi
+# Challenger passes the complete address object to AUTH_COMMAND, for example
+# {"CONTACT_PHONE":"+41700000006"}, rather than just the field value.
+# Invalid input is left to the real helper so this wrapper does not change its
+# normal error handling.
+if ! phone_number=$(
+ printf '%s\n' "$1" |
+ jq -er \
+ 'if type == "object" and ((.CONTACT_PHONE | type) == "string") then .CONTACT_PHONE else empty end' \
+ 2>/dev/null
+); then
+ exec challenger-send-sms "$@"
+fi
+
# Keep real deliveries real. Only the reserved staging phone numbers
# documented for MyTOPS development testing are captured locally.
-case "$1" in
+case "$phone_number" in
+417000000[0-9][0-9])
;;
*)
- exec /usr/bin/challenger-send-sms "$@"
+ exec challenger-send-sms "$@"
;;
esac
message_dir=/var/www/mock-mfa
# Keep phone-number filenames readable while preventing a supplied number from
# escaping the message directory.
-filename=$(LC_ALL=C printf '%s' "$1" | tr -c '[:alnum:]@+._-' '_')
+filename=$(LC_ALL=C printf '%s' "$phone_number" | tr -c '[:alnum:]@+._-' '_')
# Files must be readable by nginx through the challenger-mock-mfa group. Write
# atomically so the web server never exposes a partially-written MFA message.
diff --git a/roles/challenger/templates/etc/challenger/challenger-email.conf.j2 b/roles/challenger/templates/etc/challenger/challenger-email.conf.j2
@@ -13,9 +13,9 @@ UNIXPATH_MODE = 666
# Which external command should be used to transmit challenges?
# Example commands are challenger-send-{sms,email,post}
{% if devtesting_mock_mfa | bool %}
-AUTH_COMMAND = /usr/local/bin/mock-mfa-email
+AUTH_COMMAND = mock-mfa-email
{% else %}
-AUTH_COMMAND = /usr/bin/challenger-send-email
+AUTH_COMMAND = challenger-send-email
{% endif %}
# How long is an individual validation request valid?
diff --git a/roles/challenger/templates/etc/challenger/challenger-sms.conf.j2 b/roles/challenger/templates/etc/challenger/challenger-sms.conf.j2
@@ -13,9 +13,9 @@ UNIXPATH_MODE = 666
# Which external command should be used to transmit challenges?
# Example commands are challenger-send-{sms,email,post}
{% if devtesting_mock_mfa | bool %}
-AUTH_COMMAND = /usr/local/bin/mock-mfa-sms
+AUTH_COMMAND = mock-mfa-sms
{% else %}
-AUTH_COMMAND = /usr/bin/challenger-send-sms
+AUTH_COMMAND = challenger-send-sms
{% endif %}
# Name of a file with the message to send with the challenge.