SHOW:
|
|
- or go back to the newest paste.
1 | local files = { | |
2 | [ "/.lock/bg.nfp" ] = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb44444444\ | |
3 | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4444444444\ | |
4 | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4bbb444444\ | |
5 | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb444b4444\ | |
6 | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb44b4b\ | |
7 | bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb4bbbb\ | |
8 | bbbbbbbbbbbbbbbbbbbbbb0bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ | |
9 | bbbbbbbbbbbbbbbbbbbbb000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ | |
10 | bbbbbbbbbbbbbbbbbbb000000bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ | |
11 | bbbbbbbbbbbbbbbbbb88888888bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\ | |
12 | bbbbbbbbbbbbbbbb88888888888bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00bbbbbbbb\ | |
13 | bbbbbbbbbbbbbbb888888888888bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000bbbbbbb\ | |
14 | bbbbbbbbbbbbb888888888888888bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb080000bbbbbb\ | |
15 | bbbbbbbbbbb888888888888888888bbbbbbbbbbbbbbbbbbbbbbbbbbbbb88888888bbbbb\ | |
16 | bbbbbbbb88888888888888888888888bbbbbbbbbbbbbbbbbbbbbbbbbb8888888888bbbb\ | |
17 | bbbbbb88888888888888888888888888bbbbbbbbbbbbbbbbbbbbbbbbb88888888888bbb\ | |
18 | bbbbb888888888888ddddd88888888888bbbbbbbddddddddddd77ddd8888888888888bb\ | |
19 | dddddddddddddddddddddddddddddddddddddddddddddddddd777dddddddddddddddddd\ | |
20 | dddddddddddddddddddddddddddddddddddddddddddddddddd777dddddddddddddddddd\ | |
21 | dddddddddddddddddddddddddddddddddddddddddddddddd7777ddddddddddddddddddd\ | |
22 | dddddddddddddddddddddddddddddddddddddddddddddd777777ddddddddddddddddddd\ | |
23 | ddddddddddddddddddddddddddddddddddddddddddddd7777777ddddddddddddddddddd\ | |
24 | ddddddddddddddddddddddddddddddddddddddddd7777777777dddddddddddddddddddd\ | |
25 | dddddddddddddddddddddddddddddddddddddddd7777777777ddddddddddddddddddddd\ | |
26 | dddddddddddddddddddddddddddddddddddddd77777777777dddddddddddddddddddddd\ | |
27 | dddddddddddddddddddddddddddddddddddd777777777777ddddddddddddddddddddddd\ | |
28 | ddddddddddddddddddddddddddddddddddd777777777777dddddddddddddddddddddddd", | |
29 | [ "/.lock/lock.lua" ] = "local oldpull = os.pullEvent\ | |
30 | local running = true\ | |
31 | os.pullEvent = os.pullEventRaw\ | |
32 | print(\"Initializing\")\ | |
33 | os.loadAPI(\"/.lock/sha256\")\ | |
34 | local handle = fs.open(\"/.lock/.meta\",\"r\")\ | |
35 | local obj = handle.readAll()\ | |
36 | print(obj)\ | |
37 | handle.close()\ | |
38 | obj = textutils.unserialise(obj)\ | |
39 | function redraw()\ | |
40 | term.setBackgroundColor(colors.black)\ | |
41 | term.setTextColor(colors.white)\ | |
42 | term.clear()\ | |
43 | paintutils.drawImage(paintutils.loadImage(\"/.lock/bg.nfp\"),1,1)\ | |
44 | local msg = \"Welcome back, \" .. obj.id .. \"!\"\ | |
45 | local x,y = term.getSize()\ | |
46 | term.setCursorPos((x-#msg)/2,2)\ | |
47 | term.setTextColor(colors.orange)\ | |
48 | term.setBackgroundColor(colors.black)\ | |
49 | term.write(msg)\ | |
50 | paintutils.drawFilledBox((x-9)/2,4,(x-9)/2+8,10,colors.orange)\ | |
51 | paintutils.drawImage(paintutils.loadImage(\"/.lock/user.nfp\"),(x-7)/2,5)\ | |
52 | --paintutils.drawFilledBox((x-11)/2,12,(x-11)/2+10,12,colors.gray)\ | |
53 | term.setTextColor(colors.black)\ | |
54 | local oldterm = term.current()\ | |
55 | local w = window.create(term.current(),(x-15)/2,12,15,1)\ | |
56 | term.redirect(w)\ | |
57 | term.setBackgroundColor(colors.gray)\ | |
58 | term.clear()\ | |
59 | term.setTextColor(colors.black)\ | |
60 | local pass = read(\"*\")\ | |
61 | term.redirect(oldterm)\ | |
62 | return pass\ | |
63 | end\ | |
64 | function unlock()\ | |
65 | --os.pullEvent = oldpull\ | |
66 | running = false\ | |
67 | term.setBackgroundColor(colors.black)\ | |
68 | term.setTextColor(colors.white)\ | |
69 | local msg = \"Welcome back, \" .. obj.id .. \"!\"\ | |
70 | term.clear()\ | |
71 | local x,y = term.getSize()\ | |
72 | term.setCursorPos((x-#msg)/2,(y-1)/2)\ | |
73 | term.write(msg)\ | |
74 | sleep(1)\ | |
75 | os.pullEvent = oldpull\ | |
76 | term.clear()\ | |
77 | term.setCursorPos(1,1)\ | |
78 | end\ | |
79 | function deny()\ | |
80 | term.setBackgroundColor(colors.black)\ | |
81 | term.setTextColor(colors.white)\ | |
82 | local msg = \"Access denied.\"\ | |
83 | local msg2 = \"Password hint: \" .. obj.hint\ | |
84 | local msg3 = \"Press any key to continue\"\ | |
85 | term.clear()\ | |
86 | local x,y = term.getSize()\ | |
87 | term.setCursorPos((x-#msg)/2,(y-1)/2-1)\ | |
88 | term.write(msg)\ | |
89 | term.setCursorPos((x-#msg2)/2,(y-1)/2)\ | |
90 | term.write(msg2)\ | |
91 | term.setCursorPos((x-#msg3)/2,(y-1)/2+1)\ | |
92 | term.write(msg3)\ | |
93 | os.pullEvent(\"char\")\ | |
94 | term.clear()\ | |
95 | end\ | |
96 | while running == true do\ | |
97 | local inp = sha256.sha256(redraw())\ | |
98 | if inp == obj.password then\ | |
99 | unlock()\ | |
100 | else\ | |
101 | deny()\ | |
102 | end\ | |
103 | end", | |
104 | [ "/.lock/user.nfp" ] = "bbbbbbb\ | |
105 | bdbdbdb\ | |
106 | bddbddb\ | |
107 | bdbdbdb\ | |
108 | bbbbbbb", | |
109 | [ "/.lock/.meta" ] = "{\ | |
110 | password = \"ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb\",\ | |
111 | id = \"Unset\",\ | |
112 | hint = \"a\",\ | |
113 | }", | |
114 | [ "/.lock/set.lua" ] = "os.loadAPI(\"/.lock/sha256\")\ | |
115 | print(\"Specify user identifier\")\ | |
116 | local identifier = read()\ | |
117 | print(\"Specify new password\")\ | |
118 | local password = read(\"*\")\ | |
119 | print(\"Confirm password\")\ | |
120 | local cpass = read(\"*\")\ | |
121 | print(\"Password hint\")\ | |
122 | local hint = read()\ | |
123 | if password ~= cpass then\ | |
124 | error(\"Passwords dont match!\")\ | |
125 | else\ | |
126 | print(\"Writing to file...\")\ | |
127 | local handle = fs.open(\"/.lock/.meta\",\"w\")\ | |
128 | local object = {}\ | |
129 | object[\"password\"] = sha256.sha256(password)\ | |
130 | object[\"hint\"] = hint\ | |
131 | object[\"id\"] = identifier\ | |
132 | handle.write(textutils.serialise(object))\ | |
133 | handle.close()\ | |
134 | end\ | |
135 | print(\"Done\")\ | |
136 | ", | |
137 | [ "/.lock/sha256" ] = "\ | |
138 | -- \ | |
139 | -- Adaptation of the Secure Hashing Algorithm (SHA-244/256)\ | |
140 | -- Found Here: http://lua-users.org/wiki/SecureHashAlgorithm\ | |
141 | -- \ | |
142 | -- Using an adapted version of the bit library\ | |
143 | -- Found Here: https://bitbucket.org/Boolsheet/bslf/src/1ee664885805/bit.lua\ | |
144 | -- \ | |
145 | \ | |
146 | local MOD = 2^32\ | |
147 | local MODM = MOD-1\ | |
148 | \ | |
149 | local function memoize(f)\ | |
150 | local mt = {}\ | |
151 | local t = setmetatable({}, mt)\ | |
152 | function mt:__index(k)\ | |
153 | local v = f(k)\ | |
154 | t[k] = v\ | |
155 | return v\ | |
156 | end\ | |
157 | return t\ | |
158 | end\ | |
159 | \ | |
160 | local function make_bitop_uncached(t, m)\ | |
161 | local function bitop(a, b)\ | |
162 | local res,p = 0,1\ | |
163 | while a ~= 0 and b ~= 0 do\ | |
164 | local am, bm = a % m, b % m\ | |
165 | res = res + t[am][bm] * p\ | |
166 | a = (a - am) / m\ | |
167 | b = (b - bm) / m\ | |
168 | p = p*m\ | |
169 | end\ | |
170 | res = res + (a + b) * p\ | |
171 | return res\ | |
172 | end\ | |
173 | return bitop\ | |
174 | end\ | |
175 | \ | |
176 | local function make_bitop(t)\ | |
177 | local op1 = make_bitop_uncached(t,2^1)\ | |
178 | local op2 = memoize(function(a) return memoize(function(b) return op1(a, b) end) end)\ | |
179 | return make_bitop_uncached(op2, 2 ^ (t.n or 1))\ | |
180 | end\ | |
181 | \ | |
182 | local bxor1 = make_bitop({[0] = {[0] = 0,[1] = 1}, [1] = {[0] = 1, [1] = 0}, n = 4})\ | |
183 | \ | |
184 | local function bxor(a, b, c, ...)\ | |
185 | local z = nil\ | |
186 | if b then\ | |
187 | a = a % MOD\ | |
188 | b = b % MOD\ | |
189 | z = bxor1(a, b)\ | |
190 | if c then z = bxor(z, c, ...) end\ | |
191 | return z\ | |
192 | elseif a then return a % MOD\ | |
193 | else return 0 end\ | |
194 | end\ | |
195 | \ | |
196 | local function band(a, b, c, ...)\ | |
197 | local z\ | |
198 | if b then\ | |
199 | a = a % MOD\ | |
200 | b = b % MOD\ | |
201 | z = ((a + b) - bxor1(a,b)) / 2\ | |
202 | if c then z = bit32_band(z, c, ...) end\ | |
203 | return z\ | |
204 | elseif a then return a % MOD\ | |
205 | else return MODM end\ | |
206 | end\ | |
207 | \ | |
208 | local function bnot(x) return (-1 - x) % MOD end\ | |
209 | \ | |
210 | local function rshift1(a, disp)\ | |
211 | if disp < 0 then return lshift(a,-disp) end\ | |
212 | return math.floor(a % 2 ^ 32 / 2 ^ disp)\ | |
213 | end\ | |
214 | \ | |
215 | local function rshift(x, disp)\ | |
216 | if disp > 31 or disp < -31 then return 0 end\ | |
217 | return rshift1(x % MOD, disp)\ | |
218 | end\ | |
219 | \ | |
220 | local function lshift(a, disp)\ | |
221 | if disp < 0 then return rshift(a,-disp) end \ | |
222 | return (a * 2 ^ disp) % 2 ^ 32\ | |
223 | end\ | |
224 | \ | |
225 | local function rrotate(x, disp)\ | |
226 | x = x % MOD\ | |
227 | disp = disp % 32\ | |
228 | local low = band(x, 2 ^ disp - 1)\ | |
229 | return rshift(x, disp) + lshift(low, 32 - disp)\ | |
230 | end\ | |
231 | \ | |
232 | local k = {\ | |
233 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,\ | |
234 | 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,\ | |
235 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,\ | |
236 | 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,\ | |
237 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,\ | |
238 | 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,\ | |
239 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,\ | |
240 | 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,\ | |
241 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,\ | |
242 | 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,\ | |
243 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,\ | |
244 | 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,\ | |
245 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,\ | |
246 | 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,\ | |
247 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,\ | |
248 | 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,\ | |
249 | }\ | |
250 | \ | |
251 | local function str2hexa(s)\ | |
252 | return (string.gsub(s, \".\", function(c) return string.format(\"%02x\", string.byte(c)) end))\ | |
253 | end\ | |
254 | \ | |
255 | local function num2s(l, n)\ | |
256 | local s = \"\"\ | |
257 | for i = 1, n do\ | |
258 | local rem = l % 256\ | |
259 | s = string.char(rem) .. s\ | |
260 | l = (l - rem) / 256\ | |
261 | end\ | |
262 | return s\ | |
263 | end\ | |
264 | \ | |
265 | local function s232num(s, i)\ | |
266 | local n = 0\ | |
267 | for i = i, i + 3 do n = n*256 + string.byte(s, i) end\ | |
268 | return n\ | |
269 | end\ | |
270 | \ | |
271 | local function preproc(msg, len)\ | |
272 | local extra = 64 - ((len + 9) % 64)\ | |
273 | len = num2s(8 * len, 8)\ | |
274 | msg = msg .. \"\\128\" .. string.rep(\"\\0\", extra) .. len\ | |
275 | assert(#msg % 64 == 0)\ | |
276 | return msg\ | |
277 | end\ | |
278 | \ | |
279 | local function initH256(H)\ | |
280 | H[1] = 0x6a09e667\ | |
281 | H[2] = 0xbb67ae85\ | |
282 | H[3] = 0x3c6ef372\ | |
283 | H[4] = 0xa54ff53a\ | |
284 | H[5] = 0x510e527f\ | |
285 | H[6] = 0x9b05688c\ | |
286 | H[7] = 0x1f83d9ab\ | |
287 | H[8] = 0x5be0cd19\ | |
288 | return H\ | |
289 | end\ | |
290 | \ | |
291 | local function digestblock(msg, i, H)\ | |
292 | local w = {}\ | |
293 | for j = 1, 16 do w[j] = s232num(msg, i + (j - 1)*4) end\ | |
294 | for j = 17, 64 do\ | |
295 | local v = w[j - 15]\ | |
296 | local s0 = bxor(rrotate(v, 7), rrotate(v, 18), rshift(v, 3))\ | |
297 | v = w[j - 2]\ | |
298 | w[j] = w[j - 16] + s0 + w[j - 7] + bxor(rrotate(v, 17), rrotate(v, 19), rshift(v, 10))\ | |
299 | end\ | |
300 | \ | |
301 | local a, b, c, d, e, f, g, h = H[1], H[2], H[3], H[4], H[5], H[6], H[7], H[8]\ | |
302 | for i = 1, 64 do\ | |
303 | local s0 = bxor(rrotate(a, 2), rrotate(a, 13), rrotate(a, 22))\ | |
304 | local maj = bxor(band(a, b), band(a, c), band(b, c))\ | |
305 | local t2 = s0 + maj\ | |
306 | local s1 = bxor(rrotate(e, 6), rrotate(e, 11), rrotate(e, 25))\ | |
307 | local ch = bxor (band(e, f), band(bnot(e), g))\ | |
308 | local t1 = h + s1 + ch + k[i] + w[i]\ | |
309 | h, g, f, e, d, c, b, a = g, f, e, d + t1, c, b, a, t1 + t2\ | |
310 | end\ | |
311 | \ | |
312 | H[1] = band(H[1] + a)\ | |
313 | H[2] = band(H[2] + b)\ | |
314 | H[3] = band(H[3] + c)\ | |
315 | H[4] = band(H[4] + d)\ | |
316 | H[5] = band(H[5] + e)\ | |
317 | H[6] = band(H[6] + f)\ | |
318 | H[7] = band(H[7] + g)\ | |
319 | H[8] = band(H[8] + h)\ | |
320 | end\ | |
321 | \ | |
322 | function sha256(msg)\ | |
323 | msg = preproc(msg, #msg)\ | |
324 | local H = initH256({})\ | |
325 | for i = 1, #msg, 64 do digestblock(msg, i, H) end\ | |
326 | return str2hexa(num2s(H[1], 4) .. num2s(H[2], 4) .. num2s(H[3], 4) .. num2s(H[4], 4) ..\ | |
327 | num2s(H[5], 4) .. num2s(H[6], 4) .. num2s(H[7], 4) .. num2s(H[8], 4))\ | |
328 | end", | |
329 | } | |
330 | print("Welcome to RphLock setup") | |
331 | print("Are you sure you want to install? \nTHIS WILL OVERWRITE YOUR STARTUP AND REMOVE ALL FILES YOU MAY HAVE IN .lock") | |
332 | print("[Y/n]") | |
333 | local choice = string.lower(read()) | |
334 | if choice ~= "y" then | |
335 | error("Installation aborted") | |
336 | end | |
337 | print("Ok") | |
338 | if fs.exists("/.lock/") then | |
339 | fs.delete("/.lock/") | |
340 | end | |
341 | if fs.exists("startup") then | |
342 | fs.delete("startup") | |
343 | end | |
344 | if fs.exists("startup.lua") then | |
345 | fs.delete("startup.lua") | |
346 | end | |
347 | print("Installing files") | |
348 | fs.makeDir("/.lock") | |
349 | for k,v in pairs(files) do | |
350 | local handle = fs.open(k,"w") | |
351 | handle.write(v) | |
352 | handle.close() | |
353 | print(k) | |
354 | end | |
355 | print("Please set your password. If you cancel, the default password is \"a\"") | |
356 | shell.run("/.lock/set.lua") | |
357 | print("Thanks") | |
358 | print("Installing startup") | |
359 | local handle = fs.open("startup.lua","w") | |
360 | handle.write("shell.run(\"/.lock/lock.lua\")") | |
361 | handle.close() | |
362 | print("Done!") | |
363 | print("Run /.lock/set.lua to change your password") |