diff --git a/.github/workflows/implementation-tests.yml b/.github/workflows/implementation-tests.yml index e58a58c..ae6e71a 100644 --- a/.github/workflows/implementation-tests.yml +++ b/.github/workflows/implementation-tests.yml @@ -45,3 +45,4 @@ jobs: run: | cd vss-server/impls cargo test -- --test-threads=1 + cargo test --no-default-features -- --test-threads=1 diff --git a/Cargo.toml b/Cargo.toml index 10c1189..f7388fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ repository = "https://github.com/lightningdevkit/vss-server/" [workspace.dependencies] api = { package = "vss-api", version = "0.1.0-alpha.0", path = "./api" } auth-impls = { package = "vss-auth-impls", version = "0.1.0-alpha.0", path = "./auth-impls" } -impls = { package = "vss-impls", version = "0.1.0-alpha.0", path = "./impls" } +impls = { package = "vss-impls", version = "0.1.0-alpha.0", path = "./impls", default-features = false } [profile.release] panic = "abort" diff --git a/api/Cargo.toml b/api/Cargo.toml index 6b77c04..4516567 100644 --- a/api/Cargo.toml +++ b/api/Cargo.toml @@ -10,13 +10,13 @@ homepage.workspace = true repository.workspace = true [dependencies] -async-trait = "0.1.77" -prost = { version = "0.11.6", default-features = false, features = ["std", "prost-derive"] } -bytes = "1.4.0" -rand = { version = "0.8.5", optional = true} +async-trait = "0.1.13" +prost = { version = "0.11", default-features = false, features = ["std", "prost-derive"] } +bytes = "1" +rand = { version = "0.8", optional = true} [target.'cfg(genproto)'.build-dependencies] -prost-build = { version = "0.11.3" } +prost-build = { version = "0.11" } [dev-dependencies] diff --git a/auth-impls/Cargo.toml b/auth-impls/Cargo.toml index d167f06..07f1423 100644 --- a/auth-impls/Cargo.toml +++ b/auth-impls/Cargo.toml @@ -15,15 +15,15 @@ sigs = [ "bitcoin_hashes", "hex-conservative", "secp256k1" ] [dependencies] api = { workspace = true } -async-trait = "0.1.77" -base64 = { version = "0.22.1", optional = true, default-features = false, features = ["std"] } +async-trait = "0.1.13" +base64 = { version = "0.22", optional = true, default-features = false, features = ["std"] } bitcoin_hashes = { version = "1.0", optional = true, default-features = false } hex-conservative = { version = "1.0", optional = true, default-features = false } -openssl = { version = "0.10.75", optional = true, default-features = false } +openssl = { version = "0.10.39", optional = true, default-features = false } secp256k1 = { version = "0.31", optional = true, default-features = false, features = [ "global-context" ] } -serde = { version = "1.0.210", optional = true, default-features = false, features = ["derive"] } -serde_json = { version = "1.0.149", optional = true, default-features = false, features = ["std"] } +serde = { version = "1.0.184", optional = true, default-features = false, features = ["derive"] } +serde_json = { version = "1.0.45", optional = true, default-features = false, features = ["std"] } [dev-dependencies] -jsonwebtoken = { version = "9.3.0", default-features = false, features = ["use_pem"] } -tokio = { version = "1.38.0", default-features = false, features = ["rt-multi-thread", "macros"] } +jsonwebtoken = { version = "9", default-features = false, features = ["use_pem"] } +tokio = { version = "1.30", default-features = false, features = ["rt-multi-thread", "macros"] } diff --git a/impls/Cargo.toml b/impls/Cargo.toml index 967600b..4af495e 100644 --- a/impls/Cargo.toml +++ b/impls/Cargo.toml @@ -9,17 +9,21 @@ license.workspace = true homepage.workspace = true repository.workspace = true +[features] +default = ["postgres-native-tls"] +postgres-native-tls = ["dep:native-tls", "dep:postgres-native-tls"] + [dependencies] -async-trait = "0.1.77" +async-trait = "0.1.13" api = { workspace = true } -chrono = "0.4.38" -tokio-postgres = { version = "0.7.12", features = ["with-chrono-0_4"] } -bytes = "1.4.0" -tokio = { version = "1.38.0", default-features = false, features = ["rt", "macros"] } -native-tls = { version = "0.2.14", default-features = false } -postgres-native-tls = { version = "0.5.2", default-features = false, features = ["runtime"] } -log = { version = "0.4.29", default-features = false } +chrono = "0.4.16" +tokio-postgres = { version = "0.7.15", features = ["with-chrono-0_4"] } +bytes = "1" +tokio = { version = "1.30", default-features = false, features = ["rt", "macros"] } +native-tls = { version = "0.2.4", optional = true, default-features = false } +postgres-native-tls = { version = "0.5", optional = true, default-features = false, features = ["runtime"] } +log = { version = "0.4.8", default-features = false } [dev-dependencies] -tokio = { version = "1.38.0", default-features = false, features = ["rt-multi-thread", "macros"] } +tokio = { version = "1.30", default-features = false, features = ["rt-multi-thread", "macros"] } api = { workspace = true, features = ["_test_utils"] } diff --git a/impls/src/lib.rs b/impls/src/lib.rs index d58b84e..d157ab4 100644 --- a/impls/src/lib.rs +++ b/impls/src/lib.rs @@ -5,6 +5,8 @@ //! simplify the development process for Lightning wallets by providing a secure means to store //! and manage the essential state required for Lightning Network (LN) operations. //! +//! The `postgres-native-tls` feature enables the native TLS backend and is enabled by default. +//! //! [`KvStore`]: api::kv_store::KvStore #![deny(rustdoc::broken_intra_doc_links)] diff --git a/impls/src/postgres_store.rs b/impls/src/postgres_store.rs index 765099e..c00bb92 100644 --- a/impls/src/postgres_store.rs +++ b/impls/src/postgres_store.rs @@ -9,8 +9,6 @@ use api::types::{ use async_trait::async_trait; use bytes::Bytes; use chrono::Utc; -use native_tls::TlsConnector; -use postgres_native_tls::MakeTlsConnector; use std::cmp::min; use std::io::{self, Error, ErrorKind}; use tokio::sync::Mutex; @@ -19,8 +17,6 @@ use tokio_postgres::{error, Client, NoTls, Socket, Transaction}; use log::{debug, info, warn}; -pub use native_tls::Certificate; - pub(crate) struct VssDbRecord { pub(crate) user_token: String, pub(crate) store_id: String, @@ -146,7 +142,8 @@ where pub type PostgresPlaintextBackend = PostgresBackend; /// A postgres backend with TLS connections to the database -pub type PostgresTlsBackend = PostgresBackend; +#[cfg(feature = "postgres-native-tls")] +pub type PostgresTlsBackend = PostgresBackend; async fn make_db_connection( postgres_endpoint: &str, db_name: &str, tls: T, @@ -228,14 +225,15 @@ impl PostgresPlaintextBackend { } } +#[cfg(feature = "postgres-native-tls")] impl PostgresTlsBackend { /// Constructs a [`PostgresTlsBackend`] using `postgres_endpoint` for PostgreSQL connection information. pub async fn new( postgres_endpoint: &str, default_db: &str, vss_db: &str, crt_pem: Option<&str>, ) -> Result { - let mut builder = TlsConnector::builder(); + let mut builder = native_tls::TlsConnector::builder(); if let Some(pem) = crt_pem { - let crt = Certificate::from_pem(pem.as_bytes()).map_err(|e| { + let crt = native_tls::Certificate::from_pem(pem.as_bytes()).map_err(|e| { Error::new( ErrorKind::Other, format!("Failed to parse the PEM formatted certificate: {}", e), @@ -250,7 +248,7 @@ impl PostgresTlsBackend { postgres_endpoint, default_db, vss_db, - MakeTlsConnector::new(connector), + postgres_native_tls::MakeTlsConnector::new(connector), ) .await } diff --git a/server/Cargo.toml b/server/Cargo.toml index 296fc16..b32e4ac 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -10,9 +10,10 @@ homepage.workspace = true repository.workspace = true [features] +default = [ "jwt", "sigs", "postgres-native-tls" ] jwt = ["auth-impls/jwt"] sigs = ["auth-impls/sigs"] -default = [ "jwt", "sigs" ] +postgres-native-tls = ["impls/postgres-native-tls"] [dependencies] api = { workspace = true } @@ -21,15 +22,15 @@ impls = { workspace = true } hyper = { version = "1", default-features = false, features = ["server", "http1"] } http-body-util = { version = "0.1", default-features = false } -hyper-util = { version = "0.1", default-features = false, features = ["server-graceful"] } -tokio = { version = "1.38.0", default-features = false, features = ["time", "signal", "rt-multi-thread", "macros"] } -prost = { version = "0.11.6", default-features = false, features = ["std"] } -bytes = "1.4.0" -serde = { version = "1.0.203", default-features = false, features = ["derive"] } -toml = { version = "0.8.9", default-features = false, features = ["parse"] } -log = { version = "0.4.29", default-features = false, features = ["std"] } -chrono = { version = "0.4", default-features = false, features = ["clock"] } -rand = { version = "0.9.2", default-features = false } +hyper-util = { version = "0.1", default-features = false, features = ["tokio"] } +tokio = { version = "1.30", default-features = false, features = ["time", "signal", "rt-multi-thread", "macros"] } +prost = { version = "0.11", default-features = false, features = ["std"] } +bytes = "1" +serde = { version = "1.0.184", default-features = false, features = ["derive"] } +toml = { version = "0.8", default-features = false, features = ["parse"] } +log = { version = "0.4.8", default-features = false, features = ["std"] } +chrono = { version = "0.4.16", default-features = false, features = ["clock"] } +rand = { version = "0.9", default-features = false } [target.'cfg(noop_authorizer)'.dependencies] api = { workspace = true, features = ["_test_utils"] } diff --git a/server/src/main.rs b/server/src/main.rs index 70205e5..04ca537 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -27,7 +27,9 @@ use api::kv_store::KvStore; use auth_impls::jwt::JWTAuthorizer; #[cfg(feature = "sigs")] use auth_impls::signature::SignatureValidatingAuthorizer; -use impls::postgres_store::{PostgresPlaintextBackend, PostgresTlsBackend}; +use impls::postgres_store::PostgresPlaintextBackend; +#[cfg(feature = "postgres-native-tls")] +use impls::postgres_store::PostgresTlsBackend; use util::logger::ServerLogger; use vss_service::{VssService, VssServiceConfig}; @@ -128,33 +130,42 @@ fn main() { std::process::exit(-1); }); - let store: Arc = if let Some(crt_pem) = config.tls_config { - let postgres_tls_backend = PostgresTlsBackend::new( - &config.postgresql_prefix, - &config.default_db, - &config.vss_db, - crt_pem.as_deref(), - ) - .await - .unwrap_or_else(|e| { - error!("Failed to start postgres TLS backend: {}", e); - std::process::exit(-1); - }); - info!("Connected to PostgreSQL TLS backend, database {}", config.vss_db); - Arc::new(postgres_tls_backend) - } else { - let postgres_plaintext_backend = PostgresPlaintextBackend::new( - &config.postgresql_prefix, - &config.default_db, - &config.vss_db, - ) - .await - .unwrap_or_else(|e| { - error!("Failed to start postgres plaintext backend: {}", e); + let store: Arc = match config.tls_config { + #[cfg(feature = "postgres-native-tls")] + Some(crt_pem) => { + let postgres_tls_backend = PostgresTlsBackend::new( + &config.postgresql_prefix, + &config.default_db, + &config.vss_db, + crt_pem.as_deref(), + ) + .await + .unwrap_or_else(|e| { + error!("Failed to start postgres TLS backend: {}", e); + std::process::exit(-1); + }); + info!("Connected to PostgreSQL TLS backend, database {}", config.vss_db); + Arc::new(postgres_tls_backend) + }, + #[cfg(not(feature = "postgres-native-tls"))] + Some(_) => { + error!("PostgreSQL TLS configuration requires the `postgres-native-tls` feature"); std::process::exit(-1); - }); - info!("Connected to PostgreSQL plaintext backend, database {}", config.vss_db); - Arc::new(postgres_plaintext_backend) + }, + None => { + let postgres_plaintext_backend = PostgresPlaintextBackend::new( + &config.postgresql_prefix, + &config.default_db, + &config.vss_db, + ) + .await + .unwrap_or_else(|e| { + error!("Failed to start postgres plaintext backend: {}", e); + std::process::exit(-1); + }); + info!("Connected to PostgreSQL plaintext backend, database {}", config.vss_db); + Arc::new(postgres_plaintext_backend) + }, }; let rest_svc_listener = TcpListener::bind(&config.bind_address).await.unwrap_or_else(|e| {