public void InstancedSet(AccountId accountId, uint unInstance, EUniverse eUniverse, EAccountType eAccountType)
 {
     SetAccountId(accountId);
     SetEUniverse(eUniverse);
     SetEAccountType(eAccountType);
     SetAccountInstance(unInstance);
 }
Esempio n. 2
0
        public static byte[] GetPublicKey( EUniverse eUniverse )
        {
            if ( keys.ContainsKey( eUniverse ) )
                return keys[ eUniverse ];

            return keys[ EUniverse.Invalid ];
        }
Esempio n. 3
0
 public void InstancedSet( UInt32 unAccountID, UInt32 unInstance, EUniverse eUniverse, EAccountType eAccountType )
 {
     this.AccountID = unAccountID;
     this.AccountUniverse = eUniverse;
     this.AccountType = eAccountType;
     this.AccountInstance = unInstance;
 }
Esempio n. 4
0
        public void UnknownAccountUniversesAreInvalid(EUniverse universe)
        {
            SteamID sid = 76561198074261126;

            sid.AccountUniverse = universe;
            Assert.False(sid.IsValid);
        }
Esempio n. 5
0
        /// <summary>
        /// Sets the various components of this SteamID from a Steam2 "STEAM_" rendered form and universe.
        /// </summary>
        /// <param name="steamId">A "STEAM_" rendered form of the SteamID.</param>
        /// <param name="eUniverse">The universe the SteamID belongs to.</param>
        /// <returns><c>true</c> if this instance was successfully assigned; otherwise, <c>false</c> if the given string was in an invalid format.</returns>
        public bool SetFromString(string steamId, EUniverse eUniverse)
        {
            if (string.IsNullOrEmpty(steamId))
            {
                return(false);
            }

            Match m = Steam2Regex.Match(steamId);

            if (!m.Success)
            {
                return(false);
            }

            uint accId, authServer;

            if (!uint.TryParse(m.Groups["accountid"].Value, out accId) ||
                !uint.TryParse(m.Groups["authserver"].Value, out authServer))
            {
                return(false);
            }

            this.AccountUniverse = eUniverse;
            this.AccountInstance = 1;
            this.AccountType     = EAccountType.Individual;
            this.AccountID       = (accId << 1) | authServer;

            return(true);
        }
Esempio n. 6
0
 /// <summary>
 /// Sets the various components of this SteamID instance.
 /// </summary>
 /// <param name="unAccountID">The account ID.</param>
 /// <param name="unInstance">The instance.</param>
 /// <param name="eUniverse">The universe.</param>
 /// <param name="eAccountType">The account type.</param>
 public void InstancedSet(UInt32 unAccountID, UInt32 unInstance, EUniverse eUniverse, EAccountType eAccountType)
 {
     this.AccountID       = unAccountID;
     this.AccountUniverse = eUniverse;
     this.AccountType     = eAccountType;
     this.AccountInstance = unInstance;
 }
Esempio n. 7
0
        public void KnownAccountUniversesAreValid(EUniverse universe)
        {
            SteamID sid = 76561198074261126;

            sid.AccountUniverse = universe;
            Assert.True(sid.IsValid);
        }
		public CSteamID(AccountID_t unAccountID, uint unAccountInstance, EUniverse eUniverse, EAccountType eAccountType) {
			m_SteamID = 0;
#if _SERVER && Assert
		Assert( ! ( ( EAccountType.k_EAccountTypeIndividual == eAccountType ) && ( unAccountInstance > k_unSteamUserWebInstance ) ) );	// enforce that for individual accounts, instance is always 1
#endif // _SERVER
			InstancedSet(unAccountID, unAccountInstance, eUniverse, eAccountType);
		}
Esempio n. 9
0
 public void CreateBlankAnonUserLogon(EUniverse eUniverse)
 {
     SetAccountID(new AccountID_t(0));
     SetEUniverse(eUniverse);
     SetEAccountType(EAccountType.k_EAccountTypeAnonUser);
     SetAccountInstance(0);
 }
