Skip to content
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

Refactor key backup recovery to prepare for rust #3708

Merged
merged 5 commits into from
Sep 12, 2023

Conversation

BillCarsonFr
Copy link
Member

@BillCarsonFr BillCarsonFr commented Sep 6, 2023

Introduce a new BackupDecryptor interface, which we can implement separately for legacy and Rust crypto.

Checklist

  • Tests written for new code (and old code if feasible)
  • Linter and other CI checks pass
  • Sign-off given on the changes (see CONTRIBUTING.md)

This change is marked as an internal change (Task), so will not be included in the changelog.

@BillCarsonFr BillCarsonFr added the T-Task Tasks for the team like planning label Sep 6, 2023
@BillCarsonFr BillCarsonFr force-pushed the valere/element-r/backup/restore/pr1 branch from 4e78cf3 to 4c4ab28 Compare September 6, 2023 22:19
richvdh
richvdh previously requested changes Sep 7, 2023
src/common-crypto/CryptoBackend.ts Outdated Show resolved Hide resolved
src/common-crypto/CryptoBackend.ts Outdated Show resolved Hide resolved
src/common-crypto/CryptoBackend.ts Outdated Show resolved Hide resolved
src/common-crypto/CryptoBackend.ts Outdated Show resolved Hide resolved
src/common-crypto/CryptoBackend.ts Outdated Show resolved Hide resolved
spec/test-utils/test-data/index.ts Show resolved Hide resolved
spec/test-utils/test-data/generate-test-data.py Outdated Show resolved Hide resolved
spec/test-utils/test-data/generate-test-data.py Outdated Show resolved Hide resolved
spec/integ/crypto/megolm-backup.spec.ts Show resolved Hide resolved
Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, very minor questions and comments.

src/client.ts Outdated
const algorithm = await BackupManager.makeAlgorithm(backupInfo, async () => {
return privKey;
});
const backupDecryptor = await this.cryptoBackend!.getBackupDecryptor(backupInfo, privKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do we know that this.cryptoBackend is defined? Can we have a comment explaining?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, I see it on line 3786. In that case, I think we shouldn't need the !? If we do, please add a little comment saying that we bailed out earlier if we had no cryptoBackend

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx, removed

public async getBackupDecryptor(backupInfo: IKeyBackupInfo, privKey: ArrayLike<number>): Promise<BackupDecryptor> {
if (!(privKey instanceof Uint8Array)) {
// eslint-disable-next-line @typescript-eslint/no-base-to-string
throw new Error(`getBackupDecryptor expects Uint8Array, got ${privKey}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it potentially dangerous to log the private key here? Maybe we could log its type, or omit it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(would also mean we could remove the eslint-disable...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, was copied from old code but agree that it doesn't look right. Removed

Copy link
Member

@andybalaam andybalaam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good, thanks!

@BillCarsonFr BillCarsonFr added this pull request to the merge queue Sep 12, 2023
Merged via the queue into develop with commit c7827d9 Sep 12, 2023
20 checks passed
@BillCarsonFr BillCarsonFr deleted the valere/element-r/backup/restore/pr1 branch September 12, 2023 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-Task Tasks for the team like planning
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants