Implementing secio

Hello everyone,

I’m trying to implement secio communication following the JS and the Go implementation. My goal for now is to perform a successful handshake (open a secure connection with a remote peer). I have several questions :blush::

How would one test its implementation ? I’m currently testing it on an IPFS bootstrap node (162.243.248.213), however it’s quite difficult to understand what’s going on when the remote peer close the socket :sweat_smile:

For now my goal is just to have a proof of concept, here is what I have:

  1. Connect to the host with a TCP socket and send “/multistream/1.0.0\n”
  2. Receive “/multistream/1.0.0\n”
  3. Send “ls\n”
  4. Receive “/secio/1.0.0\n”
  5. Send “/secio/1.0.0\n”
  6. Receive “/secio/1.0.0\n”
  7. Then i receive something I can’t explain, bytes array with : [0, 0, 248, 10]
  8. Finally I send the “propose” packet (protocol buffer encoded, with a nonce, pubkey, ciphers …) something similar to this : https://github.com/libp2p/js-libp2p-secio/blob/master/src/handshake/crypto.js
  9. And then the remote peer close the socket …

Any help would be great !

Regards,
Robin

1 Like

Hi Robin!

Seems that you are off to a good start. It would be great if the WIP spec https://github.com/libp2p/specs/pull/106 was the best place to get your questions answered. Could you help us by reviewing it and see if it informs you better than just looking through the code?

Thanks in advance!

Thank you for your answer. I went through this PR but it did not help me much to be honest (well it gave me the general idea, but can’t help me figure out the exact bytes that should get in and get out).

Once I get the handshake completed, I would be happy do details everything and helps with the spec.

But I’m still stuck with what I describe in my first post.

@daviddias any help on this would be great. I also tried the seccat program packaged with the go-ipfs https://github.com/ipfs/go-ipfs/tree/master/cmd/seccat but this is not working when trying to connect to an IPFS bootstrap node.

Next step for me will be to dive into the go-ipfs code and logs everything but this would be a pain.

Some news here, I just completed the handshake !! I now have a “deep” understanding of the secio handshake and message format.

This PR https://github.com/libp2p/specs/pull/106/files is a good start but is totally incomplete and linking to the go code is not the way to go :blush:.

I will have to take some times to cleanup my code, publish it and I’ll try to propose a good spec for secio (probably beginning of 2019).

Hey, are you on IRC? We can work together.
I’m doing this: IPFS ping protocol

Hey, nice work !! My goal is also to make an ipfs client from scratch. I took a different path and started to work on the secio part. I now have to work on the multiplexing stuff :slight_smile:. Your thread will help me a lot. I have not much free time lately to work on this project. The handshake is quite complex and not documented properly. I basically read the go-secio code and log a lot of stuff in this lib. Good luck !!

1 Like

I know. Can you give me maybe your code or similar so that I can recreate and write how it works in a similar fashion as I did for multiplexing and what you’ve seen?

Sure everything is here. It’s Elixir code but totally WIP (I don’t handle failure at all :)). The handshake part is in lib/secio/handshake

1 Like