SHA256
Сделать DM body opaque для сервера и улучшить fallback UI
This commit is contained in:
@@ -239,6 +239,9 @@ const DM_MAX_ENCRYPTED_BODY_BYTES = 16384;
|
||||
const DM_CRYPTO_METHOD_X25519_HKDF_AES_GCM = 1;
|
||||
const DM_CRYPTO_VERSION_1_0 = 0;
|
||||
const DM_HKDF_INFO = utf8Bytes('SHiNE_DM|1|0|X25519+HKDF-SHA256+AES-256-GCM');
|
||||
const DM_DECRYPT_ERROR_UNSUPPORTED_FORMAT = 'unsupported_format';
|
||||
const DM_DECRYPT_ERROR_DECRYPT_FAILED = 'decrypt_failed';
|
||||
const DM_DECRYPT_ERROR_CORRUPTED = 'corrupted';
|
||||
|
||||
function ensureAsciiBytes(value, field, min = 1, max = 60) {
|
||||
const text = String(value || '').trim();
|
||||
@@ -330,6 +333,14 @@ function parseEncryptedDmBodyBytes(payloadBytes) {
|
||||
};
|
||||
}
|
||||
|
||||
function classifyDmDecryptFailure(error) {
|
||||
const code = String(error?.message || '').trim();
|
||||
if (code === 'BAD_ENCRYPTED_BODY') return DM_DECRYPT_ERROR_CORRUPTED;
|
||||
if (code === 'Неподдерживаемый метод шифрования DM') return DM_DECRYPT_ERROR_UNSUPPORTED_FORMAT;
|
||||
if (code === 'OperationError') return DM_DECRYPT_ERROR_DECRYPT_FAILED;
|
||||
return DM_DECRYPT_ERROR_DECRYPT_FAILED;
|
||||
}
|
||||
|
||||
function parseReadReceiptBodyBytes(payloadBytes) {
|
||||
if (!(payloadBytes instanceof Uint8Array)) throw new Error('BAD_RECEIPT_PAYLOAD_LEN');
|
||||
let o = 0;
|
||||
@@ -435,7 +446,6 @@ function parseSignedMessageBlockBytes(bytes) {
|
||||
let readReceiptPayload = null;
|
||||
if (messageType === DM_TYPE_INCOMING || messageType === DM_TYPE_OUTGOING_COPY) {
|
||||
if (bodyBytes.length === 0) throw new Error('BAD_MESSAGE_LEN');
|
||||
encryptedBodyPayload = parseEncryptedDmBodyBytes(bodyBytes);
|
||||
} else if (messageType === DM_TYPE_READ_INCOMING || messageType === DM_TYPE_READ_OUTGOING_COPY) {
|
||||
if (bodyBytes.length === 0) throw new Error('BAD_RECEIPT_PAYLOAD_LEN');
|
||||
if (revisionTimeMs !== 0 || reencryptedAtMs !== 0) throw new Error('BAD_RECEIPT_REVISION');
|
||||
@@ -2334,6 +2344,10 @@ export class AuthService {
|
||||
return parseReadReceiptBodyBytes(payloadBytes);
|
||||
}
|
||||
|
||||
classifyDmDecryptFailure(error) {
|
||||
return classifyDmDecryptFailure(error);
|
||||
}
|
||||
|
||||
async decryptSignedMessageContent({ parsed, blobB64 = '', login, storagePwd }) {
|
||||
const parsedBlock = parsed || this.parseSignedMessageBlob(blobB64);
|
||||
const messageType = Number(parsedBlock?.messageType || 0);
|
||||
|
||||
Reference in New Issue
Block a user