From nobody Tue Sep 9 19:05:57 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1752766190; cv=none; d=zohomail.com; s=zohoarc; b=nD+cOCwDK7qD/erinedXkuQnGyHDjHxTWO87PfymLrCaTK63VZzblwpiGM/8fcMmi/ZJsK54hqXSGNhh0pdYaWKVX7j1Q46Ie+UejrAVTnUD8kG/dNI1aoFzT4EqhxiMPyiLxRaRsVO6f/B3V9tCagmglpd9cpkUJX8VVzIQdP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752766190; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=UhB0FMYm8DPKcm70OeC3HEZ/joQPXL2lRcZ2cdtioJs=; b=jCtjYeYonpJstiGHEDDk3SQPpbCr7GjjgpUCBtB1lvjsutg5slADU+h8TaupSXuuNVykmrwZBeFlGZwPUN8uCGMgf8TpWbaEHHQ2LQFjPhxVotl+DdwVAWTFzSW/724XzThAUkz+/+DS+/A1Ab/++7LuKKMpW5kLfvdhOlBmPNs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1752766190339729.8903893946801; Thu, 17 Jul 2025 08:29:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 63A97154B; Thu, 17 Jul 2025 11:29:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id D824F145E; Thu, 17 Jul 2025 11:28:33 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 157EF1454; Thu, 17 Jul 2025 11:28:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 13D4213BF for ; Thu, 17 Jul 2025 11:28:22 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-o_L-0dzEM-ebNp3w8QxKeA-1; Thu, 17 Jul 2025 11:28:20 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 48FDF1955EAA for ; Thu, 17 Jul 2025 15:28:19 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.5]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 7C8EE18004AD for ; Thu, 17 Jul 2025 15:28:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752766101; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u1dz0PHQG3GJ//N+hqz1pv1oYOWHiIu53kcs4kcn+iw=; b=Kz58ZadVo4U3QGr2JeOpxYZbY5DVd1tJkjL20WVsr8d1xYfPtfWoGfrUV+A3WP4Lk38beD uI88sUFi9BYgQ3fVSBt1gGg93PgUuJ1eWU3rOK2efgHbNsh2zkK7IttukU+FNAqV5pl62T TyWjhzE83lkCfZ60qsZDdHbUsIEAlg4= X-MC-Unique: o_L-0dzEM-ebNp3w8QxKeA-1 X-Mimecast-MFC-AGG-ID: o_L-0dzEM-ebNp3w8QxKeA_1752766099 To: devel@lists.libvirt.org Subject: [PATCH 5/7] virPKIValidateIdentity: Validate all concatenated certificates Date: Thu, 17 Jul 2025 17:28:08 +0200 Message-ID: <1bb37599fc2cbc7e77789f1ee487d20413d62b35.1752766013.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: LiMJmZ-NWmhw-174mENYeWoJibHMqiLxZ-m4Z8q1Hv4_1752766099 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: H434MNHF3OPH746DRJEOZITQJGZ2Y3YS X-Message-ID-Hash: H434MNHF3OPH746DRJEOZITQJGZ2Y3YS X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1752766192100116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Since gnutls and thus by extension libvirt allows passing multiple certificates in one file by concatenating them, virt-pki-validate ought to validate the hostname of all of them, instead of only the first one to prevent issues when wrong certs are concatenated. Signed-off-by: Peter Krempa --- tools/virt-pki-validate.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/virt-pki-validate.c b/tools/virt-pki-validate.c index e693ffaed6..a8ea396550 100644 --- a/tools/virt-pki-validate.c +++ b/tools/virt-pki-validate.c @@ -283,19 +283,29 @@ virPKIValidateIdentity(bool isServer, bool system, co= nst char *path) } if (isServer) { - gnutls_x509_crt_t crt; + gnutls_x509_crt_t crts[16] =3D { 0 }; + size_t ncrts =3D 0; virValidateCheck(scope, "%s", _("Checking cert hostname match")); - if (!(crt =3D virNetTLSCertLoadFromFile(cert, true))) { + if (virNetTLSCertLoadListFromFile(cert, crts, 16, &ncrts) < 0) { virValidateFail(VIR_VALIDATE_FAIL, _("Unable to load %1$s: %2$s"), cert, virGetLastErrorMessage()); + ok =3D false; } else { g_autofree char *hostname =3D virGetHostname(); - int ret =3D gnutls_x509_crt_check_hostname(crt, hostname); - gnutls_x509_crt_deinit(crt); - if (!ret) { + bool mismatch =3D false; + size_t i; + + for (i =3D 0; i < ncrts; i++) { + if (gnutls_x509_crt_check_hostname(crts[i], hostname) =3D= =3D 0) + mismatch =3D true; + + gnutls_x509_crt_deinit(crts[i]); + } + + if (mismatch) { /* Only warning, since there can be valid reasons for mis-= match */ virValidateFail(VIR_VALIDATE_WARN, _("Certificate %1$s owner does not match t= he hostname %2$s"), --=20 2.50.0