欢迎光临散文网 会员登陆 & 注册

[QEMU]芯片卡接口器件 (CCID)

2022-07-24 17:38 作者:-小白之家-  | 我要投稿

USB 定向放电设备

USB CCID 设备是实现 CCID 规范的 USB 设备,它允许连接实现相同规范的智能卡读卡器。有关详细信息,请参阅规范:

Universal Serial BusDevice Class: Smart CardCCIDSpecification forIntegrated Circuit(s) Cards Interface DevicesRevision 1.1April 22rd, 2005

智能卡用于身份验证、单点登录、公共/私有方案中的解密和数字签名。客户端上的智能卡读卡器不能在具有简单 USB 直通的来宾上使用,因为它在客户端上不可用,在“删除”计算机时可能会锁定计算机。另一方面,此设备允许您在客户端和来宾计算机上使用智能卡。也可以使用此设备具有完全虚拟的智能卡读卡器和智能卡(即不受物理设备支持)。

建筑

加密功能和对物理卡的访问是通过libcacard库完成的,在构建QEMU之前必须安装其开发包:

在 redhat/fedora 中:

yum install libcacard-devel

在 ubuntu 中:

apt-get install libcacard-dev

配置和构建:

./configure --enable-smartcard && make

将 ccid 卡模拟与硬件结合使用

假设您在主机上有一个工作智能卡,使用当前用户,使用 libcacard,QEMU 使用 ccid-card 模拟充当另一个客户端:

qemu -usb -device usb-ccid -device ccid-card-emulated

将 ccid 卡模拟与存储在文件中的证书结合使用

您必须创建 CA 和卡证书。这是一个一次性过程。我们使用 NSS 证书:

mkdir fake-smartcard cd fake-smartcard certutil -N -d sql:$PWD certutil -S -d sql:$PWD -s "CN=Fake Smart Card CA" -x -t TC,TC,TC -n fake-smartcard-ca certutil -S -d sql:$PWD -t ,, -s "CN=John Doe" -n id-cert -c fake-smartcard-ca certutil -S -d sql:$PWD -t ,, -s "CN=John Doe (signing)" --nsCertType smime -n signing-cert -c fake-smartcard-ca certutil -S -d sql:$PWD -t ,, -s "CN=John Doe (encryption)" --nsCertType sslClient -n encryption-cert -c fake-smartcard-ca

注意:您必须正好有三个证书。

您可以将模拟卡类型与证书后端一起使用:

qemu -usb -device usb-ccid -device ccid-card-emulated,backend=certificates,db=sql:$PWD,cert1=id-cert,cert2=signing-cert,cert3=encryption-cert

要使用客户机中的证书,请导出 CA 证书:

certutil -L -r -d sql:$PWD -o fake-smartcard-ca.cer -n fake-smartcard-ca

并将其导入到来宾中:

certutil -A -d /etc/pki/nssdb -i fake-smartcard-ca.cer -t TC,TC,TC -n fake-smartcard-ca

在 Linux 来宾中,您可以使用 CoolKey PKCS #11 模块访问该卡:

certutil -d /etc/pki/nssdb -L -h all

它将提示您输入 PIN(这是您早期分配给证书数据库的密码),然后显示所有三个证书以及手动导入的 CA 证书:

Certificate Nickname                        Trust Attributesfake-smartcard-ca                           CT,C,CJohn Doe:CAC ID Certificate                 u,u,uJohn Doe:CAC Email Signature Certificate    u,u,uJohn Doe:CAC Email Encryption Certificate   u,u,u

如果未发生这种情况,则不会安装 CoolKey 或未向 NSS 注册。注册可以从 Firefox 或命令行完成:

modutil -dbdir /etc/pki/nssdb -add "CAC Module" -libfile /usr/lib64/pkcs11/libcoolkeypk11.somodutil -dbdir /etc/pki/nssdb -list

将 ccid-card-passthru 与客户端硬件配合使用

在主机上,使用合适的 chardev 指定 ccid-card-passthru 设备:

qemu -chardev socket,server=on,host=0.0.0.0,port=2001,id=ccid,wait=off \     -usb -device usb-ccid -device ccid-card-passthru,chardev=ccid

在客户端上运行 vscclient,在构建 QEMU 时构建:

vscclient <qemu-host> 2001

将 ccid-card-passthru 与客户端证书结合使用

这种情况不是特别有用,但您可以使用它来调试您的设置。

按照上面的说明进行操作,但运行 QEMU 和 vscclient 除外,如下所示。

如上所述运行qemu,并从“假智能卡”目录运行vscclient,如下所示:

qemu -chardev socket,server=on,host=0.0.0.0,port=2001,id=ccid,wait=off \     -usb -device usb-ccid -device ccid-card-passthru,chardev=ccidvscclient -e "db=\"sql:$PWD\" use_hw=no soft=(,Test,CAC,,id-cert,signing-cert,encryption-cert)" <qemu-host> 2001

直通协议方案

这是使用直通卡设备时的典型消息交换。usb-ccid 是一种 usb 设备。它在启动时默认为未连接的 USB 设备。usb-ccid 期望有一个 chardev,并期望在 cac_card/vscard_common.h 中定义的协议被传递。usb-ccid 设备可以处于以下三种模式之一:

  • 超然

  • 不带卡连接

  • 与卡连接

典型的交换是(箭头显示谁启动了每个交换,它可以是客户端发起的,也可以是来宾发起的):

client event        |    vscclient           |    passthru    |    usb-ccid  |  guest event------------------------------------------------------------------------------------------------                    |    VSC_Init            |                |              |                    |    VSC_ReaderAdd       |                |    attach    |                    |                        |                |              |  sees new usb device.  card inserted ->  |                        |                |              |                    |    VSC_ATR             |   insert       |    insert    |  see new card                    |                        |                |              |                    |    VSC_APDU            |   VSC_APDU     |              | <- guest sends APDUclient <-> physical |                        |                |              | card APDU exchange |                        |                |              | client response -> |    VSC_APDU            |   VSC_APDU     |              |  receive APDU response                                                    ...                                    [APDU<->APDU repeats several times]                                                    ...   card removed  -> |                        |                |              |                    |    VSC_CardRemove      |   remove       |   remove     |   card removed                                                    ...                                    [(card insert, apdu's, card remove) repeat]                                                    ...  kill/quit         |                        |                |              |    vscclient       |                        |                |              |                    |    VSC_ReaderRemove    |                |   detach     |                    |                        |                |              |   usb device removed.

利布卡卡德

ccid-card-emulated 和 vscclient 都使用 libcacard 作为卡模拟器。libcacard实现了完全虚拟的CAC(智能卡的DoD标准)兼容的卡,并使用NSS检索证书并进行任何加密。然后,后端可以是真正的读卡器和卡,也可以是存储在文件中的证书。


[QEMU]芯片卡接口器件 (CCID)的评论 (共 条)

分享到微博请遵守国家法律