seishun / node-steam

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

Get the sentry data and directly testing them #400

Closed Mediumwater closed 7 years ago

Mediumwater commented 7 years ago

Hello, i'm trying to get the sentry and directly testing it. When i execute the following code it leads to an AccountLogonDenied eresult. Maybe i do understand something wrong. The generated sentry file is also in other Programms not useable (i used in the other Programm crypto on the fileread result) Can you help me?

` var Steam = require("steam"); var fs = require("fs"); var readline = require("readline"); var crypto = require('crypto');

var steamClient = new Steam.SteamClient(); var steamUser = new Steam.SteamUser(steamClient);

var username; var password; var authCode = ""; var sentryfile;

var rl = readline.createInterface({ input: process.stdin, output: process.stdout });

rl.question("Username: ", function(answer) { username = answer; rl.question("Password: ", function(answer2) { password = answer2; rl.pause(); steamClient.connect(); }); });

steamClient.on('connected', function() { if (authCode == "") { console.log("> Logging in with only username and password"); steamUser.logOn({ account_name: username, password: password }); } else if (fs.existsSync("./sentry/" + username + '.sentry')){ sentryfile = fs.readFileSync("./sentry/" + username + '.sentry'); sha = MakeSha(sentryfile); console.log(sha); console.log("> Logging in with sentry"); steamUser.logOn({ account_name: username, password: password, sha_sentryfile: sha }); } else { console.log("> Logging in with Steam Guard code"); steamUser.logOn({ account_name: username, password: password, auth_code: authCode }); } });

steamClient.on("logOnResponse", function(result) { if (result.eresult == Steam.EResult.OK) { console.log("successfully logged in"); if (authCode !== "" && fs.existsSync("./sentry/" + username + '.sentry')) process.exit(); } if (result.eresult == Steam.EResult.AccountLogonDenied) { rl.resume(); rl.question("Steam guard code: ", function(answer) { authCode = answer; steamClient.disconnect(); steamClient.connect(); rl.pause(); }); } else { console.log("eresult " + result.eresult); }; });

steamClient.on("error", function(error) { });

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

steamUser.on('updateMachineAuth', function(sentry, callback) { console.log("sentry saved"); var file = "./sentry/" + username + ".sentry"; fs.writeFileSync(file, sentry.bytes); //steamClient.connect(); callback({sha_file: crypto.createHash('sha1').update(sentry.bytes).digest()}); steamClient.connect(); }); `

Mediumwater commented 7 years ago

I did not try it, but is it possible to say eresult=1, instead of this sha_file stuff? message CMsgClientUpdateMachineAuthResponse { optional string filename = 1; optional uint32 eresult = 2; optional uint32 filesize = 3; optional bytes sha_file = 4; optional uint32 getlasterror = 5; optional uint32 offset = 6; optional uint32 cubwrote = 7; optional int32 otp_type = 8; optional uint32 otp_value = 9; optional string otp_identifier = 10; }

seishun commented 7 years ago

You can format code in issues, it makes it much more readable.

callback({sha_file: crypto.createHash('sha1').update(sentry.bytes).digest()});
steamClient.connect();

I'm guessing this is causing your issue. connect() disconnects from Steam and Steam probably doesn't register your hash in time. Try waiting a few seconds before reconnecting.

I did not try it, but is it possible to say eresult=1, instead of this sha_file stuff?

Who knows, try it and see. Feel free to add your investigation results in the wiki.

Mediumwater commented 7 years ago

At the end i'm waiting for 5 sec before reconnecting and it do work. Maybe just today, but 5 sec is a lot of time, so lets see. Thank you very much 👍

mk-pmb commented 6 years ago

I tried firing the callback with a string of 40 hex digits in the sha_file property and it had no effect. Does your code above mean the SHA1 should be transmitted as 20 raw bytes? Could you add that in the description of the updateMachineAuth event and the CMsgClientLogon message plese?

Update: Looks like sending the hash as 20 raw bytes works, but it will take a few minutes for the newly confirmed sentry hash to become valid.