fix: include auth sogs headers everywhere

pull/2571/head
Audric Ackermann 3 years ago
parent 2fdb612a77
commit ae51b0cd96

@ -5,7 +5,7 @@ import { OpenGroupData, OpenGroupV2Room } from '../../../../data/opengroups';
import AbortController, { AbortSignal } from 'abort-controller'; import AbortController, { AbortSignal } from 'abort-controller';
import { batchGlobalIsSuccess } from './sogsV3BatchPoll'; import { batchGlobalIsSuccess } from './sogsV3BatchPoll';
export const capabilitiesFetchForServer = async ( const capabilitiesFetchForServer = async (
serverUrl: string, serverUrl: string,
serverPubKey: string, serverPubKey: string,
abortSignal: AbortSignal abortSignal: AbortSignal
@ -13,7 +13,8 @@ export const capabilitiesFetchForServer = async (
const endpoint = '/capabilities'; const endpoint = '/capabilities';
const method = 'GET'; const method = 'GET';
const serverPubkey = serverPubKey; const serverPubkey = serverPubKey;
const blinded = false; // for capabilities, blinding is always false as the request will fail if the server requires blinding // 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
const blinded = true;
const capabilityHeaders = await OpenGroupPollingUtils.getOurOpenGroupHeaders( const capabilityHeaders = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey, serverPubkey,
endpoint, endpoint,
@ -33,7 +34,6 @@ export const capabilitiesFetchForServer = async (
serverPubkey, serverPubkey,
serverUrl, serverUrl,
stringifiedBody: null, stringifiedBody: null,
doNotIncludeOurSogsHeaders: true, // the first capabilities needs to not have any authentification to pass on a blinding-required sogs,
headers: null, headers: null,
throwErrors: false, throwErrors: false,
}); });

@ -1,6 +1,10 @@
import AbortController, { AbortSignal } from 'abort-controller'; import AbortController, { AbortSignal } from 'abort-controller';
import { isUndefined, toNumber } from 'lodash'; import { isUndefined, toNumber } from 'lodash';
import { OpenGroupV2Room, OpenGroupV2RoomWithImageID } from '../../../../data/opengroups'; import {
OpenGroupData,
OpenGroupV2Room,
OpenGroupV2RoomWithImageID,
} from '../../../../data/opengroups';
import { MIME } from '../../../../types'; import { MIME } from '../../../../types';
import { processNewAttachment } from '../../../../types/MessageAttachment'; import { processNewAttachment } from '../../../../types/MessageAttachment';
import { callUtilsWorker } from '../../../../webworker/workers/util_worker_interface'; import { callUtilsWorker } from '../../../../webworker/workers/util_worker_interface';
@ -16,7 +20,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
serverPubkey: string; serverPubkey: string;
blinded: boolean; blinded: boolean;
abortSignal: AbortSignal; abortSignal: AbortSignal;
doNotIncludeOurSogsHeaders?: boolean;
headers: Record<string, any> | null; headers: Record<string, any> | null;
roomId: string; roomId: string;
fileId: string; fileId: string;
@ -28,7 +31,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
blinded, blinded,
abortSignal, abortSignal,
headers: includedHeaders, headers: includedHeaders,
doNotIncludeOurSogsHeaders,
roomId, roomId,
fileId, fileId,
throwError, throwError,
@ -41,9 +43,7 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
throw new Error('endpoint needs a leading /'); throw new Error('endpoint needs a leading /');
} }
const builtUrl = new URL(`${serverUrl}${endpoint}`); const builtUrl = new URL(`${serverUrl}${endpoint}`);
let headersWithSogsHeadersIfNeeded = doNotIncludeOurSogsHeaders let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
? {}
: await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey, serverPubkey,
endpoint, endpoint,
method, method,
@ -98,11 +98,14 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
return; return;
} }
const room = OpenGroupData.getV2OpenGroupRoom(convoId);
const blinded = roomHasBlindEnabled(room);
// make sure this runs only once for each rooms. // make sure this runs only once for each rooms.
// we don't want to trigger one of those on each setPollInfo resultsas it happens on each batch poll. // we don't want to trigger one of those on each setPollInfo results as it happens on each batch poll.
const oneAtAtimeResult = (await allowOnlyOneAtATime( const oneAtAtimeResult = (await allowOnlyOneAtATime(
`sogsV3FetchPreview-${serverUrl}-${roomId}`, `sogsV3FetchPreview-${serverUrl}-${roomId}`,
() => sogsV3FetchPreview(roomInfos) () => sogsV3FetchPreview(roomInfos, blinded)
)) as Uint8Array | null; // force the return type as allowOnlyOneAtATime does not keep it )) as Uint8Array | null; // force the return type as allowOnlyOneAtATime does not keep it
if (!oneAtAtimeResult || !oneAtAtimeResult?.byteLength) { if (!oneAtAtimeResult || !oneAtAtimeResult?.byteLength) {
@ -139,7 +142,7 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
* @returns the fetchedData in base64 * @returns the fetchedData in base64
*/ */
export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithImageID) { export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithImageID) {
const fetched = await sogsV3FetchPreview(roomInfos); const fetched = await sogsV3FetchPreview(roomInfos, true); // left pane are session official default rooms, which do require blinded
if (fetched && fetched.byteLength) { if (fetched && fetched.byteLength) {
return callUtilsWorker('arrayBufferToStringBase64', fetched); return callUtilsWorker('arrayBufferToStringBase64', fetched);
} }
@ -155,7 +158,8 @@ export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithIma
* Those default rooms do not have a conversation associated with them, as they are not joined yet * Those default rooms do not have a conversation associated with them, as they are not joined yet
*/ */
const sogsV3FetchPreview = async ( const sogsV3FetchPreview = async (
roomInfos: OpenGroupV2RoomWithImageID roomInfos: OpenGroupV2RoomWithImageID,
blinded: boolean
): Promise<Uint8Array | null> => { ): Promise<Uint8Array | null> => {
if (!roomInfos || !roomInfos.imageID) { if (!roomInfos || !roomInfos.imageID) {
return null; return null;
@ -164,11 +168,10 @@ const sogsV3FetchPreview = async (
// not a batch call yet as we need to exclude headers for this call for now // not a batch call yet as we need to exclude headers for this call for now
const fetched = await fetchBinaryFromSogsWithOnionV4({ const fetched = await fetchBinaryFromSogsWithOnionV4({
abortSignal: new AbortController().signal, abortSignal: new AbortController().signal,
blinded: false, blinded,
headers: null, headers: null,
serverPubkey: roomInfos.serverPublicKey, serverPubkey: roomInfos.serverPublicKey,
serverUrl: roomInfos.serverUrl, serverUrl: roomInfos.serverUrl,
doNotIncludeOurSogsHeaders: true,
roomId: roomInfos.roomId, roomId: roomInfos.roomId,
fileId: roomInfos.imageID, fileId: roomInfos.imageID,
throwError: false, throwError: false,
@ -198,7 +201,6 @@ export const sogsV3FetchFileByFileID = async (
headers: null, headers: null,
serverPubkey: roomInfos.serverPublicKey, serverPubkey: roomInfos.serverPublicKey,
serverUrl: roomInfos.serverUrl, serverUrl: roomInfos.serverUrl,
doNotIncludeOurSogsHeaders: true,
roomId: roomInfos.roomId, roomId: roomInfos.roomId,
fileId, fileId,
throwError: true, throwError: true,

@ -11,7 +11,7 @@ import {
export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => { export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => {
const result = await OnionSending.sendJsonViaOnionV4ToSogs({ const result = await OnionSending.sendJsonViaOnionV4ToSogs({
blinded: false, blinded: true,
endpoint: '/rooms', endpoint: '/rooms',
method: 'GET', method: 'GET',
serverPubkey: roomInfos.serverPublicKey, serverPubkey: roomInfos.serverPublicKey,
@ -19,7 +19,6 @@ export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => {
abortSignal: new AbortController().signal, abortSignal: new AbortController().signal,
serverUrl: roomInfos.serverUrl, serverUrl: roomInfos.serverUrl,
headers: null, headers: null,
doNotIncludeOurSogsHeaders: true,
throwErrors: false, throwErrors: false,
}); });
@ -91,7 +90,6 @@ export async function openGroupV2GetRoomInfoViaOnionV4({
stringifiedBody: null, stringifiedBody: null,
serverPubkey, serverPubkey,
headers: null, headers: null,
doNotIncludeOurSogsHeaders: true,
throwErrors: false, throwErrors: false,
}); });
const room = result?.body as Record<string, any> | undefined; const room = result?.body as Record<string, any> | undefined;

@ -338,6 +338,13 @@ async function processAnyOtherErrorOnPath(
if (status !== 200) { if (status !== 200) {
window?.log?.warn(`[path] Got status: ${status}`); window?.log?.warn(`[path] Got status: ${status}`);
if (status === 404 || status === 400) {
window?.log?.warn(
'processAnyOtherErrorOnPathgot 404 or 400, probably a dead sogs. Skipping bad path update'
);
return;
}
// If we have a specific node in fault we can exclude just this node. // If we have a specific node in fault we can exclude just this node.
if (ciphertext?.startsWith(NEXT_NODE_NOT_FOUND_PREFIX)) { if (ciphertext?.startsWith(NEXT_NODE_NOT_FOUND_PREFIX)) {
const nodeNotFound = ciphertext.substr(NEXT_NODE_NOT_FOUND_PREFIX.length); const nodeNotFound = ciphertext.substr(NEXT_NODE_NOT_FOUND_PREFIX.length);

@ -277,7 +277,6 @@ async function sendJsonViaOnionV4ToSogs(sendOptions: {
method: string; method: string;
stringifiedBody: string | null; stringifiedBody: string | null;
abortSignal: AbortSignal; abortSignal: AbortSignal;
doNotIncludeOurSogsHeaders?: boolean;
headers: Record<string, any> | null; headers: Record<string, any> | null;
throwErrors: boolean; throwErrors: boolean;
}): Promise<OnionV4JSONSnodeResponse | null> { }): Promise<OnionV4JSONSnodeResponse | null> {
@ -290,16 +289,13 @@ async function sendJsonViaOnionV4ToSogs(sendOptions: {
stringifiedBody, stringifiedBody,
abortSignal, abortSignal,
headers: includedHeaders, headers: includedHeaders,
doNotIncludeOurSogsHeaders,
throwErrors, throwErrors,
} = sendOptions; } = sendOptions;
if (!endpoint.startsWith('/')) { if (!endpoint.startsWith('/')) {
throw new Error('endpoint needs a leading /'); throw new Error('endpoint needs a leading /');
} }
const builtUrl = new URL(`${serverUrl}${endpoint}`); const builtUrl = new URL(`${serverUrl}${endpoint}`);
let headersWithSogsHeadersIfNeeded = doNotIncludeOurSogsHeaders let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils.getOurOpenGroupHeaders(
? {}
: await OpenGroupPollingUtils.getOurOpenGroupHeaders(
serverPubkey, serverPubkey,
endpoint, endpoint,
method, method,

@ -92,6 +92,18 @@ const decodeV4Response = (snodeResponse: SnodeResponseV4): DecodedResponseV4 | u
break; break;
case 'application/octet-stream': case 'application/octet-stream':
break; break;
case 'text/html; charset=utf-8':
try {
window?.log?.warn(
'decodeV4Response - received raw body of type "text/html; charset=utf-8": ',
to_string(bodyBinary)
);
} catch (e) {
window?.log?.warn(
'decodeV4Response - received raw body of type "text/html; charset=utf-8" but not a string'
);
}
break;
default: default:
window?.log?.warn( window?.log?.warn(
'decodeV4Response - No or unknown content-type information for response: ', 'decodeV4Response - No or unknown content-type information for response: ',

@ -46,7 +46,13 @@ export async function start(
}, 1000 * 60 * 10); // trigger and try to update every 10 minutes to let the file gets downloaded if we are updating }, 1000 * 60 * 10); // trigger and try to update every 10 minutes to let the file gets downloaded if we are updating
stopped = false; stopped = false;
global.setTimeout(async () => {
try {
await checkForUpdates(getMainWindow, messages, logger); await checkForUpdates(getMainWindow, messages, logger);
} catch (error) {
logger.error('auto-update: error:', getPrintableError(error));
}
}, 2 * 60 * 1000); // we do checks from the fileserver every 1 minute.
} }
export function stop() { export function stop() {

Loading…
Cancel
Save