Esempio n. 10
0
 public void CreateBlankAnonLogon(EUniverse eUniverse)
 {
     this.SetAccountID(new AccountID_t(0u));
     this.SetEUniverse(eUniverse);
     this.SetEAccountType(EAccountType.k_EAccountTypeAnonGameServer);
     this.SetAccountInstance(0u);
 }
Esempio n. 11
0
 public void InstancedSet(AccountID_t unAccountID, uint unInstance, EUniverse eUniverse, EAccountType eAccountType)
 {
     SetAccountID(unAccountID);
     SetEUniverse(eUniverse);
     SetEAccountType(eAccountType);
     SetAccountInstance(unInstance);
 }
 public void CreateBlankAnonLogon(EUniverse eUniverse)
 {
     SetAccountId(new AccountId(0));
     SetEUniverse(eUniverse);
     SetEAccountType(EAccountType.AnonGameServer);
     SetAccountInstance(0);
 }
        public SteamId(AccountId accountId, uint unAccountInstance, EUniverse eUniverse, EAccountType eAccountType)
        {
            Id = 0;
#if _SERVER && Assert
            Assert(!((EAccountType.Individual == eAccountType) && (unAccountInstance > SteamUserWebInstance)));                 // enforce that for individual accounts, instance is always 1
#endif // _SERVER
            InstancedSet(accountId, unAccountInstance, eUniverse, eAccountType);
        }
Esempio n. 14
0
        public EnvelopeEncryptedConnection(IConnection inner, EUniverse universe)
        {
            this.inner    = inner ?? throw new ArgumentNullException(nameof(inner));
            this.universe = universe;

            inner.NetMsgReceived += OnNetMsgReceived;
            inner.Connected      += OnConnected;
            inner.Disconnected   += OnDisconnected;
        }
Esempio n. 15
0
        public static byte[] GetPublicKey(EUniverse eUniverse)
        {
            if (keys.ContainsKey(eUniverse))
            {
                return(keys[eUniverse]);
            }

            return(keys[EUniverse.Invalid]);
        }
Esempio n. 16
0
        /// <summary>
        /// Gets the public key for the given universe.
        /// </summary>
        /// <returns>The public key.</returns>
        /// <param name="eUniverse">The universe.</param>
        public static byte[]? GetPublicKey(EUniverse eUniverse)
        {
            if (keys.TryGetValue(eUniverse, out var key))
            {
                return(key);
            }

            return(keys[EUniverse.Invalid]);
        }
Esempio n. 17
0
        public EnvelopeEncryptedConnection( IConnection inner, EUniverse universe, ILogContext log, IDebugNetworkListener? debugNetworkListener )
        {
            this.inner = inner ?? throw new ArgumentNullException( nameof(inner) );
            this.universe = universe;
            this.log = log ?? throw new ArgumentNullException( nameof( log ) );
            this.debugNetworkListener = debugNetworkListener;

            inner.NetMsgReceived += OnNetMsgReceived;
            inner.Connected += OnConnected;
            inner.Disconnected += OnDisconnected;
        }
Esempio n. 18
0
		public void Set(AccountID_t unAccountID, EUniverse eUniverse, EAccountType eAccountType) {
			SetAccountID(unAccountID);
			SetEUniverse(eUniverse);
			SetEAccountType(eAccountType);

			if (eAccountType == EAccountType.k_EAccountTypeClan || eAccountType == EAccountType.k_EAccountTypeGameServer) {
				SetAccountInstance(0);
			}
			else {
				SetAccountInstance(Constants.k_unSteamUserDefaultInstance);
			}
		}
Esempio n. 19
0
 // Token: 0x060000BA RID: 186 RVA: 0x00002767 File Offset: 0x00000967
 public void Set(AccountID_t unAccountID, EUniverse eUniverse, EAccountType eAccountType)
 {
     SetAccountID(unAccountID);
     SetEUniverse(eUniverse);
     SetEAccountType(eAccountType);
     if (eAccountType == EAccountType.k_EAccountTypeClan || eAccountType == EAccountType.k_EAccountTypeGameServer)
     {
         SetAccountInstance(0u);
         return;
     }
     SetAccountInstance(1u);
 }
