Skip to content

Sam/duress regress #663

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 2 commits into from
May 29, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- changed: Allow for duress mode setup while in duress mode but only for non-duress accounts.
- fixed: Fixed regression causing pin disabled for other accounts when disabling PIN login within a duress account

## 2.30.0 (2025-05-26)

- added: A `transactionsRemoved` event on `EdgeCurrencyWallet`.
Expand Down
3 changes: 2 additions & 1 deletion src/core/account/account-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ export function makeAccountApi(ai: ApiInput, accountId: string): EdgeAccount {
: activeAppId + '.duress'
// Ensure the duress account exists:
if (forDuressAccount) {
if (ai.props.state.clientInfo.duressEnabled) {
// Fake duress mode setup if this is a duress account:
if (this.isDuressAccount) {
fakeDuressModeSetup = opts.enableLogin ?? opts.pin != null
ai.props.dispatch({ type: 'UPDATE_NEXT' })
return ''
Expand Down
6 changes: 1 addition & 5 deletions src/core/context/client-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export const CLIENT_FILE_NAME = 'client.json'
export interface ClientInfo {
clientId: Uint8Array
/**
* LoginId of the account which is under duress and is being impersonated
* by the duress account. It should be the loginId which the duress account
* is nested under..
* This is only set if duress mode is activated via pin-login with the
* duress account's pin.
* This is a boolean flag that puts the device into duress mode.
*/
duressEnabled: boolean
}
Expand Down
16 changes: 11 additions & 5 deletions src/core/login/login-reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { base58 } from '../../util/encoding'
import { RootAction } from '../actions'
import { RootState } from '../root-reducer'
import { searchTree } from './login'
import { LoginStash } from './login-stash'
import { findDuressStash, LoginStash } from './login-stash'
import { WalletInfoFullMap } from './login-types'
import { findPin2Stash, findPin2StashDuress } from './pin2'
import { findPin2Stash } from './pin2'

export interface LoginState {
readonly apiKey: string
Expand Down Expand Up @@ -54,14 +54,20 @@ export const login = buildReducer<LoginState, RootAction, RootState>({
// This allows us to lie about PIN being enabled or disabled while in
// duress mode!
const pin2Stash = clientInfo.duressEnabled
? findPin2StashDuress(stashTree, appId)
: findPin2Stash(stashTree, appId)
? // Use the duress stash's PIN settings, but fallback for accounts
// that don't have duress mode setup
findDuressStash(stashTree, appId) ?? findPin2Stash(stashTree, appId)
: // If we're not in duress mode, then do a normal search
findPin2Stash(stashTree, appId)
// If we have found a pin2Stash, or the duress stash we found has
// a pin2Key defined:
const pinLoginEnabled = pin2Stash?.pin2Key != null

return {
keyLoginEnabled,
lastLogin,
loginId: base58.stringify(loginId),
pinLoginEnabled: pin2Stash != null,
pinLoginEnabled,
recovery2Key:
recovery2Key != null ? base58.stringify(recovery2Key) : undefined,
username,
Expand Down
15 changes: 15 additions & 0 deletions src/core/login/login-stash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { EdgeLog, EdgePendingVoucher } from '../../types/types'
import { verifyData } from '../../util/crypto/verify'
import { base58 } from '../../util/encoding'
import { ApiInput } from '../root-pixie'
import { searchTree } from './login'

/**
* The login data we store on disk.
Expand Down Expand Up @@ -195,3 +196,17 @@ export const asLoginStash: Cleaner<LoginStash> = asObject({
})

export const wasLoginStash = uncleaner(asLoginStash)

/**
* Returns the duress stash nested within a given LoginStash tree.
* This will return the duress stash even if the stashTree is the duress stash
* itself.
*/
export function findDuressStash(
stashTree: LoginStash,
appId: string
): LoginStash | undefined {
const duressAppId = appId.endsWith('.duress') ? appId : appId + '.duress'
if (stashTree.appId === duressAppId) return stashTree
return searchTree(stashTree, stash => stash.appId === duressAppId)
}
19 changes: 2 additions & 17 deletions src/core/login/pin2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { ApiInput } from '../root-pixie'
import { applyKits, searchTree, serverLogin } from './login'
import { loginFetch } from './login-fetch'
import { getStashById } from './login-selectors'
import { LoginStash } from './login-stash'
import { findDuressStash, LoginStash } from './login-stash'
import { LoginKit, LoginTree, SessionKey } from './login-types'
import { getLoginOtp } from './otp'

Expand Down Expand Up @@ -43,21 +43,6 @@ export function findPin2Stash(
if (stash?.pin2Key != null) return stash
}

/**
* Returns a copy of the PIN login key if one exists on the local device and
* the app id matches the duress appId.
*/
export function findPin2StashDuress(
stashTree: LoginStash,
appId: string
): LoginStash | undefined {
const duressAppId = appId.endsWith('.duress') ? appId : appId + '.duress'
if (stashTree.pin2Key != null && duressAppId === stashTree.appId)
return stashTree
const stash = searchTree(stashTree, stash => stash.appId === duressAppId)
if (stash?.pin2Key != null) return stash
}

/**
* Logs a user in using their PIN.
* @return A `Promise` for the new root login.
Expand Down Expand Up @@ -190,7 +175,7 @@ export async function checkPin2(
const { stashTree } = getStashById(ai, loginId)
const stash =
forDuressAccount === true
? findPin2StashDuress(stashTree, appId)
? findDuressStash(stashTree, appId)
: findPin2Stash(stashTree, appId)
if (stash == null || stash.pin2Key == null) {
throw new PinDisabledError('No PIN set locally for this account')
Expand Down
Loading
Loading