1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-24 04:04:34 +00:00

Merge branch 'master' into feature/pm-1029-tde-login

This commit is contained in:
Jacob Fink
2023-08-13 15:40:13 -04:00
6 changed files with 107 additions and 1 deletions

19
.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1,19 @@
# Please sort lines alphabetically, this will ensure we don't accidentally add duplicates.
#
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
# The following owners will be the default owners for everything in the repo.
# Unless a later match takes precedence
# @bitwarden/team-leads
## Auth team files ##
## Platform team files ##
appIcons @bitwarden/team-platform-dev
build.cake @bitwarden/team-platform-dev
## Vault team files ##
src/watchOS @bitwarden/team-vault-dev
## Tools team files ##

View File

@@ -2678,7 +2678,7 @@ Do you want to switch to this account?</value>
<value>Master password re-prompt help</value>
</data>
<data name="UnlockingMayFailDueToInsufficientMemoryDecreaseYourKDFMemorySettingsToResolve" xml:space="preserve">
<value>Unlocking may fail due to insufficient memory. Decrease your KDF memory settings to resolve.</value>
<value>Unlocking may fail due to insufficient memory. Decrease your KDF memory settings or set up biometric unlock to resolve.</value>
</data>
<data name="InvalidAPIKey" xml:space="preserve">
<value>Invalid API key</value>

View File

@@ -131,6 +131,24 @@ namespace Bit.App.Services
_messagingService.Value.Send("logout");
}
break;
case NotificationType.SyncSendCreate:
case NotificationType.SyncSendUpdate:
var sendCreateUpdateMessage = JsonConvert.DeserializeObject<SyncSendNotification>(
notification.Payload);
if (isAuthenticated && sendCreateUpdateMessage.UserId == myUserId)
{
await _syncService.Value.SyncUpsertSendAsync(sendCreateUpdateMessage,
notification.Type == NotificationType.SyncSendUpdate);
}
break;
case NotificationType.SyncSendDelete:
var sendDeleteMessage = JsonConvert.DeserializeObject<SyncSendNotification>(
notification.Payload);
if (isAuthenticated && sendDeleteMessage.UserId == myUserId)
{
await _syncService.Value.SyncDeleteSendAsync(sendDeleteMessage);
}
break;
case NotificationType.AuthRequest:
var passwordlessLoginMessage = JsonConvert.DeserializeObject<PasswordlessRequestNotification>(notification.Payload);

View File

@@ -12,8 +12,10 @@ namespace Bit.Core.Abstractions
Task SetLastSyncAsync(DateTime date);
Task<bool> SyncDeleteCipherAsync(SyncCipherNotification notification);
Task<bool> SyncDeleteFolderAsync(SyncFolderNotification notification);
Task<bool> SyncDeleteSendAsync(SyncSendNotification notification);
Task<bool> SyncUpsertCipherAsync(SyncCipherNotification notification, bool isEdit);
Task<bool> SyncUpsertFolderAsync(SyncFolderNotification notification, bool isEdit);
Task<bool> SyncUpsertSendAsync(SyncSendNotification notification, bool isEdit);
// Passwordless code will be moved to an independent service in future techdept
Task SyncPasswordlessLoginRequestsAsync();
}

View File

@@ -34,6 +34,13 @@ namespace Bit.Core.Models.Response
public DateTime Date { get; set; }
}
public class SyncSendNotification
{
public string Id { get; set; }
public string UserId { get; set; }
public DateTime RevisionDate { get; set; }
}
public class PasswordlessRequestNotification
{
public string UserId { get; set; }

View File

@@ -274,6 +274,66 @@ namespace Bit.Core.Services
return SyncCompleted(false);
}
public async Task<bool> SyncUpsertSendAsync(SyncSendNotification notification, bool isEdit)
{
SyncStarted();
if (!await _stateService.IsAuthenticatedAsync())
{
return SyncCompleted(false);
}
try
{
var localSend = await _sendService.GetAsync(notification.Id);
if ((localSend != null && localSend.RevisionDate >= notification.RevisionDate)
|| (isEdit && localSend == null) || (!isEdit && localSend != null))
{
return SyncCompleted(false);
}
var remoteSend = await _apiService.GetSendAsync(notification.Id);
if (remoteSend != null)
{
var userId = await _stateService.GetActiveUserIdAsync();
await _sendService.UpsertAsync(new SendData(remoteSend, userId));
_messagingService.Send("syncedUpsertedSend", new Dictionary<string, string>
{
["sendId"] = notification.Id
});
return SyncCompleted(true);
}
}
catch (ApiException e)
{
if (e.Error != null && e.Error.StatusCode == System.Net.HttpStatusCode.NotFound && isEdit)
{
await _sendService.DeleteAsync(notification.Id);
_messagingService.Send("syncedDeletedSend", new Dictionary<string, string>
{
["sendId"] = notification.Id
});
return SyncCompleted(true);
}
}
return SyncCompleted(false);
}
public async Task<bool> SyncDeleteSendAsync(SyncSendNotification notification)
{
SyncStarted();
if (await _stateService.IsAuthenticatedAsync())
{
await _sendService.DeleteAsync(notification.Id);
_messagingService.Send("syncedDeletedSend", new Dictionary<string, string>
{
["sendId"] = notification.Id
});
return SyncCompleted(true);
}
return SyncCompleted(false);
}
// Helpers
private void SyncStarted()