Esempio n. 20
0
 public void Set(AccountID_t unAccountID, EUniverse eUniverse, EAccountType eAccountType)
 {
     this.SetAccountID(unAccountID);
     this.SetEUniverse(eUniverse);
     this.SetEAccountType(eAccountType);
     if (eAccountType == EAccountType.k_EAccountTypeClan || eAccountType == EAccountType.k_EAccountTypeGameServer)
     {
         this.SetAccountInstance(0u);
     }
     else
     {
         this.SetAccountInstance(1u);
     }
 }
Esempio n. 21
0
        /// <summary>
        /// Sets the various components of this SteamID instance.
        /// </summary>
        /// <param name="unAccountID">The account ID.</param>
        /// <param name="eUniverse">The universe.</param>
        /// <param name="eAccountType">The account type.</param>
        public void Set(UInt32 unAccountID, EUniverse eUniverse, EAccountType eAccountType)
        {
            this.AccountID       = unAccountID;
            this.AccountUniverse = eUniverse;
            this.AccountType     = eAccountType;

            if (eAccountType == EAccountType.Clan || eAccountType == EAccountType.GameServer)
            {
                this.AccountInstance = 0;
            }
            else
            {
                this.AccountInstance = DesktopInstance;
            }
        }
Esempio n. 22
0
        public void Set(UInt32 unAccountID, EUniverse eUniverse, EAccountType eAccountType)
        {
            this.AccountID       = unAccountID;
            this.AccountUniverse = eUniverse;
            this.AccountType     = eAccountType;

            if (eAccountType == EAccountType.k_EAccountTypeClan)
            {
                this.AccountInstance = 0;
            }
            else
            {
                this.AccountInstance = 1;
            }
        }
