Skip to content

Commit

Permalink
add decryption of recived kyber keys
Browse files Browse the repository at this point in the history
  • Loading branch information
TamaraFinogina committed Jan 15, 2025
1 parent fd26a19 commit 8f78ea6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/app/auth/components/SignUp/WorkspaceGuestSignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,17 @@ function WorkspaceGuestSingUpView(): JSX.Element {
localStorageService.set('xNewToken', xNewToken);

const decryptedPrivateKey = decryptPrivateKey(xUser.privateKey, password);
const decryptedPrivateKyberKey = decryptPrivateKey(xUser.keys.kyber.privateKey, password);

const privateKey = xUser.privateKey ? Buffer.from(decryptedPrivateKey).toString('base64') : undefined;
const privateKyberKey = xUser.keys.kyber.privateKey
? Buffer.from(decryptedPrivateKyberKey).toString('base64')
: undefined;

const user = {
...xUser,
privateKey,
privateKyberKey,
} as UserSettings;

dispatch(userActions.setUser(user));
Expand Down
17 changes: 16 additions & 1 deletion src/app/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ export const doLogin = async (
.login(loginDetails, cryptoProvider)
.then(async (data) => {
const { user, token, newToken } = data;
const { privateKey, publicKey } = user;
const { privateKey, publicKey, keys } = user;
const publicKyberKey = keys.kyber.publicKey;
const privateKyberKey = keys.kyber.privateKey;

Sentry.setUser({
id: user.uuid,
Expand All @@ -172,11 +174,24 @@ export const doLogin = async (
);
}

const plainPrivateKyberKeyInBase64 = privateKyberKey
? Buffer.from(decryptPrivateKey(privateKyberKey, password)).toString('base64')
: '';

if (privateKey) {
await assertPrivateKeyIsValid(plainPrivateKyberKeyInBase64, password);
await assertValidateKeys(
Buffer.from(plainPrivateKyberKeyInBase64, 'base64').toString(),
Buffer.from(publicKyberKey, 'base64').toString(),
);
}

const clearMnemonic = decryptTextWithKey(user.mnemonic, password);
const clearUser = {
...user,
mnemonic: clearMnemonic,
privateKey: plainPrivateKeyInBase64,
privateKyberKey: plainPrivateKyberKeyInBase64,
};

localStorageService.set('xToken', token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,17 @@ function ShareGuestSingUpView(): JSX.Element {
localStorageService.set('xNewToken', xNewToken);

const decryptedPrivateKey = decryptPrivateKey(xUser.privateKey, password);
const decryptedPrivateKyberKey = decryptPrivateKey(xUser.keys.kyber.privateKey, password);

const privateKey = xUser.privateKey ? Buffer.from(decryptedPrivateKey).toString('base64') : undefined;
const privateKyberKey = xUser.keys.kyber.privateKey
? Buffer.from(decryptedPrivateKyberKey).toString('base64')
: undefined;

const user = {
...xUser,
privateKey,
privateKyberKey,
} as UserSettings;

dispatch(userActions.setUser(user));
Expand Down

0 comments on commit 8f78ea6

Please sign in to comment.