seishun / node-steam

Interface directly with Steam servers from Node.js
MIT License
1k stars 181 forks source link

Can't login when using sentry hash #370

Closed serge1peshcoff closed 8 years ago

serge1peshcoff commented 8 years ago

So, I am trying to write a bot using this module. I want to login use 2FA. It works, when I provide an two_factor_code, but fails if I provide only sha_sentryfile with error_code 85. Here is my code:

var authCode = '<code>'; // code received by email
var logOnOptions = {
  account_name: '<account_name>',
  password: '<password>'
};

try
{
  logOnOptions.sha_sentryfile = getSHA1(fs.readFileSync('sentry'));
}
catch (e) {
  logOnOptions.two_factor_code = authCode;
}
console.log(logOnOptions);

var steamClient = new Steam.SteamClient();
var steamUser = new Steam.SteamUser(steamClient);
var steamFriends = new Steam.SteamFriends(steamClient);
var steamWebLogOn = new SteamWebLogOn(steamClient, steamUser);

....

steamClient.on('logOnResponse', function(logonResp) {
  console.log(xinspect(logonResp));
  if (logonResp.eresult === Steam.EResult.OK) {
    console.log('Logged in!');
    steamFriends.setPersonaState(Steam.EPersonaState.Online);
  }
});

steamClient.on('error', function(res1, res) {

});

steamUser.on('updateMachineAuth', function(sentry, callback) {
  fs.writeFileSync('sentry', sentry.bytes);
  callback({ sha_file: getSHA1(sentry.bytes) });
});

function getSHA1(bytes) {
  var hash = crypto.createHash('sha1');
  hash.update(bytes);
  return hash.digest();
}

When I use geniune two_factor_code, here is the output:

"eresult" (number) => 1
"out_of_game_heartbeat_seconds" (number) => 9
"in_game_heartbeat_seconds" (number) => 9
"public_ip" (number) => 3642354822
"rtime32_server_time" (number) => 1466950413
"account_flags" (number) => 2637957
"cell_id" (number) => 7
"webapi_authenticate_user_nonce" (string) => pTWPAwyCxYPKYhVrIYg
"cell_id_ping_threshold" (number) => 11
"use_pics" (boolean) => true
"vanity_url" (string) => 
"client_supplied_steamid" (string) => <steam_id_here>
"ip_country_code" (string) => RU
"count_loginfailures_to_migrate" (number) => 0
"count_disconnects_to_migrate" (number) => 0
"client_instance_id" (string) => <instance_id_here>

But when sentry file is present, here is what I am getting:

"eresult" (number) => 85
"eresult_extended" (number) => 85
"client_supplied_steamid" (string) => <steam_id_here>
"count_loginfailures_to_migrate" (number) => 0
"count_disconnects_to_migrate" (number) => 0

What am I doing wrong, if so?

seishun commented 8 years ago

AFAIK you need to provide two_factor_code every time. EResult values can be found here.

Closing since this is a Steam protocol issue rather than a library issue.

scholtzm commented 8 years ago

Just fyi, once you switch to 2FA, sentry file serves no purpose and is basically ignored.

seishun commented 8 years ago

@scholtzm Perhaps you would be interested in adding this information to the wiki?

scholtzm commented 8 years ago

Added a short note.

yesworld commented 5 years ago

AFAIK you need to provide two_factor_code every time. EResult values can be found here.

Is it possible to somehow save 2FA on the server?

scholtzm commented 5 years ago

@yesworld You can generate 2FA codes programatically with steam-totp.

yesworld commented 5 years ago

Thanks for the answer! Last questions, how can I get shared_secret to generate through the steam-totp?

2FA should be used every time the bot is restarted? Or I somehow can save the session, so I don't have to generate the code every time? Similar to option logOnOptions.sha_sentryfile..