Skip to content

Commit d1b9567

Browse files
elmarcoCBenoit
authored andcommitted
docs(example/server): use server TlsIdentityCtx
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 7dd1787 commit d1b9567

File tree

3 files changed

+3
-59
lines changed

3 files changed

+3
-59
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ironrdp/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ironrdp-acceptor = { workspace = true, optional = true }
4141
ironrdp-session = { workspace = true, optional = true }
4242
ironrdp-graphics = { workspace = true, optional = true }
4343
ironrdp-input = { workspace = true, optional = true }
44-
ironrdp-server = { workspace = true, optional = true }
44+
ironrdp-server = { workspace = true, optional = true, features = ["helper"] }
4545
ironrdp-svc = { workspace = true, optional = true }
4646
ironrdp-dvc = { workspace = true, optional = true }
4747
ironrdp-rdpdr = { workspace = true, optional = true }
@@ -55,7 +55,6 @@ ironrdp-cliprdr-native.workspace = true
5555
ironrdp-tls = { workspace = true, features = ["rustls"] }
5656
anyhow = "1"
5757
async-trait = "0.1"
58-
rustls-pemfile = "2.2"
5958
bmp = "0.5"
6059
pico-args = "0.5"
6160
x509-cert = { version = "0.2", default-features = false, features = ["std"] }

crates/ironrdp/examples/server.rs

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
#[macro_use]
77
extern crate tracing;
88

9-
use std::fs::File;
10-
use std::io::BufReader;
119
use std::net::SocketAddr;
1210
use std::num::NonZeroU16;
13-
use std::path::{Path, PathBuf};
11+
use std::path::PathBuf;
1412
use std::sync::{Arc, Mutex};
1513

1614
use anyhow::Context as _;
@@ -22,14 +20,11 @@ use ironrdp_cliprdr_native::StubCliprdrBackend;
2220
use ironrdp_server::{
2321
BitmapUpdate, CliprdrServerFactory, Credentials, DisplayUpdate, KeyboardEvent, MouseEvent, PixelFormat, PixelOrder,
2422
RdpServer, RdpServerDisplay, RdpServerDisplayUpdates, RdpServerInputHandler, ServerEvent, ServerEventSender,
25-
SoundServerFactory,
23+
SoundServerFactory, TlsIdentityCtx,
2624
};
2725
use rand::prelude::*;
28-
use rustls_pemfile::{certs, pkcs8_private_keys};
2926
use tokio::sync::mpsc::UnboundedSender;
3027
use tokio::time::{self, sleep, Duration};
31-
use tokio_rustls::rustls;
32-
use tokio_rustls::TlsAcceptor;
3328

3429
const HELP: &str = "\
3530
USAGE:
@@ -134,55 +129,6 @@ fn setup_logging() -> anyhow::Result<()> {
134129
Ok(())
135130
}
136131

137-
struct TlsIdentityCtx {
138-
cert: rustls::pki_types::CertificateDer<'static>,
139-
priv_key: rustls::pki_types::PrivateKeyDer<'static>,
140-
pub_key: Vec<u8>,
141-
}
142-
143-
impl TlsIdentityCtx {
144-
fn init_from_paths(cert_path: &Path, key_path: &Path) -> anyhow::Result<Self> {
145-
use x509_cert::der::Decode as _;
146-
147-
let cert = certs(&mut BufReader::new(File::open(cert_path)?))
148-
.next()
149-
.context("no certificate")??;
150-
151-
let pub_key = {
152-
let cert = x509_cert::Certificate::from_der(&cert).map_err(std::io::Error::other)?;
153-
cert.tbs_certificate
154-
.subject_public_key_info
155-
.subject_public_key
156-
.as_bytes()
157-
.ok_or_else(|| std::io::Error::other("subject public key BIT STRING is not aligned"))?
158-
.to_owned()
159-
};
160-
161-
let priv_key = pkcs8_private_keys(&mut BufReader::new(File::open(key_path)?))
162-
.next()
163-
.context("no private key")?
164-
.map(rustls::pki_types::PrivateKeyDer::from)?;
165-
166-
Ok(Self {
167-
cert,
168-
priv_key,
169-
pub_key,
170-
})
171-
}
172-
173-
fn make_acceptor(&self) -> anyhow::Result<TlsAcceptor> {
174-
let mut server_config = rustls::ServerConfig::builder()
175-
.with_no_client_auth()
176-
.with_single_cert(vec![self.cert.clone()], self.priv_key.clone_key())
177-
.context("bad certificate/key")?;
178-
179-
// This adds support for the SSLKEYLOGFILE env variable (https://wiki.wireshark.org/TLS#using-the-pre-master-secret)
180-
server_config.key_log = Arc::new(rustls::KeyLogFile::new());
181-
182-
Ok(TlsAcceptor::from(Arc::new(server_config)))
183-
}
184-
}
185-
186132
#[derive(Clone, Debug)]
187133
struct Handler;
188134

0 commit comments

Comments
 (0)