Skip to content

Commit 4d2b296

Browse files
committed
Add some minor tweaks to the OpenSSL curves fix
1 parent 3a5a1b0 commit 4d2b296

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

src/util/openssl-compat.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import { major } from 'semver'
1+
import * as semver from 'semver';
22

33
export function areFFDHECurvesSupported(opensslVersion: string | undefined) {
4-
// FFDHE curves (ffdhe2048, ffdhe3072) are only avaliable from
4+
// FFDHE curves (ffdhe2048, ffdhe3072) are only avaliable from
55
// OpenSSL 3+
6-
6+
77
// Before 3.0.0, OpenSSL has followed non-semver version
88
// format (see https://wiki.openssl.org/index.php/Versioning).
99
// For example, there was a version `1.1.1t`. `semver` package, however
10-
// can parse such versions with `loose: true` option
10+
// can parse such versions with `loose: true` option
1111

1212
// If not version is available, assume that the curves are not supported
1313
if (!opensslVersion) {
14-
return false
14+
return false;
1515
}
1616

1717
try {
18-
const m = major(opensslVersion, true)
19-
return m >= 3
18+
const m = semver.major(opensslVersion, true);
19+
return m >= 3;
2020
}
2121
catch {
2222
// For any weirdly formed version where even the major part cannot be found,
2323
// we assume that the curves are not supported for safety
24-
return false
24+
return false;
2525
}
2626
}

test/openssl-compat-utils.spec.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

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)