forked from axiom-team/jaklis
Compare commits
1 Commits
master
...
bash-codeb
Author | SHA1 | Date |
---|---|---|
poka | c6055ccc93 |
14
deletemsg.sh
14
deletemsg.sh
|
@ -31,17 +31,17 @@ do
|
||||||
-o|--outbox) type=outbox;;
|
-o|--outbox) type=outbox;;
|
||||||
-id|--id) id="${args[$i+1]}"
|
-id|--id) id="${args[$i+1]}"
|
||||||
[[ -z $id ]] && echo "Veuillez préciser un ID de message." && exit 1;;
|
[[ -z $id ]] && echo "Veuillez préciser un ID de message." && exit 1;;
|
||||||
-k|--key) dunikey="${args[$i+1]}"
|
-k|--key) DUNIKEY="${args[$i+1]}"
|
||||||
[[ -z $dunikey ]] && echo "Veuillez préciser un fichier de trousseau." && exit 1;;
|
[[ -z $DUNIKEY ]] && echo "Veuillez préciser un fichier de trousseau." && exit 1;;
|
||||||
-h|--help) helpOpt && exit 0;;
|
-h|--help) helpOpt && exit 0;;
|
||||||
*) [[ "${args[$i]}" == "-"* ]] && echo "Option inconnue." && exit 1;;
|
*) [[ "${args[$i]}" == "-"* ]] && echo "Option inconnue." && exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z $dunikey ]]; then
|
if [[ -z $DUNIKEY ]]; then
|
||||||
read -p "Fichier de trousseau: " dunikey
|
read -p "Fichier de trousseau: " DUNIKEY
|
||||||
fi
|
fi
|
||||||
issuer=$(./natools.py pk -f pubsec -k $dunikey)
|
issuer=$(./natools.py pk -f pubsec -k $DUNIKEY)
|
||||||
|
|
||||||
if [[ -z $type ]]; then
|
if [[ -z $type ]]; then
|
||||||
type="inbox"
|
type="inbox"
|
||||||
|
@ -60,11 +60,11 @@ hashBrut="{\"version\":2,\"index\":\"message\",\"type\":\"$type\",\"id\":\"$id\"
|
||||||
hash=$(echo -n "$hashBrut" | 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)
|
||||||
|
|
||||||
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
|
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
|
||||||
jq . <<<$document
|
jq . <<<$document
|
||||||
|
|
||||||
# Envoi du document
|
# Envoi du document
|
||||||
curl -s -X POST "$pod/history/delete" -d "$document"
|
curl -s -X POST "$POD/history/delete" -d "$document"
|
||||||
echo
|
echo
|
||||||
|
|
18
readmsg.sh
18
readmsg.sh
|
@ -32,8 +32,8 @@ declare -a args=($@)
|
||||||
for ((i=0; i<${#args[*]}; ++i))
|
for ((i=0; i<${#args[*]}; ++i))
|
||||||
do
|
do
|
||||||
case ${args[$i]} in
|
case ${args[$i]} in
|
||||||
-k|--key) dunikey="${args[$i+1]}"
|
-k|--key) DUNIKEY="${args[$i+1]}"
|
||||||
[[ -z $dunikey ]] && echo "Veuillez préciser un fichier de trousseau." && exit 1;;
|
[[ -z $DUNIKEY ]] && echo "Veuillez préciser un fichier de trousseau." && exit 1;;
|
||||||
-o|--outbox) type=outbox;;
|
-o|--outbox) type=outbox;;
|
||||||
-n|--number) nbrRaw="${args[$i+1]}";;
|
-n|--number) nbrRaw="${args[$i+1]}";;
|
||||||
-n*) nbrRaw="${args[$i]:2}";;
|
-n*) nbrRaw="${args[$i]:2}";;
|
||||||
|
@ -43,9 +43,9 @@ do
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
recipient=$(./natools.py pk -f pubsec -k $dunikey)
|
recipient=$(./natools.py pk -f pubsec -k $DUNIKEY)
|
||||||
if [[ -z $dunikey ]]; then
|
if [[ -z $DUNIKEY ]]; then
|
||||||
read -p "Fichier de trousseau: " dunikey
|
read -p "Fichier de trousseau: " DUNIKEY
|
||||||
fi
|
fi
|
||||||
[[ -z $type ]] && type="inbox"
|
[[ -z $type ]] && type="inbox"
|
||||||
[[ -z $nbrRaw ]] && nbrRaw=5000
|
[[ -z $nbrRaw ]] && nbrRaw=5000
|
||||||
|
@ -55,7 +55,7 @@ fi
|
||||||
document="{\"sort\":{\"time\":\"desc\"},\"from\":0,\"size\":$nbrRaw,\"_source\":[\"issuer\",\"recipient\",\"title\",\"content\",\"time\",\"nonce\",\"read_signature\"],\"query\":{\"bool\":{\"filter\":{\"term\":{\"recipient\":\"$recipient\"}}}}}"
|
document="{\"sort\":{\"time\":\"desc\"},\"from\":0,\"size\":$nbrRaw,\"_source\":[\"issuer\",\"recipient\",\"title\",\"content\",\"time\",\"nonce\",\"read_signature\"],\"query\":{\"bool\":{\"filter\":{\"term\":{\"recipient\":\"$recipient\"}}}}}"
|
||||||
|
|
||||||
# Envoi du document
|
# Envoi du document
|
||||||
msgContent=$(curl -s -X POST "$pod/message/$type/_search" -d "$document" | jq .hits.hits[]._source -c)
|
msgContent=$(curl -s -X POST "$POD/message/$type/_search" -d "$document" | jq .hits.hits[]._source -c)
|
||||||
|
|
||||||
#Traitement des données
|
#Traitement des données
|
||||||
n=0
|
n=0
|
||||||
|
@ -69,13 +69,13 @@ for i in $msgContent; do
|
||||||
content="${dataObj[4]}"
|
content="${dataObj[4]}"
|
||||||
time="${dataObj[5]}"
|
time="${dataObj[5]}"
|
||||||
|
|
||||||
titleClear=$(./natools.py box-decrypt -p $issuer -f pubsec -k $dunikey -n $nonce -I 64 <<< "${title}")
|
titleClear=$(./natools.py box-decrypt -p $issuer -f pubsec -k $DUNIKEY -n $nonce -I 64 <<< "${title}")
|
||||||
contentClear=$(./natools.py box-decrypt -p $issuer -f pubsec -k $dunikey -n $nonce -I 64 <<< "${content}")
|
contentClear=$(./natools.py box-decrypt -p $issuer -f pubsec -k $DUNIKEY -n $nonce -I 64 <<< "${content}")
|
||||||
echo "$titleClear"
|
echo "$titleClear"
|
||||||
echo "$contentClear"
|
echo "$contentClear"
|
||||||
echo "========="
|
echo "========="
|
||||||
((n++))
|
((n++))
|
||||||
# echo "./natools.py box-decrypt -p $issuer -f pubsec -k $dunikey -n $nonce -I 64 <<< \"${title}\""
|
# echo "./natools.py box-decrypt -p $issuer -f pubsec -k $DUNIKEY -n $nonce -I 64 <<< \"${title}\""
|
||||||
done
|
done
|
||||||
|
|
||||||
#echo "$msgContent" | jq
|
#echo "$msgContent" | jq
|
||||||
|
|
24
sendmsg.sh
24
sendmsg.sh
|
@ -34,21 +34,21 @@ do
|
||||||
-f|--file) file="${args[$i+1]}"
|
-f|--file) file="${args[$i+1]}"
|
||||||
[[ ! -f $file ]] && echo "Le fichier $file n'existe pas." && exit 1;;
|
[[ ! -f $file ]] && echo "Le fichier $file n'existe pas." && exit 1;;
|
||||||
-t|--test) file="test.txt"
|
-t|--test) file="test.txt"
|
||||||
issuer=$(./natools.py pk -f pubsec -k $dunikey)
|
issuer=$(./natools.py pk -f pubsec -k $DUNIKEY)
|
||||||
recipient=$issuer;;
|
recipient=$issuer;;
|
||||||
-r|--recipient) recipient="${args[$i+1]}"
|
-r|--recipient) recipient="${args[$i+1]}"
|
||||||
[[ -z $recipient ]] && echo "Veuillez préciser un destinataire." && exit 1;;
|
[[ -z $recipient ]] && echo "Veuillez préciser un destinataire." && exit 1;;
|
||||||
-k|--key) dunikey="${args[$i+1]}"
|
-k|--key) DUNIKEY="${args[$i+1]}"
|
||||||
[[ -z $dunikey ]] && echo "Veuillez préciser un fichier de trousseau." && exit 1;;
|
[[ -z $DUNIKEY ]] && echo "Veuillez préciser un fichier de trousseau." && exit 1;;
|
||||||
-h|--help) helpOpt && exit 0;;
|
-h|--help) helpOpt && exit 0;;
|
||||||
*) [[ "${args[$i]}" == "-"* ]] && echo "Option inconnue." && exit 1;;
|
*) [[ "${args[$i]}" == "-"* ]] && echo "Option inconnue." && exit 1;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ -z $dunikey ]]; then
|
if [[ -z $DUNIKEY ]]; then
|
||||||
read -p "Fichier de trousseau: " dunikey
|
read -p "Fichier de trousseau: " DUNIKEY
|
||||||
fi
|
fi
|
||||||
issuer=$(./natools.py pk -f pubsec -k $dunikey)
|
issuer=$(./natools.py pk -f pubsec -k $DUNIKEY)
|
||||||
|
|
||||||
if [[ -z $file ]]; then
|
if [[ -z $file ]]; then
|
||||||
read -p "Objet du message: " title
|
read -p "Objet du message: " title
|
||||||
|
@ -67,8 +67,8 @@ fi
|
||||||
# Récupération et chiffrement du titre et du message
|
# Récupération et chiffrement du titre et du message
|
||||||
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)
|
||||||
b58nonce=$(echo $nonce | base64 -d | base58)
|
b58nonce=$(echo $nonce | base64 -d | base58)
|
||||||
title=$(head -n1 <<<$message | ./natools.py box-encrypt -n $nonce -f pubsec -k $dunikey -p $recipient -O 64)
|
title=$(head -n1 <<<$message | ./natools.py box-encrypt -n $nonce -f pubsec -k $DUNIKEY -p $recipient -O 64)
|
||||||
content=$(tail -n+2 <<<$message | ./natools.py box-encrypt -n $nonce -f pubsec -k $dunikey -p $recipient -O 64)
|
content=$(tail -n+2 <<<$message | ./natools.py box-encrypt -n $nonce -f pubsec -k $DUNIKEY -p $recipient -O 64)
|
||||||
|
|
||||||
times=$(date -u +'%s')
|
times=$(date -u +'%s')
|
||||||
|
|
||||||
|
@ -77,15 +77,15 @@ hashBrut="{\"issuer\":\"$issuer\",\"recipient\":\"$recipient\",\"title\":\"$titl
|
||||||
hash=$(echo -n "$hashBrut" | 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
|
||||||
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
|
document="{\"hash\":\"$hash\",\"signature\":\"$signature\",${hashBrut:1}"
|
||||||
jq . <<<$document
|
jq . <<<$document
|
||||||
|
|
||||||
# Envoi du document
|
# Envoi du document
|
||||||
#curl -s -i -X OPTIONS "$pod/message/inbox?pubkey=$issuer" -d "pubkey=$issuer"
|
#curl -s -i -X OPTIONS "$POD/message/inbox?pubkey=$issuer" -d "pubkey=$issuer"
|
||||||
msgID=$(curl -s -X POST "$pod/message/inbox?pubkey=$recipient" -d "$document")
|
msgID=$(curl -s -X POST "$POD/message/inbox?pubkey=$recipient" -d "$document")
|
||||||
echo -e "\nMessage ID: $msgID"
|
echo -e "\nMessage ID: $msgID"
|
||||||
|
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ echo -e "\nMessage ID: $msgID"
|
||||||
#sleep 1 && ./deletemsg.sh -id $msgID
|
#sleep 1 && ./deletemsg.sh -id $msgID
|
||||||
|
|
||||||
# To put the message in outbox too
|
# To put the message in outbox too
|
||||||
#curl -s -X POST "$pod/message/outbox?pubkey=$issuer" -d "$document"
|
#curl -s -X POST "$POD/message/outbox?pubkey=$issuer" -d "$document"
|
||||||
|
|
||||||
# To put the message as read, add this at the end of document
|
# To put the message as read, add this at the end of document
|
||||||
#,\"read_signature\":\"$signature\"
|
#,\"read_signature\":\"$signature\"
|
||||||
|
|
Loading…
Reference in New Issue