Skip to content

Allow pin change while in duress mode for non-duress account #665

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
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: Allow pin change while device is in duress mode and user is logged into a non-duress account.

## 2.30.2 (2025-05-30)

- fixed: Create a package.json React Native export.
Expand Down
8 changes: 4 additions & 4 deletions src/core/login/pin2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function changePin(
opts: ChangePinOptions
): Promise<void> {
const accountState = ai.props.state.accounts[accountId]
const inDuressMode = ai.props.state.clientInfo.duressEnabled
const isDuressAccount = accountState.activeAppId.endsWith('.duress')
const { loginTree, login, sessionKey } = accountState
const { username } = accountState.stashTree

Expand All @@ -95,7 +95,7 @@ export async function changePin(

// Deleting PIN logins while in duress account should delete PIN locally for
// all nodes:
if (inDuressMode && !forDuressAccount) {
if (isDuressAccount && !forDuressAccount) {
if (enableLogin) {
if (pin != null) {
await applyKits(
Expand Down Expand Up @@ -128,7 +128,7 @@ export async function changePin(
await applyKits(
ai,
sessionKey,
makeDeletePin2Kits(loginTree, forDuressAccount || inDuressMode)
makeDeletePin2Kits(loginTree, forDuressAccount || isDuressAccount)
)
return
}
Expand All @@ -139,7 +139,7 @@ export async function changePin(
username,
pin,
enableLogin,
forDuressAccount || inDuressMode
forDuressAccount || isDuressAccount
)
await applyKits(ai, sessionKey, kits)
}
Expand Down
25 changes: 25 additions & 0 deletions test/core/login/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,31 @@ describe('pin', function () {
})
})

it('can change pin while device is in duress-mode', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
await (
await context.createAccount({
username: 'other-account',
pin: '1111'
})
).logout()

const account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
await account.changePin({ pin: '0000', forDuressAccount: true })
await account.logout()

// Enable duress mode:
const duressAccount = await context.loginWithPIN(fakeUser.username, '0000')
await duressAccount.logout()

const otherAccount = await context.loginWithPIN('other-account', '1111')
await otherAccount.changePin({ pin: '1234' })
await otherAccount.logout()

await context.loginWithPIN('other-account', '1234')
})

it('pin-login remains enabled for accounts without duress mode setup after duress mode login', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
Expand Down
Loading