diff --git a/Cargo.toml b/Cargo.toml index 07d020c..c11ab53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ keywords = ["rdp", "security", "network", "windows"] categories = ["network"] license = "MIT" documentation = "https://docs.rs/rdp-rs" +edition = "2021" [lib] name = "rdp" @@ -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 } diff --git a/src/bin/mstsc-rs.rs b/src/bin/mstsc-rs.rs index e9328e1..81934a3 100644 --- a/src/bin/mstsc-rs.rs +++ b/src/bin/mstsc-rs.rs @@ -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}; diff --git a/src/codec/rle.rs b/src/codec/rle.rs index 8e7f684..ab909d0 100644 --- a/src/codec/rle.rs +++ b/src/codec/rle.rs @@ -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}; diff --git a/src/core/capability.rs b/src/core/capability.rs index a3cf40e..b84d261 100644 --- a/src/core/capability.rs +++ b/src/core/capability.rs @@ -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; diff --git a/src/core/client.rs b/src/core/client.rs index 91ab8ed..0216a41 100644 --- a/src/core/client.rs +++ b/src/core/client.rs @@ -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 { diff --git a/src/core/event.rs b/src/core/event.rs index b379171..73d3a1d 100644 --- a/src/core/event.rs +++ b/src/core/event.rs @@ -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 diff --git a/src/core/gcc.rs b/src/core/gcc.rs index 6ca719f..188f312 100644 --- a/src/core/gcc.rs +++ b/src/core/gcc.rs @@ -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; diff --git a/src/core/global.rs b/src/core/global.rs index 8d9cf69..27f02ca 100644 --- a/src/core/global.rs +++ b/src/core/global.rs @@ -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 diff --git a/src/core/license.rs b/src/core/license.rs index 960c6b1..be2974d 100644 --- a/src/core/license.rs +++ b/src/core/license.rs @@ -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; diff --git a/src/core/mcs.rs b/src/core/mcs.rs index 8fd6128..1c2439e 100644 --- a/src/core/mcs.rs +++ b/src/core/mcs.rs @@ -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)] diff --git a/src/core/per.rs b/src/core/per.rs index 453073c..b6bd5f2 100644 --- a/src/core/per.rs +++ b/src/core/per.rs @@ -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 diff --git a/src/core/sec.rs b/src/core/sec.rs index 606cd05..8ec936b 100644 --- a/src/core/sec.rs +++ b/src/core/sec.rs @@ -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 diff --git a/src/core/tpkt.rs b/src/core/tpkt.rs index cb06e37..909074f 100644 --- a/src/core/tpkt.rs +++ b/src/core/tpkt.rs @@ -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 { @@ -223,8 +223,8 @@ impl Client { 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] diff --git a/src/core/x224.rs b/src/core/x224.rs index 9a19062..ec2659d 100644 --- a/src/core/x224.rs +++ b/src/core/x224.rs @@ -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; diff --git a/src/model/data.rs b/src/model/data.rs index 98ed3c8..5555e3d 100644 --- a/src/model/data.rs +++ b/src/model/data.rs @@ -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}; diff --git a/src/model/link.rs b/src/model/link.rs index 424a1c2..e6b5a8f 100644 --- a/src/model/link.rs +++ b/src/model/link.rs @@ -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 diff --git a/src/model/unicode.rs b/src/model/unicode.rs index 5246a71..3729767 100644 --- a/src/model/unicode.rs +++ b/src/model/unicode.rs @@ -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 diff --git a/src/nla/asn1.rs b/src/nla/asn1.rs index 5b09bae..aee8d5a 100644 --- a/src/nla/asn1.rs +++ b/src/nla/asn1.rs @@ -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 diff --git a/src/nla/cssp.rs b/src/nla/cssp.rs index d327106..b75d2c0 100644 --- a/src/nla/cssp.rs +++ b/src/nla/cssp.rs @@ -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 @@ -100,7 +100,7 @@ pub fn create_ts_authenticate(nego: Vec, pub_key_auth: Vec) -> Vec { } pub fn read_public_certificate(stream: &[u8]) -> RdpResult { - let res = parse_x509_der(stream).unwrap(); + let res = parse_x509_certificate(stream).unwrap(); Ok(res.1) } diff --git a/src/nla/ntlm.rs b/src/nla/ntlm.rs index 3680c69..55a9cb8 100644 --- a/src/nla/ntlm.rs +++ b/src/nla/ntlm.rs @@ -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; @@ -264,8 +264,8 @@ fn z(m: usize) -> Vec { /// ``` fn md4(data: &[u8]) -> Vec { 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 @@ -279,8 +279,8 @@ fn md4(data: &[u8]) -> Vec { /// ``` fn md5(data: &[u8]) -> Vec { 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 @@ -310,9 +310,10 @@ fn unicode(data: &String) -> Vec { /// let signature = hmac_md5(b"foo", b"bar"); /// ``` fn hmac_md5(key: &[u8], data: &[u8]) -> Vec { - let mut stream = Hmac::::new_varkey(key).unwrap(); - stream.input(data); - stream.result().code().to_vec() + type HmacMd5 = Hmac::; + 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 diff --git a/src/nla/sspi.rs b/src/nla/sspi.rs index 4c8f848..26b16ea 100644 --- a/src/nla/sspi.rs +++ b/src/nla/sspi.rs @@ -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