Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(noise): deprecate all handshake patterns apart from XX #3768

Merged
merged 15 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions core/tests/transport_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn upgrade_pipeline() {
let listener_id = listener_keys.public().to_peer_id();
let mut listener_transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&listener_keys).unwrap())
.authenticate(noise::Config::new(&listener_keys).unwrap())
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
Expand All @@ -92,7 +92,7 @@ fn upgrade_pipeline() {
let dialer_id = dialer_keys.public().to_peer_id();
let mut dialer_transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&dialer_keys).unwrap())
.authenticate(noise::Config::new(&dialer_keys).unwrap())
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
.apply(HelloUpgrade {})
Expand Down
2 changes: 1 addition & 1 deletion examples/autonat/src/bin/autonat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.authenticate(noise::Config::new(&local_key)?)
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
2 changes: 1 addition & 1 deletion examples/autonat/src/bin/autonat_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.authenticate(noise::Config::new(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
4 changes: 1 addition & 3 deletions examples/chat-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
// Set up an encrypted DNS-enabled TCP Transport over the Mplex protocol.
let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&id_keys).expect("signing libp2p-noise static keypair"),
)
.authenticate(noise::Config::new(&id_keys).expect("signing libp2p-noise static keypair"))
.multiplex(yamux::YamuxConfig::default())
.timeout(std::time::Duration::from_secs(20))
.boxed();
Expand Down
3 changes: 1 addition & 2 deletions examples/dcutr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ fn main() -> Result<(), Box<dyn Error>> {
)
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."),
noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(yamux::YamuxConfig::default())
.boxed();
Expand Down
2 changes: 1 addition & 1 deletion examples/distributed-key-value-store/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.authenticate(noise::Config::new(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
2 changes: 1 addition & 1 deletion examples/file-sharing/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub(crate) async fn new(

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&id_keys)?)
.authenticate(noise::Config::new(&id_keys)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
2 changes: 1 addition & 1 deletion examples/identify/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.authenticate(noise::Config::new(&local_key).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
2 changes: 1 addition & 1 deletion examples/ipfs-private/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn build_transport(
key_pair: identity::Keypair,
psk: Option<PreSharedKey>,
) -> transport::Boxed<(PeerId, StreamMuxerBox)> {
let noise_config = noise::NoiseAuthenticated::xx(&key_pair).unwrap();
let noise_config = noise::Config::new(&key_pair).unwrap();
let yamux_config = YamuxConfig::default();

let base_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true));
Expand Down
2 changes: 1 addition & 1 deletion examples/metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut swarm = SwarmBuilder::without_executor(
tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.authenticate(noise::Config::new(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed(),
Behaviour::new(local_pub_key),
Expand Down
2 changes: 1 addition & 1 deletion examples/ping-example/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async fn main() -> Result<(), Box<dyn Error>> {

let transport = tcp::async_io::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&local_key)?)
.authenticate(noise::Config::new(&local_key)?)
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
3 changes: 1 addition & 2 deletions examples/relay-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let transport = tcp_transport
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."),
noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(libp2p::yamux::YamuxConfig::default())
.boxed();
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/bin/rzv-discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),
MyBehaviour {
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/bin/rzv-identify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),
MyBehaviour {
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/bin/rzv-register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),
MyBehaviour {
Expand Down
2 changes: 1 addition & 1 deletion examples/rendezvous/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() {
let mut swarm = SwarmBuilder::with_tokio_executor(
tcp::tokio::Transport::default()
.upgrade(Version::V1Lazy)
.authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap())
.authenticate(noise::Config::new(&key_pair).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed(),
MyBehaviour {
Expand Down
10 changes: 2 additions & 8 deletions interop-tests/src/bin/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ async fn main() -> Result<()> {
(Transport::Tcp, Ok(SecProtocol::Noise)) => (
tcp::tokio::Transport::new(tcp::Config::new())
.upgrade(Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.context("failed to intialise noise")?,
)
.authenticate(noise::Config::new(&local_key).context("failed to intialise noise")?)
.multiplex(muxer_protocol_from_env()?)
.timeout(Duration::from_secs(5))
.boxed(),
Expand All @@ -82,10 +79,7 @@ async fn main() -> Result<()> {
(Transport::Ws, Ok(SecProtocol::Noise)) => (
WsConfig::new(tcp::tokio::Transport::new(tcp::Config::new()))
.upgrade(Version::V1Lazy)
.authenticate(
noise::NoiseAuthenticated::xx(&local_key)
.context("failed to intialise noise")?,
)
.authenticate(noise::Config::new(&local_key).context("failed to intialise noise")?)
.multiplex(muxer_protocol_from_env()?)
.timeout(Duration::from_secs(5))
.boxed(),
Expand Down
2 changes: 1 addition & 1 deletion libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ libp2p-identity = { version = "0.1.0", path = "../identity" }
libp2p-kad = { version = "0.43.0", path = "../protocols/kad", optional = true }
libp2p-metrics = { version = "0.12.0", path = "../misc/metrics", optional = true }
libp2p-mplex = { version = "0.39.0", path = "../muxers/mplex", optional = true }
libp2p-noise = { version = "0.42.0", path = "../transports/noise", optional = true }
libp2p-noise = { version = "0.42.2", path = "../transports/noise", optional = true }
mxinden marked this conversation as resolved.
Show resolved Hide resolved
libp2p-ping = { version = "0.42.0", path = "../protocols/ping", optional = true }
libp2p-plaintext = { version = "0.39.0", path = "../transports/plaintext", optional = true }
libp2p-pnet = { version = "0.22.2", path = "../transports/pnet", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ pub async fn development_transport(

Ok(transport
.upgrade(core::upgrade::Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap())
.authenticate(noise::Config::new(&keypair).unwrap())
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
.multiplex(core::upgrade::SelectUpgrade::new(
yamux::YamuxConfig::default(),
#[allow(deprecated)]
Expand Down Expand Up @@ -288,7 +288,7 @@ pub fn tokio_development_transport(

Ok(transport
.upgrade(core::upgrade::Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap())
.authenticate(noise::Config::new(&keypair).unwrap())
.multiplex(core::upgrade::SelectUpgrade::new(
yamux::YamuxConfig::default(),
#[allow(deprecated)]
Expand Down
5 changes: 1 addition & 4 deletions protocols/identify/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,13 +564,10 @@ mod tests {
transport::Boxed<(PeerId, StreamMuxerBox)>,
) {
let id_keys = identity::Keypair::generate_ed25519();
let noise_keys = noise::Keypair::<noise::X25519Spec>::new()
.into_authentic(&id_keys)
.unwrap();
let pubkey = id_keys.public();
let transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true))
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated())
.authenticate(noise::Config::new(&id_keys).unwrap())
.multiplex(MplexConfig::new())
.boxed();
(pubkey, transport)
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/src/behaviour/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) {
let local_public_key = local_key.public();
let transport = MemoryTransport::default()
.upgrade(upgrade::Version::V1)
.authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap())
.authenticate(noise::Config::new(&local_key).unwrap())
.multiplex(yamux::YamuxConfig::default())
.boxed();

Expand Down
2 changes: 1 addition & 1 deletion protocols/perf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ instant = "0.1.11"
libp2p-core = { version = "0.39.0", path = "../../core" }
libp2p-dns = { version = "0.39.0", path = "../../transports/dns", features = ["async-std"] }
libp2p-identity = { version = "0.1.0", path = "../../identity" }
libp2p-noise = { version = "0.42.0", path = "../../transports/noise" }
libp2p-noise = { version = "0.42.2", path = "../../transports/noise" }
mxinden marked this conversation as resolved.
Show resolved Hide resolved
libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] }
libp2p-swarm = { version = "0.42.1", path = "../../swarm", features = ["macros", "async-std"] }
libp2p-tcp = { version = "0.39.0", path = "../../transports/tcp", features = ["async-io"] }
Expand Down
2 changes: 1 addition & 1 deletion protocols/perf/src/bin/perf-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async fn main() -> Result<()> {
libp2p_tcp::async_io::Transport::new(libp2p_tcp::Config::default().port_reuse(true))
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
libp2p_noise::NoiseAuthenticated::xx(&local_key)
libp2p_noise::Config::new(&local_key)
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
.expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(libp2p_yamux::YamuxConfig::default());
Expand Down
2 changes: 1 addition & 1 deletion protocols/perf/src/bin/perf-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() {
libp2p_tcp::async_io::Transport::new(libp2p_tcp::Config::default().port_reuse(true))
.upgrade(upgrade::Version::V1Lazy)
.authenticate(
libp2p_noise::NoiseAuthenticated::xx(&local_key)
libp2p_noise::Config::new(&local_key)
.expect("Signing libp2p-noise static DH keypair failed."),
)
.multiplex(libp2p_yamux::YamuxConfig::default());
Expand Down
10 changes: 10 additions & 0 deletions transports/noise/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 0.42.2 - unreleased

- Deprecate all noise handshakes apart from XX.
This deprecates `NoiseConfig` and `NoiseAuthenticated` in favor of a new `libp2p_noise::Config` struct.
In addition, we deprecate all types with a `Noise` prefix.
Users are encouraged to import the `noise` module and refer to types as `noise::Error` etc.
See [PR 3768].

[PR 3768]: https://github.com/libp2p/rust-libp2p/pull/3768

## 0.42.1

- Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312].
Expand Down
2 changes: 1 addition & 1 deletion transports/noise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-noise"
edition = "2021"
rust-version = "1.60.0"
description = "Cryptographic handshake protocol using the noise framework."
version = "0.42.1"
version = "0.42.2"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
12 changes: 6 additions & 6 deletions transports/noise/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ use std::{
/// A noise session to a remote.
///
/// `T` is the type of the underlying I/O resource.
pub struct NoiseOutput<T> {
pub struct Output<T> {
io: NoiseFramed<T, snow::TransportState>,
recv_buffer: Bytes,
recv_offset: usize,
send_buffer: Vec<u8>,
send_offset: usize,
}

impl<T> fmt::Debug for NoiseOutput<T> {
impl<T> fmt::Debug for Output<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("NoiseOutput").field("io", &self.io).finish()
}
}

impl<T> NoiseOutput<T> {
impl<T> Output<T> {
fn new(io: NoiseFramed<T, snow::TransportState>) -> Self {
NoiseOutput {
Output {
io,
recv_buffer: Bytes::new(),
recv_offset: 0,
Expand All @@ -63,7 +63,7 @@ impl<T> NoiseOutput<T> {
}
}

impl<T: AsyncRead + Unpin> AsyncRead for NoiseOutput<T> {
impl<T: AsyncRead + Unpin> AsyncRead for Output<T> {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down Expand Up @@ -99,7 +99,7 @@ impl<T: AsyncRead + Unpin> AsyncRead for NoiseOutput<T> {
}
}

impl<T: AsyncWrite + Unpin> AsyncWrite for NoiseOutput<T> {
impl<T: AsyncWrite + Unpin> AsyncWrite for Output<T> {
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
Expand Down
10 changes: 4 additions & 6 deletions transports/noise/src/io/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
//! This module provides a `Sink` and `Stream` for length-delimited
//! Noise protocol messages in form of [`NoiseFramed`].

use crate::io::NoiseOutput;
use crate::{NoiseError, Protocol, PublicKey};
use crate::io::Output;
use crate::{Error, Protocol, PublicKey};
use bytes::{Bytes, BytesMut};
use futures::prelude::*;
use futures::ready;
Expand Down Expand Up @@ -89,9 +89,7 @@ impl<T> NoiseFramed<T, snow::HandshakeState> {
/// transitioning to transport mode because the handshake is incomplete,
/// an error is returned. Similarly if the remote's static DH key, if
/// present, cannot be parsed.
pub(crate) fn into_transport<C>(
self,
) -> Result<(Option<PublicKey<C>>, NoiseOutput<T>), NoiseError>
pub(crate) fn into_transport<C>(self) -> Result<(Option<PublicKey<C>>, Output<T>), Error>
where
C: Protocol<C> + AsRef<[u8]>,
{
Expand All @@ -111,7 +109,7 @@ impl<T> NoiseFramed<T, snow::HandshakeState> {
decrypt_buffer: self.decrypt_buffer,
};

Ok((dh_remote_pubkey, NoiseOutput::new(io)))
Ok((dh_remote_pubkey, Output::new(io)))
}
}

Expand Down
Loading