@stonyx/sockets 0.1.1-beta.14 → 0.1.1-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.js +7 -1
- package/dist/server.js +6 -0
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -58,7 +58,7 @@ export default class SocketClient {
|
|
|
58
58
|
socket.on('close', (code, reason) => this.onClose(code, reason.toString()));
|
|
59
59
|
socket.on('error', () => {
|
|
60
60
|
log.socket(`Error connecting to socket server`);
|
|
61
|
-
reject('Error connecting to socket server');
|
|
61
|
+
reject(new Error('Error connecting to socket server'));
|
|
62
62
|
});
|
|
63
63
|
socket.on('open', () => {
|
|
64
64
|
this._intentionalClose = false;
|
|
@@ -72,6 +72,8 @@ export default class SocketClient {
|
|
|
72
72
|
let parsed;
|
|
73
73
|
if (this.encryptionEnabled) {
|
|
74
74
|
const key = this.sessionKey || this.globalKey;
|
|
75
|
+
if (!key)
|
|
76
|
+
throw new Error('Encryption enabled but no key available');
|
|
75
77
|
const raw = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
|
|
76
78
|
parsed = JSON.parse(decrypt(raw, key));
|
|
77
79
|
}
|
|
@@ -102,8 +104,12 @@ export default class SocketClient {
|
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
send(payload, useGlobalKey = false) {
|
|
107
|
+
if (!this.socket)
|
|
108
|
+
throw new Error('Socket is not connected');
|
|
105
109
|
if (this.encryptionEnabled) {
|
|
106
110
|
const key = useGlobalKey ? this.globalKey : this.sessionKey;
|
|
111
|
+
if (!key)
|
|
112
|
+
throw new Error('Encryption enabled but no key available');
|
|
107
113
|
const data = encrypt(JSON.stringify(payload), key);
|
|
108
114
|
this.socket.send(data);
|
|
109
115
|
}
|
package/dist/server.js
CHANGED
|
@@ -61,6 +61,8 @@ export default class SocketServer {
|
|
|
61
61
|
let parsed;
|
|
62
62
|
if (this.encryptionEnabled) {
|
|
63
63
|
const key = client.__authenticated ? client.__sessionKey : this.globalKey;
|
|
64
|
+
if (!key)
|
|
65
|
+
throw new Error('Encryption enabled but no key available');
|
|
64
66
|
const raw = Buffer.isBuffer(payload) ? payload : Buffer.from(payload);
|
|
65
67
|
parsed = JSON.parse(decrypt(raw, key));
|
|
66
68
|
}
|
|
@@ -92,6 +94,8 @@ export default class SocketServer {
|
|
|
92
94
|
if (this.encryptionEnabled) {
|
|
93
95
|
const sessionKey = generateSessionKey();
|
|
94
96
|
client.__sessionKey = sessionKey;
|
|
97
|
+
if (!this.globalKey)
|
|
98
|
+
throw new Error('Encryption enabled but globalKey not initialized');
|
|
95
99
|
client.send({ request, response, sessionKey: sessionKey.toString('base64') }, this.globalKey);
|
|
96
100
|
}
|
|
97
101
|
else {
|
|
@@ -114,6 +118,8 @@ export default class SocketServer {
|
|
|
114
118
|
client.send = (payload, keyOverride) => {
|
|
115
119
|
if (server.encryptionEnabled) {
|
|
116
120
|
const key = keyOverride || client.__sessionKey;
|
|
121
|
+
if (!key)
|
|
122
|
+
throw new Error('Encryption enabled but no key available');
|
|
117
123
|
const data = encrypt(JSON.stringify(payload), key);
|
|
118
124
|
socketSend(data);
|
|
119
125
|
}
|