forked from axiom-team/jaklis
Factorise document using; add comments
This commit is contained in:
parent
4e76e0bbf1
commit
00b7a8de0d
20
deletemsg.sh
20
deletemsg.sh
|
@ -45,23 +45,15 @@ fi
|
||||||
times=$(date -u +'%s')
|
times=$(date -u +'%s')
|
||||||
|
|
||||||
# Fabrication du hash
|
# Fabrication du hash
|
||||||
hash="{\"version\":2,\"index\":\"message\",\"type\":\"$type\",\"id\":\"$id\",\"issuer\":\"$issuer\",\"time\":$times}"
|
hashBrut="{\"version\":2,\"index\":\"message\",\"type\":\"$type\",\"id\":\"$id\",\"issuer\":\"$issuer\",\"time\":$times}"
|
||||||
hash=$(echo -n "$hash" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
|
hash=$(echo -n "$hashBrut" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
|
||||||
|
|
||||||
# Fabrication de la signature
|
# Fabrication de la signature
|
||||||
signature=$(echo -n "$hash" | ./natools.py sign -f pubsec -k $dunikey --noinc -O 64)
|
signature=$(echo -n "$hash" | ./natools.py sign -f pubsec -k $dunikey --noinc -O 64)
|
||||||
|
|
||||||
# Affichage du JSON final
|
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
|
||||||
echo "{
|
jq . <<<$document
|
||||||
\"version\": 2,
|
|
||||||
\"index\": \"message\",
|
|
||||||
\"type\": \"$type\",
|
|
||||||
\"id\": \"$id\",
|
|
||||||
\"issuer\": \"$issuer\",
|
|
||||||
\"time\": $times,
|
|
||||||
\"hash\": \"$hash\",
|
|
||||||
\"signature\": \"$signature\"
|
|
||||||
}"
|
|
||||||
|
|
||||||
# Envoi du 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
|
||||||
|
|
33
sendmsg.sh
33
sendmsg.sh
|
@ -4,6 +4,8 @@
|
||||||
# Simple testeur d'envoi de message via la messagerie de Cesium ou de Gchange.
|
# 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
|
[[ ! -f .env ]] && cp .env.template .env
|
||||||
source .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)
|
nonce=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
||||||
|
|
||||||
# Fabrication du hash
|
# Fabrication du hash
|
||||||
hash="{\"issuer\":\"$issuer\",\"recipient\":\"$recipient\",\"title\":\"$title\",\"content\":\"$content\",\"time\":$times,\"nonce\":\"$nonce\",\"version\":2}"
|
hashBrut="{\"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) }')
|
hash=$(echo -n "$hashBrut" | sha256sum | cut -d ' ' -f1 | awk '{ print toupper($0) }')
|
||||||
|
|
||||||
# Fabrication de la signature
|
# Fabrication de la signature
|
||||||
signature=$(echo -n "$hash" | ./natools.py sign -f pubsec -k $dunikey --noinc -O 64)
|
signature=$(echo -n "$hash" | ./natools.py sign -f pubsec -k $dunikey --noinc -O 64)
|
||||||
|
|
||||||
# Affichage du JSON final
|
# Affichage du JSON final
|
||||||
echo "{
|
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
|
||||||
"issuer" : \"$issuer\",
|
jq . <<<$document
|
||||||
"recipient" : \"$recipient\",
|
|
||||||
"title" : \"$title\",
|
|
||||||
"content" : \"$content\",
|
|
||||||
"time" : "$times",
|
|
||||||
"nonce" : \"$nonce\",
|
|
||||||
"version" : 2,
|
|
||||||
"hash" : \"$hash\",
|
|
||||||
"signature" : \"$signature\"
|
|
||||||
}"
|
|
||||||
|
|
||||||
# Envoi du document
|
# Envoi du document
|
||||||
curl -X OPTIONS "$pod/message/inbox?pubkey=$issuer" -d "pubkey=$issuer"
|
#curl -s -i -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}"
|
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"
|
# Delete the message 1 second later, just for test
|
||||||
# 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}"
|
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
|
# To put the message as read
|
||||||
# ,\"read_signature\":\"$signature\"
|
# ,\"read_signature\":\"$signature\"
|
||||||
|
|
Loading…
Reference in New Issue