Skip to content

Commit 51bb2c1

Browse files
authored
Merge pull request #140 from azerum/fix-new-curves-supported
fix #139
2 parents 452c6cf + 4d2b296 commit 51bb2c1

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/rules/passthrough-handling.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { CompletedBody, Headers } from '../types';
77
import { byteLength } from '../util/util';
88
import { asBuffer } from '../util/buffer-utils';
99
import { isMockttpBody, encodeBodyBuffer } from '../util/request-utils';
10+
import { areFFDHECurvesSupported } from '../util/openssl-compat';
1011

1112
import {
1213
CallbackRequestResult,
@@ -15,7 +16,7 @@ import {
1516

1617
// TLS settings for proxied connections, intended to avoid TLS fingerprint blocking
1718
// issues so far as possible, by closely emulating a Firefox Client Hello:
18-
const NEW_CURVES_SUPPORTED = Number(process.versions.node.split('.')[0]) >= 17;
19+
const NEW_CURVES_SUPPORTED = areFFDHECurvesSupported(process.versions.openssl);
1920

2021
const SSL_OP_TLSEXT_PADDING = 1 << 4;
2122
const SSL_OP_NO_ENCRYPT_THEN_MAC = 1 << 19;

src/util/openssl-compat.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as semver from 'semver';
2+
3+
export function areFFDHECurvesSupported(opensslVersion: string | undefined) {
4+
// FFDHE curves (ffdhe2048, ffdhe3072) are only avaliable from
5+
// OpenSSL 3+
6+
7+
// Before 3.0.0, OpenSSL has followed non-semver version
8+
// format (see https://wiki.openssl.org/index.php/Versioning).
9+
// For example, there was a version `1.1.1t`. `semver` package, however
10+
// can parse such versions with `loose: true` option
11+
12+
// If not version is available, assume that the curves are not supported
13+
if (!opensslVersion) {
14+
return false;
15+
}
16+
17+
try {
18+
const m = semver.major(opensslVersion, true);
19+
return m >= 3;
20+
}
21+
catch {
22+
// For any weirdly formed version where even the major part cannot be found,
23+
// we assume that the curves are not supported for safety
24+
return false;
25+
}
26+
}

test/openssl-compat.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { expect } from 'chai';
2+
import { areFFDHECurvesSupported } from '../src/util/openssl-compat';
3+
4+
describe('areFFDHECurvesSupported', () => {
5+
it('True only for 3+ versions', () => {
6+
expect(areFFDHECurvesSupported('1.0.0')).to.be.false;
7+
expect(areFFDHECurvesSupported('3.0.0')).to.be.true;
8+
expect(areFFDHECurvesSupported('4.2.1')).to.be.true;
9+
});
10+
11+
it('Copes with older OpenSSL versions format', () => {
12+
expect(areFFDHECurvesSupported('1.0.1a')).to.be.false;
13+
expect(areFFDHECurvesSupported('1.1.1t')).to.be.false;
14+
});
15+
16+
it('Assumes false for weird versions', () => {
17+
// Just in case
18+
expect(areFFDHECurvesSupported('-1.0.0')).to.be.false;
19+
});
20+
21+
it('Assumes false when version is uknown', () => {
22+
expect(areFFDHECurvesSupported(undefined)).to.be.false;
23+
});
24+
});

0 commit comments

Comments
 (0)