예제 #1
0
        public async Task <bool> AuthenticateAsync(ulong steamId, SteamClient client, string myLoginKey)
        {
            mToken           = mTokenSecure = "";
            mSessionId       = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamId.ToString()));
            mCookieContainer = new CookieContainer();
            KeyValue response;

            using (WebAPI.AsyncInterface iSteamUserAuth = client.Configuration.GetAsyncWebAPIInterface("ISteamUserAuth"))
            {
                // generate an AES session key
                var sessionKey = CryptoHelper.GenerateRandomBlock(32);

                // rsa encrypt it with the public key for the universe we're on
                byte[] cryptedSessionKey = null;
                using (RSACrypto rsa = new RSACrypto(KeyDictionary.GetPublicKey(client.Universe)))
                {
                    cryptedSessionKey = rsa.Encrypt(sessionKey);
                }

                byte[] loginKey = Encoding.UTF8.GetBytes(myLoginKey);

                // aes encrypt the loginkey with our session key
                byte[] cryptedLoginKey = CryptoHelper.SymmetricEncrypt(loginKey, sessionKey);

                try
                {
                    response = await iSteamUserAuth.CallAsync(
                        HttpMethod.Post, "AuthenticateUser", args : new Dictionary <string, object>(3, StringComparer.Ordinal)
                    {
                        { "encrypted_loginkey", cryptedLoginKey },
                        { "sessionkey", cryptedSessionKey },
                        { "steamid", client.SteamID.ConvertToUInt64() }
                    });
                }
                catch (TaskCanceledException e)
                {
                    mToken = mTokenSecure = null;
                    return(false);
                }
                catch (Exception e)
                {
                    mToken = mTokenSecure = null;
                    return(false);
                }

                mToken       = response["token"].AsString();
                mTokenSecure = response["tokensecure"].AsString();

                mCookieContainer.Add(new Cookie("sessionid", mSessionId, String.Empty, mSteamCommunityDomain));
                mCookieContainer.Add(new Cookie("steamLogin", mToken, String.Empty, mSteamCommunityDomain));
                mCookieContainer.Add(new Cookie("steamLoginSecure", mTokenSecure, String.Empty, mSteamCommunityDomain));

                return(true);
            }
        }
예제 #2
0
        public async Task DoesntThrowWhenCorrectFormatInArgsProvided()
        {
            var hookableHandler = new HookableHandler();
            var configuration   = SteamConfiguration.Create(c => c.WithHttpClientFactory(() => new HttpClient(hookableHandler)));

            WebAPI.AsyncInterface iface = configuration.GetAsyncWebAPIInterface("IFooService");

            var args = new Dictionary <string, object>
            {
                ["f"]      = "foo",
                ["b"]      = "bar",
                ["format"] = "vdf"
            };

            await iface.CallAsync(HttpMethod.Get, "GetFoo", args : args);
        }