From 014a2255dfee3b0c53520d2496acaf7b061a6ff1 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 26 Jan 2018 11:09:23 -0800 Subject: [PATCH] Nicer error message for TLS errors (#14285) Also some trivial improvements to style. --- packages/flutter_tools/lib/src/base/io.dart | 1 + packages/flutter_tools/lib/src/base/net.dart | 13 ++++++++++++- packages/flutter_tools/lib/src/doctor.dart | 18 ++++++++++++------ packages/flutter_tools/lib/src/services.dart | 2 +- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/io.dart b/packages/flutter_tools/lib/src/base/io.dart index 62eaacae3f..a2d945e0b5 100644 --- a/packages/flutter_tools/lib/src/base/io.dart +++ b/packages/flutter_tools/lib/src/base/io.dart @@ -42,6 +42,7 @@ export 'dart:io' // File NO! Use `file_system.dart` // FileSystemEntity NO! Use `file_system.dart` GZIP, + HandshakeException, HttpClient, HttpClientRequest, HttpClientResponse, diff --git a/packages/flutter_tools/lib/src/base/net.dart b/packages/flutter_tools/lib/src/base/net.dart index 52ef656911..24b90b6f08 100644 --- a/packages/flutter_tools/lib/src/base/net.dart +++ b/packages/flutter_tools/lib/src/base/net.dart @@ -37,7 +37,18 @@ Future> _attempt(Uri url) async { } else { httpClient = new HttpClient(); } - final HttpClientRequest request = await httpClient.getUrl(url); + HttpClientRequest request; + try { + request = await httpClient.getUrl(url); + } on HandshakeException catch (error) { + printTrace(error.toString()); + throwToolExit( + 'Could not authenticate download server. You may be experiencing a man-in-the-middle attack,\n' + 'your network may be compromised, or you may have malware installed on your computer.\n' + 'URL: $url', + exitCode: kNetworkProblemExitCode, + ); + } final HttpClientResponse response = await request.close(); if (response.statusCode != 200) { if (response.statusCode > 0 && response.statusCode < 500) { diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index 8af7acc68e..685bd0ed82 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -199,10 +199,13 @@ class _FlutterValidator extends DoctorValidator { final FlutterVersion version = FlutterVersion.instance; messages.add(new ValidationMessage('Flutter version ${version.frameworkVersion} at ${Cache.flutterRoot}')); - if (Cache.flutterRoot.contains(' ')) + if (Cache.flutterRoot.contains(' ')) { messages.add(new ValidationMessage.error( - 'Flutter SDK install paths with spaces are not yet supported. (https://github.com/flutter/flutter/issues/6577)\n' - 'Please move the SDK to a path that does not include spaces.')); + 'Flutter SDK install paths with spaces are not yet supported. ' + '(https://github.com/flutter/flutter/issues/6577)\n' + 'Please move the SDK to a path that does not include spaces.' + )); + } messages.add(new ValidationMessage( 'Framework revision ${version.frameworkRevisionShort} ' '(${version.frameworkAge}), ${version.frameworkDate}' @@ -215,13 +218,16 @@ class _FlutterValidator extends DoctorValidator { // Check that the binaries we downloaded for this platform actually run on it. if (!_genSnapshotRuns(genSnapshotPath)) { - messages.add(new ValidationMessage.error('Downloaded executables cannot execute ' - 'on host (see https://github.com/flutter/flutter/issues/6207 for more information)')); + messages.add(new ValidationMessage.error( + 'Downloaded executables cannot execute ' + 'on host (see https://github.com/flutter/flutter/issues/6207 for more information)' + )); valid = ValidationType.partial; } return new ValidationResult(valid, messages, - statusInfo: 'on ${os.name}, locale ${platform.localeName}, channel ${version.channel}'); + statusInfo: 'on ${os.name}, locale ${platform.localeName}, channel ${version.channel}' + ); } } diff --git a/packages/flutter_tools/lib/src/services.dart b/packages/flutter_tools/lib/src/services.dart index e4e0ff2668..863b098e14 100644 --- a/packages/flutter_tools/lib/src/services.dart +++ b/packages/flutter_tools/lib/src/services.dart @@ -78,7 +78,7 @@ Future getServiceFromUrl(String url, String rootDir, String serviceName) if (url.startsWith('android-sdk:') && androidSdk != null) { // It's something shipped in the standard android SDK. return url.replaceAll('android-sdk:', '${androidSdk.directory}/'); - } else if (url.startsWith('http')) { + } else if (url.startsWith('http:') || url.startsWith('https:')) { // It's a regular file to download. return await cache.getThirdPartyFile(url, serviceName); } else {