Merge branch 'main' of https://github.com/LD-Reborn/Ngino
Build & Deploy / build (push) Successful in 1m53s
Build & Deploy / build (push) Successful in 1m53s
This commit is contained in:
@@ -18,6 +18,8 @@ internal sealed class ClientOptions
|
||||
|
||||
public int ChunkSize { get; init; } = 64 * 1024;
|
||||
|
||||
public bool InsecureSkipTlsVerify { get; init; }
|
||||
|
||||
public Uri TunnelUri
|
||||
{
|
||||
get
|
||||
@@ -53,7 +55,8 @@ internal sealed class ClientOptions
|
||||
Token = Read(values, "token", "NGINO_TOKEN"),
|
||||
ClientId = Read(values, "client-id", "NGINO_CLIENT_ID") ?? Environment.MachineName.ToLowerInvariant(),
|
||||
ReconnectDelay = TimeSpan.FromSeconds(ReadInt(values, 5, "reconnect-delay", "NGINO_RECONNECT_DELAY_SECONDS")),
|
||||
ChunkSize = ReadInt(values, 64 * 1024, "chunk-size", "NGINO_CHUNK_SIZE")
|
||||
ChunkSize = ReadInt(values, 64 * 1024, "chunk-size", "NGINO_CHUNK_SIZE"),
|
||||
InsecureSkipTlsVerify = ReadBool(values, false, "insecure-skip-tls-verify", "NGINO_INSECURE_SKIP_TLS_VERIFY")
|
||||
};
|
||||
}
|
||||
|
||||
@@ -67,6 +70,7 @@ internal sealed class ClientOptions
|
||||
--tunnel-path <path> Defaults to /_ngino/tunnel
|
||||
--reconnect-delay <sec> Defaults to 5
|
||||
--chunk-size <bytes> Defaults to 65536
|
||||
--insecure-skip-tls-verify Disable server TLS certificate validation (unsafe)
|
||||
""";
|
||||
|
||||
private static Dictionary<string, string> ParseArgs(string[] args)
|
||||
@@ -88,6 +92,12 @@ internal sealed class ClientOptions
|
||||
continue;
|
||||
}
|
||||
|
||||
if (keyValue[0].Equals("insecure-skip-tls-verify", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
values[keyValue[0]] = "true";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i + 1 >= args.Length || args[i + 1].StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
throw new ArgumentException($"Missing value for '{arg}'.");
|
||||
@@ -124,6 +134,12 @@ internal sealed class ClientOptions
|
||||
return int.TryParse(value, out var parsed) && parsed > 0 ? parsed : fallback;
|
||||
}
|
||||
|
||||
private static bool ReadBool(Dictionary<string, string> values, bool fallback, params string[] keys)
|
||||
{
|
||||
var value = Read(values, keys);
|
||||
return bool.TryParse(value, out var parsed) ? parsed : fallback;
|
||||
}
|
||||
|
||||
private static Uri ReadUri(Dictionary<string, string> values, string key, string envKey, string fallback)
|
||||
{
|
||||
var value = Read(values, key, envKey) ?? fallback;
|
||||
|
||||
@@ -11,6 +11,10 @@ try
|
||||
Console.WriteLine($" client id: {options.ClientId}");
|
||||
Console.WriteLine($" server tunnel: {options.TunnelUri}");
|
||||
Console.WriteLine($" local upstream: {options.Upstream}");
|
||||
if (options.InsecureSkipTlsVerify)
|
||||
{
|
||||
Console.WriteLine(" WARNING: server TLS certificate validation is disabled");
|
||||
}
|
||||
|
||||
// Args are parsed by ClientOptions; keep them away from the host configuration.
|
||||
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings { Args = [] });
|
||||
|
||||
@@ -41,6 +41,11 @@ internal sealed class TunnelClient
|
||||
using var socket = new ClientWebSocket();
|
||||
socket.Options.KeepAliveInterval = TimeSpan.FromSeconds(30);
|
||||
|
||||
if (_options.InsecureSkipTlsVerify)
|
||||
{
|
||||
socket.Options.RemoteCertificateValidationCallback = static (_, _, _, _) => true;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(_options.Token))
|
||||
{
|
||||
socket.Options.SetRequestHeader(ProtocolConstants.TokenHeader, _options.Token);
|
||||
|
||||
Reference in New Issue
Block a user