示例#1
0
        public async Task InsertOrUpdateAsync(IGAPAuthenticatorDTO item, bool isLocal,
                                              string?secondaryPassword = null)
        {
            var value = Serializable.SMP(item.Value);

            var encryptionMode = GetEncryptionMode(isLocal, secondaryPassword);

            var name_bytes = await ss.E(item.Name, encryptionMode, secondaryPassword);

            name_bytes = name_bytes.ThrowIsNull(nameof(name_bytes));

            var value_bytes = await ss.EB(value, encryptionMode, secondaryPassword);

            value_bytes = value_bytes.ThrowIsNull(nameof(value_bytes));

            var entity = new GameAccountPlatformAuthenticator
            {
                Id       = item.Id,
                Name     = name_bytes,
                ServerId = item.ServerId,
                Value    = value_bytes,
            };

            await InsertOrUpdateAsync(entity);

            item.Id = entity.Id;
        }
示例#2
0
        async Task <int> UpdateIndexByItemAsync(IGAPAuthenticatorDTO item)
        {
            var dbConnection = await GetDbConnection().ConfigureAwait(false);

            return(await AttemptAndRetry(async() =>
            {
                var sql =
                    SQLStrings.Update +
                    "[" + GameAccountPlatformAuthenticator.TableName + "]" +
                    " set " +
                    "[" + GameAccountPlatformAuthenticator.ColumnName_Index + "]" +
                    $" = {item.Index}" +
                    " where " +
                    "[" + GameAccountPlatformAuthenticator.ColumnName_Id + "]" +
                    $" = {item.Id}";
                var r = await dbConnection.ExecuteAsync(sql);
                return r;
            }).ConfigureAwait(false));

            //var source = await FindAsync(item.Id);
            //if (source != null)
            //{
            //    source.Index = item.Index;
            //    var r = await UpdateAsync(source);
            //    return r;
            //}
            //return 0;
        }
示例#3
0
        async Task <GameAccountPlatformAuthenticator> Convert(IGAPAuthenticatorDTO item, bool isLocal,
                                                              string?secondaryPassword = null)
        {
            var value = Serializable.SMP(item.Value);

            (var notSecondaryPassword, var encryptionMode) = GetEncryptionMode2(isLocal, secondaryPassword);

            var name_encryptionMode = GetEncryptionMode(isLocal, null);
            var name_bytes          = await ss.E(item.Name ?? string.Empty, name_encryptionMode, null);

            var value_bytes = await ss.EB(value, encryptionMode, secondaryPassword);

            value_bytes = value_bytes.ThrowIsNull(nameof(value_bytes));

            var entity = new GameAccountPlatformAuthenticator
            {
                Id         = item.Id,
                Name       = name_bytes,
                ServerId   = item.ServerId,
                Value      = value_bytes,
                IsNotLocal = !isLocal,
                IsNeedSecondaryPassword = !notSecondaryPassword,
                Index      = item.Index,
                Created    = item.Created,
                LastUpdate = item.LastUpdate,
            };

            return(entity);
        }
        /// <inheritdoc cref="ToUrl(IGAPAuthenticatorDTO, bool)"/>
        public static LightweightExportDTO ToLightweightExportDTO(this IGAPAuthenticatorDTO @this, bool compat = false)
        {
            LightweightExportDTO dto = new();

            //Match match;
            var issuer = @this.Value.Issuer;
            var label  = @this.Name;

            //if (string.IsNullOrEmpty(issuer) && (match = Regex.Match(label, @"^([^\(]+)\s+\((.*?)\)(.*)")).Success == true)
            //{
            //    issuer = match.Groups[1].Value;
            //    label = match.Groups[2].Value + match.Groups[3].Value;
            //}
            //if (!string.IsNullOrEmpty(issuer) && (match = Regex.Match(label, @"^" + issuer + @"\s+\((.*?)\)(.*)")).Success)
            //{
            //    label = match.Groups[1].Value + match.Groups[2].Value;
            //}
            if (!string.IsNullOrEmpty(issuer))
            {
                dto.Issuer = issuer;
            }

            if (@this.Value.HMACType != DEFAULT_HMAC_TYPE)
            {
                dto.HMACType = @this.Value.HMACType;
            }

            if (@this.Value is BattleNetAuthenticator battleNetAuthenticator)
            {
                dto.Platform = GamePlatform.BattleNet;
                dto.Serial   = battleNetAuthenticator.Serial;
            }
            else if (@this.Value is SteamAuthenticator steamAuthenticator)
            {
                dto.Platform = GamePlatform.Steam;
                if (!compat)
                {
                    dto.DeviceId  = steamAuthenticator.DeviceId;
                    dto.SteamData = steamAuthenticator.SteamData;
                }
            }
            else if (@this.Value is HOTPAuthenticator hOTPAuthenticator)
            {
                dto.Platform = GamePlatform.HOTP;
                dto.Counter  = hOTPAuthenticator.Counter;
            }

            dto.SecretKey = @this.Value.SecretKey;

            if (@this.Value.Period != DEFAULT_PERIOD)
            {
                dto.Period = @this.Value.Period;
            }

            dto.CodeDigits = @this.Value.CodeDigits;
            dto.Name       = label;

            return(dto);
        }
