Skip to content

Commit 68084b7

Browse files
committed
Added environment: 'browser' to NodeRSA instances as workaround for CVE.
This change may make the encryption/decryption slower but it's necessary until Node supports SSL 3.2+
1 parent d227385 commit 68084b7

File tree

12 files changed

+24
-20
lines changed

12 files changed

+24
-20
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@brewskey/spark-server",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"license": "AGPL-3.0",
55
"repository": {
66
"type": "git",
@@ -144,4 +144,4 @@
144144
"@nx/nx-linux-x64-musl": "16.8.1",
145145
"@nx/nx-win32-x64-msvc": "16.8.1"
146146
}
147-
}
147+
}

packages/particle-collider/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"start": "ts-node ./src/index.ts",
88
"build": "tsc --noEmit"
99
},
10+
"private": "true",
1011
"repository": {
1112
"type": "git",
1213
"url": "git+https://github.com/Brewskey/particle-collider.git"
@@ -29,4 +30,4 @@
2930
"ts-node": "^10.9.2",
3031
"typescript": "^5.3.3"
3132
}
32-
}
33+
}

packages/particle-collider/src/lib/CryptoManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,24 @@ class CryptoManager {
2222
CryptoManager._serverKey = new NodeRSA(keyString, 'pkcs8-public-pem', {
2323
encryptionScheme: 'pkcs1',
2424
signingScheme: 'pkcs1',
25+
environment: 'browser',
2526
});
2627
}
2728

2829
static loadPrivateKey(keyString: string): NodeRSA {
2930
return new NodeRSA(keyString, undefined, {
3031
encryptionScheme: 'pkcs1',
3132
signingScheme: 'pkcs1',
33+
environment: 'browser',
3234
});
3335
}
3436

3537
static createKey(): NodeRSA {
36-
return new NodeRSA({
38+
const rsa = new NodeRSA({
3739
b: 1024,
3840
});
41+
rsa.setOptions({ environment: 'browser' }); //By default it will use the node crypto library with the CVE
42+
return rsa;
3943
}
4044

4145
static randomBytes(count: number): Buffer {

packages/spark-protocol/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@brewskey/spark-protocol",
3-
"version": "1.0.11",
3+
"version": "1.0.12",
44
"main": "./dist/index.js",
55
"repository": {
66
"type": "git",
@@ -89,4 +89,4 @@
8989
"ts-node": "^10.9.2",
9090
"typescript": "^5.3.3"
9191
}
92-
}
92+
}

packages/spark-protocol/src/lib/CryptoManager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class CryptoManager {
5555

5656
async _createServerKeys(): Promise<NodeRSA> {
5757
const privateKey = new NodeRSA({ b: 2048 });
58+
privateKey.setOptions({ environment: 'browser' }); //By default it will use the node crypto library with the CVE
5859

5960
await this._serverKeyRepository.createKeys(
6061
Buffer.from(privateKey.exportKey('pkcs1-private-pem')),
@@ -74,6 +75,7 @@ class CryptoManager {
7475
return new NodeRSA(privateKeyString, undefined, {
7576
encryptionScheme: 'pkcs1',
7677
signingScheme: 'pkcs1',
78+
environment: 'browser',
7779
});
7880
}
7981

@@ -114,6 +116,7 @@ class CryptoManager {
114116
try {
115117
return this._serverPrivateKey.decrypt(data);
116118
} catch (error) {
119+
console.error(error);
117120
return null;
118121
}
119122
}

packages/spark-protocol/src/lib/DeviceKey.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class DeviceKey {
1111
this._nodeRsa = new NodeRSA(pemString, 'pkcs8-public-pem', {
1212
encryptionScheme: 'pkcs1',
1313
signingScheme: 'pkcs1',
14+
environment: 'browser',
1415
});
1516
} catch (_) {
1617
this._ecKey = new ECKey(pemString, 'pem');

packages/spark-protocol/src/lib/Handshake.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ class Handshake {
212212
deviceProvidedPem: string | null | undefined;
213213
}> {
214214
const decryptedHandshakeData = this._cryptoManager.decrypt(data);
215-
216215
if (!decryptedHandshakeData) {
217216
throw new Error(
218217
'handshake data decryption failed. ' +
@@ -252,6 +251,7 @@ class Handshake {
252251

253252
const deviceProvidedPem = this._convertDERtoPEM(deviceKeyBuffer);
254253
const deviceID = deviceIDBuffer.toString('hex');
254+
console.log('decrypted', { deviceID, deviceProvidedPem });
255255

256256
return { deviceID, deviceProvidedPem };
257257
}

src/__tests__/WebhookManager.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import { CoreOptions, UrlOptions } from 'request';
1414
const WEBHOOK_BASE: Webhook = {
1515
event: 'test-event',
1616
requestType: 'POST',
17-
url: 'https://webhook.site/7d7dff97-b980-4d36-a4ed-ac7e94cc0c0f',
17+
// TODO - use supertest or something for a mock server. This API will break whenever they decide to clean up old webhooks
18+
url: 'https://webhook.site/fb2d5641-92c6-4b1d-9df9-4fbccfd22aa6',
1819
created_at: new Date(),
1920
id: 'test-id',
2021
ownerID: 'test-owner-id',

src/__tests__/setup/TestData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class TestData {
6565

6666
static getPublicKey: () => string = (): string => {
6767
const key = new NodeRSA({ b: 1024 });
68+
key.setOptions({ environment: 'browser' }); //By default it will use the node crypto library with the CVE
6869

6970
return key.exportKey('pkcs8-public-pem');
7071
};

0 commit comments

Comments
 (0)