Skip to content

Commit 5046dd9

Browse files
authored
feat: E2EE new arch (#6624)
1 parent 62af14e commit 5046dd9

File tree

62 files changed

+609
-521
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+609
-521
lines changed

.rnstorybook/preview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import type { Preview } from '@storybook/react';
33
import { Provider } from 'react-redux';
44

5-
import { themes } from '../app/lib/constants';
5+
import { themes } from '../app/lib/constants/colors';
66
import MessageContext from '../app/containers/message/Context';
77
import { selectServerRequest } from '../app/actions/server';
88
import { mockedStore as store } from '../app/reducers/mockedStore';

android/app/src/main/java/chat/rocket/reactnative/notification/Encryption.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package chat.rocket.reactnative.notification;
22

3-
import android.database.Cursor;
3+
import android.database.Cursor;
44
import android.util.Base64;
55
import android.util.Log;
66

@@ -10,13 +10,11 @@
1010
import com.wix.reactnativenotifications.core.AppLifecycleFacade;
1111
import com.wix.reactnativenotifications.core.AppLifecycleFacadeHolder;
1212
import com.google.gson.Gson;
13-
import com.pedrouid.crypto.RCTAes;
14-
import com.pedrouid.crypto.RCTRsaUtils;
15-
import com.pedrouid.crypto.RSA;
16-
import com.pedrouid.crypto.Util;
13+
import chat.rocket.mobilecrypto.algorithms.AESCrypto;
14+
import chat.rocket.mobilecrypto.algorithms.RSACrypto;
15+
import chat.rocket.mobilecrypto.algorithms.CryptoUtils;
1716
import com.nozbe.watermelondb.WMDatabase;
1817

19-
import java.io.File;
2018
import java.lang.reflect.Field;
2119
import java.security.SecureRandom;
2220
import java.util.Arrays;
@@ -149,7 +147,7 @@ public String readUserKey(final Ejson ejson) throws Exception {
149147
jwk.putString("dq", privKey.dq);
150148
jwk.putString("qi", privKey.qi);
151149

152-
return new RCTRsaUtils(reactContext).jwkToPrivatePkcs1(jwk);
150+
return RSACrypto.INSTANCE.importJwkKey(jwk);
153151
}
154152

155153
public String decryptRoomKey(final String e2eKey, final Ejson ejson) throws Exception {
@@ -161,28 +159,29 @@ public String decryptRoomKey(final String e2eKey, final Ejson ejson) throws Exce
161159
return null;
162160
}
163161

164-
RSA rsa = new RSA();
165-
rsa.setPrivateKey(userKey);
166-
String decrypted = rsa.decrypt(key);
162+
String decrypted = RSACrypto.INSTANCE.decrypt(key, userKey);
167163

168164
RoomKey roomKey = gson.fromJson(decrypted, RoomKey.class);
169165
byte[] decoded = Base64.decode(roomKey.k, Base64.NO_PADDING | Base64.NO_WRAP | Base64.URL_SAFE);
170166

171-
return Util.bytesToHex(decoded);
167+
return CryptoUtils.INSTANCE.bytesToHex(decoded);
172168
}
173169

174170
private String decryptText(String text, String e2eKey) throws Exception {
175171
String msg = text.substring(12);
176172
byte[] msgData = Base64.decode(msg, Base64.NO_WRAP);
177173
String b64 = Base64.encodeToString(Arrays.copyOfRange(msgData, 16, msgData.length), Base64.DEFAULT);
178-
String decrypted = RCTAes.decrypt(b64, e2eKey, Util.bytesToHex(Arrays.copyOfRange(msgData, 0, 16)));
174+
String decrypted = AESCrypto.INSTANCE.decryptBase64(b64, e2eKey, CryptoUtils.INSTANCE.bytesToHex(Arrays.copyOfRange(msgData, 0, 16)));
179175
byte[] data = Base64.decode(decrypted, Base64.NO_WRAP);
180176
return new String(data, "UTF-8");
181177
}
182178

