Exemplo n.º 1
0
        private static void HandleCryptKeyArgument(string cryptKey)
        {
            if (string.IsNullOrEmpty(cryptKey))
            {
                ASF.ArchiLogger.LogNullError(nameof(cryptKey));

                return;
            }

            ArchiCryptoHelper.SetEncryptionKey(cryptKey);
        }
Exemplo n.º 2
0
        internal async Task <(bool IsSteamParentalEnabled, string SteamParentalCode)?> ValidateSteamParental(string steamParentalCode = null)
        {
            if (!Client.IsConnected)
            {
                return(null);
            }

            CParental_GetParentalSettings_Request request = new CParental_GetParentalSettings_Request {
                steamid = Client.SteamID
            };

            SteamUnifiedMessages.ServiceMethodResponse response;

            try {
                response = await UnifiedParentalService.SendMessage(x => x.GetParentalSettings(request));
            } catch (Exception e) {
                ArchiLogger.LogGenericWarningException(e);

                return(null);
            }

            if (response == null)
            {
                ArchiLogger.LogNullError(nameof(response));

                return(null);
            }

            if (response.Result != EResult.OK)
            {
                return(null);
            }

            CParental_GetParentalSettings_Response body = response.GetDeserializedResponse <CParental_GetParentalSettings_Response>();

            if (!body.settings.is_enabled)
            {
                return(false, null);
            }

            ArchiCryptoHelper.ESteamParentalAlgorithm steamParentalAlgorithm;

            switch (body.settings.passwordhashtype)
            {
            case 4:
                steamParentalAlgorithm = ArchiCryptoHelper.ESteamParentalAlgorithm.Pbkdf2;

                break;

            case 6:
                steamParentalAlgorithm = ArchiCryptoHelper.ESteamParentalAlgorithm.SCrypt;

                break;

            default:
                ASF.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(body.settings.passwordhashtype), body.settings.passwordhashtype));

                return(false, null);
            }

            if ((steamParentalCode != null) && (steamParentalCode.Length == BotConfig.SteamParentalCodeLength))
            {
                byte   i        = 0;
                byte[] password = new byte[steamParentalCode.Length];

                foreach (char character in steamParentalCode)
                {
                    if ((character < '0') || (character > '9'))
                    {
                        break;
                    }

                    password[i++] = (byte)character;
                }

                if (i >= steamParentalCode.Length)
                {
                    byte[] passwordHash = ArchiCryptoHelper.GenerateSteamParentalHash(password, body.settings.salt, (byte)body.settings.passwordhash.Length, steamParentalAlgorithm);

                    if (passwordHash.SequenceEqual(body.settings.passwordhash))
                    {
                        return(true, steamParentalCode);
                    }
                }
            }

            ArchiLogger.LogGenericInfo(Strings.BotGeneratingSteamParentalCode);

            steamParentalCode = ArchiCryptoHelper.RecoverSteamParentalCode(body.settings.passwordhash, body.settings.salt, steamParentalAlgorithm);

            ArchiLogger.LogGenericInfo(Strings.Done);

            return(true, steamParentalCode);
        }