From: Shan Shaji <s.shaji@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox_dart_api_client 2/2] fix: ios: add explicit throw of `HandshakeException`
Date: Mon, 8 Sep 2025 16:11:49 +0200 [thread overview]
Message-ID: <20250908141149.51106-3-s.shaji@proxmox.com> (raw)
In-Reply-To: <20250908141149.51106-1-s.shaji@proxmox.com>
The `cupertino_http` package 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 `NSErrorClientException` and
rethrow `HandShakeException` if the certificate is not valid.
Signed-off-by: Shan Shaji <s.shaji@proxmox.com>
---
lib/src/authenticate.dart | 35 +++++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)
diff --git a/lib/src/authenticate.dart b/lib/src/authenticate.dart
index 118408f..5217578 100644
--- a/lib/src/authenticate.dart
+++ b/lib/src/authenticate.dart
@@ -1,12 +1,13 @@
import 'dart:async';
import 'dart:convert';
+import 'dart:io';
+import 'package:cupertino_http/cupertino_http.dart';
import 'package:http/http.dart' as http;
import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart';
import 'package:proxmox_dart_api_client/src/handle_ticket_response.dart';
import 'package:proxmox_dart_api_client/src/models/serializers.dart';
-
/// Returns an authenticated client to work with if successful.
///
/// This is the function you are looking for if you want to interact with any
@@ -56,6 +57,12 @@ Future<ProxmoxApiClient> authenticate(
} on TimeoutException catch (_) {
throw ProxmoxApiException(
'Authentication takes unusually long, check network connection', 408);
+ } on NSErrorClientException catch (e) {
+ // Treat untrusted server certificate (-1202) as a handshake failure.
+ if (e.error.code == -1202) {
+ throw HandshakeException(e.message);
+ }
+ rethrow;
}
}
@@ -64,14 +71,22 @@ Future<List<PveAccessDomainModel?>> 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 NSErrorClientException catch (e) {
+ // Treat untrusted server certificate (-1202) as a handshake failure.
+ if (e.error.code == -1202) {
+ throw HandshakeException(e.message);
+ }
+ rethrow;
+ }
}
--
2.50.1
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-09-08 14:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 14:11 [pve-devel] [PATCH proxmox_dart_api_client 0/2] fix: ios: add support for custom user certificates Shan Shaji
2025-09-08 14:11 ` [pve-devel] [PATCH proxmox_dart_api_client 1/2] fix: ios: use `cupertino_http` package to honor " Shan Shaji
2025-09-08 14:11 ` Shan Shaji [this message]
2025-09-09 9:58 ` [pve-devel] [PATCH proxmox_dart_api_client 0/2] fix: ios: add support for " Shan Shaji
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250908141149.51106-3-s.shaji@proxmox.com \
--to=s.shaji@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.