Skip to content

Commit

Permalink
upgrade to edition 2021 and dependencies upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
fplust committed May 27, 2022
1 parent 7ac880d commit 5a852e5
Show file tree
Hide file tree
Showing 21 changed files with 93 additions and 101 deletions.
21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ keywords = ["rdp", "security", "network", "windows"]
categories = ["network"]
license = "MIT"
documentation = "https://docs.rs/rdp-rs"
edition = "2021"

[lib]
name = "rdp"
Expand All @@ -27,17 +28,17 @@ mstsc-rs = ["hex", "winapi", "minifb", "clap", "libc"]

[dependencies]
native-tls = "^0.2"
byteorder = "^1.3"
byteorder = "^1.4"
bufstream = "0.1"
indexmap = "^1.3"
yasna = { version = "^0.3" }
md4 = "^0.8"
hmac = "^0.7"
md-5 = "^0.8"
rand = "^0.7"
num-bigint = "^0.2"
x509-parser = "0.6.5"
num_enum = "0.4.3"
indexmap = "^1.8"
yasna = { version = "^0.5" }
md4 = "^0.10"
hmac = "^0.12"
md-5 = "^0.10"
rand = "^0.8"
num-bigint = "^0.4"
x509-parser = "0.13"
num_enum = "0.5"

# for mtsc-rs
hex = { version = "^0.4", optional = true }
Expand Down
10 changes: 0 additions & 10 deletions src/bin/mstsc-rs.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
#[cfg(target_os = "windows")]
extern crate winapi;
#[cfg(any(target_os = "linux", target_os = "macos"))]
extern crate libc;
extern crate minifb;
extern crate rdp;
extern crate hex;
extern crate clap;
extern crate hmac;

use minifb::{Key, Window, WindowOptions, MouseMode, MouseButton, KeyRepeat};
use std::net::{SocketAddr, TcpStream};
use std::io::{Read, Write};
Expand Down
2 changes: 1 addition & 1 deletion src/codec/rle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use std::io::{Cursor, Read};
use byteorder::{ReadBytesExt, LittleEndian};

Expand Down
6 changes: 3 additions & 3 deletions src/core/capability.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use model::data::{Component, U16, U32, DynOption, MessageOption, Message, DataType, Check, Trame, to_vec};
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::data::{Component, U16, U32, DynOption, MessageOption, Message, DataType, Check, Trame, to_vec};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use std::io::Cursor;
use core::gcc::{KeyboardLayout, KeyboardType};
use crate::core::gcc::{KeyboardLayout, KeyboardType};
use num_enum::TryFromPrimitive;
use std::convert::TryFrom;

Expand Down
22 changes: 11 additions & 11 deletions src/core/client.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use core::x224;
use core::gcc::KeyboardLayout;
use core::mcs;
use core::tpkt;
use core::sec;
use core::global;
use crate::core::x224;
use crate::core::gcc::KeyboardLayout;
use crate::core::mcs;
use crate::core::tpkt;
use crate::core::sec;
use crate::core::global;
use std::io::{Read, Write};
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use model::link::{Link, Stream};
use core::event::{RdpEvent, PointerButton};
use core::global::{ts_pointer_event, PointerFlag, ts_keyboard_event, KeyboardFlag};
use nla::ntlm::Ntlm;
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::link::{Link, Stream};
use crate::core::event::{RdpEvent, PointerButton};
use crate::core::global::{ts_pointer_event, PointerFlag, ts_keyboard_event, KeyboardFlag};
use crate::nla::ntlm::Ntlm;

