@@ -36,6 +36,55 @@ pub use self::license_exchange::{LicenseExchangeSequence, LicenseExchangeState};
3636pub use self :: server_name:: ServerName ;
3737pub use crate :: license_exchange:: LicenseCache ;
3838
39+ /// Provides user-friendly error messages for RDP negotiation failures
40+ #[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
41+ pub struct NegotiationFailure ( ironrdp_pdu:: nego:: FailureCode ) ;
42+
43+ impl NegotiationFailure {
44+ pub fn code ( self ) -> ironrdp_pdu:: nego:: FailureCode {
45+ self . 0
46+ }
47+ }
48+
49+ impl core:: error:: Error for NegotiationFailure { }
50+
51+ impl From < ironrdp_pdu:: nego:: FailureCode > for NegotiationFailure {
52+ fn from ( code : ironrdp_pdu:: nego:: FailureCode ) -> Self {
53+ Self ( code)
54+ }
55+ }
56+
57+ impl fmt:: Display for NegotiationFailure {
58+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
59+ use ironrdp_pdu:: nego:: FailureCode ;
60+
61+ match self . 0 {
62+ FailureCode :: SSL_REQUIRED_BY_SERVER => {
63+ write ! ( f, "server requires Enhanced RDP Security with TLS or CredSSP" )
64+ }
65+ FailureCode :: SSL_NOT_ALLOWED_BY_SERVER => {
66+ write ! ( f, "server only supports Standard RDP Security" )
67+ }
68+ FailureCode :: SSL_CERT_NOT_ON_SERVER => {
69+ write ! ( f, "server lacks valid authentication certificate" )
70+ }
71+ FailureCode :: INCONSISTENT_FLAGS => {
72+ write ! ( f, "inconsistent security protocol flags" )
73+ }
74+ FailureCode :: HYBRID_REQUIRED_BY_SERVER => {
75+ write ! ( f, "server requires Enhanced RDP Security with CredSSP" )
76+ }
77+ FailureCode :: SSL_WITH_USER_AUTH_REQUIRED_BY_SERVER => {
78+ write ! (
79+ f,
80+ "server requires Enhanced RDP Security with TLS and client certificate"
81+ )
82+ }
83+ _ => write ! ( f, "unknown negotiation failure (code: 0x{:08x})" , u32 :: from( self . 0 ) ) ,
84+ }
85+ }
86+ }
87+
3988#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
4089#[ cfg_attr( feature = "arbitrary" , derive( arbitrary:: Arbitrary ) ) ]
4190pub struct DesktopSize {
@@ -276,6 +325,7 @@ pub enum ConnectorErrorKind {
276325 AccessDenied ,
277326 General ,
278327 Custom ,
328+ Negotiation ( NegotiationFailure ) ,
279329}
280330
281331impl fmt:: Display for ConnectorErrorKind {
@@ -288,6 +338,7 @@ impl fmt::Display for ConnectorErrorKind {
288338 ConnectorErrorKind :: AccessDenied => write ! ( f, "access denied" ) ,
289339 ConnectorErrorKind :: General => write ! ( f, "general error" ) ,
290340 ConnectorErrorKind :: Custom => write ! ( f, "custom error" ) ,
341+ ConnectorErrorKind :: Negotiation ( failure) => write ! ( f, "negotiation failure: {failure}" ) ,
291342 }
292343 }
293344}
@@ -302,6 +353,7 @@ impl core::error::Error for ConnectorErrorKind {
302353 ConnectorErrorKind :: AccessDenied => None ,
303354 ConnectorErrorKind :: Custom => None ,
304355 ConnectorErrorKind :: General => None ,
356+ ConnectorErrorKind :: Negotiation ( failure) => Some ( failure) ,
305357 }
306358 }
307359}
0 commit comments