Esempio n. 23
0
        public void Set( UInt32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
        {
            this.AccountID = unAccountID;
            this.AccountUniverse = eUniverse;
            this.AccountType = eAccountType;

            if ( eAccountType == EAccountType.k_EAccountTypeClan )
            {
                this.AccountInstance = 0;
            }
            else
            {
                this.AccountInstance = 1;
            }
        }
        public void Set(AccountId accountId, EUniverse eUniverse, EAccountType eAccountType)
        {
            SetAccountId(accountId);
            SetEUniverse(eUniverse);
            SetEAccountType(eAccountType);

            if (eAccountType == EAccountType.Clan || eAccountType == EAccountType.GameServer)
            {
                SetAccountInstance(0);
            }
            else
            {
                // by default we pick the desktop instance
                SetAccountInstance(Constants.SteamUserDesktopInstance);
            }
        }
Esempio n. 25
0
        public void ParseFromBuffer(BinaryReader reader)
        {
            if (_headerType != null)
            {
                // Version and universe are not present
                // on pure binary VDF files e.g coplay, so only read them here
                Version      = reader.ReadUInt32();
                UniverseType = (EUniverse)reader.ReadUInt32();

                // Ensure there is a supported version for the type
                if (!SupportedVersionMappings.Select(t => t.Key == _headerType && t.Value == Version).Any())
                {
                    throw new InvalidOperationException($"Unsupported binary VDF version: {Version}");
                }

                while (reader.BaseStream.Position != reader.BaseStream.Length)
                {
                    // If we have a terminator with 0 (for appinfo.vdf)
                    // or -1 (for packageinfo.vdf), no more sections to read
                    var terminator = reader.ReadUInt32();
                    if (_headerType == typeof(BinaryVdfAppHeader) &&
                        terminator == BinaryVdfAppHeader.Terminator)
                    {
                        break;
                    }
                    if (_headerType == typeof(BinaryVdfPackageHeader) &&
                        terminator == BinaryVdfPackageHeader.Terminator)
                    {
                        break;
                    }

                    // Rewind stream after peek
                    reader.BaseStream.Position = reader.BaseStream.Position - sizeof(uint);

                    // Create the node instance
                    var node = (IBinaryParseable)Activator.CreateInstance(_headerType);
                    node.ParseFromBuffer(reader);
                    Add(node);
                }
            }
            else
            {
                // No header type? Skip this entirely and parse raw keyvalues1.
                Add(KvSerializer.Create(KvSerializationFormat.KeyValues1Binary).Deserialize(new NonClosingStream(reader.BaseStream)));
            }
        }
Esempio n. 26
0
        void HandleEncryptRequest(IPacketMsg packetMsg)
        {
            var encRequest = new Msg <MsgChannelEncryptRequest>(packetMsg);

            EUniverse eUniv        = encRequest.Body.Universe;
            uint      protoVersion = encRequest.Body.ProtocolVersion;

            DebugLog.WriteLine("CMClient", "Got encryption request. Universe: {0} Protocol ver: {1}", eUniv, protoVersion);
            DebugLog.Assert(protoVersion == 1, "CMClient", "Encryption handshake protocol version mismatch!");

            byte[] pubKey = KeyDictionary.GetPublicKey(eUniv);

            if (pubKey == null)
            {
                DebugLog.WriteLine("CMClient", "HandleEncryptionRequest got request for invalid universe! Universe: {0} Protocol ver: {1}", eUniv, protoVersion);
                return;
            }

            ConnectedUniverse = eUniv;

            var encResp = new Msg <MsgChannelEncryptResponse>();

            tempSessionKey = CryptoHelper.GenerateRandomBlock(32);
            byte[] cryptedSessKey = null;

            using (var rsa = new RSACrypto(pubKey))
            {
                cryptedSessKey = rsa.Encrypt(tempSessionKey);
            }

            byte[] keyCrc = CryptoHelper.CRCHash(cryptedSessKey);

            encResp.Write(cryptedSessKey);
            encResp.Write(keyCrc);
            encResp.Write(( uint )0);

            this.Send(encResp);
        }
Esempio n. 27
0
        /// <summary>
        /// Sets the various components of this SteamID from a Steam2 "STEAM_" rendered form and universe.
        /// </summary>
        /// <param name="steamId">A "STEAM_" rendered form of the SteamID.</param>
        /// <param name="eUniverse">The universe the SteamID belongs to.</param>
        /// <returns><c>true</c> if this instance was successfully assigned; otherwise, <c>false</c> if the given string was in an invalid format.</returns>
        public bool SetFromString( string steamId, EUniverse eUniverse )
        {
            if ( string.IsNullOrEmpty( steamId ) )
                return false;

            Match m = SteamIDRegex.Match( steamId );

            if ( !m.Success )
                return false;

            uint accId, authServer;
            if ( !uint.TryParse( m.Groups[ "accountid" ].Value, out accId ) || 
                 !uint.TryParse( m.Groups[ "authserver" ].Value, out authServer ) )
                return false;

            this.AccountUniverse = eUniverse;
            this.AccountInstance = 1;
            this.AccountType = EAccountType.Individual;
            this.AccountID = ( accId << 1 ) | authServer;

            return true;
        }
Esempio n. 28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SteamID"/> class from a Steam2 "STEAM_" rendered form and universe.
 /// </summary>
 /// <param name="steamId">A "STEAM_" rendered form of the SteamID.</param>
 /// <param name="eUniverse">The universe the SteamID belongs to.</param>
 public SteamID( string steamId, EUniverse eUniverse )
     : this()
 {
     SetFromString( steamId, eUniverse );
 }
Esempio n. 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SteamID"/> class.
 /// </summary>
 /// <param name="unAccountID">The account ID.</param>
 /// <param name="unInstance">The instance.</param>
 /// <param name="eUniverse">The universe.</param>
 /// <param name="eAccountType">The account type.</param>
 public SteamID( UInt32 unAccountID, UInt32 unInstance, EUniverse eUniverse, EAccountType eAccountType )
     : this()
 {
     InstancedSet( unAccountID, unInstance, eUniverse, eAccountType );
 }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SteamID"/> class.
 /// </summary>
 /// <param name="unAccountID">The account ID.</param>
 /// <param name="eUniverse">The universe.</param>
 /// <param name="eAccountType">The account type.</param>
 public SteamID( UInt32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
     : this()
 {
     Set( unAccountID, eUniverse, eAccountType );
 }
Esempio n. 31
0
        bool HandleEncryptRequest(IPacketMsg packetMsg)
        {
            var encRequest = new Msg <MsgChannelEncryptRequest>(packetMsg);

            EUniverse eUniv        = encRequest.Body.Universe;
            uint      protoVersion = encRequest.Body.ProtocolVersion;

            DebugLog.WriteLine("CMClient", "Got encryption request. Universe: {0} Protocol ver: {1}", eUniv, protoVersion);
            DebugLog.Assert(protoVersion == 1, "CMClient", "Encryption handshake protocol version mismatch!");

            byte[] randomChallenge;
            if (encRequest.Payload.Length >= 16)
            {
                randomChallenge = encRequest.Payload.ToArray();
            }
            else
            {
                randomChallenge = null;
            }

            byte[] pubKey = KeyDictionary.GetPublicKey(eUniv);

            if (pubKey == null)
            {
                connection.Disconnect();

                DebugLog.WriteLine("CMClient", "HandleEncryptionRequest got request for invalid universe! Universe: {0} Protocol ver: {1}", eUniv, protoVersion);
                return(false);
            }

            ConnectedUniverse = eUniv;

            var encResp = new Msg <MsgChannelEncryptResponse>();

            var tempSessionKey = CryptoHelper.GenerateRandomBlock(32);

            byte[] encryptedHandshakeBlob = null;

            using (var rsa = new RSACrypto(pubKey))
            {
                if (randomChallenge != null)
                {
                    var blobToEncrypt = new byte[tempSessionKey.Length + randomChallenge.Length];
                    Array.Copy(tempSessionKey, blobToEncrypt, tempSessionKey.Length);
                    Array.Copy(randomChallenge, 0, blobToEncrypt, tempSessionKey.Length, randomChallenge.Length);

                    encryptedHandshakeBlob = rsa.Encrypt(blobToEncrypt);
                }
                else
                {
                    encryptedHandshakeBlob = rsa.Encrypt(tempSessionKey);
                }
            }

            var keyCrc = CryptoHelper.CRCHash(encryptedHandshakeBlob);

            encResp.Write(encryptedHandshakeBlob);
            encResp.Write(keyCrc);
            encResp.Write(( uint )0);

            if (randomChallenge != null)
            {
                pendingNetFilterEncryption = new NetFilterEncryptionWithHMAC(tempSessionKey);
            }
            else
            {
                pendingNetFilterEncryption = new NetFilterEncryption(tempSessionKey);
            }

            this.Send(encResp);
            return(true);
        }
Esempio n. 32
0
		internal async Task<bool> Init(ulong steamID, EUniverse universe, string webAPIUserNonce, string parentalPin) {
			if ((steamID == 0) || (universe == EUniverse.Invalid) || string.IsNullOrEmpty(webAPIUserNonce) || string.IsNullOrEmpty(parentalPin)) {
				Bot.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(universe) + " || " + nameof(webAPIUserNonce) + " || " + nameof(parentalPin));
				return false;
			}

			SteamID = steamID;

			string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString()));

			// Generate an AES session key
			byte[] sessionKey = SteamKit2.CryptoHelper.GenerateRandomBlock(32);

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

			// Copy our login key
			byte[] loginKey = new byte[webAPIUserNonce.Length];
			Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length);

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

			// Do the magic
			Bot.ArchiLogger.LogGenericInfo("Logging in to ISteamUserAuth...");

			KeyValue authResult;
			using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) {
				iSteamUserAuth.Timeout = Timeout;

				try {
					authResult = iSteamUserAuth.AuthenticateUser(steamid: steamID, sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)), encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)), method: WebRequestMethods.Http.Post, secure: !Program.GlobalConfig.ForceHttp);
				} catch (Exception e) {
					Bot.ArchiLogger.LogGenericException(e);
					return false;
				}
			}

			if (authResult == null) {
				Bot.ArchiLogger.LogNullError(nameof(authResult));
				return false;
			}

			string steamLogin = authResult["token"].Value;
			if (string.IsNullOrEmpty(steamLogin)) {
				Bot.ArchiLogger.LogNullError(nameof(steamLogin));
				return false;
			}

			string steamLoginSecure = authResult["tokensecure"].Value;
			if (string.IsNullOrEmpty(steamLoginSecure)) {
				Bot.ArchiLogger.LogNullError(nameof(steamLoginSecure));
				return false;
			}

			WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamCommunityHost));
			WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamStoreHost));

			WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamCommunityHost));
			WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamStoreHost));

			WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamCommunityHost));
			WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamStoreHost));

			Bot.ArchiLogger.LogGenericInfo("Success!");

			// Unlock Steam Parental if needed
			if (!parentalPin.Equals("0")) {
				if (!await UnlockParentalAccount(parentalPin).ConfigureAwait(false)) {
					return false;
				}
			}

			Ready = true;
			LastSessionRefreshCheck = DateTime.Now;
			return true;
		}
