-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwot.lsp.template
executable file
·502 lines (501 loc) · 20.4 KB
/
wot.lsp.template
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#!___NEWLISPPATH___
(context (quote wot))
(set (quote TEMPDIR) "___KEYRINGDIRPATH___/tempdir")
(set (quote MKTEMP) "___MKTEMPPATH___")
(set (quote MYSQLACCESSFILE) "___KEYRINGDIRPATH___/readonly")
(set (quote PASSPHRASEFILE) "___KEYRINGDIRPATH___/gpgpassphrase")
;(set (quote SECPUBKEYRING) "___KEYRINGDIRPATH___/secpubring.gpg")
(set (quote SECSECKEYRING) "___KEYRINGDIRPATH___/secsecring.gpg")
(set (quote SECTRUSTDB) "___KEYRINGDIRPATH___/sectrustdb.gpg")
(set (quote PUBPUBKEYRING) "___KEYRINGDIRPATH___/pubpubring.gpg")
(set (quote PUBSECKEYRING) "___KEYRINGDIRPATH___/pubsecring.gpg")
(set (quote PUBTRUSTDB) "___KEYRINGDIRPATH___/pubtrustdb.gpg")
(if (!= (env "REQUEST_METHOD") nil)
(load "___NEWLISPMODULESPATH___/cgi.lsp")
)
(load "___NEWLISPMODULESPATH___/mysql.lsp")
(load "___NEWLISPMODULESPATH___/crypto.lsp")
(load "___CGIBINPATH___/wotlocal.lsp")
; just about any character is allowd in email address. Just needs
; a single @, 64 byte first part, 255 byte second part.
; To send into gpg, single-quote it to prevent shell escape.
(set (quote checkemailaddress)
(lambda (emailaddress)
(begin
(if (> (length emailaddress) 320)
(begin
(CGI:put-page "invalidemail.html")
(exit)
)
)
(set (quote partlist) (parse emailaddress "@"))
(if (> (length partlist) 2)
(begin
(CGI:put-page "invalidemail.html")
(exit)
)
)
(if (or (> (length (first partlist)) 64) (> (length (last partlist)) 255))
(begin
(CGI:put-page "invalidemail.html")
(exit)
)
)
)
)
)
(set (quote checkkey)
(lambda (targetkey "")
(begin
(if (regex "[^-a-zA-Z0-9/=+\n\s]+" targetkey)
(throw nil)
(throw true)
)
)
)
)
(set (quote runit)
(lambda (runstring inputstring timeout)
(begin
;(println runstring)
;(println inputstring)
(map set (quote (myin childout)) (pipe))
(map set (quote (childin myout)) (pipe))
(map set (quote (myerrin childerrout)) (pipe))
(set (quote childpid) (process runstring childin childout childerrout))
(if (string? inputstring)
(begin
(set (quote byteswritten) (write-line myout inputstring))
)
)
(close myout)
(close childin)
(set (quote childoutput) "")
(set (quote childerror) "")
(set (quote waits) 0)
(set (quote returnpid) 0)
(while (and (= returnpid 0) (< waits timeout))
(begin
(if (> (peek myerrin) 0)
(begin
(read myerrin myerrinbuffer (peek myerrin))
(set (quote childerror) (append childerror myerrinbuffer))
)
)
(if (> (peek myin) 0)
(begin
(read myin myinbuffer (peek myin))
(set (quote childoutput) (append childoutput myinbuffer))
)
)
(set (quote pidreturnlist) (wait-pid childpid nil))
(set (quote returnpid) (nth 0 pidreturnlist))
(sleep 1000)
(set (quote waits) (+ waits 1))
)
)
(if (= returnpid 0)
(begin
(print "timed out!\n")
(destroy childpid)
)
)
(throw (list (>> (nth 1 pidreturnlist) 8) childoutput childerror))
)
)
)
(set (quote trustkey)
(lambda ((keytotrust ""))
(begin
; get long key id
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --fixed-list-mode --with-fingerprint --with-fingerprint --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --with-colons --keyring " PUBPUBKEYRING " --secret-keyring " PUBSECKEYRING " --trustdb-name " PUBTRUSTDB " --list-keys '" keytotrust "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(set (quote keyidlist) (list))
(set (quote keyid) nil)
(dolist (x (find-all {pub:\S:\d+:\d:([a-zA-Z0-9]{16}):\d\d\d\d-\d\d-\d\d} (nth 1 runitlist) $1))
(begin
(set (quote keyid) x)
(set (quote keyidlist) (append keyidlist (list keyid)))
)
)
(dolist (x keyidlist)
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --with-colons --keyring " PUBPUBKEYRING " --secret-keyring " PUBSECKEYRING " --trustdb-name " PUBTRUSTDB " --trusted-key '" x "' --update-trustdb"))
(set (quote runitlist) (catch (runit runstring nil 20)))
)
)
)
)
(set (quote signkey)
(lambda ((sponsorkey "") (applicantkey ""))
(begin
(if (!= sponsorkey applicantkey)
(begin
(set (quote runstring) (string "___KEYRINGDIRPATH___/tsign.exp '" sponsorkey "' '" applicantkey "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
; need to update pubtrustdb
(checktrustdb)
)
)
)
)
)
(set (quote checktrustdb)
(lambda ((pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --check-trustdb" ))
(set (quote runitlist) (catch (runit runstring nil 20)))
(throw runitlist)
)
)
)
(set (quote gentestkey)
(lambda ((pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote runstring) (string "___GPG2PATH___ --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --quick-gen-key [email protected]" ))
(set (quote runitlist) (catch (runit runstring nil 20)))
(throw runitlist)
)
)
)
(set (quote listkeys)
(lambda ((userid "") (pubring PUBPUBKEYRING) (secring SECSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --fixed-list-mode --with-fingerprint --with-fingerprint --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --list-keys '" userid "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(throw runitlist)
)
)
)
(set (quote importkey)
(lambda ((keyfile "") (pubring PUBPUBKEYRING) (secring SECSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --import " keyfile))
(set (quote runitlist) (catch (runit runstring nil 20)))
(throw runitlist)
)
)
)
(set (quote exportkey)
(lambda ((targetemail "") (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote runstring) (string MKTEMP " --tmpdir=" TEMPDIR))
(set (quote keyfile) (trim (nth 1 (catch (runit runstring nil 20)))))
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --yes --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --output " keyfile " --export '" targetemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(throw keyfile)
)
)
)
(set (quote delsig)
(lambda ((sponsorkey "") (applicantkey ""))
(begin
(set (quote runstring) (string "___KEYRINGDIRPATH___/revsig.exp '" sponsorkey "' '" applicantkey "'"))
(print "runstring (" runstring ")\n")
(set (quote runitlist) (catch (runit runstring nil 20)))
(print " runitlist (" runitlist ")\n")
)
)
)
(set (quote untrustkey)
(lambda ((targetkey "") )
(begin
(set (quote runstring) (string "___KEYRINGDIRPATH___/untrustkey.exp '" targetkey "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
)
)
)
(set (quote listormakekey)
(lambda ((testemail "") (makeit nil) (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote keyidlist) (list))
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --fixed-list-mode --with-fingerprint --with-fingerprint --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --list-keys '" testemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(write-file "t.out" (nth 1 runitlist))
(replace "<" (nth 1 runitlist) "<")
(replace ">" (nth 1 runitlist) ">")
;(print "list-keys: <pre>" runitlist "</pre>")
(set (quote keyfound) nil)
(dolist (x (find-all (string "uid:.*(" testemail ").*") (nth 1 runitlist) $1 ))
(set (quote keyfound) x)
)
(if (= keyfound nil)
(begin
(if (!= makeit true)
(begin
(set (quote keyidlist) (list ()))
)
(begin
;(print "not found, generating keypair for " testemail "<br>\n")
(set (quote gpgrunstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --no-default-keyring --passphrase-file " PASSPHRASEFILE " --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --gen-key"))
(set (quote gkeyinput) (string [text]Key-Type: RSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: WOT Admin
Name-Comment: WOT Signer
Name-Email: [/text] testemail "\n"
[text]Expire-Date: 0
%commit
%echo done
%exit
%done
%quit
missingcolonexit
[/text])
)
(set (quote runitlist) (catch (runit gpgrunstring gkeyinput 300)))
(set (quote keyid) nil)
(dolist (x (find-all {\ngpg: key (\S+) marked} (nth 2 runitlist) $1))
(begin
(set (quote keyid) x)
; trust newly made keys, since untrusted users will already
; have a key, so should not get here
(set (quote keyidlist) (append keyidlist (list keyid)))
)
)
; check to make sure sponsor key got generated
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --fixed-list-mode --with-fingerprint --with-fingerprint --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " PUBPUBKEYRING " --secret-keyring " PUBSECKEYRING " --trustdb-name " PUBTRUSTDB " --list-keys '" testemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(set (quote keyfound) nil)
(dolist (x (find-all (string "uid:.*(" testemail ").*") (nth 1 runitlist) $1 ))
(set (quote keyfound) x)
)
(if (= keyfound nil)
(begin
(CGI:put-page "failsponsorkey.html")
(exit)
)
)
)
)
)
(begin
; returned 0, so we found at least one key
(set (quote keyid) nil)
(dolist (x (find-all {pub:\S:\d+:\d:([a-zA-Z0-9]{16}):\d+:} (nth 1 runitlist) $1))
(begin
(set (quote keyid) x)
(set (quote keyidlist) (append keyidlist (list keyid)))
)
)
)
)
(throw keyidlist)
)
)
)
(set (quote makekey)
(lambda ((testemail "") (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote keyidlist) (list))
(set (quote gpgrunstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --no-default-keyring --passphrase-file " PASSPHRASEFILE " --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --gen-key"))
(print "gpgrunstring (" gpgrunstring ")\n")
(set (quote gkeyinput) (string [text]Key-Type: RSA
Key-Length: 1024
Subkey-Type: ELG-E
Subkey-Length: 1024
Name-Real: WOT Admin
Name-Comment: WOT Signer
Name-Email: [/text] testemail "\n"
[text]Expire-Date: 0
%commit
%echo done
%exit
%done
%quit
missingcolonexit
[/text])
)
(print "gkeyinput (" gkeyinput ")\n")
(set (quote runitlist) (catch (runit gpgrunstring gkeyinput 300)))
(print "output (" runitlist ")\n")
(set (quote keyid) nil)
(dolist (x (find-all {\ngpg: key (\S+) marked} (nth 2 runitlist) $1))
(begin
(set (quote keyid) x)
; trust newly made keys, since untrusted users will already
; have a key, so should not get here
(set (quote keyidlist) (append keyidlist (list keyid)))
)
)
; check to make sure sponsor key got generated
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --fixed-list-mode --with-fingerprint --with-fingerprint --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " PUBPUBKEYRING " --secret-keyring " PUBSECKEYRING " --trustdb-name " PUBTRUSTDB " --list-keys '" testemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(set (quote keyfound) nil)
(dolist (x (find-all (string "uid:.*(" testemail ").*") (nth 1 runitlist) $1 ))
(set (quote keyfound) x)
)
(if (= keyfound nil)
(begin
(CGI:put-page "failsponsorkey.html")
(exit)
)
(begin
(throw keyidlist)
)
)
)
)
)
(set (quote listkeys)
(lambda ((testemail "") (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(set (quote keyidlist) (list))
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --fixed-list-mode --with-fingerprint --with-fingerprint --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --list-keys '" testemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(write-file "t.out" (nth 1 runitlist))
(replace "<" (nth 1 runitlist) "<")
(replace ">" (nth 1 runitlist) ">")
(set (quote keyfound) nil)
(dolist (x (find-all (string "uid:.*(" testemail ").*") (nth 1 runitlist) $1 ))
(set (quote keyfound) x)
)
(if (!= keyfound nil)
(begin
; returned 0, so we found at least one key
(set (quote keyid) nil)
(dolist (x (find-all {pub:\S:\d+:\d:([a-zA-Z0-9]{16}):\d+:} (nth 1 runitlist) $1))
(begin
(set (quote keyid) x)
(set (quote keyidlist) (append keyidlist (list keyid)))
)
)
)
)
(throw keyidlist)
)
)
)
(set (quote checktrust)
(lambda ((testemail "") (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(if (empty? testemail) (throw (list nil (list))) )
(set (quote trustfound) nil)
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " PUBPUBKEYRING " --secret-keyring " PUBSECKEYRING " --trustdb-name " PUBTRUSTDB " --check-sigs '" testemail "'"))
;(print "<pre>\n")
;(print "runstring (" runstring ")\n")
;(print "</pre>\n")
(set (quote runitlist) (catch (runit runstring nil 20)))
(set (quote trustfound) nil)
;(print "lines: (" (nth 1 runitlist) ")\n")
(setq signerslist (list))
(dolist (x (find-all {\npub:(\S)} (nth 1 runitlist) $1))
(begin
(if (ref x (quote ("f" "u")))
(begin
(set (quote trustfound) x)
)
(begin
;(print "not f or u in (" x ")\n")
)
)
)
)
;(dolist (x (find-all {\nsig:\S*:\S*:\S*:\S*:\S*:\S*:.*:\S*:(.*):\S+:} (nth 1 runitlist) $1))
(dolist (x (find-all {\nsig:\S*:\S*:\S*:\S*:\S*:\S*:.*:\S*:(.*):\S+:\S*:\S*:\S*:\S*:\S*:} (nth 1 runitlist) $1))
(begin
(if (find testemail x)
(begin
; can't self-sponsor
)
(begin
;(print "sponsored by: " x "\n")
(push x signerslist)
)
)
)
)
(throw (list trustfound signerslist))
)
)
)
(set (quote getsiginfo)
(lambda ((testemail "") (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(if (empty? testemail) (throw nil))
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --check-sigs '" testemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(throw (nth 1 runitlist))
)
)
)
(set (quote getsigkeypairs)
(lambda ((sponsoremail "") (applicantemail "") (pubring PUBPUBKEYRING) (secring PUBSECRING) (trustdb PUBTRUSTDB))
(begin
(if (or (empty? sponsoremail) (empty? applicantemail)) (throw nil))
(set (quote runstring) (string "___GPGPATH___ --homedir ___KEYRINGDIRPATH___ --debug-level 8 --batch --no-default-keyring --no-auto-key-locate --with-colons --keyring " pubring " --secret-keyring " secring " --trustdb-name " trustdb " --check-sigs '" applicantemail "'"))
(set (quote runitlist) (catch (runit runstring nil 20)))
(set (quote returnlist) (list))
(set (quote regexstring) (string "^(.*)$"))
(set (quote pubkeyid) nil)
(set (quote sigkeyid) nil)
(set (quote teststring) (copy (nth 1 runitlist)))
(replace "<" teststring "<")
(replace ">" teststring ">")
(dolist (linetext (find-all regexstring (nth 1 runitlist) $1 "m"))
(replace "<" linetext "<")
(replace ">" linetext ">")
(set (quote pubsubstring) (string "^(pub|sub):\\S:\\d+:\\d+:([a-zA-Z0-9]{16}):.*$"))
;(println "pubstring: >" pubstring "<br>\n")
(set (quote sigstring) (string "^sig:\\S::\\d+:([a-zA-Z0-9]{16}):.*" sponsoremail ".*$"))
;(println "linetext: >" linetext "<<br>\n")
(set (quote foundpub) (regex pubsubstring linetext))
(if (!= foundpub nil)
(begin
;(println "foundpub: >" foundpub "<<br>\n")
(set (quote pubkeyid) (nth 6 foundpub))
)
;(begin
; (println "foundpub is nil <br>\n")
;)
)
(set (quote foundsig) (regex sigstring linetext))
(if (and (!= foundsig nil) (!= pubkeyid (nth 3 foundsig)))
(begin
(set (quote sigkeyid) (nth 3 foundsig))
(set (quote returnlist) (append returnlist (list (list pubkeyid sigkeyid))))
(set (quote foundsig) nil)
)
)
)
(throw returnlist)
)
)
)
(set (quote verifypassword)
(lambda ((sponsoremail "[email protected]") (userpassword "userpassword"))
(begin
;(println "(trim userpassword) >" (trim userpassword) "<<br>\n")
(set (quote usermd5password) (crypto:md5 (trim userpassword)))
;(println "usermd5password >" usermd5password "<<br>\n")
(set (quote passwordverified) nil)
(if (= "___EMAILPWQUERY___" "mysql")
(set (quote emailpwquery) wotlocal:getemailpwsmysql)
(set (quote emailpwquery) wotlocal:getemailpwstextfile)
)
(map
(lambda (x)
(begin
;(print x "<br>")
(if (= (nth 1 x) usermd5password)
(begin
;(print (nth 1 x) " matches " usermd5password " <br>")
(set (quote passwordverified) true)
)
(begin
;(print (nth 1 x) " does not match " usermd5password " <br>")
)
)
)
)
(catch (emailpwquery sponsoremail))
)
(if (not passwordverified)
(begin
(CGI:put-page "unpass.html")
(exit)
)
)
)
)
)