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