Advertisement
osmarks

turtl

Sep 3rd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local function a(b,c)local d=fs.open(b,"w")d.write(c)d.close()end;local function e(b)local d=fs.open(b,"r")local c=d.readAll()d.close()return c end;local function f(g)local h=http.get(g)local c=h.readAll()h.close()return c end;local function i(g,d)a(d,f(g))end;i("https://pastebin.com/raw/Sc0DU3rA","ecc.lua");i("https://raw.githubusercontent.com/osmarks/skynet/master/client.lua","skynet.lua")
  2.  
  3. local channel = ... or "turtl"
  4.  
  5. local skynet = require "./skynet"
  6.  
  7. local ecc = require "./ecc"
  8. local e = ecc "ecc"
  9.  
  10. local pub_file = "/.nd_pub"
  11. local pub
  12.  
  13. if not fs.exists(pub_file) then
  14.     error "No public key file - should be saved to .nd_pub"
  15. else
  16.     local f
  17.     f = fs.open(pub_file, "r")
  18.     pub = textutils.unserialize(f.readAll())
  19.     f.close()
  20. end
  21.  
  22. local function verif(data, sig)
  23.     local ok, res = pcall(e.verify, pub, data, sig)
  24.     return ok and res
  25. end
  26.  
  27. while true do
  28.     local chan, msg = skynet.receive(channel)
  29.     if type(msg) == "table" and msg.code and msg.signature and verif(msg.code, msg.signature) then
  30.         print("Executing ", msg.code)
  31.         local func, err = load(msg.code)
  32.         local reply
  33.         if err then
  34.             reply = { false, err }
  35.         else
  36.             reply = { pcall(func) }
  37.         end
  38.         skynet.send(chan, { result = reply })
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement