From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C1E97D673 for ; Thu, 1 Dec 2022 10:27:36 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A8A6726F64 for ; Thu, 1 Dec 2022 10:27:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 1 Dec 2022 10:27:36 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id C6BB043940 for ; Thu, 1 Dec 2022 10:27:35 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Thu, 1 Dec 2022 10:27:34 +0100 Message-Id: <20221201092734.1171699-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.086 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_2 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_4 0.1 random spam to be learned in bayes 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-login-manager] login: fix login for saved ipv6 addresses 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: , X-List-Received-Date: Thu, 01 Dec 2022 09:27:36 -0000 Since we only string concatenated the host + port, ipv6 addresses were invalid because their missing [] around the ip. To fix that, use 'Uri's 'toString' method but strip the 'https://' prefix when creating an Uri object again This now also allows to enter the 'https://' prefix manually Signed-off-by: Dominik Csapak --- lib/proxmox_login_form.dart | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/proxmox_login_form.dart b/lib/proxmox_login_form.dart index 706315f..41bf68f 100644 --- a/lib/proxmox_login_form.dart +++ b/lib/proxmox_login_form.dart @@ -197,8 +197,7 @@ class _ProxmoxLoginPageState extends State { _progressModel ..inProgress = true ..message = 'Connection test...'; - _originController.text = - '${userModel.origin?.host}:${userModel.origin?.port}'; + _originController.text = userModel.origin?.toString() ?? ''; _accessDomains = _getAccessDomains(); _usernameController.text = userModel.username!; if (widget.ticket!.isNotEmpty && userModel.activeSession) { @@ -279,15 +278,13 @@ class _ProxmoxLoginPageState extends State { if (value == null || value.isEmpty) { return 'Please enter origin'; } - if (value.startsWith('https://') || - value.startsWith('http://')) { - return 'Do not prefix with scheme'; - } try { - Uri.https(value, ''); + normalizeUrl(value); return null; } on FormatException catch (_) { return 'Invalid URI'; + } on Exception catch (e) { + return 'Invalid URI: $e'; } }, usernameController: _usernameController, @@ -412,7 +409,7 @@ class _ProxmoxLoginPageState extends State { final settings = await ProxmoxGeneralSettingsModel.fromLocalStorage(); //cleaned form fields - final origin = Uri.https(_originController.text.trim(), ''); + final origin = normalizeUrl(_originController.text.trim()); final username = _usernameController.text.trim(); final password = ticket.isNotEmpty ? ticket : _passwordController.text.trim(); @@ -502,7 +499,7 @@ class _ProxmoxLoginPageState extends State { ..message = 'Connection test...'; }); var host = _originController.text.trim(); - var apiBaseUrl = Uri.https(host, ''); + var apiBaseUrl = normalizeUrl(host); RegExp portRE = new RegExp(r":\d{1,5}$"); @@ -667,3 +664,14 @@ class ProxmoxCertificateErrorDialog extends StatelessWidget { ); } } + +Uri normalizeUrl(String urlText) { + if (urlText.startsWith('https://')) { + urlText = urlText.substring('https://'.length); + } + if (urlText.startsWith('http://')) { + throw new Exception("HTTP without TLS is not supported"); + } + + return Uri.https(urlText, ''); +} -- 2.30.2