-
Notifications
You must be signed in to change notification settings - Fork 4
[PB-4737] feat(user): add public keys validation for account recovery #851
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1075,10 +1075,15 @@ export class UserUseCases { | |
| ecc: string; | ||
| kyber: string; | ||
| }; | ||
| publicKeys?: { | ||
| ecc?: string; | ||
| kyber?: string; | ||
| }; | ||
| }, | ||
| withReset = false, | ||
| ): Promise<void> { | ||
| const { mnemonic, password, salt, privateKeys } = newCredentials; | ||
| const { mnemonic, password, salt, privateKeys, publicKeys } = | ||
| newCredentials; | ||
|
|
||
| const shouldUpdateKeys = privateKeys && Object.keys(privateKeys).length > 0; | ||
|
|
||
|
|
@@ -1088,8 +1093,26 @@ export class UserUseCases { | |
| ); | ||
| } | ||
|
|
||
| if (!withReset && !publicKeys) { | ||
| throw new BadRequestException('Invalid keys'); | ||
| } | ||
|
|
||
| const user = await this.userRepository.findByUuid(userUuid); | ||
|
|
||
| if (publicKeys) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if withReset = true and mismatching public keys, then backup won't go through?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sg-gs Do we require/can send publicKeys for account reset? Becuase now we check public keys and if they fail we abort even if it's withReset=true |
||
| const existingKeys = await this.keyServerUseCases.getPublicKeys(user.id); | ||
| const eccMismatch = publicKeys.ecc && existingKeys.ecc !== publicKeys.ecc; | ||
|
||
| const kyberMismatch = | ||
| publicKeys.kyber && existingKeys.kyber !== publicKeys.kyber; | ||
|
||
|
|
||
| if (eccMismatch) { | ||
| throw new BadRequestException('Invalid ECC public key'); | ||
| } | ||
| if (kyberMismatch) { | ||
| throw new BadRequestException('Invalid Kyber public key'); | ||
| } | ||
| } | ||
|
|
||
| if (shouldUpdateKeys) { | ||
| for (const [version, privateKey] of Object.entries(privateKeys)) { | ||
| await this.keyServerUseCases.updateByUserAndEncryptVersion( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a line between this class and the next one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why in this class ecc and kyber are optional? Isn't it enough just to have optional public keys field in RecoverAccountDto? Because now we can have {ecc: undefined, kyber: underfined}, {ecc: , kyber: underfined}, {ecc: undefined, kyber: } and I don't think we should accept those as valid input