Skip to content

Commit

Permalink
refactor: centralise definition of certificate server name
Browse files Browse the repository at this point in the history
This was declared both in `config` and `endpoint`, but is now exported
from `config` and imported in `endpoint`.
  • Loading branch information
Chris Connelly authored and lionel-faber committed Oct 13, 2021
1 parent c6a9a42 commit c88fbdb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pub const DEFAULT_RETRY_DELAY_RAND_FACTOR: f64 = 0.3;
/// Default for [`RetryConfig::retrying_max_elapsed_time`] (30 s).
pub const DEFAULT_RETRYING_MAX_ELAPSED_TIME: Duration = Duration::from_secs(30);

const MAIDSAFE_DOMAIN: &str = "maidsafe.net";
// We use a hard-coded server name for self-signed certificates.
pub(crate) const SERVER_NAME: &str = "maidsafe.net";

// Convenience alias – not for export.
type Result<T, E = ConfigError> = std::result::Result<T, E>;
Expand Down Expand Up @@ -287,7 +288,7 @@ impl InternalConfig {
}

fn generate_cert() -> Result<(quinn::Certificate, quinn::PrivateKey)> {
let cert = rcgen::generate_simple_self_signed(vec![MAIDSAFE_DOMAIN.to_string()])?;
let cert = rcgen::generate_simple_self_signed(vec![SERVER_NAME.to_string()])?;

let cert_der = cert.serialize_der()?;
let key_der = cert.serialize_private_key_der();
Expand Down
8 changes: 2 additions & 6 deletions src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use super::igd::{forward_port, IgdError};
use super::wire_msg::WireMsg;
use super::{
config::{Config, InternalConfig},
config::{Config, InternalConfig, SERVER_NAME},
connection_deduplicator::{ConnectionDeduplicator, DedupHandle},
connection_pool::{ConnId, ConnectionPool, ConnectionRemover},
connections::{
Expand All @@ -36,10 +36,6 @@ use tokio::sync::mpsc::{self, Receiver as MpscReceiver, Sender as MpscSender};
use tokio::time::{timeout, Duration};
use tracing::{debug, error, info, trace, warn};

/// Host name of the Quic communication certificate used by peers
// FIXME: make it configurable
const CERT_SERVER_NAME: &str = "MaidSAFE.net";

// Number of seconds before timing out the IGD request to forward a port.
#[cfg(feature = "igd")]
const PORT_FORWARD_TIMEOUT: Duration = Duration::from_secs(30);
Expand Down Expand Up @@ -497,7 +493,7 @@ impl<I: ConnId> Endpoint<I> {
let connecting = match self.quic_endpoint.connect_with(
self.config.client.clone(),
node_addr,
CERT_SERVER_NAME,
SERVER_NAME,
) {
Ok(conn) => Ok(conn),
Err(error) => {
Expand Down

0 comments on commit c88fbdb

Please sign in to comment.