Insecure mode for https forwarding (#79)

This commit is contained in:
Pavel Iakovenko 2024-02-26 06:37:49 -05:00 коммит произвёл GitHub
Родитель 3ffabee941
Коммит 89b5018407
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 17 добавлений и 5 удалений

Просмотреть файл

@ -385,6 +385,7 @@ used on the same entry. For multiple bindings they can be used to form a list.
* **HostPort** - TCP port on the host to forward to
* **PortName** - Logical port name
* **LocalSocket** - named UNIX socket forward to
* **Insecure** - ignores certificate validation errors for https forwarding
Examples:

Просмотреть файл

@ -103,6 +103,12 @@
set;
}
public bool Insecure
{
get;
set;
}
public string Path
{
get;

Просмотреть файл

@ -109,7 +109,7 @@ namespace Microsoft.Azure.Relay.Bridge
if (binding.Http)
{
var tcpRemoteForwarder =
new TcpRemoteForwarder(this.config, remoteForward.RelayName, binding.PortName, binding.Host, binding.HostPort, binding.Path, binding.Http);
new TcpRemoteForwarder(this.config, remoteForward.RelayName, binding.PortName, binding.Host, binding.HostPort, binding.Path, binding.Http, binding.Insecure);
remoteForwarders.Add(tcpRemoteForwarder.PortName, tcpRemoteForwarder);
}
else if (!string.IsNullOrEmpty(binding.LocalSocket))
@ -127,7 +127,7 @@ namespace Microsoft.Azure.Relay.Bridge
else if (binding.HostPort > 0)
{
var tcpRemoteForwarder =
new TcpRemoteForwarder(this.config, remoteForward.RelayName, binding.PortName, binding.Host, binding.HostPort, binding.Path, binding.Http);
new TcpRemoteForwarder(this.config, remoteForward.RelayName, binding.PortName, binding.Host, binding.HostPort, binding.Path, binding.Http, binding.Insecure);
remoteForwarders.Add(tcpRemoteForwarder.PortName, tcpRemoteForwarder);
}
else if (binding.HostPort < 0)

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.Azure.Relay.Bridge
private HttpClient httpClient;
private string relaySubpath;
internal TcpRemoteForwarder(Config config, string relayName, string portName, string targetServer, int targetPort, string targetPath, bool http)
internal TcpRemoteForwarder(Config config, string relayName, string portName, string targetServer, int targetPort, string targetPath, bool http, bool insecure)
{
this.config = config;
this.PortName = portName;
@ -38,7 +38,12 @@ namespace Microsoft.Azure.Relay.Bridge
if ( http )
{
this.httpClient = new HttpClient();
var httpHandler = new HttpClientHandler();
if ( insecure )
{
httpHandler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
}
this.httpClient = new HttpClient(httpHandler);
this.httpClient.BaseAddress = new UriBuilder(portName, targetServer, targetPort, targetPath).Uri;
this.httpClient.DefaultRequestHeaders.ExpectContinue = false;
this.relaySubpath = "/" + relayName;