This repository was archived by the owner on Jul 6, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Implement SNMfaService #392
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b061286
feat: Implement SNMfaService
gorjan5sk 4b5b304
test: fix settings test
gorjan5sk 9a07217
feat: adapt settings update for sensitive settings
gorjan5sk b16ce76
test: fix extension key tests
gorjan5sk 960fcce
fix: detach test container
gorjan5sk 7228167
test: fix features test
gorjan5sk be08c3d
fix: keep comment for Invalid session response
gorjan5sk f869279
fix: mfa_service call super.deinit()
gorjan5sk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { SettingName } from '@standardnotes/settings'; | ||
|
|
||
| import { SNSettingsService } from './settings_service'; | ||
| import { PureService } from './pure_service'; | ||
| import * as messages from './api/messages'; | ||
| import { SNPureCrypto } from '@standardnotes/sncrypto-common'; | ||
|
|
||
| export class SNMfaService extends PureService { | ||
| constructor( | ||
| private settingsService: SNSettingsService, | ||
| private crypto: SNPureCrypto | ||
| ) { | ||
| super(); | ||
| } | ||
|
|
||
| private async saveMfaSetting(secret: string): Promise<void> { | ||
| return await this.settingsService.updateSetting( | ||
| SettingName.MfaSecret, | ||
| secret, | ||
| true | ||
| ); | ||
| } | ||
|
|
||
| async isMfaActivated() { | ||
| const mfaSetting = await this.settingsService.getSensitiveSetting( | ||
| SettingName.MfaSecret | ||
| ); | ||
| return mfaSetting != null && mfaSetting != false; | ||
| } | ||
|
|
||
| async generateMfaSecret() { | ||
| return this.crypto.generateOtpSecret(); | ||
| } | ||
|
|
||
| async getOtpToken(secret: string) { | ||
| return this.crypto.totpToken(secret, Date.now(), 6, 30); | ||
| } | ||
|
|
||
| async enableMfa(secret: string, otpToken: string) { | ||
| const otpTokenValid = | ||
| otpToken != null && otpToken === (await this.getOtpToken(secret)); | ||
| if (!otpTokenValid) throw new Error(messages.SignInStrings.IncorrectMfa); | ||
|
|
||
| return this.saveMfaSetting(secret); | ||
| } | ||
|
|
||
| async disableMfa(): Promise<void> { | ||
| return await this.settingsService.deleteSetting(SettingName.MfaSecret); | ||
| } | ||
|
|
||
| deinit() { | ||
| (this.settingsService as unknown) = undefined; | ||
| (this.crypto as unknown) = undefined; | ||
| super.deinit(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/snjs/lib/services/settings_service/SensitiveSettingName.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import { SettingName } from '@standardnotes/settings'; | ||
|
|
||
| export type SensitiveSettingName = | ||
| | SettingName.MfaSecret | ||
| | SettingName.ExtensionKey; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.