Index: client/pkgr.eagle ================================================================== --- client/pkgr.eagle +++ client/pkgr.eagle @@ -101,12 +101,12 @@ if {[isEagle]} then { set fileName [appendArgs \" $fileName \"] return [expr {[catch { - eval exec -success Success [subst $pgpCommand]}] == 0 - }] + eval exec -success Success [subst $pgpCommand] + }] == 0}] } else { return [expr {[catch { eval exec [subst $pgpCommand] 2>@1 }] == 0}] } @@ -365,10 +365,28 @@ # if {![info exists metadata(certificate)]} then { error "missing script certificate" } + # + # NOTE: Create common cleanup script block that deletes any temporary + # files created for the script verification process. + # + set script(cleanup) { + if {[string length $fileName(2)] > 0 && \ + [file exists $fileName(2)]} then { + catch {file delete $fileName(2)} + unset -nocomplain fileName(2) + } + + if {[string length $fileName(1)] > 0 && \ + [file exists $fileName(1)]} then { + catch {file delete $fileName(1)} + unset -nocomplain fileName(1) + } + } + # # NOTE: Figure out the "type" of script certificate we are now dealing # with. # if {[isHarpyCertificate $metadata(certificate)]} then { @@ -375,30 +393,34 @@ # # NOTE: Attempt to create a completely unique array variable name to # hold the package metadata in this scripting language as well # as possibly in the other necessary scripting language(s). # - set newVarName [appendArgs \ + set newVarName(1) [appendArgs \ [getLookupVarNamePrefix] metadata_ [getLookupVarNameSuffix]] + set newVarName(2) [appendArgs \ + [getLookupVarNamePrefix] cleanup_ [getLookupVarNameSuffix]] + set newProcName(1) [appendArgs \ [getLookupVarNamePrefix] eagleHasSecurity_ [getLookupVarNameSuffix]] set newProcName(2) [appendArgs \ - [getLookupVarNamePrefix] tclMustBeReady_ [getLookupVarNameSuffix]] + [getLookupVarNamePrefix] getFileTempName_ [getLookupVarNameSuffix]] set newProcName(3) [appendArgs \ - [getLookupVarNamePrefix] getFileTempName_ [getLookupVarNameSuffix]] + [getLookupVarNamePrefix] tclMustBeReady_ [getLookupVarNameSuffix]] # # NOTE: Create the Eagle script block that will be used to securely # evaluate a signed package script. This must be evaluated in # Eagle because it uses several plugins only available there. # set script(outer) [string map [list \ - %metadata% $newVarName %eagleHasSecurity% $newProcName(1) \ - %tclMustBeReady% $newProcName(2) %getFileTempName% $newProcName(3)] { + %metadata% $newVarName(1) %cleanup% $newVarName(2) \ + %eagleHasSecurity% $newProcName(1) %getFileTempName% \ + $newProcName(2) %tclMustBeReady% $newProcName(3)] { try { # # NOTE: If there is no package ifneeded script, there is nothing we # can do here. # @@ -474,24 +496,13 @@ error "unsupported language" } } } finally { # - # NOTE: Delete the temporary files that we created for the - # signed script verification. - # - if {[string length $fileName(2)] > 0 && \ - [file exists $fileName(2)]} then { - catch {file delete $fileName(2)} - unset -nocomplain fileName(2) - } - - if {[string length $fileName(1)] > 0 && \ - [file exists $fileName(1)]} then { - catch {file delete $fileName(1)} - unset -nocomplain fileName(1) - } + # NOTE: Perform any necessary cleanup steps. + # + eval ${%cleanup%} } } finally { # # NOTE: Restore the saved security state for the interpreter. # @@ -498,48 +509,51 @@ if {!$savedSecurity} then {source disableSecurity} unset -nocomplain savedSecurity } } } finally { - rename {%getFileTempName%} "" rename {%tclMustBeReady%} "" + rename {%getFileTempName%} "" rename {%eagleHasSecurity%} "" + unset -nocomplain {%cleanup%} unset -nocomplain {%metadata%} } }] # # NOTE: Copy the package metadata into the fresh array variable, # if necessary, marshalling it from native Tcl to Eagle. # if {[isEagle]} then { - array set $newVarName [array get metadata] + array set $newVarName(1) [array get metadata] + set $newVarName(2) $script(cleanup) proc $newProcName(1) {} [info body [appendArgs \ [namespace current] ::eagleHasSecurity]] proc $newProcName(2) {} [info body [appendArgs \ - [namespace current] ::tclMustBeReady]] + [namespace current] ::getFileTempName]] proc $newProcName(3) {} [info body [appendArgs \ - [namespace current] ::getFileTempName]] + [namespace current] ::tclMustBeReady]] return [eval $script(outer)] } else { eagleMustBeReady - eagle [list array set $newVarName [array get metadata]] + eagle [list array set $newVarName(1) [array get metadata]] + eagle [list set $newVarName(2) $script(cleanup)] eagle [list proc $newProcName(1) {} [info body [appendArgs \ [namespace current] ::eagleHasSecurity]]] eagle [list proc $newProcName(2) {} [info body [appendArgs \ - [namespace current] ::tclMustBeReady]]] + [namespace current] ::getFileTempName]]] eagle [list proc $newProcName(3) {} [info body [appendArgs \ - [namespace current] ::getFileTempName]]] + [namespace current] ::tclMustBeReady]]] return [eagle $script(outer)] } } elseif {[isPgpSignature $metadata(certificate)]} then { # @@ -566,33 +580,32 @@ writeFile $fileName(2) $metadata(certificate) } # # NOTE: Attempt to verify the PGP signature for the package script. - # If this fails, raise an error. # - if {![verifyPgpSignature $fileName(2)]} then { + if {[verifyPgpSignature $fileName(2)]} then { + # + # NOTE: Delete the temporary files that we created for the PGP + # signature verification. + # + eval $script(cleanup) + } else { + # + # NOTE: Delete the temporary files that we created for the PGP + # signature verification. + # + eval $script(cleanup) + + # + # NOTE: PGP signature verification failed. Raise an error and + # do not proceed with evaluating the package script. + # error [appendArgs \ "couldn't read file \"" $fileName(1) "\": bad PGP signature"] } - # - # NOTE: Delete the temporary files that we created for the PGP - # signature verification. - # - if {[string length $fileName(2)] > 0 && \ - [file exists $fileName(2)]} then { - catch {file delete $fileName(2)} - unset -nocomplain fileName(2) - } - - if {[string length $fileName(1)] > 0 && \ - [file exists $fileName(1)]} then { - catch {file delete $fileName(1)} - unset -nocomplain fileName(1) - } - # # NOTE: The PGP signature was verified; use the downloaded package # script verbatim. # set script(inner) $metadata(ifNeeded) Index: client/pkgr.eagle.harpy ================================================================== --- client/pkgr.eagle.harpy +++ client/pkgr.eagle.harpy @@ -19,32 +19,32 @@ None Mistachkin Systems - 24efe138-647e-406e-a4ff-1d8728db1a30 + 6b9ca4d2-f735-4a9c-9e98-6eb4e20071e5 SHA512 Script - 2016-08-16T23:06:52.1540547Z + 2016-08-16T23:38:50.4841328Z -1.00:00:00 0x2c322765603b5278 - RXTu3ZtnYNyuZx4ljp1N1Xma67EhkVAKOSZSXp4o6TjLPOkxMA+hXRS8fIVl+U6z0Uv9Pa5kLXOa - CVuv5yJjm+ushIzOqxjEUk1rLrw+TCFQyYYDsCvlNoiqpUDerPnp8JB08tQXnmO+mRKscGOEw9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