From 24c8458545a362ab594412c278f2a87ebce31656 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Tue, 3 Sep 2024 10:48:11 +0300 Subject: [PATCH 1/6] feat: update SpoofedHostname generation --- src/AuthenticationClient.ts | 2 ++ src/helpers.ts | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/AuthenticationClient.ts b/src/AuthenticationClient.ts index 9e1c5bc..3b32ecb 100644 --- a/src/AuthenticationClient.ts +++ b/src/AuthenticationClient.ts @@ -128,6 +128,8 @@ export default class AuthenticationClient extends EventEmitter { } else if (this._machineId === true) { data.device_details.machine_id = createMachineId(details.accountName); } + + this._clientFriendlyName = this._clientFriendlyName || getSpoofedHostname(details.accountName); } if (details.steamGuardMachineToken) { diff --git a/src/helpers.ts b/src/helpers.ts index 893fc32..8c5535b 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -49,12 +49,12 @@ export function isJwtValidForAudience(jwt:string, audience:string, steamId?:stri return (decodedToken.aud || []).includes(audience); } -export function getSpoofedHostname() { +export function getSpoofedHostname(accountName?: string): string { let hash = createHash('sha1'); - hash.update(hostname()); + hash.update(accountName || hostname()); let sha1 = hash.digest(); - const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + const CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let output = 'DESKTOP-'; for (let i = 0; i < 7; i++) { From cbb2d5f1e4f020f60081ac6f536fbf4d32628312 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Tue, 3 Sep 2024 10:48:51 +0300 Subject: [PATCH 2/6] fix: update machine name check --- test/LoginSession.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/LoginSession.test.ts b/test/LoginSession.test.ts index a5216db..e574c73 100644 --- a/test/LoginSession.test.ts +++ b/test/LoginSession.test.ts @@ -75,7 +75,7 @@ describe('LoginSession tests', () => { }); expect(req.device_details).toMatchObject({ - device_friendly_name: getSpoofedHostname(), + device_friendly_name: getSpoofedHostname(LOGIN_USERNAME), platform_type: EAuthTokenPlatformType.SteamClient, os_type: 20, gaming_device_type: 1 @@ -198,7 +198,7 @@ describe('LoginSession tests', () => { remember_login: true, website_id: 'Unknown', device_details: { - device_friendly_name: getSpoofedHostname(), + device_friendly_name: getSpoofedHostname(LOGIN_USERNAME), platform_type: EAuthTokenPlatformType.SteamClient, os_type: 20, gaming_device_type: 1, From f4cac06aed4ad1fee575c441334f78367d7b7480 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Tue, 3 Sep 2024 10:51:04 +0300 Subject: [PATCH 3/6] docs: update machine name faq --- README.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7ce2b70..2a7d226 100644 --- a/README.md +++ b/README.md @@ -265,12 +265,17 @@ event is emitted. this property to not send a machine ID (not sending a machine ID may cause problems in the future). - `machineFriendlyName` - Only applicable when using EAuthTokenPlatformType.SteamClient. Pass a `string` containing the machine name that you want to report to Steam when logging on. If omitted, a machine name will automatically - be generated in the format `DESKTOP-ABCDEFG`. Auto-generated machine IDs are always the same on the same machine - (it's based on the hash of your actual machine's hostname) + be generated in the format `DESKTOP-ABCDEFG`. You can only use one of `localAddress`, `httpProxy`, `socksProxy` or `agent` at the same time. If you try to use more than one of them, an Error will be thrown. +Auto-generated machine names are always the same for the same account (based on hash of account name) if account name is known, +or always the same for the same machine (based on hash of your machine's hostname) if account name is unknown. +In other words: + - When using `startWithCredentials` method, auto-generated machine name will base on account name + - When using `startWithQR` method, auto-generated machine name will base on machine's hostname + If you specify a custom transport, then you are responsible for handling proxy or agent usage in your transport. Constructs a new `LoginSession` instance. Example usage: @@ -579,7 +584,7 @@ If this is a `string`, it must be either hex- or base64-encoded. ## Methods -### Constructor(accessToken, sharedSecret[, transport]) +### Constructor(accessToken, sharedSecret[, options]) - `accessToken` - A `string` containing a valid access token for the account you want to approve logins for. This access token (**not refresh token**) must have been created using the `MobileApp` platform type. - `sharedSecret` - A `string` or `Buffer` containing your account's TOTP shared secret. If this is a string, it must be From 707a04a56eb414202dc8d8e91db009e1a1b6c4ee Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Tue, 3 Sep 2024 11:25:54 +0300 Subject: [PATCH 4/6] fix: fixed creating client name --- src/AuthenticationClient.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/AuthenticationClient.ts b/src/AuthenticationClient.ts index 3b32ecb..e630cb3 100644 --- a/src/AuthenticationClient.ts +++ b/src/AuthenticationClient.ts @@ -109,6 +109,12 @@ export default class AuthenticationClient extends EventEmitter { } async startSessionWithCredentials(details: StartAuthSessionWithCredentialsRequest): Promise { + if (details.platformType == EAuthTokenPlatformType.SteamClient) { + // For SteamClient logins, we also need a machine id and machine name + this._machineId = this._machineId === true ? createMachineId(details.accountName) : this._machineId; + this._clientFriendlyName = this._clientFriendlyName || getSpoofedHostname(details.accountName); + } + let {websiteId, deviceDetails} = this._getPlatformData(); let data:CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData = { @@ -121,15 +127,8 @@ export default class AuthenticationClient extends EventEmitter { device_details: deviceDetails }; - if (details.platformType == EAuthTokenPlatformType.SteamClient) { - // For SteamClient logins, we also need a machine id - if (this._machineId && Buffer.isBuffer(this._machineId)) { - data.device_details.machine_id = this._machineId; - } else if (this._machineId === true) { - data.device_details.machine_id = createMachineId(details.accountName); - } - - this._clientFriendlyName = this._clientFriendlyName || getSpoofedHostname(details.accountName); + if (details.platformType == EAuthTokenPlatformType.SteamClient && Buffer.isBuffer(this._machineId)) { + data.device_details.machine_id = this._machineId; } if (details.steamGuardMachineToken) { From 441b199dd4b4a3677636d363e912c72fbf978258 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Tue, 3 Sep 2024 11:38:46 +0300 Subject: [PATCH 5/6] fix: tweaks --- src/AuthenticationClient.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/AuthenticationClient.ts b/src/AuthenticationClient.ts index e630cb3..c5be14b 100644 --- a/src/AuthenticationClient.ts +++ b/src/AuthenticationClient.ts @@ -127,10 +127,6 @@ export default class AuthenticationClient extends EventEmitter { device_details: deviceDetails }; - if (details.platformType == EAuthTokenPlatformType.SteamClient && Buffer.isBuffer(this._machineId)) { - data.device_details.machine_id = this._machineId; - } - if (details.steamGuardMachineToken) { if (Buffer.isBuffer(details.steamGuardMachineToken)) { data.guard_data = details.steamGuardMachineToken; @@ -388,7 +384,8 @@ export default class AuthenticationClient extends EventEmitter { platform_type: EAuthTokenPlatformType.SteamClient, os_type: EOSType.Win11, // EGamingDeviceType full definition is unknown, but 1 appears to be a desktop PC - gaming_device_type: 1 + gaming_device_type: 1, + ...(Buffer.isBuffer(this._machineId) ? { machine_id: this._machineId } : {}) } }; From 931aa888cd24a2d3a54750d153038d380dfbf941 Mon Sep 17 00:00:00 2001 From: Sadzurami Date: Wed, 4 Sep 2024 15:00:24 +0300 Subject: [PATCH 6/6] refactor: rename getSpoofedHostname() -> createMachineName() --- src/AuthenticationClient.ts | 6 +++--- src/helpers.ts | 2 +- test/LoginSession.test.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/AuthenticationClient.ts b/src/AuthenticationClient.ts index c5be14b..7206ba3 100644 --- a/src/AuthenticationClient.ts +++ b/src/AuthenticationClient.ts @@ -19,7 +19,7 @@ import { createMachineId, decodeJwt, eresultError, - getSpoofedHostname, + createMachineName, isJwtValidForAudience } from './helpers'; import { @@ -112,7 +112,7 @@ export default class AuthenticationClient extends EventEmitter { if (details.platformType == EAuthTokenPlatformType.SteamClient) { // For SteamClient logins, we also need a machine id and machine name this._machineId = this._machineId === true ? createMachineId(details.accountName) : this._machineId; - this._clientFriendlyName = this._clientFriendlyName || getSpoofedHostname(details.accountName); + this._clientFriendlyName = this._clientFriendlyName || createMachineName(details.accountName); } let {websiteId, deviceDetails} = this._getPlatformData(); @@ -352,7 +352,7 @@ export default class AuthenticationClient extends EventEmitter { _getPlatformData(): PlatformData { switch (this._platformType) { case EAuthTokenPlatformType.SteamClient: - let machineName = this._clientFriendlyName || getSpoofedHostname(); + let machineName = this._clientFriendlyName || createMachineName(); let refererQuery = { IN_CLIENT: 'true', diff --git a/src/helpers.ts b/src/helpers.ts index 8c5535b..129d819 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -49,7 +49,7 @@ export function isJwtValidForAudience(jwt:string, audience:string, steamId?:stri return (decodedToken.aud || []).includes(audience); } -export function getSpoofedHostname(accountName?: string): string { +export function createMachineName(accountName?: string): string { let hash = createHash('sha1'); hash.update(accountName || hostname()); let sha1 = hash.digest(); diff --git a/test/LoginSession.test.ts b/test/LoginSession.test.ts index e574c73..ab02baa 100644 --- a/test/LoginSession.test.ts +++ b/test/LoginSession.test.ts @@ -14,7 +14,7 @@ import { LoginSession } from '../src'; import {createTokenPair, protobufDecodeRequest} from './src/helpers'; -import {getSpoofedHostname} from '../src/helpers'; +import {createMachineName} from '../src/helpers'; import { CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData, CAuthentication_BeginAuthSessionViaCredentials_Response, @@ -75,7 +75,7 @@ describe('LoginSession tests', () => { }); expect(req.device_details).toMatchObject({ - device_friendly_name: getSpoofedHostname(LOGIN_USERNAME), + device_friendly_name: createMachineName(LOGIN_USERNAME), platform_type: EAuthTokenPlatformType.SteamClient, os_type: 20, gaming_device_type: 1 @@ -198,7 +198,7 @@ describe('LoginSession tests', () => { remember_login: true, website_id: 'Unknown', device_details: { - device_friendly_name: getSpoofedHostname(LOGIN_USERNAME), + device_friendly_name: createMachineName(LOGIN_USERNAME), platform_type: EAuthTokenPlatformType.SteamClient, os_type: 20, gaming_device_type: 1,