View difference between Paste ID: TfNgRUKC and 9tb0RW04
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.")
4-
local thing = ...
4+
5
6
local ecc = require "./ecc"
7
local t = ecc "ecc"
8
9
local thing, UUID_override = ...
10
local function fread(thing)
11
    local f = fs.open(thing, "r")
12
    local text = f.readAll()
13
    f.close()
14
    return text
15
end
16
17
local function hexize(key)
18
    local out = ""
19
    for _, v in pairs(key) do
20
        out = out .. string.format("%.2x", v)
21
    end
22
    return out
23
end
24
25
local function unhexize(key)
26-
local pkey = textutils.unserialise(fread ".potato_rds_priv")
26+
    local out = {}
27
    for i = 1, #key, 2 do
28-
while true do
28+
        local pair = key:sub(i, i + 1)
29-
    local _, side = os.pullEvent "disk"
29+
        table.insert(out, tonumber(pair, 16))
30-
    local mp = disk.getMountPath(side)
30+
31-
    local path = fs.combine(mp, "startup")
31+
32-
    local sig_path = fs.combine(mp, "signature")
32+
33-
    local UUID_path = fs.combine(mp, "UUID")
33+
34-
    local UUID = math.random(0, 1000000)
34+
35-
    print(UUID)
35+
36-
    disk.setLabel(side, thing)
36+
37-
    local text = fread(thing):gsub("@UUID@", tostring(UUID))
37+
38-
    --print(text, path)
38+
39-
    fwrite(path, text)
39+
40-
    print "Written data."
40+
local pkey = unhexize(fread(privkey_path))
41-
    fwrite(sig_path, hexize(t.sign(
41+
42-
        pkey,
42+
local _, side = os.pullEvent "disk"
43-
        text
43+
local mp = disk.getMountPath(side)
44-
    )))
44+
local path = fs.combine(mp, "startup")
45-
    fwrite(UUID_path, tostring(UUID))
45+
local sig_path = fs.combine(mp, "signature")
46-
    print "Written signature."
46+
47-
end
47+
local UUID_path = fs.combine(mp, "UUID")
48
local UUID = ""
49
50
if UUID_override then UUID = UUID_override
51
else
52
	if fs.exists(UUID_path) then UUID = fread(UUID_path)
53
	else
54
		for i = 1, 10 do
55
			UUID = UUID .. string.char(math.random(97, 122))
56
		end
57
	end
58
end
59
60
print("UUID:", UUID)
61
62
disk.setLabel(side, thing)
63
local text = fread(thing):gsub("@UUID@", UUID)
64
65
fwrite(path, text)
66
print "Written data."
67
fwrite(sig_path, hexize(t.sign(
68
    pkey,
69
    text
70
)))
71
fwrite(UUID_path, tostring(UUID))
72
print "Written signature."
73
print("Disk ID:", disk.getID(side))