Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/implementation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ jobs:
run: |
cd vss-server/impls
cargo test -- --test-threads=1
cargo test --no-default-features -- --test-threads=1
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
14 changes: 7 additions & 7 deletions auth-impls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
22 changes: 13 additions & 9 deletions impls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 2 additions & 0 deletions impls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
14 changes: 6 additions & 8 deletions impls/src/postgres_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -146,7 +142,8 @@ where
pub type PostgresPlaintextBackend = PostgresBackend<NoTls>;

/// A postgres backend with TLS connections to the database
pub type PostgresTlsBackend = PostgresBackend<MakeTlsConnector>;
#[cfg(feature = "postgres-native-tls")]
pub type PostgresTlsBackend = PostgresBackend<postgres_native_tls::MakeTlsConnector>;

async fn make_db_connection<T>(
postgres_endpoint: &str, db_name: &str, tls: T,
Expand Down Expand Up @@ -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<Self, Error> {
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),
Expand All @@ -250,7 +248,7 @@ impl PostgresTlsBackend {
postgres_endpoint,
default_db,
vss_db,
MakeTlsConnector::new(connector),
postgres_native_tls::MakeTlsConnector::new(connector),
)
.await
}
Expand Down
21 changes: 11 additions & 10 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand Down
65 changes: 38 additions & 27 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -128,33 +130,42 @@ fn main() {
std::process::exit(-1);
});

let store: Arc<dyn KvStore> = 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<dyn KvStore> = 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| {
Expand Down
Loading