aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-10-27 09:25:53 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-10-27 09:25:53 +0200
commit25db9ff8a4cfb4b98aeeaae360e8c718b9c5e20c (patch)
tree079ea63fcc874506072a91b13d2612b510cf158e /client
parent9eaf47d5dfa56ca79ae903aabfc2cf52bdfb981e (diff)
downloadcmix-25db9ff8a4cfb4b98aeeaae360e8c718b9c5e20c.tar.gz
cmix-25db9ff8a4cfb4b98aeeaae360e8c718b9c5e20c.tar.bz2
cmix-25db9ff8a4cfb4b98aeeaae360e8c718b9c5e20c.zip
Adds libgcrypt implementation for elgamal in multiplicative group.
Also adapts the API to both handle sodium and gcrypt libraries.
Diffstat (limited to 'client')
-rw-r--r--client/CMakeLists.txt1
-rw-r--r--client/cmixclient.cpp31
2 files changed, 25 insertions, 7 deletions
diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt
index 68a37da..b8fa287 100644
--- a/client/CMakeLists.txt
+++ b/client/CMakeLists.txt
@@ -15,7 +15,6 @@ else(WIN32)
)
endif(WIN32)
-
target_link_libraries(client
PRIVATE Boost::boost
PRIVATE Boost::program_options
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 <iostream>
+
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<ssl::stream<tcp::socket>>(new ssl::stream<tcp::socket>(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() {