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 diff --git a/src/AuthenticationClient.ts b/src/AuthenticationClient.ts index 9e1c5bc..7206ba3 100644 --- a/src/AuthenticationClient.ts +++ b/src/AuthenticationClient.ts @@ -19,7 +19,7 @@ import { createMachineId, decodeJwt, eresultError, - getSpoofedHostname, + createMachineName, isJwtValidForAudience } from './helpers'; import { @@ -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 || createMachineName(details.accountName); + } + let {websiteId, deviceDetails} = this._getPlatformData(); let data:CAuthentication_BeginAuthSessionViaCredentials_Request_BinaryGuardData = { @@ -121,15 +127,6 @@ 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); - } - } - if (details.steamGuardMachineToken) { if (Buffer.isBuffer(details.steamGuardMachineToken)) { data.guard_data = details.steamGuardMachineToken; @@ -355,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', @@ -387,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 } : {}) } }; diff --git a/src/helpers.ts b/src/helpers.ts index 893fc32..129d819 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 createMachineName(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++) { diff --git a/test/LoginSession.test.ts b/test/LoginSession.test.ts index a5216db..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(), + 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(), + device_friendly_name: createMachineName(LOGIN_USERNAME), platform_type: EAuthTokenPlatformType.SteamClient, os_type: 20, gaming_device_type: 1,