Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Jason Dusek <jason.dusek@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: [PATCH] Handle (a) changes in Screech and (b) borrow issue
Date: Tue, 14 Feb 2017 05:09:47 +0000	[thread overview]
Message-ID: <CAO3NbwO_Wh_h9UgGdBRz_BZn4Pp8G=CxMJCSsjZpDZ-ampPTYw@mail.gmail.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 93 bytes --]

Tried submitting this with git send-email but it doesn’t seem to have shown
up yet.
​

[-- Attachment #1.2: Type: text/html, Size: 693 bytes --]

[-- Attachment #2: 0001-Handle-a-changes-in-Screech-and-b-borrow-issue.patch --]
[-- Type: application/octet-stream, Size: 5051 bytes --]

From 1b216dbebd28c77614714bc08293fed65cf0fb4f Mon Sep 17 00:00:00 2001
From: Jason Dusek <jason.dusek@gmail.com>
Date: Mon, 13 Feb 2017 19:16:01 -0800
Subject: [PATCH] Handle (a) changes in Screech and (b) borrow issue

---
 contrib/external-tests/rust/Cargo.toml  |  2 +-
 contrib/external-tests/rust/src/main.rs | 66 +++++++++++++++++----------------
 2 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/contrib/external-tests/rust/Cargo.toml b/contrib/external-tests/rust/Cargo.toml
index c064905..32499e5 100644
--- a/contrib/external-tests/rust/Cargo.toml
+++ b/contrib/external-tests/rust/Cargo.toml
@@ -3,7 +3,7 @@ name = "wireguard-keepalive"
 version = "0.1.0"
 authors = ["jason@zx2c4.com"]
 [dependencies]
-screech = { git = "https://github.com/trevp/screech" }
+screech = { git = "https://github.com/solidsnack/screech", branch = "wg" }
 rust-crypto = "*"
 byteorder = "*"
 rustc-serialize = "*"
diff --git a/contrib/external-tests/rust/src/main.rs b/contrib/external-tests/rust/src/main.rs
index 232375c..65baf47 100644
--- a/contrib/external-tests/rust/src/main.rs
+++ b/contrib/external-tests/rust/src/main.rs
@@ -38,39 +38,43 @@ fn main() {
 	owner.set_s(my_keypair);
 	owner.set_rs(&their_public);
 	let mut cipherstate1 : CipherState<CipherChaChaPoly> = Default::default();
-        let mut cipherstate2 : CipherState<CipherChaChaPoly> = Default::default();
-	let mut handshake = HandshakeState::new_from_owner(&mut owner, true, HandshakePattern::IK, "WireGuard v0 zx2c4 Jason@zx2c4.com".as_bytes(), Some(&my_preshared[..]), &mut cipherstate1, &mut cipherstate2);
+	let mut cipherstate2 : CipherState<CipherChaChaPoly> = Default::default();
 
-	let now = time::get_time();
-	let mut tai64n = [0; 12];
-	BigEndian::write_i64(&mut tai64n[0..], 4611686018427387914ULL + now.sec);
-	BigEndian::write_i32(&mut tai64n[8..], now.nsec);
-	let mut initiation_packet = [0; 148];
-	initiation_packet[0] = 1; /* Type: Initiation */
-	initiation_packet[1] = 0; /* Reserved */
-	initiation_packet[2] = 0; /* Reserved */
-	initiation_packet[3] = 0; /* Reserved */
-	LittleEndian::write_u32(&mut initiation_packet[4..], 28); /* Sender index: 28 (arbitrary) */
-	handshake.write_message(&tai64n, &mut initiation_packet[8..]);
-	let mut mac_material = [0; 148];
-	memcpy(&mut mac_material, &their_public);
-	memcpy(&mut mac_material[32..], &initiation_packet[0..116]);
-	let mut mac = [0; 16];
-	Blake2s::blake2s(&mut mac, &mac_material, &my_preshared);
-	memcpy(&mut initiation_packet[116..], &mac);
-	socket.send_to(&initiation_packet, &send_addr).unwrap();
+	let their_index = {
+		let mut handshake = HandshakeState::new_from_owner(&mut owner, true, HandshakePattern::IK, "WireGuard v0 zx2c4 Jason@zx2c4.com".as_bytes(), Some(&my_preshared[..]), &mut cipherstate1, &mut cipherstate2);
 
-	let mut response_packet = [0; 92];
-	socket.recv_from(&mut response_packet).unwrap();
-	assert!(response_packet[0] == 2 /* Type: Response */);
-	assert!(response_packet[1] == 0 /* Reserved */);
-	assert!(response_packet[2] == 0 /* Reserved */);
-	assert!(response_packet[3] == 0 /* Reserved */);
-	let their_index = LittleEndian::read_u32(&response_packet[4..]);
-	let our_index = LittleEndian::read_u32(&response_packet[8..]);
-	assert!(our_index == 28);
-	let (payload_len, last) = handshake.read_message(&response_packet[12..60], &mut empty_payload).unwrap();
-	assert!(payload_len == 0 && last);
+		let now = time::get_time();
+		let mut tai64n = [0; 12];
+		BigEndian::write_i64(&mut tai64n[0..], 4611686018427387914 + now.sec);
+		BigEndian::write_i32(&mut tai64n[8..], now.nsec);
+		let mut initiation_packet = [0; 148];
+		initiation_packet[0] = 1; /* Type: Initiation */
+		initiation_packet[1] = 0; /* Reserved */
+		initiation_packet[2] = 0; /* Reserved */
+		initiation_packet[3] = 0; /* Reserved */
+		LittleEndian::write_u32(&mut initiation_packet[4..], 28); /* Sender index: 28 (arbitrary) */
+		handshake.write_message(&tai64n, &mut initiation_packet[8..]);
+		let mut mac_material = [0; 148];
+		memcpy(&mut mac_material, &their_public);
+		memcpy(&mut mac_material[32..], &initiation_packet[0..116]);
+		let mut mac = [0; 16];
+		Blake2s::blake2s(&mut mac, &mac_material, &my_preshared);
+		memcpy(&mut initiation_packet[116..], &mac);
+		socket.send_to(&initiation_packet, &send_addr).unwrap();
+
+		let mut response_packet = [0; 92];
+		socket.recv_from(&mut response_packet).unwrap();
+		assert!(response_packet[0] == 2 /* Type: Response */);
+		assert!(response_packet[1] == 0 /* Reserved */);
+		assert!(response_packet[2] == 0 /* Reserved */);
+		assert!(response_packet[3] == 0 /* Reserved */);
+		let their_index = LittleEndian::read_u32(&response_packet[4..]);
+		let our_index = LittleEndian::read_u32(&response_packet[8..]);
+		assert!(our_index == 28);
+		let (payload_len, last) = handshake.read_message(&response_packet[12..60], &mut empty_payload).unwrap();
+		assert!(payload_len == 0 && last);
+		their_index
+	};
 
 	let mut keepalive_packet = [0; 32];
 	keepalive_packet[0] = 4; /* Type: Data */
-- 
2.10.0


             reply	other threads:[~2017-02-14  4:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-14  5:09 Jason Dusek [this message]
2017-02-17 13:50 ` Jason A. Donenfeld
2017-02-17 18:39   ` Jason Dusek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAO3NbwO_Wh_h9UgGdBRz_BZn4Pp8G=CxMJCSsjZpDZ-ampPTYw@mail.gmail.com' \
    --to=jason.dusek@gmail.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).