Skip to content

Commit f9eb762

Browse files
committed
decrypt message text with rsa in handleMessage
1 parent d6194ee commit f9eb762

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/utils/SocketController.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
} from "../context/actions/roomsActions";
1212
import { updateTypingUsers } from "../context/actions/typingUsersAction";
1313
import { IndicatorProps } from "../context/reducers/appReducer";
14-
import { aesDecrypt } from "./encryption";
14+
import { aesDecrypt, rsaDecrypt } from "./encryption";
1515
import { handleLogger } from "../service";
1616
import * as events from "./events";
1717

@@ -28,6 +28,7 @@ const SocketController = () => {
2828
subscriptionKey,
2929
secretKey,
3030
projectName,
31+
e2e,
3132
},
3233
},
3334
},
@@ -224,9 +225,24 @@ const SocketController = () => {
224225

225226
let { message } = decryptedMessage;
226227
const { roomId } = decryptedMessage;
228+
const room = rooms.find(({ roomId: Id }) => Id === roomId);
229+
230+
// If the e2e feature of the client is enabled, the active user has a private key, the room is a one-to-one room (not a group), and the message is not generated by the system
231+
if (
232+
e2e &&
233+
selfUser?.privateKey &&
234+
!room?.groupAvatar &&
235+
!message.system
236+
) {
237+
// decrypt message text using RSA
238+
const decryptedMsg = rsaDecrypt({
239+
encryptedMsg: message.text,
240+
privateKey: selfUser.privateKey,
241+
});
242+
message = { ...message, text: decryptedMsg };
243+
}
227244

228245
message = { ...message, user: { _id: message.senderId } };
229-
const room = rooms.find(({ roomId: Id }) => Id === roomId);
230246

231247
// if message belongs community room, add avatar and name to user object
232248
if (room && room.groupAvatar) {

0 commit comments

Comments
 (0)