183179
public String decryptMessage(final Ejson ejson, final ReactApplicationContext reactContext) {
184180
try {
185-
this.reactContext = reactContext;
181+
AppLifecycleFacade facade = AppLifecycleFacadeHolder.get();
182+
if (facade != null && facade.getRunningReactContext() instanceof ReactApplicationContext) {
183+
this.reactContext = (ReactApplicationContext) facade.getRunningReactContext();
184+
}
186185

187186
Room room = readRoom(ejson);
188187
if (room == null || room.e2eKey == null) {
@@ -219,12 +218,6 @@ public String encryptMessage(final String message, final String id, final Ejson
219218
AppLifecycleFacade facade = AppLifecycleFacadeHolder.get();
220219
if (facade != null && facade.getRunningReactContext() instanceof ReactApplicationContext) {
221220
this.reactContext = (ReactApplicationContext) facade.getRunningReactContext();
222-
} else {
223-
this.reactContext = null;
224-
}
225-
if (this.reactContext == null) {
226-
Log.i("[ROCKETCHAT][E2E]", "ReactApplicationContext is null, returning unencrypted message");
227-
return message;
228221
}
229222

230223
Room room = readRoom(ejson);
@@ -244,7 +237,7 @@ public String encryptMessage(final String message, final String id, final Ejson
244237
byte[] bytes = new byte[16];
245238
random.nextBytes(bytes);
246239

247-
String encrypted = RCTAes.encrypt(Base64.encodeToString(cypher.getBytes("UTF-8"), Base64.NO_WRAP), e2eKey, Util.bytesToHex(bytes));
240+
String encrypted = AESCrypto.INSTANCE.encryptBase64(Base64.encodeToString(cypher.getBytes("UTF-8"), Base64.NO_WRAP), e2eKey, CryptoUtils.INSTANCE.bytesToHex(bytes));
248241
byte[] data = Base64.decode(encrypted, Base64.NO_WRAP);
249242

250243
return keyId + Base64.encodeToString(concat(bytes, data), Base64.NO_WRAP);

app/containers/ActivityIndicator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { ActivityIndicator, ActivityIndicatorProps, StyleSheet } from 'react-native';
33

44
import { useTheme } from '../theme';
5-
import { themes } from '../lib/constants';
5+
import { themes } from '../lib/constants/colors';
66

77
interface IActivityIndicator extends ActivityIndicatorProps {
88
absolute?: boolean;

app/containers/AudioPlayer/PlaybackSpeed.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import i18n from '../../i18n';
55
import styles from './styles';
66
import { useTheme } from '../../theme';
77
import { AUDIO_PLAYBACK_SPEED, AVAILABLE_SPEEDS } from './constants';
8-
import { useUserPreferences } from '../../lib/methods';
8+
import { useUserPreferences } from '../../lib/methods/userPreferences';
99
import NativeButton from '../NativeButton';
1010

1111
const PlaybackSpeed = () => {

app/containers/AudioPlayer/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import PlayButton from './PlayButton';
1313
import AudioManager from '../../lib/methods/AudioManager';
1414
import { AUDIO_PLAYBACK_SPEED, AVAILABLE_SPEEDS } from './constants';
1515
import { TDownloadState } from '../../lib/methods/handleMediaDownload';
16-
import { emitter } from '../../lib/methods/helpers';
16+
import { emitter } from '../../lib/methods/helpers/emitter';
1717
import { TAudioState } from './types';
18-
import { useUserPreferences } from '../../lib/methods';
18+
import { useUserPreferences } from '../../lib/methods/userPreferences';
1919

2020
interface IAudioPlayerProps {
2121
fileUri: string;

app/containers/Avatar/AvatarWithEdit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import I18n from '../../i18n';
88
import { useTheme } from '../../theme';
99
import { BUTTON_HIT_SLOP } from '../message/utils';
1010
import { useAppSelector } from '../../lib/hooks';
11-
import { compareServerVersion } from '../../lib/methods/helpers';
11+
import { compareServerVersion } from '../../lib/methods/helpers/compareServerVersion';
1212
import sharedStyles from '../../views/Styles';
1313

1414
const styles = StyleSheet.create({

app/containers/Avatar/__snapshots__/Avatar.test.tsx.snap

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ exports[`Story Snapshots: AvatarExternalProviderUrl should match snapshot 1`] =
3737
source={
3838
[
3939
{
40-
"headers": {
41-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
42-
},
40+
"headers": undefined,
4341
"uri": "https://hips.hearstapps.com/hmg-prod/images/dog-puppy-on-garden-royalty-free-image-1586966191.jpg?crop=0.752xw:1.00xh;0.175xw,0&resize=1200:*&format=png&size=112",
4442
},
4543
]
@@ -94,9 +92,7 @@ exports[`Story Snapshots: AvatarPath should match snapshot 1`] = `
9492
source={
9593
[
9694
{
97-
"headers": {
98-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
99-
},
95+
"headers": undefined,
10096
"uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=112",
10197
},
10298
]
@@ -151,9 +147,7 @@ exports[`Story Snapshots: AvatarRoomId should match snapshot 1`] = `
151147
source={
152148
[
153149
{
154-
"headers": {
155-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
156-
},
150+
"headers": undefined,
157151
"uri": "https://open.rocket.chat/avatar/room/devWBbYr7inwupPqK?format=png&size=112",
158152
},
159153
]
@@ -208,9 +202,7 @@ exports[`Story Snapshots: AvatarText should match snapshot 1`] = `
208202
source={
209203
[
210204
{
211-
"headers": {
212-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
213-
},
205+
"headers": undefined,
214206
"uri": "https://open.rocket.chat/avatar/Avatar?format=png&size=112",
215207
},
216208
]
@@ -265,9 +257,7 @@ exports[`Story Snapshots: AvatarUrl should match snapshot 1`] = `
265257
source={
266258
[
267259
{
268-
"headers": {
269-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
270-
},
260+
"headers": undefined,
271261
"uri": "https://user-images.githubusercontent.com/29778115/89444446-14738480-d728-11ea-9412-75fd978d95fb.jpg",
272262
},
273263
]
@@ -322,9 +312,7 @@ exports[`Story Snapshots: Channel should match snapshot 1`] = `
322312
source={
323313
[
324314
{
325-
"headers": {
326-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
327-
},
315+
"headers": undefined,
328316
"uri": "https://open.rocket.chat/avatar/@general?format=png&size=112",
329317
},
330318
]
@@ -379,9 +367,7 @@ exports[`Story Snapshots: Children should match snapshot 1`] = `
379367
source={
380368
[
381369
{
382-
"headers": {
383-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
384-
},
370+
"headers": undefined,
385371
"uri": "https://open.rocket.chat/avatar/Avatar?format=png&size=112",
386372
},
387373
]
@@ -476,9 +462,7 @@ exports[`Story Snapshots: CustomBorderRadius should match snapshot 1`] = `
476462
source={
477463
[
478464
{
479-
"headers": {
480-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
481-
},
465+
"headers": undefined,
482466
"uri": "https://open.rocket.chat/avatar/Avatar?format=png&size=112",
483467
},
484468
]
@@ -535,9 +519,7 @@ exports[`Story Snapshots: CustomStyle should match snapshot 1`] = `
535519
source={
536520
[
537521
{
538-
"headers": {
539-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
540-
},
522+
"headers": undefined,
541523
"uri": "https://open.rocket.chat/avatar/Avatar?format=png&size=112",
542524
},
543525
]
@@ -592,9 +574,7 @@ exports[`Story Snapshots: Direct should match snapshot 1`] = `
592574
source={
593575
[
594576
{
595-
"headers": {
596-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
597-
},
577+
"headers": undefined,
598578
"uri": "https://open.rocket.chat/avatar/diego.mello?format=png&size=112",
599579
},
600580
]
@@ -702,9 +682,7 @@ exports[`Story Snapshots: RoomAvatarExternalProviderUrl should match snapshot 1`
702682
source={
703683
[
704684
{
705-
"headers": {
706-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
707-
},
685+
"headers": undefined,
708686
"uri": "https://cdn.pensador.com/img/authors/ho/me/homer-simpson-l.jpg?format=png&size=112",
709687
},
710688
]
@@ -759,9 +737,7 @@ exports[`Story Snapshots: Static should match snapshot 1`] = `
759737
source={
760738
[
761739
{
762-
"headers": {
763-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
764-
},
740+
"headers": undefined,
765741
"uri": "https://user-images.githubusercontent.com/29778115/89444446-14738480-d728-11ea-9412-75fd978d95fb.jpg",
766742
},
767743
]
@@ -850,9 +826,7 @@ exports[`Story Snapshots: Touchable should match snapshot 1`] = `
850826
source={
851827
[
852828
{
853-
"headers": {
854-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
855-
},
829+
"headers": undefined,
856830
"uri": "https://open.rocket.chat/avatar/Avatar?format=png&size=112",
857831
},
858832
]
@@ -908,9 +882,7 @@ exports[`Story Snapshots: WithETag should match snapshot 1`] = `
908882
source={
909883
[
910884
{
911-
"headers": {
912-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
913-
},
885+
"headers": undefined,
914886
"uri": "https://open.rocket.chat/avatar/djorkaeff.alexandre?format=png&size=112&etag=5ag8KffJcZj9m5rCv",
915887
},
916888
]
@@ -965,9 +937,7 @@ exports[`Story Snapshots: WithoutETag should match snapshot 1`] = `
965937
source={
966938
[
967939
{
968-
"headers": {
969-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
970-
},
940+
"headers": undefined,
971941
"uri": "https://open.rocket.chat/avatar/djorkaeff.alexandre?format=png&size=112",
972942
},
973943
]
@@ -1022,9 +992,7 @@ exports[`Story Snapshots: WrongServer should match snapshot 1`] = `
1022992
source={
1023993
[
1024994
{
1025-
"headers": {
1026-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
1027-
},
995+
"headers": undefined,
1028996
"uri": "https://google.com/avatar/Avatar?format=png&size=112",
1029997
},
1030998
]

app/containers/Chip/__snapshots__/Chip.test.tsx.snap

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ exports[`Story Snapshots: ChipText should match snapshot 1`] = `
103103
source={
104104
[
105105
{
106-
"headers": {
107-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
108-
},
106+
"headers": undefined,
109107
"uri": "https://open.rocket.chat/avatar/rocket.cat?format=png&size=56",
110108
},
111109
]
@@ -283,9 +281,7 @@ exports[`Story Snapshots: ChipWithShortText should match snapshot 1`] = `
283281
source={
284282
[
285283
{
286-
"headers": {
287-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
288-
},
284+
"headers": undefined,
289285
"uri": "https://open.rocket.chat/avatar/rocket.cat?format=png&size=56",
290286
},
291287
]
@@ -683,9 +679,7 @@ exports[`Story Snapshots: ChipWithoutIcon should match snapshot 1`] = `
683679
source={
684680
[
685681
{
686-
"headers": {
687-
"User-Agent": "RC Mobile; ios unknown; vunknown (unknown)",
688-
},
682+
"headers": undefined,
689683
"uri": "https://open.rocket.chat/avatar/rocket.cat?format=png&size=56",
690684
},
691685
]

app/containers/EmojiPicker/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { useSafeAreaInsets } from 'react-native-safe-area-context';
66
import EmojiCategory from './EmojiCategory';
77
import Footer from './Footer';
88
import styles from './styles';
9-
import { categories } from '../../lib/constants';
9+
import { categories } from '../../lib/constants/emojis';
1010
import { IEmoji } from '../../definitions';
11-
import { addFrequentlyUsed } from '../../lib/methods';
11+
import { addFrequentlyUsed } from '../../lib/methods/emojis';
1212
import { IEmojiPickerProps, EventTypes } from './interfaces';
1313
import { CustomIcon, TIconsName } from '../CustomIcon';
1414
import { TabView } from '../TabView';

app/containers/Header/components/HeaderButton/Common.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { StackActions, useNavigation } from '@react-navigation/native';
33
import { StyleProp, ViewStyle } from 'react-native';
44

55
import I18n from '../../../../i18n';
6-
import { isIOS } from '../../../../lib/methods/helpers';
6+
import { isIOS } from '../../../../lib/methods/helpers/deviceInfo';
77
import Container from './HeaderButtonContainer';
88
import Item, { IHeaderButtonItem } from './HeaderButtonItem';
99
import { useTheme } from '../../../../theme';

0 commit comments

Comments
 (0)