Skip to content

Commit

Permalink
Add Reconnect command
Browse files Browse the repository at this point in the history
SSLproxy Pass filtering rules cause sslproxy to disconnect/reconnect to
the server, so the reconnect cmd instructs the server to allow it.
  • Loading branch information
sonertari committed Sep 24, 2021
1 parent 2082e38 commit 488ccaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl Client {

if self.base.proto.set_ecdhcurve {
let ecdh = EcKey::from_curve_name(Nid::from_raw(ssl_nid_by_name(&self.base.proto.ecdhcurve))).expect("Cannot create EcKey");
// TODO: Is this the right way of typecasting to EcKeyRef, the compiler is fine with just &ecdh below, but the editor complains
scb.set_tmp_ecdh(&ecdh as &EcKeyRef<Params>).expect("Cannot set ecdh");
}

Expand Down
12 changes: 12 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ impl Server {
fn run_tcp(&mut self, tcp_stream: &TcpStream, failed: &mut bool) -> bool {
self.base.cmd_trials = 0;
loop {
if self.base.prev_cmd == Command::Reconnect {
debug!(target: &self.base.name, "Executing Reconnect command");
self.base.prev_cmd = Command::None;
break false;
}

if let Err(RecvTimeoutError::Disconnected) = self.base.get_command() {
break false;
}
Expand Down Expand Up @@ -148,6 +154,12 @@ impl Server {
if let Ok(mut ssl_stream) = ssl_stream_result {
self.base.cmd_trials = 0;
exit = loop {
if self.base.prev_cmd == Command::Reconnect {
debug!(target: &self.base.name, "Executing Reconnect command");
self.base.prev_cmd = Command::None;
break false;
}

if let Err(RecvTimeoutError::Disconnected) = self.base.get_command() {
break false;
}
Expand Down
12 changes: 12 additions & 0 deletions src/testend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pub enum Command {
Recv,
SslConnectFail,
Timeout,
Reconnect,
Quit,
Fail,
KeepAlive,
Expand All @@ -229,6 +230,7 @@ impl Command {
Command::Recv => true,
Command::SslConnectFail => true,
Command::Timeout => true,
Command::Reconnect => false,
Command::Quit => false,
Command::Fail => false,
Command::KeepAlive => false,
Expand All @@ -245,6 +247,7 @@ impl Display for Command {
Command::Recv => write!(fmt, "recv"),
Command::SslConnectFail => write!(fmt, "sslconnectfail"),
Command::Timeout => write!(fmt, "timeout"),
Command::Reconnect => write!(fmt, "reconnect"),
Command::Quit => write!(fmt, "quit"),
Command::Fail => write!(fmt, "fail"),
Command::KeepAlive => write!(fmt, "keepalive"),
Expand All @@ -262,6 +265,7 @@ impl FromStr for Command {
"recv" => Ok(Command::Recv),
"sslconnectfail" => Ok(Command::SslConnectFail),
"timeout" => Ok(Command::Timeout),
"reconnect" => Ok(Command::Reconnect),
cmd => {
error!("Command not supported: {}", cmd);
panic!("Command not supported")
Expand Down Expand Up @@ -334,6 +338,7 @@ pub struct TestEndBase {
recv_trials: i32,
pub cmd_trials: i32,
disconnect_detect_trials: i32,
pub prev_cmd: Command,
}

impl TestEndBase {
Expand All @@ -352,6 +357,7 @@ impl TestEndBase {
recv_trials: 0,
cmd_trials: 0,
disconnect_detect_trials: 0,
prev_cmd: Command::None,
};
testend.configure_proto(config);
testend
Expand Down Expand Up @@ -730,6 +736,12 @@ impl TestEndBase {
/// Executes commands which do not try to connect/send/recv
pub fn execute_non_action_command(&mut self) -> CommandResult {
match self.cmd {
Command::Reconnect => {
debug!(target: &self.name, "Received Reconnect command");
self.report_cmd_result(None).unwrap_or(());
// Signal the SSL stream loop to break out, which disconnects the current TCP stream
self.prev_cmd = Command::Reconnect;
}
Command::Quit => {
debug!(target: &self.name, "Received Quit command");
self.reset_command();
Expand Down

0 comments on commit 488ccaf

Please sign in to comment.