-
Notifications
You must be signed in to change notification settings - Fork 2
/
check.sh
executable file
·39 lines (38 loc) · 1.05 KB
/
check.sh
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
#!/bin/bash
key_pass='34fefd7a5e239681fe83bf4e3bef7dca'
echo -n "Generating keys .. "
rm -f test*
ssh-keygen -b 1024 -f test -q -N "$key_pass"
ssh-keygen -f test.pub -e -m pkcs8 > pub.pem
mv test test.priv
mv pub.pem test.pub
echo done
echo -n "Generating data .. "
dd if=/dev/urandom of=in.bin bs=10212 count=3 > /dev/null 2>&1
echo done
md5sum in.bin
echo -n "Encrypting .. "
# manually enter the password
./enc in.bin out.bin test.priv
echo done
echo "Signing .. "
openssl dgst -passin pass:"$key_pass" -sha512 -sign test.priv -out sign.bin out.bin
echo done
cat out.bin sign.bin > send.bin
rm -f out.bin sign.bin
echo -n "Sending .. "
echo done
echo -n "Receiving .. "
echo done
echo "Verifying .. "
fsize=`stat "-c%s" send.bin`
to_seek=$(($fsize-128))
dd if=send.bin of=sign.bin bs=1 skip=$to_seek > /dev/null 2>&1
dd if=send.bin of=out.bin bs=$to_seek count=1 > /dev/null 2>&1
openssl dgst -sha512 -verify test.pub -signature sign.bin out.bin
echo done
./dec out.bin out-dec.bin test.pub
md5sum out-dec.bin
echo -n "Comparing .. "
cmp in.bin out-dec.bin
echo done