-
Notifications
You must be signed in to change notification settings - Fork 0
/
Script
155 lines (128 loc) · 7.87 KB
/
Script
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/bash
#
# MixMailFrom<username>.sh - Mail from phone to Remailer
# Written for the purpose of sending remailer messages via
# email from a cell phone. Remailer headers and message must
# be PGP symmetrically encrypted using OpenKeyChain before it is
# sent to mask the remailer message and headers.
# Create a new user on your server. That is all that needs
# to be done concerning the new user. Choose an inconspicuous
# user name so as to not let on that it has anything to do
# with a remailer. This user will be the user that receives
# the encrypted email sent from your cell phone.
# The program checks the 'var/mail/<username>' mail file for
# text. If text is found, it strips out all of the pgp bundles
# and decrypts the mixmaster headers/message and sends the message
# with the mixmaster client. The script can handle multiple
# received emails/pgp bundles if present.
# This script is executred every few minutes to process incoming
# messages.
# cron:
# */1 * * * * /usr/local/sbin/MixMailFrom<username>.sh
# Script parameters setup: (Replace all parameters within double quotation marks "".
# These parameters are located under '# --- Parameters ---'
# near line 84 below.)
# username="<username>" # the name of the new user you created on your server
# emailaddr="<any email address>" # an email address to receive Success/Error messages
# passwd="<symmeteric password>" # the pgp symmeteric password you will use to
# symmetrically encrypt your remailer headers/message
# on your cell phone
#-------------------------------------------------------------#
# Cell phone: #
# Install 'OpenKeychain' and 'K-9 Mail'. #
# [Do not use Google's AndroidEmail. It has a return receipt #
# feature that cannot be turned off.] #
# #
# 'Clipboard Manager' #
# I suggest you install 'Clipboard Manager' to more easily #
# retrieve the remailer headers. Place the following headers #
# along with needed spaces in 'Clipboard Manager' and give #
# the clip a name. Another clip can be made for newsgroups. #
# #
# Chain *,*,*; Copies=3; #
# To: #
# Subject: #
# <additional blank line> #
# msg #
# #
# 'K-9 Mail' #
# After installing 'K-9 Mail' and 'OpenKeychain', go to #
# 'K-9 Mail' Settings/Account settings/Cryptography/OpenPGP #
# and choose 'OpenKeychain'. #
# #
# 'To send a message to your server for remailing': #
# Start 'Clipboard Manager' and retrieve the remailer headers.#
# Start 'K-9 Mail'. Click on the envelope icon. Paste the #
# the remailer headers into the message text area and fill #
# them out. Fill out the 'K-9 Mail' From, To, and Subject #
# lines. Now for the tricky procedure of symmetrically #
# encrypting the remailer headers/message in the 'K-9 Mail' #
# Message text area. (You could also do the encrypting #
# in 'OpenKeychain' and just copy it over.). Press and hold #
# down on the 'K-9 Mail' Message text area and click SELECT #
# ALL. In the next menu, click the 3 dots. Then click #
# ENCRYPT. Click the 3 dots again and check Encrypt with #
# password. Type in the symetric password that matches the #
# 'passwd=' field you chose in this script below. Next #
# press the little clipboard icon at the top of the window #
# and the encrypted remailer headers/message will be placed #
# back into 'K-9 Mail'. Now press the paper airplane icon #
# to send. #
#-------------------------------------------------------------#
filePath=${0%/*} # current file path $filePath/
# --- Parameters ---
username="" # user name used for incoming remailer mail
emailaddr="" # an email address to receive send Success/Error messages
passwd="" # pgp symeteric password (same one used to symmetrically encrypt on your phone)
if [ ! -e /var/mail/$username ] && [[ $(cat $filePath/MixMailFrom$username.ctl | wc -l) -eq 0 ]]; then # is user's file mail present
echo "$(date '+%a %b %d %G %r %Z') /var/mail/$username file not present!" >> $filePath/MixMailFrom$username.err
mutt -s "$username malfunction!" $emailaddr <<< "/var/mail/$username mail file not present! - $(date '+%a %b %d %G %r %Z')"
cat "error" > $filePath/MixMailFrom$username.ctl # mark ctl file of error
exit 0
else
cat /dev/null > $filePath/MixMailFrom$username.ctl # file exist
fi
if [[ $(cat /var/mail/$username | wc -l) -eq 0 ]]; then # is mail file empty - exit
exit 0
fi
# '-------------------'
# 'Extract PGP MESSAGE'
# '-------------------'
if [[ $(grep -c "\-\-\-\-\-BEGIN PGP MESSAGE\-\-\-\-\-" /var/mail/$username) -gt 0 ]]; then # see if any messages
echo "$(date '+%a %b %d %G %r %Z') /var/mail/$username contains -----BEGIN PGP MESSAGE-----"
sed -ne '/-----BEGIN PGP MESSAGE-----/,/-----END PGP MESSAGE-----/p' < /var/mail/$username > $filePath/tempwork # strip out pgp message
sed -i '/<br>/d' $filePath/tempwork # remove any duplicate messages with appended <br>
sed -e 's/=.*/=/' $filePath/tempwork > $filePath/tempwork2 # remove any added printable chars from PGP payload or decrypt will bombs
cat /dev/null > $filePath/tempwork3 # clear tempwork3
msgcnt=0
while read line1; do #loop thru pgp messages, decrypt, and send with mixmaster
echo $line1 >> $filePath/tempwork3 # copy line 1 to tempwork3
if [[ $line1 == "-----END PGP MESSAGE-----" ]]; then # now have complete pgp bundle
echo $passwd|gpg --yes --passphrase-fd 0 --no-tty --decrypt $filePath/tempwork3 > /home/$username/message.txt 2> $filePath/MixMailFrom$username.err # decrypt message
if [[ $(grep -c "gpg: decryption failed: bad key" $filePath/MixMailFrom$username.err) -gt 0 ]]; then # signal bad passphrase
mutt -s "$username?" $emailaddr <<< "$username: bad msg - $(date '+%a %b %d %G %r %Z')"
cat /dev/null > $filePath/MixMailFrom$username.err
continue
fi
if [ -s /home/$username/message.txt ] && [[ $(grep -c "To: " /home/$username/message.txt) -gt 0 ]] && [[ $(grep -c "Subject: " /home/$username/message.txt) -gt 0 ]]; then # do a bit of editing
((msgcnt++))
sleep 5 # pause 5 sec for mixmaster
/usr/bin/mixmaster /home/$username/message.txt --send --mail # exec mixmaster
echo "$(date '+%a %b %d %G %r %Z') Message sent." >> $filePath/MixMailFrom$username.log
echo "" >> $filePath/MixMailFrom$username.log
fi
cat /dev/null > $filePath/tempwork3
fi
done< $filePath/tempwork2 # read file line by line
fi # 'if [[ $(grep'
if [[ msgcnt -gt 0 ]]; then
mutt -s "$username!" $emailaddr <<< "$username: $msgcnt - $(date '+%a %b %d %G %r %Z')"
fi
cp /var/mail/$username /var/mail/$username.save
shrred -n 7 -z -u /var/mail/$username # shred/delete alread processed mail file and del any invalid msgs/spam
cat /dev/null > /var/mail/$username # recreate file
shred -n 7 -z -u $filePath/tempwork
shred -n 7 -z -u $filePath/tempwork2
shred -n 7 -z -u $filePath/tempwork3
shred -n 7 -z -u /home/$username/message.txt
exit 0