Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/configuration/uapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn handle<S: Read + Write, C: Configuration>(stream: &mut S, config: &C) {
(Some(key), Some(value)) => Ok((key, value)),
_ => Err(ConfigError::LineTooLong),
}
};
}

// read operation line
match readline(stream)?.as_str() {
Expand All @@ -53,7 +53,7 @@ pub fn handle<S: Read + Write, C: Configuration>(stream: &mut S, config: &C) {
let mut parser = LineParser::new(config);
loop {
let ln = readline(stream)?;
if ln == "" {
if ln.is_empty() {
break;
}
let (k, v) = keypair(ln.as_str())?;
Expand Down
6 changes: 3 additions & 3 deletions src/configuration/uapi/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<'a, C: Configuration> LineParser<'a, C> {
};

None
};
}

// parse line and update parser state
match self.state {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl<'a, C: Configuration> LineParser<'a, C> {
ParserState::Peer(ref mut peer) => match key {
// opt: new peer
"public_key" => {
flush_peer(self.config, &peer);
flush_peer(self.config, peer);
self.state = Self::new_peer(value)?;
Ok(())
}
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<'a, C: Configuration> LineParser<'a, C> {
// flush (used at end of transcipt)
"" => {
log::trace!("UAPI, Set, processes end of transaction");
flush_peer(self.config, &peer);
flush_peer(self.config, peer);
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/dummy/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl Endpoint for UnitEndpoint {
UnitEndpoint {}
}

fn into_address(&self) -> SocketAddr {
fn to_address(&self) -> SocketAddr {
"127.0.0.1:8080".parse().unwrap()
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ use std::net::SocketAddr;

pub trait Endpoint: Send + 'static {
fn from_address(addr: SocketAddr) -> Self;
fn into_address(&self) -> SocketAddr;
fn to_address(&self) -> SocketAddr;
fn clear_src(&mut self);
}
2 changes: 1 addition & 1 deletion src/platform/linux/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl Endpoint for LinuxEndpoint {
}
}

fn into_address(&self) -> SocketAddr {
fn to_address(&self) -> SocketAddr {
match self {
LinuxEndpoint::V4(EndpointV4 { ref dst, .. }) => {
SocketAddr::V4(SocketAddrV4::new(
Expand Down
1 change: 1 addition & 0 deletions src/platform/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub trait Writer<E: Endpoint>: Send + Sync + 'static {
fn write(&self, buf: &[u8], dst: &mut E) -> Result<(), Self::Error>;
}

#[allow(clippy::upper_case_acronyms)]
pub trait UDP: Send + Sync + 'static {
type Error: Error;
type Endpoint: Endpoint;
Expand Down
22 changes: 2 additions & 20 deletions src/wireguard/handshake/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ pub const MAX_HANDSHAKE_MSG_SIZE: usize = max(
/* Handshake messsages */

#[repr(packed)]
#[derive(Copy, Clone, FromBytes, AsBytes)]
#[derive(Copy, Clone, FromBytes, AsBytes, Default)]
pub struct Response {
pub noise: NoiseResponse, // inner message covered by macs
pub macs: MacsFooter,
}

#[repr(packed)]
#[derive(Copy, Clone, FromBytes, AsBytes)]
#[derive(Copy, Clone, FromBytes, AsBytes, Default)]
pub struct Initiation {
pub noise: NoiseInitiation, // inner message covered by macs
pub macs: MacsFooter,
Expand Down Expand Up @@ -130,24 +130,6 @@ impl CookieReply {

/* Default values */

impl Default for Response {
fn default() -> Self {
Self {
noise: Default::default(),
macs: Default::default(),
}
}
}

impl Default for Initiation {
fn default() -> Self {
Self {
noise: Default::default(),
macs: Default::default(),
}
}
}

impl Default for CookieReply {
fn default() -> Self {
Self {
Expand Down
4 changes: 2 additions & 2 deletions src/wireguard/handshake/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub(super) fn create_initiation<R: RngCore + CryptoRng, O>(

// (C, k) := Kdf2(C, DH(E_priv, S_pub))

let (ck, key) = KDF2!(&ck, shared_secret(&eph_sk, &pk)?.as_bytes());
let (ck, key) = KDF2!(&ck, shared_secret(&eph_sk, pk)?.as_bytes());

// msg.static := Aead(k, 0, S_pub, H)

Expand Down Expand Up @@ -444,7 +444,7 @@ pub(super) fn create_response<R: RngCore + CryptoRng, O>(

// C := Kdf1(C, DH(E_priv, S_pub))

let ck = KDF1!(&ck, shared_secret(&eph_sk, &pk)?.as_bytes());
let ck = KDF1!(&ck, shared_secret(&eph_sk, pk)?.as_bytes());

// (C, tau, k) := Kdf3(C, Q)

Expand Down
2 changes: 1 addition & 1 deletion src/wireguard/handshake/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl<O> Peer<O> {

// check replay attack
if let Some(timestamp_old) = *timestamp {
if !timestamp::compare(&timestamp_old, &timestamp_new) {
if !timestamp::compare(&timestamp_old, timestamp_new) {
return Err(HandshakeError::OldTimestamp);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/wireguard/router/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> DeviceHandle<
///
/// # Returns
pub fn recv(&self, src: E, msg: Vec<u8>) -> Result<(), RouterError> {
log::trace!("receive, src: {}", src.into_address());
log::trace!("receive, src: {}", src.to_address());

// parse / cast
let (header, _) = match LayoutVerified::new_from_prefix(&msg[..]) {
Expand Down
8 changes: 4 additions & 4 deletions src/wireguard/router/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,12 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> Peer<E, C, T,
return;
}
};
if !Arc::ptr_eq(&next, keypair) {
if !Arc::ptr_eq(next, keypair) {
return;
}

// allocate new encryption state
let ekey = Some(EncryptionState::new(&next));
let ekey = Some(EncryptionState::new(next));

// rotate key-wheel
let mut swap = None;
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> PeerHandle<E,
/// Does not convey potential "sticky socket" information
pub fn get_endpoint(&self) -> Option<SocketAddr> {
log::trace!("peer.get_endpoint");
self.peer.endpoint.lock().as_ref().map(|e| e.into_address())
self.peer.endpoint.lock().as_ref().map(|e| e.to_address())
}

/// Zero all key-material related to the peer
Expand Down Expand Up @@ -440,7 +440,7 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> PeerHandle<E,
let release = {
let new = Arc::new(new);
let mut keys = self.peer.keys.lock();
let mut release = mem::replace(&mut keys.retired, vec![]);
let mut release = mem::take(&mut keys.retired);

// update key-wheel
if new.initiator {
Expand Down
10 changes: 4 additions & 6 deletions src/wireguard/router/receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> ParallelJob
* since this can cause dropping of packets (leaving the window) due to scheduling.
*/
fn parallel_work(&self) {
debug_assert_eq!(
self.is_ready(),
false,
debug_assert!(
!self.is_ready(),
"doing parallel work on completed job"
);
log::trace!("processing parallel receive job");
Expand Down Expand Up @@ -109,7 +108,7 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> ParallelJob
}

// check crypto-key router
packet.len() == SIZE_TAG || peer.device.table.check_route(&peer, &packet)
packet.len() == SIZE_TAG || peer.device.table.check_route(peer, packet)
})();

// remove message in case of failure:
Expand All @@ -132,9 +131,8 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> SequentialJob
}

fn sequential_work(self) {
debug_assert_eq!(
debug_assert!(
self.is_ready(),
true,
"doing sequential work on an incomplete job"
);
log::trace!("processing sequential receive job");
Expand Down
8 changes: 3 additions & 5 deletions src/wireguard/router/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> ParallelJob
}

fn parallel_work(&self) {
debug_assert_eq!(
self.is_ready(),
false,
debug_assert!(
!self.is_ready(),
"doing parallel work on completed job"
);
log::trace!("processing parallel send job");
Expand Down Expand Up @@ -117,9 +116,8 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> SequentialJob
}

fn sequential_work(self) {
debug_assert_eq!(
debug_assert!(
self.is_ready(),
true,
"doing sequential work
on an incomplete job"
);
Expand Down
2 changes: 1 addition & 1 deletion src/wireguard/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ pub fn handshake_worker<T: Tun, B: UDP>(
&mut OsRng,
&msg[..],
if under_load {
Some(src.into_address())
Some(src.to_address())
} else {
None
},
Expand Down