View difference between Paste ID: Bi7aCjQi and TfNgRUKC
SHOW: | | - or go back to the newest paste.
1
local privkey_path = ".potatos_dsk"
2
if not fs.exists(privkey_path) then
3-
	error("Please save the potatOS disk signing key (or alternate table-format ECC signing key) to " .. privkey_path .. " to use this program.")
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"
6+
local ecc = require "./ecc" "ecc"
7-
local t = ecc "ecc"
7+
8
local input, output, UUID_override = ...
9-
local thing, UUID_override = ...
9+
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-
local _, side = os.pullEvent "disk"
42+
43-
local mp = disk.getMountPath(side)
43+
44-
local path = fs.combine(mp, "startup")
44+
	for i = 1, 10 do
45-
local sig_path = fs.combine(mp, "signature")
45+
		UUID = UUID .. string.char(math.random(97, 122))
46
	end
47-
local UUID_path = fs.combine(mp, "UUID")
47+
48
49
print("UUID:", UUID)
50
51
local text = fread(input):gsub("@UUID@", UUID)
52-
	if fs.exists(UUID_path) then UUID = fread(UUID_path)
52+
local signature = hexize(ecc.sign(pkey, text))
53-
	else
53+
local fullcode = ([[---PXSIG:%s
54-
		for i = 1, 10 do
54+
---PXUUID:%s
55-
			UUID = UUID .. string.char(math.random(97, 122))
55+
%s]]):format(signature, UUID, text)
56-
		end
56+
fwrite(output, fullcode)