Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check tls certs exist for grpc management serve #637

Merged
merged 3 commits into from
Mar 8, 2025
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: 43 additions & 3 deletions crates/cdk-mint-rpc/src/proto/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,49 @@ impl MintRPCServer {
let server = match tls_dir {
Some(tls_dir) => {
tracing::info!("TLS configuration found, starting secure server");
let cert = std::fs::read_to_string(tls_dir.join("server.pem"))?;
let key = std::fs::read_to_string(tls_dir.join("server.key"))?;
let client_ca_cert = std::fs::read_to_string(tls_dir.join("ca.pem"))?;
let server_pem_path = tls_dir.join("server.pem");
let server_key_path = tls_dir.join("server.key");
let ca_pem_path = tls_dir.join("ca.pem");

if !server_pem_path.exists() {
tracing::error!(
"Server certificate file does not exist: {}",
server_pem_path.display()
);
return Err(Error::Io(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!(
"Server certificate file not found: {}",
server_pem_path.display()
),
)));
}

if !server_key_path.exists() {
tracing::error!(
"Server key file does not exist: {}",
server_key_path.display()
);
return Err(Error::Io(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("Server key file not found: {}", server_key_path.display()),
)));
}

if !ca_pem_path.exists() {
tracing::error!(
"CA certificate file does not exist: {}",
ca_pem_path.display()
);
return Err(Error::Io(std::io::Error::new(
std::io::ErrorKind::NotFound,
format!("CA certificate file not found: {}", ca_pem_path.display()),
)));
}

let cert = std::fs::read_to_string(&server_pem_path)?;
let key = std::fs::read_to_string(&server_key_path)?;
let client_ca_cert = std::fs::read_to_string(&ca_pem_path)?;
let client_ca_cert = Certificate::from_pem(client_ca_cert);
let server_identity = Identity::from_pem(cert, key);
let tls_config = ServerTlsConfig::new()
Expand Down
2 changes: 1 addition & 1 deletion crates/cdk-mintd/example.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mnemonic = ""
# enable_swagger_ui = false

[mint_management_rpc]
enabled = true
# enabled = false
# address = "127.0.0.1"
# port = 8086

Expand Down
5 changes: 5 additions & 0 deletions crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ async fn main() -> anyhow::Result<()> {

let tls_dir = rpc_settings.tls_dir_path.unwrap_or(work_dir.join("tls"));

if !tls_dir.exists() {
tracing::error!("TLS directory does not exist: {}", tls_dir.display());
bail!("Cannot start RPC server: TLS directory does not exist");
}

mint_rpc.start(Some(tls_dir)).await?;

rpc_server = Some(mint_rpc);
Expand Down
Loading