Skip to content

Conversation

@paulocoutinhox
Copy link
Contributor

No description provided.

@paulocoutinhox paulocoutinhox changed the title Noise support noise support Jul 20, 2025
@kaganisildak
Copy link

Error raised at private messaging

[03:53:37] [03:53] You: hi
[03:53:43] [03:53] anon3276: Selam
[03:53:44] Peer connected: c484916e3aa6fe0e (anon9532)
[03:53:44] *** anon9532 joined ***
[03:53:53] Received NOISE_IDENTITY_ANNOUNCE from cbed00792f9da82f
[03:53:53] === RECEIVED NOISE IDENTITY ANNOUNCE ===
[03:53:53] From peerId: 'cbed00792f9da82f'
[03:53:53] Preferring to initiate handshake with cbed00792f9da82f (our peerID c484916e3aa6fe0e < their peerID cbed00792f9da82f)
[03:53:53] === INITIATING HANDSHAKE ===
[03:53:53] Remote Peer ID: cbed00792f9da82f
[03:53:53] Creating new initiator session for cbed00792f9da82f
[03:53:53] Calling session->startHandshake()...
[03:53:53] === STARTING NOISE HANDSHAKE ===
[03:53:53] Peer: cbed00792f9da82f, Role: INITIATOR
[03:53:53] === LOCAL STATIC KEY COMPARISON ===
[03:53:53] Local static key (32 bytes): 4888e6d5a26ff9be48ac0100f10efc0285f31b96103d0d5d081d8a6359539766
[03:53:53] Expected from Swift: [COMPARE WITH SWIFT LOG]
[03:53:53] === END KEY COMPARISON ===
[03:53:53] Creating handshake state with pattern: Noise_XX_25519_ChaChaPoly_SHA256
[03:53:53] Role: INITIATOR
[03:53:53] Expected protocol name from Swift: Noise_XX_25519_ChaChaPoly_SHA256
[03:53:53] Expected initial hash from Swift: 4e6f6973655f58585f32353531395f43...
[03:53:53] Handshake state created successfully
[03:53:53] Handshake state pointer: 0x60e0000106c0
[03:53:53] === CHECKING INITIAL HASH STATE ===
[03:53:53] noise_handshakestate_get_handshake_hash returned: 17676 (0x450c)
[03:53:53] Failed to get initial hash: 17676 (Invalid state)
[03:53:53] This is the root cause of the MAC failure!
[03:53:53] === END INITIAL HASH CHECK ===
[03:53:53] Setting local static key...
[03:53:53] Local DH state found, setting private key...
[03:53:53] noise_dhstate_set_keypair_private returned: 0 (0x0)
[03:53:53] Local static key set successfully
[03:53:53] Private key length in DH state: 32
[03:53:53] Initial handshake action: 0 (0x0)
[03:53:53] Starting handshake...
[03:53:53] Handshake started successfully
[03:53:53] Handshake action after start: 16641 (0x4101)
[03:53:53] Initiator: preparing to write first message
[03:53:53] Initiator handshake action before write: 16641 (0x4101)
[03:53:53] Expected action: 16641 (0x4101)
[03:53:53] Initiator: calling writeHandshakeMessage()
[03:53:53] === WRITING HANDSHAKE MESSAGE ===
[03:53:53] Current handshake action: 16641 (0x4101)
[03:53:53] Expected action: 16641 (0x4101)
[03:53:53] === HANDSHAKE STATE DEBUG ===
[03:53:53] Role: INITIATOR
[03:53:53] Protocol: Noise_XX_25519_ChaChaPoly_SHA256
[03:53:53] === HANDSHAKE STEP ANALYSIS ===
[03:53:53] Current handshake step: 0
[03:53:53] Initiator: This is the FIRST message (32 bytes)
[03:53:53] Initiator: Expected: 32 bytes (ephemeral key)
[03:53:53] === END HANDSHAKE STEP ANALYSIS ===
[03:53:53] === END HANDSHAKE STATE DEBUG ===
[03:53:53] Preparing message buffer (1024 bytes)
[03:53:53] Message buffer initialized: data=0x619000030280, size=0, max_size=1024
[03:53:53] ✓ Correct: size=0, max_size=1024 (noise-c will set size after write)
[03:53:53] Preparing payload buffer (empty)
[03:53:53] ✓ No payload buffer provided (testing if nullptr causes AEAD tag)
[03:53:53] Validating parameters before write_message...
[03:53:53] ✓ No payload buffer provided (testing if nullptr causes AEAD tag)
[03:53:53] === FORCE SET LOCAL STATIC KEY ===
[03:53:53] Setting local static key before write_message...
[03:53:53] Local static key size: 32 bytes
[03:53:53] Local static key (first 8 bytes): 4888e6d5a26ff9be
[03:53:53] noise_dhstate_set_keypair_private returned: 0 (0x0)
[03:53:53] ✓ Local static key set successfully before write_message
[03:53:53] === END FORCE SET LOCAL STATIC KEY ===
[03:53:53] All parameters validated, calling noise_handshakestate_write_message...
[03:53:53] ✓ Message buffer: size=0, max_size=1024 (correct for output)
[03:53:53] ✓ No payload buffer (testing if nullptr causes AEAD tag)
[03:53:53] noise_handshakestate_write_message returned: 0 (0x0)
[03:53:53] === BUFFER SIZE DEBUG ===
[03:53:53] After write_message: messageBuffer.size=32, messageBuffer.max_size=1024
[03:53:53] Role: INITIATOR
[03:53:53] Initiator expected: 32 bytes (first XX message)
[03:53:53] === END BUFFER SIZE DEBUG ===
[03:53:53] === MESSAGE RESIZE DEBUG ===
[03:53:53] Before resize: message.size() = 1024
[03:53:53] noise-c wrote: messageBuffer.size = 32 bytes
[03:53:53] noise-c buffer max: messageBuffer.max_size = 1024 bytes
[03:53:53] After resize: message.size() = 32 bytes
[03:53:53] ✓ Message correctly resized to 32 bytes
[03:53:53] === END MESSAGE RESIZE DEBUG ===
[03:53:53] ✓ Message size is correct for role
[03:53:53] Initiator: expected 48 bytes, got 32 bytes
[03:53:53] Initiator generated message of 32 bytes, expected 48 bytes
[03:53:53] === OUTGOING MESSAGE COMPARISON ===
[03:53:53] Handshake message (32 bytes): e294031c9f11af5a13262bda06fd57ede1de4c3df2586c66935421617a744c6b
[03:53:53] Expected from Swift: [COMPARE WITH SWIFT LOG]
[03:53:53] Role: INITIATOR
[03:53:53] === END MESSAGE COMPARISON ===
[03:53:53] Handshake action after write: 16642 (0x4102)
[03:53:53] === FINAL MESSAGE VERIFICATION ===
[03:53:53] Returning message with size: 32 bytes
[03:53:53] First 48 bytes: e294031c9f11af5a13262bda06fd57ede1de4c3df2586c66935421617a744c6b
[03:53:53] === END FINAL MESSAGE VERIFICATION ===
[03:53:53] Handshake step incremented to: 1
[03:53:53] === HANDSHAKE MESSAGE WRITTEN ===
[03:53:53] Handshake initiated successfully with cbed00792f9da82f, data size: 32
[03:53:53] === HANDSHAKE INITIATION COMPLETE ===
[03:53:53] === SENDING NOISE HANDSHAKE INIT ===
[03:53:53] To peerId: 'cbed00792f9da82f'
[03:53:53] Handshake data size: 32 bytes
[03:53:53] Sent Noise handshake init to cbed00792f9da82f
[03:53:53] Received NOISE_HANDSHAKE_RESP from cbed00792f9da82f
[03:53:53] === RECEIVED NOISE_HANDSHAKE_RESP ===
[03:53:53] From peerId: 'cbed00792f9da82f' (size: 16)
[03:53:53] Payload size: 96 bytes
[03:53:53] Local peerId: 'c484916e3aa6fe0e' (size: 16)
[03:53:53] Our role: INITIATOR (localPeerId: 'c484916e3aa6fe0e' vs remotePeerId: 'cbed00792f9da82f')
[03:53:53] === CALLING handleIncomingHandshake ===
[03:53:53] PeerId: 'cbed00792f9da82f'
[03:53:53] Payload size: 96 bytes
[03:53:53] Payload (first 32 bytes): 0b1ca62514a08bcdda0fc705ba510bd44a121f27a1e9a735e4e91c7dbc303a0b
[03:53:53] HandleIncomingHandshake: local='c484916e3aa6fe0e', remote='cbed00792f9da82f'
[03:53:53] === ROLE RESOLUTION COMPARISON ===
[03:53:53] Local PeerID: 'c484916e3aa6fe0e'
[03:53:53] Remote PeerID: 'cbed00792f9da82f'
[03:53:53] Role comparison: 'c484916e3aa6fe0e' < 'cbed00792f9da82f' = true
[03:53:53] Resolved role: INITIATOR
[03:53:53] Expected from Swift: [COMPARE WITH SWIFT LOG]
[03:53:53] === END ROLE RESOLUTION ===
[03:53:53] Message size: 96 bytes, forceReset: false
[03:53:53] === PROCESSING HANDSHAKE MESSAGE ===
[03:53:53] Peer: cbed00792f9da82f, Message size: 96
[03:53:53] Role: INITIATOR
[03:53:53] Protocol: Noise_XX_25519_ChaChaPoly_SHA256
[03:53:53] === INCOMING MESSAGE COMPARISON ===
[03:53:53] Message hex: 0b1ca62514a08bcdda0fc705ba510bd44a121f27a1e9a735e4e91c7dbc303a0bf9f66002585c80333f6e21b8f3adab380ee59fa24cf9751174fe7fca598451f7a43f41824e4e0f30106e65cc0dadde5d29df00750ee24b0be7c693e50f30342c
[03:53:53] Message size: 96 bytes
[03:53:53] Expected from Swift: [COMPARE WITH SWIFT LOG]
[03:53:53] === END MESSAGE COMPARISON ===
[03:53:53] Initiator: processing handshake response (96 bytes)
[03:53:53] Initiator: after this, should generate 64-byte final message
[03:53:53] Using existing handshake state
[03:53:53] Current handshake action: 16642 (0x4102)
[03:53:53] Reading handshake message, size: 96
[03:53:53] Trying to read handshake message: data=0x608000019120, size=96
[03:53:53] Handshake input hex: 0b1ca62514a08bcdda0fc705ba510bd44a121f27a1e9a735e4e91c7dbc303a0bf9f66002585c80333f6e21b8f3adab380ee59fa24cf9751174fe7fca598451f7a43f41824e4e0f30106e65cc0dadde5d29df00750ee24b0be7c693e50f30342c
[03:53:53] === XX PATTERN MESSAGE STRUCTURE ===
[03:53:53] Message size: 96 bytes (expected for XX responder->initiator)
[03:53:53] Ephemeral key (e) - 32 bytes: 0b1ca62514a08bcdda0fc705ba510bd44a121f27a1e9a735e4e91c7dbc303a0b
[03:53:53] Encrypted static key (s) - 48 bytes: f9f66002585c80333f6e21b8f3adab380ee59fa24cf9751174fe7fca598451f7a43f41824e4e0f30106e65cc0dadde5d
[03:53:53] Payload tag - 16 bytes: 29df00750ee24b0be7c693e50f30342c
[03:53:53] === END MESSAGE STRUCTURE ===
[03:53:53] NoiseBuffer for read: data=0x608000019120, size=96, max_size=96
[03:53:53] === BUFFER CONFIGURATION ===
[03:53:53] Message buffer: data=0x608000019120, size=96, max_size=96
[03:53:53] Payload buffer: data=0x611000062ec0, size=0, max_size=256
[03:53:53] Payload data vector size: 256
[03:53:53] === END BUFFER CONFIGURATION ===
[03:53:53] Handshake action before read: 16642 (0x4102)
[03:53:53] Expected action for read: 16642 (0x4102)
[03:53:53] Calling noise_handshakestate_read_message...
[03:53:53] Handshake state: 0x60e0000106c0
[03:53:53] Message buffer: data=0x608000019120, size=96, max_size=96
[03:53:53] Payload buffer: data=0x611000062ec0, size=0, max_size=256
[03:53:53] === BEFORE STATIC KEY DECRYPTION ===
[03:53:53] noise_handshakestate_get_handshake_hash (before decryption) returned: 17676 (0x450c)
[03:53:53] Failed to get hash before decryption: 17676 (Invalid state)
[03:53:53] This explains the MAC failure!
[03:53:53] === STATIC KEY DATA COMPARISON ===
[03:53:53] Static key data to decrypt (48 bytes): f9f66002585c80333f6e21b8f3adab380ee59fa24cf9751174fe7fca598451f7a43f41824e4e0f30106e65cc0dadde5d
[03:53:53] Expected from Swift: b27a49c908e0deafbd1f1a4e57b8f46c33b3f11cec59c5b6e3c985aa228116a4
[03:53:53] Role: INITIATOR
[03:53:53] Message size: 96 bytes
[03:53:53] ✗ Static key data MISMATCH with Swift!
[03:53:53] Expected: b27a49c908e0deafbd1f1a4e57b8f46c33b3f11cec59c5b6e3c985aa228116a4
[03:53:53] Got: f9f66002585c80333f6e21b8f3adab380ee59fa24cf9751174fe7fca598451f7a43f41824e4e0f30106e65cc0dadde5d
[03:53:53] This indicates a handshake state divergence!
[03:53:53] === END STATIC KEY DATA COMPARISON ===
[03:53:53] === ATTEMPTING STATIC KEY DECRYPTION ===
[03:53:53] noise_handshakestate_read_message returned: 17668 (0x4504)
[03:53:53] Failed to read handshake message: 17668 (MAC failure)
[03:53:53] Error details: MAC failure
[03:53:53] === STATIC KEY DECRYPTION FAILED ===
[03:53:53] This is likely a MAC failure due to hash/nonce/key mismatch
[03:53:53] Compare the hash above with the Swift logs
[03:53:53] Handshake failed for cbed00792f9da82f: Failed to read handshake message
[03:53:53] Failed to handle handshake response from cbed00792f9da82f: Failed to read handshake message

