Skip to content

Commit

Permalink
Reenable header, add disable e2ee on header if needed, disable most o…
Browse files Browse the repository at this point in the history
…f actions on RoomActionsView
  • Loading branch information
diegolmello committed May 9, 2024
1 parent 354e156 commit 9c796e0
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 114 deletions.
8 changes: 7 additions & 1 deletion app/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -841,5 +841,11 @@
"Your_invite_link_will_never_expire": "Your invite link will never expire.",
"Your_password_is": "Your password is",
"Your_push_was_sent_to_s_devices": "Your push was sent to {{s}} devices",
"Your_workspace": "Your workspace"
"Your_workspace": "Your workspace",
"Enable": "Enable",
"Disable": "Disable",
"Disable_encryption_title": "Disable encryption",
"Enable_encryption_title": "Enable encryption",
"Disable_encryption_description": "Disabling E2EE compromises privacy. You can re-enable it later if needed. Proceed with caution.",
"Enable_encryption_description": "Ensure conversations are kept private"
}
8 changes: 7 additions & 1 deletion app/i18n/locales/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -827,5 +827,11 @@
"Your_invite_link_will_never_expire": "Seu link de convite nunca irá vencer.",
"Your_password_is": "Sua senha é",
"Your_push_was_sent_to_s_devices": "A sua notificação foi enviada para {{s}} dispositivos",
"Your_workspace": "Sua workspace"
"Your_workspace": "Sua workspace",
"Enable": "Habilitar",
"Disable": "Desabilitar",
"Disable_encryption_title": "Desabilitar criptografia",
"Enable_encryption_title": "Habilitar criptografia",
"Disable_encryption_description": "Desabilitar a criptografia compromete sua privacidade. Você pode reabilitá-la depois se precisar. Continue com cautela.",
"Enable_encryption_description": "Garante a privacidade das suas conversas"
}
20 changes: 0 additions & 20 deletions app/lib/encryption/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,26 +501,6 @@ class Encryption {

// Decrypt multiple subscriptions
decryptSubscriptions = (subscriptions: ISubscription[]) => Promise.all(subscriptions.map(s => this.decryptSubscription(s)));

// Missing room encryption key
isMissingRoomE2EEKey = ({
encryptionEnabled,
roomEncrypted,
E2EKey
}: {
encryptionEnabled: boolean;
roomEncrypted: TSubscriptionModel['encrypted'];
E2EKey: TSubscriptionModel['E2EKey'];
}) => (encryptionEnabled && roomEncrypted && !E2EKey) ?? false;

// Encrypted room, but user session is not encrypted
isE2EEDisabledEncryptedRoom = ({
encryptionEnabled,
roomEncrypted
}: {
encryptionEnabled: boolean;
roomEncrypted: TSubscriptionModel['encrypted'];
}) => (!encryptionEnabled && roomEncrypted) ?? false;
}

const encryption = new Encryption();
Expand Down
70 changes: 70 additions & 0 deletions app/lib/encryption/helpers/toggleRoomE2EE.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { Alert } from 'react-native';

import { Services } from '../../services';
import database from '../../database';
import { getSubscriptionByRoomId } from '../../database/services/Subscription';
import log from '../../methods/helpers/log';
import I18n from '../../../i18n';

export const toggleRoomE2EE = async (rid: string): Promise<void> => {
const room = await getSubscriptionByRoomId(rid);
if (!room) {
return;
}

const isEncrypted = room.encrypted;
const title = I18n.t(isEncrypted ? 'Disable_encryption_title' : 'Enable_encryption_title');
const message = I18n.t(isEncrypted ? 'Disable_encryption_description' : 'Enable_encryption_description');
const confirmationText = I18n.t(isEncrypted ? 'Disable' : 'Enable');

Alert.alert(
title,
message,
[
{
text: I18n.t('Cancel'),
style: 'cancel'
},
{
text: confirmationText,
style: isEncrypted ? 'destructive' : 'default',
onPress: async () => {
try {
const db = database.active;

// Toggle encrypted value
const encrypted = !room.encrypted;

// Instantly feedback to the user
await db.write(async () => {
await room.update(r => {
r.encrypted = encrypted;
});
});

try {
// Send new room setting value to server
const { result } = await Services.saveRoomSettings(rid, { encrypted });
// If it was saved successfully
if (result) {
return;
}
} catch {
// do nothing
}

// If something goes wrong we go back to the previous value
await db.write(async () => {
await room.update(r => {
r.encrypted = room.encrypted;
});
});
} catch (e) {
log(e);
}
}
}
],
{ cancelable: true }
);
};
39 changes: 39 additions & 0 deletions app/lib/encryption/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import SimpleCrypto from 'react-native-simple-crypto';

import { random } from '../methods/helpers';
import { fromByteArray, toByteArray } from './helpers/base64-js';
import { TSubscriptionModel } from '../../definitions';

const BASE64URI = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';

Expand Down Expand Up @@ -58,3 +59,41 @@ export const toString = (thing: string | ByteBuffer | Buffer | ArrayBuffer | Uin
return new ByteBuffer.wrap(thing).toString('binary');
};
export const randomPassword = (): string => `${random(3)}-${random(3)}-${random(3)}`.toLowerCase();

// Missing room encryption key
export const isMissingRoomE2EEKey = ({
encryptionEnabled,
roomEncrypted,
E2EKey
}: {
encryptionEnabled: boolean;
roomEncrypted: TSubscriptionModel['encrypted'];
E2EKey: TSubscriptionModel['E2EKey'];
}): boolean => (encryptionEnabled && roomEncrypted && !E2EKey) ?? false;

// Encrypted room, but user session is not encrypted
export const isE2EEDisabledEncryptedRoom = ({
encryptionEnabled,
roomEncrypted
}: {
encryptionEnabled: boolean;
roomEncrypted: TSubscriptionModel['encrypted'];
}): boolean => (!encryptionEnabled && roomEncrypted) ?? false;

export const hasE2EEWarning = ({
encryptionEnabled,
roomEncrypted,
E2EKey
}: {
encryptionEnabled: boolean;
roomEncrypted: TSubscriptionModel['encrypted'];
E2EKey: TSubscriptionModel['E2EKey'];
}): boolean => {
if (isMissingRoomE2EEKey({ encryptionEnabled, roomEncrypted, E2EKey })) {
return true;
}
if (isE2EEDisabledEncryptedRoom({ encryptionEnabled, roomEncrypted })) {
return true;
}
return false;
};
4 changes: 2 additions & 2 deletions app/views/RoomActionsView/components/CallSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import * as List from '../../../containers/List';
import { useVideoConf } from '../../../lib/hooks/useVideoConf';

export default function CallSection({ rid }: { rid: string }): React.ReactElement | null {
export default function CallSection({ rid, disabled }: { rid: string; disabled: boolean }): React.ReactElement | null {
const { callEnabled, showInitCallActionSheet, disabledTooltip } = useVideoConf(rid);
if (callEnabled)
return (
Expand All @@ -15,7 +15,7 @@ export default function CallSection({ rid }: { rid: string }): React.ReactElemen
testID='room-actions-call'
left={() => <List.Icon name='phone' />}
showActionIndicator
disabled={disabledTooltip}
disabled={disabledTooltip || disabled}
/>
<List.Separator />
</List.Section>
Expand Down

0 comments on commit 9c796e0

Please sign in to comment.