SHA256
Исправить подпись сигналов звонка и ширину чата
This commit is contained in:
@@ -1314,7 +1314,7 @@ export class AuthService {
|
||||
const cleanLogin = (login || '').trim();
|
||||
if (!cleanLogin) throw new Error('Нет login для авто-входа');
|
||||
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin);
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin, targetSessionId);
|
||||
if (!sessionMaterial?.sessionId || !sessionMaterial?.sessionKey || !sessionMaterial?.sessionPrivPkcs8) {
|
||||
throw new Error('На устройстве нет сохраненного ключа сессии');
|
||||
}
|
||||
@@ -1400,7 +1400,7 @@ export class AuthService {
|
||||
includeClientSignature = true,
|
||||
timeMs = Date.now(),
|
||||
} = {}) {
|
||||
const cleanToLogin = String(toLogin || '').trim();
|
||||
const requestedToLogin = String(toLogin || '').trim();
|
||||
const cleanTargetMode = String(targetMode || '').trim();
|
||||
const cleanTargetSessionId = String(targetSessionId || '').trim();
|
||||
const cleanSignalType = String(signalType || '').trim();
|
||||
@@ -1408,7 +1408,7 @@ export class AuthService {
|
||||
const cleanLogin = String(this.currentLogin || '').trim();
|
||||
const cleanSessionId = String(this.currentSessionId || '').trim();
|
||||
if (!cleanLogin || !cleanSessionId) throw new Error('SendSignal: нет активного login/sessionId');
|
||||
if (!cleanToLogin || !cleanSignalType || !cleanSignalRequestId) {
|
||||
if (!requestedToLogin || !cleanSignalType || !cleanSignalRequestId) {
|
||||
throw new Error('SendSignal: не переданы toLogin/signalType/signalRequestId');
|
||||
}
|
||||
if (cleanTargetMode !== SIGNAL_TARGET_SINGLE && cleanTargetMode !== SIGNAL_TARGET_ALL) {
|
||||
@@ -1418,12 +1418,17 @@ export class AuthService {
|
||||
throw new Error('SendSignal: targetSessionId обязателен для single_session');
|
||||
}
|
||||
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin);
|
||||
if (!sessionMaterial?.sessionPrivPkcs8) {
|
||||
throw new Error('На устройстве нет сохранённого session key для SendSignal');
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin, cleanSessionId);
|
||||
if (!sessionMaterial?.sessionPrivPkcs8 || String(sessionMaterial.sessionId || '').trim() !== cleanSessionId) {
|
||||
throw new Error('SendSignal: ключ активной сессии не найден; выполните вход заново');
|
||||
}
|
||||
const sessionPrivateKey = await importPkcs8Ed25519(sessionMaterial.sessionPrivPkcs8);
|
||||
|
||||
// Сервер заменяет login адресата на каноническое значение из user registry
|
||||
// до проверки подписи. Подписываем то же значение, а не вариант из UI.
|
||||
const cleanToLogin = await this.resolveCanonicalDisplayLogin(requestedToLogin);
|
||||
if (!cleanToLogin) throw new Error('SendSignal: не удалось определить канонический login адресата');
|
||||
|
||||
const dataText = typeof data === 'string' ? data : JSON.stringify(data || {});
|
||||
const dataSha256B64 = await sha256Base64FromText(dataText);
|
||||
|
||||
|
||||
@@ -2620,6 +2620,10 @@ export async function startOutgoingCall(peerLogin, options = {}) {
|
||||
scheduleOutgoingAckTimeout(call);
|
||||
} catch (error) {
|
||||
recordCallTimeline(call, 'invite_broadcast_failed', toErrorText(error), 'warn');
|
||||
if (String(error?.code || '').toUpperCase() === 'NO_TARGET_SESSIONS') {
|
||||
await finalizeCall(call, { localReasonCode: 'no_answer', debugReason: 'invite_failed:peer_offline' });
|
||||
throw new Error(t('remaining.call.user_is_offline'));
|
||||
}
|
||||
const text = String(error?.message || '').toUpperCase();
|
||||
const isNotAuth = text.includes('NOT_AUTHENTICATED');
|
||||
if (isNotAuth) {
|
||||
|
||||
@@ -138,7 +138,7 @@ async function createUploadContext({ login, sessionId, wsUrl }) {
|
||||
const cleanLogin = String(login || '').trim();
|
||||
const cleanSessionId = String(sessionId || '').trim();
|
||||
if (!cleanLogin || !cleanSessionId) throw new Error('Нет активной пользовательской сессии');
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin);
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin, cleanSessionId);
|
||||
if (!sessionMaterial?.sessionPrivPkcs8) {
|
||||
throw new Error('На устройстве нет сохранённого session key для загрузки файла');
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ async function getBackgroundPreview(payload, session, signal, onRealtimeEvent, t
|
||||
// Never send a session signature to an unencrypted endpoint in production.
|
||||
if (url.protocol !== 'wss:' || url.username || url.password) { trace('unsafe_endpoint'); return ''; }
|
||||
trace('session_material_load');
|
||||
const material = await loadSessionMaterial(session.login);
|
||||
const material = await loadSessionMaterial(session.login, session.sessionId);
|
||||
if (material?.sessionId !== session.sessionId || !material?.sessionKey || !material?.sessionPrivPkcs8) { trace('session_material_missing'); return ''; }
|
||||
trace('session_material_ready');
|
||||
const privateKey = await importPkcs8Ed25519(material.sessionPrivPkcs8);
|
||||
|
||||
@@ -5,9 +5,10 @@ import {
|
||||
} from './crypto-utils.js';
|
||||
|
||||
const DB_NAME = 'shine-ui-auth';
|
||||
const DB_VERSION = 1;
|
||||
const DB_VERSION = 2;
|
||||
const STORE_SECRETS = 'encrypted-secrets';
|
||||
const STORE_SESSIONS = 'session-keys';
|
||||
const STORE_SESSIONS_V2 = 'session-keys-by-id';
|
||||
const FALLBACK_SECRETS_KEY = 'shine-ui-auth-secrets-fallback-v1';
|
||||
const FALLBACK_SESSIONS_KEY = 'shine-ui-auth-sessions-fallback-v1';
|
||||
|
||||
@@ -22,6 +23,11 @@ function normalizeLoginStorageKey(login) {
|
||||
return String(login || '').trim().toLowerCase();
|
||||
}
|
||||
|
||||
function normalizeSessionStorageKey(login, sessionId) {
|
||||
const cleanSessionId = String(sessionId || '').trim();
|
||||
return cleanSessionId ? `${normalizeLoginStorageKey(login)}\n${cleanSessionId}` : '';
|
||||
}
|
||||
|
||||
function readFallbackRow(storageKey, login) {
|
||||
try {
|
||||
if (typeof localStorage === 'undefined') return null;
|
||||
@@ -67,6 +73,9 @@ function openDb() {
|
||||
if (!db.objectStoreNames.contains(STORE_SESSIONS)) {
|
||||
db.createObjectStore(STORE_SESSIONS, { keyPath: 'login' });
|
||||
}
|
||||
if (!db.objectStoreNames.contains(STORE_SESSIONS_V2)) {
|
||||
db.createObjectStore(STORE_SESSIONS_V2, { keyPath: 'key' });
|
||||
}
|
||||
};
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error || new Error(t('remaining.key_storage.indexeddb_is_unavailable')));
|
||||
@@ -161,21 +170,51 @@ export async function updateEncryptedUserSecrets(login, storagePwd, updater) {
|
||||
|
||||
export async function saveSessionMaterial(login, material) {
|
||||
const normalizedLogin = normalizeLoginStorageKey(login);
|
||||
const sessionId = String(material?.sessionId || '').trim();
|
||||
if (!sessionId) throw new Error('Нельзя сохранить session material без sessionId');
|
||||
const row = {
|
||||
login: normalizedLogin,
|
||||
...material,
|
||||
sessionId,
|
||||
updatedAtMs: Date.now(),
|
||||
};
|
||||
const sessionKey = normalizeSessionStorageKey(normalizedLogin, sessionId);
|
||||
const indexedRow = { ...row, key: sessionKey };
|
||||
memorySessions.set(sessionKey, row);
|
||||
memorySessions.set(normalizedLogin, row);
|
||||
try {
|
||||
await put(STORE_SESSIONS, row);
|
||||
// Старая запись нужна только чтобы resumeSession(login) мог выбрать
|
||||
// последнюю сессию без sessionId. Подписывающий код всегда берёт V2 по id.
|
||||
await Promise.all([
|
||||
put(STORE_SESSIONS_V2, indexedRow),
|
||||
put(STORE_SESSIONS, row),
|
||||
]);
|
||||
} catch {
|
||||
writeFallbackRow(FALLBACK_SESSIONS_KEY, sessionKey, row);
|
||||
writeFallbackRow(FALLBACK_SESSIONS_KEY, normalizedLogin, row);
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadSessionMaterial(login) {
|
||||
export async function loadSessionMaterial(login, sessionId = '') {
|
||||
const normalizedLogin = normalizeLoginStorageKey(login);
|
||||
const cleanSessionId = String(sessionId || '').trim();
|
||||
const sessionKey = normalizeSessionStorageKey(normalizedLogin, cleanSessionId);
|
||||
if (sessionKey) {
|
||||
let row = null;
|
||||
try { row = await get(STORE_SESSIONS_V2, sessionKey); } catch {}
|
||||
row = row || memorySessions.get(sessionKey) || readFallbackRow(FALLBACK_SESSIONS_KEY, sessionKey);
|
||||
if (row) return row;
|
||||
|
||||
// Совместимость с единственной записью старых версий: использовать её
|
||||
// можно только для того же sessionId, чтобы не подписать запрос чужим ключом.
|
||||
let legacyRow = null;
|
||||
try { legacyRow = await get(STORE_SESSIONS, normalizedLogin); } catch {}
|
||||
legacyRow = legacyRow || readFallbackRow(FALLBACK_SESSIONS_KEY, normalizedLogin);
|
||||
return String(legacyRow?.sessionId || '').trim() === cleanSessionId ? legacyRow : null;
|
||||
}
|
||||
|
||||
// Вызовы без sessionId оставлены только для выбора единственной старой
|
||||
// сессии при авто-входе. Подписи всегда должны передавать sessionId.
|
||||
let row = null;
|
||||
try { row = await get(STORE_SESSIONS, normalizedLogin); } catch {}
|
||||
row = row || memorySessions.get(normalizedLogin) || readFallbackRow(FALLBACK_SESSIONS_KEY, normalizedLogin);
|
||||
|
||||
@@ -62,7 +62,7 @@ async function createUploadContext({ login, sessionId, wsUrl }) {
|
||||
const cleanLogin = String(login || '').trim();
|
||||
const cleanSessionId = String(sessionId || '').trim();
|
||||
if (!cleanLogin || !cleanSessionId) throw new Error(t('remaining.file_errors.no_active_user_session'));
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin);
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin, cleanSessionId);
|
||||
if (!sessionMaterial?.sessionPrivPkcs8) {
|
||||
throw new Error(t('remaining.file_errors.session_key_for_uploading_files_is_missing_on_this_dev'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user