Advertisement
osmarks

pxsign

Apr 15th, 2020
423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local privkey_path = ".potatos_dsk"
  2. if not fs.exists(privkey_path) then
  3.     error("Please save the potatOS disk signing key (ECC signing key) to " .. privkey_path .. " to use this program.")
  4. end
  5.  
  6. local ecc = require "./ecc" "ecc"
  7.  
  8. local input, output, UUID_override = ...
  9. local function fread(thing)
  10.     local f = fs.open(thing, "r")
  11.     local text = f.readAll()
  12.     f.close()
  13.     return text
  14. end
  15.  
  16. local function hexize(key)
  17.     local out = ""
  18.     for _, v in pairs(key) do
  19.         out = out .. string.format("%.2x", v)
  20.     end
  21.     return out
  22. end
  23.  
  24. local function unhexize(key)
  25.     local out = {}
  26.     for i = 1, #key, 2 do
  27.         local pair = key:sub(i, i + 1)
  28.         table.insert(out, tonumber(pair, 16))
  29.     end
  30.     return out
  31. end
  32.  
  33. local function fwrite(fname, text)
  34.     local f = fs.open(fname, "w")
  35.     f.write(text)
  36.     f.close()
  37. end
  38.  
  39. local pkey = unhexize(fread(privkey_path))
  40.  
  41. local UUID = ""
  42. if UUID_override then UUID = UUID_override
  43. else
  44.     for i = 1, 10 do
  45.         UUID = UUID .. string.char(math.random(97, 122))
  46.     end
  47. end
  48.  
  49. print("UUID:", UUID)
  50.  
  51. local text = fread(input):gsub("@UUID@", UUID)
  52. local signature = hexize(ecc.sign(pkey, text))
  53. local fullcode = ([[---PXSIG:%s
  54. ---PXUUID:%s
  55. %s]]):format(signature, UUID, text)
  56. fwrite(output, fullcode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement