anastasis

Credential backup and recovery protocol and service
Log | Files | Refs | Submodules | README | LICENSE

commit d2180b4bbf2c7cfba67ef9ed5bf848e9d4e55c00
parent aba0baaf11a0598aa57ef03f40eb042a63c17bce
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Sat, 24 Dec 2022 20:06:54 +0100

start work on pingen v2 migration

Diffstat:
Asrc/authorization/anastasis-authorization-post.sh | 129+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/authorization/anastasis-authorization-sms.sh | 27+++++++++++++++++++++++++++
2 files changed, 156 insertions(+), 0 deletions(-)

diff --git a/src/authorization/anastasis-authorization-post.sh b/src/authorization/anastasis-authorization-post.sh @@ -0,0 +1,129 @@ +#!/bin/bash +set -eu + +# Theses are Anastasis SARL specific, do not share! +# CLIENT_ID= +# CLIENT_SECRET= +# ORG_ID= +. pingen-secrets + +ENDPOINT=https://api.v2.pingen.com/ + +MESSAGE=`cat -` +DATE=`date +%F` + +ACCESS_TOKEN=`curl -X POST -H "Content-Type: application/x-www-form-urlencoded" \ + --data-urlencode "grant_type=client_credentials" \ + --data-urlencode "client_id=$CLIENT_ID" \ + --data-urlencode "client_secret=$CLIENT_SECRET" \ + --data-urlencode "scope=letter" \ + https://identity.pingen.com/auth/access-tokens | jq .access_token` + +# FIXME: create PDF with: +#title: "Anastasis", +# place: "Luxembourg", +# date: $DATE, +# content: $MESSAGE, + +ATTRS=`curl \ + -X GET "$ENDPOINT/organisations/$ORG_ID/letters" \ + -H "Authorization: Bearer $ACCESS_TOKEN" | jq .data.attributes` + +UPLOAD_URL=`echo $ATTRS | jq .url` +URL_SIG=`echo $ATTRS | jq .url_signature` + +# FIXME: somehow should PUT the file on $UPLOAD_URL here! +# (not sure how to use URL_SIG, if at all!) + +LOGS="authorization-post.log" +ADDR="$1" +NAME=`echo $ADDR | jq -r .full_name` +STREET=`echo $ADDR | jq -r .street` +CITY=`echo $ADDR | jq -r .city` +POSTCODE=`echo $ADDR | jq -r .postcode` +COUNTRY=`echo $ADDR | jq -r .country` +ADDRESS=`echo -e "$STREET\n$POSTCODE $CITY\n$COUNTRY"` +RECIPIENT="$(jq -n ' + { + name: $NAME, + street: $STREET, + number: "", + city: $CITY, + zip: $POSTCODE, + country: $COUNTRY, + }' \ + --arg NAME "$NAME" \ + --arg STREET "$STREET" \ + --arg CITY "$CITY" \ + --arg POSTCODE "$POSTCODE" \ + --arg COUNTRY "$COUNTRY" + )" +SENDER="$(jq -n ' + { + name: "Anastasis SARL", + street: "Rue de Mondorf", + number: "7", + zip: "5421", + city: "Erpeldange", + country: "Luxembourg" + }' + )" +REQUEST="$(jq -n ' + { data: { + type: "letters", + attributes: { + file_original_name: "wtf.pdf", + file_url: "$UPLOAD_URL", + file_url_signature: "$URL_SIG", + address_position: "right", + delivery_product: "cheap", + print_mode: "duplex", + print_spectrum: "grayscale", + meta_data: { + recipient: $RECIPIENT, + sender: $SENDER + } + }' \ + --argjson RECIPIENT "$RECIPIENT" \ + --argjson SENDER "$SENDER" \ + --arg UPLOAD_URL "$UPLOAD_URL" \ + --arg URL_SIG "$URL_SIG" + )" +REPLY=`mktemp /tmp/authorization-add-replyXXXXXX` +STATUS=$(curl --request POST \ + --url $ENDPOINT/organizations/${ORG_ID}/letters \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Bearer $ACCESS_TOKEN' \ + -d "$REQUEST" \ + -o $REPLY \ + -w "%{http_code}" -s) +cat $REPLY >> $LOGS +case $STATUS in + 201) + ;; + *) + echo "Failed to add letter: $STATUS" >> $LOGS + exit 1; + ;; +esac +LETTER_ID=`cat $REPLY | jq -r .data.id` +rm $REPLY + +exit 0 + +REPLY=`mktemp /tmp/authorization-delete-replyXXXXXX` +STATUS=$(curl --request POST \ + --url $ENDPOINT/organizations/$ORG_ID/letters/$LETTER_ID \ + -o $REPLY \ + -w "%{http_code}" -s) +cat $REPLY >> $LOGS +case $STATUS in + 200) + ;; + *) + echo "Failed to delete letter: $STATUS" >> $LOGS + ;; +esac +rm $REPLY + +exit 0 diff --git a/src/authorization/anastasis-authorization-sms.sh b/src/authorization/anastasis-authorization-sms.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -eu +. telesign-secrets +# Set AUTH_TOKEN=... + +MESSAGE=`cat -` +TMPFILE=`mktemp /tmp/sms-loggingXXXXXX` +STATUS=$(curl --request POST \ + --url https://rest-api.telesign.com/v1/messaging \ + --header 'authorization: Basic $AUTH_TOKEN' \ + --header 'content-type: application/x-www-form-urlencoded' \ + --data account_livecycle_event=transact \ + --data "message=$MESSAGE" \ + --data message_type=OTP \ + --data "phone_number=$1" \ + -w "%{http_code}" -s -o $TMPFILE) +echo `cat $TMPFILE` >> /var/log/sms.log +rm -f $TMPFILE +case $STATUS in + 200|203|250|290|291|295) + exit 0; + ;; + *) + exit 1; + ;; +esac +exit 1