Skip to content

Conversation

@benthecarman
Copy link
Collaborator

Implement self-signed certificate generation using ring directly, removing the rcgen dependency along with its transitive dependencies (yasna, time). ring was already in our dependency tree via tokio-rustls.

@ldk-reviews-bot
Copy link

ldk-reviews-bot commented Jan 20, 2026

👋 Thanks for assigning @TheBlueMatt as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Copy link

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not actually clear on why we want support for building a self-signed cert? In such cases shouldn't we just not use TLS?

// Clear the high bit to ensure the number is positive.
serial[0] &= 0x7F;

// Validity period: now to now + 10 years

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just fix constants 2025 through 2100?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did til 2049 because its a different encoding after that year

tokio = { version = "1.38.0", default-features = false, features = ["time", "signal", "rt-multi-thread"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["ring"] }
rcgen = { version = "0.13", default-features = false, features = ["ring"] }
ring = { version = "0.17", default-features = false }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given we're gonna ship a binary, I do very much wonder whether we shouldn't use native-tls across the stack in ldk-server. That would avoid us being responsible for shipping updates to ring and rustls in case of a security issue (though honestly I'm not entirely clear on why we want TLS for the RPC to begin with)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that if we did so we could retain the cert-building logic here by switching to secp256k1 rather than secp256r1-via-ring.

Ok(der_sequence(&san_ext))
}

fn build_san_extension(hosts: &[String]) -> Result<Vec<u8>, String> {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given its self-signed anyway why are we building a SAN? Can't we just have a fixed CN of localhost and call it a day?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's been many times where I need to do this with lnd. A lot with docker containers where we need to add the container's name to the cert so other containers can call on the rpc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right but its a self-signed cert so the hostname is usually not validated? Or are there things that validate the hostname even for a self-signed cert?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure the hostname is validated because I normally am not able to get anything to work unless I add it to the cert

let mut rng = rand::thread_rng();
let mut key_bytes = [0u8; 32];
rng.fill(&mut key_bytes);
getrandom::getrandom(&mut key_bytes)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rand as a dep isn't actually removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah its still a transitive dep but if our underlying crates stop using it, we will be fine now

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its in Cargo.toml still?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it never was in there

benthecarman and others added 2 commits January 20, 2026 13:54
Implement self-signed certificate generation using ring directly,
removing the rcgen dependency along with its transitive dependencies
(yasna, time). ring was already in our dependency tree via tokio-rustls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@benthecarman
Copy link
Collaborator Author

I'm not actually clear on why we want support for building a self-signed cert? In such cases shouldn't we just not use TLS?

there are definitely cases where you want encryption but dont want to go through the hassle of the CA and can just share the certificate directly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants