ironrdp-tls provides TLS boilerplate common to most IronRDP clients, offering a clean abstraction over different TLS backends with deliberate backend selection.
Overview
This crate handles TLS connection upgrades for RDP connections by:
- Supporting multiple TLS backends (rustls, native-tls)
- Extracting server certificates for RDP protocol verification
- Configuring TLS appropriately for RDP (no resumption, no cert verification)
- Providing a stub backend for testing
Backend Selection
The crate uses mutually exclusive features to select exactly one TLS backend:
Enabling multiple backends simultaneously will cause a compile-time error. This is intentional and prevents accidental misconfiguration.
Why This Design?
This explicit selection approach has several benefits:
- Deliberate choice: It’s obvious which backend is enabled by looking at dependencies
- No defaults to disable: No need for
default-features = false
- Easier re-export: When re-exposing features, you don’t need to disable defaults
- Prevents mistakes: Cannot accidentally enable multiple backends
Available Backends
rustls Backend
Uses the pure-Rust rustls TLS implementation:
Advantages:
- Pure Rust (no C dependencies)
- Memory safe
- Supports SSLKEYLOGFILE for Wireshark debugging
- Works on all platforms
Dependencies:
tokio-rustls: Tokio integration for rustls
x509-cert: Certificate parsing
native-tls Backend
Uses platform-native TLS implementations:
Platform mappings:
- Windows: SChannel
- macOS: Secure Transport
- Linux: OpenSSL
Advantages:
- Uses platform TLS (may be required for compliance)
- Smaller binary size
- Leverages system certificate stores
Dependencies:
tokio-native-tls: Tokio integration
x509-cert: Certificate parsing
stub Backend
A no-op implementation for testing and compile-time checking:
The stub backend will panic at runtime if you attempt to use it. It’s only for making code compile with minimal dependencies during development.
Usage
The API is identical regardless of backend:
TlsStream Type
The TlsStream<S> type alias points to the backend-specific TLS stream:
This allows your code to be backend-agnostic while still getting concrete types.
RDP requires the server’s public key for protocol validation:
TLS Configuration
The crate configures TLS appropriately for RDP:
Certificate Verification
RDP clients typically do not verify server certificates through standard CA chains. Instead:
- Certificates are accepted without validation
- The server public key is extracted
- RDP protocol-level validation occurs later
This matches how native RDP clients work and allows self-signed certificates.
rustls Configuration
native-tls Configuration
Why No Session Resumption?
The CredSSP protocol used by RDP does not support TLS session resumption:
The CredSSP Protocol does not extend the TLS wire protocol. TLS session resumption is not supported.
— MS-CSSP § 1 Overview
Complete Connection Example
Debugging TLS with SSLKEYLOGFILE
When using the rustls backend, you can decrypt TLS traffic in Wireshark:
This is extremely useful for debugging RDP protocol issues.
Error Handling
The upgrade function returns io::Result<(TlsStream<S>, Certificate)>:
Re-exporting in Your Crate
If you’re building a library that uses IronRDP, you can re-export the TLS backend features:
Users of your library can then choose:
When to Use Each Backend
Choose rustls when:
- Building cross-platform applications
- Want pure Rust dependencies
- Need memory safety guarantees
- Want SSLKEYLOGFILE debugging support
- Prefer explicit TLS implementation
Choose native-tls when:
- Need platform TLS for compliance
- Want smaller binary sizes
- Leveraging system certificate stores
- Targeting enterprise environments with specific TLS requirements
Choose stub when:
- Writing tests that don’t need real TLS
- Checking that code compiles without TLS dependencies
- Building for constrained environments
Never use the stub backend in production code.
Dependencies
Common dependencies:
With rustls feature:
- tokio-rustls: Tokio + rustls integration
- x509-cert: Certificate parsing
With native-tls feature:
- tokio-native-tls: Tokio + native TLS integration
- x509-cert: Certificate parsing