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 8 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/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
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
21 changes: 8 additions & 13 deletions interop-tests/src/bin/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use env_logger::{Env, Target};
use futures::{future, AsyncRead, AsyncWrite, StreamExt};
use libp2p::core::muxing::StreamMuxerBox;
use libp2p::core::upgrade::{MapInboundUpgrade, MapOutboundUpgrade, Version};
use libp2p::noise::{NoiseOutput, X25519Spec, XX};
use libp2p::noise::Output;
use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmEvent};
use libp2p::tls::TlsStream;
use libp2p::websocket::WsConfig;
Expand Down Expand Up @@ -168,17 +168,14 @@ fn secure_channel_protocol_from_env<C: AsyncRead + AsyncWrite + Unpin + Send + '
identity: &identity::Keypair,
) -> Result<
MapOutboundUpgrade<
MapInboundUpgrade<
Either<noise::NoiseAuthenticated<XX, X25519Spec, ()>, tls::Config>,
MapSecOutputFn<C>,
>,
MapInboundUpgrade<Either<noise::Config, tls::Config>, MapSecOutputFn<C>>,
MapSecOutputFn<C>,
>,
> {
let either_sec_upgrade = match from_env("security")? {
SecProtocol::Noise => Either::Left(
noise::NoiseAuthenticated::xx(identity).context("failed to intialise noise")?,
),
SecProtocol::Noise => {
Either::Left(noise::Config::new(identity).context("failed to intialise noise")?)
mxinden marked this conversation as resolved.
Show resolved Hide resolved
}
SecProtocol::Tls => {
Either::Right(tls::Config::new(identity).context("failed to initialise tls")?)
}
Expand All @@ -189,12 +186,10 @@ fn secure_channel_protocol_from_env<C: AsyncRead + AsyncWrite + Unpin + Send + '
.map_outbound(factor_peer_id as MapSecOutputFn<C>))
}

type SecOutput<C> = future::Either<(PeerId, NoiseOutput<C>), (PeerId, TlsStream<C>)>;
type MapSecOutputFn<C> = fn(SecOutput<C>) -> (PeerId, future::Either<NoiseOutput<C>, TlsStream<C>>);
type SecOutput<C> = future::Either<(PeerId, Output<C>), (PeerId, TlsStream<C>)>;
type MapSecOutputFn<C> = fn(SecOutput<C>) -> (PeerId, future::Either<Output<C>, TlsStream<C>>);

fn factor_peer_id<C>(
output: SecOutput<C>,
) -> (PeerId, future::Either<NoiseOutput<C>, TlsStream<C>>) {
fn factor_peer_id<C>(output: SecOutput<C>) -> (PeerId, future::Either<Output<C>, TlsStream<C>>) {
match output {
future::Either::Left((peer, stream)) => (peer, future::Either::Left(stream)),
future::Either::Right((peer, stream)) => (peer, future::Either::Right(stream)),
Expand Down
4 changes: 2 additions & 2 deletions libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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 @@ -286,7 +286,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/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 @@ -38,23 +38,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 @@ -64,7 +64,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 @@ -100,7 +100,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
8 changes: 4 additions & 4 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 @@ -90,7 +90,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 fn into_transport<C>(self) -> Result<(Option<PublicKey<C>>, NoiseOutput<T>), NoiseError>
pub fn into_transport<C>(self) -> Result<(Option<PublicKey<C>>, Output<T>), Error>
where
C: Protocol<C> + AsRef<[u8]>,
{
Expand All @@ -110,7 +110,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