aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cookie.rs1
-rw-r--r--src/noise.rs36
-rw-r--r--src/protocol/peer.rs6
3 files changed, 19 insertions, 24 deletions
diff --git a/src/cookie.rs b/src/cookie.rs
index 2fd9f56..c4e1887 100644
--- a/src/cookie.rs
+++ b/src/cookie.rs
@@ -1,5 +1,4 @@
use blake2_rfc::blake2s::blake2s;
-use chacha20_poly1305_aead;
use failure::Error;
use subtle;
diff --git a/src/noise.rs b/src/noise.rs
index 11310ab..c8ef182 100644
--- a/src/noise.rs
+++ b/src/noise.rs
@@ -7,26 +7,22 @@ lazy_static! {
}
/// Wrapper around the `snow` library to easily setup the handshakes for WireGuard.
-pub struct Noise {}
-impl Noise {
- fn new_foundation(local_privkey: &[u8]) -> NoiseBuilder {
- NoiseBuilder::new(NOISE_PARAMS.clone())
- .local_private_key(local_privkey)
- .prologue(b"WireGuard v1 zx2c4 Jason@zx2c4.com")
- }
-
- pub fn build_initiator(local_privkey: &[u8], remote_pubkey: &[u8], psk: &Option<[u8; 32]>) -> Result<Session, Error> {
- Ok(Noise::new_foundation(local_privkey)
- .remote_public_key(remote_pubkey)
- .psk(2, psk.as_ref().unwrap_or_else(|| &[0u8; 32]))
- .build_initiator()
- .map_err(SyncFailure::new)?)
- }
+fn new_foundation(local_privkey: &[u8]) -> NoiseBuilder {
+ NoiseBuilder::new(NOISE_PARAMS.clone())
+ .local_private_key(local_privkey)
+ .prologue(b"WireGuard v1 zx2c4 Jason@zx2c4.com")
+}
- pub fn build_responder(local_privkey: &[u8]) -> Result<Session, Error> {
- Ok(Noise::new_foundation(local_privkey)
- .build_responder()
- .map_err(SyncFailure::new)?)
- }
+pub fn build_initiator(local_privkey: &[u8], remote_pubkey: &[u8], psk: &Option<[u8; 32]>) -> Result<Session, Error> {
+ Ok(new_foundation(local_privkey)
+ .remote_public_key(remote_pubkey)
+ .psk(2, psk.as_ref().unwrap_or_else(|| &[0u8; 32]))
+ .build_initiator()
+ .map_err(SyncFailure::new)?)
+}
+pub fn build_responder(local_privkey: &[u8]) -> Result<Session, Error> {
+ Ok(new_foundation(local_privkey)
+ .build_responder()
+ .map_err(SyncFailure::new)?)
}
diff --git a/src/protocol/peer.rs b/src/protocol/peer.rs
index dd7df9e..bf130db 100644
--- a/src/protocol/peer.rs
+++ b/src/protocol/peer.rs
@@ -3,7 +3,7 @@ use byteorder::{ByteOrder, LittleEndian};
use consts::{TRANSPORT_OVERHEAD, TRANSPORT_HEADER_SIZE, MAX_SEGMENT_SIZE, REJECT_AFTER_MESSAGES};
use cookie;
use failure::{Error, SyncFailure, err_msg};
-use noise::Noise;
+use noise;
use std::{self, mem};
use std::fmt::{self, Debug, Display, Formatter};
use std::net::SocketAddr;
@@ -133,7 +133,7 @@ impl Peer {
}
pub fn initiate_new_session(&mut self, private_key: &[u8]) -> Result<(SocketAddr, Vec<u8>, u32, Option<u32>), Error> {
- let noise = Noise::build_initiator(private_key, &self.info.pub_key, &self.info.psk)?;
+ let noise = noise::build_initiator(private_key, &self.info.pub_key, &self.info.psk)?;
let mut session = Session::from(noise);
let endpoint = self.info.endpoint.ok_or_else(|| err_msg("no known peer endpoint"))?;
let mut packet = vec![0; 148];
@@ -157,7 +157,7 @@ impl Peer {
pub fn process_incoming_handshake(private_key: &[u8], packet: &[u8]) -> Result<IncompleteIncomingHandshake, Error> {
let mut timestamp = [0u8; 12];
- let mut noise = Noise::build_responder(private_key)?;
+ let mut noise = noise::build_responder(private_key)?;
let their_index = LittleEndian::read_u32(&packet[4..]);
let len = noise.read_message(&packet[8..116], &mut timestamp).map_err(SyncFailure::new)?;