Skip to content

Commit b31855f

Browse files
committed
fix: ed25519 certs now work, this includes the fast check generated ones
I've also updated the tests to use a random selection of the example cert fixtures and the generated polykey cert. * Fixes #8 [ci skip]
1 parent 09c7264 commit b31855f

File tree

6 files changed

+67
-76
lines changed

6 files changed

+67
-76
lines changed

index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export function retry(scid: Uint8Array, dcid: Uint8Array, newScid: Uint8Array, t
132132
export function versionIsSupported(version: number): boolean
133133
export class Config {
134134
constructor()
135-
static withBoringSslCtx(certPem?: Uint8Array | undefined | null, keyPem?: Uint8Array | undefined | null): Config
135+
static withBoringSslCtx(certPem?: Uint8Array | undefined | null, keyPem?: Uint8Array | undefined | null, supportedKeyAlgos?: string | undefined | null): Config
136136
loadCertChainFromPemFile(file: string): void
137137
loadPrivKeyFromPemFile(file: string): void
138138
loadVerifyLocationsFromFile(file: string): void

src/config.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import type { Config as QuicheConfig } from './native/types';
22
import { quiche } from './native';
33

4+
// All the algos chrome supports + ed25519
5+
const supportedPrivateKeyAlgosDefault =
6+
"ed25519:RSA+SHA256:RSA+SHA384:RSA+SHA512:ECDSA+SHA256:ECDSA+SHA384:ECDSA+SHA512:RSA-PSS+SHA256:RSA-PSS+SHA384:RSA-PSS+SHA512";
7+
48
export type TlsConfig = {
59
certChainPem: string | null;
610
privKeyPem: string | null;
@@ -11,6 +15,7 @@ export type TlsConfig = {
1115

1216
type QUICConfig = {
1317
tlsConfig: TlsConfig | undefined;
18+
supportedPrivateKeyAlgos: string | undefined;
1419
verifyPeer: boolean;
1520
logKeys: string | undefined;
1621
grease: boolean;
@@ -29,6 +34,7 @@ type QUICConfig = {
2934

3035
const clientDefault: QUICConfig = {
3136
tlsConfig: undefined,
37+
supportedPrivateKeyAlgos: supportedPrivateKeyAlgosDefault,
3238
logKeys: undefined,
3339
verifyPeer: false,
3440
grease: true,
@@ -53,6 +59,7 @@ const clientDefault: QUICConfig = {
5359

5460
const serverDefault: QUICConfig = {
5561
tlsConfig: undefined,
62+
supportedPrivateKeyAlgos: supportedPrivateKeyAlgosDefault,
5663
logKeys: undefined,
5764
verifyPeer: false,
5865
grease: true,
@@ -76,14 +83,18 @@ const serverDefault: QUICConfig = {
7683
};
7784

7885
function buildQuicheConfig(config: QUICConfig): QuicheConfig {
79-
let quicheConfig: QuicheConfig;
86+
let certChainPem: Buffer | null = null;
87+
let privKeyPem: Buffer | null = null;
8088
if (config.tlsConfig != null && 'certChainPem' in config.tlsConfig) {
81-
quicheConfig = quiche.Config.withBoringSslCtx(
82-
config.tlsConfig.certChainPem != null ? Buffer.from(config.tlsConfig.certChainPem) : null,
83-
config.tlsConfig.privKeyPem != null ? Buffer.from(config.tlsConfig.privKeyPem) : null,
84-
)
85-
} else {
86-
quicheConfig = new quiche.Config();
89+
if (config.tlsConfig.certChainPem != null) certChainPem = Buffer.from(config.tlsConfig.certChainPem)
90+
if (config.tlsConfig.privKeyPem != null) privKeyPem = Buffer.from(config.tlsConfig.privKeyPem)
91+
}
92+
let quicheConfig: QuicheConfig = quiche.Config.withBoringSslCtx(
93+
certChainPem,
94+
privKeyPem,
95+
config.supportedPrivateKeyAlgos ?? null,
96+
);
97+
if (config.tlsConfig != null && 'certChainFromPemFile' in config.tlsConfig) {
8798
if (config.tlsConfig?.certChainFromPemFile != null) {
8899
quicheConfig.loadCertChainFromPemFile(config.tlsConfig.certChainFromPemFile);
89100
}

src/native/napi/config.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ impl Config {
5050
pub fn with_boring_ssl_ctx(
5151
cert_pem: Option<Uint8Array>,
5252
key_pem: Option<Uint8Array>,
53+
supported_key_algos: Option<String>,
5354
) -> Result<Self> {
5455
let mut ssl_ctx_builder = boring::ssl::SslContextBuilder::new(
5556
boring::ssl::SslMethod::tls(),
5657
).or_else(
5758
|err| Err(Error::from_reason(err.to_string()))
5859
)?;
59-
// ssl_ctx_builder.set_verify(
60-
// boring::ssl::SslVerifyMode::NONE
61-
// );
6260
// Processing and adding the cert chain
6361
if let Some(cert_pem) = cert_pem {
6462
let x509_cert_chain = boring::x509::X509::stack_from_pem(
@@ -93,6 +91,13 @@ impl Config {
9391
|err| Err(Error::from_reason(err.to_string()))
9492
)?;
9593
}
94+
// Adding supported private key algorithms
95+
if let Some(supported_key_algos) = supported_key_algos {
96+
ssl_ctx_builder.set_sigalgs_list(&supported_key_algos)
97+
.or_else(
98+
|err| Err(Error::from_reason(err.to_string()))
99+
)?;
100+
}
96101
let ssl_ctx= ssl_ctx_builder.build();
97102
let config = quiche::Config::with_boring_ssl_ctx(
98103
quiche::PROTOCOL_VERSION,

src/native/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ interface Config {
4040
interface ConfigConstructor {
4141
new(): Config;
4242
withBoringSslCtx(
43-
cert_pem: Uint8Array | null,
44-
key_pem: Uint8Array | null,
43+
certPem: Uint8Array | null,
44+
keyPem: Uint8Array | null,
45+
supportedKeyAlgos: String | null,
4546
): Config;
4647
};
4748

tests/QUICClient.test.ts

Lines changed: 5 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,19 @@
1-
import type { Crypto, Host, Hostname, Port } from '@/types';
2-
import { webcrypto } from 'crypto';
1+
import type { Crypto, Host, Port } from '@/types';
32
import Logger, { LogLevel, StreamHandler, formatting } from '@matrixai/logger';
43
import QUICClient from '@/QUICClient';
54
import QUICServer from '@/QUICServer';
6-
import QUICConnection from '@/QUICConnection';
75
import * as events from '@/events';
86
import * as utils from '@/utils';
97
import * as testsUtils from './utils';
10-
import * as tls from 'tls';
118
import * as errors from '@/errors';
129
import { fc } from '@fast-check/jest';
1310
import * as tlsUtils from './tlsUtils';
1411
import * as certFixtures from './fixtures/certFixtures';
1512

16-
17-
const privKeyPem = `
18-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2lZY4DxUAr6JEmC2aOObv7gcr1W
55-
nhdO9PnY9aXhF2aVXsThkp8izP2ET9C7OmpMdajnVVbTW4PFU5YLnKFZFY5CmnaR
56-
08QWFByxGVKDkt5c3sPvBnI0Dfc1LvfCKFJZ4CtJs7+i+O2Y2ticLwur678wvXO9
57-
OGN6CIIC2A9c4H8I8qpE+N/frYfTg/E7/j0dbQIDAQABo3MwcTAOBgNVHQ8BAf8E
58-
BAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsGAQUFBwMCMB0GA1UdDgQWBBR0
59-
zbkYQmSgopJsbuNKOQV9qjYu7TAhBgNVHREEGjAYhwR/AAABhxAAAAAAAAAAAAAA
60-
AAAAAAABMA0GCSqGSIb3DQEBCwUAA4IBAQAWLolrv0NuKqhZndYLPCT3C013Qo6y
61-
QeQPbyZbJgHhRZd2feP8sEQ1U4f48OKL5ejWEKOaUvH/sVI9Jume4ve2xOxqz+ST
62-
csZqUqinnUT/12jwGOys2IIEPBnlMxBFon54G336+LGgl9CX+rXKeJZgIbmZpcCa
63-
J948KRJwJ4E4UgnNIY/e4J5nCpScA0b5GlmcvpoV5yBoIf6vvnrWeyyl4rotPx9Q
64-
jm/r7v5BQrwMjbcrLCA9Nob5tSMEHDjlvt4cNzOnMWdsjB735QaMsA8qZX8m2NpX
65-
jti9iwz2QT6q1s+PjS/gbflIO3j4FP4XOEQGtWm9iqPbVhoUIB9PBED3
66-
-----END CERTIFICATE-----
67-
`
68-
69-
const tlsArb = fc.constant(certFixtures.tlsConfigFileRSA1);
70-
// const tlsArb = tlsUtils.tlsConfigArb(tlsUtils.keyPairsArb(1));
71-
// const tlsArb = fc.constant({
72-
// certChainPem,
73-
// privKeyPem,
74-
// });
13+
const tlsArb = fc.oneof(
14+
certFixtures.tlsConfigExampleArb,
15+
tlsUtils.tlsConfigArb(),
16+
);
7517
describe(QUICClient.name, () => {
7618
const logger = new Logger(`${QUICClient.name} Test`, LogLevel.DEBUG, [
7719
new StreamHandler(formatting.format`${formatting.level}:${formatting.keys}:${formatting.msg}`),

tests/fixtures/certFixtures.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import { fc } from '@fast-check/jest';
34

45
function fixturePath(name: string) {
56
return {
@@ -71,6 +72,33 @@ const tlsConfigMemECDSA2 = {
7172
privKeyPem: fs.readFileSync(tlsConfigFileECDSA2.privKeyFromPemFile).toString(),
7273
};
7374

75+
const tlsConfigRSAExampleArb = fc.oneof(
76+
fc.constant(tlsConfigFileRSA1),
77+
fc.constant(tlsConfigFileRSA2),
78+
fc.constant(tlsConfigMemRSA1),
79+
fc.constant(tlsConfigMemRSA2),
80+
)
81+
82+
const tlsConfigECDSAExampleArb = fc.oneof(
83+
fc.constant(tlsConfigFileECDSA1),
84+
fc.constant(tlsConfigFileECDSA2),
85+
fc.constant(tlsConfigMemECDSA1),
86+
fc.constant(tlsConfigMemECDSA2),
87+
)
88+
89+
const tlsConfigOKPExampleArb = fc.oneof(
90+
fc.constant(tlsConfigFileOKP1),
91+
fc.constant(tlsConfigFileOKP2),
92+
fc.constant(tlsConfigMemOKP1),
93+
fc.constant(tlsConfigMemOKP2),
94+
)
95+
96+
const tlsConfigExampleArb = fc.oneof(
97+
tlsConfigRSAExampleArb,
98+
tlsConfigECDSAExampleArb,
99+
tlsConfigOKPExampleArb,
100+
)
101+
74102

75103
export {
76104
tlsConfigFileRSA1,
@@ -85,4 +113,8 @@ export {
85113
tlsConfigMemOKP2,
86114
tlsConfigMemECDSA1,
87115
tlsConfigMemECDSA2,
116+
tlsConfigRSAExampleArb,
117+
tlsConfigECDSAExampleArb,
118+
tlsConfigOKPExampleArb,
119+
tlsConfigExampleArb,
88120
}

0 commit comments

Comments
 (0)