6
6
#[ macro_use]
7
7
extern crate tracing;
8
8
9
- use std:: fs:: File ;
10
- use std:: io:: BufReader ;
11
9
use std:: net:: SocketAddr ;
12
10
use std:: num:: NonZeroU16 ;
13
- use std:: path:: { Path , PathBuf } ;
11
+ use std:: path:: PathBuf ;
14
12
use std:: sync:: { Arc , Mutex } ;
15
13
16
14
use anyhow:: Context as _;
@@ -22,14 +20,11 @@ use ironrdp_cliprdr_native::StubCliprdrBackend;
22
20
use ironrdp_server:: {
23
21
BitmapUpdate , CliprdrServerFactory , Credentials , DisplayUpdate , KeyboardEvent , MouseEvent , PixelFormat , PixelOrder ,
24
22
RdpServer , RdpServerDisplay , RdpServerDisplayUpdates , RdpServerInputHandler , ServerEvent , ServerEventSender ,
25
- SoundServerFactory ,
23
+ SoundServerFactory , TlsIdentityCtx ,
26
24
} ;
27
25
use rand:: prelude:: * ;
28
- use rustls_pemfile:: { certs, pkcs8_private_keys} ;
29
26
use tokio:: sync:: mpsc:: UnboundedSender ;
30
27
use tokio:: time:: { self , sleep, Duration } ;
31
- use tokio_rustls:: rustls;
32
- use tokio_rustls:: TlsAcceptor ;
33
28
34
29
const HELP : & str = "\
35
30
USAGE:
@@ -134,55 +129,6 @@ fn setup_logging() -> anyhow::Result<()> {
134
129
Ok ( ( ) )
135
130
}
136
131
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
-
186
132
#[ derive( Clone , Debug ) ]
187
133
struct Handler ;
188
134
0 commit comments