Description
Specification
In QUIC our current system requires passing a file path into QUICConfig
.
{
certChainFromPemFile: string | undefined;
privKeyFromPemFile: string | undefined;
}
These 2 properties are required on the server side, while they are optional on the client side. PK will of course use these 2 on both client and server.
These 2 properties are later used by config.buildQuicheConfig
:
if (config.certChainFromPemFile != null) {
quicheConfig.loadCertChainFromPemFile(config.certChainFromPemFile);
}
if (config.privKeyFromPemFile != null) {
quicheConfig.loadPrivKeyFromPemFile(config.privKeyFromPemFile);
}
It's better to be able to pass PEM strings, then require the QUIC client and QUIC server to read certificates and keys from the local filesystem. It's more secure as we don't leave any secrets on the local filesystem.
In order to do this, we need to add a new factory method to the config.rs
.
#[napi(factory)]
pub fn with_boring_ssl_ctx(version: i64, certPEM: String, keyPEM: String) -> Result<Self> {
// ... figure out this ...
}
The body of this function will need to take the PEM strings bridged by napi-rs, and then use the boring
package to turn them into the x509
objects.
Subsequently use boring::ssl::SslContext::builder
to create a SSL context builder, which then takes those objects and builds the SSL context.
Finally it should be possible to use quiche::Config::with_boring_ssl_ctx
to finally build a config object with string cert and key.
Currently in PK, we have the types:
CertificatePEMChain
PrivateKeyPEM
Both are string types. These will be used when we want to load certs and key into the QUIC connection.
Tests should test the usage of this on both client and server, with the verifyPeer
option set to true.
Tests should ensure that certificate chains are also accepted. The cert chain PEM doesn't just mean 1 certificate, it could have a whole chain of certificates.
An additional problem is dealing with certificate and key rotation. I'll address this in a separate issue.
Additional context
- Create QUIC library that can be exposed to JS and uses the Node
dgram
module #1 (comment) - How to create a local TLS certificate and key usingstep
CLI program. - Clarify which configuration options are mandatory cloudflare/quiche#1250 - Proves that TLS configuration is necessary for the server to run.
Tasks
- Bring in the
boring
package intoCargo.toml
. - Update the
shell.nix
withrustPlatform.bindgenHook
so thatboring
can actually compile - Update the
config.rs
with thewith_boring_ssl_ctx
method. Use chat gpt and github copilot to help you find out what kind of code to write. - Compile it with
npm run napi-build
. - Expose the method in
src/native/types.ts
- Change the
buildQuicheConfig
to take the TLS cert pem and key pem strings. - Eliminate the file path options, we won't even bother implementing these.
- Change tests to stop using the
localhost.key
andlocalhost.crt
, but instead synthetically generate these 2 in-memory now. You can use peculiar's x509 library as adevDependency
and follow the PK'ssrc/keys/utils/x509.ts
to understand how to generate a relevant certificate chain for testing purposes. - You can sanity check by reading the
localhost.crt
andlocalhost.key
first as strings. But it's better we can use fastcheck to generate different kinds of certs for testing.