Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions docs/client-security-architecture.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ByteSync Client Security Architecture

> Historical overview. For the current relay identity protocol, authorization boundary, local filesystem permissions, migration and validation status, see [Security boundary changes](security-boundaries.md). The short legacy ClientId described below is a display/trust alias and is not an authenticated identity.

**Last Updated:** November 6, 2025
**Analyzed Codebase:** ByteSync.Client (.NET 8.0)

Expand Down Expand Up @@ -52,14 +54,14 @@ public void InitializeRsa()

### Client Identifier

The `ClientId` is cryptographically derived from the RSA public key:
The legacy display `ClientId` is derived from the RSA public key:

```
ClientId = Base26(SHA256(InstallationId + SHA256(PublicKeyRSA)))
Format: XXXX-XXX-XXX (e.g., "ABCD-EFG-HIJ")
```

This creates a stable, human-readable identifier that is unique to each client's cryptographic identity.
This creates a human-readable alias. Its numeric reduction does not provide a collision-resistant security identity; the current protocol uses the full SHA-256 fingerprint described in the security boundary document.

### Local Key Storage

Expand Down
249 changes: 249 additions & 0 deletions docs/security-boundaries.md

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion src/ByteSync.Client/Assets/Resources/Resources.en.resx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<root>
<root>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
Expand Down Expand Up @@ -38,5 +38,14 @@ You must select at least 2 data nodes.</value>
</data>
<data name="InventoryProcess_LocalInventory_NotLaunched" xml:space="preserve">
<value>Local Inventory not launched</value>
</data>
<data name="ConnectionStatus_RelayIncompatible" xml:space="preserve">
<value>Incompatible relay server</value>
</data>
<data name="ConnectionStatus_RelayIncompatibleDetails" xml:space="preserve">
<value>The relay server does not provide the secure authentication required by this client. Check the relay address or update the relay server. Automatic reconnection has stopped.</value>
</data>
<data name="TrustedNetworkView_RenewKeyAvailability" xml:space="preserve">
<value>Renew your key outside a session, after connection attempts have finished.</value>
</data>
</root>
9 changes: 9 additions & 0 deletions src/ByteSync.Client/Assets/Resources/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1831,5 +1831,14 @@ Voulez-vous enregistrer ce nouveau Profil de Session avec ce nom ?</value>
<data name="SynchronizationConfirmation_Cancel" xml:space="preserve">
<value>ANNULER</value>
</data>
<data name="ConnectionStatus_RelayIncompatible" xml:space="preserve">
<value>Serveur relais incompatible</value>
</data>
<data name="ConnectionStatus_RelayIncompatibleDetails" xml:space="preserve">
<value>Le serveur relais ne fournit pas l’authentification sécurisée requise par ce client. Vérifiez l’adresse du relais ou mettez à jour le serveur. La reconnexion automatique est arrêtée.</value>
</data>
<data name="TrustedNetworkView_RenewKeyAvailability" xml:space="preserve">
<value>Renouvelez votre clé hors session, une fois les tentatives de connexion terminées.</value>
</data>
</root>

9 changes: 9 additions & 0 deletions src/ByteSync.Client/Assets/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1856,4 +1856,13 @@ Do you want to save this new Session Profile with this name?</value>
<data name="SynchronizationConfirmation_Cancel" xml:space="preserve">
<value>CANCEL</value>
</data>
<data name="ConnectionStatus_RelayIncompatible" xml:space="preserve">
<value>Incompatible relay server</value>
</data>
<data name="ConnectionStatus_RelayIncompatibleDetails" xml:space="preserve">
<value>The relay server does not provide the secure authentication required by this client. Check the relay address or update the relay server. Automatic reconnection has stopped.</value>
</data>
<data name="TrustedNetworkView_RenewKeyAvailability" xml:space="preserve">
<value>Renew your key outside a session, after connection attempts have finished.</value>
</data>
</root>
13 changes: 2 additions & 11 deletions src/ByteSync.Client/Business/Actions/Shared/SharedActionsGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,8 @@ public HashSet<string> GetTargetsFullNames(ByteSyncEndpoint endpoint)