@paulocoutinhox
Copy link
Contributor Author

Yes, im in a war to understand what is wrong when use noise. If you have any knowledge, help me.

@kaganisildak
Copy link

im also in a war for python version :/
https://github.com/kaganisildak/bitchat-python/blob/noise/dummy/ble_service.py
this version can send and handle private message but still to buggy and cli side vibed, now im refactoring but maybe the handshake part can help to you

@paulocoutinhox
Copy link
Contributor Author

paulocoutinhox commented Jul 22, 2025

Your handshake part is working with noise protocol? I get the source and call iA to understand your noise impl and it sad:

Now I understand the issue! The Python code doesn't use Noise Protocol at all. It uses a simple X25519 key exchange with AES-GCM encryption. The C++ code is trying to implement Noise Protocol handshake, but the Python implementation uses a much simpler approach.

@kaganisildak
Copy link

i think i solved dm part now
checkout https://github.com/kaganisildak/bitchat-python
image

@paulocoutinhox
Copy link
Contributor Author

python-bitchat

it works in part, no message is sent, and after no device is visible and dm message is never received

@kaganisildak
Copy link

Today jack release new changes packet format, im working on that

@paulocoutinhox paulocoutinhox merged commit 30f4fb1 into main Jul 26, 2025
2 checks passed
@paulocoutinhox paulocoutinhox deleted the noise-support branch July 26, 2025 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants