Pergunta

I'm using QT 5.0.2 prebuilt and QT creator 2.7.0 and my goal is to login to steam network programmatically using uname, password and steamguard code. Or to be more precise: get QNetworkAccessManager from its initial uninitialized state to the state where it could retrieve any data from steam related sites as if it was logged in as some user.

So the login happens in 4 steps (4 request-response combos): NOTE: Steam site javascript uses post in all requests, but it seems that get also works. Assume username "hyper"

1. Initial request:

post https://store.steampowered.com/login/getrsakey/?username=hyper

Here is my function:

void http::steam_auth(const QString &uname, const QString &pwd)
{
    QString encrypted_password, sg, pkey_exp, pkey_mod, timestamp, emailsteamid;
    QJsonDocument json_buffer;
    QByteArray buffer;
    QUrl rsa(steam_getrsa), login(steam_dologin); //steam login urls
    QUrlQuery urlquery;

Here we send our request:

  urlquery.addQueryItem("username", uname); //first step
    urlquery.addQueryItem("l", "english"); //set communication language
    rsa.setQuery(urlquery);
    QNetworkRequest first(rsa);
    QNetworkReply *reply = this->get(first);
    buffer = reply->readAll();

As a response we get:

{"success":true,"publickey_mod":"AC41A964789638B6A3B3BD5ADD9F3680FA45881C70FD2032B10A3BB6D2ACF021C2B3D564DC44DE3054E3BF78A1753399223C794A0DED03A76CD1F1DFE851E30F0D6F14484C258EB6053676A47D20A68E11ECCD783F343594DDA3817AA5DCCE75FAF5C68BB197DA1FF12F22F9FCD83624D00A23CC57A367563ADBBCEDF5C8742A57B12A4BD04DC02A55C80F4F6984B1E2D5A99081510326E1C6BAB2C2723560487E8F7EA1A2CB55AEFC5594C9FBB71CAD553CB2D866214BC41156259FEC55362D38DCDBE8FADFB577FE0736CE3E37AF6D2CDDF28FA218C1E477E29B17713BFC48A227455B6B0DE09884CC0820CE40CD4877D93704D00E20A235FCF55D100A01C1","publickey_exp":"010001","timestamp":"284691100000"}

Which means everything is ok. Now we need to encrypt our password before sending it

json_buffer = QJsonDocument::fromJson(buffer);
pkey_exp = json_buffer.object().value("publickey_exp").toString();
pkey_mod = json_buffer.object().value("publickey_mod").toString();
timestamp = json_buffer.object().value("timestamp").toString();
delete reply;
urlquery.clear();
encrypted_password = app::core::get_encrypted_password(pwd, pkey_exp, pkey_mod);

2. Send encrypted password:

urlquery.addQueryItem("username", uname);
urlquery.addQueryItem("password", encrypted_password);
urlquery.addQueryItem("emailauth", "");
urlquery.addQueryItem("captchagid", "");
urlquery.addQueryItem("captcha_text", "");
urlquery.addQueryItem("emailsteamid", "");
urlquery.addQueryItem("rsatimestamp", timestamp);
urlquery.addQueryItem("remember_login", "false");
login.setQuery(urlquery);
QNetworkRequest second(login);
second.setUrl(login);
reply = this->get(second);
buffer = reply->readAll();

We get a request string as follows:

post https://store.steampowered.com/login/dologin/?username=solidbeetle2&password=YmhTKVkRXyiCYe6wx+ZJ8PIhzj4A4BLWgJFOE5ge7nbIAM6m1G9qHh+Iqx30ZLdB0wW0xdWDNCgHBNPHKLA+P2pYhPF0DeL9v8UQsers6NCNNPZ0SFN4HhNlu6Gwh8QAjrNykev7N5FADXwJnFjPBvmvthATmrktVEtFYF54lckaPnijXYSDIpfEjmG8+bCDKT/GLaUiftA2QauUY9ap8WHSEoykiTmfL344ghzjhCA33UKx0NIgBrDdI1RLfHVcmAcU/c9NEhoHLOT93n8hqWY+YVx9VbOcKqqZPrbCiQoU2BZrqK6N7aj+K6kH0VWHH7+LD2KJx4BUJgHOmNqVDg%3D%3D&emailauth=&captchagid=&captcha_text=&emailsteamid=&rsatimestamp=50693150000&remember_login=false

It is perfectly valid as far as I can tell, JS on steam site sends ajax with the same, but... Here is the problem When I get a response with this it says message:Invalid login in json... But if I save the full query string from my request to file and then paste it either in browser or in HTTP Request builder inside HTTP Analyzer, it works fine displaying message:SteamGuard What could be wrong? Is there something I'm missing? Does QNetworkAccessManager break this somehow?:c Sorry if something is not clear, I'll try my best to explain again if needed. Thanks in advance!

P.S. Is there any solid way to examine requests my app is sending?

P.S.S. my qt creator seems to crash when debugging projects with qml option, idk why...

Foi útil?

Solução

I have inspected all this stuff and finally was able to achieve my goal. In short the problem was in qt's web-oriented classes. It seemed obvious that qurlquery should encode characters such as / or = in their %-encoded form.. but it is NOT the case, therefore I had to replace them manually in QString. If someone needs a working routine, it can be found here (Its not pretty :c)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top