WIP
This commit is contained in:
parent
a547922e01
commit
ef0b07bb7a
|
@ -3,6 +3,7 @@
|
|||
|
||||
const functions = {
|
||||
arrayBufferToStringBase64,
|
||||
fromBase64ToArrayBuffer,
|
||||
};
|
||||
|
||||
onmessage = async e => {
|
||||
|
@ -36,3 +37,7 @@ function prepareErrorForPostMessage(error) {
|
|||
function arrayBufferToStringBase64(arrayBuffer) {
|
||||
return dcodeIO.ByteBuffer.wrap(arrayBuffer).toString('base64');
|
||||
}
|
||||
|
||||
function fromBase64ToArrayBuffer(value) {
|
||||
return dcodeIO.ByteBuffer.wrap(value, 'base64').toArrayBuffer();
|
||||
}
|
||||
|
|
|
@ -296,7 +296,6 @@ const utilWorkerPath = path.join(app.getAppPath(), 'js', 'util_worker.js');
|
|||
const utilWorker = new WorkerInterface(utilWorkerPath, 3 * 60 * 1000);
|
||||
|
||||
window.callWorker = (fnName, ...args) => utilWorker.callWorker(fnName, ...args);
|
||||
|
||||
// Linux seems to periodically let the event loop stop, so this is a global workaround
|
||||
setInterval(() => {
|
||||
window.nodeSetImmediate(() => {});
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
import { OpenGroupV2Request } from '../opengroup/opengroupV2/ApiUtil';
|
||||
import { sendApiV2Request } from '../opengroup/opengroupV2/OpenGroupAPIV2';
|
||||
import { parseStatusCodeFromOnionRequest } from '../opengroup/opengroupV2/OpenGroupAPIV2Parser';
|
||||
import { fromArrayBufferToBase64, fromBase64ToArrayBuffer } from '../session/utils/String';
|
||||
|
||||
// tslint:disable-next-line: no-http-string
|
||||
export const oldFileServerV2URL = 'http://88.99.175.227';
|
||||
|
@ -41,7 +40,7 @@ export const uploadFileToFsV2 = async (
|
|||
return null;
|
||||
}
|
||||
const queryParams = {
|
||||
file: fromArrayBufferToBase64(fileContent),
|
||||
file: await window.callWorker('arrayBufferToStringBase64', fileContent),
|
||||
};
|
||||
|
||||
const request: FileServerV2Request = {
|
||||
|
@ -110,7 +109,7 @@ export const downloadFileFromFSv2 = async (
|
|||
if (!base64Data) {
|
||||
return null;
|
||||
}
|
||||
return fromBase64ToArrayBuffer(base64Data);
|
||||
return window.callWorker('fromBase64ToArrayBuffer', base64Data);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -153,8 +153,11 @@ export async function requestNewAuthToken({
|
|||
window?.log?.warn('Parsing failed');
|
||||
return null;
|
||||
}
|
||||
const ciphertext = fromBase64ToArrayBuffer(base64EncodedCiphertext);
|
||||
const ephemeralPublicKey = fromBase64ToArrayBuffer(base64EncodedEphemeralPublicKey);
|
||||
const ciphertext = await window.callWorker('fromBase64ToArrayBuffer', base64EncodedCiphertext);
|
||||
const ephemeralPublicKey = await window.callWorker(
|
||||
'fromBase64ToArrayBuffer',
|
||||
base64EncodedEphemeralPublicKey
|
||||
);
|
||||
try {
|
||||
const symmetricKey = await window.libloki.crypto.deriveSymmetricKey(
|
||||
ephemeralPublicKey,
|
||||
|
|
|
@ -47,7 +47,7 @@ export const parseMessages = async (
|
|||
window?.log?.info('no new messages');
|
||||
return [];
|
||||
}
|
||||
const chunks = _.chunk(rawMessages, 10);
|
||||
const chunks = _.chunk(rawMessages, 1000);
|
||||
|
||||
const handleChunk = async (chunk: Array<Record<string, any>>) => {
|
||||
return Promise.all(
|
||||
|
@ -65,8 +65,14 @@ export const parseMessages = async (
|
|||
}
|
||||
// Validate the message signature
|
||||
const senderPubKey = PubKey.cast(opengroupv2Message.sender).withoutPrefix();
|
||||
const signature = fromBase64ToArrayBuffer(opengroupv2Message.base64EncodedSignature);
|
||||
const messageData = fromBase64ToArrayBuffer(opengroupv2Message.base64EncodedData);
|
||||
const signature = await window.callWorker(
|
||||
'fromBase64ToArrayBuffer',
|
||||
opengroupv2Message.base64EncodedSignature
|
||||
);
|
||||
const messageData = await window.callWorker(
|
||||
'fromBase64ToArrayBuffer',
|
||||
opengroupv2Message.base64EncodedData
|
||||
);
|
||||
// throws if signature failed
|
||||
await window.libsignal.Curve.async.verifySignature(
|
||||
fromHex(senderPubKey),
|
||||
|
|
|
@ -7,7 +7,6 @@ import {
|
|||
import { FSv2 } from '../../fileserver/';
|
||||
import { sendViaOnion } from '../../session/onions/onionSend';
|
||||
import { PubKey } from '../../session/types';
|
||||
import { fromArrayBufferToBase64, fromBase64ToArrayBuffer } from '../../session/utils/String';
|
||||
import { OpenGroupRequestCommonType, OpenGroupV2Info, OpenGroupV2Request } from './ApiUtil';
|
||||
import {
|
||||
parseMemberCount,
|
||||
|
@ -396,7 +395,7 @@ export const downloadFileOpenGroupV2 = async (
|
|||
if (!base64Data) {
|
||||
return null;
|
||||
}
|
||||
return new Uint8Array(fromBase64ToArrayBuffer(base64Data));
|
||||
return new Uint8Array(await window.callWorker('fromBase64ToArrayBuffer', base64Data));
|
||||
};
|
||||
|
||||
export const downloadFileOpenGroupV2ByUrl = async (
|
||||
|
@ -423,7 +422,7 @@ export const downloadFileOpenGroupV2ByUrl = async (
|
|||
if (!base64Data) {
|
||||
return null;
|
||||
}
|
||||
return new Uint8Array(fromBase64ToArrayBuffer(base64Data));
|
||||
return new Uint8Array(await window.callWorker('fromBase64ToArrayBuffer', base64Data));
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -469,7 +468,7 @@ export const uploadFileOpenGroupV2 = async (
|
|||
return null;
|
||||
}
|
||||
const queryParams = {
|
||||
file: fromArrayBufferToBase64(fileContent),
|
||||
file: await window.callWorker('arrayBufferToStringBase64', fileContent),
|
||||
};
|
||||
|
||||
const filesEndpoint = 'files';
|
||||
|
@ -509,7 +508,7 @@ export const uploadImageForRoomOpenGroupV2 = async (
|
|||
}
|
||||
|
||||
const queryParams = {
|
||||
file: fromArrayBufferToBase64(fileContent),
|
||||
file: await window.callWorker('arrayBufferToStringBase64', fileContent),
|
||||
};
|
||||
|
||||
const imageEndpoint = `rooms/${roomInfos.roomId}/image`;
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
import { getSodium } from '../../session/crypto';
|
||||
import { UserUtils } from '../../session/utils';
|
||||
import {
|
||||
fromArrayBufferToBase64,
|
||||
fromBase64ToArray,
|
||||
fromHex,
|
||||
fromHexToArray,
|
||||
toHex,
|
||||
} from '../../session/utils/String';
|
||||
import { fromBase64ToArray } from '../../session/utils/String';
|
||||
|
||||
export class OpenGroupMessageV2 {
|
||||
public serverId?: number;
|
||||
|
@ -77,7 +70,7 @@ export class OpenGroupMessageV2 {
|
|||
return new OpenGroupMessageV2({
|
||||
base64EncodedData: this.base64EncodedData,
|
||||
sentTimestamp: this.sentTimestamp,
|
||||
base64EncodedSignature: fromArrayBufferToBase64(signature),
|
||||
base64EncodedSignature: await window.callWorker('arrayBufferToStringBase64', signature),
|
||||
sender: this.sender,
|
||||
serverId: this.serverId,
|
||||
});
|
||||
|
|
|
@ -480,7 +480,7 @@ const handleBase64AvatarUpdate = async (
|
|||
|
||||
const upgradedAttachment = await processNewAttachment({
|
||||
isRaw: true,
|
||||
data: fromBase64ToArrayBuffer(res.base64),
|
||||
data: await window.callWorker('fromBase64ToArrayBuffer', res.base64),
|
||||
url: `${serverUrl}/${res.roomId}`,
|
||||
});
|
||||
// update the hash on the conversationModel
|
||||
|
|
|
@ -70,8 +70,6 @@ export async function updateOpenGroupV2(convo: ConversationModel, groupName: str
|
|||
isRaw: true,
|
||||
url: pathname,
|
||||
});
|
||||
// FIXME audric update of roomname on the server?
|
||||
window?.log?.warn('TODO update of roomName');
|
||||
const newHash = sha256(fromArrayBufferToBase64(downloaded.buffer));
|
||||
await convo.setLokiProfile({
|
||||
displayName: groupName || convo.get('name') || 'Unknown',
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { serverRequest } from '../session/onions/onionSend';
|
||||
import { fromArrayBufferToBase64 } from '../session/utils/String';
|
||||
|
||||
const pnServerPubkeyHex = '642a6585919742e5a2d4dc51244964fbcd8bcab2b75612407de58b810740d049';
|
||||
|
||||
|
@ -11,7 +10,7 @@ export async function notify(plainTextBuffer: ArrayBuffer, sentTo: string) {
|
|||
const options = {
|
||||
method: 'post',
|
||||
objBody: {
|
||||
data: fromArrayBufferToBase64(plainTextBuffer),
|
||||
data: await window.callWorker('arrayBufferToStringBase64', plainTextBuffer),
|
||||
send_to: sentTo,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -2,7 +2,6 @@ import _ from 'lodash';
|
|||
|
||||
import { MessageModel } from '../models/message';
|
||||
import { saveMessage } from '../../ts/data/data';
|
||||
import { fromBase64ToArrayBuffer } from '../session/utils/String';
|
||||
import { AttachmentDownloads } from '../session/utils';
|
||||
import { ConversationModel } from '../models/conversation';
|
||||
import {
|
||||
|
@ -54,8 +53,8 @@ export async function downloadAttachment(attachment: any) {
|
|||
|
||||
data = await window.textsecure.crypto.decryptAttachment(
|
||||
data,
|
||||
fromBase64ToArrayBuffer(key),
|
||||
fromBase64ToArrayBuffer(digest)
|
||||
await window.callWorker('fromBase64ToArrayBuffer', key),
|
||||
await window.callWorker('fromBase64ToArrayBuffer', digest)
|
||||
);
|
||||
|
||||
if (!size || size !== data.byteLength) {
|
||||
|
|
|
@ -4,7 +4,7 @@ import https from 'https';
|
|||
import { dropSnodeFromSnodePool, dropSnodeFromSwarmIfNeeded, updateSwarmFor } from './snodePool';
|
||||
import ByteBuffer from 'bytebuffer';
|
||||
import { OnionPaths } from '../onions';
|
||||
import { fromBase64ToArrayBuffer, toHex } from '../utils/String';
|
||||
import { toHex } from '../utils/String';
|
||||
import pRetry from 'p-retry';
|
||||
import { incrementBadPathCountOrDrop } from '../onions/onionPath';
|
||||
import _ from 'lodash';
|
||||
|
@ -395,7 +395,7 @@ export async function decodeOnionResult(symmetricKey: ArrayBuffer, ciphertext: s
|
|||
} catch (e) {
|
||||
// just try to get a json object from what is inside (for PN requests), if it fails, continue ()
|
||||
}
|
||||
const ciphertextBuffer = fromBase64ToArrayBuffer(parsedCiphertext);
|
||||
const ciphertextBuffer = await window.callWorker('fromBase64ToArrayBuffer', parsedCiphertext);
|
||||
|
||||
const plaintextBuffer = await window.libloki.crypto.DecryptAESGCM(symmetricKey, ciphertextBuffer);
|
||||
|
||||
|
|
|
@ -14,14 +14,11 @@ import {
|
|||
ConfigurationMessageContact,
|
||||
} from '../messages/outgoing/controlMessage/ConfigurationMessage';
|
||||
import { ConversationModel } from '../../models/conversation';
|
||||
import { fromBase64ToArray, fromBase64ToArrayBuffer, fromHexToArray } from './String';
|
||||
import { fromBase64 } from 'bytebuffer';
|
||||
import { fromBase64ToArray } from './String';
|
||||
import { SignalService } from '../../protobuf';
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
AttachmentPointer,
|
||||
AttachmentPointerWithUrl,
|
||||
Preview,
|
||||
PreviewWithAttachmentUrl,
|
||||
Quote,
|
||||
VisibleMessage,
|
||||
|
|
|
@ -84,5 +84,9 @@ declare global {
|
|||
LokiPushNotificationServer: any;
|
||||
globalOnlineStatus: boolean;
|
||||
confirmationDialog: any;
|
||||
callWorker: (
|
||||
fnName: 'arrayBufferToStringBase64' | 'fromBase64ToArrayBuffer',
|
||||
...args
|
||||
) => Promise<any>;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue