Skip to content

Fix bug confusing disable duress for disable pin-login #656

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 1 commit into from
May 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: Disable duress pin mistakenly disables pin-login for entire account.

## 2.27.3 (2025-05-12)

- fixed: Bug causing duress account creation from `loginWithKey` while in duress mode.
Expand Down
3 changes: 1 addition & 2 deletions src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
// For crash errors:
ai.props.log.breadcrumb('EdgeAccount.changePin', {})
// Check if we are in duress mode:
const inDuressMode = ai.props.state.clientInfo.duressEnabled
const { forDuressAccount = inDuressMode } = opts
const { forDuressAccount = false } = opts
const { activeAppId } = accountState()
const duressAppId = activeAppId.endsWith('.duress')
? activeAppId
Expand Down
16 changes: 5 additions & 11 deletions src/core/login/pin2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export async function changePin(
opts: ChangePinOptions
): Promise<void> {
const accountState = ai.props.state.accounts[accountId]
const inDuressMode = ai.props.state.clientInfo.duressEnabled
const { loginTree, login, sessionKey } = accountState
const { username } = accountState.stashTree

Expand All @@ -99,22 +100,15 @@ export async function changePin(

// Deleting PIN logins while in duress account should delete PIN locally for
// all nodes:
if (forDuressAccount && !enableLogin) {
if (inDuressMode && !forDuressAccount && !enableLogin) {
if (pin == null) {
await applyKitsTemporarily(ai, makeDeletePin2Kits(loginTree))
} else {
await applyKitsTemporarily(ai, [
// Delete for other apps:
...makeDeletePin2Kits(loginTree, false),
// Change PIN for duress app:
...makeChangePin2Kits(
ai,
loginTree,
username,
pin,
enableLogin,
forDuressAccount
)
...makeChangePin2Kits(ai, loginTree, username, pin, enableLogin, true)
])
}
return
Expand All @@ -131,7 +125,7 @@ export async function changePin(
await applyKits(
ai,
sessionKey,
makeDeletePin2Kits(loginTree, forDuressAccount)
makeDeletePin2Kits(loginTree, forDuressAccount || inDuressMode)
)
return
}
Expand All @@ -142,7 +136,7 @@ export async function changePin(
username,
pin,
enableLogin,
forDuressAccount
forDuressAccount || inDuressMode
)
await applyKits(ai, sessionKey, kits)
}
Expand Down
14 changes: 14 additions & 0 deletions test/core/login/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,20 @@ describe('pin', function () {
expect(successAccount.id).equals(duressAccount.id)
})

it('disable duress does not disable pin-login', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
expect(context.localUsers[0].pinLoginEnabled).equals(true)
// Setup duress mode:
const account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
await account.changePin({ pin: '0000', forDuressAccount: true })
// Disable duress mode:
await account.changePin({
enableLogin: false,
forDuressAccount: true
})
expect(context.localUsers[0].pinLoginEnabled).equals(true)
})
it('check', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
Expand Down
Loading