Skip to content

Commit

Permalink
Update tokio dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
CBenoit committed Apr 13, 2021
1 parent 66aa58c commit 8570b33
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 305 deletions.
350 changes: 157 additions & 193 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 6 additions & 10 deletions devolutions-gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ url = "1.7.1"
url_serde = "0.2.0"
hostname = "^0.3"
lazy_static = "1.2.0"
tokio = { version = "0.3.4", features = ["signal", "net", "io-util", "time", "rt", "rt-multi-thread", "sync", "macros"]}
tokio = { version = "1", features = ["signal", "net", "io-util", "time", "rt", "rt-multi-thread", "sync", "macros"]}
tokio_02 = {version = "0.2", package = "tokio", features = ["rt-core", "time"]}
tokio-util = { version = "0.4", features = ["codec"] }
tokio-tungstenite = { git = "https://github.com/snapview/tokio-tungstenite", rev = "3c6d4280d77fdff3e25f68ad703d94e89f38dae2", features = [ "tls" ] }
tokio-compat-02 = "0.1"
tokio-util = { version = "0.6", features = ["codec"] }
tokio-tungstenite = "0.14"
tokio-compat-02 = "0.2"
tokio-rustls = { version = "0.22", features = ["dangerous_configuration"] }
futures = "0.3"
webpki = "0.21.0"
native-tls = "0.2"
byteorder = "1.2.7"
bytes = "0.5"
bytes = "1"
uuid = { version = "0.8", features = ["v4", "serde"] }
pcap-file = "0.10.0"
packet = { git = "https://github.com/fdubois1/rust-packet.git" }
Expand Down Expand Up @@ -62,11 +63,6 @@ version = "2.8"
default-features = false
features = ["https", "json", "macro", "form"]

[dependencies.tokio-rustls]
git = "https://github.com/tokio-rs/tls.git"
rev = "a517e1d0a636359c4e54b0735d7f4e73b786d2c0"
features = ["dangerous_configuration"]

[target.'cfg(windows)'.dependencies]
winapi = { version = "0.3", features = ["winbase", "winuser", "winsvc", "libloaderapi", "errhandlingapi", "winerror"] }

