コード例 #1
0
ファイル: evp_pkey.cpp プロジェクト: BobLC/liblogicalaccess
		EVPPKey EVPPKey::discardPrivateCompound() const
		{
			if (hasPrivateCompound())
			{
				if (type() == EVP_PKEY_RSA)
				{
					return createFromRSAKey(rsaKey().discardPrivateCompound());
				}

				throw Exception::bad_function_call("Unsupported key type");
			}
			else
			{
				return *this;
			}
		}
コード例 #2
0
ファイル: WebAPI.cpp プロジェクト: popoklopsi/MessageBot
Json::Value WebAPI::LoginSteamCommunity(std::string username, std::string password) {
    Debug("[DEBUG] Trying to login to the steam community");

    Json::Value result;
    Json::Reader reader;

    // First add needed cookies
    this->AddCookie(this->steamCommunityClient, MOBILE_CLIENT_COOKIE);
    this->AddCookie(this->steamCommunityClient, MOBILE_CLIENT_VERSION_COOKIE);
    this->AddCookie(this->steamCommunityClient, LANGUAGE_COOKIE);

    // Notify steam that we need oauth
    std::string sessionPage = "https://steamcommunity.com/mobilelogin?oauth_client_id=" + this->urlencode(CLIENT_ID) + "&oauth_scope=" + this->urlencode(CLIENT_SCOPE);

    WriteDataInfo pageInfo = this->GetPage(this->steamCommunityClient, sessionPage, USER_AGENT_ANDROID, nullptr);
    if (!pageInfo.error.empty()) {
        result["success"] = false;
        result["error"] = "Failed to receive SteamCommunity RSA key. Error: '" + pageInfo.error + "'";
        return result;
    }

    // Get the RSA key to login
    long long time = std::chrono::system_clock::now().time_since_epoch().count();
    pageInfo = this->GetPage(this->steamCommunityClient, "https://steamcommunity.com/mobilelogin/getrsakey", USER_AGENT_ANDROID,
                             "username=%s&donotcache=%lld", const_cast<char *>(this->urlencode(username).c_str()), time);

    // Check for errors
    if (!pageInfo.error.empty()) {
        result["success"] = false;
        result["error"] = "Failed to receive SteamCommunity RSA key. Error: '" + pageInfo.error + "'";
        return result;
    }

    result.clear();
    if (!reader.parse(pageInfo.content, result)) {
        result["success"] = false;
        result["error"] = "Failed to parse SteamCommunity RSA key. Error: '" + reader.getFormattedErrorMessages() + "'";
        return result;
    }

    if (!result.get("success", false).asBool()) {
        std::string json = result.toStyledString();

        result["error"] = "Failed to get SteamCommunity RSA key. JSON: '" + json + "'";
        return result;
    }

    // Read RSA information
    std::string mod = result.get("publickey_mod", "").asString();
    std::string exp = result.get("publickey_exp", "").asString();
    std::string timestamp = result.get("timestamp", "").asString();

    if (mod.empty() || exp.empty() || timestamp.empty()) {
        result["success"] = false;
        result["error"] = "Failed to get SteamCommunity RSA Key information. Got: (mod, exp, timestamp) -> (" + mod + ", " + exp + ", " + timestamp + ")";
        return result;
    }

    // Now encrypt it with RSA
    RSAKey rsaKey(mod.c_str(), exp.c_str());
    std::string encrypted = rsaKey.Encrypt(password.c_str());

    // And login with it
    pageInfo = this->GetPage(this->steamCommunityClient, "https://steamcommunity.com/mobilelogin/dologin/", USER_AGENT_ANDROID,
                             "donotcache=%lld&password=%s&username=%s&twofactorcode=&emailauth=&loginfriendlyname=CallAdmin&captchagid=-1&captcha_text=&emailsteamid=&rsatimestamp=%s&remember_login=true&oauth_client_id=%s",
                             time, this->urlencode(encrypted).c_str(), this->urlencode(username).c_str(), timestamp.c_str(), CLIENT_ID);

    // Check for errors
    if (!pageInfo.error.empty()) {
        result["success"] = false;
        result["error"] = "Failed to login. Error: '" + pageInfo.error + "'";
        return result;
    }

    result.clear();
    if (!reader.parse(pageInfo.content, result)) {
        result["success"] = false;
        result["error"] = "Failed to parse login result. Error: '" + reader.getFormattedErrorMessages() + "'";
        return result;
    }

    if (!result.get("success", false).asBool() || !result.get("login_complete", false).asBool()) {
        std::string json = result.toStyledString();

        result["success"] = false;
        result["error"] = "Failed to successfully login. JSON: '" + json + "'";
        return result;
    }

    // Read oauth from result
    std::string auth = result.get("oauth", "").asString();
    if (auth.empty()) {
        result["success"] = false;
        result["error"] = "Got empty oauth!";
        return result;
    }

    result.clear();
    if (!reader.parse(auth, result)) {
        result["success"] = false;
        result["error"] = "Failed to parse oauth token. Error: '" + reader.getFormattedErrorMessages() + "'";
        return result;
    }

    // And from there read steamid and oauth token
    if (result.get("steamid", "").asString().empty() || result.get("oauth_token", "").asString().empty()) {
        result["success"] = false;
        result["error"] = "Failed to get login steamid or oauth. Got: '" + auth + "'";
        return result;
    }

    Debug("[DEBUG] Logged in succesfully");

    result["success"] = true;
    return result;
}