public string GetFullName(SharedDataPart sharedDataPart)
{
string sourceFileName;
if (sharedDataPart.InventoryPartType == FileSystemTypes.Directory)
{
sourceFileName = IOUtils.Combine(sharedDataPart.RootPath, sharedDataPart.RelativePath!);
}
else
{
sourceFileName = sharedDataPart.RootPath;
}

return sourceFileName;
return sharedDataPart.LocalPathResolver?.Invoke()
?? throw new UnauthorizedAccessException("Action has no local source authorization");
}

private bool Equals(SharedActionsGroup other)
Expand Down
13 changes: 11 additions & 2 deletions src/ByteSync.Client/Business/Actions/Shared/SharedDataPart.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ByteSync.Common.Business.Inventories;
using ByteSync.Common.Business.Inventories;
using ByteSync.Models.Inventories;

namespace ByteSync.Business.Actions.Shared;
Expand All @@ -20,6 +20,9 @@ public SharedDataPart(string name, Inventory inventory, InventoryPart inventoryP
InventoryCodeAndId = inventory.CodeAndId;
NodeId = inventory.NodeId;
RootPath = inventoryPart.RootPath;
SourceId = inventoryPart.SourceId;
SourceRelativePath = inventoryPart.InventoryPartType == FileSystemTypes.File ? "" :
(relativePath?.StartsWith('/') == true ? relativePath[1..] : relativePath);
RelativePath = relativePath;
SignatureGuid = signatureGuid;
SignatureHash = signatureHash;
Expand All @@ -37,6 +40,10 @@ public SharedDataPart(string name, Inventory inventory, InventoryPart inventoryP
public string? NodeId { get; set; }

public string RootPath { get; set; } = null!;
public string? SourceId { get; set; }
public string? SourceRelativePath { get; set; }
[System.Text.Json.Serialization.JsonIgnore]
public Func<string>? LocalPathResolver { get; set; }

public string? RelativePath { get; set; }

Expand All @@ -48,7 +55,9 @@ public SharedDataPart(string name, Inventory inventory, InventoryPart inventoryP

protected bool Equals(SharedDataPart other)
{
return Equals(ClientInstanceId, other.ClientInstanceId) &&
return Equals(SourceId, other.SourceId) && Equals(NodeId, other.NodeId) &&
Equals(SourceRelativePath, other.SourceRelativePath) &&
Equals(ClientInstanceId, other.ClientInstanceId) &&
RootPath.Equals(other.RootPath, StringComparison.InvariantCultureIgnoreCase) &&
Equals (RelativePath, other.RelativePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ public enum ConnectionStatuses
Connected = 2,
RetryConnectingSoon = 3,
ConnectionFailed = 4,
}
RelayIncompatible = 5,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using ByteSync.Common.Business.SharedFiles;
using ByteSync.Interfaces.Controls.Synchronizations;

Expand All @@ -16,6 +16,14 @@ public DownloadTarget(SharedFileDefinition sharedFileDefinition, LocalSharedFile
MemoryStreams = new Dictionary<int, MemoryStream>();
}

public Action? ValidateAccess { get; set; }

public void CheckAccess()
{
if (SharedFileDefinition.IsSynchronization && ValidateAccess == null) throw new UnauthorizedAccessException("Missing download authorization");
ValidateAccess?.Invoke();
}

public SharedFileDefinition SharedFileDefinition { get; set; }

public LocalSharedFile? LocalSharedFile { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading;
using System.Threading;

namespace ByteSync.Business.Communications.PublicKeysTrusting;

Expand All @@ -19,6 +19,19 @@ public PeerTrustProcessData(string otherPartyClientId)
SyncRoot = new object();
}

public PeerTrustProcessData(ByteSync.Common.Business.EndPoints.PublicKeyCheckData peer) : this(peer.IssuerPublicKeyInfo.ClientId)
{
OtherPartyIdentity = ByteSync.Common.Business.Auth.AuthenticationProtocol.GetIdentity(peer.IssuerPublicKeyInfo.PublicKey);
OtherPartyClientInstanceId = peer.IssuerClientInstanceId;
ExchangeId = peer.Salt;
if (!ByteSync.Common.Business.Auth.AuthenticationProtocol.IsInstanceOf(OtherPartyClientInstanceId, OtherPartyIdentity) ||
string.IsNullOrWhiteSpace(ExchangeId) || ExchangeId.Length > 128)
throw new ArgumentException("Invalid peer trust exchange", nameof(peer));
}

public string? OtherPartyClientInstanceId { get; }
public string? OtherPartyIdentity { get; }
public string? ExchangeId { get; }
public string OtherPartyClientId { get; }

public bool HasOtherPartyValidatedPublicKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Serilog;

namespace ByteSync.Business.Communications.PublicKeysTrusting;
namespace ByteSync.Business.Communications.PublicKeysTrusting;

public class TrustProcessPublicKeysData
{
Expand All @@ -23,26 +21,22 @@ public TrustProcessPublicKeysData(string sessionId)

public SessionMemberTrustProcessData SessionMemberTrustProcessData { get; }

public void AddPeerTrustProcessData(PeerTrustProcessData peerTrustProcessData)
public PeerTrustProcessData AddPeerTrustProcessData(PeerTrustProcessData peer)
{
if (PeerTrustProcessDatas.ContainsKey(peerTrustProcessData.OtherPartyClientId))
{
PeerTrustProcessDatas.Remove(peerTrustProcessData.OtherPartyClientId);
}

PeerTrustProcessDatas.Add(peerTrustProcessData.OtherPartyClientId, peerTrustProcessData);
var instance = peer.OtherPartyClientInstanceId!;
if (PeerTrustProcessDatas.TryGetValue(instance, out var existing) &&
existing.OtherPartyIdentity == peer.OtherPartyIdentity && existing.ExchangeId == peer.ExchangeId)
return existing;
PeerTrustProcessDatas[instance] = peer;
return peer;
}

public void SetOtherPartyChecked(string issuerClientId, bool isValidated)
public void SetOtherPartyChecked(ByteSync.Common.Business.Sessions.Cloud.Connections.PublicKeyValidationParameters parameters)
{
PeerTrustProcessData? peerTrustProcessData;
if (PeerTrustProcessDatas.TryGetValue(issuerClientId, out peerTrustProcessData))
{
peerTrustProcessData.SetOtherPartyChecked(isValidated);
}
else
{
Log.Warning("Can not find PeerTrustProcessData with ClientId {issuerClientId}", issuerClientId);
}
if (parameters.IssuerClientInstanceId != null &&
PeerTrustProcessDatas.TryGetValue(parameters.IssuerClientInstanceId, out var peer) &&
peer.OtherPartyIdentity == parameters.IssuerIdentity && peer.ExchangeId == parameters.ExchangeId &&
!peer.OtherPartyHasFinished())
peer.SetOtherPartyChecked(parameters.IsValidated);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.ObjectModel;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
Expand All @@ -11,6 +11,8 @@ namespace ByteSync.Business.Configurations;

public class ApplicationSettings : ICloneable
{
public List<ByteSync.Business.DataSources.LocalSourcePermission> LocalSourcePermissions { get; set; } = new();

private string? _rsaPrivateKey;

public ApplicationSettings()
Expand Down Expand Up @@ -229,7 +231,9 @@ public List<string> DecodedAcknowledgedAnnouncementIds

public object Clone()
{
return this.MemberwiseClone();
var clone = (ApplicationSettings)MemberwiseClone();
clone.LocalSourcePermissions = LocalSourcePermissions.Select(p => p with { }).ToList();
return clone;
}

public void SetEncryptionPassword(string encryptionPassword)
Expand Down
12 changes: 12 additions & 0 deletions src/ByteSync.Client/Business/DataSources/LocalSourcePermission.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using ByteSync.Common.Business.Inventories;

namespace ByteSync.Business.DataSources;

public record LocalSourcePermission
{
public LocalSourcePermission() { }
public LocalSourcePermission(string identity, string path, FileSystemTypes type) { Identity = identity; Path = path; Type = type; }
public string Identity { get; set; } = "";
public string Path { get; set; } = "";
public FileSystemTypes Type { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.IO;
using System.IO;
using System.IO.Compression;
using ByteSync.Common.Business.Misc;
using ByteSync.Common.Business.SharedFiles;
Expand Down Expand Up @@ -28,6 +28,7 @@ public MultiUploadZip(string key, SharedFileDefinition sharedFileDefinition)
ActionsGroupIdsConcatenationLength = 0;
}

public List<Action> AccessValidators { get; } = new();
public string Key { get; }

public SharedFileDefinition SharedFileDefinition { get; }
Expand Down Expand Up @@ -57,7 +58,8 @@ public bool CanAdd(FileInfo fileInfo, string actionsGroupId)
public void AddEntry(FileInfo fileInfo, string actionsGroupId)
{
// https://stackoverflow.com/questions/22339260/how-do-i-add-files-to-an-existing-zip-archive
ZipArchive.CreateEntryFromFile(fileInfo.FullName, actionsGroupId, CompressionLevel.Fastest);
using (var input = ByteSync.Services.Synchronizations.LocalPathSafety.OpenRead(fileInfo.FullName))
using (var output = ZipArchive.CreateEntry(actionsGroupId, CompressionLevel.Fastest).Open()) input.CopyTo(output);

ActionGroupsIds.Add(actionsGroupId);
FilesFullNames.Add(fileInfo.FullName);
Expand Down
7 changes: 4 additions & 3 deletions src/ByteSync.Client/DependencyInjection/ServiceRegistrar.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Autofac;
using Autofac;
using Avalonia.ReactiveUI;
using ByteSync.Business.Arguments;
using ByteSync.DependencyInjection.Modules;
Expand Down Expand Up @@ -86,7 +86,8 @@ private static void FeedClientId(this IContainer container)
var environmentService = scope.Resolve<IEnvironmentService>();

var applicationSettings = applicationSettingsRepository.GetCurrentApplicationSettings();
environmentService.SetClientId(applicationSettings.ClientId);
environmentService.SetClientIdentity(applicationSettings.ClientId,
ByteSync.Common.Business.Auth.AuthenticationProtocol.GetIdentity(applicationSettings.DecodedRsaPublicKey!));
}

private static void LogBootstrapHeader(this IContainer container)
Expand All @@ -104,4 +105,4 @@ private static void LogBootstrap(this IContainer container)
var logger = scope.Resolve<IBootstrapLogger>();
logger.LogBootstrapContent();
}
}
}
10 changes: 10 additions & 0 deletions src/ByteSync.Client/Exceptions/RelayIncompatibleException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ByteSync.Exceptions;

public sealed class RelayIncompatibleException : BuildConnectionException
{
public RelayIncompatibleException(Exception innerException)
: base("The relay returned HTTP 404 for auth/challenge, which is required for this client's secure authentication. " +
"Check the relay address or update the relay server. Automatic reconnection has stopped.", innerException)
{
}
}
3 changes: 2 additions & 1 deletion src/ByteSync.Client/Factories/InventoryBuilderFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Autofac;
using Autofac;
using ByteSync.Business;
using ByteSync.Business.DataNodes;
using ByteSync.Business.Inventories;
Expand Down Expand Up @@ -59,6 +59,7 @@ public IInventoryBuilder CreateInventoryBuilder(DataNode dataNode)
{
try
{
_context.Resolve<ILocalSourceAuthorizationService>().CheckNetworkSource(dataSource, dataSource.ClientInstanceId);
inventoryBuilder.AddInventoryPart(dataSource);
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IEnvironmentService

public bool IsAutoRunProfile();

public void SetClientId(string clientId);
public void SetClientIdentity(string clientId, string identity);

string AssemblyFullName { get; }

Expand All @@ -35,5 +35,7 @@ public interface IEnvironmentService

string ClientId { get; }

string Identity { get; }

string ClientInstanceId { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Threading;
using System.Threading;
using System.Threading.Tasks;
using ByteSync.Common.Business.Sessions;
using ByteSync.Common.Business.Sessions.Cloud;
Expand All @@ -14,6 +14,8 @@ public interface ICloudSessionApiClient

Task ResetCloudSession(string sessionId);

Task<List<string>> BeginJoin(AskCloudSessionPasswordExchangeKeyParameters parameters, CancellationToken cancellationToken = default);

Task<JoinSessionResult> AskPasswordExchangeKey(AskCloudSessionPasswordExchangeKeyParameters parameters,
CancellationToken cancellationToken = default);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace ByteSync.Interfaces.Controls.Communications;

public interface IFileUploader
{
Action? ValidateAccess { get; set; }
Task Upload();
}
Loading