Skip to content

Commit

Permalink
Merge pull request #65 from muhkuh-sys/dev_NXTFLASHER-844
Browse files Browse the repository at this point in the history
[code] support verify signature for HTBL chunks for netx90_rev2 (NXTF…
  • Loading branch information
FrikadellenFred authored Jan 18, 2024
2 parents a11cda3 + a8feccd commit e29204c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 17 deletions.
Binary file modified helper_binaries/netx90/verify_sig.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions lua/lua/flasher_helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ function M.connect_retry(tPlugin, uLRetries)
strError = "No plugin selected for connect"
end

-- default retries are 5
-- default retries are 3
if uLRetries == nil then
uLRetries = 5
uLRetries = 3
end

while uLRetries > 0 do
Expand Down
4 changes: 2 additions & 2 deletions lua/lua/helper_files.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ local atHelperFileVersions = {
{ -- This is verify_sig_intram from the build
key = "verify_sig",
filename = "verify_sig.bin",
version = "Ver:GITv1.0.0-0-g427ff28e7e1a:reV",
version_offset = 0x93c
version = "Ver:GITv1.0.0-dev5-0",
version_offset = 0x9B8
},

{ -- Todo: Turn this into a template to insert version automatically.
Expand Down
56 changes: 44 additions & 12 deletions lua/lua/sipper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ function Sipper:gen_data_block(strFileData, strOutputBinPath)
local ulSignatureSize
local strPaddedKey
local strChunkHash
local fPlaceSignatureAtEnd = false

local tChunkHash = mhash.mhash_state()
tChunkHash:init(mhash.MHASH_SHA384)
Expand Down Expand Up @@ -299,31 +300,62 @@ function Sipper:gen_data_block(strFileData, strOutputBinPath)

strChunkHash = tChunkHash:hash_end()

print(tBinStringHandle:seek())
-- print(tBinStringHandle:seek())
-- chunk size does not include the chunk id and the chunk size itself
ulSignatureSize = ulChunkSize - ulReadSize + 8
strSignature = tBinStringHandle:read(ulSignatureSize)
-- write whole 512 bytes as signature for verify_sig.bin to determine the actual signature size
-- to get the the signature from the end of buffer
if ulSignatureSize > 512 then
-- strip signature string to be exact 512 bytes
strSignature = string.sub(strSignature, -512)
else
-- fill up signature string to be exact 512 bytes
local ulFillupSize = 512 - ulSignatureSize

strSignature = string.rep(string.char(0x0), ulFillupSize) .. strSignature
end
fPlaceSignatureAtEnd = true
end

if tResult == true then
-- create the data block with the collected data
local usOption = 0x0100
local usUsedKeys = 0x0000

if ulPageSelect == 1 and ulKeyIdx == 16 then
strDataBlock = strDataBlock .. string.char(0x03, 0x01)
strDataBlock = strDataBlock .. string.char(0x04, 0x00)
usOption = usOption | 0x0003
usUsedKeys = usOption | 0x0004
-- strDataBlock = strDataBlock .. string.char(0x03, 0x01)
-- strDataBlock = strDataBlock .. string.char(0x04, 0x00)
elseif ulPageSelect == 1 and ulKeyIdx == 17 then
strDataBlock = strDataBlock .. string.char(0x02, 0x01)
strDataBlock = strDataBlock .. string.char(0x01, 0x00)
usOption = usOption | 0x0002
usUsedKeys =usOption | 0x0001
-- strDataBlock = strDataBlock .. string.char(0x02, 0x01)
-- strDataBlock = strDataBlock .. string.char(0x01, 0x00)
elseif ulPageSelect == 2 and ulKeyIdx == 16 then
strDataBlock = strDataBlock .. string.char(0x04, 0x01)
strDataBlock = strDataBlock .. string.char(0x08, 0x00)
usOption = usOption | 0x0004
usUsedKeys = usOption | 0x0008
-- strDataBlock = strDataBlock .. string.char(0x04, 0x01)
-- strDataBlock = strDataBlock .. string.char(0x08, 0x00)
elseif ulPageSelect == 2 and ulKeyIdx == 17 then
strDataBlock = strDataBlock .. string.char(0x00, 0x01)
strDataBlock = strDataBlock .. string.char(0x02, 0x00)
else
strDataBlock = strDataBlock .. string.char(0x00, 0x01)
strDataBlock = strDataBlock .. string.char(0x00, 0x00)
usOption = usOption | 0x0004
usUsedKeys = usOption | 0x0008
-- strDataBlock = strDataBlock .. string.char(0x00, 0x01)
-- strDataBlock = strDataBlock .. string.char(0x02, 0x00)
end
if fPlaceSignatureAtEnd then
usOption = usOption | 0x1000 -- set flag UNKNOWN_SIGNATURE_SIZE
end

local usOptionL = (usOption >> 8) & 0xff;
local usOptionH = (usOption) & 0xff;
local usUsedKeysL = (usUsedKeys >> 8) & 0xff;
local usUsedKeysH = (usUsedKeys) & 0xff;

strDataBlock = strDataBlock .. string.char(usOptionH, usOptionL)
strDataBlock = strDataBlock .. string.char(usUsedKeysH, usUsedKeysL)

strDataBlock = strDataBlock .. strChunkHash

local strBindingData = ""
Expand Down
2 changes: 1 addition & 1 deletion lua/usip_player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2842,7 +2842,7 @@ local strSecureOptionDir = path.join(strSecureOption, strNetxName)
local strSecureOptionPhaseTwoDir = path.join(tArgs.strSecureOptionPhaseTwo, strNetxName)

-- If no helpers are required, skip the checks.
if #astrHelpersToCheck == 0 then
if astrHelpersToCheck == 0 then
tLog.info("Skipping version/signature tests for helper files.")
else
-- Print the list.
Expand Down

0 comments on commit e29204c

Please sign in to comment.