From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 393CE1FF16F for ; Tue, 2 Sep 2025 12:17:52 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 220BCFA74; Tue, 2 Sep 2025 12:18:06 +0200 (CEST) From: Shan Shaji To: pve-devel@lists.proxmox.com Date: Tue, 2 Sep 2025 12:17:13 +0200 Message-ID: <20250902101713.82292-4-s.shaji@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250902101713.82292-1-s.shaji@proxmox.com> References: <20250902101713.82292-1-s.shaji@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1756808238169 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.163 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH proxmox_dart_api_client 2/2] fix: add explicit throw of `HandShakeException` X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox VE development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" The `cronet_http` is throwing `ClientException` [0] instead of `HandShakeException` when the certificate is not valid. Due to this the exception was directly shown in the UI. Inorder to make the error more user friendly catch the `ClientException` and rethrow `HandShakeException` if the certificate is not valid. [0] - https://github.com/dart-lang/http/blob/ef05b3744424885d93f88a6a50664fb5b7d5cbdb/pkgs/cronet_http/lib/src/cronet_client.dart#L327 Signed-off-by: Shan Shaji --- lib/src/authenticate.dart | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/src/authenticate.dart b/lib/src/authenticate.dart index 118408f..a142a4c 100644 --- a/lib/src/authenticate.dart +++ b/lib/src/authenticate.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:io'; import 'package:http/http.dart' as http; import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart'; @@ -56,6 +57,11 @@ Future authenticate( } on TimeoutException catch (_) { throw ProxmoxApiException( 'Authentication takes unusually long, check network connection', 408); + } on http.ClientException catch (e) { + if (e.message.contains('net::ERR_CERT_AUTHORITY_INVALID')) { + throw HandshakeException(e.message); + } + rethrow; } } @@ -64,14 +70,21 @@ Future> accessDomains( bool validateSSL, { http.Client? httpClient, }) async { - httpClient ??= getCustomIOHttpClient(validateSSL: validateSSL); + try { + httpClient ??= getCustomIOHttpClient(validateSSL: validateSSL); - final path = '/api2/json/access/domains'; - final response = await httpClient - .get(apiBaseUrl.replace(path: path)) - .timeout(Duration(seconds: 25)); - var data = (json.decode(response.body)['data'] as List).map((f) { - return serializers.deserializeWith(PveAccessDomainModel.serializer, f); - }); - return data.toList(); + final path = '/api2/json/access/domains'; + final response = await httpClient + .get(apiBaseUrl.replace(path: path)) + .timeout(Duration(seconds: 25)); + var data = (json.decode(response.body)['data'] as List).map((f) { + return serializers.deserializeWith(PveAccessDomainModel.serializer, f); + }); + return data.toList(); + } on http.ClientException catch (e) { + if (e.message.contains('net::ERR_CERT_AUTHORITY_INVALID')) { + throw HandshakeException(e.message); + } + rethrow; + } } -- 2.47.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel