+// clib_ffi.rs
+//
+// Tests the C FFI interface from Rust.
+// Performs handshake and exchanges a few messages.
+//
use ossuary::clib::{
ossuary_create_connection,
ossuary_destroy_connection,
&mut out_len);
let _ = stream.write_all(&out_buf[0..sz as usize]).unwrap();
+ let mut msgs = Vec::<String>::new();
let in_buf = reader.fill_buf().unwrap();
if in_buf.len() > 0 {
let mut out_len = out_buf.len() as u16;
if len != -1 {
println!("CLIB READ: {:?}",
std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap());
+ msgs.push(std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap().into());
reader.consume(len as usize);
}
}
+ assert_eq!(msgs, vec!("from client".to_string()));
ossuary_destroy_connection(&mut conn);
break;
//let mut stream = std::io::BufReader::new(stream);
let mut count = 0;
+ let mut msgs = Vec::<String>::new();
loop {
let in_buf = reader.fill_buf().unwrap();
if in_buf.len() == 0 || count == 2 {
if len > 0 {
println!("CLIB READ: {:?}",
std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap());
+ msgs.push(std::str::from_utf8(&out_buf[0..out_len as usize]).unwrap().into());
reader.consume(len as usize);
count += 1;
}
}
+ assert_eq!(msgs, vec!("from server 1".to_string(), "from server 2".to_string()));
ossuary_destroy_connection(&mut conn);
Ok(())
+// corruption.rs
+//
+// Test cases for Ossuary handshakes with packet corruption
+//
+// Runs through a bunch of rounds of connection handshaking with corrupted data
+// injected at known points throughout the handshake. Verifies that the correct
+// errors are raised, and that the connection either retries successfully or
+// fails permanently depending on the test.
+//
use ossuary::{OssuaryConnection, ConnectionType};
use ossuary::OssuaryError;
+#[derive(Debug)]
+enum Corruption {
+ ClientKey,
+ ClientNonce,
+ ClientChal,
+ ClientAuth,
+ ClientInvalidPkt,
+ ServerKey,
+ ServerNonce,
+ ServerAuth,
+ ServerInvalidPkt,
+}
+
#[test]
fn corruption() {
- #[derive(Debug)]
- enum Corruption {
- ClientKey,
- ClientNonce,
- ClientChal,
- ClientAuth,
- ClientInvalidPkt,
- ServerKey,
- ServerNonce,
- ServerAuth,
- ServerInvalidPkt,
- };
-
// Corruption test tuple format:
// (test type, loop iteration, byte offset, byte value, expected recv error, permanent)
let corruptions = [
LoopClient,
LoopServer,
};
+
for corruption in &corruptions {
println!("Corruption test: {:?}", corruption.0);
let server_secret_key = &[
_ => panic!("Handshake failed: {:?}", e),
},
}
+ // Check if handshake is done and call recv_data because recv_handshake()
+ // does not respond to connection resets after the connection is (thought
+ // to be) established.
match send_conn.handshake_done() {
Ok(true) => {
let mut plaintext = Vec::<u8>::new();