Esempio n. 33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SteamID"/> class from a Steam2 "STEAM_" rendered form and universe.
 /// </summary>
 /// <param name="steamId">A "STEAM_" rendered form of the SteamID.</param>
 /// <param name="eUniverse">The universe the SteamID belongs to.</param>
 public SteamID(string steamId, EUniverse eUniverse)
     : this()
 {
     SetFromString(steamId, eUniverse);
 }
Esempio n. 34
0
 public void SetEUniverse(EUniverse other)
 {
     m_SteamID = (m_SteamID & ~(0xFFul << (ushort)56)) | (((ulong)(other) & 0xFFul) << (ushort)56);
 }
Esempio n. 35
0
 public CSteamID(AccountID_t unAccountID, EUniverse eUniverse, EAccountType eAccountType)
 {
     m_SteamID = 0;
     Set(unAccountID, eUniverse, eAccountType);
 }
 public ISteamConfigurationBuilder WithUniverse(EUniverse universe)
 {
     state.Universe = universe;
     return(this);
 }
Esempio n. 37
0
		public MsgChannelEncryptRequest()
		{
			ProtocolVersion = MsgChannelEncryptRequest.PROTOCOL_VERSION;
			Universe = EUniverse.Invalid;
		}
Esempio n. 38
0
		public void Deserialize( Stream stream )
		{
			BinaryReader br = new BinaryReader( stream );

			ProtocolVersion = br.ReadUInt32();
			Universe = (EUniverse)br.ReadInt32();
		}
