Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird output of TransportState::get_remote_static #144

Open
hMihaiDavid opened this issue Dec 8, 2022 · 1 comment
Open

Weird output of TransportState::get_remote_static #144

hMihaiDavid opened this issue Dec 8, 2022 · 1 comment

Comments

@hMihaiDavid
Copy link

hMihaiDavid commented Dec 8, 2022

Hello,

I'm trying to use TransportState::get_remote_static to get the remote end static public key to verify the identity of the remote peer in both ends. I call this right after the handshake is done, on the object returned by HandshakeState::into_transport_mode.

Here's a small program that does the handshake and sends some data from a tcp client stream to a tcp server stream, based on the example in the repo, but it also calls get_remote_static and prints everything from every step to stdout for debugging.
All static keys are hardcoded at the top of the program.
https://gist.github.com/hMihaiDavid/dd2c58378b64b6ae9062cd1a743fe618

I've put some comments with the log of 2 runs, one with .remote_public_key(...) in the builder chain and one without it. It uses an XX noise pattern. The logs are the same.
The output of get_remote_static does not coincide with the peer's static public key.

static STATIC_PRIVKEY_CLIENT: [u8; 32] = [ 52, 18, 25, 179, ...
static STATIC_PUBKEY_CLIENT: [u8; 32] = [  160, 244, 254, 226, ...          
static STATIC_PRIVKEY_SERVER: [u8; 32]  = [ 136, 238, 164, 3, ...
static STATIC_PUBKEY_SERVER: [u8; 32]= [ 171, 232, 231, 4, ...

Whereas the output of get_remote_static is:

server: remote_pubkey_from_transport_state: Some([117, 128, 194, 127,  ...
client: remote_pubkey_from_transport_state: Some([52, 18, 25, 179, ...

Same output without .remote_public_key(...) in the builder chain.

Am I using this wrong? What should I expect from that api?
Also, as you can see, the Client (initiator), gets its static private key as the output of TransportState::get_remote_static.

Thanks in advance, have a nice day.

@hMihaiDavid
Copy link
Author

Ok so right after writing this I just realised that my key gen code (at the bottom of the sample) used the pattern Noise_XXpsk3_25519_ChaChaPoly_BLAKE2s whereas the client and server use Noise_XX_25519_ChaChaPoly_BLAKE2s. When regenerating the static keys with the proper pattern the outputs of get_remote_static are as expected -- the pubkey of the other peer.

I've been stuck for days lol.

So I guess that problem solved, but why that weird behavior tho? Why did the client get its private key when calling get_remote_static?

@hMihaiDavid hMihaiDavid changed the title Help understanding output of TransportState::get_remote_static Weird output of TransportState::get_remote_static Dec 8, 2022
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

No branches or pull requests

1 participant