-
-
Notifications
You must be signed in to change notification settings - Fork 238
feat: add option to force encryption #6410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ import { I18nContext } from '../contexts/I18nContext' | |
| const log = getLogger('renderer/loginForm') | ||
|
|
||
| import type { Credentials } from './Settings/DefaultCredentials' | ||
| import SettingsStoreInstance, { useSettingsStore } from '../stores/settings' | ||
| import Switch from './Switch' | ||
|
|
||
| const Socket = { | ||
| automatic: 'automatic', | ||
|
|
@@ -29,19 +31,26 @@ const CertificateChecks = { | |
| type LoginProps = React.PropsWithChildren<{ | ||
| credentials: Credentials | ||
| setCredentials: (credentials: Credentials) => void | ||
| forceEncryption?: boolean | ||
| setForceEncryption?: (forceEncryption: boolean) => void | ||
| /** whether editing existing account */ | ||
| isEdit?: true | ||
| }> | ||
|
|
||
| export default function LoginForm({ | ||
| credentials, | ||
| setCredentials, | ||
| forceEncryption: forceEncryptionProp, | ||
| setForceEncryption, | ||
| isEdit, | ||
| }: LoginProps) { | ||
| const [uiShowAdvanced, setUiShowAdvanced] = useState<boolean>(false) | ||
| const [providerInfo, setProviderInfo] = useState< | ||
| Type.ProviderInfo | undefined | ||
| >() | ||
| const settingsStore = useSettingsStore()[0] | ||
| const forceEncryption = | ||
| forceEncryptionProp ?? settingsStore?.settings['force_encryption'] === '1' | ||
|
|
||
| const handleCredentialsChange = ( | ||
| event: React.ChangeEvent<HTMLInputElement> | ||
|
|
@@ -260,7 +269,6 @@ export default function LoginForm({ | |
| <option value={Socket.starttls}>STARTTLS</option> | ||
| <option value={Socket.plain}>{tx('off')}</option> | ||
| </DeltaSelect> | ||
|
|
||
| <DeltaSelect | ||
| id='certificateChecks' | ||
| label={tx('login_certificate_checks')} | ||
|
|
@@ -275,6 +283,26 @@ export default function LoginForm({ | |
| {tx('accept_invalid_certificates')} | ||
| </option> | ||
| </DeltaSelect> | ||
| <div className='delta-form-group delta-switch'> | ||
| <label> | ||
| <span>{tx('enforce_e2ee')}</span> | ||
| {/** be aware that this setting applies to all relays! */} | ||
| <Switch | ||
| checked={forceEncryption} | ||
| disabled={settingsStore == null} | ||
| onChange={() => { | ||
| if (setForceEncryption) { | ||
| setForceEncryption(!forceEncryption) | ||
| return | ||
| } | ||
| SettingsStoreInstance.effect.setCoreSetting( | ||
| 'force_encryption', | ||
| forceEncryption ? '0' : '1' | ||
| ) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is basically unused now, right? |
||
| }} | ||
| /> | ||
| </label> | ||
| </div> | ||
| </Collapse> | ||
| <br /> | ||
| </div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,7 @@ import useDialog from '../../hooks/dialog/useDialog' | |||||
| import type { DialogProps } from '../../contexts/DialogContext' | ||||||
| import AlertDialog from './AlertDialog' | ||||||
| import { T } from '@deltachat/jsonrpc-client' | ||||||
| import { useSettingsStore } from '../../stores/settings' | ||||||
| import SettingsStoreInstance, { useSettingsStore } from '../../stores/settings' | ||||||
| import { getLogger } from '@deltachat-desktop/shared/logger' | ||||||
|
|
||||||
| type AccountAndPasswordDialogProps = DialogProps & { | ||||||
|
|
@@ -57,11 +57,15 @@ function EditAccountInner({ | |||||
| onClose: DialogProps['onClose'] | ||||||
| addr?: string | ||||||
| }) { | ||||||
| const settingsStore = useSettingsStore()[0] | ||||||
| const [initialSettings, setInitialAccountSettings] = | ||||||
| useState<Credentials>(defaultCredentials()) | ||||||
|
|
||||||
| const [accountSettings, setAccountSettings] = | ||||||
| useState<Credentials>(defaultCredentials()) | ||||||
| const [forceEncryption, setForceEncryption] = useState<boolean>( | ||||||
| settingsStore?.settings['force_encryption'] !== '0' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We already changed this in one place, so let's be consistent? Especially here where the |
||||||
| ) | ||||||
|
|
||||||
| const { openDialog } = useDialog() | ||||||
| const tx = useTranslationFunction() | ||||||
|
|
@@ -105,7 +109,18 @@ function EditAccountInner({ | |||||
| }, [addr]) | ||||||
|
|
||||||
| const onUpdate = useCallback(async () => { | ||||||
| const onSuccess = () => onClose() | ||||||
| const onSuccess = async () => { | ||||||
| const forceEncryptionValue = forceEncryption ? '1' : '0' | ||||||
| if ( | ||||||
| settingsStore?.settings['force_encryption'] !== forceEncryptionValue | ||||||
| ) { | ||||||
| await SettingsStoreInstance.effect.setCoreSetting( | ||||||
| 'force_encryption', | ||||||
| forceEncryptionValue | ||||||
| ) | ||||||
| } | ||||||
| onClose() | ||||||
| } | ||||||
|
|
||||||
| const update = () => { | ||||||
| openDialog(ConfigureProgressDialog, { | ||||||
|
|
@@ -121,8 +136,16 @@ function EditAccountInner({ | |||||
| log.error('changing email addres of transport is not allowed') | ||||||
| return | ||||||
| } | ||||||
|
|
||||||
| update() | ||||||
| }, [accountSettings, initialSettings, onClose, openDialog]) | ||||||
| }, [ | ||||||
| accountSettings, | ||||||
| forceEncryption, | ||||||
| initialSettings, | ||||||
| onClose, | ||||||
| openDialog, | ||||||
| settingsStore, | ||||||
| ]) | ||||||
|
|
||||||
| const onOk = useCallback(async () => { | ||||||
| await onUpdate() | ||||||
|
|
@@ -137,6 +160,8 @@ function EditAccountInner({ | |||||
| <LoginForm | ||||||
| credentials={accountSettings} | ||||||
| setCredentials={setAccountSettings} | ||||||
| forceEncryption={forceEncryption} | ||||||
| setForceEncryption={setForceEncryption} | ||||||
| isEdit | ||||||
| /> | ||||||
| )} | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,6 +16,7 @@ import useTranslationFunction from '../../hooks/useTranslationFunction' | |||||
| import useDialog from '../../hooks/dialog/useDialog' | ||||||
| import { DialogId } from '../../contexts/DialogContext' | ||||||
| import AlertDialog from '../dialogs/AlertDialog' | ||||||
| import SettingsStoreInstance, { useSettingsStore } from '../../stores/settings' | ||||||
|
|
||||||
| import type ScreenController from '../../ScreenController' | ||||||
|
|
||||||
|
|
@@ -32,25 +33,43 @@ export default function AccountSetupScreen({ | |||||
|
|
||||||
| const [credentials, setCredentials] = | ||||||
| useState<Credentials>(defaultCredentials()) | ||||||
|
|
||||||
| const onClickLogin = useCallback( | ||||||
| () => | ||||||
| openDialog(ConfigureProgressDialog, { | ||||||
| credentials, | ||||||
| onSuccess: () => { | ||||||
| selectAccount(accountId) | ||||||
| }, | ||||||
| onFail: (error: string) => | ||||||
| setPromptDialogId( | ||||||
| openDialog(AlertDialog, { | ||||||
| message: error, | ||||||
| cb: () => setPromptDialogId(null), | ||||||
| }) | ||||||
| ), | ||||||
| }), | ||||||
| [accountId, openDialog, selectAccount, credentials] | ||||||
| const settingsStore = useSettingsStore()[0] | ||||||
| const [forceEncryption, setForceEncryption] = useState<boolean>( | ||||||
| settingsStore?.settings['force_encryption'] !== '0' | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See #6410 (comment) |
||||||
| ) | ||||||
|
|
||||||
| const onClickLogin = useCallback(() => { | ||||||
| openDialog(ConfigureProgressDialog, { | ||||||
| credentials, | ||||||
| onSuccess: async () => { | ||||||
| const forceEncryptionValue = forceEncryption ? '1' : '0' | ||||||
| if ( | ||||||
| settingsStore?.settings['force_encryption'] !== forceEncryptionValue | ||||||
| ) { | ||||||
| await SettingsStoreInstance.effect.setCoreSetting( | ||||||
| 'force_encryption', | ||||||
| forceEncryptionValue | ||||||
| ) | ||||||
| } | ||||||
| selectAccount(accountId) | ||||||
| }, | ||||||
| onFail: (error: string) => | ||||||
| setPromptDialogId( | ||||||
| openDialog(AlertDialog, { | ||||||
| message: error, | ||||||
| cb: () => setPromptDialogId(null), | ||||||
| }) | ||||||
| ), | ||||||
| }) | ||||||
| }, [ | ||||||
| accountId, | ||||||
| credentials, | ||||||
| forceEncryption, | ||||||
| openDialog, | ||||||
| selectAccount, | ||||||
| settingsStore, | ||||||
| ]) | ||||||
|
|
||||||
| // TODO(maxph): we're now using <dialog> and can submit result via input | ||||||
| // and not an explicit keyboard handling | ||||||
| const onKeyDown = useCallback( | ||||||
|
|
@@ -88,6 +107,8 @@ export default function AccountSetupScreen({ | |||||
| <LoginForm | ||||||
| credentials={credentials} | ||||||
| setCredentials={setCredentials} | ||||||
| forceEncryption={forceEncryption} | ||||||
| setForceEncryption={setForceEncryption} | ||||||
| /> | ||||||
| </DialogContent> | ||||||
| </DialogBody> | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't do anything, right? It's the default value anyway.