Esempio n. 39
0
        /// <summary>
        /// Sets the various components of this SteamID instance.
        /// </summary>
        /// <param name="unAccountID">The account ID.</param>
        /// <param name="eUniverse">The universe.</param>
        /// <param name="eAccountType">The account type.</param>
        public void Set( UInt32 unAccountID, EUniverse eUniverse, EAccountType eAccountType )
        {
            this.AccountID = unAccountID;
            this.AccountUniverse = eUniverse;
            this.AccountType = eAccountType;

            if ( eAccountType == EAccountType.Clan || eAccountType == EAccountType.GameServer )
            {
                this.AccountInstance = 0;
            }
            else
            {
                this.AccountInstance = DesktopInstance;
            }
        }
        internal async Task <bool> Init(ulong steamID, EUniverse universe, string webAPIUserNonce, string parentalPin)
        {
            if ((steamID == 0) || (universe == EUniverse.Invalid) || string.IsNullOrEmpty(webAPIUserNonce) || string.IsNullOrEmpty(parentalPin))
            {
                Logging.LogNullError(nameof(steamID) + " || " + nameof(universe) + " || " + nameof(webAPIUserNonce) + " || " + nameof(parentalPin), Bot.BotName);
                return(false);
            }

            SteamID = steamID;

            string sessionID = Convert.ToBase64String(Encoding.UTF8.GetBytes(steamID.ToString()));

            // Generate an AES session key
            byte[] sessionKey = SteamKit2.CryptoHelper.GenerateRandomBlock(32);

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

            // Copy our login key
            byte[] loginKey = new byte[webAPIUserNonce.Length];
            Array.Copy(Encoding.ASCII.GetBytes(webAPIUserNonce), loginKey, webAPIUserNonce.Length);

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

            // Do the magic
            Logging.LogGenericInfo("Logging in to ISteamUserAuth...", Bot.BotName);

            KeyValue authResult;

            using (dynamic iSteamUserAuth = WebAPI.GetInterface("ISteamUserAuth")) {
                iSteamUserAuth.Timeout = Timeout;

                try {
                    authResult = iSteamUserAuth.AuthenticateUser(
                        steamid: steamID,
                        sessionkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedSessionKey, 0, cryptedSessionKey.Length)),
                        encrypted_loginkey: Encoding.ASCII.GetString(WebUtility.UrlEncodeToBytes(cryptedLoginKey, 0, cryptedLoginKey.Length)),
                        method: WebRequestMethods.Http.Post,
                        secure: !Program.GlobalConfig.ForceHttp
                        );
                } catch (Exception e) {
                    Logging.LogGenericException(e, Bot.BotName);
                    return(false);
                }
            }

            if (authResult == null)
            {
                Logging.LogNullError(nameof(authResult), Bot.BotName);
                return(false);
            }

            string steamLogin = authResult["token"].Value;

            if (string.IsNullOrEmpty(steamLogin))
            {
                Logging.LogNullError(nameof(steamLogin), Bot.BotName);
                return(false);
            }

            string steamLoginSecure = authResult["tokensecure"].Value;

            if (string.IsNullOrEmpty(steamLoginSecure))
            {
                Logging.LogNullError(nameof(steamLoginSecure), Bot.BotName);
                return(false);
            }

            WebBrowser.CookieContainer.Add(new Cookie("sessionid", sessionID, "/", "." + SteamCommunityHost));
            WebBrowser.CookieContainer.Add(new Cookie("steamLogin", steamLogin, "/", "." + SteamCommunityHost));
            WebBrowser.CookieContainer.Add(new Cookie("steamLoginSecure", steamLoginSecure, "/", "." + SteamCommunityHost));

            Logging.LogGenericInfo("Success!", Bot.BotName);

            // Unlock Steam Parental if needed
            if (!parentalPin.Equals("0"))
            {
                if (!await UnlockParentalAccount(parentalPin).ConfigureAwait(false))
                {
                    return(false);
                }
            }

            Ready = true;
            LastSessionRefreshCheck = DateTime.Now;
            return(true);
        }
Esempio n. 41
0
            internal FriendMsgHistoryCallback( CMsgClientFSGetFriendMessageHistoryResponse msg, EUniverse universe )
            {
                Result = ( EResult )msg.success;

                SteamID = msg.steamid;

                var messages = msg.messages
                 .Select( m =>
                    {
                        SteamID senderID = new SteamID( m.accountid, universe, EAccountType.Individual );
                        DateTime timestamp = DateUtils.DateTimeFromUnixTime( m.timestamp );

                        return new FriendMessage( senderID, m.unread, m.message, timestamp );
                    }
                 )
                 .ToList();

                Messages = new ReadOnlyCollection<FriendMessage>( messages );
            }
Esempio n. 42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SteamID"/> class.
 /// </summary>
 /// <param name="unAccountID">The account ID.</param>
 /// <param name="unInstance">The instance.</param>
 /// <param name="eUniverse">The universe.</param>
 /// <param name="eAccountType">The account type.</param>
 public SteamID(UInt32 unAccountID, UInt32 unInstance, EUniverse eUniverse, EAccountType eAccountType)
     : this()
 {
     InstancedSet(unAccountID, unInstance, eUniverse, eAccountType);
 }