0

I'm trying to do substrate node handshake. As far as I understand we first do Noise XX handshake with our initial request and then we proceed to upgrade the connection.

With the following code the substrate-node-template is accepting my connection but it's returning empty response:

    // snow crate 0.9.6
    let builder: Builder<'_> = Builder::new("Noise_XX_25519_ChaChaPoly_BLAKE2s".parse().unwrap());
    let keypair = builder.generate_keypair().unwrap();
    let static_private_key = keypair.private.clone();
    let static_public_key = keypair.public.clone();

    // Initialize Noise with the local private key
    let mut noise = builder
        .local_private_key(&static_private_key)
        .build_initiator()
        .unwrap();

    // Perform the initial handshake step (Message 1)
    let mut buf = vec![0u8; 65535];
    let len = noise.write_message(&[], &mut buf).unwrap();
    println!("Sending 1st msg");
    stream.write_all(&buf[..len]).await?;
    stream.flush().await?;

I expect that the node will return me his authentication data as described here:

https://spec.polkadot.network/chap-networking https://noiseexplorer.com/patterns/XX/

I assume that I'm missing something but can't figure out what. I'm using simple tcp streams as I don't care what will happen after the handshake is done or for any post traffic.

1 Answer 1

0

Looking offhand at the code:

  • you are using Noise_XX_25519_ChaChaPoly_BLAKE2s, while substrate is using Noise_XX_25519_ChaChaPoly_SHA256
  • We are using an initial message of let mut buffer = vec![0u8; 256]; instead of 65535. That shouldn't matter tho.
  • You'd need to read from the socket to receive the handshake message

We have a few examples in our litep2p crate:

I believe step 2 is missing here, let me know if this helped, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.