Expand Down
14 changes: 7 additions & 7 deletions devolutions-gateway/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ cfg_if! {

#[derive(Debug, Clone, Copy)]
pub enum Protocol {
WAYK,
RDP,
UNKNOWN,
Wayk,
Rdp,
Unknown,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -116,7 +116,7 @@ impl Default for Config {
hostname: default_hostname,
routing_url: None,
capture_path: None,
protocol: Protocol::UNKNOWN,
protocol: Protocol::Unknown,
log_file: None,
application_protocols: Vec::new(),
certificate: CertificateConfig {
Expand Down Expand Up @@ -567,9 +567,9 @@ impl Config {

if let Some(protocol) = matches.value_of(ARG_PROTOCOL) {
match protocol {
"wayk" => config.protocol = Protocol::WAYK,
"rdp" => config.protocol = Protocol::RDP,
_ => config.protocol = Protocol::UNKNOWN,
"wayk" => config.protocol = Protocol::Wayk,
"rdp" => config.protocol = Protocol::Rdp,
_ => config.protocol = Protocol::Unknown,
}
};

Expand Down
10 changes: 4 additions & 6 deletions devolutions-gateway/src/interceptor/pcap_recording.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::interceptor::{PacketInterceptor, PeerInfo};
use crate::plugin_manager::{PacketsParser, Recorder, PLUGIN_MANAGER};
use slog_scope::{debug, error};
use std::{
net::SocketAddr,
sync::{Arc, Condvar, Mutex},
thread,
time::Duration,
};
use std::net::SocketAddr;
use std::sync::{Arc, Condvar, Mutex};
use std::thread;
use std::time::Duration;

#[derive(Debug)]
enum RecordingState {
Expand Down
37 changes: 15 additions & 22 deletions devolutions-gateway/src/jet_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,26 @@ use std::pin::Pin;
use std::sync::Arc;

use byteorder::{BigEndian, LittleEndian, ReadBytesExt};
use jet_proto::{
accept::{JetAcceptReq, JetAcceptRsp},
connect::{JetConnectReq, JetConnectRsp},
test::{JetTestReq, JetTestRsp},
JetMessage, StatusCode, JET_VERSION_V1, JET_VERSION_V2,
};
use jet_proto::accept::{JetAcceptReq, JetAcceptRsp};
use jet_proto::connect::{JetConnectReq, JetConnectRsp};
use jet_proto::test::{JetTestReq, JetTestRsp};
use jet_proto::{JetMessage, StatusCode, JET_VERSION_V1, JET_VERSION_V2};
use slog_scope::{debug, error};
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::sync::Mutex;
use uuid::Uuid;

use crate::{
config::Config,
http::controllers::jet::{remove_association, JetTpType},
interceptor::pcap_recording::PcapRecordingInterceptor,
jet::{
association::Association,
candidate::{Candidate, CandidateState},
TransportType,
},
transport::{tcp::TcpTransport, JetTransport, Transport},
utils::{
association::{remove_jet_association, ACCEPT_REQUEST_TIMEOUT},
create_tls_connector, into_other_io_error as error_other,
},
Proxy,
};
use crate::config::Config;
use crate::http::controllers::jet::{remove_association, JetTpType};
use crate::interceptor::pcap_recording::PcapRecordingInterceptor;
use crate::jet::association::Association;
use crate::jet::candidate::{Candidate, CandidateState};
use crate::jet::TransportType;
use crate::transport::tcp::TcpTransport;
use crate::transport::{JetTransport, Transport};
use crate::utils::association::{remove_jet_association, ACCEPT_REQUEST_TIMEOUT};
use crate::utils::{create_tls_connector, into_other_io_error as error_other};
use crate::Proxy;

use tokio_rustls::{TlsAcceptor, TlsStream};

Expand Down
3 changes: 2 additions & 1 deletion devolutions-gateway/src/plugin_manager.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use dlopen::{symbor::Library, Error};
use dlopen::symbor::Library;
use dlopen::Error;
use lazy_static::lazy_static;
use slog_scope::debug;
use std::sync::{Arc, Mutex};
Expand Down
5 changes: 4 additions & 1 deletion devolutions-gateway/src/plugin_manager/packets_parsing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::utils::into_other_io_error;
use dlopen::symbor::{Library, SymBorApi, Symbol};
use dlopen_derive::SymBorApi;
use std::{io::Error, mem::transmute, slice::from_raw_parts, sync::Arc};
use std::io::Error;
use std::mem::transmute;
use std::slice::from_raw_parts;
use std::sync::Arc;

pub type NowPacketParser = usize;

Expand Down
8 changes: 7 additions & 1 deletion devolutions-gateway/src/plugin_manager/plugin_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ use crate::utils::into_other_io_error;
use dlopen::symbor::{Library, SymBorApi, Symbol};
use dlopen_derive::SymBorApi;
use slog_scope::{debug, error};
use std::{convert::TryFrom, ffi::CStr, io::Error, mem::transmute, os::raw::c_char, slice::from_raw_parts, sync::Arc};
use std::convert::TryFrom;
use std::ffi::CStr;
use std::io::Error;
use std::mem::transmute;
use std::os::raw::c_char;
use std::slice::from_raw_parts;
use std::sync::Arc;

#[derive(Debug, PartialEq)]
pub enum PluginCapabilities {
Expand Down
14 changes: 6 additions & 8 deletions devolutions-gateway/src/plugin_manager/recording.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ use crate::plugin_manager::packets_parsing::ImageUpdate;
use crate::utils::into_other_io_error;
use dlopen::symbor::{Library, SymBorApi, Symbol};
use dlopen_derive::SymBorApi;
use std::ffi::CString;
use std::io::Error;
use std::mem::transmute;
use std::os::raw::c_char;
use std::path::{Path, PathBuf};
use std::string::FromUtf8Error;
use std::{
ffi::CString,
io::Error,
mem::transmute,
os::raw::c_char,
path::{Path, PathBuf},
sync::Arc,
};
use std::sync::Arc;

pub type RecordingContext = usize;
const MAX_PATH_LEN: usize = 512;
Expand Down
20 changes: 9 additions & 11 deletions devolutions-gateway/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
use crate::config::{Config, Protocol};
use crate::interceptor::pcap::PcapInterceptor;
use crate::interceptor::rdp::RdpMessageReader;
use crate::interceptor::PacketInterceptor;
use crate::interceptor::{MessageReader, UnknownMessageReader, WaykMessageReader};
use crate::interceptor::{MessageReader, PacketInterceptor, UnknownMessageReader, WaykMessageReader};
use crate::rdp::{DvcManager, RDP8_GRAPHICS_PIPELINE_NAME};
use crate::transport::{Transport, BIP_BUFFER_LEN};
use crate::SESSION_IN_PROGRESS_COUNT;
use futures::{select, FutureExt, StreamExt};
use slog_scope::{info, warn};
use spsc_bip_buffer::bip_buffer_with_len;
use std::{
collections::HashMap,
io,
path::PathBuf,
sync::{atomic::Ordering, Arc},
};
use std::collections::HashMap;
use std::io;
use std::path::PathBuf;
use std::sync::atomic::Ordering;
use std::sync::Arc;

pub struct Proxy {
config: Arc<Config>,
Expand All @@ -31,12 +29,12 @@ impl Proxy {
client_transport: U,
) -> Result<(), io::Error> {
match self.config.protocol {
Protocol::WAYK => {
Protocol::Wayk => {
info!("WaykMessageReader will be used to interpret application protocol.");
self.build_with_message_reader(server_transport, client_transport, Some(Box::new(WaykMessageReader)))
.await
}
Protocol::RDP => {
Protocol::Rdp => {
info!("RdpMessageReader will be used to interpret application protocol");
self.build_with_message_reader(
server_transport,
Expand All @@ -50,7 +48,7 @@ impl Proxy {
)
.await
}
Protocol::UNKNOWN => {
Protocol::Unknown => {
warn!("Protocol is unknown. Data received will not be split to get application message.");
self.build_with_message_reader(server_transport, client_transport, Some(Box::new(UnknownMessageReader)))
.await
Expand Down
35 changes: 15 additions & 20 deletions devolutions-gateway/src/rdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ mod preconnection_pdu;

mod sequence_future;

use self::accept_connection_future::AcceptConnectionFuture;
use self::connection_sequence_future::ConnectionSequenceFuture;
use self::sequence_future::create_downgrade_dvc_capabilities_future;
use crate::config::Config;
use crate::interceptor::rdp::RdpMessageReader;
use crate::jet_client::JetAssociationsMap;
use crate::jet_rendezvous_tcp_proxy::JetRendezvousTcpProxy;
use crate::transport::tcp::TcpTransport;
use crate::transport::{JetTransport, Transport};
use crate::{utils, Proxy};
use accept_connection_future::AcceptConnectionMode;
use slog_scope::{error, info};

use sspi::internal::credssp;
use sspi::AuthIdentity;

use bytes::Buf;
use std::io;
use std::sync::Arc;
use tokio::io::AsyncWriteExt;
Expand All @@ -23,18 +30,6 @@ use url::Url;

pub use self::dvc_manager::{DvcManager, RDP8_GRAPHICS_PIPELINE_NAME};

use self::accept_connection_future::AcceptConnectionFuture;
use self::connection_sequence_future::ConnectionSequenceFuture;
use self::sequence_future::create_downgrade_dvc_capabilities_future;

use crate::config::Config;
use crate::interceptor::rdp::RdpMessageReader;
use crate::jet_client::JetAssociationsMap;
use crate::jet_rendezvous_tcp_proxy::JetRendezvousTcpProxy;
use crate::transport::tcp::TcpTransport;
use crate::transport::{JetTransport, Transport};
use crate::{utils, Proxy};

pub const GLOBAL_CHANNEL_NAME: &str = "GLOBAL";
pub const USER_CHANNEL_NAME: &str = "USER";
pub const DR_DYN_VC_CHANNEL_NAME: &str = "drdynvc";
Expand Down Expand Up @@ -102,13 +97,15 @@ impl RdpClient {
})?;

match mode {
AcceptConnectionMode::RdpTcp { url, leftover_request } => {
AcceptConnectionMode::RdpTcp {
url,
mut leftover_request,
} => {
info!("Starting RDP-TCP redirection");

let mut server_conn = TcpTransport::connect(&url).await?;
let client_transport = TcpTransport::new(client);

let mut leftover_request = leftover_request.bytes();
server_conn.write_buf(&mut leftover_request).await.map_err(|e| {
error!("Failed to write leftover request: {}", e);
e
Expand All @@ -127,10 +124,8 @@ impl RdpClient {
} => {
info!("Starting RdpTcpRendezvous redirection");

let leftover_request = leftover_request.bytes();

JetRendezvousTcpProxy::new(jet_associations, JetTransport::new_tcp(client), association_id)
.proxy(config, leftover_request)
.proxy(config, &*leftover_request)
.await
}
AcceptConnectionMode::RdpTls { identity, request } => {
Expand Down
6 changes: 2 additions & 4 deletions devolutions-gateway/src/transport/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ use tokio::net::TcpStream;
use tokio_rustls::TlsStream;
use url::Url;

use crate::{
transport::{JetFuture, JetSinkImpl, JetSinkType, JetStreamImpl, JetStreamType, Transport},
utils::{create_tls_connector, resolve_url_to_socket_arr},
};
use crate::transport::{JetFuture, JetSinkImpl, JetSinkType, JetStreamImpl, JetStreamType, Transport};
use crate::utils::{create_tls_connector, resolve_url_to_socket_arr};

#[allow(clippy::large_enum_variant)]
pub enum TcpStreamWrapper {
Expand Down
3 changes: 1 addition & 2 deletions devolutions-gateway/src/transport/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};
use tokio::net::TcpStream;
use tokio_compat_02::IoCompat;
use tokio_rustls::{rustls, TlsConnector, TlsStream};
use tokio_tungstenite::tungstenite;
use tokio_tungstenite::tungstenite::handshake::client::Request;
use tokio_tungstenite::tungstenite::protocol::Role;
use tokio_tungstenite::WebSocketStream;
use tokio_tungstenite::{tungstenite, WebSocketStream};
use url::Url;

enum WsStreamSendState {
Expand Down
33 changes: 14 additions & 19 deletions devolutions-gateway/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
pub mod association;

use std::{
collections::HashMap,
fs,
future::Future,
hash::Hash,
io::{self, BufReader},
net::SocketAddr,
pin::Pin,
sync::Arc,
task::{Context, Poll},
};

use futures::{ready, stream::Stream};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::{lookup_host, TcpListener, TcpStream},
};
use crate::config::CertificateConfig;
use futures::ready;
use futures::stream::Stream;
use std::collections::HashMap;
use std::fs;
use std::future::Future;
use std::hash::Hash;
use std::io::{self, BufReader};
use std::net::SocketAddr;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::{lookup_host, TcpListener, TcpStream};
use tokio_rustls::{rustls, Connect, TlsConnector};
use tokio_util::codec::{Decoder, Encoder, Framed, FramedParts};
use url::Url;
use x509_parser::parse_x509_der;

use crate::config::CertificateConfig;

pub mod danger_transport {
use tokio_rustls::rustls;

Expand Down

0 comments on commit 8570b33

Please sign in to comment.