Skip to content

Sam/duress duress #660

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 22, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- fixed: Disabling pin-login while in duress mode disables pin-login for the main login.
- fixed: `loginWithPassword` bug disabled duress mode when doing an online login.
- fixed: Properly fake duress mode settings while in duress mode.

## 2.27.4 (2025-05-13)

Expand Down
11 changes: 11 additions & 0 deletions src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
}
}

// This is used to fake duress mode settings while in duress mode:
let fakeDuressModeSetup = false

const out: EdgeAccount = {
on: onMethod,
watch: watchMethod,
Expand Down Expand Up @@ -188,6 +191,9 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {

get canDuressLogin(): boolean {
const { activeAppId } = accountState()
if (ai.props.state.clientInfo.duressEnabled) {
return fakeDuressModeSetup
}
const duressAppId = activeAppId.endsWith('.duress')
? activeAppId
: activeAppId + '.duress'
Expand Down Expand Up @@ -257,6 +263,11 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
: activeAppId + '.duress'
// Ensure the duress account exists:
if (forDuressAccount) {
if (ai.props.state.clientInfo.duressEnabled) {
fakeDuressModeSetup = opts.enableLogin ?? opts.pin != null
ai.props.dispatch({ type: 'UPDATE_NEXT' })
return ''
}
await ensureAccountExists(
ai,
accountState().stashTree,
Expand Down
21 changes: 21 additions & 0 deletions test/core/login/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,27 @@ describe('duress', function () {
expect(topicAccount.appId).equals('.duress')
})

it('fake duress mode settings while in duress mode', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
let account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
await account.changePin({ pin: '0000', forDuressAccount: true })
await account.logout()

let duressAccount = await context.loginWithPIN(fakeUser.username, '0000')
expect(duressAccount.canDuressLogin).equals(false)
await duressAccount.changePin({ forDuressAccount: true, enableLogin: true })
expect(duressAccount.canDuressLogin).equals(true)
await duressAccount.logout()

duressAccount = await context.loginWithPIN(fakeUser.username, '0000')
expect(duressAccount.canDuressLogin).equals(false)

// Doesn't impact main account:
account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
expect(account.canDuressLogin).equals(true)
})

it('Avoid creating duress account when using loginWithPassword', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
Expand Down
Loading