aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-23 11:43:29 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-08-23 11:43:29 +0200
commite88ed5d02da3687bb1315edeea853f8588bb445a (patch)
tree9e6606e4246087ee15a7d4d7ea9c88f9303688dc
parentDerieve clone for timer (handle) (diff)
downloadwireguard-rs-e88ed5d02da3687bb1315edeea853f8588bb445a.tar.xz
wireguard-rs-e88ed5d02da3687bb1315edeea853f8588bb445a.zip
Allow DoS mitigation to take any endpoint impl.
-rw-r--r--src/handshake/device.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/handshake/device.rs b/src/handshake/device.rs
index 1c7a30d..d29c41b 100644
--- a/src/handshake/device.rs
+++ b/src/handshake/device.rs
@@ -197,12 +197,12 @@ where
/// # Arguments
///
/// * `msg` - Byte slice containing the message (untrusted input)
- pub fn process<R: RngCore + CryptoRng>(
+ pub fn process<'a, R: RngCore + CryptoRng, S>(
&self,
- rng: &mut R,
- msg: &[u8], // message buffer
- src: Option<&SocketAddr>, // optional source address, set when "under load"
- ) -> Result<Output<T>, HandshakeError> {
+ rng: &mut R, // rng instance to sample randomness from
+ msg: &[u8], // message buffer
+ src: Option<&'a S>, // optional source endpoint, set when "under load"
+ ) -> Result<Output<T>, HandshakeError> where &'a S: Into<&'a SocketAddr> {
match msg.get(0) {
Some(&TYPE_INITIATION) => {
// parse message
@@ -213,6 +213,9 @@ where
// address validation & DoS mitigation
if let Some(src) = src {
+ // obtain ref to socket addr
+ let src = src.into();
+
// check mac2 field
if !self.macs.check_mac2(msg.noise.as_bytes(), src, &msg.macs) {
let mut reply = Default::default();
@@ -269,6 +272,9 @@ where
// address validation & DoS mitigation
if let Some(src) = src {
+ // obtain ref to socket addr
+ let src = src.into();
+
// check mac2 field
if !self.macs.check_mac2(msg.noise.as_bytes(), src, &msg.macs) {
let mut reply = Default::default();