refactor(masque): allow empty credentials and enable TLS by default (#10601)

- Accept empty username/password, which is common in MASQUE + WARP
  setups where credentials are optional.
- Enable TLS by default, as forced by Xray and sing-box.
This commit is contained in:
Kazuto Iris
2026-11-15 19:03:57 +08:00
committed by GitHub
parent f5bdbe3466
commit c374f26d28
5 changed files with 18 additions and 9 deletions
@@ -777,10 +777,6 @@ public static class ConfigDbHandler
{
profileItem.StreamSecurity = Global.StreamSecurity;
}
if (profileItem.Password.IsNullOrEmpty())
{
return -1;
}
await AddServerCommon(profileItem, toFile);
return 0;
}
@@ -656,8 +656,11 @@ public partial class CoreConfigV2rayService
case "masque":
var headers = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var authValue = $"Basic {Utils.Base64Encode($"{_node.Username}:{_node.Password}")}";
headers.Add("Authorization", authValue);
if (!string.IsNullOrEmpty(_node.Username) || !string.IsNullOrEmpty(_node.Password))
{
var authValue = $"Basic {Utils.Base64Encode($"{_node.Username}:{_node.Password}")}";
headers.Add("Authorization", authValue);
}
if (!string.IsNullOrEmpty(protocolExtra?.MasqueHeaders))
{
var userHeaders = Utils.ParseHeaders(protocolExtra.MasqueHeaders)
@@ -501,7 +501,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
return;
}
}
if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP)
if (SelectedSource.ConfigType is not EConfigType.SOCKS and not EConfigType.HTTP and not EConfigType.MASQUE)
{
if (SelectedSource.Password.IsNullOrEmpty())
{
@@ -311,6 +311,11 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
gridMasque.IsVisible = true;
sepa2.IsVisible = false;
gridTransport.IsVisible = false;
lstStreamSecurity.Remove(string.Empty);
if (string.IsNullOrEmpty(profileItem.StreamSecurity))
{
profileItem.StreamSecurity = lstStreamSecurity.First();
}
break;
}
cmbStreamSecurity.ItemsSource = lstStreamSecurity;
@@ -334,7 +339,7 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
private void CmbStreamSecurity_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
var security = cmbStreamSecurity.SelectedItem.ToString();
var security = cmbStreamSecurity.SelectedItem?.ToString();
if (security == Global.StreamSecurityReality)
{
gridRealityMore.IsVisible = true;
+6 -1
View File
@@ -299,6 +299,11 @@ public partial class AddServerWindow
gridMasque.Visibility = Visibility.Visible;
sepa2.Visibility = Visibility.Collapsed;
gridTransport.Visibility = Visibility.Collapsed;
lstStreamSecurity.Remove(string.Empty);
if (string.IsNullOrEmpty(profileItem.StreamSecurity))
{
profileItem.StreamSecurity = lstStreamSecurity.First();
}
break;
}
cmbStreamSecurity.ItemsSource = lstStreamSecurity;
@@ -322,7 +327,7 @@ public partial class AddServerWindow
private void CmbStreamSecurity_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var security = cmbStreamSecurity.SelectedItem.ToString();
var security = cmbStreamSecurity.SelectedItem?.ToString();
if (security == Global.StreamSecurityReality)
{
gridRealityMore.Visibility = Visibility.Visible;