Skip to content

Commit

Permalink
Feature/coconut feature (#805)
Browse files Browse the repository at this point in the history
* 'Coconut' feature in gateway

* Enabled coconut feature in gateway-requests

* Native client coconut feature

* Ibid for socks5 client

* Ibid for wasm client

* Coconut feature flag for validator-api

* Added coconut feature flag to our CI

* build.yml typo

* Continue on windows errors

* Missing quote

* Another typo in build.yml

* Reclaiming disk space when building for windows on CI
  • Loading branch information
jstuczyn authored Oct 11, 2021
1 parent 51dc8c8 commit 4e0e081
Show file tree
Hide file tree
Showing 27 changed files with 397 additions and 205 deletions.
104 changes: 96 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.rust == 'nightly' || matrix.rust == 'beta' }}
continue-on-error: ${{ matrix.rust == 'nightly' || matrix.rust == 'beta' || matrix.os == 'windows-latest' }}
strategy:
matrix:
rust: [stable, beta, nightly]
Expand All @@ -16,33 +16,121 @@ jobs:
run: sudo apt-get update && sudo apt-get install libwebkit2gtk-4.0-dev build-essential curl wget libssl-dev libgtk-3-dev squashfs-tools
if: matrix.os == 'ubuntu-latest'

- uses: actions/checkout@v2
- name: Check out repository code
uses: actions/checkout@v2

- uses: actions-rs/toolchain@v1
- name: Install rust toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
components: rustfmt, clippy

- uses: actions-rs/cargo@v1
- name: Build all binaries
uses: actions-rs/cargo@v1
with:
command: build
args: --all


- uses: actions-rs/cargo@v1
- name: Run all tests
uses: actions-rs/cargo@v1
with:
command: test
args: --all

- uses: actions-rs/cargo@v1
- name: Check formatting
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check

- uses: actions-rs/cargo@v1
- name: Run clippy
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != 'nightly' }}
with:
command: clippy
args: -- -D warnings

# COCONUT stuff
- name: Reclaim some disk space (because Windows is being annoying)
uses: actions-rs/cargo@v1
if: ${{ matrix.os == 'windows-latest' }}
with:
command: clean

# BUILD
- name: Build gateway with coconut feature
uses: actions-rs/cargo@v1
with:
command: build
args: --bin nym-gateway --features=coconut

- name: Build native client with coconut feature
uses: actions-rs/cargo@v1
with:
command: build
args: --bin nym-client --features=coconut

- name: Build socks5 client with coconut feature
uses: actions-rs/cargo@v1
with:
command: build
args: --bin nym-socks5-client --features=coconut

- name: Build validator-api with coconut feature
uses: actions-rs/cargo@v1
with:
command: build
args: --bin nym-validator-api --features=coconut

# TEST
- name: Test gateway with coconut feature
uses: actions-rs/cargo@v1
with:
command: test
args: --bin nym-gateway --features=coconut

- name: Test native client with coconut feature
uses: actions-rs/cargo@v1
with:
command: test
args: --bin nym-client --features=coconut

- name: Test socks5 client with coconut feature
uses: actions-rs/cargo@v1
with:
command: test
args: --bin nym-socks5-client --features=coconut

- name: Test validator-api with coconut feature
uses: actions-rs/cargo@v1
with:
command: test
args: --bin nym-validator-api --features=coconut

# CLIPPY

- name: Run clippy on gateway with coconut feature
uses: actions-rs/cargo@v1
with:
command: clippy
args: --bin nym-gateway --features=coconut -- -D warnings

- name: Run clippy on native client with coconut feature
uses: actions-rs/cargo@v1
with:
command: clippy
args: --bin nym-client --features=coconut -- -D warnings

- name: Run clippy on socks5 client with coconut feature
uses: actions-rs/cargo@v1
with:
command: clippy
args: --bin nym-socks5-client --features=coconut -- -D warnings

- name: Run clippy on validator-api with coconut feature
uses: actions-rs/cargo@v1
with:
command: clippy
args: --bin nym-validator-api --features=coconut -- -D warnings
5 changes: 5 additions & 0 deletions .github/workflows/wasm_client_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ jobs:
command: build
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown

- uses: actions-rs/cargo@v1
with:
command: build
args: --manifest-path clients/webassembly/Cargo.toml --target wasm32-unknown-unknown --features=coconut

