@@ -23,7 +23,7 @@ use tungstenite::protocol::Role;
2323
2424use crate :: {
2525 defaults:: timeouts:: relay:: SERVER_WRITE_TIMEOUT as WRITE_TIMEOUT ,
26- key:: { PublicKey , SecretKey } ,
26+ key:: PublicKey ,
2727 relay:: {
2828 codec:: {
2929 recv_client_key, DerpCodec , PER_CLIENT_SEND_QUEUE_DEPTH , PROTOCOL_VERSION ,
@@ -58,10 +58,6 @@ pub struct ServerActorTask {
5858 /// Optionally specifies how long to wait before failing when writing
5959 /// to a client
6060 write_timeout : Option < Duration > ,
61- /// secret_key of the client
62- secret_key : SecretKey ,
63- /// The DER encoded x509 cert to send after `LetsEncrypt` cert+intermediate.
64- meta_cert : Vec < u8 > ,
6561 /// Channel on which to communicate to the [`ServerActor`]
6662 server_channel : mpsc:: Sender < ServerMessage > ,
6763 /// When true, the server has been shutdown.
@@ -73,37 +69,30 @@ pub struct ServerActorTask {
7369 // TODO: stats collection
7470}
7571
76- impl ServerActorTask {
77- /// TODO: replace with builder
78- pub fn new ( key : SecretKey ) -> Self {
72+ impl Default for ServerActorTask {
73+ fn default ( ) -> Self {
7974 let ( server_channel_s, server_channel_r) = mpsc:: channel ( SERVER_CHANNEL_SIZE ) ;
80- let server_actor = ServerActor :: new ( key . public ( ) , server_channel_r) ;
75+ let server_actor = ServerActor :: new ( server_channel_r) ;
8176 let cancel_token = CancellationToken :: new ( ) ;
8277 let done = cancel_token. clone ( ) ;
8378 let server_task = AbortOnDropHandle :: new ( tokio:: spawn (
84- async move { server_actor. run ( done) . await }
85- . instrument ( info_span ! ( "relay.server" , me = %key. public( ) . fmt_short( ) ) ) ,
79+ async move { server_actor. run ( done) . await } . instrument ( info_span ! ( "relay.server" ) ) ,
8680 ) ) ;
87- let meta_cert = init_meta_cert ( & key . public ( ) ) ;
81+
8882 Self {
8983 write_timeout : Some ( WRITE_TIMEOUT ) ,
90- secret_key : key,
91- meta_cert,
9284 server_channel : server_channel_s,
9385 closed : false ,
9486 loop_handler : server_task,
9587 cancel : cancel_token,
9688 }
9789 }
90+ }
9891
99- /// Returns the server's secret key.
100- pub fn secret_key ( & self ) -> & SecretKey {
101- & self . secret_key
102- }
103-
104- /// Returns the server's public key.
105- pub fn public_key ( & self ) -> PublicKey {
106- self . secret_key . public ( )
92+ impl ServerActorTask {
93+ /// Creates a new default `ServerActorTask`.
94+ pub fn new ( ) -> Self {
95+ Self :: default ( )
10796 }
10897
10998 /// Closes the server and waits for the connections to disconnect.
@@ -142,17 +131,10 @@ impl ServerActorTask {
142131 pub fn client_conn_handler ( & self , default_headers : HeaderMap ) -> ClientConnHandler {
143132 ClientConnHandler {
144133 server_channel : self . server_channel . clone ( ) ,
145- secret_key : self . secret_key . clone ( ) ,
146134 write_timeout : self . write_timeout ,
147135 default_headers : Arc :: new ( default_headers) ,
148136 }
149137 }
150-
151- /// Returns the server metadata cert that can be sent by the TLS server to
152- /// let the client skip a round trip during start-up.
153- pub fn meta_cert ( & self ) -> & [ u8 ] {
154- & self . meta_cert
155- }
156138}
157139
158140/// Handle incoming connections to the Server.
@@ -163,7 +145,6 @@ impl ServerActorTask {
163145#[ derive( Debug ) ]
164146pub struct ClientConnHandler {
165147 server_channel : mpsc:: Sender < ServerMessage > ,
166- secret_key : SecretKey ,
167148 write_timeout : Option < Duration > ,
168149 pub ( crate ) default_headers : Arc < HeaderMap > ,
169150}
@@ -172,7 +153,6 @@ impl Clone for ClientConnHandler {
172153 fn clone ( & self ) -> Self {
173154 Self {
174155 server_channel : self . server_channel . clone ( ) ,
175- secret_key : self . secret_key . clone ( ) ,
176156 write_timeout : self . write_timeout ,
177157 default_headers : Arc :: clone ( & self . default_headers ) ,
178158 }
@@ -236,17 +216,15 @@ impl ClientConnHandler {
236216}
237217
238218struct ServerActor {
239- key : PublicKey ,
240219 receiver : mpsc:: Receiver < ServerMessage > ,
241220 /// All clients connected to this server
242221 clients : Clients ,
243222 client_counter : ClientCounter ,
244223}
245224
246225impl ServerActor {
247- fn new ( key : PublicKey , receiver : mpsc:: Receiver < ServerMessage > ) -> Self {
226+ fn new ( receiver : mpsc:: Receiver < ServerMessage > ) -> Self {
248227 Self {
249- key,
250228 receiver,
251229 clients : Clients :: new ( ) ,
252230 client_counter : ClientCounter :: default ( ) ,
@@ -310,7 +288,7 @@ impl ServerActor {
310288
311289 report_usage_stats( & UsageStatsReport :: new(
312290 "relay_accepts" . to_string( ) ,
313- self . key . to_string( ) ,
291+ "relay_server" . to_string( ) , // TODO: other id?
314292 1 ,
315293 None , // TODO(arqu): attribute to user id; possibly with the re-introduction of request tokens or other auth
316294 Some ( key. to_string( ) ) ,
@@ -346,36 +324,6 @@ impl ServerActor {
346324 }
347325}
348326
349- /// Initializes the [`ServerActor`] with a self-signed x509 cert
350- /// encoding this server's public key and protocol version. "cmd/relay_server
351- /// then sends this after the Let's Encrypt leaf + intermediate certs after
352- /// the ServerHello (encrypted in TLS 1.3, not that is matters much).
353- ///
354- /// Then the client can save a round trime getting that and can start speaking
355- /// relay right away. (we don't use ALPN because that's sent in the clear and
356- /// we're being paranoid to not look too weird to any middleboxes, given that
357- /// relay is an ultimate fallback path). But since the post-ServerHello certs
358- /// are encrypted we can have the client also use them as a signal to be able
359- /// to start speaking relay right away, starting with its identity proof,
360- /// encrypted to the server's public key.
361- ///
362- /// This RTT optimization fails where there's a corp-mandated TLS proxy with
363- /// corp-mandated root certs on employee machines and TLS proxy cleans up
364- /// unnecessary certs. In that case we just fall back to the extra RTT.
365- fn init_meta_cert ( server_key : & PublicKey ) -> Vec < u8 > {
366- let mut params =
367- rcgen:: CertificateParams :: new ( [ format ! ( "derpkey{}" , hex:: encode( server_key. as_bytes( ) ) ) ] ) ;
368- params. serial_number = Some ( ( PROTOCOL_VERSION as u64 ) . into ( ) ) ;
369- // Windows requires not_after and not_before set:
370- params. not_after = time:: OffsetDateTime :: now_utc ( ) . saturating_add ( 30 * time:: Duration :: DAY ) ;
371- params. not_before = time:: OffsetDateTime :: now_utc ( ) . saturating_sub ( 30 * time:: Duration :: DAY ) ;
372-
373- rcgen:: Certificate :: from_params ( params)
374- . expect ( "fixed inputs" )
375- . serialize_der ( )
376- . expect ( "fixed allocations" )
377- }
378-
379327struct ClientCounter {
380328 clients : HashMap < PublicKey , usize > ,
381329 last_clear_date : Date ,
@@ -412,6 +360,7 @@ impl ClientCounter {
412360#[ cfg( test) ]
413361mod tests {
414362 use bytes:: Bytes ;
363+ use iroh_base:: key:: SecretKey ;
415364 use tokio:: io:: DuplexStream ;
416365 use tokio_util:: codec:: { FramedRead , FramedWrite } ;
417366 use tracing_subscriber:: { prelude:: * , EnvFilter } ;
@@ -446,11 +395,9 @@ mod tests {
446395
447396 #[ tokio:: test]
448397 async fn test_server_actor ( ) -> Result < ( ) > {
449- let server_key = SecretKey :: generate ( ) . public ( ) ;
450-
451398 // make server actor
452399 let ( server_channel, server_channel_r) = mpsc:: channel ( 20 ) ;
453- let server_actor: ServerActor = ServerActor :: new ( server_key , server_channel_r) ;
400+ let server_actor: ServerActor = ServerActor :: new ( server_channel_r) ;
454401 let done = CancellationToken :: new ( ) ;
455402 let server_done = done. clone ( ) ;
456403
@@ -518,7 +465,6 @@ mod tests {
518465 let ( server_channel_s, mut server_channel_r) = mpsc:: channel ( 10 ) ;
519466 let client_key = SecretKey :: generate ( ) ;
520467 let handler = ClientConnHandler {
521- secret_key : client_key. clone ( ) ,
522468 write_timeout : None ,
523469 server_channel : server_channel_s,
524470 default_headers : Default :: default ( ) ,
@@ -580,8 +526,7 @@ mod tests {
580526 let _guard = iroh_test:: logging:: setup ( ) ;
581527
582528 // create the server!
583- let server_key = SecretKey :: generate ( ) ;
584- let server: ServerActorTask = ServerActorTask :: new ( server_key) ;
529+ let server: ServerActorTask = ServerActorTask :: new ( ) ;
585530
586531 // create client a and connect it to the server
587532 let key_a = SecretKey :: generate ( ) ;
@@ -656,8 +601,7 @@ mod tests {
656601 . ok ( ) ;
657602
658603 // create the server!
659- let server_key = SecretKey :: generate ( ) ;
660- let server: ServerActorTask = ServerActorTask :: new ( server_key) ;
604+ let server: ServerActorTask = ServerActorTask :: new ( ) ;
661605
662606 // create client a and connect it to the server
663607 let key_a = SecretKey :: generate ( ) ;
0 commit comments