Skip to content

Commit ae51b0c

Browse files
committed
fix: include auth sogs headers everywhere
1 parent 2fdb612 commit ae51b0c

File tree

7 files changed

+58
-37
lines changed

7 files changed

+58
-37
lines changed

ts/session/apis/open_group_api/sogsv3/sogsV3Capabilities.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ import { OpenGroupData, OpenGroupV2Room } from '../../../../data/opengroups';
55
import AbortController, { AbortSignal } from 'abort-controller';
66
import { batchGlobalIsSuccess } from './sogsV3BatchPoll';
77

8-
export const capabilitiesFetchForServer = async (
8+
const capabilitiesFetchForServer = async (
99
serverUrl: string,
1010
serverPubKey: string,
1111
abortSignal: AbortSignal
1212
): Promise<Array<string> | null> => {
1313
const endpoint = '/capabilities';
1414
const method = 'GET';
1515
const serverPubkey = serverPubKey;
16-
const blinded = false; // for capabilities, blinding is always false as the request will fail if the server requires blinding
16+
// for the capabilities call, we require blinded to be ON now. A sogs with blinding disabled will still allow this call and verify the blinded signature
17+
const blinded = true;
1718
const capabilityHeaders = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
1819
serverPubkey,
1920
endpoint,
@@ -33,7 +34,6 @@ export const capabilitiesFetchForServer = async (
3334
serverPubkey,
3435
serverUrl,
3536
stringifiedBody: null,
36-
doNotIncludeOurSogsHeaders: true, // the first capabilities needs to not have any authentification to pass on a blinding-required sogs,
3737
headers: null,
3838
throwErrors: false,
3939
});

ts/session/apis/open_group_api/sogsv3/sogsV3FetchFile.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import AbortController, { AbortSignal } from 'abort-controller';
22
import { isUndefined, toNumber } from 'lodash';
3-
import { OpenGroupV2Room, OpenGroupV2RoomWithImageID } from '../../../../data/opengroups';
3+
import {
4+
OpenGroupData,
5+
OpenGroupV2Room,
6+
OpenGroupV2RoomWithImageID,
7+
} from '../../../../data/opengroups';
48
import { MIME } from '../../../../types';
59
import { processNewAttachment } from '../../../../types/MessageAttachment';
610
import { callUtilsWorker } from '../../../../webworker/workers/util_worker_interface';
@@ -16,7 +20,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
1620
serverPubkey: string;
1721
blinded: boolean;
1822
abortSignal: AbortSignal;
19-
doNotIncludeOurSogsHeaders?: boolean;
2023
headers: Record<string, any> | null;
2124
roomId: string;
2225
fileId: string;
@@ -28,7 +31,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
2831
blinded,
2932
abortSignal,
3033
headers: includedHeaders,
31-
doNotIncludeOurSogsHeaders,
3234
roomId,
3335
fileId,
3436
throwError,
@@ -41,15 +43,13 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
4143
throw new Error('endpoint needs a leading /');
4244
}
4345
const builtUrl = new URL(`${serverUrl}${endpoint}`);
44-
let headersWithSogsHeadersIfNeeded = doNotIncludeOurSogsHeaders
45-
? {}
46-
: await OpenGroupPollingUtils.getOurOpenGroupHeaders(
47-
serverPubkey,
48-
endpoint,
49-
method,
50-
blinded,
51-
stringifiedBody
52-
);
46+
let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
47+
serverPubkey,
48+
endpoint,
49+
method,
50+
blinded,
51+
stringifiedBody
52+
);
5353

5454
if (isUndefined(headersWithSogsHeadersIfNeeded)) {
5555
return null;
@@ -98,11 +98,14 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
9898
return;
9999
}
100100

101+
const room = OpenGroupData.getV2OpenGroupRoom(convoId);
102+
const blinded = roomHasBlindEnabled(room);
103+
101104
// make sure this runs only once for each rooms.
102-
// we don't want to trigger one of those on each setPollInfo resultsas it happens on each batch poll.
105+
// we don't want to trigger one of those on each setPollInfo results as it happens on each batch poll.
103106
const oneAtAtimeResult = (await allowOnlyOneAtATime(
104107
`sogsV3FetchPreview-${serverUrl}-${roomId}`,
105-
() => sogsV3FetchPreview(roomInfos)
108+
() => sogsV3FetchPreview(roomInfos, blinded)
106109
)) as Uint8Array | null; // force the return type as allowOnlyOneAtATime does not keep it
107110

