Skip to content

Commit

Permalink
Mobile: Fixes laurent22#5585: Fixed logic of setting master password …
Browse files Browse the repository at this point in the history
…in Encryption screen
  • Loading branch information
laurent22 committed Oct 17, 2021
1 parent a5560a6 commit 1406d97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Expand Up @@ -106,7 +106,7 @@ const EncryptionConfigScreen = (props: Props) => {
<View style={{ flex: 1, flexDirection: 'row', alignItems: 'center' }}>
<TextInput selectionColor={theme.textSelectionColor} keyboardAppearance={theme.keyboardAppearance} secureTextEntry={true} value={password} onChangeText={(text: string) => onInputPasswordChange(mk, text)} style={inputStyle}></TextInput>
<Text style={{ fontSize: theme.fontSize, marginRight: 10, color: theme.color }}>{passwordOk}</Text>
<Button title={_('Save')} onPress={() => onSavePasswordClick(mk, props.passwords)}></Button>
<Button title={_('Save')} onPress={() => onSavePasswordClick(mk, inputPasswords)}></Button>
</View>
);
}
Expand Down
6 changes: 5 additions & 1 deletion packages/app-mobile/root.tsx
Expand Up @@ -476,7 +476,7 @@ async function initialize(dispatch: Function) {
if (Setting.value('env') == 'prod') {
await db.open({ name: 'joplin.sqlite' });
} else {
await db.open({ name: 'joplin-104.sqlite' });
await db.open({ name: 'joplin-107.sqlite' });

// await db.clearForTesting();
}
Expand All @@ -492,6 +492,10 @@ async function initialize(dispatch: Function) {
// Setting.setValue('sync.10.userContentPath', 'https://joplinusercontent.com');
Setting.setValue('sync.10.path', 'http://api.joplincloud.local:22300');
Setting.setValue('sync.10.userContentPath', 'http://joplinusercontent.local:22300');

Setting.setValue('sync.target', 10);
Setting.setValue('sync.10.username', 'user1@example.com');
Setting.setValue('sync.10.password', 'hunter1hunter2hunter3');
}

if (!Setting.value('clientId')) Setting.setValue('clientId', uuid.create());
Expand Down
13 changes: 12 additions & 1 deletion packages/lib/components/EncryptionConfigScreen/utils.ts
Expand Up @@ -96,6 +96,13 @@ export const onSavePasswordClick = (mk: MasterKeyEntity, passwords: Record<strin
} else {
Setting.setObjectValue('encryption.passwordCache', mk.id, password);
}

// When setting a master key password, if the master password is not set, we
// assume that this password is the master password. If it turns out it's
// not, it's always possible to change it in the UI.
if (password && !Setting.value('encryption.masterPassword')) {
Setting.setValue('encryption.masterPassword', password);
}
};

export const onMasterPasswordSave = (masterPasswordInput: string) => {
Expand Down Expand Up @@ -141,6 +148,11 @@ export const useInputPasswords = (propsPasswords: Record<string, string>) => {

export const usePasswordChecker = (masterKeys: MasterKeyEntity[], activeMasterKeyId: string, masterPassword: string, passwords: Record<string, string>) => {
const [passwordChecks, setPasswordChecks] = useState<PasswordChecks>({});

// "masterPasswordKeys" are the master key that can be decrypted with the
// master password. It should be all of them normally, but in previous
// versions it was possible to have different passwords for different keys,
// so we need this for backward compatibility.
const [masterPasswordKeys, setMasterPasswordKeys] = useState<PasswordChecks>({});
const [masterPasswordStatus, setMasterPasswordStatus] = useState<MasterPasswordStatus>(MasterPasswordStatus.Unknown);

Expand All @@ -167,7 +179,6 @@ export const usePasswordChecker = (masterKeys: MasterKeyEntity[], activeMasterKe

setMasterPasswordKeys(masterPasswordKeys => {
if (JSON.stringify(newMasterPasswordKeys) === JSON.stringify(masterPasswordKeys)) return masterPasswordKeys;
console.info('====', JSON.stringify(newMasterPasswordKeys), JSON.stringify(masterPasswordKeys));
return newMasterPasswordKeys;
});

Expand Down

0 comments on commit 1406d97

Please sign in to comment.