示例#5
0
        public async Task InsertOrUpdateAsync(IGAPAuthenticatorDTO item, bool isLocal,
                                              string?secondaryPassword = null)
        {
            var entity = await Convert(item, isLocal, secondaryPassword);

            await InsertOrUpdateAsync(entity);

            item.Id = entity.Id;
        }
        public static string ToUrl(this IGAPAuthenticatorDTO @this, bool compat = false)
        {
            string type        = "totp";
            string extraparams = string.Empty;

            //Match match;
            var issuer = @this.Value.Issuer;
            var label  = @this.Name;

            //if (string.IsNullOrEmpty(issuer) && (match = Regex.Match(label, @"^([^\(]+)\s+\((.*?)\)(.*)")).Success == true)
            //{
            //    issuer = match.Groups[1].Value;
            //    label = match.Groups[2].Value + match.Groups[3].Value;
            //}
            //if (!string.IsNullOrEmpty(issuer) && (match = Regex.Match(label, @"^" + issuer + @"\s+\((.*?)\)(.*)")).Success)
            //{
            //    label = match.Groups[1].Value + match.Groups[2].Value;
            //}
            if (!string.IsNullOrEmpty(issuer))
            {
                extraparams += "&issuer=" + HttpUtility.UrlEncode(issuer);
            }

            if (@this.Value.HMACType != DEFAULT_HMAC_TYPE)
            {
                extraparams += "&algorithm=" + @this.Value.HMACType.ToString();
            }

            if (@this.Value is BattleNetAuthenticator battleNetAuthenticator)
            {
                extraparams += "&serial=" + HttpUtility.UrlEncode(battleNetAuthenticator.Serial?.Replace("-", ""));
            }
            else if (@this.Value is SteamAuthenticator steamAuthenticator)
            {
                if (!compat)
                {
                    extraparams += "&deviceid=" + HttpUtility.UrlEncode(steamAuthenticator.DeviceId);
                    extraparams += "&data=" + HttpUtility.UrlEncode(steamAuthenticator.SteamData);
                }
            }
            else if (@this.Value is HOTPAuthenticator hOTPAuthenticator)
            {
                type         = "hotp";
                extraparams += "&counter=" + hOTPAuthenticator.Counter;
            }

            var secret = HttpUtility.UrlEncode(Base32.GetInstance().Encode(@this.Value.SecretKey ?? Array.Empty <byte>()));

            if (@this.Value.Period != DEFAULT_PERIOD)
            {
                extraparams += "&period=" + @this.Value.Period;
            }

            var url = string.Format("otpauth://" + type + "/{0}?secret={1}&digits={2}{3}",
                                    !string.IsNullOrEmpty(issuer) ? HttpUtility.UrlPathEncode(issuer) + ":" + HttpUtility.UrlPathEncode(label) : HttpUtility.UrlPathEncode(label),
                                    secret,
                                    @this.Value.CodeDigits,
                                    extraparams);

            return(url);
        }
 public MyAuthenticator(IGAPAuthenticatorDTO data)
 {
     AuthenticatorData = data;
     OriginName        = AuthenticatorData.Name;
 }