Fix access modes
This commit is contained in:
parent
bbff98d04b
commit
6d59d9651d
@ -162,31 +162,34 @@ proc {system encryptionkey} {} {{key ""}} {
|
||||
return [system keybytestostring $bytes]
|
||||
}
|
||||
|
||||
proc {system customencryptionkey} {{key ""}} {
|
||||
|
||||
proc open_keyfile {{access r}} {
|
||||
return [open "/mod/boot/cryptokey" $access]
|
||||
}
|
||||
|
||||
proc {system customencryptionkey} {{key ""}} {{keyfile "/mod/boot/cryptokey"}} {
|
||||
set ck_fd {}
|
||||
try {
|
||||
if {$key ne ""} {
|
||||
if {$key eq ""}
|
||||
set ck_fd [open $keyfile r]
|
||||
set ck_bytes [$ck_fd read 16]
|
||||
return [system keybytestostring $ck_bytes]
|
||||
} elseif {[string equal -nocase $key [system encryptionkey]]} {
|
||||
file delete -force $keyfile
|
||||
return $key
|
||||
} else {
|
||||
set ck_bytes [binary format H* $key]
|
||||
set test [system keybytestostring $ck_bytes]
|
||||
if {![string equal -nocase $test $key]} {
|
||||
throw 1 "Invalid custom key"
|
||||
}
|
||||
# attempt not to truncate on update until written
|
||||
set ck_fd [open_keyfile a]
|
||||
if {[file exists $keyfile]} {
|
||||
# attempt not to truncate on update until written
|
||||
set mode r+
|
||||
} else {
|
||||
set mode w
|
||||
}
|
||||
set ck_fd [open $keyfile $mode]
|
||||
$ck_fd seek 0
|
||||
$ck_fd puts -nonewline $ck_bytes
|
||||
$ck_fd close
|
||||
set ck_fd {}
|
||||
return $key
|
||||
} else {
|
||||
set ck_fd [open_keyfile]
|
||||
set ck_bytes [$ck_fd read 16]
|
||||
return [system keybytestostring $ck_bytes]
|
||||
}
|
||||
} on error {msg opts} {
|
||||
return {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user