@@ -22,7 +22,6 @@ use std::{
22
22
} ;
23
23
24
24
use anyhow:: { bail, Context , Result } ;
25
- use data_encoding:: BASE32_DNSSEC ;
26
25
use ed25519_dalek:: { pkcs8:: DecodePublicKey , VerifyingKey } ;
27
26
use iroh_base:: { NodeAddr , NodeId , RelayUrl , SecretKey } ;
28
27
use iroh_relay:: RelayMap ;
@@ -78,16 +77,6 @@ pub use super::magicsock::{
78
77
/// is still no connection the configured [`Discovery`] will be used however.
79
78
const DISCOVERY_WAIT_PERIOD : Duration = Duration :: from_millis ( 500 ) ;
80
79
81
- /// Maximum amount of TLS tickets we will cache (by default) for 0-RTT connection
82
- /// establishment.
83
- ///
84
- /// 8 tickets per remote endpoint, 32 different endpoints would max out the required storage:
85
- /// ~200 bytes per session + certificates (which are ~387 bytes)
86
- /// So 8 * 32 * (200 + 387) = 150.272 bytes, assuming pointers to certificates
87
- /// are never aliased pointers (they're Arc'ed).
88
- /// I think 150KB is an acceptable default upper limit for such a cache.
89
- const MAX_TLS_TICKETS : usize = 8 * 32 ;
90
-
91
80
type DiscoveryBuilder = Box < dyn FnOnce ( & SecretKey ) -> Option < Box < dyn Discovery > > + Send + Sync > ;
92
81
93
82
/// Defines the mode of path selection for all traffic flowing through
@@ -175,9 +164,8 @@ impl Builder {
175
164
. unwrap_or_else ( || SecretKey :: generate ( rand:: rngs:: OsRng ) ) ;
176
165
let static_config = StaticConfig {
177
166
transport_config : Arc :: new ( self . transport_config ) ,
178
- tls_auth : self . tls_auth ,
167
+ tls_config : tls :: TlsConfig :: new ( self . tls_auth , secret_key . clone ( ) ) ,
179
168
keylog : self . keylog ,
180
- secret_key : secret_key. clone ( ) ,
181
169
} ;
182
170
#[ cfg( not( wasm_browser) ) ]
183
171
let dns_resolver = self . dns_resolver . unwrap_or_default ( ) ;
@@ -191,7 +179,7 @@ impl Builder {
191
179
1 => Some ( discovery. into_iter ( ) . next ( ) . expect ( "checked length" ) ) ,
192
180
_ => Some ( Box :: new ( ConcurrentDiscovery :: from_services ( discovery) ) ) ,
193
181
} ;
194
- let server_config = static_config. create_server_config ( self . alpn_protocols ) ? ;
182
+ let server_config = static_config. create_server_config ( self . alpn_protocols ) ;
195
183
196
184
let metrics = EndpointMetrics :: default ( ) ;
197
185
@@ -544,22 +532,21 @@ impl Builder {
544
532
/// Configuration for a [`quinn::Endpoint`] that cannot be changed at runtime.
545
533
#[ derive( Debug ) ]
546
534
struct StaticConfig {
547
- tls_auth : tls:: Authentication ,
548
- secret_key : SecretKey ,
535
+ tls_config : tls:: TlsConfig ,
549
536
transport_config : Arc < quinn:: TransportConfig > ,
550
537
keylog : bool ,
551
538
}
552
539
553
540
impl StaticConfig {
554
541
/// Create a [`quinn::ServerConfig`] with the specified ALPN protocols.
555
- fn create_server_config ( & self , alpn_protocols : Vec < Vec < u8 > > ) -> Result < ServerConfig > {
556
- let quic_server_config =
557
- self . tls_auth
558
- . make_server_config ( & self . secret_key , alpn_protocols, self . keylog ) ? ;
542
+ fn create_server_config ( & self , alpn_protocols : Vec < Vec < u8 > > ) -> ServerConfig {
543
+ let quic_server_config = self
544
+ . tls_config
545
+ . make_server_config ( alpn_protocols, self . keylog ) ;
559
546
let mut server_config = ServerConfig :: with_crypto ( Arc :: new ( quic_server_config) ) ;
560
547
server_config. transport_config ( self . transport_config . clone ( ) ) ;
561
548
562
- Ok ( server_config)
549
+ server_config
563
550
}
564
551
}
565
552
@@ -596,8 +583,6 @@ pub struct Endpoint {
596
583
rtt_actor : Arc < rtt_actor:: RttHandle > ,
597
584
/// Configuration structs for quinn, holds the transport config, certificate setup, secret key etc.
598
585
static_config : Arc < StaticConfig > ,
599
- /// Cache for TLS session keys we receive.
600
- session_store : Arc < dyn rustls:: client:: ClientSessionStore > ,
601
586
}
602
587
603
588
impl Endpoint {
@@ -616,7 +601,7 @@ impl Endpoint {
616
601
///
617
602
/// This is for internal use, the public interface is the [`Builder`] obtained from
618
603
/// [Self::builder]. See the methods on the builder for documentation of the parameters.
619
- #[ instrument( "ep" , skip_all, fields( me = %static_config. secret_key. public( ) . fmt_short( ) ) ) ]
604
+ #[ instrument( "ep" , skip_all, fields( me = %static_config. tls_config . secret_key. public( ) . fmt_short( ) ) ) ]
620
605
async fn bind ( static_config : StaticConfig , msock_opts : magicsock:: Options ) -> Result < Self > {
621
606
let msock = magicsock:: MagicSock :: spawn ( msock_opts) . await ?;
622
607
trace ! ( "created magicsock" ) ;
@@ -626,9 +611,6 @@ impl Endpoint {
626
611
msock : msock. clone ( ) ,
627
612
rtt_actor : Arc :: new ( rtt_actor:: RttHandle :: new ( msock. metrics . magicsock . clone ( ) ) ) ,
628
613
static_config : Arc :: new ( static_config) ,
629
- session_store : Arc :: new ( rustls:: client:: ClientSessionMemoryCache :: new (
630
- MAX_TLS_TICKETS ,
631
- ) ) ,
632
614
} ;
633
615
Ok ( ep)
634
616
}
@@ -637,10 +619,9 @@ impl Endpoint {
637
619
///
638
620
/// This will only affect new incoming connections.
639
621
/// Note that this *overrides* the current list of ALPNs.
640
- pub fn set_alpns ( & self , alpns : Vec < Vec < u8 > > ) -> Result < ( ) > {
641
- let server_config = self . static_config . create_server_config ( alpns) ? ;
622
+ pub fn set_alpns ( & self , alpns : Vec < Vec < u8 > > ) {
623
+ let server_config = self . static_config . create_server_config ( alpns) ;
642
624
self . msock . endpoint ( ) . set_server_config ( Some ( server_config) ) ;
643
- Ok ( ( ) )
644
625
}
645
626
646
627
// # Methods for establishing connectivity.
@@ -758,28 +739,16 @@ impl Endpoint {
758
739
let client_config = {
759
740
let mut alpn_protocols = vec ! [ alpn. to_vec( ) ] ;
760
741
alpn_protocols. extend ( options. additional_alpns ) ;
761
- let quic_client_config = self . static_config . tls_auth . make_client_config (
762
- & self . static_config . secret_key ,
763
- node_id,
764
- alpn_protocols,
765
- Some ( self . session_store . clone ( ) ) ,
766
- self . static_config . keylog ,
767
- ) ?;
742
+ let quic_client_config = self
743
+ . static_config
744
+ . tls_config
745
+ . make_client_config ( alpn_protocols, self . static_config . keylog ) ;
768
746
let mut client_config = quinn:: ClientConfig :: new ( Arc :: new ( quic_client_config) ) ;
769
747
client_config. transport_config ( transport_config) ;
770
748
client_config
771
749
} ;
772
750
773
- // We used to use a constant "localhost" for this - however, that would put all of
774
- // the TLS session tickets we receive into the same bucket in the TLS session ticket cache.
775
- // So we choose something that'd dependent on the NodeId.
776
- // We cannot use hex to encode the NodeId, as that'd encode to 64 characters, but we only
777
- // have 63 maximum per DNS subdomain. Base32 is the next best alternative.
778
- // We use the `.invalid` TLD, as that's specified (in RFC 2606) to never actually resolve
779
- // "for real", unlike `.localhost` which is allowed to resolve to `127.0.0.1`.
780
- // We also add "iroh" as a subdomain, although those 5 bytes might not be necessary.
781
- // We *could* decide to remove that indicator in the future likely without breakage.
782
- let server_name = & format ! ( "{}.iroh.invalid" , BASE32_DNSSEC . encode( node_id. as_bytes( ) ) ) ;
751
+ let server_name = & tls:: name:: encode ( node_id) ;
783
752
let connect = self . msock . endpoint ( ) . connect_with (
784
753
client_config,
785
754
mapped_addr. private_socket_addr ( ) ,
@@ -883,15 +852,15 @@ impl Endpoint {
883
852
884
853
/// Returns the secret_key of this endpoint.
885
854
pub fn secret_key ( & self ) -> & SecretKey {
886
- & self . static_config . secret_key
855
+ & self . static_config . tls_config . secret_key
887
856
}
888
857
889
858
/// Returns the node id of this endpoint.
890
859
///
891
860
/// This ID is the unique addressing information of this node and other peers must know
892
861
/// it to be able to connect to this node.
893
862
pub fn node_id ( & self ) -> NodeId {
894
- self . static_config . secret_key . public ( )
863
+ self . static_config . tls_config . secret_key . public ( )
895
864
}
896
865
897
866
/// Returns the current [`NodeAddr`] for this endpoint.
@@ -1571,7 +1540,7 @@ impl Future for IncomingFuture {
1571
1540
Poll :: Ready ( Ok ( inner) ) => {
1572
1541
let conn = Connection {
1573
1542
inner,
1574
- tls_auth : this. ep . static_config . tls_auth ,
1543
+ tls_auth : this. ep . static_config . tls_config . auth ,
1575
1544
} ;
1576
1545
try_send_rtt_msg ( & conn, this. ep , None ) ;
1577
1546
Poll :: Ready ( Ok ( conn) )
@@ -1644,7 +1613,7 @@ impl Connecting {
1644
1613
Ok ( ( inner, zrtt_accepted) ) => {
1645
1614
let conn = Connection {
1646
1615
inner,
1647
- tls_auth : self . ep . static_config . tls_auth ,
1616
+ tls_auth : self . ep . static_config . tls_config . auth ,
1648
1617
} ;
1649
1618
let zrtt_accepted = ZeroRttAccepted {
1650
1619
inner : zrtt_accepted,
@@ -1699,7 +1668,7 @@ impl Future for Connecting {
1699
1668
Poll :: Ready ( Ok ( inner) ) => {
1700
1669
let conn = Connection {
1701
1670
inner,
1702
- tls_auth : this. ep . static_config . tls_auth ,
1671
+ tls_auth : this. ep . static_config . tls_config . auth ,
1703
1672
} ;
1704
1673
try_send_rtt_msg ( & conn, this. ep , * this. remote_node_id ) ;
1705
1674
Poll :: Ready ( Ok ( conn) )
0 commit comments