# for some reason this does not seem to work correctly, leave it for later, building is good enough for now
# - uses: actions-rs/cargo@v1
# with:
Expand Down
7 changes: 5 additions & 2 deletions clients/native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ tokio-tungstenite = "0.14" # websocket

## internal
client-core = { path = "../client-core" }
coconut-interface = { path = "../../common/coconut-interface" }
credentials = { path = "../../common/credentials" }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
credentials = { path = "../../common/credentials", optional = true }
config = { path = "../../common/config" }
crypto = { path = "../../common/crypto" }
gateway-client = { path = "../../common/client-libs/gateway-client" }
Expand All @@ -44,5 +44,8 @@ websocket-requests = { path = "websocket-requests" }
validator-client = { path = "../../common/client-libs/validator-client" }
version-checker = { path = "../../common/version-checker" }

[features]
coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut"]

[dev-dependencies]
serde_json = "1.0" # for the "textsend" example
20 changes: 13 additions & 7 deletions clients/native/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ use client_core::client::topology_control::{
TopologyAccessor, TopologyRefresher, TopologyRefresherConfig,
};
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
use coconut_interface::Credential;
use credentials::bandwidth::prepare_for_spending;
use credentials::obtain_aggregate_verification_key;
use crypto::asymmetric::identity;
use futures::channel::mpsc;
use gateway_client::{
Expand All @@ -38,6 +35,11 @@ use nymsphinx::anonymous_replies::ReplySurb;
use nymsphinx::receiver::ReconstructedMessage;
use tokio::runtime::Runtime;

#[cfg(feature = "coconut")]
use coconut_interface::Credential;
#[cfg(feature = "coconut")]
use credentials::{bandwidth::prepare_for_spending, obtain_aggregate_verification_key};

pub(crate) mod config;

pub struct NymClient {
Expand Down Expand Up @@ -166,7 +168,8 @@ impl NymClient {
.start(self.runtime.handle())
}

async fn prepare_credential(&self) -> Credential {
#[cfg(feature = "coconut")]
async fn prepare_coconut_credential(&self) -> Credential {
let verification_key = obtain_aggregate_verification_key(
&self.config.get_base().get_validator_api_endpoints(),
)
Expand Down Expand Up @@ -208,7 +211,8 @@ impl NymClient {
.expect("provided gateway id is invalid!");

self.runtime.block_on(async {
let coconut_credential = self.prepare_credential().await;
#[cfg(feature = "coconut")]
let coconut_credential = self.prepare_coconut_credential().await;

let mut gateway_client = GatewayClient::new(
gateway_address,
Expand All @@ -218,11 +222,13 @@ impl NymClient {
mixnet_message_sender,
ack_sender,
self.config.get_base().get_gateway_response_timeout(),
coconut_credential,
);

gateway_client
.authenticate_and_start()
.authenticate_and_start(
#[cfg(feature = "coconut")]
Some(coconut_credential),
)
.await
.expect("could not authenticate and start up the gateway connection");

Expand Down
31 changes: 2 additions & 29 deletions clients/native/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use crate::commands::override_config;
use clap::{App, Arg, ArgMatches};
use client_core::client::key_manager::KeyManager;
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
use coconut_interface::Credential;
use config::NymConfig;
use credentials::bandwidth::prepare_for_spending;
use credentials::obtain_aggregate_verification_key;
use crypto::asymmetric::{encryption, identity};
use gateway_client::GatewayClient;
use gateway_requests::registration::handshake::SharedKeys;
Expand Down Expand Up @@ -60,34 +57,15 @@ pub fn command_args<'a, 'b>() -> clap::App<'a, 'b> {
)
}

// this behaviour should definitely be changed, we shouldn't
// need to get bandwidth credential for registration
async fn prepare_temporary_credential(validators: &[Url], raw_identity: &[u8]) -> Credential {
let verification_key = obtain_aggregate_verification_key(validators)
.await
.expect("could not obtain aggregate verification key of validators");

let bandwidth_credential = credentials::bandwidth::obtain_signature(raw_identity, validators)
.await
.expect("could not obtain bandwidth credential");

prepare_for_spending(raw_identity, &bandwidth_credential, &verification_key)
.expect("could not prepare out bandwidth credential for spending")
}

async fn register_with_gateway(
gateway: &gateway::Node,
our_identity: Arc<identity::KeyPair>,
validator_urls: Vec<Url>,
) -> Arc<SharedKeys> {
let timeout = Duration::from_millis(1500);
let coconut_credential =
prepare_temporary_credential(&validator_urls, &our_identity.public_key().to_bytes()).await;
let mut gateway_client = GatewayClient::new_init(
gateway.clients_address(),
gateway.identity_key,
our_identity.clone(),
coconut_credential,
timeout,
);
gateway_client
Expand Down Expand Up @@ -210,13 +188,8 @@ pub fn execute(matches: &ArgMatches) {
config
.get_base_mut()
.with_gateway_id(gate_details.identity_key.to_base58_string());
let validator_urls = config.get_base().get_validator_api_endpoints();
let shared_keys = register_with_gateway(
&gate_details,
key_manager.identity_keypair(),
validator_urls,
)
.await;
let shared_keys =
register_with_gateway(&gate_details, key_manager.identity_keypair()).await;
(shared_keys, gate_details.clients_address())
};

Expand Down
7 changes: 5 additions & 2 deletions clients/socks5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ url = "2.2"

# internal
client-core = { path = "../client-core" }
coconut-interface = { path = "../../common/coconut-interface" }
credentials = { path = "../../common/credentials" }
coconut-interface = { path = "../../common/coconut-interface", optional = true }
credentials = { path = "../../common/credentials", optional = true }
config = { path = "../../common/config" }
crypto = { path = "../../common/crypto" }
gateway-client = { path = "../../common/client-libs/gateway-client" }
Expand All @@ -38,3 +38,6 @@ pemstore = { path = "../../common/pemstore" }
proxy-helpers = { path = "../../common/socks5/proxy-helpers" }
validator-client = { path = "../../common/client-libs/validator-client" }
version-checker = { path = "../../common/version-checker" }

[features]
coconut = ["coconut-interface", "credentials", "gateway-requests/coconut", "gateway-client/coconut"]
20 changes: 13 additions & 7 deletions clients/socks5/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ use client_core::client::topology_control::{
TopologyAccessor, TopologyRefresher, TopologyRefresherConfig,
};
use client_core::config::persistence::key_pathfinder::ClientKeyPathfinder;
use coconut_interface::Credential;
use credentials::bandwidth::prepare_for_spending;
use credentials::obtain_aggregate_verification_key;
use crypto::asymmetric::identity;
use futures::channel::mpsc;
use gateway_client::{
Expand All @@ -37,6 +34,11 @@ use nymsphinx::addressing::clients::Recipient;
use nymsphinx::addressing::nodes::NodeIdentity;
use tokio::runtime::Runtime;

#[cfg(feature = "coconut")]
use coconut_interface::Credential;
#[cfg(feature = "coconut")]
use credentials::{bandwidth::prepare_for_spending, obtain_aggregate_verification_key};

pub(crate) mod config;

pub struct NymClient {
Expand Down Expand Up @@ -154,7 +156,8 @@ impl NymClient {
.start(self.runtime.handle())
}

async fn prepare_credential(&self) -> Credential {
#[cfg(feature = "coconut")]
async fn prepare_coconut_credential(&self) -> Credential {
let verification_key = obtain_aggregate_verification_key(
&self.config.get_base().get_validator_api_endpoints(),
)
Expand Down Expand Up @@ -196,7 +199,8 @@ impl NymClient {
.expect("provided gateway id is invalid!");

self.runtime.block_on(async {
let coconut_credential = self.prepare_credential().await;
#[cfg(feature = "coconut")]
let coconut_credential = self.prepare_coconut_credential().await;

let mut gateway_client = GatewayClient::new(
gateway_address,
Expand All @@ -206,11 +210,13 @@ impl NymClient {
mixnet_message_sender,
ack_sender,
self.config.get_base().get_gateway_response_timeout(),
coconut_credential,
);

gateway_client
.authenticate_and_start()
.authenticate_and_start(
#[cfg(feature = "coconut")]
Some(coconut_credential),
)
.await
.expect("could not authenticate and start up the gateway connection");

Expand Down
Loading

0 comments on commit 4e0e081

Please sign in to comment.