additional Polish; missing features, extra test, etc
This commit is contained in:
committed by
Simon Wicky
parent
bfa52f7634
commit
cb1731494f
Generated
+2
-3
@@ -6422,16 +6422,15 @@ dependencies = [
|
||||
"arc-swap",
|
||||
"bytes",
|
||||
"futures",
|
||||
"log",
|
||||
"nym-crypto",
|
||||
"nym-noise-keys",
|
||||
"pin-project",
|
||||
"serde",
|
||||
"sha2 0.10.9",
|
||||
"sha2 0.10.8",
|
||||
"snow",
|
||||
"thiserror 2.0.12",
|
||||
"tokio",
|
||||
"tokio-util",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
@@ -9,9 +9,8 @@ license.workspace = true
|
||||
arc-swap = { workspace = true }
|
||||
bytes = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
log = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
pin-project = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
sha2 = { workspace = true }
|
||||
snow = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
@@ -21,3 +20,6 @@ tokio-util = { workspace = true, features = ["codec"] }
|
||||
# internal
|
||||
nym-crypto = { path = "../crypto" }
|
||||
nym-noise-keys = { path = "keys" }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -11,4 +11,7 @@ serde = { workspace = true, features = ["derive"] }
|
||||
utoipa = { workspace = true }
|
||||
|
||||
# internal
|
||||
nym-crypto = { path = "../../crypto" }
|
||||
nym-crypto = { path = "../../crypto", features = ["asymmetric", "serde"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@@ -26,6 +26,8 @@ impl NoisePattern {
|
||||
}
|
||||
}
|
||||
|
||||
// SAFETY: if unwraps failed, it means hardcoded patterns were wrong
|
||||
#[allow(clippy::unwrap_used)]
|
||||
pub(crate) fn psk_position(&self) -> u8 {
|
||||
//automatic parsing, works for correct pattern, more convenient
|
||||
match self.as_str().find("psk") {
|
||||
@@ -33,7 +35,6 @@ impl NoisePattern {
|
||||
let psk_index = n + 3;
|
||||
let psk_char = self.as_str().chars().nth(psk_index).unwrap();
|
||||
psk_char.to_string().parse().unwrap()
|
||||
//if this fails, it means hardcoded pattern are wrong
|
||||
}
|
||||
None => 0,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2024 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use std::io;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use snow::Error;
|
||||
use std::io;
|
||||
@@ -10,10 +10,10 @@ pub enum NoiseError {
|
||||
#[error("encountered a Noise decryption error")]
|
||||
DecryptionError,
|
||||
|
||||
#[error("encountered a Noise Protocol error - {0}")]
|
||||
#[error("encountered a Noise Protocol error: {0}")]
|
||||
ProtocolError(Error),
|
||||
|
||||
#[error("encountered an IO error - {0}")]
|
||||
#[error("encountered an IO error: {0}")]
|
||||
IoError(#[from] io::Error),
|
||||
|
||||
#[error("Incorrect state")]
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::config::{NoiseConfig, NoisePattern};
|
||||
use crate::connection::Connection;
|
||||
use crate::error::NoiseError;
|
||||
use crate::stream::NoiseStream;
|
||||
use log::*;
|
||||
use nym_crypto::asymmetric::x25519;
|
||||
use nym_noise_keys::NoiseVersion;
|
||||
use sha2::{Digest, Sha256};
|
||||
use snow::{error::Prerequisite, Builder, Error};
|
||||
use tokio::net::TcpStream;
|
||||
use tracing::*;
|
||||
|
||||
pub mod config;
|
||||
pub mod connection;
|
||||
@@ -137,10 +137,7 @@ pub async fn upgrade_noise_responder(
|
||||
// Port is random and we just need the support info
|
||||
match config.get_noise_support(initiator_addr.ip()) {
|
||||
None => {
|
||||
warn!(
|
||||
"{:?} can't speak Noise yet, falling back to TCP",
|
||||
initiator_addr
|
||||
);
|
||||
warn!("{initiator_addr} can't speak Noise yet, falling back to TCP",);
|
||||
Ok(Connection::Tcp(conn))
|
||||
}
|
||||
//responder's info on version is shaky, so initiator has to adapt. This behavior can change in the future
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
// Copyright 2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::error::NoiseError;
|
||||
use bytes::BytesMut;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2023 - Nym Technologies SA <contact@nymtech.net>
|
||||
// Copyright 2023-2025 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::api::v1::node::models::{LegacyHostInformation, LegacyHostInformationV2};
|
||||
@@ -8,7 +8,6 @@ use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::ops::Deref;
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[cfg(feature = "client")]
|
||||
pub mod client;
|
||||
@@ -20,7 +19,7 @@ pub use client::Client;
|
||||
// create the type alias manually if openapi is not enabled
|
||||
pub type SignedHostInformation = SignedData<crate::api::v1::node::models::HostInformation>;
|
||||
|
||||
#[derive(ToSchema)]
|
||||
#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
|
||||
pub struct SignedDataHostInfo {
|
||||
// #[serde(flatten)]
|
||||
pub data: crate::api::v1::node::models::HostInformation,
|
||||
@@ -40,6 +39,7 @@ impl<T> SignedData<T> {
|
||||
T: Serialize,
|
||||
{
|
||||
let plaintext = serde_json::to_string(&data)?;
|
||||
|
||||
let signature = key.sign(plaintext).to_base58_string();
|
||||
Ok(SignedData { data, signature })
|
||||
}
|
||||
@@ -66,6 +66,8 @@ impl SignedHostInformation {
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: @JS: to remove downgrade support in future release(s)
|
||||
|
||||
// attempt to verify legacy signatures
|
||||
let legacy_v2 = SignedData {
|
||||
data: LegacyHostInformationV2::from(self.data.clone()),
|
||||
@@ -107,6 +109,7 @@ impl Display for ErrorResponse {
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use crate::api::v1::node::models::HostInformation;
|
||||
use nym_crypto::asymmetric::{ed25519, x25519};
|
||||
use nym_noise_keys::{NoiseVersion, VersionedNoiseKey};
|
||||
use rand_chacha::rand_core::SeedableRng;
|
||||
@@ -224,6 +227,48 @@ mod tests {
|
||||
assert!(!current_struct_no_noise.verify(ed22519.public_key()));
|
||||
assert!(current_struct_no_noise.verify_host_information());
|
||||
|
||||
assert!(!current_struct_noise.verify(ed22519.public_key()));
|
||||
assert!(current_struct_noise.verify_host_information())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dummy_current_signed_host_verification() {
|
||||
let mut rng = rand_chacha::ChaCha20Rng::from_seed([0u8; 32]);
|
||||
let ed22519 = ed25519::KeyPair::new(&mut rng);
|
||||
let x25519_sphinx = x25519::KeyPair::new(&mut rng);
|
||||
let x25519_noise = x25519::KeyPair::new(&mut rng);
|
||||
|
||||
let host_info_no_noise = HostInformation {
|
||||
ip_address: vec!["1.1.1.1".parse().unwrap()],
|
||||
hostname: Some("foomp.com".to_string()),
|
||||
keys: crate::api::v1::node::models::HostKeys {
|
||||
ed25519_identity: *ed22519.public_key(),
|
||||
x25519_sphinx: *x25519_sphinx.public_key(),
|
||||
x25519_noise: None,
|
||||
},
|
||||
};
|
||||
|
||||
let host_info_noise = crate::api::v1::node::models::HostInformation {
|
||||
ip_address: vec!["1.1.1.1".parse().unwrap()],
|
||||
hostname: Some("foomp.com".to_string()),
|
||||
keys: crate::api::v1::node::models::HostKeys {
|
||||
ed25519_identity: *ed22519.public_key(),
|
||||
x25519_sphinx: *x25519_sphinx.public_key(),
|
||||
x25519_noise: Some(VersionedNoiseKey {
|
||||
version: NoiseVersion::V1,
|
||||
x25519_pubkey: *x25519_noise.public_key(),
|
||||
}),
|
||||
},
|
||||
};
|
||||
|
||||
// signature on legacy data
|
||||
let current_struct_no_noise =
|
||||
SignedData::new(host_info_no_noise, ed22519.private_key()).unwrap();
|
||||
let current_struct_noise = SignedData::new(host_info_noise, ed22519.private_key()).unwrap();
|
||||
|
||||
assert!(current_struct_no_noise.verify(ed22519.public_key()));
|
||||
assert!(current_struct_no_noise.verify_host_information());
|
||||
|
||||
// if noise key is present, the signature is actually valid
|
||||
assert!(current_struct_noise.verify(ed22519.public_key()));
|
||||
assert!(current_struct_noise.verify_host_information())
|
||||
|
||||
Generated
+12
@@ -4017,6 +4017,7 @@ dependencies = [
|
||||
"nym-mixnet-contract-common",
|
||||
"nym-network-defaults",
|
||||
"nym-node-requests",
|
||||
"nym-noise-keys",
|
||||
"nym-serde-helpers",
|
||||
"nym-ticketbooks-merkle",
|
||||
"schemars",
|
||||
@@ -4277,6 +4278,7 @@ dependencies = [
|
||||
"nym-crypto",
|
||||
"nym-exit-policy",
|
||||
"nym-http-api-client",
|
||||
"nym-noise-keys",
|
||||
"nym-wireguard-types",
|
||||
"schemars",
|
||||
"serde",
|
||||
@@ -4287,6 +4289,16 @@ dependencies = [
|
||||
"utoipa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nym-noise-keys"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"nym-crypto",
|
||||
"schemars",
|
||||
"serde",
|
||||
"utoipa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nym-pemstore"
|
||||
version = "0.3.0"
|
||||
|
||||
Reference in New Issue
Block a user