Короче, я студент-первокурсник, и количество опыта пока не позволяет мне переписать собственный стимовский шифратор из rsa.js, а то, что я нашёл не работает(
Видел вроде как рабочие решения на C#, но его я не знаю, а C+\CLI так-же требует времени.
Возможно, проблема не в этом.
Вообще, по всей видимости, сам запрос неверный, ибо даже при отрицательном ответе должно выдавать что-то больше, чем просто "success:false" (что-то про каптчу и ещё какую-то хрень).
Собственно, вот сам говнокод (думал всё красивенько оформить с использованием классов, но уже который день долблюсь с авторизацией :faceonwall: )
Код: Выделить всё
#pragma comment(lib, "libcurl.lib")
#pragma comment(lib, "lib_json.lib")
//#pragma comment(lib, "cryptlib.lib")
#include <stdio.h>
#include <curl.h>
#include <stdlib.h>
//#include <stdlib.h>
#include <iostream>
#include <string>
#include <fstream>
#include <locale.h>
//#include <stdlib.h>
#include <json.h>
#include <writer.h>
//#include "Rsa.h"
//#include <msclr/marshal_cppstd.h>
#include <iostream>
#include <string>
#include <Windows.h>
//#include <atltime.h>
#include <time.h>
//using namespace Rsacs;
using namespace std;
typedef void (WINAPI * LPFN_set_Exponent) (const char *);
typedef void (WINAPI * LPFN_set_Modulus) (const char *);
typedef char* (WINAPI * LPFN_Encrypt) (const char *);
// Write all expected data in here
static string buffer;
// This is the writer call back function used by curl
static int writer(char *data, size_t size, size_t nmemb, string *buffer)
{
int result = 0;
if (buffer != NULL)
{
buffer->append(data, size * nmemb);
result = size * nmemb;
}
return result;
}
int main()
{
HINSTANCE hMyDLL = LoadLibrary("DllRsaCS.dll");
if (NULL == hMyDLL)
{
std::cout << "LoadLibrary failed\n";
getchar();
return -1;
}
LPFN_set_Exponent SetExponent = (LPFN_set_Exponent)GetProcAddress(hMyDLL, "set_Exponent");
if (NULL == SetExponent)
{
std::cout << "GetProcAddress set_Exponent failed\n";
getchar();
return -2;
}
LPFN_set_Modulus SetModulus = (LPFN_set_Modulus)GetProcAddress(hMyDLL, "set_Modulus");
if (NULL == SetModulus)
{
std::cout << "GetProcAddress set_Modulus failed\n";
getchar();
return -3;
}
LPFN_Encrypt Encrypt = (LPFN_Encrypt)GetProcAddress(hMyDLL, "Encrypt");
if (NULL == Encrypt)
{
std::cout << "GetProcAddress Encrypt failed\n";
getchar();
return -4;
}
string login = "1337test666";
string password = "simplepassword666!!!";
Json::Value forDoLogin;
forDoLogin["username"] = login;
forDoLogin["donotcache"] = to_string(time(NULL) * 1000);
Json::FastWriter JSwriter;
//JSwriter.write(forDoLogin);
ofstream file("file.html");
CURL *handle = curl_easy_init();
if (!handle) { cout << "handle error"; file << endl << "HOMEhandle error"; getchar(); return 0; }
curl_easy_setopt(handle, CURLOPT_HEADER, 0);
curl_easy_setopt(handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0");
curl_easy_setopt(handle, CURLOPT_ENCODING, "gzip,deflate"); // Принудительно ставим gzip
curl_easy_setopt(handle, CURLOPT_COOKIEJAR, "cookie.txt"); // указываем имя файла для хранения и считывания cookies-файлов
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, "cookie.txt");
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); // не проверять SSL сертификат
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0); // не проверять Host SSL сертификата
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 3);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buffer);
static char ErrorBuffer3[CURL_ERROR_SIZE];
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, ErrorBuffer3);
curl_easy_setopt(handle, CURLOPT_URL, "https://steamcommunity.com/login/home"); //store.steampowered.com
CURLcode res = curl_easy_perform(handle);
if (res != CURLE_OK)
{
cout << "Error!" << ErrorBuffer3 << endl;
getchar();
return 0;
}
//file << buffer;
buffer.clear();
curl_easy_cleanup(handle);
handle = curl_easy_init();
if (!handle) { cout << "RSAhandle error"; getchar(); file << endl << "RSAhandle error"; return 0; }
curl_easy_setopt(handle, CURLOPT_HEADER, 0);
curl_easy_setopt(handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0");
curl_easy_setopt(handle, CURLOPT_ENCODING, "gzip,deflate"); // Принудительно ставим gzip
curl_easy_setopt(handle, CURLOPT_COOKIEJAR, "cookie.txt"); // указываем имя файла для хранения и считывания cookies-файлов
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, "cookie.txt");
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); // не проверять SSL сертификат
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0); // не проверять Host SSL сертификата
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 3);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buffer);
static char ErrorBuffer[CURL_ERROR_SIZE];
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, ErrorBuffer);
string post_data = "username=" + login;
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, post_data.c_str());
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, post_data.length());
curl_easy_setopt(handle, CURLOPT_URL, "https://steamcommunity.com/login/getrsakey/"); //store.steampowered.com
res = curl_easy_perform(handle);
if (res != CURLE_OK)
{
cout << "Error!" << ErrorBuffer << endl;
file << endl << "Error!" << ErrorBuffer << endl;
getchar( );
return 0;
}
file << buffer;
Json::Value retJson; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse(buffer, retJson);
if (!parsingSuccessful)
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration\n" << reader.getFormatedErrorMessages();
file << endl << "Failed to parse configuration\n" << reader.getFormatedErrorMessages();
return 0;
}
if (retJson["success"].asString()!="true")
{
cout << "getRSAKey: "<<retJson["success"];
file << endl << "getRSAKey: " << retJson["success"];
getchar();
return 0;
}
// string exp = retJson["publickey_exp"].toStyledString( );
// string mod = retJson["publickey_mod"].toStyledString( );
SetExponent(retJson["publickey_exp"].toStyledString().c_str());
SetModulus(retJson["publickey_mod"].toStyledString().c_str()); //
string encryptetPassword = Encrypt(password.c_str());
//delete &password;
FreeLibrary(hMyDLL);
buffer.clear( );
curl_easy_cleanup(handle);
//-----------------------------------------------------------2222222222222
//CTime tm = CTime::GetCurrentTime();
forDoLogin["password"] = encryptetPassword;
forDoLogin["rsatimestamp"] = retJson["timestamp"];
forDoLogin["remember_login"] = "true";
forDoLogin["captchagid"] = -1;
forDoLogin["emailauth"]="";
forDoLogin["emailsteamid"]="";
forDoLogin["loginfriendlyname"]="";
forDoLogin["captcha_text"]="";
post_data = "username=" + login + "&password=" + encryptetPassword + "&emailauth=&captchagid=-1&captcha_text=&emailsteamid=&rsatimestamp=" + retJson["timestamp"].toStyledString( );
//post_data = JSwriter.write(forDoLogin);
//post_data = "username=" + login + "&password=" + encryptetPassword + "&rsatimestamp=" + retJson["timestamp"].toStyledString( );
//post_data = "a";
//post_data = ""
//post_data = "{\"donotcache\":\"" + forDoLogin["donotcache"].toStyledString() + "\",\"password\":" + forDoLogin["password"].toStyledString() + "\",\"rsatimestamp\":\"" + forDoLogin["rsatimestamp"].toStyledString() + "\,\"username\":\"" + login;
cout << post_data;
file << endl<<post_data;
//"{\"donotcache\":\"1398173411000\",\"password\":\"HzMGm0mk9QCg0OL1pDTuC1Z0I9nxq40uuXJGXPF7NClMQliCDrAgWvyeYwORp/4OgJeXVK9v6bEHnOPjYFAzrRlWsvi01ysd4obKae4Z3ooBOSXFFPaLk9+pEAgbhw+C581ENtd0nD/jQtP8aqpcH1eHZrRxU+... std::basic_string<char,std::char_traits<char>,std::allocator<char> >
//"{\n \"donotcache\" : \"1398173558000\",\n \"password\" : \"CSI5FI8UBiS9kMfUOON/IMjiO2yvcOC3BNUt9tFVlfIr275JWaF7U3LIdN1hdlHihQmY1/ENcf2Gl8ZQS8IsQnUPu8qsyOOzQAaIRcpbTD32Gl6wrjZ9AkMrRlYSiRUHScTURUL1DQx2S2u3gf... std::basic_string<char,std::char_traits<char>,std::allocator<char> >
//char post_data2[] = new char(writer.write(forDoLogin).c_str());
handle = curl_easy_init();
if (!handle) { cout << "handle error"; file << endl<<"handle error"; getchar(); return 0; }
curl_easy_setopt(handle, CURLOPT_HEADER, 0);
curl_easy_setopt(handle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0");
curl_easy_setopt(handle, CURLOPT_ENCODING, "gzip,deflate"); // Принудительно ставим gzip
curl_easy_setopt(handle, CURLOPT_COOKIEJAR, "cookie.txt"); // указываем имя файла для хранения и считывания cookies-файлов
curl_easy_setopt(handle, CURLOPT_COOKIEFILE, "cookie.txt");
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0); // не проверять SSL сертификат
curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 0); // не проверять Host SSL сертификата
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 3);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, &buffer);
//static char ErrorBuffer[CURL_ERROR_SIZE];
curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, ErrorBuffer);
//string post_data = forDoLogin_s;
curl_easy_setopt(handle, CURLOPT_POSTFIELDS,post_data.c_str());
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, post_data.length());
curl_easy_setopt(handle, CURLOPT_URL, "https://steamcommunity.com/login/dologin/"); //
CURLcode res2 = curl_easy_perform(handle);
if (res != CURLE_OK)
{
cout << "Error!" << ErrorBuffer << endl;
file <<endl<< "Error!" << ErrorBuffer << endl;
getchar();
return 0;
}
retJson.clear( );
parsingSuccessful = reader.parse(buffer, retJson);
if (!parsingSuccessful)
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration\n" << reader.getFormatedErrorMessages();
file << endl << "Failed to parse configuration\n" << reader.getFormatedErrorMessages();
return 0;
}
if (retJson["success"].asString() != "true")
{
cout <<"doLogin: "<<retJson["success"]<<"azazazazazasykablyat\'";
file << endl << "doLogin: " << retJson["success"];
//getchar();
//return 0;
}
file << buffer;
file.close();
buffer.clear();
curl_easy_cleanup(handle);
//Json::StyledWriter writer;
cout << "End."<< endl;
file << endl << "End." << endl;
getchar( );
return 0;
}
То самое решение на C#
Помогите, слишком много времени потратил, чтобы просто так забить.