Advertisement
Redxone

[CC - ID System] - Secure ID System WIP

Jan 14th, 2017
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. --
  2. -- encrypt( securekey(hash) - keyhere, securesalt(hash) - salthere)
  3. --
  4. -- 1. Recieve on random stonefruit channel (gained from ecnrypted server request encrypted then appended with encrypted salt)
  5. -- 2. Retreived channel will be send back encrypted with retrievers id
  6. -- 3. unencrypted the client uses this new channel to communicate with the server
  7. -- 3. the client requests a session, a random id is generated if it isnt in use (session table)
  8. -- 4. ID is then encrypted with clients id, then sent to the client
  9. -- 5. clients new requests must be met with a session id as the clients id is stored in a table
  10. --
  11.  
  12.  
  13. function setupModem()
  14.     return peripheral.find("modem")
  15. end
  16.  
  17. function getSession(modem,key)
  18.     -- Send rednet signal to server
  19.     local sessionid = 0
  20.     rednet.broadcast("stone-freq",{type="auth",data.encrypt(key,os.getComputerID())})
  21.     local sid, mes = rednet.receive("3")
  22.     local mes = data.decrypt(mes,os.getComputerID())
  23.     if(type(mes)=="table")then
  24.         if(mes.auth == true)then
  25.             -- Get random channel from server
  26.             modem.open(auth.channel)
  27.             local _, _, senderChannel, replyChannel, message, _ = os.pullEvent("modem_message")
  28.             if(senderChannel == auth.channnel and replyChannel == auth.channel)then
  29.                 local sessionid = message.session
  30.             end
  31.         end
  32.     elseif(mes ~= nil)then
  33.         error("Possible Rednet interference detected, please contact StoneFruit! ".."\nInterference ID: " .. sid)
  34.     else
  35.         return 0
  36.     end
  37. end
  38.  
  39.  
  40. -- Generate keys based on unique id's then store those ID's in a file to be compared,
  41. -- Send the key out encrypted, then have the server decrypt the key,
  42. -- Compare the decrypted ID with the register ID's if it matches then GG.
  43.  
  44. function decryptKey(key,cid,securekey,securesalt)
  45.     return data.decrypt(data.decrypt(data.decrypt(key,securekey),securesalt),cid)
  46. end
  47.  
  48. function generateKey(cid,uid,securekey,securesalt)
  49.     return data.encrypt(data.encrypt(data.encrypt(uid,securekey),securesalt),cid)
  50. end
  51.  
  52.  
  53. function generateSession(uid,cid,auth,securekey,securesalt)
  54.     -- Check key based on decoded security key
  55.     local compses = {
  56.         [cid] = {
  57.             sesid = uid,
  58.             ses = data.encrypt(data.encrypt(data.encrypt(cid, securekey),uid),securesalt),
  59.         }
  60.     }
  61.     return compses
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement