mirror of
https://github.com/bitwarden/mobile
synced 2026-01-19 17:03:21 +00:00
[SG-671] OTP Menu Screen causes Crash on Android (#2097)
* [SG-671] removed unnecessary calc of otpauth period. protected cal of otpauth from crashing the app if url has a wrong format. * [SG-671] changed logger * [SG-671] Refactored GetQueryParams code to used HttpUtility.ParseQueryString. * [SG-671] refactor and null protection. * [SG-671] code format * [SG-671] fixed bug where totp circle countdown was fixed to 30. * [SG-167] added fallback for uri check. Changed all default totp timers to constant. * [SG-671] missed unsaved file * [SG-671] simplified code
This commit is contained in:
@@ -40,8 +40,8 @@ namespace Bit.App.Pages
|
||||
private string _totpCode;
|
||||
private string _totpCodeFormatted;
|
||||
private string _totpSec;
|
||||
private double _totpInterval = Constants.TotpDefaultTimer;
|
||||
private bool _totpLow;
|
||||
private DateTime? _totpInterval = null;
|
||||
private string _previousCipherId;
|
||||
private byte[] _attachmentData;
|
||||
private string _attachmentFilename;
|
||||
@@ -241,7 +241,7 @@ namespace Bit.App.Pages
|
||||
Page.Resources["textTotp"] = ThemeManager.Resources()[value ? "text-danger" : "text-default"];
|
||||
}
|
||||
}
|
||||
public double TotpProgress => string.IsNullOrEmpty(TotpSec) ? 0 : double.Parse(TotpSec) * 100 / 30;
|
||||
public double TotpProgress => string.IsNullOrEmpty(TotpSec) ? 0 : double.Parse(TotpSec) * 100 / _totpInterval;
|
||||
public bool IsDeleted => Cipher.IsDeleted;
|
||||
public bool CanEdit => !Cipher.IsDeleted;
|
||||
|
||||
@@ -265,6 +265,7 @@ namespace Bit.App.Pages
|
||||
{
|
||||
_totpTickHelper = new TotpHelper(Cipher);
|
||||
_totpTickCancellationToken?.Cancel();
|
||||
_totpInterval = _totpTickHelper.Interval;
|
||||
_totpTickCancellationToken = new CancellationTokenSource();
|
||||
_totpTickTask = new TimerTask(_logger, StartCiphersTotpTick, _totpTickCancellationToken).RunPeriodic();
|
||||
}
|
||||
@@ -284,6 +285,7 @@ namespace Bit.App.Pages
|
||||
await _totpTickHelper.GenerateNewTotpValues();
|
||||
TotpSec = _totpTickHelper.TotpSec;
|
||||
TotpCodeFormatted = _totpTickHelper.TotpCodeFormatted;
|
||||
_totpInterval = _totpTickHelper.Interval;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -429,7 +431,6 @@ namespace Bit.App.Pages
|
||||
{
|
||||
if (Cipher == null || Cipher.Type != Core.Enums.CipherType.Login || Cipher.Login.Totp == null)
|
||||
{
|
||||
_totpInterval = null;
|
||||
return;
|
||||
}
|
||||
_totpCode = await _totpService.GetCodeAsync(Cipher.Login.Totp);
|
||||
@@ -449,7 +450,6 @@ namespace Bit.App.Pages
|
||||
else
|
||||
{
|
||||
TotpCodeFormatted = null;
|
||||
_totpInterval = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ namespace Bit.App.Pages
|
||||
private bool _websiteIconsEnabled;
|
||||
private string _iconImageSource = string.Empty;
|
||||
|
||||
public int interval { get; set; }
|
||||
private double _progress;
|
||||
private string _totpSec;
|
||||
private string _totpCodeFormatted;
|
||||
@@ -37,7 +36,6 @@ namespace Bit.App.Pages
|
||||
|
||||
Cipher = cipherView;
|
||||
WebsiteIconsEnabled = websiteIconsEnabled;
|
||||
interval = _totpService.GetTimeInterval(Cipher.Login.Totp);
|
||||
CopyCommand = new AsyncCommand(CopyToClipboardAsync,
|
||||
onException: ex => _logger.Value.Exception(ex),
|
||||
allowsMultipleExecutions: false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Abstractions;
|
||||
using Bit.Core.Models.View;
|
||||
using Bit.Core.Utilities;
|
||||
@@ -10,26 +11,26 @@ namespace Bit.App.Utilities
|
||||
{
|
||||
private ITotpService _totpService;
|
||||
private CipherView _cipher;
|
||||
private int _interval;
|
||||
|
||||
public TotpHelper(CipherView cipher)
|
||||
{
|
||||
_totpService = ServiceContainer.Resolve<ITotpService>("totpService");
|
||||
_cipher = cipher;
|
||||
_interval = _totpService.GetTimeInterval(cipher?.Login?.Totp);
|
||||
Interval = _totpService.GetTimeInterval(cipher?.Login?.Totp);
|
||||
}
|
||||
|
||||
public string TotpSec { get; private set; }
|
||||
public string TotpCodeFormatted { get; private set; }
|
||||
public double Progress { get; private set; }
|
||||
public double Interval { get; private set; } = Constants.TotpDefaultTimer;
|
||||
|
||||
public async Task GenerateNewTotpValues()
|
||||
{
|
||||
var epoc = CoreHelpers.EpocUtcNow() / 1000;
|
||||
var mod = epoc % _interval;
|
||||
var totpSec = _interval - mod;
|
||||
var mod = epoc % Interval;
|
||||
var totpSec = Interval - mod;
|
||||
TotpSec = totpSec.ToString();
|
||||
Progress = totpSec * 100 / 30;
|
||||
Progress = totpSec * 100 / Interval;
|
||||
if (mod == 0 || string.IsNullOrEmpty(TotpCodeFormatted))
|
||||
{
|
||||
TotpCodeFormatted = await TotpUpdateCodeAsync();
|
||||
|
||||
Reference in New Issue
Block a user