Skip to content

Commit ab33a67

Browse files
committed
wip: loading Ca from mem
* Related #9 [ci skip]
1 parent 667db28 commit ab33a67

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

src/QUICConnection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ class QUICConnection extends EventTarget {
265265
} = {}
266266
) {
267267
this.logger.info(`Destroy ${this.constructor.name}`);
268+
console.log(this.conn.localError())
269+
console.log(this.conn.peerError())
268270
for (const stream of this.streamMap.values()) {
269271
await stream.destroy();
270272
}

src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export type TlsConfig = {
1515

1616
type QUICConfig = {
1717
tlsConfig: TlsConfig | undefined;
18+
verifyPem: string | undefined;
1819
verifyFromPemFile: string | undefined;
1920
supportedPrivateKeyAlgos: string | undefined;
2021
verifyPeer: boolean;
@@ -35,6 +36,7 @@ type QUICConfig = {
3536

3637
const clientDefault: QUICConfig = {
3738
tlsConfig: undefined,
39+
verifyPem: undefined,
3840
verifyFromPemFile: undefined,
3941
supportedPrivateKeyAlgos: supportedPrivateKeyAlgosDefault,
4042
logKeys: undefined,
@@ -61,6 +63,7 @@ const clientDefault: QUICConfig = {
6163

6264
const serverDefault: QUICConfig = {
6365
tlsConfig: undefined,
66+
verifyPem: undefined,
6467
verifyFromPemFile: undefined,
6568
supportedPrivateKeyAlgos: supportedPrivateKeyAlgosDefault,
6669
logKeys: undefined,
@@ -96,6 +99,7 @@ function buildQuicheConfig(config: QUICConfig): QuicheConfig {
9699
certChainPem,
97100
privKeyPem,
98101
config.supportedPrivateKeyAlgos ?? null,
102+
config.verifyPem != null ? Buffer.from(config.verifyPem) : null,
99103
);
100104
if (config.tlsConfig != null && 'certChainFromPemFile' in config.tlsConfig) {
101105
if (config.tlsConfig?.certChainFromPemFile != null) {

src/native/napi/config.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ impl Config {
5151
cert_pem: Option<Uint8Array>,
5252
key_pem: Option<Uint8Array>,
5353
supported_key_algos: Option<String>,
54+
ca_cert_pem: Option<Uint8Array>,
5455
) -> Result<Self> {
5556
let mut ssl_ctx_builder = boring::ssl::SslContextBuilder::new(
5657
boring::ssl::SslMethod::tls(),
@@ -98,6 +99,29 @@ impl Config {
9899
|err| Err(Error::from_reason(err.to_string()))
99100
)?;
100101
}
102+
// Processing CA certificate
103+
if let Some(ca_cert_pem) = ca_cert_pem {
104+
let x509_certs = boring::x509::X509::stack_from_pem(
105+
&cert_pem.to_vec()
106+
).or_else(
107+
|err| Err(Error::from_reason(err.to_string()))
108+
)?;
109+
let mut x509_store_builder = boring::x509::store::X509StoreBuilder::new()
110+
.or_else(
111+
|err| Err(Error::from_reason(err.to_string()))
112+
)?;
113+
for x509 in x509_certs.into_iter() {
114+
x509_store_builder.add_cert(x509)
115+
.or_else(
116+
|err| Err(Error::from_reason(err.to_string()))
117+
)?;
118+
}
119+
let x509_store = x509_store_builder.build();
120+
ssl_ctx_builder.set_verify_cert_store(x509_store)
121+
.or_else(
122+
|err| Err(Error::from_reason(err.to_string()))
123+
)?;
124+
}
101125
let ssl_ctx= ssl_ctx_builder.build();
102126
let config = quiche::Config::with_boring_ssl_ctx(
103127
quiche::PROTOCOL_VERSION,

src/native/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ interface ConfigConstructor {
4343
certPem: Uint8Array | null,
4444
keyPem: Uint8Array | null,
4545
supportedKeyAlgos: String | null,
46+
ca_cert_pem: Uint8Array | null,
4647
): Config;
4748
};
4849

tests/QUICClient.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,12 @@ describe(QUICClient.name, () => {
293293
} = fc.sample(tlsArb, 1)[0]
294294

295295
test('server verification succeeds', async () => {
296+
const tlsConfig = await (fc.sample(tlsUtils.tlsConfigArb(tlsUtils.keyPairsArb(2)), {numRuns: 1})[0]);
296297
const server = new QUICServer({
297298
crypto,
298299
logger: logger.getChild(QUICServer.name),
299300
config: {
300-
tlsConfig: tlsConfig1,
301+
tlsConfig: certFixtures.tlsConfigMemOKP1,
301302
verifyPeer: false,
302303
}
303304
});
@@ -315,7 +316,7 @@ describe(QUICClient.name, () => {
315316
logger: logger.getChild(QUICClient.name),
316317
config: {
317318
verifyPeer: true,
318-
verifyFromPemFile: ca.certChainFromPemFile,
319+
verifyPem: tlsConfig.caPem,
319320
}
320321
});
321322
await handleConnectionEventProm.p

0 commit comments

Comments
 (0)