bug(settings): Use correct current key stretch version for signin unblock

Because:
- We were always using v1 ks
- This won't work for an account that has been upgraded to v2 ks

This Commit:
- Gets client salt and current ks version for account
- Fixes bug in gql. The version field should have been called currentVersion.
This commit is contained in:
dschom 2024-06-06 12:28:57 -07:00
Родитель 2765219735
Коммит f510a8593c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: F26AEE99174EE68B
4 изменённых файлов: 24 добавлений и 7 удалений

Просмотреть файл

@ -16,7 +16,7 @@ export class CredentialStatusPayload {
description: 'The current version of the credentials.',
nullable: true,
})
public version?: string;
public currentVersion?: string;
@Field({
description:

Просмотреть файл

@ -17,8 +17,8 @@ import {
} from '../../../models';
// using default signin handlers
import { BEGIN_SIGNIN_MUTATION } from '../gql';
import { BeginSigninResponse } from '../interfaces';
import { BEGIN_SIGNIN_MUTATION, CREDENTIAL_STATUS_MUTATION } from '../gql';
import { BeginSigninResponse, CredentialStatusResponse } from '../interfaces';
import SigninUnblock from '.';
import {
@ -36,7 +36,7 @@ import {
getHandledError,
getLocalizedErrorMessage,
} from '../../../lib/error-utils';
import { getCredentials } from 'fxa-auth-client/lib/crypto';
import { getCredentials, getCredentialsV2 } from 'fxa-auth-client/lib/crypto';
import { AuthUiErrors } from '../../../lib/auth-errors/auth-errors';
import { SignInOptions } from 'fxa-auth-client/browser';
@ -70,6 +70,9 @@ const SigninUnblockContainer = ({
);
const [beginSignin] = useMutation<BeginSigninResponse>(BEGIN_SIGNIN_MUTATION);
const [credentialStatus] = useMutation<CredentialStatusResponse>(
CREDENTIAL_STATUS_MUTATION
);
const signinWithUnblockCode: BeginSigninWithUnblockCodeHandler = async (
unblockCode: string,
@ -87,7 +90,21 @@ const SigninUnblockContainer = ({
),
};
const credentials = await getCredentials(authEmail, password!);
// Get credentials with the correct key version
const credentials = await (async () => {
const { data } = await credentialStatus({
variables: {
input: email,
},
});
const currentVersion = data?.credentialStatus.currentVersion;
if (currentVersion === 'v2') {
const clientSalt = data?.credentialStatus.clientSalt || '';
return await getCredentialsV2({ password, clientSalt });
}
return await getCredentials(authEmail, password);
})();
try {
return await beginSignin({
variables: {

Просмотреть файл

@ -65,7 +65,7 @@ export const CREDENTIAL_STATUS_MUTATION = gql`
mutation CredentialStatus($input: String!) {
credentialStatus(input: $input) {
upgradeNeeded
version
currentVersion
clientSalt
}
}

Просмотреть файл

@ -106,7 +106,7 @@ export interface SigninFormData {
export interface CredentialStatusResponse {
credentialStatus: {
upgradeNeeded: boolean;
version?: string;
currentVersion?: string;
clientSalt?: string;
};
}