send.sh
1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
SERV=$1
MSG=$2
PHONE=$3
TYPE=$4
# receive public key if I don't have it
if [ ! -e server_rsa_key.pub ]
then
echo "getting public key from server"
curl 192.168.15.75:5000/key > server_rsa_key.pub
fi
# generate random key
echo "generating random encryption key"
openssl rand -base64 32 > rand.key
# encode data with random key
echo "encoding $MSG with random key"
echo "$MSG" | openssl enc -aes-256-cbc -salt -out data.enc -pass file:./rand.key
# encrypt random key with server's pubkey
openssl rsautl -encrypt -inkey server_rsa_key.pub -pubin -in rand.key -out rand.key.enc
# send data as file (with optional encripted symectric key)
MSG_ID=$(curl -F "data=@data.enc" -F "key=@rand.key.enc" 192.168.15.75:5000/data)
# send the rest of the parameter to send the data
echo "calling message sending method of server"
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
# cleanup
rm rand.key.enc
rm data.enc
rm rand.key
# DEBUGGING
rm /dev/shm/info_colmena
rm server_rsa_key.pub