Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSocket support custom sni host,when use doh #374

Open
weatherfish opened this issue Jun 6, 2024 · 1 comment
Open

WebSocket support custom sni host,when use doh #374

weatherfish opened this issue Jun 6, 2024 · 1 comment

Comments

@weatherfish
Copy link

In someplace, the dns server is not work well, so we need use doh (DNS OVER HTTP)to resolve first.
but when I repace the hsot to ip and call like that, server recieved error host

  Uri wsUri = Uri.parse(webSocketUrl);
  if (useDOH) {
    final domain = wsUri.host;
    if (domain.isNotEmpty && !CliNetUtils.isIpV4Address(domain) && !CliNetUtils.isIPv6(domain)) {
      final ip = await CliNetDns().adjustIp(domain);
      if (ip?.isNotEmpty ?? false) {
        webSocketUrl = '${wsUri.scheme}://$ip:${wsUri.port}${wsUri.path}';
        headers = {'Host': domain};
      }
    }
  }
  HttpClient client = HttpClient();
  client.badCertificateCallback = (X509Certificate cr, String host, int port) {
    return true;
  };

  WebSocket channel = await WebSocket.connect(webSocketUrl, customClient: client, headers: headers);

the headers params not gived to tls,so when tls check it return

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketChannelException: 
HandshakeException: Handshake error in client (OS Error: SSLV3_ALERT_HANDSHAKE_FAILURE(tls_record.cc:592)
HANDSHAKE_FAILURE_ON_CLIENT_HELLO(handshake.cc:644))
@932707629
Copy link

I used IOWebSocketChannel and HtmlWebSocketChannel to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants