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