Skip to content

Commit

Permalink
vopono v0.10.5 - fix error handling in basic_tcp_proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesmcm committed Mar 3, 2023
1 parent 29af9f8 commit 8218e34
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono"
description = "Launch applications via VPN tunnels using temporary network namespaces"
version = "0.10.4"
version = "0.10.5"
authors = ["James McMurray <[email protected]>"]
edition = "2021"
license = "GPL-3.0-or-later"
Expand All @@ -28,7 +28,7 @@ chrono = "0.4"
bs58 = "0.4"
nix = "0.26"
config = "0.13"
basic_tcp_proxy = "0.3"
basic_tcp_proxy = "0.3.1"
strum = "0.24"
strum_macros = "0.24"

Expand Down
8 changes: 4 additions & 4 deletions vopono_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono_core"
description = "Library code for running VPN connections in network namespaces"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
authors = ["James McMurray <[email protected]>"]
license = "GPL-3.0-or-later"
Expand All @@ -24,15 +24,15 @@ ron = "0.8"
walkdir = "2"
# Must use rand 0.7 for compatibility with x25519-dalek for now
rand = "0.7"
toml = "0.5"
toml = "0.7"
ipnet = { version = "2", features = ["serde"] }
reqwest = { default-features = false, version = "0.11", features = [
"blocking",
"json",
"rustls-tls",
] } # TODO: Can we remove Tokio dependency?
sysinfo = "0.27"
base64 = "0.20"
sysinfo = "0.28"
base64 = "0.21"
x25519-dalek = "1"
strum = "0.24"
strum_macros = "0.24"
Expand Down
15 changes: 11 additions & 4 deletions vopono_core/src/util/wireguard.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
use base64::{
engine::{general_purpose, GeneralPurpose},
Engine as _,
};

use rand::rngs::OsRng;
use serde::Deserialize;
use std::fmt::Display;
use x25519_dalek::{PublicKey, StaticSecret};

const B64_ENGINE: GeneralPurpose = general_purpose::STANDARD;

#[derive(Deserialize, Debug, Clone)]
pub struct WgKey {
pub public: String,
Expand All @@ -29,8 +36,8 @@ pub fn generate_keypair() -> anyhow::Result<WgKey> {
// Generate new keypair
let private = StaticSecret::new(OsRng);
let public = PublicKey::from(&private);
let public_key = base64::encode(public.as_bytes());
let private_key = base64::encode(private.to_bytes());
let public_key = B64_ENGINE.encode(public.as_bytes());
let private_key = B64_ENGINE.encode(private.to_bytes());

let keypair = WgKey {
public: public_key,
Expand All @@ -40,12 +47,12 @@ pub fn generate_keypair() -> anyhow::Result<WgKey> {
}

pub fn generate_public_key(private_key: &str) -> anyhow::Result<String> {
let private_bytes = base64::decode(private_key)?;
let private_bytes = B64_ENGINE.decode(private_key)?;
let mut byte_array = [0; 32];
byte_array.copy_from_slice(&private_bytes);

let private = StaticSecret::from(byte_array);
let public = PublicKey::from(&private);
let public_key = base64::encode(public.as_bytes());
let public_key = B64_ENGINE.encode(public.as_bytes());
Ok(public_key)
}

0 comments on commit 8218e34

Please sign in to comment.