From 8bd89de35aa724438bdbf1aef4740f5f768cd1c1 Mon Sep 17 00:00:00 2001 From: yougotwill Date: Fri, 14 Feb 2025 16:55:36 +1100 Subject: [PATCH] feat: added os arch and release channel to desktop update requests to the file server we now use blindVersionSignRequest --- ts/OS.ts | 1 + .../apis/file_server_api/FileServerApi.ts | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ts/OS.ts b/ts/OS.ts index 0f92f9d93..adb8a11cf 100644 --- a/ts/OS.ts +++ b/ts/OS.ts @@ -15,3 +15,4 @@ export const isWindows = (minVersion?: string) => { }; export const getOSArchitecture = () => os.arch(); +export const getOSPlatform = () => os.platform(); diff --git a/ts/session/apis/file_server_api/FileServerApi.ts b/ts/session/apis/file_server_api/FileServerApi.ts index 231a4807a..b0b3228b0 100644 --- a/ts/session/apis/file_server_api/FileServerApi.ts +++ b/ts/session/apis/file_server_api/FileServerApi.ts @@ -8,7 +8,7 @@ import { import { fromUInt8ArrayToBase64 } from '../../utils/String'; import { NetworkTime } from '../../../util/NetworkTime'; import { DURATION } from '../../constants'; -import { getOSArchitecture } from '../../../OS'; +import { getOSArchitecture, getOSPlatform } from '../../../OS'; import type { ReleaseChannels } from '../../../updater/types'; import { Storage } from '../../../util/storage'; @@ -16,7 +16,7 @@ export const fileServerHost = 'filev2.getsession.org'; export const fileServerURL = `http://${fileServerHost}`; export const fileServerPubKey = 'da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59'; -const RELEASE_VERSION_ENDPOINT = '/session_version?platform=desktop'; +const RELEASE_VERSION_ENDPOINT = '/session_version'; const POST_GET_FILE_ENDPOINT = '/file'; @@ -133,15 +133,23 @@ const parseStatusCodeFromOnionRequestV4 = ( * This call is onion routed and so do not expose our ip to github nor the file server. */ export const getLatestReleaseFromFileServer = async ( - userEd25519SecretKey: Uint8Array + userEd25519SecretKey: Uint8Array, + releaseType?: ReleaseChannels ): Promise => { const sigTimestampSeconds = NetworkTime.getNowWithNetworkOffsetSeconds(); const blindedPkHex = await BlindingActions.blindVersionPubkey({ ed25519SecretKey: userEd25519SecretKey, }); - const signature = await BlindingActions.blindVersionSign({ + const method = 'GET'; + const releaseChannel = Storage.get('releaseChannel') as ReleaseChannels; + const endpoint = `${RELEASE_VERSION_ENDPOINT}?platform=desktop&os=${getOSPlatform()}&arch=${getOSArchitecture()}${releaseChannel ? `&release_channel=${releaseType || releaseChannel}` : ''}`; + + const signature = await BlindingActions.blindVersionSignRequest({ ed25519SecretKey: userEd25519SecretKey, sigTimestampSeconds, + sigMethod: method, + sigPath: endpoint, + sigBody: null, }); const headers = { @@ -150,16 +158,15 @@ export const getLatestReleaseFromFileServer = async ( 'X-FS-Signature': fromUInt8ArrayToBase64(signature), }; - const releaseChannel = Storage.get('releaseChannel') as ReleaseChannels; - const endpoint = `${RELEASE_VERSION_ENDPOINT}&arch=${getOSArchitecture()}${releaseChannel ? `&releases=${releaseChannel}` : ''}`; - const result = await OnionSending.sendJsonViaOnionV4ToFileServer({ + const params = { abortSignal: new AbortController().signal, endpoint, - method: 'GET', + method, stringifiedBody: null, headers, timeoutMs: 10 * DURATION.SECONDS, - }); + }; + const result = await OnionSending.sendJsonViaOnionV4ToFileServer(params); if (!batchGlobalIsSuccess(result) || parseStatusCodeFromOnionRequestV4(result) !== 200) { return null;