flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.7k stars 27.36k forks source link

[windows][sandoxed] Release mode throws Handshake error when making network request #88869

Open krll-kov opened 3 years ago

krll-kov commented 3 years ago

I've made a flutter desktop app, build it in a Release mode and decided to test in on Windows' SandBox. The problem is that any https request to any server leads to "Handshake error in client (OS Error: CERTIFICATE_VERIFY_FAILED: unable to get local issuer certificate(handshake.cc:363))" error. If this happens on an official SandBox, it also might happen on default Windows version of some user. In this example i'm making request to Google Analytics server and encounter this error.

minimal code sample ```dart import 'dart:io'; import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatefulWidget { @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State { String text = 'No errors!'; @override void initState() { WidgetsBinding.instance?.addPostFrameCallback((timeStamp) async { try { HttpClientRequest request = await HttpClient().postUrl(Uri.parse( 'https://www.google-analytics.com/mp/collect?measurement_id=test&api_secret=test2')); HttpClientResponse response = await request.close(); setState(() => text = 'Request was successfully sent to the Google server. Status code: ${response.statusCode.toString()}'); } catch (error) { setState(() => text = error.toString()); } }); super.initState(); } @override Widget build(BuildContext context) { return MaterialApp( title: 'Material App', home: Scaffold( appBar: AppBar( title: Text('Material App Bar'), ), body: Center( child: Container( child: Text(text), ), ), ), ); } } ```
preview Sandbox: ![image](https://user-images.githubusercontent.com/63228361/130776743-2461e987-8ac3-4ce3-be73-42ef745e990f.png) My pc: ![image](https://user-images.githubusercontent.com/63228361/130776817-18cf6898-d529-45d1-83ff-987c3191ffbc.png)

I also found a solution to this problem but i'm not sure that it's safe to allow any certificate to be used

class FixSSLOverride extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) {
    return super.createHttpClient(context)
      ..badCertificateCallback =
          (X509Certificate cert, String host, int port) => true;
  }
}

HttpOverrides.global = FixSSLOverride();

Flutter doctor -v

flutter doctor -v ```console [√] Flutter (Channel stable, 2.2.3, on Microsoft Windows [Version 10.0.19043.1165], locale en-US) • Flutter version 2.2.3 at C:\Install\flutter • Framework revision f4abaa0735 (8 weeks ago), 2021-07-01 12:46:11 -0700 • Engine revision 241c87ad80 • Dart version 2.13.4 [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\Users\karnm\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.3 • Java binary at: C:\Install\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.4) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.9.31205.134 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio (version 4.1.0) • Android Studio at C:\Install\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [√] IntelliJ IDEA Ultimate Edition (version 2021.1) • IntelliJ at C:\Install\IntelliJ IDEA 2020.3.1 • Flutter plugin version 58.0.3 • Dart plugin version 211.7727 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19043.1165] • Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.77 • Edge (web) • edge • web-javascript • Microsoft Edge 92.0.902.78 • No issues found! ```
TahaTesser commented 3 years ago

Hi @kirill-21 macOS, are sandboxed you cant make network calls in Sandbox mode, This applies to Windows as you're testing in Sandbox. Using new project in release mode, there is no such issue

krll-kov commented 3 years ago

Hi @kirill-21 macOS, are sandboxed you cant make network calls in Sandbox mode, This applies to Windows as you're testing in Sandbox. Using new project in release mode, there is no such issue

Well, making https request with apps developed with other programming languages (on sandbox) work fine, tcp/udp socket connections(with dart) work fine, other apps with network part work fine, browsers work fine. But flutter app in release mode can not make https requests (on sandbox).

Windows is not macOS, it has totally different sandbox image

flutter-triage-bot[bot] commented 4 months ago

The triaged-desktop label is irrelevant if there is no team-desktop label or fyi-desktop label.