From nobody Mon Nov 23 04:44:14 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1794318577; cv=none; d=zohomail.com; s=zohoarc; b=I1M/ztqYni04eQZ0p4zU9frf3VK7EkqK+nQ9g1+djLBS6u2GRnaLZQLtT7Uoiud/4q8dd9YE+UqPSaNQjERxzXOF/qRnjoBAAK055Uoc4+9TuiPdcIj4cUyTDYB3NO6mg/Dstpvqs9hmfvUJAEMBzhIbSwemIdgvVm+PXQBgQg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1794318577; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=MU/hWuJhy9vPXtZ1xFRCzD80SgcRCoDtxuyDTNZiAWI=; b=hRtb7yex+L9P5t/reEf0RrpO5+QenjzMW0HBHK7RG+0G80o1GO041H9zRuuULvS1rbRxDjKcUM2E+x6H6U9iRthYHR57YHlzwmirAGD/SUdZWa7eZAwUqfhJM59mtg5VoqttxLy0D4Q2yayLBZ3Mk4+CuIdaCrrhVAtrnKSatt8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1794318576399896.0014081463048; Tue, 10 Nov 2026 05:49:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xQmDV-0002lj-Me; Tue, 10 Nov 2026 08:48:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xQmDU-0002lR-6q for qemu-devel@nongnu.org; Tue, 10 Nov 2026 08:48:52 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1xQmDR-0007eU-Mv for qemu-devel@nongnu.org; Tue, 10 Nov 2026 08:48:51 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-4a35a60499eso15762615e9.0 for ; Tue, 10 Nov 2026 05:48:49 -0800 (PST) Received: from lanath.. (wildly.archaic.org.uk. [81.2.115.145]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-49835d2c05dsm5087444f8f.25.2026.11.10.05.48.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Nov 2026 05:48:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1794318527; x=1794923327; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=MU/hWuJhy9vPXtZ1xFRCzD80SgcRCoDtxuyDTNZiAWI=; b=N3kVgN3wl3RzmLTYooM4fZw84M7CHZMoo62scfi/aWJf5S4mfZGpU8SxIicRqmu5Ov Des6v6V/FZzyD8ehfa3BaBu5Azk+r0AD2m9tsa7GC7XbSYon9jULTgUpriy8b9jI0tlZ 0bRxSF/2H3y3bK+WvcQeGlUL1x1S6K+8Pfwa92XqlVm/TaGDs9UIy9/icOQPro2onKNl hsWIPi1vNDngcDoucbrIh4xQ3XkQl4LTFFCTfcSr43zvkgTf4TTCS6VrAoEEIU2nWOSI kf/pX1mrWKhn9MCAKRwTTd3+SQ/a24cLLUhK7rdpR1wDLZA/ZZhUKcqnAPr/wYSRKX1Y YeOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794318527; x=1794923327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MU/hWuJhy9vPXtZ1xFRCzD80SgcRCoDtxuyDTNZiAWI=; b=F8MXJ8oGwDjqJ3J20ZdDT2gsRuh1gvHiVWvwK8RfLokiTVa7aer3w2eVm+65SN8V7F 2r1Rzp/SqqE7T/+miThS381aqV+0q9BpZGzfH1qs9OuoNeVamzrFUpP9Qe3RCHOE7TRz uU2oR0aPggekPnpTcldtvYNfPoqg4710B4pazAldfehAFzHD64yhi/+xTRi8/tpbsCY2 ybKGLbuyQw5dfwZd5evEwhlztDz0bJ3gd6g4/KCIrr2IpUT9fnnswPtLzYkHpiJ/vyy9 iZ9MCpceQtCUATHhMGML3tnbuD1BaioPBYTbKOFhzjyipweUJgXKhkGD2n5/F8ZFGkN9 Mo+Q== X-Gm-Message-State: APuU4Z+JQ8rQdivIxtvKnVhTFZeNk6nTQ7/bG2EQqI0d+bYfTXW/zCOq T7yHO6Pr5jA/4dv66hDlRoQCyh7pnurXbIvGgSO8yIkP/1oJPTLGz+ILiHVgiMtVNWLY+EMFjof gwXu1eZw= X-Gm-Gg: AYBFou15ClFnvMO7V/gWQFdVD9dahoxaCr2uBnfSj/V5SFaYQIahdy2D6RnIdhjfMwY jAFsY/ML5pMz/hdmLGW/lKhp/g1bfeW2QPcDsXCLInlWEfRXGvMLNXoYwzAbaUO8wNAMTvsTW/f JTlwQYvey60/6WNvwHf9eX8mirlgjz1foKqJpeQePZ/Ug7KeC3zvPpWtck4MihfNukMrHLQKc/3 5bCCvkPAhCt5J4LkLAdkY6ofsDyWBWGwp8z8y5/k0GkDkt/v84bnh83z1FXQislVGDiZr8wftj5 xYiQ0h0+eHnGAJcm/rDka3bExfsYN5FHbhlWHDagFfQuJGo6z/0K8nF+hZva3+VRnbTrUPW44e1 BhvvZJnvyg58qcYlsB5GV2W4TXEOZIH7aX+q6jWItkpLBi8lZcvZBmtGVwVq/pVZ9h+PBr1Wigb fkI2WmUhOH3lWSniZ38Ru1MilmaXS1baZErlDn5+lWLEe26ROvpWE9drFNbPWlHxWb7ocRDsi2c ymn2besQai7HPphARXVkwbUIeKqfXWbp7ShZBuxkeOUFg4o1DLxij+w47N5xXZCBrldN6FKSsx/ USVUx3cL/YapqYQuZIljScueimTA71tPHr8QVGTgmzxM6sep1ykk/vZTiYofyqDTFsoid+OQB5+ bnqJAddb8AuFTS1conR9TYy615qOE/ZoRig== X-Received: by 2002:a05:600c:4e55:b0:4a2:397:73f6 with SMTP id 5b1f17b1804b1-4ba0233e687mr45060105e9.8.1794318527323; Tue, 10 Nov 2026 05:48:47 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH] tests/functional/x86_64: Add test for ccid-card-emulated Date: Tue, 10 Nov 2026 13:48:45 +0000 Message-ID: <20261110134845.1770151-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1794318581520158500 Content-Type: text/plain; charset="utf-8" Add a functional test for ccid-card-emulated. This roughly follows the usage procedure we document in system/devices/ccid.rst of creating some fake certificates, pointing the device at them, and then inside the guest querying the smartcard for the certificates and checking they validate. It deviates slightly from the suggested commands in the docs because the buildroot based rootfs doesn't have glibc and so "NSS-based smartcard integration with coolkey plus certutil" doesn't work. Instead we use opensc's pkcs15-tool to read the certs off the card and check them with openssl. Signed-off-by: Peter Maydell Reviewed-by: Marc-Andr=C3=A9 Lureau --- Here's the functional test I mentioned when I sent my other patch for ccid-card-emulated. --- tests/functional/x86_64/meson.build | 1 + tests/functional/x86_64/test_ccid_emulated.py | 169 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100755 tests/functional/x86_64/test_ccid_emulated.py diff --git a/tests/functional/x86_64/meson.build b/tests/functional/x86_64/= meson.build index bcda07620ff..9ed55fa99b3 100644 --- a/tests/functional/x86_64/meson.build +++ b/tests/functional/x86_64/meson.build @@ -35,6 +35,7 @@ endif =20 tests_x86_64_system_thorough =3D [ 'acpi_bits', + 'ccid_emulated', 'hotplug_blk', 'hotplug_scsi', 'hotplug_cpu', diff --git a/tests/functional/x86_64/test_ccid_emulated.py b/tests/function= al/x86_64/test_ccid_emulated.py new file mode 100755 index 00000000000..0c2d02fb3de --- /dev/null +++ b/tests/functional/x86_64/test_ccid_emulated.py @@ -0,0 +1,169 @@ +#!/usr/bin/env python3 +# +# Test of the ccid-emulated device. This roughly follows the lines +# suggested in our documentation of it, but deviates a bit because +# the buildroot-based rootfs we use doesn't have glibc to use the +# certutil + NSS validation process. Instead we use opensc's +# pkcs15-tool to read the certs off the card and openssl to check them. +# +# Copyright (c) 2026 Linaro Ltd +# SPDX-License-Identifier: GPL-2.0-or-later + +import os +import shutil +import subprocess + +from qemu_test import (Asset, exec_command_and_wait_for_pattern, + skipIfMissingCommands) +from qemu_test.tuxruntest import TuxRunBaselineTest + + +class CCIDEmulatedTest(TuxRunBaselineTest): + + ASSET_KERNEL =3D Asset( + 'https://storage.tuxboot.com/kernels/20261110/6.18.54/x86_64/bzIma= ge', + 'ba98a8a07d5f3f3e20119341059c0f0096fda499d30e30049c1ea64553b7e7c2') + ASSET_ROOTFS =3D Asset( + 'https://storage.tuxboot.com/buildroot/20261110/x86_64/rootfs.ext4= .zst', + '267172d47dc9594a8f07ec7fec05dc17b0fc21c64d5b635fccd6455128a2eb58') + + DEFAULT_KERNEL_PARAMS =3D ('console=3DttyS0') + + def create_certs(self): + # Create a CA and certificates in a dir under our test's + # working dir (removing any stale contents it had first). We + # return the db_spec that the ccid-card-emulated options need, + # plus the filename of the exported CA cert + + certdir =3D self.scratch_file("certs") + shutil.rmtree(certdir, ignore_errors=3DTrue) + os.mkdir(certdir) + + db_spec =3D f'sql:{certdir}' + + # certutil will by default block asking for some keyboard + # input to get randomness; create a noise-file to pass to it + # instead so it will work non-interactively + noise_file=3Dself.scratch_file("noise.bin") + with open(noise_file, 'wb') as f: + f.write(os.urandom(2048)) + + subprocess.check_call(['certutil', '-N', '-d', db_spec, + '--empty-password']) + + # We explicitly specify serial numbers (420, 421, 422, 423), + # because certutil's default is to generate a serial based on + # the current time, and when run from a script it will end up + # repeating the same serial for two certificates, which causes + # it to error out. + subprocess.check_call(['certutil', '-S', '-d', db_spec, + '-z', noise_file, + '-s', "CN=3DFake Smart Card CA", + '-x', '-t', 'TC,TC,TC', + '-m', '420', + '--keyUsage', + 'certSigning,crlSigning,critical', + '-n', 'fake-smartcard-ca'], + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.DEVNULL) + + subprocess.check_call(['certutil', '-S', '-d', db_spec, + '-z', noise_file, + '-t', ',,', + '-s', "CN=3DJohn Doe", + '-n', 'id-cert', + '-m', '421', + '-c', 'fake-smartcard-ca'], + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.DEVNULL) + + subprocess.check_call(['certutil', '-S', '-d', db_spec, + '-z', noise_file, + '-t', ',,', + '-s', "CN=3DJohn Doe (signing)", + '--nsCertType', 'smime', + '-n', 'signing-cert', + '-m', '422', + '-c', 'fake-smartcard-ca'], + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.DEVNULL) + + subprocess.check_call(['certutil', '-S', '-d', db_spec, + '-z', noise_file, + '-t', ',,', + '-s', "CN=3DJohn Doe (encryption)", + '--nsCertType', 'sslClient', + '-n', 'encryption-cert', + '-m', '423', + '-c', 'fake-smartcard-ca'], + stdout=3Dsubprocess.DEVNULL, + stderr=3Dsubprocess.DEVNULL) + + # Now export the CA cert to a file + ca_cert =3D self.scratch_file("fake-smartcard-ca.pem") + subprocess.check_call(['certutil', '-L', '-a', '-d', db_spec, + '-o', ca_cert, '-n', 'fake-smartcard-ca']) + + return (db_spec, ca_cert) + + def run_cmd(self, cmd): + # Run a command, and wait for the following prompt + exec_command_and_wait_for_pattern(self, cmd, '# ') + + @skipIfMissingCommands('certutil') + def test_ccid(self): + self.set_machine('q35') + self.require_device('usb-ccid') + self.require_device('ccid-card-emulated') + self.cpu =3D 'Nehalem' + self.root =3D 'sda' + + (kernel, disk, _, _) =3D self.fetch_tuxrun_assets(self.ASSET_KERNE= L, + self.ASSET_ROOTFS) + + (db_spec, ca_cert) =3D self.create_certs() + + certspec =3D f'db=3D{db_spec},cert1=3Did-cert,cert2=3Dsigning-cert= ,cert3=3Dencryption-cert' + + self.vm.add_args('-m', '1G', '-usb', + '-device', 'usb-ccid', + '-device', + f'ccid-card-emulated,backend=3Dcertificates,{cert= spec}', + '-fw_cfg', f'opt/org.qemu/ccid-test,file=3D{ca_ce= rt}') + + self.prepare_run(None, kernel, disk, + drive=3D"driver=3Dide-hd,bus=3Dide.0,unit=3D0") + self.vm.launch() + + ps1=3D'root@tuxtest:~#' + self.wait_for_console_pattern(self.kcmd_line) + self.wait_for_console_pattern('tuxtest login:') + exec_command_and_wait_for_pattern(self, 'root', ps1) + + self.run_cmd('cp ' + '/sys/firmware/qemu_fw_cfg/by_name/opt/org.qemu/ccid-= test/raw ' + '/tmp/fake-smartcard-ca.pem') + + # Start the daemon which actually talks to the smartcard + self.run_cmd('pcscd -d') + + # list the certs; having this in the console log may help debugging + self.run_cmd('pkcs15-tool --list-certificates') + + # Read each cert off the card, and get openssl to check that it + # validates against our fake CA cert + for cert in ('0001', '0002', '0003'): + self.run_cmd('pkcs15-tool ' + f'--read-certificate {cert} -o /tmp/cert-{cert}.p= em') + exec_command_and_wait_for_pattern(self, + 'openssl verify ' + '-CAfile ' + '/tmp/fake-smartcard-ca.pem ' + f'/tmp/cert-{cert}.pem', + f'/tmp/cert-{cert}.pem: OK', + failure_message=3D'# ') + self.wait_for_console_pattern('# ') + + +if __name__ =3D=3D '__main__': + CCIDEmulatedTest.main() --=20 2.43.0