fix(liteclient): write both magics in auth-complete payload (#463) - #501
Open
chiliec wants to merge 1 commit into
Open
fix(liteclient): write both magics in auth-complete payload (#463)#501chiliec wants to merge 1 commit into
chiliec wants to merge 1 commit into
Conversation
sendAuthComplete built the tcp.authentificationComplete payload with a 4-byte buffer and two PutUint32 calls that both wrote to offset 0, so the message-type magic (magicTcpAuthentificationComplete) was immediately overwritten by the PublicKey constructor magic (magicPubKey). The message was sent with the wrong type prefix and was 4 bytes short. Write the two magics into distinct 4-byte slots. Extract the payload construction into buildAuthCompletePayload so the byte layout can be unit-tested without a live connection. Closes tonkeeper#463. Signed-off-by: Vladimir Babin <vovababin@gmail.com>
Contributor
|
lgtm |
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.
What
Closes #463.
sendAuthComplete(liteclient/connection.go) built thetcp.authentificationCompletepayload like this:Both
PutUint32calls write to offset 0 of the same 4-byte buffer, so the second write (magicPubKey) immediately overwrites the first (magicTcpAuthentificationComplete). The auth-complete message is therefore sent with the wrong type prefix and is 4 bytes short.Cause
The TL schema is:
so the serialized layout must be two distinct magics — the message-type magic followed by the
PublicKeyconstructor magic — then the 32-byte key and the length-prefixed signature. The buffer needs 8 bytes for the two magics, not 4.Fix
Write the two magics into distinct 4-byte slots, and extract the payload construction into a pure
buildAuthCompletePayload(pubKey, signature)helper so the byte layout is unit-testable without a live connection:Tests
Added
liteclient/auth_complete_test.go, which asserts the exact byte layout: message magic at[0:4], pubkey magic at[4:8], the public key at offset 8, the length-prefixed signature after it, and 4-byte alignment.Verified genuine RED→GREEN: with the original construction restored, the test fails with
message magic: got 0x4813b4c6, want 0xf7ad9ea6— i.e. it catches the exact overwrite; with the fix it passes.Validation (real results, Go 1.24.5)
go test ./liteclient/ -run TestBuildAuthCompletePayloadLayout: PASSgo build ./...: successgofmt -landgo vet ./liteclient/: cleanNote: the package's
client_test.gotests (e.g.TestGeneratedMethod3) connect to a live lite server and fail in a sandbox without outbound network — I confirmed they fail identically on a cleanmastercheckout, so that is unrelated to this change.First-time contributor here — happy to adjust the helper's name/placement or the test if you'd prefer a different approach.