Fix autokey generation
This commit is contained in:
parent
39345d9b99
commit
e6d0670714
|
@ -201,15 +201,18 @@ def chroot(path,cmd,*args,**kwargs):
|
|||
pass
|
||||
raise e
|
||||
|
||||
def randhex(length):
|
||||
chars = "0123456789ABCDEF"
|
||||
def randomString(length,chars):
|
||||
charsLength = len(chars)
|
||||
output = ""
|
||||
cLength = 0
|
||||
while cLength < length:
|
||||
output = output + chars[random.randrange(0,15)]
|
||||
cLength += 1
|
||||
index = 0
|
||||
while index < length:
|
||||
output = output + chars[random.randrange(0,charsLength)]
|
||||
index += 1
|
||||
return output
|
||||
|
||||
def randomHex(length):
|
||||
return randomString(length,"0123456789ABCDEF")
|
||||
|
||||
def debconfSetSelections(root,options):
|
||||
proc = subprocess.Popen(["chroot",root,"debconf-set-selections"],stdin=subprocess.PIPE)
|
||||
proc.stdin.write((options + "\n").encode("utf-8"))
|
||||
|
@ -369,7 +372,7 @@ def main():
|
|||
call(["unsquashfs","-f","-d",ipth(),"/lib/live/mount/medium/live/filesystem.squashfs"])
|
||||
|
||||
print("Setting hostname ...")
|
||||
hostname = randhex(8)
|
||||
hostname = randomHex(8)
|
||||
fh = open(ipth("etc/hostname"),"w")
|
||||
fh.write(hostname + "\n")
|
||||
fh.close()
|
||||
|
@ -382,12 +385,14 @@ def main():
|
|||
fh.close()
|
||||
|
||||
print("Writing luks auto-key ...")
|
||||
key = callString(["xxd","-l","64","-c","0","-ps","/dev/random"])
|
||||
fh = open(ipth(".luks-key"),"w")
|
||||
fh.write(key)
|
||||
fh.write(randomString(64,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"))
|
||||
fh.close()
|
||||
os.chmod(ipth(".luks-key"),600)
|
||||
call(["cryptosetup","luksAddKey",cryptPartition,ipth(".luks-key")])
|
||||
proc = subprocess.Popen(["cryptsetup","luksAddKey",ipth(".luks-key")],stdin=subprocess.PIPE)
|
||||
proc.stdin.write((mainPass + "\n").encode("utf-8"))
|
||||
proc.stdin.flush()
|
||||
checkProc(proc)
|
||||
|
||||
print("Writing crypttab ...")
|
||||
fh = open(ipth("etc/crypttab"),"w")
|
||||
|
|
Loading…
Reference in New Issue