impl From<&str> for KeyboardLayout {
fn from(e: &str) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions src/core/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use num_enum::TryFromPrimitive;
use codec::rle::{rle_32_decompress, rle_16_decompress, rgb565torgb32};
use crate::codec::rle::{rle_32_decompress, rle_16_decompress, rgb565torgb32};

/// A bitmap event is used
/// to notify client that it received
Expand Down
8 changes: 4 additions & 4 deletions src/core/gcc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use model::data::{Component, U32, U16, Trame, to_vec, Message, DataType, DynOption, MessageOption, Check, Array};
use model::unicode::Unicode;
use model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use core::per;
use crate::model::data::{Component, U32, U16, Trame, to_vec, Message, DataType, DynOption, MessageOption, Check, Array};
use crate::model::unicode::Unicode;
use crate::model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use crate::core::per;
use std::io::{Cursor, Read};
use std::collections::HashMap;

Expand Down
16 changes: 8 additions & 8 deletions src/core/global.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use core::mcs;
use core::tpkt;
use crate::core::mcs;
use crate::core::tpkt;
use std::io::{Read, Write, Cursor};
use model::error::{RdpResult, Error, RdpErrorKind, RdpError};
use model::data::{Component, MessageOption, U32, DynOption, U16, DataType, Message, Array, Trame, Check, to_vec};
use core::event::{RdpEvent, BitmapEvent};
use crate::model::error::{RdpResult, Error, RdpErrorKind, RdpError};
use crate::model::data::{Component, MessageOption, U32, DynOption, U16, DataType, Message, Array, Trame, Check, to_vec};
use crate::core::event::{RdpEvent, BitmapEvent};
use num_enum::TryFromPrimitive;
use std::convert::TryFrom;
use core::capability::{Capability, capability_set};
use core::capability;
use core::gcc::KeyboardLayout;
use crate::core::capability::{Capability, capability_set};
use crate::core::capability;
use crate::core::gcc::KeyboardLayout;


/// Raw PDU type use by the protocol
Expand Down
4 changes: 2 additions & 2 deletions src/core/license.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use model::data::{Component, Check, DynOption, U16, MessageOption, U32, DataType, Message};
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::data::{Component, Check, DynOption, U16, MessageOption, U32, DataType, Message};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use std::io::{Cursor, Read};
use num_enum::TryFromPrimitive;
use std::convert::TryFrom;
Expand Down
14 changes: 7 additions & 7 deletions src/core/mcs.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use core::x224;
use core::tpkt;
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use core::gcc::{KeyboardLayout, client_core_data, ClientData, ServerData, client_security_data, client_network_data, block_header, write_conference_create_request, MessageType, read_conference_create_response, Version};
use model::data::{Trame, to_vec, Message, DataType, U16};
use nla::asn1::{Sequence, ImplicitTag, OctetString, Enumerate, ASN1Type, Integer, to_der, from_ber};
use crate::core::x224;
use crate::core::tpkt;
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::core::gcc::{KeyboardLayout, client_core_data, ClientData, ServerData, client_security_data, client_network_data, block_header, write_conference_create_request, MessageType, read_conference_create_response, Version};
use crate::model::data::{Trame, to_vec, Message, DataType, U16};
use crate::nla::asn1::{Sequence, ImplicitTag, OctetString, Enumerate, ASN1Type, Integer, to_der, from_ber};
use yasna::{Tag};
use std::io::{Write, Read, BufRead, Cursor};
use core::per;
use crate::core::per;
use std::collections::HashMap;

#[allow(dead_code)]
Expand Down
4 changes: 2 additions & 2 deletions src/core/per.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use model::data::{Message, U16, Trame, U32};
use crate::model::data::{Message, U16, Trame, U32};
use std::io::{Read, Write};
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};


/// PER encoding length
Expand Down
12 changes: 6 additions & 6 deletions src/core/sec.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use core::mcs;
use core::license;
use core::tpkt;
use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use model::data::{Message, Component, U16, U32, DynOption, MessageOption, Trame, DataType};
use crate::core::mcs;
use crate::core::license;
use crate::core::tpkt;
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::data::{Message, Component, U16, U32, DynOption, MessageOption, Trame, DataType};
use std::io::{Write, Read};
use model::unicode::Unicode;
use crate::model::unicode::Unicode;

/// Security flag send as header flage in core ptotocol
/// https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/e13405c5-668b-4716-94b2-1c2654ca1ad4?redirectedfrom=MSDN
Expand Down
14 changes: 7 additions & 7 deletions src/core/tpkt.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use model::link::{Link};
use model::data::{Message, U16, Component, Trame};
use model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use crate::model::link::{Link};
use crate::model::data::{Message, U16, Component, Trame};
use crate::model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use std::io::{Cursor, Write, Read};
use nla::cssp::cssp_connect;
use nla::sspi::AuthenticationProtocol;
use crate::nla::cssp::cssp_connect;
use crate::nla::sspi::AuthenticationProtocol;

