SHA256
Исправить восстановление входа при занятом WebSocket
This commit is contained in:
@@ -175,9 +175,15 @@ export function render({ navigate }) {
|
||||
retry.disabled = true;
|
||||
status.textContent = t('screens.registration_email_view.text_022');
|
||||
try {
|
||||
const result = await confirmFreeRegistration(draft.challengeId, code.value.trim());
|
||||
// Подтверждение email идемпотентно на уровне сценария: после первого
|
||||
// успешного ответа повторяем только финальный вход, а не AuthChallenge
|
||||
// регистрации. Иначе предыдущий CreateAuthSession мог оставить сокет
|
||||
// авторизованным, и сервер вернёт ALREADY_AUTHED.
|
||||
if (!draft.dataItemId) {
|
||||
const result = await confirmFreeRegistration(draft.challengeId, code.value.trim());
|
||||
draft.dataItemId = result.dataItemId;
|
||||
}
|
||||
if (!screen.isConnected || disposed) return;
|
||||
draft.dataItemId = result.dataItemId;
|
||||
status.textContent = t('screens.registration_email_view.text_023');
|
||||
await completeRegistrationLogin({ navigate, keyBundle: draft.preGeneratedKeyBundle });
|
||||
} catch (error) {
|
||||
|
||||
@@ -91,7 +91,9 @@ function clamp(value, min, max) {
|
||||
}
|
||||
|
||||
export async function completeRegistrationLogin({ navigate, keyBundle }) {
|
||||
await authService.reconnect(state.entrySettings.shineServer);
|
||||
// Финальный вход регистрации нельзя повторять на сокете, который мог
|
||||
// стать авторизованным после частично успешной предыдущей попытки.
|
||||
authService.resetConnection(state.entrySettings.shineServer, { clearSessionContext: true });
|
||||
const result = await authService.createSessionForExistingUser(
|
||||
state.registrationDraft.login,
|
||||
state.registrationDraft.password,
|
||||
|
||||
@@ -1151,13 +1151,33 @@ export class AuthService {
|
||||
const clientPair = keyBundle?.clientPair;
|
||||
if (!clientPair) throw new Error('createAuthSession: не передан clientPair');
|
||||
|
||||
// Новый вход всегда начинается на анонимном транспорте. Это важно после
|
||||
// частично успешной попытки: сервер хранит авторизацию в ConnectionContext
|
||||
// конкретного WebSocket, поэтому повторный AuthChallenge на нём получает
|
||||
// ALREADY_AUTHED даже для другого логина.
|
||||
if (this.ws.isSessionReady()) {
|
||||
this.resetConnection(this.serverUrl, { clearSessionContext: true });
|
||||
}
|
||||
|
||||
const sessionPair = await generateEd25519Pair();
|
||||
const sessionKeyPub = await exportEd25519PublicKeyB64(sessionPair.publicKey);
|
||||
const sessionKey = `ed25519/${sessionKeyPub}`;
|
||||
const storagePwd = randomBase64(32);
|
||||
|
||||
const challengeResp = await this.ws.request('AuthChallenge', { login: cleanLogin });
|
||||
if (challengeResp.status !== 200) throw opError('AuthChallenge', challengeResp);
|
||||
let challengeResp;
|
||||
for (let attempt = 0; attempt < 2; attempt += 1) {
|
||||
challengeResp = await this.ws.request('AuthChallenge', { login: cleanLogin });
|
||||
if (challengeResp.status === 200) break;
|
||||
|
||||
const error = opError('AuthChallenge', challengeResp);
|
||||
if (attempt === 0 && error.code === 'ALREADY_AUTHED') {
|
||||
// Сбрасываем только транспорт. Ключи и данные регистрации остаются
|
||||
// в памяти, после чего повторяем только challenge на новом сокете.
|
||||
this.resetConnection(this.serverUrl, { clearSessionContext: true });
|
||||
continue;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
const authNonce = challengeResp?.payload?.authNonce;
|
||||
if (!authNonce) throw new Error('AuthChallenge: сервер не вернул authNonce');
|
||||
|
||||
Reference in New Issue
Block a user