Skip to content

Sam/duress biometric #651

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 8, 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 @@ -9,6 +9,7 @@
- fixed: Made `changePassword` a no-op for duress accounts
- fixed: Made `enableOtp`/`disableOtp` a no-op for duress accounts.
- fixed: Spoof `changeRecovery` for duress account.
- fixed: Support duress mode when logging in with `loginWithKey` (biometric login).
- fixed: Unintentional pin timeouts caused by duress mode pin-logins.

## 2.27.1 (2025-04-30)
Expand Down
40 changes: 33 additions & 7 deletions src/core/context/context-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
opts: EdgeAccountOptions & { useLoginId?: boolean } = {}
): Promise<EdgeAccount> {
const { now = new Date(), useLoginId = false } = opts
const inDuressMode = ai.props.state.clientInfo.duressEnabled

const stashTree = useLoginId
? getStashById(ai, base58.parse(usernameOrLoginId)).stashTree
Expand All @@ -148,13 +149,35 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
if (appStash == null) {
throw new Error(`Cannot find requested appId: "${appId}"`)
}
const sessionKey: SessionKey = {
loginId: appStash.loginId,
loginKey: base58.parse(loginKey)
}

// Verify that the provided key works for decryption:
makeAuthJson(stashTree, sessionKey)
let sessionKey: SessionKey
try {
sessionKey = {
loginId: appStash.loginId,
loginKey: base58.parse(loginKey)
}

// Verify that the provided key works for decryption:
makeAuthJson(stashTree, sessionKey)
} catch (error) {
if (error instanceof Error && error.message === 'Invalid checksum') {
const duressStash = searchTree(stashTree, stash =>
stash.appId.endsWith('.duress')
)
if (duressStash == null) {
throw error
}
sessionKey = {
loginId: duressStash.loginId,
loginKey: base58.parse(loginKey)
}

// Verify that the provided key works for decryption:
makeAuthJson(stashTree, sessionKey)
} else {
throw error
}
}

// Save the date:
stashTree.lastLogin = now
Expand All @@ -163,7 +186,10 @@ export function makeContextApi(ai: ApiInput): EdgeContext {
// Since we logged in offline, update the stash in the background:
syncLogin(ai, sessionKey).catch(error => ai.props.onError(error))

return await makeAccount(ai, sessionKey, 'keyLogin', opts)
return await makeAccount(ai, sessionKey, 'keyLogin', {
...opts,
duressMode: inDuressMode
})
},

async loginWithPassword(
Expand Down
24 changes: 24 additions & 0 deletions test/core/login/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,30 @@ describe('duress', function () {
expect(topicAccount.isDuressAccount).equals(true)
})

it('persist duress mode when using loginWithKey', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
const account = await context.loginWithPIN(fakeUser.username, fakeUser.pin)
const loginKey = await account.getLoginKey()
await account.changePin({ pin: '0000', forDuressAccount: true })
const duressAccount = await context.loginWithPIN(fakeUser.username, '0000')

// Login to the main account using the loginKey:
const topicAccount = await context.loginWithKey(fakeUser.username, loginKey)
expect(topicAccount.isDuressAccount).equals(true)

// Get the loginKey for the duress account:
const duressLoginKey = await duressAccount.getLoginKey()
expect(duressLoginKey).not.equals(loginKey)

// Login to the duress account using the duressLoginKey:
const topicAccount2 = await context.loginWithKey(
fakeUser.username,
duressLoginKey
)
expect(topicAccount2.isDuressAccount).equals(true)
})

it('check password', async function () {
const world = await makeFakeEdgeWorld([fakeUser], quiet)
const context = await world.makeEdgeContext(contextOptions)
Expand Down
Loading