Read endorsement VNB/VNA at the start of the signed structure - #4
Open
erkki wants to merge 1 commit into
Open
Conversation
The UA-Signed Evidence Structure (RFC 9575 section 4.1) is [VNB (4)] [VNA (4)] [Evidence] [UA DET (16)] [UA Signature (64)]. handleEndorsementStructure advanced the buffer position past the signed content before calling getInt(), so VNB/VNA were decoded from the first 8 signature bytes. verifyTimestamps then evaluated random values and rejected nearly every Wrapper/Manifest; when the garbage happened to pass, evidenceSize went negative (remaining - SIGNATURE_SIZE - DET_SIZE with only the signature remaining) and Buffer.limit() threw IllegalArgumentException on the scanner thread. Read VNB/VNA in place, derive evidenceSize from messageSize, and reject structures shorter than VNB+VNA+DET. Pass only the Evidence field to handleWrapper/handleManifest: both previously received the whole signed structure, so the wrapper %25 check ran over VNB/VNA+DET too and the manifest consumed VNB/VNA as the previous/current manifest hashes. EndorsementStructureTest feeds synthetic Ed25519-signed Manifest SAMs through handleSAMMessage. Against the previous parsing, the positive cases fail (VNB/VNA decoded from signature bytes reject the structure) and the tampered-signature case reproduces the Buffer.limit(-24) crash. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The UA-Signed Evidence Structure (RFC 9575 §4.1) is
[VNB (4)][VNA (4)][Evidence][UA DET (16)][UA Signature (64)].handleEndorsementStructureadvanced the buffer position past the signed contentbefore calling
getInt(), so VNB/VNA were decoded from the first 8 signature bytes:verifyTimestampsevaluated random values and rejected nearly every Wrapper/Manifest;when the garbage happened to pass,
evidenceSizewent negative andBuffer.limit()threw
IllegalArgumentExceptionon the scanner thread. Additionally bothhandleWrapper/handleManifestreceived the whole signed structure instead of theEvidence field: the wrapper
% 25check ran over VNB/VNA+DET, and the manifestconsumed VNB/VNA as the previous/current manifest hashes.
This is a regression from
1e08f74("DET verification"): the initial-commitversion read VNB/VNA in place and passed the Evidence slice to the handlers; that
refactor added the premature
position()advance (invalidating theevidenceSizecomputation written for the old cursor position) and swapped thehandler arguments from
evidencetoentire_message.Change: read VNB/VNA in place, derive
evidenceSizefrommessageSize, rejectstructures shorter than VNB+VNA+DET, pass the Evidence slice to the handlers.
Device-verified: manifests pass timestamp, DET, and Ed25519 signature checks.
Tests:
EndorsementStructureTestbuilds Manifest SAMs signed with a deterministicEd25519 test key and feeds them through
handleSAMMessage. Against the previousparsing, the positive cases fail (VNB/VNA decoded from signature bytes reject the
structure) and the tampered-signature case reproduces the
Buffer.limit(-24)crash. Also covers expired VNA, tampered signature, and truncated-structure
rejection. Test dependencies:
androidx.arch.core:core-testing(synchronousLiveData) and
org.mockito:mockito-core—android.util.Logis statically mockedper test class instead of enabling the module-global
unitTests.returnDefaultValues, which would silently default every android.jarstub. The mockito line is identical in #4 and merges cleanly.