Giter Site home page Giter Site logo

handshake's Introduction

Build Status codecov

kuska handshake

kuska means together in Runasimi

kuska is an implementation of decentralized social network Secure Scuttlebut written in rust, it does not aim to provide a user interface and the functionality implemented in some clients like Patchwork, Patchbay, but the full set of libraries to be able to develop applications for the secure scuttlebut network.

kuska-handshake is the implementation of the handhake and box stream used in SSB, detailed information about the protocol can be found in https://ssbc.github.io/scuttlebutt-protocol-guide/.

the current implementation contains:

  • an agnostic implementation of the protcol using sodiumoxide
  • a synchronous version (needs sync feature)
  • an asynchronous async_std version (needs async_std feature, with wrappers for tokio with tokio_compat feature)

sync client/server

server

Create the server key pair

let (pk, sk) = ed25519::gen_keypair();
let pk_b64 = base64::encode_config(&pk, base64::STANDARD);

Define the network to connect

let net_id_hex = "d4a1cb88a66f02f8db635ce26441cc5dac1b08420ceaac230839b755845a9ffb";
let net_id = auth::Key::from_slice(&hex::decode(net_id_hex).unwrap()).unwrap();

Listen, accept the socket, and perform the handshake

let listener = TcpListener::bind(...).unwrap();
let (socket, addr) = listener.accept().unwrap();
let handshake = handshake_server(&socket, net_id, pk, sk)?;

Once the handshake is performed, create both box streams, one to send and another to recieve data, those box streams implements std::io::Read and std::io::Write to perform usual i/o operations on them.

let (key_nonce_send, key_nonce_recv) = KeyNonce::from_handshake(handshake);
let (mut box_stream_read, mut box_stream_write) =
        BoxStream::new(&socket, &socket, key_nonce_send, key_nonce_recv).split_read_write();

box_stream_read.read_exact(...)
box_stream_write.write_all(...)

client

Create the client key pair

let (pk, sk) = ed25519::gen_keypair();
let pk_b64 = base64::encode_config(&pk, base64::STANDARD);

Connect to the server, perform the handshake (you need the server public key), and create the box streams to communicate

let socket = TcpStream::connect(...).unwrap();
let handshake = handshake_client(&socket, net_id, pk, sk, server_pk)?;

let (key_nonce_send, key_nonce_recv) = KeyNonce::from_handshake(handshake);
let (mut box_stream_read, mut box_stream_write) =
  BoxStream::new(&socket, &socket, key_nonce_send, key_nonce_recv).split_read_write();

box_stream_read.read_exact(...)
box_stream_write.write_all(...)

async_std client

The async_std client is analogous to the sync version, just all functions are async and uses async_std::io::Read and async_std::io::Write for box streams

use async_std::io::{Read,Write};
use async_std::net::TcpStream;
use kuska_handshake::async_std::{handshake_client,BoxStream};

#[async_std::main]
async fn main() -> Result<T, Box<dyn Error>> {
  ...
  let mut socket = TcpStream::connect("127.0.0.1:8008").await?;
  let (_,handshake) = handshake_client(&mut socket, ssb_net_id(), pk, sk, server_pk).await?;

  let (box_stream_read, box_stream_write) =
      BoxStream::from_handhake(&socket, &socket, handshake, 0x8000)
      .split_read_write();

tokio client

To use the tokio you need the wrappers used in kuska_handshake::async_std::tokio_compat:

use tokio::net::TcpStream;
use kuska_handshake::async_std::{BoxStream,handshake_client,TokioCompatExt,TokioCompatExtRead,TokioCompatExtWrite};

let tokio_socket : TcpStream = TcpStream::connect("127.0.0.1:8008").await?;
let asyncstd_socket = TokioCompatExt::wrap(tokio_socket);

let (asyncstd_socket,handshake) = handshake_client(asyncstd_socket, ssb_net_id(), pk, sk.clone(), pk).await?;
let mut tokio_socket = asyncstd_socket.into_inner();
let (read,write) = tokio_socket.split();

let read = TokioCompatExtRead::wrap(read);
let write = TokioCompatExtWrite::wrap(write);

let (box_stream_read, box_stream_write) =
    BoxStream::from_handhake(read, write, handshake, 0x8000)
    .split_read_write();

handshake's People

Contributors

adria0 avatar alexis211 avatar dhole avatar mycognosist avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

handshake's Issues

Implement iot-solar example

  • actix/tokio/no_std interop
  • compressed feed database
  • architecture PoC
  • kv database
  • muxrpc server
  • feed sync
  • command processor
  • solar api
  • command line

iot-solar allows to use ssb to interface with solar mini/microgrids allowing to have a secure way to control them.

The general context is

  • AYO, BAAKO, CHIKE, DESTA and EKENE (*1) are the members of a small community powered by solar energy.

  • Each member have its own laptop, so there's no central servers to make backups, and they want to manage all the solar energy stuff and keep a track of all things done there.

  • For this, the community creates an special SSB network only to manage the microgrids. The community uses SSB to communicate and share things as usual:

    • discuss about what needs to be done
    • votings
    • share manuals, schemas, etc...
    • anotate operation on solar panels
  • but also wants some extra functionality

    • allow grid to be operated remotely, via admin feed subscription
      commands the device will process
    • allow grid to to generate feed about its status, by generating a message each day about its performance
  • iot-solar, is the bot that is installed in the microgrid allowing interaction

command line

iot-solar setup - creates an identity and setups the database
iot-solar admin add @id - adds a friend (can send commands)
iot-solar admin remove @id - removes a friend (cannot send commands)
iot-solar report filename.txt - generates a post with the report
iot-solar action action.txt - generates a post with the action (self-consumed)

config.toml

netid = # networkid to use
actionpath = # executable to call when an action is triggered via special admin feed

storage

KV database

  • current admins

filesystem

  • own feed
  • admin feeds

api (actix)

POST /api/admin/add/ @id
POST /api/admin/rm/ @id
POST /api/admin/report in body is the report content
POST /api/admin/action in body is the action content

app architecture draft

                  http
+------+           +           +------------+
|cmd   +-+http+--+ |       +-->+ssb rpc(ro) +---+
+------+         | |       |   +------------+   |
                 v v       |                    |
+------+    +----+-+---+   |   +------------+   |
|tokio +-+->+actix     +---+-->+solar api   |   |
+------+ |  +----------+       +-----+------+   |
         |                           |          |
         |  +----------+             |          |
         |  |command   +<-+msg chan<-+---+      |
         +->+processor |                 |      |
         |  |loop      +---------+       |      |
         |  +----+-----+         |       |      |
         |       ^ term ch       |       |      |
         |  +----+-----+     +---v---+   |      |
         +->+SIGTERMhnd|     |storage|   |      |
         |  +----+-----+     |KV + fs+<---------+
         |       | term ch   +-------+   |
         |  +----v-----+         ^       |
         +->+feed sync +---------+-------+
         |  +----------+
         +->+peer disc |
            +----+-----+
                 |
                 v
           ssbrpc/bot/lan

(*1) https://www.babynames.net/girl/african

Move all crypto functions to a module

There are different modules that currently import sodiumoxide.

This issue is about moving all the cryptographic functions (for now taken from sodiumoxide) into a module and only import that module in the rest of the library without importing sodiumoxide.

Remove old examples

Some examples are just old code used to prototype the implementation of different ssb algorithms. They should be removed because they are not examples that use this crate.

Check if we have unused libraries, and remove them if necessary

In #22 mentions that he updated Cargo.toml to use the last version of each library, but he hasn't checked if there are any libraries that are not used. We need to check them and remove any library that is not used.

Edit: I think arrayref is not currently used. But we need to check it.

Replace/fix sodiumoxidez

@Dhole crate sodiumoxide = { git = "https://github.com/Dhole/sodiumoxidez", branch = "extra" } reports a problem when using cargo audit

ID:       RUSTSEC-2019-0026
Crate:    sodiumoxide
Version:  0.2.4
Date:     2019-10-11
URL:      https://rustsec.org/advisories/RUSTSEC-2019-0026
Title:    generichash::Digest::eq always return true
Solution:  upgrade to >= 0.2.5
Dependency tree: 
sodiumoxide 0.2.4

Reorganize repository towards a library/crate

This repository was initially created as a gathering of resources and study of the ssb, but it already contains a library in the code folder with working and somehow tested modules.

We should reorganize the entire repository so that it can be offered as a rust crate, also renaming to stop using the ssb-study name. In case we need a space to discuss and study further stuff, we may create another repository.

It's open to debate whether to make a single crate out of this, or offer multiple crates.

Rethink sodiumoxidez fork

sodiumoxidez was the fork I made of sodiumoxide that adds the functions to convert from ed25519 to curve25519 which in the original sodiumoxide, but it's implemented in libsodium. Maybe instead of using a fork we should solve this via the kuska-crypto crate? Or maybe we could keep sodiumoxidez and move it here?

Make an agnostic boxstream

Currently handshake has an agnostic implementation that works just with slices. There's a "sync" wrapper to use the handshake with a sync stream (std::io::Read, std::io::Write). And the "async" wrapper is pending (currently we have an async handshake but it doesn't reuse code).

This issue is about doing the same for boxstream.

Add test_utils async net functions

I haven't managed to get async closures working to replicate the api of the test_utils sync net functions :(

Use these functions in handshake_async.

Publish kuska-handshake on crates.io?

Hi,

I'd like to publish on crates.io a crate that depends on kuska-handshake, but it seems that I can't do that for the moment because kuska-handshake itself is not on crates.io. Are you considering publishing it anytime soon?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.