From 25db9ff8a4cfb4b98aeeaae360e8c718b9c5e20c Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 27 Oct 2016 09:25:53 +0200 Subject: Adds libgcrypt implementation for elgamal in multiplicative group. Also adapts the API to both handle sodium and gcrypt libraries. --- client/cmixclient.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'client/cmixclient.cpp') diff --git a/client/cmixclient.cpp b/client/cmixclient.cpp index 6866274..9ee1d81 100644 --- a/client/cmixclient.cpp +++ b/client/cmixclient.cpp @@ -1,14 +1,23 @@ #include "cmixclient.hpp" +#include + using namespace boost::asio::ip; using namespace boost::asio; void CMixClient::key_exchange(int i) { BOOST_LOG_TRIVIAL(trace) << "Sending KeyExchange for node: " << i; + char* buffer; + size_t len; + + api.get_key_array(&buffer, &len, keypair.pub); + cmix_proto::KeyExchange ke; - ke.set_public_key(keypair.pub, keypair.pub_len); + ke.set_public_key(buffer, len); + + free(buffer); network_connections.at(i).async_send(ke); network_connections.at(i).async_receive([i, this](cmix_proto::CMixMessage message) { @@ -27,8 +36,9 @@ void CMixClient::initialize_connections() { imaclient.set_id("A"); BOOST_LOG_TRIVIAL(trace) << "sending imaclient to node: " << i; network_connections.at(i).async_send(imaclient); - - key_exchange(i); + network_connections.at(i).async_receive([i, this](cmix_proto::CMixMessage message) { + handle_message(i, message); + }); }; network_connections.emplace_back(std::unique_ptr>(new ssl::stream(io_service, *ctx))); @@ -48,12 +58,12 @@ void CMixClient::handle_message(int node_id, cmix_proto::CMixMessage message) { switch(message.contents_case()) { case cmix_proto::CMixMessage::ContentsCase::kKeyexchange: { - BOOST_LOG_TRIVIAL(trace) << "handling keyexchange"; + BOOST_LOG_TRIVIAL(trace) << "handling keyexchange for node: " << node_id; handle_key_exchange(node_id, *message.mutable_keyexchange()); return; } case cmix_proto::CMixMessage::ContentsCase::kBye: { - BOOST_LOG_TRIVIAL(trace) << "handling bye"; + BOOST_LOG_TRIVIAL(trace) << "handling bye for node: " << node_id; network_connections.at(node_id).close(); if(std::all_of(network_connections.begin(), network_connections.end(), [](SSLSenderReceiver const& c) { return !c.is_open(); })) { break; @@ -61,6 +71,11 @@ void CMixClient::handle_message(int node_id, cmix_proto::CMixMessage message) return; } } + case cmix_proto::CMixMessage::ContentsCase::kNodeready: { + BOOST_LOG_TRIVIAL(trace) << "handling NodeReady: " << node_id; + key_exchange(node_id); + return; + } default: { BOOST_LOG_TRIVIAL(error) << "Received unknown message"; } @@ -86,7 +101,11 @@ CMixClient::CMixClient(NetworkDetails details) CMixClient::~CMixClient() { - api.free_key_pair(keypair); + api.free_key_pair(&keypair); + for(auto&& d : data) { + api.free_shared_key(&d.shared_value); + } + } void CMixClient::run() { -- cgit v1.2.3-70-g09d2