Skip to content

Commit 136b855

Browse files
feat(iroh)!: remove deprecated x509 libp2p TLS authentication (#3330)
## Description As previously announced, we are fully transitioning to using Raw Public Keys for the TLS authentication, so this old method is now removed, in preparation of cleanup & stabilization in 1.0. ## Breaking Changes - `iroh::endpoint::Builder:: tls_x509` removed, this is the tls mechanism that has been removed - `iroh::endpoint::Builder:: tls_raw_public_keys ` removed, this is the default mechanism now, so not needed anymore
1 parent b647af9 commit 136b855

File tree

8 files changed

+100
-780
lines changed

8 files changed

+100
-780
lines changed

Cargo.lock

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

iroh/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ quinn = { package = "iroh-quinn", version = "0.13.0", default-features = false,
5454
quinn-proto = { package = "iroh-quinn-proto", version = "0.13.0" }
5555
quinn-udp = { package = "iroh-quinn-udp", version = "0.5.7" }
5656
rand = "0.8"
57-
rcgen = "0.13"
5857
reqwest = { version = "0.12", default-features = false, features = [
5958
"rustls-tls",
6059
"stream",
@@ -79,7 +78,6 @@ url = { version = "2.5", features = ["serde"] }
7978
webpki = { package = "rustls-webpki", version = "0.103", features = ["ring"] }
8079
webpki_types = { package = "rustls-pki-types", version = "1.12" }
8180
webpki-roots = "0.26"
82-
x509-parser = "0.16"
8381
z32 = "1.0.3"
8482

8583
# fix minimal versions

iroh/src/endpoint.rs

Lines changed: 9 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ pub struct Builder {
145145
addr_v6: Option<SocketAddrV6>,
146146
#[cfg(any(test, feature = "test-utils"))]
147147
path_selection: PathSelection,
148-
tls_auth: tls::Authentication,
149148
}
150149

151150
impl Default for Builder {
@@ -171,7 +170,6 @@ impl Default for Builder {
171170
addr_v6: None,
172171
#[cfg(any(test, feature = "test-utils"))]
173172
path_selection: PathSelection::default(),
174-
tls_auth: tls::Authentication::RawPublicKey,
175173
}
176174
}
177175
}
@@ -190,7 +188,7 @@ impl Builder {
190188
.unwrap_or_else(|| SecretKey::generate(rand::rngs::OsRng));
191189
let static_config = StaticConfig {
192190
transport_config: Arc::new(self.transport_config),
193-
tls_config: tls::TlsConfig::new(self.tls_auth, secret_key.clone()),
191+
tls_config: tls::TlsConfig::new(secret_key.clone()),
194192
keylog: self.keylog,
195193
};
196194
#[cfg(not(wasm_browser))]
@@ -397,24 +395,6 @@ impl Builder {
397395
self
398396
}
399397

400-
/// Use libp2p based self signed certificates for TLS.
401-
///
402-
/// For details see the libp2p spec at <https://github.com/libp2p/specs/blob/master/tls/tls.md>
403-
///
404-
/// This is the only mechanism available in `iroh@0.33.0` and earlier.
405-
pub fn tls_x509(mut self) -> Self {
406-
self.tls_auth = tls::Authentication::X509;
407-
self
408-
}
409-
410-
/// Use TLS Raw Public Keys
411-
///
412-
/// This is the default, but is not compatible with older versions of iroh.
413-
pub fn tls_raw_public_keys(mut self) -> Self {
414-
self.tls_auth = tls::Authentication::RawPublicKey;
415-
self
416-
}
417-
418398
#[cfg(feature = "discovery-pkarr-dht")]
419399
/// Configures the endpoint to also use the mainline DHT with default settings.
420400
///
@@ -1706,10 +1686,7 @@ impl Future for IncomingFuture {
17061686
Poll::Pending => Poll::Pending,
17071687
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
17081688
Poll::Ready(Ok(inner)) => {
1709-
let conn = Connection {
1710-
inner,
1711-
tls_auth: this.ep.static_config.tls_config.auth,
1712-
};
1689+
let conn = Connection { inner };
17131690
try_send_rtt_msg(&conn, this.ep, None);
17141691
Poll::Ready(Ok(conn))
17151692
}
@@ -1797,10 +1774,7 @@ impl Connecting {
17971774
pub fn into_0rtt(self) -> Result<(Connection, ZeroRttAccepted), Self> {
17981775
match self.inner.into_0rtt() {
17991776
Ok((inner, zrtt_accepted)) => {
1800-
let conn = Connection {
1801-
inner,
1802-
tls_auth: self.ep.static_config.tls_config.auth,
1803-
};
1777+
let conn = Connection { inner };
18041778
let zrtt_accepted = ZeroRttAccepted {
18051779
inner: zrtt_accepted,
18061780
_discovery_drop_guard: self._discovery_drop_guard,
@@ -1850,10 +1824,7 @@ impl Future for Connecting {
18501824
Poll::Pending => Poll::Pending,
18511825
Poll::Ready(Err(err)) => Poll::Ready(Err(err)),
18521826
Poll::Ready(Ok(inner)) => {
1853-
let conn = Connection {
1854-
inner,
1855-
tls_auth: this.ep.static_config.tls_config.auth,
1856-
};
1827+
let conn = Connection { inner };
18571828
try_send_rtt_msg(&conn, this.ep, *this.remote_node_id);
18581829
Poll::Ready(Ok(conn))
18591830
}
@@ -1902,7 +1873,6 @@ impl Future for ZeroRttAccepted {
19021873
#[derive(Debug, Clone)]
19031874
pub struct Connection {
19041875
inner: quinn::Connection,
1905-
tls_auth: tls::Authentication,
19061876
}
19071877

19081878
#[allow(missing_docs)]
@@ -2144,19 +2114,10 @@ impl Connection {
21442114
return Err(RemoteNodeIdSnafu.build());
21452115
}
21462116

2147-
match self.tls_auth {
2148-
tls::Authentication::X509 => {
2149-
let cert = tls::certificate::parse(&certs[0])
2150-
.map_err(|_| RemoteNodeIdSnafu.build())?;
2151-
Ok(cert.peer_id())
2152-
}
2153-
tls::Authentication::RawPublicKey => {
2154-
let peer_id = VerifyingKey::from_public_key_der(&certs[0])
2155-
.map_err(|_| RemoteNodeIdSnafu.build())?
2156-
.into();
2157-
Ok(peer_id)
2158-
}
2159-
}
2117+
let peer_id = VerifyingKey::from_public_key_der(&certs[0])
2118+
.map_err(|_| RemoteNodeIdSnafu.build())?
2119+
.into();
2120+
Ok(peer_id)
21602121
}
21612122
Err(err) => {
21622123
warn!("invalid peer certificate: {:?}", err);
@@ -2358,7 +2319,6 @@ mod tests {
23582319
use crate::{
23592320
endpoint::{ConnectOptions, Connection, ConnectionType, RemoteInfo},
23602321
test_utils::{run_relay_server, run_relay_server_with},
2361-
tls,
23622322
watcher::Watcher,
23632323
RelayMode,
23642324
};
@@ -2694,34 +2654,16 @@ mod tests {
26942654

26952655
#[tokio::test]
26962656
#[traced_test]
2697-
async fn endpoint_bidi_send_recv_x509() -> Result {
2698-
endpoint_bidi_send_recv(tls::Authentication::X509).await
2699-
}
2700-
2701-
#[tokio::test]
2702-
#[traced_test]
2703-
async fn endpoint_bidi_send_recv_raw_public_key() -> Result {
2704-
endpoint_bidi_send_recv(tls::Authentication::RawPublicKey).await
2705-
}
2706-
2707-
async fn endpoint_bidi_send_recv(auth: tls::Authentication) -> Result {
2657+
async fn endpoint_bidi_send_recv() -> Result {
27082658
let ep1 = Endpoint::builder()
27092659
.alpns(vec![TEST_ALPN.to_vec()])
27102660
.relay_mode(RelayMode::Disabled);
27112661

2712-
let ep1 = match auth {
2713-
tls::Authentication::X509 => ep1.tls_x509(),
2714-
tls::Authentication::RawPublicKey => ep1.tls_raw_public_keys(),
2715-
};
27162662
let ep1 = ep1.bind().await?;
27172663
let ep2 = Endpoint::builder()
27182664
.alpns(vec![TEST_ALPN.to_vec()])
27192665
.relay_mode(RelayMode::Disabled);
27202666

2721-
let ep2 = match auth {
2722-
tls::Authentication::X509 => ep2.tls_x509(),
2723-
tls::Authentication::RawPublicKey => ep2.tls_raw_public_keys(),
2724-
};
27252667
let ep2 = ep2.bind().await?;
27262668

27272669
let ep1_nodeaddr = ep1.node_addr().initialized().await?;

iroh/src/magicsock.rs

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,8 +3565,7 @@ mod tests {
35653565
impl Default for Options {
35663566
fn default() -> Self {
35673567
let secret_key = SecretKey::generate(rand::rngs::OsRng);
3568-
let tls_auth = crate::tls::Authentication::RawPublicKey;
3569-
let server_config = make_default_server_config(&secret_key, tls_auth);
3568+
let server_config = make_default_server_config(&secret_key);
35703569
Options {
35713570
addr_v4: None,
35723571
addr_v6: None,
@@ -3589,12 +3588,9 @@ mod tests {
35893588
}
35903589

35913590
/// Generate a server config with no ALPNS and a default transport configuration
3592-
fn make_default_server_config(
3593-
secret_key: &SecretKey,
3594-
tls_auth: crate::tls::Authentication,
3595-
) -> ServerConfig {
3596-
let quic_server_config = crate::tls::TlsConfig::new(tls_auth, secret_key.clone())
3597-
.make_server_config(vec![], false);
3591+
fn make_default_server_config(secret_key: &SecretKey) -> ServerConfig {
3592+
let quic_server_config =
3593+
crate::tls::TlsConfig::new(secret_key.clone()).make_server_config(vec![], false);
35983594
let mut server_config = ServerConfig::with_crypto(Arc::new(quic_server_config));
35993595
server_config.transport_config(Arc::new(quinn::TransportConfig::default()));
36003596
server_config
@@ -4166,9 +4162,9 @@ mod tests {
41664162
///
41674163
/// Use [`magicsock_connect`] to establish connections.
41684164
#[instrument(name = "ep", skip_all, fields(me = secret_key.public().fmt_short()))]
4169-
async fn magicsock_ep(secret_key: SecretKey, tls_auth: tls::Authentication) -> Result<Handle> {
4170-
let quic_server_config = tls::TlsConfig::new(tls_auth, secret_key.clone())
4171-
.make_server_config(vec![ALPN.to_vec()], true);
4165+
async fn magicsock_ep(secret_key: SecretKey) -> Result<Handle> {
4166+
let quic_server_config =
4167+
tls::TlsConfig::new(secret_key.clone()).make_server_config(vec![ALPN.to_vec()], true);
41724168
let mut server_config = ServerConfig::with_crypto(Arc::new(quic_server_config));
41734169
server_config.transport_config(Arc::new(quinn::TransportConfig::default()));
41744170

@@ -4202,7 +4198,6 @@ mod tests {
42024198
ep_secret_key: SecretKey,
42034199
addr: NodeIdMappedAddr,
42044200
node_id: NodeId,
4205-
tls_auth: tls::Authentication,
42064201
) -> Result<quinn::Connection> {
42074202
// Endpoint::connect sets this, do the same to have similar behaviour.
42084203
let mut transport_config = quinn::TransportConfig::default();
@@ -4214,7 +4209,6 @@ mod tests {
42144209
addr,
42154210
node_id,
42164211
Arc::new(transport_config),
4217-
tls_auth,
42184212
)
42194213
.await
42204214
}
@@ -4231,11 +4225,10 @@ mod tests {
42314225
mapped_addr: NodeIdMappedAddr,
42324226
node_id: NodeId,
42334227
transport_config: Arc<quinn::TransportConfig>,
4234-
tls_auth: tls::Authentication,
42354228
) -> Result<quinn::Connection> {
42364229
let alpns = vec![ALPN.to_vec()];
42374230
let quic_client_config =
4238-
tls::TlsConfig::new(tls_auth, ep_secret_key.clone()).make_client_config(alpns, true);
4231+
tls::TlsConfig::new(ep_secret_key.clone()).make_client_config(alpns, true);
42394232
let mut client_config = quinn::ClientConfig::new(Arc::new(quic_client_config));
42404233
client_config.transport_config(transport_config);
42414234
let connect = ep
@@ -4255,15 +4248,13 @@ mod tests {
42554248
// Regression test: if there is no send_addr we should keep being able to use the
42564249
// Endpoint.
42574250

4258-
let tls_auth = tls::Authentication::RawPublicKey;
4259-
42604251
let secret_key_1 = SecretKey::from_bytes(&[1u8; 32]);
42614252
let secret_key_2 = SecretKey::from_bytes(&[2u8; 32]);
42624253
let node_id_2 = secret_key_2.public();
42634254
let secret_key_missing_node = SecretKey::from_bytes(&[255u8; 32]);
42644255
let node_id_missing_node = secret_key_missing_node.public();
42654256

4266-
let msock_1 = magicsock_ep(secret_key_1.clone(), tls_auth).await.unwrap();
4257+
let msock_1 = magicsock_ep(secret_key_1.clone()).await.unwrap();
42674258

42684259
// Generate an address not present in the NodeMap.
42694260
let bad_addr = NodeIdMappedAddr::generate();
@@ -4279,14 +4270,13 @@ mod tests {
42794270
secret_key_1.clone(),
42804271
bad_addr,
42814272
node_id_missing_node,
4282-
tls_auth,
42834273
),
42844274
)
42854275
.await;
42864276
assert!(res.is_err(), "expecting timeout");
42874277

42884278
// Now check we can still create another connection with this endpoint.
4289-
let msock_2 = magicsock_ep(secret_key_2.clone(), tls_auth).await.unwrap();
4279+
let msock_2 = magicsock_ep(secret_key_2.clone()).await.unwrap();
42904280

42914281
// This needs an accept task
42924282
let accept_task = tokio::spawn({
@@ -4336,13 +4326,7 @@ mod tests {
43364326
let addr = msock_1.get_mapping_addr(node_id_2).unwrap();
43374327
let res = tokio::time::timeout(
43384328
Duration::from_secs(10),
4339-
magicsock_connect(
4340-
msock_1.endpoint(),
4341-
secret_key_1.clone(),
4342-
addr,
4343-
node_id_2,
4344-
tls_auth,
4345-
),
4329+
magicsock_connect(msock_1.endpoint(), secret_key_1.clone(), addr, node_id_2),
43464330
)
43474331
.await
43484332
.expect("timeout while connecting");
@@ -4360,14 +4344,12 @@ mod tests {
43604344
// This specifically tests the `if udp_addr.is_none() && relay_url.is_none()`
43614345
// behaviour of MagicSock::try_send.
43624346

4363-
let tls_auth = tls::Authentication::RawPublicKey;
4364-
43654347
let secret_key_1 = SecretKey::from_bytes(&[1u8; 32]);
43664348
let secret_key_2 = SecretKey::from_bytes(&[2u8; 32]);
43674349
let node_id_2 = secret_key_2.public();
43684350

4369-
let msock_1 = magicsock_ep(secret_key_1.clone(), tls_auth).await.unwrap();
4370-
let msock_2 = magicsock_ep(secret_key_2.clone(), tls_auth).await.unwrap();
4351+
let msock_1 = magicsock_ep(secret_key_1.clone()).await.unwrap();
4352+
let msock_2 = magicsock_ep(secret_key_2.clone()).await.unwrap();
43714353
let ep_2 = msock_2.endpoint().clone();
43724354

43734355
// We need a task to accept the connection.
@@ -4425,7 +4407,6 @@ mod tests {
44254407
addr_2,
44264408
node_id_2,
44274409
Arc::new(transport_config),
4428-
tls_auth,
44294410
)
44304411
.await;
44314412
assert!(res.is_err(), "expected timeout");
@@ -4454,15 +4435,10 @@ mod tests {
44544435
// We can now connect
44554436
tokio::time::timeout(Duration::from_secs(10), async move {
44564437
info!("establishing new connection");
4457-
let conn = magicsock_connect(
4458-
msock_1.endpoint(),
4459-
secret_key_1.clone(),
4460-
addr_2,
4461-
node_id_2,
4462-
tls_auth,
4463-
)
4464-
.await
4465-
.unwrap();
4438+
let conn =
4439+
magicsock_connect(msock_1.endpoint(), secret_key_1.clone(), addr_2, node_id_2)
4440+
.await
4441+
.unwrap();
44664442
info!("have connection");
44674443
let mut stream = conn.open_uni().await.unwrap();
44684444
stream.write_all(b"hello").await.unwrap();

0 commit comments

Comments
 (0)