-
Notifications
You must be signed in to change notification settings - Fork 12.6k
feat(e2ee): passphrase requirements #37327
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
Merged
Merged
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
a746188
feat(e2ee): passphrase requirements
cardoso 5152cc3
chore: reuse PasswordVerifier
cardoso 6ad591f
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 3379080
test: fix passphrase conformance
cardoso 6cda95d
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso 4f49988
fix: keysExist reactivity
cardoso b6f776c
Merge branch 'develop' into feat/ESH-43
cardoso 6ca60b2
Merge branch 'develop' into feat/ESH-43
cardoso 1859f0a
Merge branch 'develop' into feat/ESH-43
cardoso 9f4b310
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso eee5b95
refactor(e2ee): split change and reset components
cardoso 0683b3b
Merge branch 'develop' of https://github.com/RocketChat/Rocket.Chat i…
cardoso bb14a39
refactor(e2ee): change password hook
cardoso f034226
Merge branch 'develop' into feat/ESH-43
cardoso a595fca
refactor: remove unneeded param
cardoso f0ecb7a
Merge branch 'develop' into feat/ESH-43
cardoso 8b5b953
Merge branch 'develop' into feat/ESH-43
cardoso cb5572a
fix: change passphrase form reactivity
cardoso 213ee9d
chore: remove unneeded comments
cardoso f482202
chore: reuse PasswordValidation type
cardoso b72382b
Merge branch 'develop' into feat/ESH-43
cardoso 2297bea
fix: password verifier accessibility
cardoso 3540a40
Merge branch 'develop' into feat/ESH-43
cardoso 71bce62
fix: relax password policy type
cardoso 0649230
chore: remove unneeded type constraint
cardoso 323039c
fix: inneffective memoization
cardoso a33533b
Merge branch 'develop' into feat/ESH-43
cardoso afca159
fix: useKeysExist
cardoso 4350c2f
Merge branch 'develop' into feat/ESH-43
cardoso 82a4ab1
fix: accessibility
cardoso 3772dc9
Merge branch 'develop' into feat/ESH-43
cardoso cb536c8
fix: aria-required and aria-invalid
cardoso f262d1e
Merge branch 'develop' into feat/ESH-43
cardoso 578a672
chore: apply review suggestions
cardoso 612a1a4
chore: add changeset
cardoso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
apps/meteor/client/views/account/security/ChangePassphrase.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,211 @@ | ||
| import { Box, Field, FieldError, FieldGroup, FieldHint, FieldLabel, FieldRow, PasswordInput, Button } from '@rocket.chat/fuselage'; | ||
| import { PasswordVerifierList } from '@rocket.chat/ui-client'; | ||
| import { useToastMessageDispatch, usePasswordPolicy } from '@rocket.chat/ui-contexts'; | ||
| import { useMutation } from '@tanstack/react-query'; | ||
| import DOMPurify from 'dompurify'; | ||
| import { useEffect, useId } from 'react'; | ||
| import { Controller, useForm } from 'react-hook-form'; | ||
| import { Trans, useTranslation } from 'react-i18next'; | ||
|
|
||
| import { e2e } from '../../../lib/e2ee/rocketchat.e2e'; | ||
| import { useE2EEState } from '../../room/hooks/useE2EEState'; | ||
|
|
||
| const PASSPHRASE_POLICY = Object.freeze({ | ||
| enabled: true, | ||
| minLength: 30, | ||
| mustContainAtLeastOneLowercase: true, | ||
| mustContainAtLeastOneUppercase: true, | ||
| mustContainAtLeastOneNumber: true, | ||
| mustContainAtLeastOneSpecialCharacter: true, | ||
| forbidRepeatingCharacters: false, | ||
| }); | ||
|
|
||
| const useKeysExist = () => { | ||
| const state = useE2EEState(); | ||
| return state === 'READY' || state === 'SAVE_PASSWORD'; | ||
| }; | ||
|
|
||
| const useValidatePassphrase = (passphrase: string) => { | ||
| const validate = usePasswordPolicy(PASSPHRASE_POLICY); | ||
| return validate(passphrase); | ||
| }; | ||
|
|
||
| const useChangeE2EPasswordMutation = () => { | ||
| return useMutation({ | ||
| mutationFn: async (newPassword: string) => { | ||
| await e2e.changePassword(newPassword); | ||
| }, | ||
| }); | ||
| }; | ||
|
|
||
| const defaultValues = { | ||
| passphrase: '', | ||
| confirmationPassphrase: '', | ||
| }; | ||
|
|
||
| export const ChangePassphrase = (): JSX.Element => { | ||
| const { t } = useTranslation(); | ||
| const dispatchToastMessage = useToastMessageDispatch(); | ||
|
|
||
| const uniqueId = useId(); | ||
| const passphraseId = `passphrase-${uniqueId}`; | ||
| const passphraseHintId = `${passphraseId}-hint`; | ||
| const passphraseErrorId = `${passphraseId}-error`; | ||
| const confirmPassphraseId = `confirm-passphrase-${uniqueId}`; | ||
| const confirmPassphraseErrorId = `${confirmPassphraseId}-error`; | ||
| const passphraseVerifierId = `verifier-${uniqueId}`; | ||
| const e2ePasswordExplanationId = `explanation-${uniqueId}`; | ||
|
|
||
| const { | ||
| watch, | ||
| formState: { errors, isValid }, | ||
| handleSubmit, | ||
| reset, | ||
| resetField, | ||
| control, | ||
| trigger, | ||
| } = useForm({ | ||
| defaultValues, | ||
| mode: 'all', | ||
| }); | ||
|
|
||
| const { passphrase, confirmationPassphrase } = watch(); | ||
| const { validations, valid } = useValidatePassphrase(passphrase); | ||
| useEffect(() => { | ||
| if (!valid) { | ||
| resetField('confirmationPassphrase'); | ||
| return; | ||
| } | ||
| if (confirmationPassphrase) { | ||
| const validateConfirmation = async () => { | ||
| await trigger('confirmationPassphrase'); | ||
| }; | ||
| void validateConfirmation(); | ||
| } | ||
| }, [valid, confirmationPassphrase, resetField, trigger]); | ||
| const keysExist = useKeysExist(); | ||
|
|
||
| const updatePassword = useChangeE2EPasswordMutation(); | ||
|
|
||
| const handleSave = async ({ passphrase }: { passphrase: string }) => { | ||
| try { | ||
| await updatePassword.mutateAsync(passphrase); | ||
| dispatchToastMessage({ type: 'success', message: t('Encryption_key_saved_successfully') }); | ||
| reset(); | ||
| } catch (error) { | ||
| dispatchToastMessage({ type: 'error', message: error }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
cardoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <Box | ||
| is='p' | ||
| fontScale='p1' | ||
| id={e2ePasswordExplanationId} | ||
| dangerouslySetInnerHTML={{ __html: DOMPurify.sanitize(t('E2E_Encryption_Password_Explanation')) }} | ||
| /> | ||
| <Box mbs={36} w='full'> | ||
| <Box is='h3' fontScale='h4' mbe={12}> | ||
| {t('Change_E2EE_password')} | ||
| </Box> | ||
| <FieldGroup w='full'> | ||
| <Field> | ||
| <FieldLabel htmlFor={passphraseId}>{t('New_E2EE_password')}</FieldLabel> | ||
| <FieldRow> | ||
| <Controller | ||
| control={control} | ||
| name='passphrase' | ||
| rules={{ | ||
| required: t('Required_field', { field: t('New_E2EE_password') }), | ||
| validate: () => (valid ? true : t('Password_must_meet_the_complexity_requirements')), | ||
| }} | ||
| render={({ field }) => ( | ||
| <PasswordInput | ||
| {...field} | ||
| id={passphraseId} | ||
| error={errors.passphrase?.message} | ||
| disabled={!keysExist} | ||
| aria-describedby={[ | ||
| e2ePasswordExplanationId, | ||
| keysExist ? passphraseVerifierId : passphraseHintId, | ||
| errors.passphrase && passphraseErrorId, | ||
| ] | ||
| .filter(Boolean) | ||
| .join(' ')} | ||
| aria-invalid={errors.passphrase ? 'true' : 'false'} | ||
| /> | ||
| )} | ||
| /> | ||
| </FieldRow> | ||
| {errors.passphrase && ( | ||
| <FieldError role='alert' id={passphraseErrorId} hidden aria-hidden={!errors.passphrase}> | ||
| {errors.passphrase.message} | ||
| </FieldError> | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| )} | ||
| {keysExist ? ( | ||
| <PasswordVerifierList id={passphraseVerifierId} validations={validations} /> | ||
| ) : ( | ||
| <FieldHint id={passphraseHintId}> | ||
| <Trans i18nKey='Enter_current_E2EE_password_to_set_new'> | ||
| To set a new password, first | ||
| <Box | ||
| is='a' | ||
| href='#' | ||
| onClick={async (e) => { | ||
| e.preventDefault(); | ||
| await e2e.decodePrivateKeyFlow(); | ||
| }} | ||
cardoso marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| > | ||
| enter your current E2EE password. | ||
| </Box> | ||
| </Trans> | ||
| </FieldHint> | ||
| )} | ||
| </Field> | ||
| {valid && ( | ||
| <Field> | ||
| <FieldLabel htmlFor={confirmPassphraseId}>{t('Confirm_new_E2EE_password')}</FieldLabel> | ||
| <FieldRow> | ||
| <Controller | ||
| control={control} | ||
| name='confirmationPassphrase' | ||
| rules={{ | ||
| required: t('Required_field', { field: t('Confirm_password') }), | ||
| validate: (value) => (passphrase !== value ? t('Passwords_do_not_match') : true), | ||
| }} | ||
| render={({ field }) => ( | ||
| <PasswordInput | ||
| {...field} | ||
| id={confirmPassphraseId} | ||
| error={errors.confirmationPassphrase?.message} | ||
| flexGrow={1} | ||
| disabled={!keysExist || !valid} | ||
| aria-required={passphrase ? 'true' : 'false'} | ||
| aria-invalid={errors.confirmationPassphrase ? 'true' : 'false'} | ||
| aria-describedby={errors.confirmationPassphrase ? confirmPassphraseErrorId : undefined} | ||
| /> | ||
| )} | ||
| /> | ||
| </FieldRow> | ||
| {errors.confirmationPassphrase && ( | ||
| <FieldError aria-live='assertive' id={confirmPassphraseErrorId} role='alert'> | ||
| {errors.confirmationPassphrase.message} | ||
| </FieldError> | ||
| )} | ||
| </Field> | ||
| )} | ||
| </FieldGroup> | ||
| <Button | ||
| primary | ||
| disabled={!(keysExist && valid && isValid)} | ||
| onClick={handleSubmit(handleSave)} | ||
| mbs={12} | ||
| data-qa-type='e2e-encryption-save-password-button' | ||
| > | ||
| {t('Save_changes')} | ||
| </Button> | ||
| </Box> | ||
| </> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.