Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 42 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mm2src/mm2_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ gstuff = { version = "0.7", features = ["nightly"] }
mm2_rpc = { path = "../mm2_rpc" }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
futures-rustls = { version = "0.21.1" }
gstuff = { version = "0.7", features = ["nightly"] }
48 changes: 48 additions & 0 deletions mm2src/mm2_core/src/mm_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ cfg_wasm32! {

cfg_native! {
use db_common::sqlite::rusqlite::Connection;
use futures_rustls::webpki::DNSNameRef;
use mm2_metrics::prometheus;
use mm2_metrics::MmMetricsError;
use std::net::{IpAddr, SocketAddr, AddrParseError};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::MutexGuard;
}

Expand Down Expand Up @@ -197,6 +199,52 @@ impl MmCtx {
Ok(SocketAddr::new(ip, port as u16))
}

/// Whether to use HTTPS for RPC server or not.
#[cfg(not(target_arch = "wasm32"))]
pub fn is_https(&self) -> bool { self.conf["https"].as_bool().unwrap_or(false) }

/// SANs for self-signed certificate generation.
#[cfg(not(target_arch = "wasm32"))]
pub fn alt_names(&self) -> Result<Vec<String>, String> {
// Helper function to validate `alt_names` entries
fn validate_alt_name(name: &str) -> Result<(), String> {
// Check if it is a valid IP address
if let Ok(ip) = IpAddr::from_str(name) {
if ip.is_unspecified() {
return ERR!("IP address {} must be specified", ip);
}
return Ok(());
}

// Check if it is a valid DNS name
if DNSNameRef::try_from_ascii_str(name).is_ok() {
return Ok(());
}

ERR!(
"`alt_names` contains {} which is neither a valid IP address nor a valid DNS name",
name
)
}

if self.conf["alt_names"].is_null() {
// Default SANs
return Ok(vec!["localhost".to_string(), "127.0.0.1".to_string()]);
}

json::from_value(self.conf["alt_names"].clone())
.map_err(|e| format!("`alt_names` is not a valid JSON array of strings: {}", e))
.and_then(|names: Vec<String>| {
if names.is_empty() {
return ERR!("alt_names is empty");
}
for name in &names {
try_s!(validate_alt_name(name));
}
Ok(names)
})
}

/// MM database path.
/// Defaults to a relative "DB".
///
Expand Down
7 changes: 5 additions & 2 deletions mm2src/mm2_main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,20 @@ enum-primitive-derive = "0.2"
futures01 = { version = "0.1", package = "futures" }
futures = { version = "0.3.1", package = "futures", features = ["compat", "async-await"] }
gstuff = { version = "0.7", features = ["nightly"] }
mm2_gui_storage = { path = "../mm2_gui_storage" }
hash256-std-hasher = "0.15.2"
hash-db = "0.15.2"
hex = "0.4.2"
http = "0.2"
hw_common = { path = "../hw_common" }
instant = { version = "0.1.12" }
itertools = "0.10"
keys = { path = "../mm2_bitcoin/keys" }
lazy_static = "1.4"
# ledger = { path = "../ledger" }
libc = "0.2"
mm2_core = { path = "../mm2_core" }
mm2_err_handle = { path = "../mm2_err_handle" }
mm2_gui_storage = { path = "../mm2_gui_storage" }
mm2_io = { path = "../mm2_io" }
mm2-libp2p = { path = "../mm2_libp2p" }
mm2_metrics = { path = "../mm2_metrics" }
Expand Down Expand Up @@ -90,7 +91,6 @@ sp-trie = { version = "6.0", default-features = false }
trie-db = { version = "0.23.1", default-features = false }
trie-root = "0.16.0"
uuid = { version = "1.2.2", features = ["fast-rng", "serde", "v4"] }
instant = { version = "0.1.12" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { version = "0.1.12", features = ["wasm-bindgen"] }
Expand All @@ -106,6 +106,9 @@ web-sys = { version = "0.3.55", features = ["console"] }
dirs = { version = "1" }
futures-rustls = { version = "0.21.1" }
hyper = { version = "0.14.26", features = ["client", "http2", "server", "tcp"] }
rcgen = "0.10"
rustls = { version = "0.20", default-features = false }
rustls-pemfile = "1.0.2"
tokio = { version = "1.20", features = ["io-util", "rt-multi-thread", "net"] }

[target.'cfg(windows)'.dependencies]
Expand Down
Loading