-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnovaweb
More file actions
106 lines (105 loc) · 2.63 KB
/
novaweb
File metadata and controls
106 lines (105 loc) · 2.63 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
if [ "$1" == "image" ]
then
docker build -t "$3" -f "$2" .
docker login
docker push "$3"
elif [ "$1" == "vpn" ]
then
if [ "$2" == kill ]
then
if [ -f "$HOME/.scripts/vpnpid" ]
then
sudo kill $(cat $HOME/.scripts/vpnpid)
rm $HOME/.scripts/vpnpid
fi
else
if [ -f "$HOME/.scripts/vpnpid" ]
then
echo "There was a vpn connection open! Closing it before opening another"
sleep 1
sudo kill $(cat $HOME/.scripts/vpnpid)
fi
if [ "$2" == esc ]
then
sudo openvpn $HOME/.scripts/mateust.ovpn &
echo $! > $HOME/.scripts/vpnpid
elif [ "$2" == home ]
then
sudo openvpn $HOME/.scripts/mateust.ovpn
echo $! > $HOME/.scripts/vpnpid
else
echo "Você deve escolher 'esc' ou 'home'!"
fi
fi
elif [ "$1" == "encrypt" ]
then
options=$(getopt -o d:i:o: -- "$@")
[ $? -eq 0 ] || {
echo "Você deve informar ao menos o destinatário com a opção -d e o arquivo a cifrar com -i."
return 1
}
eval set -- "$options"
while true; do
case "$1" in
-d)
shift
DEST="$1"
echo "Mensagem para $DEST@novaweb.mobi"
;;
-i)
shift
INFILE="$1"
echo "Arquivo é $INFILE"
;;
-o)
shift
OUTFILE="$1"
;;
--)
shift
break
;;
esac
shift
done
[[ ! -z "$OUTFILE" ]] || OUTFILE="$INFILE.enc"
openssl rand -base64 -out key.bin 128 && echo "Generated Symetric key" || "Symetric key gen failed"
openssl enc -aes-256-cbc -e -pbkdf2 -salt -in "$INFILE" -out $OUTFILE -pass file:./key.bin && echo "Encrypted file" || "Encrypting failed"
openssl rsautl -encrypt -pubin -inkey <(ssh-keygen -e -m PKCS8 -f "$HOME/.scripts/$DEST@novaweb.mobi_rsa.pub") -in key.bin -out key.bin.enc && echo "Encrypted key" || "Encrypting key failed"
rm key.bin && echo "Erased plaintext key file" || "Failed removing plaintext key"
unset INFILE
unset OUTFILE
unset DEST
elif [ "$1" == "decrypt" ]
then
options=$(getopt -o i:o: -- "$@")
[ $? -eq 0 ] || {
echo "Você deve informar ao menos o arquivo a decifrar com -i."
return 1
}
eval set -- "$options"
while true; do
case "$1" in
-i)
shift
INFILE="$1"
echo "Arquivo é $INFILE"
;;
-o)
shift
OUTFILE="$1"
;;
--)
shift
break
;;
esac
shift
done
[[ ! -z "$OUTFILE" ]] || OUTFILE="${INFILE::-4}"
openssl rsautl -decrypt -inkey $HOME/.ssh/id_rsa -in key.bin.enc -out key.bin && echo "Decrypted key" || echo "Failed decrypting key"
openssl enc -d -aes-256-cbc -pbkdf2 -in $INFILE -out $OUTFILE -pass file:./key.bin && echo "Decrypted file" || echo "Failed decrypting file"
rm $INFILE key.bin.enc key.bin && echo "Removed cryptographed file and key"
unset INFILE
unset OUTFILE
fi