Commit 520622ca by Luciano Barletta

added message checking

1 parent e372f88b
LINE=1
while IFS= read -r ID while IFS= read -r ID
do do
DATA=$(curl -d "id=$ID" -H "application/x-www-form-urlencoded" 192.168.15.75:5000/cons)
echo $DATA
done < msg_id.txt
\ No newline at end of file \ No newline at end of file
if [ $(echo $ID | cut -c1-1 | grep [0-9]) ]
then
STATUS=$(curl -d "id=$ID" 192.168.15.75:5000/cons)
if [[ $STATUS != "queued" ]]
then
echo $LINE >> delete
fi
else
echo $LINE >> delete
fi
LINE=$(($LINE+1))
done < msg_ids.txt
if [ -e delete ]
then
tac delete > aux
cat aux > delete
while IFS= read -r LINE
do
sed ${LINE}d msg_ids.txt > aux
cat aux > msg_ids.txt
done < delete
rm delete
rm aux
fi
...@@ -3,12 +3,11 @@ MSG=$2 ...@@ -3,12 +3,11 @@ MSG=$2
PHONE=$3 PHONE=$3
TYPE=$4 TYPE=$4
# receive public key if one doesn't exist # receive public key if I don't have it
if [ ! -e server_rsa_key.pub ] if [ ! -e server_rsa_key.pub ]
then then
echo "getting new public key from server" echo "getting public key from server"
PUB_KEY=$(curl 192.168.15.75:5000/init) curl 192.168.15.75:5000/key > server_rsa_key.pub
printf "%s" "$PUB_KEY" > server_rsa_key.pub
fi fi
# generate random key # generate random key
...@@ -18,26 +17,23 @@ openssl rand -base64 32 > rand.key ...@@ -18,26 +17,23 @@ openssl rand -base64 32 > rand.key
# encode data with random key # encode data with random key
echo "encoding $MSG with random key" echo "encoding $MSG with random key"
echo "$MSG" | openssl enc -aes-256-cbc -salt -out data.enc -pass file:./rand.key echo "$MSG" | openssl enc -aes-256-cbc -salt -out data.enc -pass file:./rand.key
#printf "%s" "$MSG" > data
# encrypt random key with server's pubkey # encrypt random key with server's pubkey
openssl rsautl -encrypt -inkey server_rsa_key.pub -pubin -in rand.key -out rand.key.enc openssl rsautl -encrypt -inkey server_rsa_key.pub -pubin -in rand.key -out rand.key.enc
rm rand.key
# send data as file (with optional encripted symectric key) # send data as file (with optional encripted symectric key)
curl -F "data=@data.enc" -F "key=@rand.key.enc" 192.168.15.75:5000/data MSG_ID=$(curl -F "data=@data.enc" -F "key=@rand.key.enc" 192.168.15.75:5000/data)
#curl -F "data=@data" 192.168.15.75:5000/data
# send the rest of the parameter to send the data # send the rest of the parameter to send the data
echo "calling message sending method of server" echo "calling message sending method of server"
DATA=$(curl -d "serv=$SERV" -d "dest=$PHONE" -d "type=$TYPE" 192.168.15.75:5000/msg) ID=$(curl -d "id=$MSG_ID" -d "serv=$SERV" -d "dest=$PHONE" -d "type=$TYPE" 192.168.15.75:5000/msg)
echo $ID >> msg_ids.txt
echo $DATA >> msg_ids.txt
# cleanup # cleanup
rm ./rand.key.enc rm rand.key.enc
rm ./data.enc rm data.enc
rm rand.key
# DEBUGGING # DEBUGGING
rm /dev/shm/info_colmena rm /dev/shm/info_colmena
rm ./server_rsa_key.pub
\ No newline at end of file \ No newline at end of file
rm server_rsa_key.pub
\ No newline at end of file \ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!