Factorise document using; add comments

This commit is contained in:
poka 2020-11-05 13:46:07 +01:00
parent 4e76e0bbf1
commit 00b7a8de0d
2 changed files with 21 additions and 32 deletions

View File

@ -45,23 +45,15 @@ fi
times=$(date -u +'%s')
# Fabrication du hash
hash="{\"version\":2,\"index\":\"message\",\"type\":\"$type\",\"id\":\"$id\",\"issuer\":\"$issuer\",\"time\":$times}"
hash=$(echo -n "$hash" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
hashBrut="{\"version\":2,\"index\":\"message\",\"type\":\"$type\",\"id\":\"$id\",\"issuer\":\"$issuer\",\"time\":$times}"
hash=$(echo -n "$hashBrut" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
# Fabrication de la signature
signature=$(echo -n "$hash" | ./natools.py sign -f pubsec -k $dunikey --noinc -O 64)
# Affichage du JSON final
echo "{
\"version\": 2,
\"index\": \"message\",
\"type\": \"$type\",
\"id\": \"$id\",
\"issuer\": \"$issuer\",
\"time\": $times,
\"hash\": \"$hash\",
\"signature\": \"$signature\"
}"
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
jq . <<<$document
# Envoi du document
curl -X POST "$pod/history/delete" -d "{\"version\":2,\"index\":\"message\",\"type\":\"$type\",\"id\":\"$id\",\"issuer\":\"$issuer\",\"time\":$times,\"hash\":\"$hash\",\"signature\":\"$signature\"}"
curl -s -X POST "$pod/history/delete" -d "$document"
echo

View File

@ -4,6 +4,8 @@
# Simple testeur d'envoi de message via la messagerie de Cesium ou de Gchange.
# ###
[[ -z $(which jq) || -z $(which curl) ]] && echo "Installation de jq et curl ..." && sudo apt update && sudo apt install jq curl -y
[[ ! -f .env ]] && cp .env.template .env
source .env
@ -74,31 +76,26 @@ times=$(date -u +'%s')
nonce=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# Fabrication du hash
hash="{\"issuer\":\"$issuer\",\"recipient\":\"$recipient\",\"title\":\"$title\",\"content\":\"$content\",\"time\":$times,\"nonce\":\"$nonce\",\"version\":2}"
hash=$(echo -n "$hash" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
hashBrut="{\"issuer\":\"$issuer\",\"recipient\":\"$recipient\",\"title\":\"$title\",\"content\":\"$content\",\"time\":$times,\"nonce\":\"$nonce\",\"version\":2}"
hash=$(echo -n "$hashBrut" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
# Fabrication de la signature
signature=$(echo -n "$hash" | ./natools.py sign -f pubsec -k $dunikey --noinc -O 64)
# Affichage du JSON final
echo "{
"issuer" : \"$issuer\",
"recipient" : \"$recipient\",
"title" : \"$title\",
"content" : \"$content\",
"time" : "$times",
"nonce" : \"$nonce\",
"version" : 2,
"hash" : \"$hash\",
"signature" : \"$signature\"
}"
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
jq . <<<$document
# Envoi du document
curl -X OPTIONS "$pod/message/inbox?pubkey=$issuer" -d "pubkey=$issuer"
curl -X POST "$pod/message/inbox?pubkey=$issuer" -d "{\"hash\":\"$hash\",\"signature\":\"$signature\",\"issuer\":\"$issuer\",\"recipient\":\"$recipient\",\"title\":\"$title\",\"content\":\"$content\",\"time\":$times,\"nonce\":\"$nonce\",\"version\":2}"
#curl -s -i -X OPTIONS "$pod/message/inbox?pubkey=$issuer" -d "pubkey=$issuer"
msgID=$(curl -s -X POST "$pod/message/inbox?pubkey=$issuer" -d "$document")
echo -e "\nMessage ID: $msgID"
# curl -X OPTIONS "$pod/message/outbox?pubkey=$issuer" -d "pubkey=$issuer"
# curl -X POST "$pod/message/outbox?pubkey=$issuer" -d "{\"hash\":\"$hash\",\"signature\":\"$signature\",\"issuer\":\"$issuer\",\"recipient\":\"$recipient\",\"title\":\"$title\",\"content\":\"$content\",\"time\":$times,\"nonce\":\"$nonce\",\"version\":2}"
# Delete the message 1 second later, just for test
sleep 1 && ./deletemsg.sh -id $msgID
# To put the message in outbox too
# curl -s -X POST "$pod/message/outbox?pubkey=$issuer" -d "$document"
# To put the message as read
# ,\"read_signature\":\"$signature\"
# ,\"read_signature\":\"$signature\"