-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgpg.mrc
409 lines (338 loc) · 10.7 KB
/
gpg.mrc
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
; mirc-gpg by Phil Lavin (0x3FFC291A) & Allan Jude (0x7F697DBA)
; SVN: $Id$
alias gpg.setver {
set %gpg.scriptver 0.8
}
alias gpg.updatever {
if ($file($script).mtime != %gpg.scriptmtime) {
set %gpg.scriptmtime $file($script).mtime
gpg.setver
}
}
menu status,channel,query,nicklist,menubar {
-
mIRC-GPG
.Automatic Decryption
..$iif($group(#gpg).status == on,$style(1)) Enable:.enable #gpg
..$iif($group(#gpg).status == off,$style(1)) Disable:.disable #gpg
.Generate a new Key:runapp cmd /c %gpg.path $+ gpg --gen-key
;.Upload my Keys:runapp cmd /c %gpg.path $+ gpg --keyserver gpg.geekshed.net --send-keys ; doesn't work yet
.Refresh my Keys:echo -at Refreshing keys from gpg.geekshed.net please wait... | runapphidden cmd /c %gpg.path $+ gpg --keyserver gpg.geekshed.net --refresh-keys | echo -at All keys have been refreshed
.Search for Keys:runapp cmd /c %gpg.path $+ gpg --keyserver gpg.geekshed.net --search-keys $$?="Search Parameters (Email is best)"
;.Set Key Trust: ;not implemented
}
on *:load:{
gpg.setver
if (!$isdir($scriptdir $+ gpg)) {
runapphidden cmd /c mkdir " $+ $scriptdir $+ gpg $+ "
}
if (!$isdir($scriptdir $+ gpg\textin)) {
runapphidden cmd /c mkdir " $+ $scriptdir $+ gpg\textin $+ "
}
if ($isfile(C:\Program Files\GNU\GnuPG\gpg.exe)) {
set %gpg.path $shortfn(C:\Program Files\GNU\GnuPG\)
echo -at GPG Found At C:\Program Files\GNU\GnuPG\
}
elseif ($isfile(C:\Program Files (x86)\GNU\GnuPG\gpg.exe)) {
set %gpg.path $shortfn(C:\Program Files (x86)\GNU\GnuPG\)
echo -at GPG Found At C:\Program Files (x86)\GNU\GnuPG\
}
else {
set %gpg.path $shortfn($sdir(C:\, Please choose the directory where gpg.exe was installed to))
}
}
on *:START:{
gpg.setver
.timergpgverupdate 0 60 gpg.updatever
}
alias runAppHidden {
set %gpg.runname rah $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z)
.comopen %gpg.runname WScript.Shell
.comclose %gpg.runname $com(%gpg.runname, Run, 1, *bstr, $$1-, int, 0, bool, true)
}
alias runApp {
set %gpg.runname rah $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z)
.comopen %gpg.runname WScript.Shell
.comclose %gpg.runname $com(%gpg.runname, Run, 1, *bstr, $$1-, int, 3, bool, true)
}
alias runAppMin {
set %gpg.runname rah $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z) $+ $rand(a,z)
.comopen %gpg.runname WScript.Shell
.comclose %gpg.runname $com(%gpg.runname, Run, 1, *bstr, $$1-, int, 7, bool, true)
}
alias f8 {
gpgEncrypt
}
alias gpgEncrypt {
if (!$editbox($active, 0)) {
echo -a No Text To Send
}
else {
who $me
$dialog(spk, selPubKey)
if (%gpg.halt == $null) {
set %gpg.sourcefile $scriptdir $+ gpg\source.txt
set %gpg.destfile $scriptdir $+ gpg\dest.gpg
set %gpg.outfile $scriptdir $+ gpg\out.txt
write -c " $+ %gpg.sourcefile $+ " $editbox($active, 0)
runapp cmd /c %gpg.path $+ gpg -e -a %gpg.recipients -o " $+ %gpg.destfile $+ " " $+ %gpg.sourcefile $+ " > " $+ %gpg.outfile $+ " 2>&1
if ($lines(%gpg.outfile) > 0) {
echo -at Possible error detected. GPG produced output:
set %gpg.i 1
while (%gpg.i <= $lines(%gpg.outfile)) {
echo -at $read(%gpg.outfile, %gpg.i)
inc %gpg.i
}
}
set %gpg.editbox $editbox($active, 0)
editbox -a $null
set %gpg.i 1
while (%gpg.i <= $lines(%gpg.destfile)) {
set %gpg.line $read(%gpg.destfile, %gpg.i)
if ($len(%gpg.line) == 0) {
msg $active Comment: mirc-gpg by GeekShed.net version %gpg.scriptver http://mirc-gpg.googlecode.com
set %gpg.body 1
}
if (%gpg.line == -----END PGP MESSAGE-----) {
msg $active %gpg.outmsg
unset %gpg.outmsg
unset %gpg.body
}
if (%gpg.body == 1) {
;510 = Buffer of 512 bytes minus \r\n
;Minus from that length of your host, 14 other chars and the length of the channel
if ($calc($len(%gpg.line) + $len(%gpg.outmsg)) >= $calc(510 - ($len($address($me, 5)) + 14 + $len($active)))) {
msg $active %gpg.outmsg
unset %gpg.outmsg
set %gpg.outmsg %gpg.line
}
else {
set %gpg.outmsg %gpg.outmsg $+ %gpg.line
}
}
else {
msg $active %gpg.line
}
inc %gpg.i
}
if ($len(%gpg.outmsg) > 0) {
msg $active %gpg.outmsg
unset %gpg.outmsg
}
unset %gpg.body
}
if (%gpg.editbox != $null) {
echo -at < $+ $me [UNENC]> 4 $+ %gpg.editbox
unset %gpg.editbox
}
unset %gpg.halt
runapphidden cmd /c del " $+ $scriptdir $+ gpg\*" /Q
}
}
alias gpgDecrypt {
set %gpg.destfile $4- $+ .unenc
runappmin cmd /c %gpg.path $+ gpg -d -o " $+ %gpg.destfile $+ " " $+ $4- $+ " 2> " $+ $4- $+ .out $+ "
.timergpg $+ . $+ $3 $+ . $+ $2 off
if (!$isfile(%gpg.destfile)) {
echo $2 $timestamp < $+ $1 [ERROR]> 4This message may not have been for you
}
else {
set %gpg.i 1
while (%gpg.i <= $lines($4- $+ .unenc)) {
set %gpg.readline $read($4- $+ .unenc, %gpg.i)
if ($len(%gpg.readline) > 0) {
echo $2 $timestamp < $+ $1 [UNENC]> 4 $+ $strip(%gpg.readline)
}
else {
echo $2 $timestamp < $+ $1 $+ [UNENC]> 4 $+ $chr(1)
}
inc %gpg.i
}
runapphidden cmd /c del " $+ $4- $+ *" /Q
}
}
alias addKeysToSPK {
set %gpg.keyfile $scriptdir $+ gpg\keylist.txt
if ($1 == $null) {
runapphidden cmd /c %gpg.path $+ gpg --list-keys > " $+ %gpg.keyfile $+ "
}
else {
runapphidden cmd /c %gpg.path $+ gpg --list-keys " $+ $1- $+ " > " $+ %gpg.keyfile $+ "
}
; Reset $readn - is there a better way?
set %gpg.random $read(%gpg.keyfile, 1)
unset %gpg.random
set %gpg.readn 0
while ($readn != 0) {
set %gpg.line $read(%gpg.keyfile, s, uid, $calc(%gpg.readn + 1))
if ($readn != 0) {
did -a spk 1 %gpg.line
set %gpg.readn $readn
}
}
}
on *:dialog:spk:init:*:{
if (%gpg.searchstr == $null) {
addKeysToSPK
}
else {
addKeysToSPK %gpg.searchstr
did -a spk 4 %gpg.searchstr
}
}
on *:dialog:spk:sclick:*:{
if ($did == 3) {
set %gpg.halt 1
}
elseif ($did == 5) {
did -r spk 1
set %gpg.searchstr $did(4).text
addkeystospk %gpg.searchstr
}
elseif ($did == 2) {
set %gpg.i 1
set %gpg.checkCount 0
while (%gpg.i <= $did(1).lines) {
if ($did(1, %gpg.i).cstate == 1) {
inc %gpg.checkCount
}
inc %gpg.i
}
if (%gpg.checkCount == 0) {
echo -at No key was selected
set %gpg.halt 1
}
else {
set %gpg.i 1
set %gpg.recipients $null
while (%gpg.i <= $did(1).lines) {
if ($did(1, %gpg.i).cstate == 1 || $did(1, %gpg.i).state == 1) {
set %gpg.revitem $rev($did(1, %gpg.i))
set %gpg.emailstart $pos(%gpg.revitem, >, 1)
set %gpg.emailend $pos(%gpg.revitem, <, 1)
set %gpg.recipients %gpg.recipients -r $rev($mid(%gpg.revitem, $calc(%gpg.emailstart + 1), $calc(%gpg.emailend - %gpg.emailstart - 1)))
}
inc %gpg.i
}
}
}
elseif ($did == 6) {
set %gpg.i 1
while (%gpg.i <= $did(1).lines) {
if ($did(6).state == 1) {
did -s spk 1 %gpg.i
}
else {
did -l spk 1 %gpg.i
}
inc %gpg.i
}
}
elseif ($did == 1) {
set %gpg.i 1
set %gpg.checkAll 1
while (%gpg.i <= $did(1).lines) {
if ($did(1, %gpg.i).cstate == 0) {
set %gpg.checkAll 0
}
inc %gpg.i
}
if (%gpg.checkAll == 1) {
did -c spk 6
}
else {
did -u spk 6
}
}
}
dialog selPubKey {
title "Select Public Key"
size -1 -1 250 170
option dbu
edit "", 4, 10 10 190 10
button "Search", 5, 205 8 35 14, default
check "Select/Deselect All", 6, 12 25 100 10
list 1, 10 37 230 100, multsel check result
button "OK", 2, 65 142 50 20, ok %gpg.okbut
button "Cancel", 3, 125 142 50 20, cancel %gpg.cancelbut
}
alias dodel {
if (%gpg.textin. [ $+ [ $1 $+ . [ $+ [ $2 ] ] ] ] == $null) {
runapphidden cmd /c del " $+ $scriptdir $+ gpg\textin\ $+ $1 $+ - $+ $2 $+ .*" /Q
.timergpg $+ . $+ $1 $+ . $+ $2 off
dec %gpg.incount 1
if (%gpg.incount <= 0) {
disable #gpg.capture
}
}
}
#gpg on
on 1:TEXT:-----BEGIN PGP MESSAGE-----:*:{
set -u10 %gpg.textin. [ $+ [ $network $+ . [ $+ [ $nick ] ] ] ] 1
write -c " $+ $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg $+ " $1-
.timergpg $+ . $+ $network $+ . $+ $nick 0 1 dodel $network $nick
.enable #gpg.capture
if (%gpg.incount < 0) {
set %gpg.incount 0
}
inc %gpg.incount 1
}
on 1:TEXT:-----END PGP MESSAGE-----:*:{
if (%gpg.textin. [ $+ [ $network $+ . [ $+ [ $nick ] ] ] ] != $null) {
.timergpg $+ . $+ $network $+ . $+ $nick off
unset %gpg.textin. [ $+ [ $network $+ . [ $+ [ $nick ] ] ] ]
write " $+ $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg $+ " $1-
}
dec %gpg.incount 1
if (%gpg.incount <= 0) {
.disable #gpg.capture
}
if ($chan != $null) {
set %gpg.src $chan
}
else {
set %gpg.src $nick
}
gpgdecrypt $nick %gpg.src $network $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg
}
#gpg end
#gpg.capture off
on 1:TEXT:*:*:{
if ($1 != -----END PGP MESSAGE-----) {
if (%gpg.textin. [ $+ [ $network $+ . [ $+ [ $nick ] ] ] ] != $null) {
set -u10 %gpg.textin. [ $+ [ $network $+ . [ $+ [ $nick ] ] ] ] 1
if ($pos($1-,!,0) > 0) {
write " $+ $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg $+ " $replace($replace($1-,~!,$chr(10)),!,$chr(10))
}
elseif ($pos($1-,~,0) > 0) {
write " $+ $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg $+ " $replace($1-,~,$chr(10))
}
elseif ($1- != ~) {
write " $+ $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg $+ " $1-
}
else {
write " $+ $scriptdir $+ gpg\textin\ $+ $network $+ - $+ $nick $+ .txt.gpg $+ " $chr(13)
}
}
}
}
#gpg.capture end
; Update the IAL
on 1:NOTICE:Your vhost of *:?:{
who $me
}
alias rev {
if ($1) {
set %gpg.c $strip($1-)
set %gpg.a $len(%gpg.c)
while (%gpg.a >= 1) {
set %gpg.b %gpg.b $+ $replace($mid(%gpg.c,%gpg.a,1),$chr(32),$str($chr(32),2))
dec %gpg.a
}
}
set %gpg.o %gpg.b
unset %gpg.a
unset %gpg.b
unset %gpg.c
return %gpg.o
}