Skip to content

Commit

Permalink
feat(noise): deprecate LegacyConfig without replacement (#3265)
Browse files Browse the repository at this point in the history
As the name implies, `LegacyConfig` allows users to interact with older versions of the noise protocol. These are not interoperable and we've been supporting them for a long time now. Hopefully, users have migrated away from it since. To not directly break them, we officially deprecate now without a replacement.
  • Loading branch information
thomaseizinger authored Jan 11, 2023
1 parent 87dc7b6 commit cafa37e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
7 changes: 7 additions & 0 deletions transports/noise/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

- Update to `libp2p-core` `v0.39.0`.

- Deprecate non-compliant noise implementation. We intend to remove it in a future release without replacement. See [PR 3227].

- Deprecate `LegacyConfig` without replacement. See [PR 3265].

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

# 0.41.0

- Remove `prost::Error` from public API. See [PR 3058].
Expand Down
6 changes: 6 additions & 0 deletions transports/noise/src/io/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod payload_proto {

use crate::io::{framed::NoiseFramed, NoiseOutput};
use crate::protocol::{KeypairIdentity, Protocol, PublicKey};
#[allow(deprecated)]
use crate::LegacyConfig;
use crate::NoiseError;
use bytes::Bytes;
Expand Down Expand Up @@ -77,6 +78,7 @@ pub struct State<T> {
/// The known or received public identity key of the remote, if any.
id_remote_pubkey: Option<identity::PublicKey>,
/// Legacy configuration parameters.
#[allow(deprecated)]
legacy: LegacyConfig,
}

Expand All @@ -86,6 +88,7 @@ impl<T> State<T> {
/// will be sent and received on the given I/O resource and using the
/// provided session for cryptographic operations according to the chosen
/// Noise handshake pattern.
#[allow(deprecated)]
pub fn new(
io: T,
session: snow::HandshakeState,
Expand Down Expand Up @@ -177,6 +180,7 @@ where

let mut pb_result = payload_proto::NoiseHandshakePayload::decode(&msg[..]);

#[allow(deprecated)]
if pb_result.is_err() && state.legacy.recv_legacy_handshake {
// NOTE: This is support for legacy handshake payloads. As long as
// the frame length is less than 256 bytes, which is the case for
Expand Down Expand Up @@ -238,6 +242,7 @@ where
pb.identity_sig = sig.clone()
}

#[allow(deprecated)]
let mut msg = if state.legacy.send_legacy_handshake {
let mut msg = Vec::with_capacity(2 + pb.encoded_len());
msg.extend_from_slice(&(pb.encoded_len() as u16).to_be_bytes());
Expand All @@ -264,6 +269,7 @@ where
pb.identity_sig = sig.clone()
}

#[allow(deprecated)]
let mut msg = if state.legacy.send_legacy_handshake {
let mut msg = Vec::with_capacity(2 + pb.encoded_len());
msg.extend_from_slice(&(pb.encoded_len() as u16).to_be_bytes());
Expand Down
30 changes: 26 additions & 4 deletions transports/noise/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ use zeroize::Zeroize;
pub struct NoiseConfig<P, C: Zeroize, R = ()> {
dh_keys: AuthenticKeypair<C>,
params: ProtocolParams,
#[allow(deprecated)]
legacy: LegacyConfig,
remote: R,
_marker: std::marker::PhantomData<P>,
Expand All @@ -105,6 +106,11 @@ impl<H, C: Zeroize, R> NoiseConfig<H, C, R> {
}

/// Sets the legacy configuration options to use, if any.
#[deprecated(
since = "0.42.0",
note = "`LegacyConfig` will be removed without replacement."
)]
#[allow(deprecated)]
pub fn set_legacy_config(&mut self, cfg: LegacyConfig) -> &mut Self {
self.legacy = cfg;
self
Expand Down Expand Up @@ -150,7 +156,10 @@ where
NoiseConfig {
dh_keys,
params: C::params_ix(),
legacy: LegacyConfig::default(),
legacy: {
#[allow(deprecated)]
LegacyConfig::default()
},
remote: (),
_marker: std::marker::PhantomData,
prologue: Vec::default(),
Expand All @@ -167,7 +176,10 @@ where
NoiseConfig {
dh_keys,
params: C::params_xx(),
legacy: LegacyConfig::default(),
legacy: {
#[allow(deprecated)]
LegacyConfig::default()
},
remote: (),
_marker: std::marker::PhantomData,
prologue: Vec::default(),
Expand All @@ -187,7 +199,10 @@ where
NoiseConfig {
dh_keys,
params: C::params_ik(),
legacy: LegacyConfig::default(),
legacy: {
#[allow(deprecated)]
LegacyConfig::default()
},
remote: (),
_marker: std::marker::PhantomData,
prologue: Vec::default(),
Expand All @@ -211,7 +226,10 @@ where
NoiseConfig {
dh_keys,
params: C::params_ik(),
legacy: LegacyConfig::default(),
legacy: {
#[allow(deprecated)]
LegacyConfig::default()
},
remote: (remote_dh, remote_id),
_marker: std::marker::PhantomData,
prologue: Vec::default(),
Expand Down Expand Up @@ -573,6 +591,10 @@ where

/// Legacy configuration options.
#[derive(Clone, Copy, Default)]
#[deprecated(
since = "0.42.0",
note = "`LegacyConfig` will be removed without replacement."
)]
pub struct LegacyConfig {
/// Whether to continue sending legacy handshake payloads,
/// i.e. length-prefixed protobuf payloads inside a length-prefixed
Expand Down
2 changes: 1 addition & 1 deletion transports/noise/src/protocol/x25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static PARAMS_XX: Lazy<ProtocolParams> = Lazy::new(|| {
/// A X25519 key.
#[derive(Clone)]
#[deprecated(
since = "0.41.1",
since = "0.42.0",
note = "Will be removed because it is not compliant with the official libp2p specification. Use `X25519Spec` instead."
)]
pub struct X25519([u8; 32]);
Expand Down

0 comments on commit cafa37e

Please sign in to comment.