Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update spoofed hostname #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions src/AuthenticationClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
createMachineId,
decodeJwt,
eresultError,
getSpoofedHostname,
createMachineName,
isJwtValidForAudience
} from './helpers';
import {
Expand Down Expand Up @@ -109,6 +109,12 @@ export default class AuthenticationClient extends EventEmitter {
}

async startSessionWithCredentials(details: StartAuthSessionWithCredentialsRequest): Promise<StartAuthSessionWithCredentialsResponse> {
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 = {
Expand All @@ -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;
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 } : {})
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
6 changes: 3 additions & 3 deletions test/LoginSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down