108111
if (!oneAtAtimeResult || !oneAtAtimeResult?.byteLength) {
@@ -139,7 +142,7 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
139142
* @returns the fetchedData in base64
140143
*/
141144
export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithImageID) {
142-
const fetched = await sogsV3FetchPreview(roomInfos);
145+
const fetched = await sogsV3FetchPreview(roomInfos, true); // left pane are session official default rooms, which do require blinded
143146
if (fetched && fetched.byteLength) {
144147
return callUtilsWorker('arrayBufferToStringBase64', fetched);
145148
}
@@ -155,7 +158,8 @@ export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithIma
155158
* Those default rooms do not have a conversation associated with them, as they are not joined yet
156159
*/
157160
const sogsV3FetchPreview = async (
158-
roomInfos: OpenGroupV2RoomWithImageID
161+
roomInfos: OpenGroupV2RoomWithImageID,
162+
blinded: boolean
159163
): Promise<Uint8Array | null> => {
160164
if (!roomInfos || !roomInfos.imageID) {
161165
return null;
@@ -164,11 +168,10 @@ const sogsV3FetchPreview = async (
164168
// not a batch call yet as we need to exclude headers for this call for now
165169
const fetched = await fetchBinaryFromSogsWithOnionV4({
166170
abortSignal: new AbortController().signal,
167-
blinded: false,
171+
blinded,
168172
headers: null,
169173
serverPubkey: roomInfos.serverPublicKey,
170174
serverUrl: roomInfos.serverUrl,
171-
doNotIncludeOurSogsHeaders: true,
172175
roomId: roomInfos.roomId,
173176
fileId: roomInfos.imageID,
174177
throwError: false,
@@ -198,7 +201,6 @@ export const sogsV3FetchFileByFileID = async (
198201
headers: null,
199202
serverPubkey: roomInfos.serverPublicKey,
200203
serverUrl: roomInfos.serverUrl,
201-
doNotIncludeOurSogsHeaders: true,
202204
roomId: roomInfos.roomId,
203205
fileId,
204206
throwError: true,

ts/session/apis/open_group_api/sogsv3/sogsV3RoomInfos.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ import {
1111

1212
export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => {
1313
const result = await OnionSending.sendJsonViaOnionV4ToSogs({
14-
blinded: false,
14+
blinded: true,
1515
endpoint: '/rooms',
1616
method: 'GET',
1717
serverPubkey: roomInfos.serverPublicKey,
1818
stringifiedBody: null,
1919
abortSignal: new AbortController().signal,
2020
serverUrl: roomInfos.serverUrl,
2121
headers: null,
22-
doNotIncludeOurSogsHeaders: true,
2322
throwErrors: false,
2423
});
2524

@@ -91,7 +90,6 @@ export async function openGroupV2GetRoomInfoViaOnionV4({
9190
stringifiedBody: null,
9291
serverPubkey,
9392
headers: null,
94-
doNotIncludeOurSogsHeaders: true,
9593
throwErrors: false,
9694
});
9795
const room = result?.body as Record<string, any> | undefined;

ts/session/apis/snode_api/onions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,13 @@ async function processAnyOtherErrorOnPath(
338338
if (status !== 200) {
339339
window?.log?.warn(`[path] Got status: ${status}`);
340340

341+
if (status === 404 || status === 400) {
342+
window?.log?.warn(
343+
'processAnyOtherErrorOnPathgot 404 or 400, probably a dead sogs. Skipping bad path update'
344+
);
345+
return;
346+
}
347+
341348
// If we have a specific node in fault we can exclude just this node.
342349
if (ciphertext?.startsWith(NEXT_NODE_NOT_FOUND_PREFIX)) {
343350
const nodeNotFound = ciphertext.substr(NEXT_NODE_NOT_FOUND_PREFIX.length);

ts/session/onions/onionSend.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ async function sendJsonViaOnionV4ToSogs(sendOptions: {
277277
method: string;
278278
stringifiedBody: string | null;
279279
abortSignal: AbortSignal;
280-
doNotIncludeOurSogsHeaders?: boolean;
281280
headers: Record<string, any> | null;
282281
throwErrors: boolean;
283282
}): Promise<OnionV4JSONSnodeResponse | null> {
@@ -290,22 +289,19 @@ async function sendJsonViaOnionV4ToSogs(sendOptions: {
290289
stringifiedBody,
291290
abortSignal,
292291
headers: includedHeaders,
293-
doNotIncludeOurSogsHeaders,
294292
throwErrors,
295293
} = sendOptions;
296294
if (!endpoint.startsWith('/')) {
297295
throw new Error('endpoint needs a leading /');
298296
}
299297
const builtUrl = new URL(`${serverUrl}${endpoint}`);
300-
let headersWithSogsHeadersIfNeeded = doNotIncludeOurSogsHeaders
301-
? {}
302-
: await OpenGroupPollingUtils.getOurOpenGroupHeaders(
303-
serverPubkey,
304-
endpoint,
305-
method,
306-
blinded,
307-
stringifiedBody
308-
);
298+
let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
299+
serverPubkey,
300+
endpoint,
301+
method,
302+
blinded,
303+
stringifiedBody
304+
);
309305

310306
if (!headersWithSogsHeadersIfNeeded) {
311307
return null;

ts/session/onions/onionv4.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ const decodeV4Response = (snodeResponse: SnodeResponseV4): DecodedResponseV4 | u
9292
break;
9393
case 'application/octet-stream':
9494
break;
95+
case 'text/html; charset=utf-8':
96+
try {
97+
window?.log?.warn(
98+
'decodeV4Response - received raw body of type "text/html; charset=utf-8": ',
99+
to_string(bodyBinary)
100+
);
101+
} catch (e) {
102+
window?.log?.warn(
103+
'decodeV4Response - received raw body of type "text/html; charset=utf-8" but not a string'
104+
);
105+
}
106+
break;
95107
default:
96108
window?.log?.warn(
97109
'decodeV4Response - No or unknown content-type information for response: ',

ts/updater/updater.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,13 @@ export async function start(
4646
}, 1000 * 60 * 10); // trigger and try to update every 10 minutes to let the file gets downloaded if we are updating
4747
stopped = false;
4848

49-
await checkForUpdates(getMainWindow, messages, logger);
49+
global.setTimeout(async () => {
50+
try {
51+
await checkForUpdates(getMainWindow, messages, logger);
52+
} catch (error) {
53+
logger.error('auto-update: error:', getPrintableError(error));
54+
}
55+
}, 2 * 60 * 1000); // we do checks from the fileserver every 1 minute.
5056
}
5157

5258
export function stop() {

0 commit comments

Comments
 (0)