/// TPKT must implement this two kind of payload
pub enum Payload {
Expand Down Expand Up @@ -223,8 +223,8 @@ impl<S: Read + Write> Client<S> {
mod test {
use super::*;
use std::io::Cursor;
use model::data::{U32, DataType};
use model::link::Stream;
use crate::model::data::{U32, DataType};
use crate::model::link::Stream;

/// Test the tpkt header type in write context
#[test]
Expand Down
8 changes: 4 additions & 4 deletions src/core/x224.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::tpkt;
use model::data::{Message, Check, U16, U32, Component, DataType, Trame};
use model::error::{Error, RdpError, RdpResult, RdpErrorKind};
use crate::core::tpkt;
use crate::model::data::{Message, Check, U16, U32, Component, DataType, Trame};
use crate::model::error::{Error, RdpError, RdpResult, RdpErrorKind};
use std::io::{Read, Write};
use std::option::{Option};
use nla::sspi::AuthenticationProtocol;
use crate::nla::sspi::AuthenticationProtocol;
use num_enum::TryFromPrimitive;
use std::convert::TryFrom;

Expand Down
2 changes: 1 addition & 1 deletion src/model/data.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::io::{Write, Read, Cursor};
use model::error::{RdpResult, RdpErrorKind, RdpError, Error};
use crate::model::error::{RdpResult, RdpErrorKind, RdpError, Error};
use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian, BigEndian};
use indexmap::IndexMap;
use std::collections::{HashSet, HashMap};
Expand Down
4 changes: 2 additions & 2 deletions src/model/link.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
extern crate native_tls;

use model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use crate::model::error::{RdpResult, Error, RdpError, RdpErrorKind};
use std::io::{Cursor, Read, Write};
use self::native_tls::{TlsConnector, TlsStream, Certificate};
use model::data::{Message};
use crate::model::data::{Message};

/// This a wrapper to work equals
/// for a stream and a TLS stream
Expand Down
2 changes: 1 addition & 1 deletion src/model/unicode.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use model::data::{Message, U16};
use crate::model::data::{Message, U16};
use std::io::Cursor;

/// Use to to_unicode function for String
Expand Down
2 changes: 1 addition & 1 deletion src/nla/asn1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use yasna::{Tag, DERWriter, BERReader};
use model::error::{RdpResult, Error};
use crate::model::error::{RdpResult, Error};
use indexmap::map::IndexMap;

/// Enum all possible value
Expand Down
12 changes: 6 additions & 6 deletions src/nla/cssp.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use nla::asn1::{ASN1, Sequence, ExplicitTag, SequenceOf, ASN1Type, OctetString, Integer, to_der};
use model::error::{RdpError, RdpErrorKind, Error, RdpResult};
use crate::nla::asn1::{ASN1, Sequence, ExplicitTag, SequenceOf, ASN1Type, OctetString, Integer, to_der};
use crate::model::error::{RdpError, RdpErrorKind, Error, RdpResult};
use num_bigint::{BigUint};
use yasna::Tag;
use x509_parser::{parse_x509_der, X509Certificate};
use nla::sspi::AuthenticationProtocol;
use model::link::Link;
use x509_parser::prelude::{parse_x509_certificate, X509Certificate};
use crate::nla::sspi::AuthenticationProtocol;
use crate::model::link::Link;
use std::io::{Read, Write};

/// Create a ts request as expected by the specification
Expand Down Expand Up @@ -100,7 +100,7 @@ pub fn create_ts_authenticate(nego: Vec<u8>, pub_key_auth: Vec<u8>) -> Vec<u8> {
}

pub fn read_public_certificate(stream: &[u8]) -> RdpResult<X509Certificate> {
let res = parse_x509_der(stream).unwrap();
let res = parse_x509_certificate(stream).unwrap();
Ok(res.1)
}

Expand Down
25 changes: 13 additions & 12 deletions src/nla/ntlm.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use nla::sspi::{AuthenticationProtocol, GenericSecurityService};
use model::data::{Message, Component, U16, U32, Trame, DynOption, Check, DataType, MessageOption, to_vec};
use crate::nla::sspi::{AuthenticationProtocol, GenericSecurityService};
use crate::model::data::{Message, Component, U16, U32, Trame, DynOption, Check, DataType, MessageOption, to_vec};
use std::io::{Cursor};
use model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use crate::model::error::{RdpResult, RdpError, RdpErrorKind, Error};
use std::collections::HashMap;
use md4::{Md4, Digest};
use hmac::{Hmac, Mac};
use md5::{Md5};
use model::rnd::{random};
use nla::rc4::{Rc4};
use crate::model::rnd::{random};
use crate::nla::rc4::{Rc4};
use num_enum::TryFromPrimitive;
use std::convert::TryFrom;

Expand Down Expand Up @@ -264,8 +264,8 @@ fn z(m: usize) -> Vec<u8> {
/// ```
fn md4(data: &[u8]) -> Vec<u8> {
let mut hasher = Md4::new();
hasher.input(data);
hasher.result().to_vec()
hasher.update(data);
hasher.finalize().to_vec()
}

/// Compute the MD5 Hash of input vector
Expand All @@ -279,8 +279,8 @@ fn md4(data: &[u8]) -> Vec<u8> {
/// ```
fn md5(data: &[u8]) -> Vec<u8> {
let mut hasher = Md5::new();
hasher.input(data);
hasher.result().to_vec()
hasher.update(data);
hasher.finalize().to_vec()
}

/// Encode a string into utf-16le
Expand Down Expand Up @@ -310,9 +310,10 @@ fn unicode(data: &String) -> Vec<u8> {
/// let signature = hmac_md5(b"foo", b"bar");
/// ```
fn hmac_md5(key: &[u8], data: &[u8]) -> Vec<u8> {
let mut stream = Hmac::<Md5>::new_varkey(key).unwrap();
stream.input(data);
stream.result().code().to_vec()
type HmacMd5 = Hmac::<Md5>;
let mut stream = HmacMd5::new_from_slice(key).unwrap();
stream.update(data);
stream.finalize().into_bytes().to_vec()
}

/// This function is used to compute init key of another hmac_md5
Expand Down
2 changes: 1 addition & 1 deletion src/nla/sspi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use model::error::RdpResult;
use crate::model::error::RdpResult;

/// This is a trait use by authentication
/// protocol to provide a context
Expand Down

0 comments on commit 5a852e5

Please sign in to comment.