mirror of
https://github.com/rosenpass/rosenpass.git
synced 2026-02-27 14:03:11 -08:00
chore: Restructure imports in various places
This commit is contained in:
@@ -1,14 +1,15 @@
|
|||||||
use anyhow::Result;
|
|
||||||
use rosenpass::protocol::basic_types::{MsgBuf, SPk, SSk, SymKey};
|
|
||||||
use rosenpass::protocol::{CryptoServer, HandleMsgResult, PeerPtr, ProtocolVersion};
|
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
|
||||||
|
use anyhow::Result;
|
||||||
|
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||||
|
|
||||||
use rosenpass_cipher_traits::primitives::Kem;
|
use rosenpass_cipher_traits::primitives::Kem;
|
||||||
use rosenpass_ciphers::StaticKem;
|
use rosenpass_ciphers::StaticKem;
|
||||||
|
|
||||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
|
||||||
use rosenpass_secret_memory::secret_policy_try_use_memfd_secrets;
|
use rosenpass_secret_memory::secret_policy_try_use_memfd_secrets;
|
||||||
|
|
||||||
|
use rosenpass::protocol::basic_types::{MsgBuf, SPk, SSk, SymKey};
|
||||||
|
use rosenpass::protocol::{CryptoServer, HandleMsgResult, PeerPtr, ProtocolVersion};
|
||||||
|
|
||||||
fn handle(
|
fn handle(
|
||||||
tx: &mut CryptoServer,
|
tx: &mut CryptoServer,
|
||||||
msgb: &mut MsgBuf,
|
msgb: &mut MsgBuf,
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
use std::{
|
use std::io::{self, Write};
|
||||||
collections::HashMap,
|
use std::time::{Duration, Instant};
|
||||||
hint::black_box,
|
use std::{collections::HashMap, hint::black_box, ops::DerefMut};
|
||||||
io::{self, Write},
|
|
||||||
ops::DerefMut,
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
use libcrux_test_utils::tracing::{EventType, Trace as _};
|
use libcrux_test_utils::tracing::{EventType, Trace as _};
|
||||||
|
|
||||||
use rosenpass_cipher_traits::primitives::Kem;
|
use rosenpass_cipher_traits::primitives::Kem;
|
||||||
|
|||||||
@@ -1,57 +1,32 @@
|
|||||||
/// This contains the bulk of the rosenpass server IO handling code whereas
|
/// This contains the bulk of the rosenpass server IO handling code whereas
|
||||||
/// the actual cryptographic code lives in the [crate::protocol] module
|
/// the actual cryptographic code lives in the [crate::protocol] module
|
||||||
use anyhow::bail;
|
use std::collections::{HashMap, VecDeque};
|
||||||
|
use std::io::{stdout, ErrorKind, Write};
|
||||||
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
use std::{cell::Cell, fmt::Debug, io, path::PathBuf, slice};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::{bail, Context, Result};
|
||||||
use anyhow::Result;
|
|
||||||
use derive_builder::Builder;
|
use derive_builder::Builder;
|
||||||
use log::{error, info, warn};
|
use log::{error, info, warn};
|
||||||
use mio::Interest;
|
use mio::{Interest, Token};
|
||||||
use mio::Token;
|
|
||||||
use rosenpass_secret_memory::Public;
|
|
||||||
use rosenpass_secret_memory::Secret;
|
|
||||||
use rosenpass_util::build::ConstructionSite;
|
|
||||||
use rosenpass_util::file::StoreValueB64;
|
|
||||||
use rosenpass_util::functional::run;
|
|
||||||
use rosenpass_util::functional::ApplyExt;
|
|
||||||
use rosenpass_util::io::IoResultKindHintExt;
|
|
||||||
use rosenpass_util::io::SubstituteForIoErrorKindExt;
|
|
||||||
use rosenpass_util::option::SomeExt;
|
|
||||||
use rosenpass_util::result::OkExt;
|
|
||||||
use rosenpass_wireguard_broker::WireguardBrokerMio;
|
|
||||||
use rosenpass_wireguard_broker::{WireguardBrokerCfg, WG_KEY_LEN};
|
|
||||||
use zerocopy::AsBytes;
|
use zerocopy::AsBytes;
|
||||||
|
|
||||||
use std::cell::Cell;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::collections::VecDeque;
|
|
||||||
use std::fmt::Debug;
|
|
||||||
use std::io;
|
|
||||||
use std::io::stdout;
|
|
||||||
use std::io::ErrorKind;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::net::Ipv4Addr;
|
|
||||||
use std::net::Ipv6Addr;
|
|
||||||
use std::net::SocketAddr;
|
|
||||||
use std::net::SocketAddrV4;
|
|
||||||
use std::net::SocketAddrV6;
|
|
||||||
use std::net::ToSocketAddrs;
|
|
||||||
use std::path::PathBuf;
|
|
||||||
use std::slice;
|
|
||||||
use std::time::Duration;
|
|
||||||
use std::time::Instant;
|
|
||||||
|
|
||||||
use crate::config::ProtocolVersion;
|
|
||||||
use crate::protocol::BuildCryptoServer;
|
|
||||||
use crate::protocol::HostIdentification;
|
|
||||||
use crate::{
|
|
||||||
config::Verbosity,
|
|
||||||
protocol::basic_types::{MsgBuf, SPk, SSk, SymKey},
|
|
||||||
protocol::{timing::Timing, CryptoServer, PeerPtr},
|
|
||||||
};
|
|
||||||
use rosenpass_util::attempt;
|
use rosenpass_util::attempt;
|
||||||
use rosenpass_util::b64::B64Display;
|
use rosenpass_util::functional::{run, ApplyExt};
|
||||||
|
use rosenpass_util::io::{IoResultKindHintExt, SubstituteForIoErrorKindExt};
|
||||||
|
use rosenpass_util::{
|
||||||
|
b64::B64Display, build::ConstructionSite, file::StoreValueB64, option::SomeExt, result::OkExt,
|
||||||
|
};
|
||||||
|
|
||||||
|
use rosenpass_secret_memory::{Public, Secret};
|
||||||
|
use rosenpass_wireguard_broker::{WireguardBrokerCfg, WireguardBrokerMio, WG_KEY_LEN};
|
||||||
|
|
||||||
|
use crate::config::{ProtocolVersion, Verbosity};
|
||||||
|
|
||||||
|
use crate::protocol::basic_types::{MsgBuf, SPk, SSk, SymKey};
|
||||||
|
use crate::protocol::timing::Timing;
|
||||||
|
use crate::protocol::{BuildCryptoServer, CryptoServer, HostIdentification, PeerPtr};
|
||||||
|
|
||||||
/// The maximum size of a base64 encoded symmetric key (estimate)
|
/// The maximum size of a base64 encoded symmetric key (estimate)
|
||||||
pub const MAX_B64_KEY_SIZE: usize = 32 * 5 / 3;
|
pub const MAX_B64_KEY_SIZE: usize = 32 * 5 / 3;
|
||||||
|
|||||||
@@ -7,20 +7,18 @@
|
|||||||
//! - TODO: support `~` in <https://github.com/rosenpass/rosenpass/issues/237>
|
//! - TODO: support `~` in <https://github.com/rosenpass/rosenpass/issues/237>
|
||||||
//! - TODO: provide tooling to create config file from shell <https://github.com/rosenpass/rosenpass/issues/247>
|
//! - TODO: provide tooling to create config file from shell <https://github.com/rosenpass/rosenpass/issues/247>
|
||||||
|
|
||||||
use crate::protocol::basic_types::{SPk, SSk};
|
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs};
|
||||||
use rosenpass_util::file::LoadValue;
|
use std::path::{Path, PathBuf};
|
||||||
use std::{
|
use std::{collections::HashSet, fs, io::Write};
|
||||||
collections::HashSet,
|
|
||||||
fs,
|
|
||||||
io::Write,
|
|
||||||
net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSocketAddrs},
|
|
||||||
path::{Path, PathBuf},
|
|
||||||
};
|
|
||||||
|
|
||||||
use anyhow::{bail, ensure};
|
use anyhow::{bail, ensure};
|
||||||
use rosenpass_util::file::{fopen_w, Visibility};
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use rosenpass_util::file::{fopen_w, LoadValue, Visibility};
|
||||||
|
|
||||||
|
use crate::protocol::basic_types::{SPk, SSk};
|
||||||
|
|
||||||
use crate::app_server::AppServer;
|
use crate::app_server::AppServer;
|
||||||
|
|
||||||
#[cfg(feature = "experiment_api")]
|
#[cfg(feature = "experiment_api")]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
use rosenpass_util::mem::{DiscardResultExt, SwapWithDefaultExt};
|
||||||
|
use rosenpass_util::{build::Build, result::ensure_or};
|
||||||
|
|
||||||
|
use crate::config::ProtocolVersion;
|
||||||
|
|
||||||
use super::basic_types::{SPk, SSk, SymKey};
|
use super::basic_types::{SPk, SSk, SymKey};
|
||||||
use super::{CryptoServer, PeerPtr};
|
use super::{CryptoServer, PeerPtr};
|
||||||
use crate::config::ProtocolVersion;
|
|
||||||
use rosenpass_util::{
|
|
||||||
build::Build,
|
|
||||||
mem::{DiscardResultExt, SwapWithDefaultExt},
|
|
||||||
result::ensure_or,
|
|
||||||
};
|
|
||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
/// A pair of matching public/secret keys used to launch the crypto server.
|
/// A pair of matching public/secret keys used to launch the crypto server.
|
||||||
@@ -386,16 +386,18 @@ impl BuildCryptoServer {
|
|||||||
/// Extracting the server configuration from a builder:
|
/// Extracting the server configuration from a builder:
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// // We have to define the security policy before using Secrets.
|
/// use rosenpass_util::build::Build;
|
||||||
|
/// use rosenpass_secret_memory::secret_policy_use_only_malloc_secrets;
|
||||||
|
///
|
||||||
/// use rosenpass::config::ProtocolVersion;
|
/// use rosenpass::config::ProtocolVersion;
|
||||||
/// use rosenpass::hash_domains::protocol;
|
/// use rosenpass::hash_domains::protocol;
|
||||||
/// use rosenpass_secret_memory::secret_policy_use_only_malloc_secrets;
|
|
||||||
/// secret_policy_use_only_malloc_secrets();
|
|
||||||
///
|
///
|
||||||
/// use rosenpass_util::build::Build;
|
|
||||||
/// use rosenpass::protocol::basic_types::{SymKey, SPk};
|
/// use rosenpass::protocol::basic_types::{SymKey, SPk};
|
||||||
/// use rosenpass::protocol::{BuildCryptoServer, Keypair};
|
/// use rosenpass::protocol::{BuildCryptoServer, Keypair};
|
||||||
///
|
///
|
||||||
|
/// // We have to define the security policy before using Secrets.
|
||||||
|
/// secret_policy_use_only_malloc_secrets();
|
||||||
|
///
|
||||||
/// let keypair = Keypair::random();
|
/// let keypair = Keypair::random();
|
||||||
/// let peer_pk = SPk::random();
|
/// let peer_pk = SPk::random();
|
||||||
/// let mut builder = BuildCryptoServer::new(Some(keypair.clone()), vec![]);
|
/// let mut builder = BuildCryptoServer::new(Some(keypair.clone()), vec![]);
|
||||||
|
|||||||
@@ -24,11 +24,14 @@
|
|||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! use std::ops::DerefMut;
|
//! use std::ops::DerefMut;
|
||||||
|
//!
|
||||||
//! use rosenpass_secret_memory::policy::*;
|
//! use rosenpass_secret_memory::policy::*;
|
||||||
//! use rosenpass_cipher_traits::primitives::Kem;
|
//! use rosenpass_cipher_traits::primitives::Kem;
|
||||||
//! use rosenpass_ciphers::StaticKem;
|
//! use rosenpass_ciphers::StaticKem;
|
||||||
|
//!
|
||||||
//! use rosenpass::protocol::basic_types::{SSk, SPk, MsgBuf, SymKey};
|
//! use rosenpass::protocol::basic_types::{SSk, SPk, MsgBuf, SymKey};
|
||||||
//! use rosenpass::protocol::{PeerPtr, CryptoServer};
|
//! use rosenpass::protocol::{PeerPtr, CryptoServer};
|
||||||
|
//!
|
||||||
//! # fn main() -> anyhow::Result<()> {
|
//! # fn main() -> anyhow::Result<()> {
|
||||||
//! // Set security policy for storing secrets
|
//! // Set security policy for storing secrets
|
||||||
//!
|
//!
|
||||||
|
|||||||
@@ -35,23 +35,19 @@ use rosenpass_util::{
|
|||||||
|
|
||||||
use crate::{hash_domains, msgs::*, RosenpassError};
|
use crate::{hash_domains, msgs::*, RosenpassError};
|
||||||
|
|
||||||
|
use super::basic_types::{
|
||||||
|
BiscuitId, EPk, ESk, MsgBuf, PeerId, PeerNo, SPk, SSk, SessionId, SymKey, XAEADNonce,
|
||||||
|
};
|
||||||
use super::constants::{
|
use super::constants::{
|
||||||
BISCUIT_EPOCH, COOKIE_SECRET_EPOCH, COOKIE_SECRET_LEN, COOKIE_VALUE_LEN,
|
BISCUIT_EPOCH, COOKIE_SECRET_EPOCH, COOKIE_SECRET_LEN, COOKIE_VALUE_LEN,
|
||||||
PEER_COOKIE_VALUE_EPOCH, REJECT_AFTER_TIME, REKEY_AFTER_TIME_INITIATOR,
|
PEER_COOKIE_VALUE_EPOCH, REJECT_AFTER_TIME, REKEY_AFTER_TIME_INITIATOR,
|
||||||
REKEY_AFTER_TIME_RESPONDER, RETRANSMIT_DELAY_BEGIN, RETRANSMIT_DELAY_END,
|
REKEY_AFTER_TIME_RESPONDER, RETRANSMIT_DELAY_BEGIN, RETRANSMIT_DELAY_END,
|
||||||
RETRANSMIT_DELAY_GROWTH, RETRANSMIT_DELAY_JITTER,
|
RETRANSMIT_DELAY_GROWTH, RETRANSMIT_DELAY_JITTER,
|
||||||
};
|
};
|
||||||
|
use super::cookies::{BiscuitKey, CookieSecret, CookieStore};
|
||||||
use super::index::{PeerIndex, PeerIndexKey};
|
use super::index::{PeerIndex, PeerIndexKey};
|
||||||
use super::timing::{has_happened, Timing, BCE, UNENDING};
|
use super::timing::{has_happened, Timing, BCE, UNENDING};
|
||||||
use super::zerocopy::{truncating_cast_into, truncating_cast_into_nomut};
|
use super::zerocopy::{truncating_cast_into, truncating_cast_into_nomut};
|
||||||
use super::{
|
|
||||||
basic_types::{
|
|
||||||
BiscuitId, EPk, ESk, MsgBuf, PeerId, PeerNo, SPk, SSk, SessionId, SymKey, XAEADNonce,
|
|
||||||
},
|
|
||||||
cookies::BiscuitKey,
|
|
||||||
};
|
|
||||||
|
|
||||||
use super::cookies::{CookieSecret, CookieStore};
|
|
||||||
|
|
||||||
#[cfg(feature = "trace_bench")]
|
#[cfg(feature = "trace_bench")]
|
||||||
use rosenpass_util::trace_bench::Trace as _;
|
use rosenpass_util::trace_bench::Trace as _;
|
||||||
@@ -177,11 +173,13 @@ impl From<crate::config::ProtocolVersion> for ProtocolVersion {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use std::ops::DerefMut;
|
/// use std::ops::DerefMut;
|
||||||
/// use rosenpass::protocol::basic_types::{SSk, SPk, SymKey};
|
///
|
||||||
/// use rosenpass::protocol::{Peer, ProtocolVersion};
|
|
||||||
/// use rosenpass_ciphers::StaticKem;
|
/// use rosenpass_ciphers::StaticKem;
|
||||||
/// use rosenpass_cipher_traits::primitives::Kem;
|
/// use rosenpass_cipher_traits::primitives::Kem;
|
||||||
///
|
///
|
||||||
|
/// use rosenpass::protocol::basic_types::{SSk, SPk, SymKey};
|
||||||
|
/// use rosenpass::protocol::{Peer, ProtocolVersion};
|
||||||
|
///
|
||||||
/// rosenpass_secret_memory::secret_policy_try_use_memfd_secrets();
|
/// rosenpass_secret_memory::secret_policy_try_use_memfd_secrets();
|
||||||
///
|
///
|
||||||
/// let (mut sskt, mut spkt) = (SSk::zero(), SPk::zero());
|
/// let (mut sskt, mut spkt) = (SSk::zero(), SPk::zero());
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ use rosenpass_util::mem::DiscardResultExt;
|
|||||||
|
|
||||||
use crate::msgs::{EmptyData, Envelope, InitConf, InitHello, MsgType, RespHello, MAX_MESSAGE_LEN};
|
use crate::msgs::{EmptyData, Envelope, InitConf, InitHello, MsgType, RespHello, MAX_MESSAGE_LEN};
|
||||||
|
|
||||||
|
use super::basic_types::{MsgBuf, SPk, SSk, SymKey};
|
||||||
|
use super::constants::REKEY_AFTER_TIME_RESPONDER;
|
||||||
|
use super::zerocopy::{truncating_cast_into, truncating_cast_into_nomut};
|
||||||
use super::{
|
use super::{
|
||||||
basic_types::{MsgBuf, SPk, SSk, SymKey},
|
|
||||||
constants::REKEY_AFTER_TIME_RESPONDER,
|
|
||||||
zerocopy::{truncating_cast_into, truncating_cast_into_nomut},
|
|
||||||
CryptoServer, HandleMsgResult, HostIdentification, KnownInitConfResponsePtr, PeerPtr,
|
CryptoServer, HandleMsgResult, HostIdentification, KnownInitConfResponsePtr, PeerPtr,
|
||||||
PollResult, ProtocolVersion,
|
PollResult, ProtocolVersion,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,21 +1,14 @@
|
|||||||
use std::{
|
use std::thread::{self, sleep};
|
||||||
net::SocketAddr,
|
use std::{net::SocketAddr, ops::DerefMut, str::FromStr, sync::mpsc, time::Duration};
|
||||||
ops::DerefMut,
|
|
||||||
str::FromStr,
|
|
||||||
sync::mpsc,
|
|
||||||
thread::{self, sleep},
|
|
||||||
time::Duration,
|
|
||||||
};
|
|
||||||
|
|
||||||
use rosenpass::config::ProtocolVersion;
|
|
||||||
use rosenpass::{
|
|
||||||
app_server::{AppServer, AppServerTest, MAX_B64_KEY_SIZE},
|
|
||||||
protocol::basic_types::{SPk, SSk, SymKey},
|
|
||||||
};
|
|
||||||
use rosenpass_cipher_traits::primitives::Kem;
|
use rosenpass_cipher_traits::primitives::Kem;
|
||||||
use rosenpass_ciphers::StaticKem;
|
use rosenpass_ciphers::StaticKem;
|
||||||
use rosenpass_util::{file::LoadValueB64, functional::run, mem::DiscardResultExt, result::OkExt};
|
use rosenpass_util::{file::LoadValueB64, functional::run, mem::DiscardResultExt, result::OkExt};
|
||||||
|
|
||||||
|
use rosenpass::app_server::{AppServer, AppServerTest, MAX_B64_KEY_SIZE};
|
||||||
|
use rosenpass::config::ProtocolVersion;
|
||||||
|
use rosenpass::protocol::basic_types::{SPk, SSk, SymKey};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn key_exchange_with_app_server_v02() -> anyhow::Result<()> {
|
fn key_exchange_with_app_server_v02() -> anyhow::Result<()> {
|
||||||
key_exchange_with_app_server(ProtocolVersion::V02)
|
key_exchange_with_app_server(ProtocolVersion::V02)
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ use rosenpass_cipher_traits::primitives::Kem;
|
|||||||
use rosenpass_ciphers::StaticKem;
|
use rosenpass_ciphers::StaticKem;
|
||||||
use rosenpass_util::result::OkExt;
|
use rosenpass_util::result::OkExt;
|
||||||
|
|
||||||
use rosenpass::protocol::{
|
use rosenpass::protocol::basic_types::{MsgBuf, SPk, SSk, SymKey};
|
||||||
basic_types::{MsgBuf, SPk, SSk, SymKey},
|
use rosenpass::protocol::testutils::time_travel_forward;
|
||||||
testutils::time_travel_forward,
|
use rosenpass::protocol::timing::{Timing, UNENDING};
|
||||||
timing::{Timing, UNENDING},
|
use rosenpass::protocol::{CryptoServer, HostIdentification, PeerPtr, PollResult, ProtocolVersion};
|
||||||
CryptoServer, HostIdentification, PeerPtr, PollResult, ProtocolVersion,
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: Most of the utility functions in here should probably be moved to
|
// TODO: Most of the utility functions in here should probably be moved to
|
||||||
// rosenpass::protocol::testutils;
|
// rosenpass::protocol::testutils;
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
use anyhow::Error;
|
use std::{
|
||||||
|
future::Future, net::SocketAddr, ops::DerefMut, path::PathBuf, pin::Pin, process::Command,
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
|
|
||||||
|
use anyhow::{Error, Result};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::future::Future;
|
|
||||||
use std::ops::DerefMut;
|
use rosenpass::config::ProtocolVersion;
|
||||||
use std::pin::Pin;
|
|
||||||
use std::sync::Arc;
|
|
||||||
use std::{net::SocketAddr, path::PathBuf, process::Command};
|
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||||
use crate::key::WG_B64_LEN;
|
use crate::key::WG_B64_LEN;
|
||||||
use anyhow::Result;
|
|
||||||
use rosenpass::config::ProtocolVersion;
|
|
||||||
|
|
||||||
/// Used to define a peer for the rosenpass connection that consists of
|
/// Used to define a peer for the rosenpass connection that consists of
|
||||||
/// a directory for storing public keys and optionally an IP address and port of the endpoint,
|
/// a directory for storing public keys and optionally an IP address and port of the endpoint,
|
||||||
|
|||||||
Reference in New Issue
Block a user