Harden CultMesh route fallback and secure onboarding
This commit is contained in:
parent
f622ee1b24
commit
c194bd4cc8
11 changed files with 329 additions and 47 deletions
|
|
@ -1084,16 +1084,21 @@ namespace GameCult.Mesh
|
|||
CultMeshSessionTarget target,
|
||||
CultMeshProtocolId protocol)
|
||||
{
|
||||
return discovery.Candidates
|
||||
var routes = discovery.Candidates
|
||||
.SelectMany(candidate => candidate.Descriptor.AuthorityRoutes)
|
||||
.Where(route => string.Equals(
|
||||
route.AuthorityRuntimeId,
|
||||
target.AuthorityRuntimeId,
|
||||
StringComparison.Ordinal))
|
||||
.Where(route => route.Supports(protocol))
|
||||
.GroupBy(route => route.Endpoint, StringComparer.Ordinal)
|
||||
.Select(group => group.OrderBy(route => route.Priority).First())
|
||||
.Select(route => new CultMeshTransportCandidate(
|
||||
.ToArray();
|
||||
var verified = new List<CultMeshTransportCandidate>();
|
||||
var rejected = new List<Exception>();
|
||||
foreach (var route in routes)
|
||||
{
|
||||
try
|
||||
{
|
||||
verified.Add(new CultMeshTransportCandidate(
|
||||
route.Endpoint,
|
||||
priority: route.Priority,
|
||||
authorityRuntimeId: route.AuthorityRuntimeId,
|
||||
|
|
@ -1102,7 +1107,23 @@ namespace GameCult.Mesh
|
|||
.WithVerifiedAuthority(_options.Trust.Verify(
|
||||
target.VerseId,
|
||||
route,
|
||||
_options.Clock.UtcNow)))
|
||||
_options.Clock.UtcNow)));
|
||||
}
|
||||
catch (CultMeshSessionException error)
|
||||
{
|
||||
rejected.Add(error);
|
||||
}
|
||||
}
|
||||
if (verified.Count == 0 && rejected.Count > 0)
|
||||
{
|
||||
throw Failure(
|
||||
CultMeshSessionFailureReason.Authentication,
|
||||
$"No trusted route remained for CultMesh target '{target}' and protocol '{protocol}'.",
|
||||
new AggregateException(rejected));
|
||||
}
|
||||
return verified
|
||||
.GroupBy(candidate => candidate.Endpoint, StringComparer.Ordinal)
|
||||
.Select(group => group.OrderBy(candidate => candidate.Priority).First())
|
||||
.OrderBy(candidate => candidate.Priority)
|
||||
.ThenBy(candidate => candidate.Endpoint, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
|
|
|||
|
|
@ -207,6 +207,12 @@ namespace GameCult.Mesh
|
|||
/// </summary>
|
||||
public Func<ICultNetSchemaClient>? CreateClient { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an endpoint-aware client factory for external transport packages.
|
||||
/// When present, this owns discovery transport selection for each exact Odin route.
|
||||
/// </summary>
|
||||
public Func<string, ICultNetSchemaClient>? CreateClientForEndpoint { get; set; }
|
||||
|
||||
/// <summary>Gets or sets the clock that owns discovery deadlines.</summary>
|
||||
public ICultMeshClock Clock { get; set; } = CultMeshSystemClock.Instance;
|
||||
|
||||
|
|
@ -341,7 +347,8 @@ namespace GameCult.Mesh
|
|||
|
||||
private ICultNetSchemaClient CreateClient(string endpoint)
|
||||
{
|
||||
return _options.CreateClient?.Invoke()
|
||||
return _options.CreateClientForEndpoint?.Invoke(endpoint)
|
||||
?? _options.CreateClient?.Invoke()
|
||||
?? CultNetSchemaClients.CreateForEndpoint(endpoint, _options.Security, _options.ConfigureClient);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ become usable by merely repeating the expected Verse and runtime strings.
|
|||
|
||||
```csharp
|
||||
using GameCult.Mesh;
|
||||
using GameCult.Networking.WebSockets;
|
||||
|
||||
var odinEndpoint = Environment.GetEnvironmentVariable("ODIN_ENDPOINT")
|
||||
?? throw new InvalidOperationException("Set ODIN_ENDPOINT to the configured rendezvous route.");
|
||||
|
|
@ -33,11 +34,22 @@ var odinRoot = new CultMeshEcdsaP256PublicKey(
|
|||
using var mesh = new CultMeshClient(new CultMeshClientOptions
|
||||
{
|
||||
RendezvousEndpoints = new[] { odinEndpoint },
|
||||
Discovery = new CultMeshVerseDiscoveryClientOptions
|
||||
{
|
||||
CreateClientForEndpoint = _ => new CultNetWebSocketSchemaClient()
|
||||
},
|
||||
Sessions = new CultMeshSessionManagerOptions
|
||||
{
|
||||
Trust = new CultMeshAuthorityTrustPolicy(
|
||||
CultMeshAuthorityTrustMode.AuthenticatedRemote,
|
||||
new[] { odinRoot })
|
||||
},
|
||||
Connectors = new ICultMeshTransportConnector[]
|
||||
{
|
||||
new CultMeshUriSchemaTransportConnector(
|
||||
"cultnet-websocket",
|
||||
new[] { "wss" },
|
||||
_ => new CultNetWebSocketSchemaClient())
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -93,6 +105,30 @@ provider names, and Odin wire fields cannot turn this exception on. Remote
|
|||
routes require a trusted Odin signature, provider nonce proof, certificate
|
||||
validity, and a protected channel.
|
||||
|
||||
The remote example requires both `GameCult.Mesh` and
|
||||
`GameCult.Networking.WebSockets` at the same CultLib package version. Core
|
||||
CultMesh does not silently install a network stack: the consumer chooses the
|
||||
secure connector and its TLS policy. The default TCP connector exists for the
|
||||
explicit loopback-development case and cannot satisfy authenticated-remote
|
||||
trust.
|
||||
|
||||
An authenticated provider receives an Odin-certified route and its matching
|
||||
provider private key from deployment configuration. It attaches the proof gate
|
||||
to the same WSS schema server before publishing the route:
|
||||
|
||||
```csharp
|
||||
using var identity = new CultMeshSessionIdentityServer(
|
||||
schemaServer,
|
||||
authorityRuntimeId: "sample.counter-daemon",
|
||||
verseIds: new[] { "sample.counter" },
|
||||
protocolIds: new[] { CultMeshProtocols.Documents.Value },
|
||||
routeGenerations: new[] { certifiedRoute.Generation },
|
||||
proofSigners: new[] { new CultMeshSessionProofSigner(certifiedRoute, providerPrivateKey) });
|
||||
```
|
||||
|
||||
`certifiedRoute` is the exact signed route Odin publishes. The provider never
|
||||
holds Odin's signing key, and an unsigned WSS route is still untrusted.
|
||||
|
||||
Fast session-management check (this uses controlled transports; it is not the
|
||||
network proof):
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue