diff --git a/utils/dotnet/Devolutions.Gateway.Utils.Tests/JsonSerializationTests.cs b/utils/dotnet/Devolutions.Gateway.Utils.Tests/JsonSerializationTests.cs index 7cac82088..97a40e860 100644 --- a/utils/dotnet/Devolutions.Gateway.Utils.Tests/JsonSerializationTests.cs +++ b/utils/dotnet/Devolutions.Gateway.Utils.Tests/JsonSerializationTests.cs @@ -82,6 +82,29 @@ public void JmuxClaimsHttpAllowAnyAdditional() Assert.Equal(EXPECTED, result); } + [Fact] + public void JmuxClaimsHttpAllowAnyPort() + { + const string EXPECTED = """{"dst_hst":"http://hello.world:0","dst_addl":["https://example.com:0","tcp://test.com:0"],"jet_ap":"http","jet_aid":"3e7c1854-f1eb-42d2-b9cb-9303036e50da","jet_gw_id":"ccbaad3f-4627-4666-8bb5-cb6a1a7db815"}"""; + + var claims = new JmuxClaims(gatewayId, "http://hello.world:80", ApplicationProtocol.Http, sessionId); + claims.AdditionalDestinations = new List { "https://example.com:443", "tcp://test.com:8080" }; + claims.HttpAllowAnyPort(); + string result = JsonSerializer.Serialize(claims); + Assert.Equal(EXPECTED, result); + } + + [Fact] + public void JmuxClaimsHttpAllowAnything() + { + const string EXPECTED = """{"dst_hst":"http://hello.world:80","dst_addl":["http://*:0","https://*:0"],"jet_ap":"http","jet_aid":"3e7c1854-f1eb-42d2-b9cb-9303036e50da","jet_gw_id":"ccbaad3f-4627-4666-8bb5-cb6a1a7db815"}"""; + + var claims = new JmuxClaims(gatewayId, "http://hello.world", ApplicationProtocol.Http, sessionId); + claims.HttpAllowAnything(); + string result = JsonSerializer.Serialize(claims); + Assert.Equal(EXPECTED, result); + } + [Fact] public void AssociationClaims() { diff --git a/utils/dotnet/Devolutions.Gateway.Utils/src/JmuxClaims.cs b/utils/dotnet/Devolutions.Gateway.Utils/src/JmuxClaims.cs index 4e00682dc..5daee5309 100644 --- a/utils/dotnet/Devolutions.Gateway.Utils/src/JmuxClaims.cs +++ b/utils/dotnet/Devolutions.Gateway.Utils/src/JmuxClaims.cs @@ -78,6 +78,35 @@ public void HttpExpandAdditionals() } } + /// Modify all destinations to set the port to 0 (wildcard port). + public void HttpAllowAnyPort() + { + // Set the main destination port to 0 + this.Destination = new TargetAddr(this.Destination.Scheme, this.Destination.Host, 0); + + // Set all additional destinations ports to 0 + if (this.AdditionalDestinations != null) + { + for (int i = 0; i < this.AdditionalDestinations.Count; i++) + { + var dest = this.AdditionalDestinations[i]; + this.AdditionalDestinations[i] = new TargetAddr(dest.Scheme, dest.Host, 0); + } + } + } + + /// Insert *:0 to allow any port for any destination. + public void HttpAllowAnything() + { + if (this.AdditionalDestinations is null) + { + this.AdditionalDestinations = new List(); + } + + this.AdditionalDestinations.Add(new TargetAddr("http", "*", 0)); + this.AdditionalDestinations.Add(new TargetAddr("https", "*", 0)); + } + public string GetContentType() { return "JMUX";