diff --git a/webif/lib/ts.class b/webif/lib/ts.class index 34087cf..68817ca 100644 --- a/webif/lib/ts.class +++ b/webif/lib/ts.class @@ -2,6 +2,7 @@ if {![exists -proc class]} { package require oo } if {![exists -proc pack]} { package require pack } if {![exists -proc xconv]} { package require xconv } +if {![exists -proc binary]} { package require binary } source /mod/webif/lib/setup require system.class tvdb.class classdump @@ -829,3 +830,41 @@ proc {ts genrelist} {} { return $glist } +# return the key that will decrypt the file in the mode, or nothing +ts method getkey {mode} { + # mode: dlna (active key), direct + + set rfile [file rootname $file] + + # the active key + set keys = {} + set key [string range [system nugget cryptokey -key] 0 31] + if {$key ne ""} { + lappend keys $key + } + if { mode ne "dlna" } { + # also try other keys, such as the native key + if {![catch {set fd [open "/mod/boot/cryptokey"]}]} { + set bytes [$fd read 16] + $fd close + binary scan $bytes H* key + if {[string length $key] == 32} { + if {$key ni $keys} { + lappend keys $key + } + } + } + set key [system encryptionkey] + if {$key ni $keys} { + lappend keys $key + } + } + + foreach key $keys { + if {[catch { + set ret [exec /mod/bin/stripts -q/ $key $rfile] + }]} continue + if {$ret eq "1"} return $key + } + return +}