http icon indicating copy to clipboard operation
http copied to clipboard

I want to set the ServerName of TLS to verify the https SNI certificate

Open rayku-chans opened this issue 3 years ago • 0 comments

"HandshakeException: Connection terminated during handshake" or "{"code":401,"message":"Unauthorized"}" error when using flutter HttpClient for SNI request. Ask the operation and maintenance and learn that the two types of errors are different for SSL certificates. Using an RSA certificate will result in a 401 error, and using an ECC certificate will result in a HandshakeException. I don't get this error when I use NodeJS or android native network for such requests Here is the sample code that goes wrong:

import 'dart:convert';
import 'dart:io';

Future<void> main(List<String> arguments) async {
  var url = "https://54.89.26.2/";
  var host = "chans.vip";
  var httpClient = HttpClient();
  httpClient.badCertificateCallback = (a,b,c) => true;
  httpClient.connectionTimeout = Duration(milliseconds: 1500);
  var request = await httpClient.getUrl(Uri.parse(url));
  request.headers.add("host", host);
  HttpClientResponse response = await request.close();
  var body = await response.transform(Utf8Decoder()).join();
  print(body);
}

rayku-chans avatar Feb 25 '22 08:02 rayku-chans