Skip to content

Latest commit

 

History

History
64 lines (49 loc) · 1.78 KB

File metadata and controls

64 lines (49 loc) · 1.78 KB

Channeling

Channeling is a library abstracting away handshaking and encryption for secure communication.

Currently the only handshaking protocol implemented is one of PAKE (Password Authenticated Key Exchange) variety.

The encryption is done by libsodium’s implementation of XChaCha20-Poly1305.

Work In Progress

The library is considered to be in pre-alpha, unstable state. Everything may change, API included.

Current API

Server

#include "PakeHandshaker.h"
#include "Server.h"

using namespace Channeling;

int main() {
  const auto message_handler = [](const Bytes& data) {
    // Print the message, treating is as a string.
    std::cout.write(reinterpret_cast<const char*>(data.data()),
                    data.size()) << '\n';

    // Return "response" in bytes.
    return Bytes{'r', 'e', 's', 'p', 'o', 'n', 's', 'e'};
  };

  auto server = MakeServer<PakeHandshaker>(message_handler, "password");

  // Bind to ZeroMQ address, could be "tcp://1.2.3.4:5678" for network address
  server.Bind("ipc://zeromq-server");
  server.Run(); // never exits
}

Client

#include "Client.h"
#include "PakeHandshaker.h"

using namespace Channeling;

int main() {
  auto client = MakeClient<PakeHandshaker>("password");

  if (not client.Connect("ipc://zeromq-server")) {
    std::cerr << "Connection failed\n";
    return 1;
  }

  // tl::expected<Bytes, std::error_code>
  const auto maybe_response = client.Request(data); // is thread safe
  if (maybe_response) {
    // Print data as a string
    std::cout.write(reinterpret_cast<const char*>(maybe_response.value()))
        << '\n';
  } else {
    std::cerr << maybe_response.error().message() << '\n';
  }

  return 0;
}