fca-nx 6.6.9 → 6.7.0
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/module/login.js +17 -8
- package/module/loginHelper.js +31 -2
- package/package.json +3 -2
- package/src/api/messaging/uploadAttachment.js +2 -2
- package/src/api/socket/e2ee/index.js +1 -1
- package/src/api/socket/listenE2EE.js +14 -4
- package/src/api/socket/listenMqtt.js +13 -3
- package/src/utils/format/utils.js +18 -12
- package/src/utils/utils.js +15 -6
- package/e2ee/config.json +0 -0
- package/e2ee/crypto.js +0 -173
- package/e2ee/index.js +0 -1032
- package/e2ee/proto/ArmadilloApplication.proto +0 -281
- package/e2ee/proto/ArmadilloICDC.proto +0 -14
- package/e2ee/proto/ConsumerApplication.proto +0 -232
- package/e2ee/proto/MessageApplication.proto +0 -82
- package/e2ee/proto/MessageTransport.proto +0 -77
- package/e2ee/proto/WACommon.proto +0 -66
- package/e2ee/proto/WAMediaTransport.proto +0 -176
- package/e2ee/protocol.js +0 -196
- package/e2ee/ratchet.js +0 -219
- package/e2ee/store.js +0 -182
- package/e2ee/vendor/fb-e2ee.cjs +0 -9159
- package/e2ee/vendor/proto/ArmadilloApplication.proto +0 -281
- package/e2ee/vendor/proto/ArmadilloICDC.proto +0 -14
- package/e2ee/vendor/proto/ConsumerApplication.proto +0 -232
- package/e2ee/vendor/proto/MessageApplication.proto +0 -82
- package/e2ee/vendor/proto/MessageTransport.proto +0 -77
- package/e2ee/vendor/proto/WACommon.proto +0 -66
- package/e2ee/vendor/proto/WAMediaTransport.proto +0 -176
- package/src/api/socket/e2ee/e2ee/crypto.js +0 -173
- package/src/api/socket/e2ee/e2ee/index.js +0 -421
- package/src/api/socket/e2ee/e2ee/proto/ArmadilloApplication.proto +0 -281
- package/src/api/socket/e2ee/e2ee/proto/ArmadilloICDC.proto +0 -14
- package/src/api/socket/e2ee/e2ee/proto/ConsumerApplication.proto +0 -232
- package/src/api/socket/e2ee/e2ee/proto/MessageApplication.proto +0 -82
- package/src/api/socket/e2ee/e2ee/proto/MessageTransport.proto +0 -77
- package/src/api/socket/e2ee/e2ee/proto/WACommon.proto +0 -66
- package/src/api/socket/e2ee/e2ee/proto/WAMediaTransport.proto +0 -176
- package/src/api/socket/e2ee/e2ee/protocol.js +0 -196
- package/src/api/socket/e2ee/e2ee/ratchet.js +0 -219
- package/src/api/socket/e2ee/e2ee/store.js +0 -182
- package/src/api/socket/e2ee/e2ee/vendor/fb-e2ee.cjs +0 -9162
- package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloApplication.proto +0 -281
- package/src/api/socket/e2ee/e2ee/vendor/proto/ArmadilloICDC.proto +0 -14
- package/src/api/socket/e2ee/e2ee/vendor/proto/ConsumerApplication.proto +0 -232
- package/src/api/socket/e2ee/e2ee/vendor/proto/MessageApplication.proto +0 -82
- package/src/api/socket/e2ee/e2ee/vendor/proto/MessageTransport.proto +0 -77
- package/src/api/socket/e2ee/e2ee/vendor/proto/WACommon.proto +0 -66
- package/src/api/socket/e2ee/e2ee/vendor/proto/WAMediaTransport.proto +0 -176
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* E2EE Device/Session Store
|
|
5
|
-
* Persists key material to a JSON file (encrypted with a device secret).
|
|
6
|
-
* Each E2EE session (thread) is stored separately.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const fs = require("fs");
|
|
10
|
-
const path = require("path");
|
|
11
|
-
const crypto = require("crypto");
|
|
12
|
-
|
|
13
|
-
class E2EEStore {
|
|
14
|
-
constructor(storePath, userID) {
|
|
15
|
-
this.storePath = storePath;
|
|
16
|
-
this.userID = userID;
|
|
17
|
-
this.data = {
|
|
18
|
-
identityKey: null,
|
|
19
|
-
signedPreKey: null,
|
|
20
|
-
oneTimePreKeys: [],
|
|
21
|
-
sessions: {}, // threadID -> serialized DoubleRatchetSession
|
|
22
|
-
deviceSecret: null // 32-byte random secret for local encryption
|
|
23
|
-
};
|
|
24
|
-
this._loaded = false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
_storeFile() {
|
|
28
|
-
return path.join(this.storePath, `shadowx_e2ee_${this.userID}.json`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
_salt() {
|
|
32
|
-
return Buffer.from(this.userID.padEnd(16, "0").slice(0, 16), "utf8");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_localEncrypt(data) {
|
|
36
|
-
if (!this.data.deviceSecret) return data;
|
|
37
|
-
const key = Buffer.from(this.data.deviceSecret, "base64");
|
|
38
|
-
if (key.length !== 32) return data;
|
|
39
|
-
const iv = crypto.randomBytes(12);
|
|
40
|
-
const cipher = crypto.createCipheriv("aes-256-gcm", key, iv);
|
|
41
|
-
const enc = Buffer.concat([cipher.update(Buffer.from(data, "utf8")), cipher.final()]);
|
|
42
|
-
const tag = cipher.getAuthTag();
|
|
43
|
-
return Buffer.concat([iv, tag, enc]).toString("base64");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
_localDecrypt(data) {
|
|
47
|
-
if (!this.data.deviceSecret) return data;
|
|
48
|
-
try {
|
|
49
|
-
const key = Buffer.from(this.data.deviceSecret, "base64");
|
|
50
|
-
if (key.length !== 32) return data;
|
|
51
|
-
const buf = Buffer.from(data, "base64");
|
|
52
|
-
const iv = buf.slice(0, 12);
|
|
53
|
-
const tag = buf.slice(12, 28);
|
|
54
|
-
const enc = buf.slice(28);
|
|
55
|
-
const decipher = crypto.createDecipheriv("aes-256-gcm", key, iv);
|
|
56
|
-
decipher.setAuthTag(tag);
|
|
57
|
-
return Buffer.concat([decipher.update(enc), decipher.final()]).toString("utf8");
|
|
58
|
-
} catch (_) {
|
|
59
|
-
return data;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
load() {
|
|
64
|
-
const file = this._storeFile();
|
|
65
|
-
if (!fs.existsSync(file)) return false;
|
|
66
|
-
try {
|
|
67
|
-
const raw = fs.readFileSync(file, "utf8");
|
|
68
|
-
const parsed = JSON.parse(raw);
|
|
69
|
-
if (parsed.deviceSecret) this.data.deviceSecret = parsed.deviceSecret;
|
|
70
|
-
const decrypted = this._localDecrypt(parsed.payload || "{}");
|
|
71
|
-
const payload = JSON.parse(decrypted);
|
|
72
|
-
this.data.identityKey = payload.identityKey || null;
|
|
73
|
-
this.data.signedPreKey = payload.signedPreKey || null;
|
|
74
|
-
this.data.oneTimePreKeys = payload.oneTimePreKeys || [];
|
|
75
|
-
this.data.sessions = payload.sessions || {};
|
|
76
|
-
this._loaded = true;
|
|
77
|
-
return true;
|
|
78
|
-
} catch (_) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
save() {
|
|
84
|
-
if (!fs.existsSync(this.storePath)) {
|
|
85
|
-
fs.mkdirSync(this.storePath, { recursive: true });
|
|
86
|
-
}
|
|
87
|
-
if (!this.data.deviceSecret) {
|
|
88
|
-
this.data.deviceSecret = crypto.randomBytes(32).toString("base64");
|
|
89
|
-
}
|
|
90
|
-
const payload = JSON.stringify({
|
|
91
|
-
identityKey: this.data.identityKey,
|
|
92
|
-
signedPreKey: this.data.signedPreKey,
|
|
93
|
-
oneTimePreKeys: this.data.oneTimePreKeys,
|
|
94
|
-
sessions: this.data.sessions
|
|
95
|
-
});
|
|
96
|
-
const encrypted = this._localEncrypt(payload);
|
|
97
|
-
fs.writeFileSync(this._storeFile(), JSON.stringify({ deviceSecret: this.data.deviceSecret, payload: encrypted }, null, 2), "utf8");
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
hasIdentityKey() { return !!this.data.identityKey; }
|
|
101
|
-
|
|
102
|
-
getIdentityKey() {
|
|
103
|
-
const ik = this.data.identityKey;
|
|
104
|
-
if (!ik) return null;
|
|
105
|
-
return {
|
|
106
|
-
privateKey: Buffer.from(ik.privateKey, "base64"),
|
|
107
|
-
publicKey: Buffer.from(ik.publicKey, "base64"),
|
|
108
|
-
publicKeyRaw: Buffer.from(ik.publicKeyRaw, "base64")
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
setIdentityKey(keyPair) {
|
|
113
|
-
this.data.identityKey = {
|
|
114
|
-
privateKey: keyPair.privateKey.toString("base64"),
|
|
115
|
-
publicKey: keyPair.publicKey.toString("base64"),
|
|
116
|
-
publicKeyRaw: keyPair.publicKeyRaw.toString("base64")
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
getSignedPreKey() {
|
|
121
|
-
const spk = this.data.signedPreKey;
|
|
122
|
-
if (!spk) return null;
|
|
123
|
-
return {
|
|
124
|
-
privateKey: Buffer.from(spk.privateKey, "base64"),
|
|
125
|
-
publicKey: Buffer.from(spk.publicKey, "base64"),
|
|
126
|
-
publicKeyRaw: Buffer.from(spk.publicKeyRaw, "base64"),
|
|
127
|
-
signature: Buffer.from(spk.signature, "base64"),
|
|
128
|
-
keyId: spk.keyId
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
setSignedPreKey(keyPair) {
|
|
133
|
-
this.data.signedPreKey = {
|
|
134
|
-
privateKey: keyPair.privateKey.toString("base64"),
|
|
135
|
-
publicKey: keyPair.publicKey.toString("base64"),
|
|
136
|
-
publicKeyRaw: keyPair.publicKeyRaw.toString("base64"),
|
|
137
|
-
signature: keyPair.signature ? keyPair.signature.toString("base64") : "",
|
|
138
|
-
keyId: keyPair.keyId || 1
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getOneTimePreKeys() {
|
|
143
|
-
return (this.data.oneTimePreKeys || []).map(k => ({
|
|
144
|
-
privateKey: Buffer.from(k.privateKey, "base64"),
|
|
145
|
-
publicKey: Buffer.from(k.publicKey, "base64"),
|
|
146
|
-
publicKeyRaw: Buffer.from(k.publicKeyRaw, "base64"),
|
|
147
|
-
keyId: k.keyId
|
|
148
|
-
}));
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
addOneTimePreKey(keyPair) {
|
|
152
|
-
this.data.oneTimePreKeys = this.data.oneTimePreKeys || [];
|
|
153
|
-
this.data.oneTimePreKeys.push({
|
|
154
|
-
privateKey: keyPair.privateKey.toString("base64"),
|
|
155
|
-
publicKey: keyPair.publicKey.toString("base64"),
|
|
156
|
-
publicKeyRaw: keyPair.publicKeyRaw.toString("base64"),
|
|
157
|
-
keyId: keyPair.keyId
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
consumeOneTimePreKey(keyId) {
|
|
162
|
-
const idx = (this.data.oneTimePreKeys || []).findIndex(k => k.keyId === keyId);
|
|
163
|
-
if (idx < 0) return null;
|
|
164
|
-
const k = this.data.oneTimePreKeys.splice(idx, 1)[0];
|
|
165
|
-
return {
|
|
166
|
-
privateKey: Buffer.from(k.privateKey, "base64"),
|
|
167
|
-
publicKey: Buffer.from(k.publicKey, "base64"),
|
|
168
|
-
publicKeyRaw: Buffer.from(k.publicKeyRaw, "base64"),
|
|
169
|
-
keyId: k.keyId
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
hasSession(threadID) { return !!this.data.sessions[threadID]; }
|
|
174
|
-
|
|
175
|
-
getSession(threadID) { return this.data.sessions[threadID] || null; }
|
|
176
|
-
|
|
177
|
-
setSession(threadID, serializedSession) { this.data.sessions[threadID] = serializedSession; }
|
|
178
|
-
|
|
179
|
-
deleteSession(threadID) { delete this.data.sessions[threadID]; }
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
module.exports = { E2EEStore };
|