usb-ccid
PATCH v21 1/11 trace: move trace objects from Makefile to Makefile.objs
In reply to Alon Levy--- Makefile | 32 -------------------------------- Makefile.objs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-)
Makefile +0 -32
@@ -112,38 +112,6 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS) bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS) -ifeq ($(TRACE_BACKEND),dtrace) -trace.h: trace.h-timestamp trace-dtrace.h -else -trace.h: trace.h-timestamp -endif -trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h") - @cmp -s $@ trace.h || cp $@ trace.h - -trace.c: trace.c-timestamp -trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c") - @cmp -s $@ trace.c || cp $@ trace.c - -trace.o: trace.c $(GENERATED_HEADERS) - -trace-dtrace.h: trace-dtrace.dtrace - $(call quiet-command,dtrace -o $@ -h -s $<, " GEN trace-dtrace.h") - -# Normal practice is to name DTrace probe file with a '.d' extension -# but that gets picked up by QEMU's Makefile as an external dependancy -# rule file. So we use '.dtrace' instead -trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp -trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@," GEN trace-dtrace.dtrace") - @cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace - -trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS) - $(call quiet-command,dtrace -o $@ -G -s $<, " GEN trace-dtrace.o") - -simpletrace.o: simpletrace.c $(GENERATED_HEADERS) - version.o: $(SRC_PATH)/version.rc config-host.mak $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")
Makefile.objs +32 -0
@@ -309,6 +309,38 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o # trace ifeq ($(TRACE_BACKEND),dtrace) +trace.h: trace.h-timestamp trace-dtrace.h +else +trace.h: trace.h-timestamp +endif +trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h") + @cmp -s $@ trace.h || cp $@ trace.h + +trace.c: trace.c-timestamp +trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c") + @cmp -s $@ trace.c || cp $@ trace.c + +trace.o: trace.c $(GENERATED_HEADERS) + +trace-dtrace.h: trace-dtrace.dtrace + $(call quiet-command,dtrace -o $@ -h -s $<, " GEN trace-dtrace.h") + +# Normal practice is to name DTrace probe file with a '.d' extension +# but that gets picked up by QEMU's Makefile as an external dependancy +# rule file. So we use '.dtrace' instead +trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp +trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@," GEN trace-dtrace.dtrace") + @cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace + +trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS) + $(call quiet-command,dtrace -o $@ -G -s $<, " GEN trace-dtrace.o") + +simpletrace.o: simpletrace.c $(GENERATED_HEADERS) + +ifeq ($(TRACE_BACKEND),dtrace) trace-obj-y = trace-dtrace.o else trace-obj-y = trace.o
Signature · 1 line
1.7.4.1
PATCH v21 5/11 ccid: add passthru card device
In reply to Alon LevyThe passthru ccid card is a device sitting on the usb-ccid bus and using a chardevice to communicate with a remote device using the VSCard protocol defined in libcacard/vscard_common.h
Usage docs available in following patch in docs/ccid.txt
---
Changes from v20->v21: (Jes Sorenson review)
* add reference to COPYING in header
* long comment reformatting
Changes from v19->v20:
* checkpatch.pl
Changes from v18->v19:
* add qdev.desc
* remove .qdev.unplug (no hot unplug support for ccid bus)
Changes from v16->v17:
* fix wrong cast when receiving VSC_Error
* ccid-card-passthru: force chardev user wakeup by sending Init see lengthy comment below.
Changes from v15->v16:
Behavioral changes:
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* reset vscard_in indices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicate reader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* send VSC_SUCCESS on card insert/remove and reader add/remove
Style fixes:
* width of line fix
* update copyright
* remove old TODO's
* update file header comment
* use macros for debug levels
* c++ style comment replacement
* update copyright license
* fix ATR size comment
* fix whitespace in struct def
* fix DPRINTF prefix
* line width fix
ccid-card-passthru: force chardev user wakeup by sending Init
The problem: how to wakeup the user of the smartcard when the smartcard device is initialized?
Long term solution: have a callback interface. This was done via the deprecated so called chardev ioctl interface.
Short term solution: do a write. Specifically we write an Init message. And we change the client to send it's own Init message regardless of receiving this one. Additional Init messages will be regarded as acceptable, the first one received after connection establishment is the determining one wrt capabilities.
--- Makefile.objs | 2 +- hw/ccid-card-passthru.c | 341 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 342 insertions(+), 1 deletions(-) create mode 100644 hw/ccid-card-passthru.c
Makefile.objs +1 -1
@@ -199,7 +199,7 @@ hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_HPET) += hpet.o hw-obj-$(CONFIG_APPLESMC) += applesmc.o -hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o +hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
hw/ccid-card-passthru.c new file +341 -0
341 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v21 7/11 libcacard: add vscclient
In reply to Alon LevyFrom: Robert Relyea <[email protected]>
client to talk to ccid-card-passthru and use smartcard on client to perform actual operations.
--- libcacard/Makefile | 7 +- libcacard/vscclient.c | 730 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 736 insertions(+), 1 deletions(-) create mode 100644 libcacard/vscclient.c
libcacard/Makefile +6 -1
@@ -12,6 +12,11 @@ endif QEMU_OBJS=$(QEMU_THREAD) $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o +vscclient: $(libcacard-y) $(QEMU_OBJS) vscclient.o + $(call quiet-command,$(CC) $(libcacard_libs) -lrt -o $@ $^," LINK $(TARGET_DIR)$@") + +all: vscclient + clean: - rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ + rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ vscclient
libcacard/vscclient.c new file +730 -0
730 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v21 3/11 usb-ccid: add CCID bus
In reply to Alon LevyA CCID device is a smart card reader. It is a USB device, defined at [1]. This patch introduces the usb-ccid device that is a ccid bus. Next patches will introduce two card types to use it, a passthru card and an emulated card.
[1] http://www.usb.org/developers/devclass_docs/DWG_Smart-Card_CCID_Rev110.
---
changes from v20->v21: (Jes Sorenson review)
* cosmetic changes - fix multi line comments.
* reorder fields in USBCCIDState
* add reference to COPYING
* add --enable-smartcard and --disable-smartcard here (moved from last patch)
changes from v19->v20:
* checkpatch.pl
changes from v18->v19:
* merged: ccid.h: add copyright, fix define and remove non C89 comments
* add qdev.desc
changes from v15->v16:
Behavioral changes:
* fix abort on client answer after card remove
* enable migration
* remove side affect code from asserts
* return consistent self-powered state
* mask out reserved bits in ccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
whitefixes / comments / consts defines:
* remove stale comment
* remove ccid_print_pending_answers if no DEBUG_CCID
* replace printf's with DPRINTF, remove DEBUG_CCID, add verbosity defines
* use error_report
* update copyright (most of the code is not original)
* reword known bug comment
* add missing closing quote in comment
* add missing whitespace on one line
* s/CCID_SetParameter/CCID_SetParameters/
* add comments
* use define for max packet size
Comment for "return consistent self-powered state":
the Configuration Descriptor bmAttributes claims we are self powered, but we were returning not self powered to USB_REQ_GET_STATUS control message.
In practice, this message is not sent by a linux 2.6.35.10-74.fc14.x86_64 guest (not tested on other guests), unless you issue lsusb -v as root (for example).
--- Makefile.objs | 1 + configure | 11 + hw/ccid.h | 59 +++ hw/usb-ccid.c | 1419 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1490 insertions(+), 0 deletions(-) create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c
Makefile.objs +1 -0
@@ -199,6 +199,7 @@ hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_HPET) += hpet.o hw-obj-$(CONFIG_APPLESMC) += applesmc.o +hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
configure +11 -0
@@ -174,6 +174,7 @@ trace_backend="nop" trace_file="trace" spice="" rbd="" +smartcard="" # parse CC options first for opt do
@@ -719,6 +720,10 @@ for opt do ;; --enable-rbd) rbd="yes" ;; + --disable-smartcard) smartcard="no" + ;; + --enable-smartcard) smartcard="yes" + ;; *) echo "ERROR: unknown option $opt"; show_help="yes" ;; esac
@@ -914,6 +919,8 @@ echo " Default:trace-<pid>" echo " --disable-spice disable spice" echo " --enable-spice enable spice" echo " --enable-rbd enable building the rados block device (rbd)" +echo " --disable-smartcard disable smartcard support" +echo " --enable-smartcard enable smartcard support" echo "" echo "NOTE: The object files are built at the place where configure is launched" exit 1
@@ -2809,6 +2816,10 @@ if test "$spice" = "yes" ; then echo "CONFIG_SPICE=y" >> $config_host_mak fi +if test "$smartcard" = "yes" ; then + echo "CONFIG_SMARTCARD=y" >> $config_host_mak +fi + # XXX: suppress that if [ "$bsd" = "yes" ] ; then echo "CONFIG_BSD=y" >> $config_host_mak
hw/ccid.h new file +59 -0
59 lines not on this page · raw message
hw/usb-ccid.c new file +1419 -0
1,419 lines not on this page · raw message
Signature · 1 line
1.7.4.1
v21 cover usb-ccid
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
Tree for pull: git://anongit.freedesktop.org/~alon/qemu usb_ccid.v20
v20->v21 changes:
* all: cosmetics
* libcacard, ccid-card-passthru:
* use qemu-{malloc,free} and qemu-thread, error_report
* libcacard:
* split to multiple patches
v19->v20 changes:
* checkpatch.pl. Here are the remaining errors with explanation:
* ignored 5 macro errors of the type
"ERROR: Macros with complex values should be enclosed in parenthesis" because fixing them breaks current code, if it really bothers someone I can fix it.
* four of them are in libcacard/card_7816t.h:
/* give the subfields a unified look */
..
#define a_cla a_header->ah_cla /* class */
#define a_ins a_header->ah_ins /* instruction */
#define a_p1 a_header->ah_p1 /* parameter 1 */
#define a_p2 a_header->ah_p2 /* parameter 2 */
* and the fifth:
#4946: FILE: libcacard/vcardt.h:31:
+#define VCARD_ATR_PREFIX(size) 0x3b, 0x66+(size), 0x00, 0xff, \
+ 'V', 'C', 'A', 'R', 'D', '_'
* Ignored this warning since I couldn't figure it out, and it's a test file:
WARNING: externs should be avoided in .c files
#2343: FILE: libcacard/link_test.c:7:
+VCardStatus cac_card_init(const char *flags, VCard *card,
v18-v19 changes:
* more merges, down to a single digit number of patches.
* drop enumeration property, use string.
* rebased (trivial)
v17-v18 changes:
* merge vscard_common.h patches.
* actually provide a tree to pull.
v16-v17 changes:
* merged all the "v15->v16" patches
* merged some more wherever it was easy (all same file commits).
* added signed off by to first four patches
* ccid.h: added copyright, removed underscore in defines, and replaced non C89 comments
v15-v16 changes:
* split vscard_common introducing patch for ease of review
* sum of commit logs for the v15-v16 commits: (whitespace fixes
removed for space, see original commit messages in later patches)
* usb-ccid:
* fix abort on client answer after card remove
* enable migration
* remove side affect code from asserts
* return consistent self-powered state
* mask out reserved bits in ccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
* vscard_common.h protocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* define VSCARD_MAGIC
* added error code VSC_SUCCESS.
* ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* reset vscard_in indices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicate reader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* send VSC_SUCCESS on card insert/remove and reader add/remove
* ccid-card-emulated
* fix error reporting in initfn
v14-v15 changes:
* add patch with --enable-smartcard and --disable-smartcard and only disable ccid-card-emulated if nss not found.
* add patch with description strings
* s/libcaccard/libcacard/ in docs/ccid.txt
v13-v14 changes:
- support device_del/device_add on ccid-card-* and usb-ccid
* usb-ccid:
* lose card reference when card device deleted
* check slot number and deny adding a slot if one is already added.
* ccid-card-*: use qdev_simple_unplug_cb in both emulated and passthru ccid cards, the exitfn already takes care of triggering card removal in the usb dev.
* libcacard:
* remove double include of config-host.mak
* add replay of card events to libcacard to support second and more emulation
* don't initialize more then once (doesn't support it right now, so one thread, NSS thread, is left when device_del is done)
* add VCARD_EMUL_INIT_ALREADY_INITED
* ccid-card-emulated:
* take correct mutexes on signaling to fix deadlocks on device_del
* allow card insertion/removal event without proper reader insertion event
v12-v13 changes:
* libcacard:
* fix Makefile clean to remove vscclient
* fix double include of config-host in Makefile
* usb-ccid: remove attach/detach logic, usb is always attached. Guest doesn't care if there is a reader attached with no card anyway.
* ccid-card-passthru: don't close chr_dev on removal, makes it possible to use device_del/device_add to create remove/insertion for debugging.
v11-v12 changes:
* fix out of tree build
v10-v11 changes:
* fix last patch that removed one of the doc files.
* updated flow table in docs/ccid.txt
v8-v10 changes:
* usb-ccid:
* add slot for future use (Gerd)
* ifdef ENABLE_MIGRATION for migration support on account of usb migration not being ready in general. (Gerd)
* verbosified commit messages. (Gerd)
* put libcacard docs in libcacard commit. (Gerd)
v8-v9 changes:
* Blue Swirl comments:
* white space fixes
* enabled by default, disabled only if missing nss
* forgotten fix from v8 (don't build libcacard.so)
* added a note about device being little endian
* library renamed from libcaccard to libcacard
* squashed both of libcacard patches, they touched different files anyway.
v7-v8 changes:
* Blue Swirl comments:
* usb-ccid: deannonymize some structs
* usb-ccid: coding style change - answer_t and bulk_in_t fixed
* usb-ccid: handle endianess conversion between guest and host
* usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
* ccid-card-emulated: fix segfault if backend not specified
* ccid-card-emulated: let last reader inserted win
* libcaccard: remove double vscard_common.h
v6->v7 changes:
* external libcaccard became internal directory libcaccard
* statically link object files into qemu
* produce libcaccard.so for usage by external projects
* applied coding style to new code (please check me)
- did not use the qemu options parsing for libcaccard, since it seems to draw large amounts of qemu code (monitor for instance).
v5->v6 changes:
* really remove static debug (I apologize for claiming to have done so before)
v4->v5 changes:
* rebased to latest
* remove static debug in card devices
* fix --enable-smartcard to link
* stall instead of assert when exceeding BULK_OUT_DATA_SIZE
* make ccid_reserve_recv_buf for too large len discard message, not exit
* make ccid_reserve_recv_buf return void*
* fix typo
* remove commented code in VMState
v3->v4:
* remove ccid field in CCIDBus
* remove static debug in bus
* add back docs
v2->v3:
* split into bus (usb-ccid.c, uses ccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v1->v2:
* all QSIMPLEQ turned into fixed sized rings
* all allocated buffers turned into fixed size buffers
* added migration support
* added a message to tell client qemu has migrated to ip:port
* for lack of monitor commands ip:port are 0:0, which causes the updated vscclient to connect to one port higher on the same host. will add monitor commands in a separate patch. tested with current setup.
Alon Levy (7):
trace: move trace objects from Makefile to Makefile.objs qemu-thread.h: include inttypes.h
usb-ccid: add CCID bus
introduce libcacard/vscard_common.h
ccid: add passthru card device
ccid: add ccid-card-emulated device
ccid: add docs
Robert Relyea (4):
libcacard: initial commit
libcacard: add vscclient
libcacard: add passthru
libcacard: add docs
Makefile | 38 +- Makefile.objs | 39 ++ Makefile.target | 2 + configure | 60 ++ docs/ccid.txt | 135 ++++ docs/libcacard.txt | 483 +++++++++++++++ hw/ccid-card-emulated.c | 595 ++++++++++++++++++ hw/ccid-card-passthru.c | 341 +++++++++++ hw/ccid.h | 59 ++ hw/usb-ccid.c | 1419 +++++++++++++++++++++++++++++++++++++++++++ libcacard/Makefile | 22 + libcacard/cac.c | 406 ++++++++++++ libcacard/cac.h | 23 + libcacard/card_7816.c | 763 +++++++++++++++++++++++ libcacard/card_7816.h | 62 ++ libcacard/card_7816t.h | 165 +++++ libcacard/event.c | 108 ++++ libcacard/eventt.h | 29 + libcacard/link_test.c | 21 + libcacard/passthru.c | 609 +++++++++++++++++++ libcacard/passthru.h | 53 ++ libcacard/vcard.c | 341 +++++++++++ libcacard/vcard.h | 86 +++ libcacard/vcard_emul.h | 65 ++ libcacard/vcard_emul_nss.c | 1159 +++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 63 ++ libcacard/vcard_emul_type.h | 32 + libcacard/vcardt.h | 64 ++ libcacard/vevent.h | 27 + libcacard/vreader.c | 519 ++++++++++++++++ libcacard/vreader.h | 55 ++ libcacard/vreadert.h | 24 + libcacard/vscard_common.h | 178 ++++++ libcacard/vscclient.c | 746 +++++++++++++++++++++++ qemu-thread.h | 2 + 35 files changed, 8759 insertions(+), 34 deletions(-) create mode 100644 docs/ccid.txt create mode 100644 docs/libcacard.txt create mode 100644 hw/ccid-card-emulated.c create mode 100644 hw/ccid-card-passthru.c create mode 100644 hw/ccid.h create mode 100644 hw/usb-ccid.c create mode 100644 libcacard/Makefile create mode 100644 libcacard/cac.c create mode 100644 libcacard/cac.h create mode 100644 libcacard/card_7816.c create mode 100644 libcacard/card_7816.h create mode 100644 libcacard/card_7816t.h create mode 100644 libcacard/event.c create mode 100644 libcacard/eventt.h create mode 100644 libcacard/link_test.c create mode 100644 libcacard/passthru.c create mode 100644 libcacard/passthru.h create mode 100644 libcacard/vcard.c create mode 100644 libcacard/vcard.h create mode 100644 libcacard/vcard_emul.h create mode 100644 libcacard/vcard_emul_nss.c create mode 100644 libcacard/vcard_emul_type.c create mode 100644 libcacard/vcard_emul_type.h create mode 100644 libcacard/vcardt.h create mode 100644 libcacard/vevent.h create mode 100644 libcacard/vreader.c create mode 100644 libcacard/vreader.h create mode 100644 libcacard/vreadert.h create mode 100644 libcacard/vscard_common.h create mode 100644 libcacard/vscclient.c
Signature · 1 line
1.7.4.1
PATCH v21 4/11 introduce libcacard/vscard_common.h
---
v20->v21 changes: (Jes Sorenson review)
* license set to 2+
* long comment fixes, remove empty line at eof.
* add reference to COPYING
v19->v20 changes:
* checkpatch.pl
v15->v16 changes:
Protocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* adaded Flush and FlushComplete, remove Reconnect.
* define VSCARD_MAGIC
* added error code VSC_SUCCESS.
Fixes:
* update VSCMsgInit comment
* fix message type enum
* remove underscore from wrapping define
* update copyright
* updated comments.
* Header comment updated
* remove C++ style comment
* fix comment for VSCMsgError
* give names to enums in typedefs
--- libcacard/vscard_common.h | 178 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 178 insertions(+), 0 deletions(-) create mode 100644 libcacard/vscard_common.h
libcacard/vscard_common.h new file +178 -0
@@ -0,0 +1,178 @@ +/* Virtual Smart Card protocol definition +* +* This protocol is between a host using virtual smart card readers, +* and a client providing the smart cards, perhaps by emulating them or by +* access to real cards. +* +* Definitions for this protocol: +* Host - user of the card +* Client - owner of the card +* +* The current implementation passes the raw APDU's from 7816 and additionally +* contains messages to setup and teardown readers, handle insertion and +* removal of cards, negotiate the protocol via capabilities and provide +* for error responses. +* +* Copyright (c) 2011 Red Hat. +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +*/ + +#ifndef VSCARD_COMMON_H +#define VSCARD_COMMON_H + +#include <stdint.h> + +#define VERSION_MAJOR_BITS 11 +#define VERSION_MIDDLE_BITS 11 +#define VERSION_MINOR_BITS 10 + +#define MAKE_VERSION (major, middle, minor) \ + ((major << (VERSION_MINOR_BITS + VERSION_MIDDLE_BITS)) \ + | (middle << VERSION_MINOR_BITS) \ + | (minor)) + +/* +* IMPORTANT NOTE on VERSION +* +* The version below MUST be changed whenever a change in this file is made. +* +* The last digit, the minor, is for bug fix changes only. +* +* The middle digit is for backward / forward compatible changes, updates +* to the existing messages, addition of fields. +* +* The major digit is for a breaking change of protocol, presumably +* something that cannot be accomodated with the existing protocol. +*/ + +#define VSCARD_VERSION MAKE_VERSION(0, 0, 2) + +typedef enum VSCMsgType { + VSC_Init =1 , + VSC_Error, + VSC_ReaderAdd, + VSC_ReaderRemove, +VSC_ATR , + VSC_CardRemove, +VSC_APDU , + VSC_Flush, + VSC_FlushComplete +}VSCMsgType ; + +typedef enum VSCErrorCode { +VSC_SUCCESS =0 , +VSC_GENERAL_ERROR =1 , +VSC_CANNOT_ADD_MORE_READERS , +VSC_CARD_ALREAY_INSERTED , +}VSCErrorCode ; + +#define VSCARD_UNDEFINED_READER_ID 0xffffffff +#define VSCARD_MINIMAL_READER_ID 0 + +#define VSCARD_MAGIC (*(uint32_t *)"VSCD") + +/* +* Header +* Each message starts with the header. +* type - message type +* reader_id - used by messages that are reader specific +* length - length of payload (not including header, i.e. zero for +* messages containing empty payloads) +*/ +typedef struct VSCMsgHeader { +uint32_t type; +uint32_t reader_id; +uint32_t length; +uint8_t data[0 ]; +}VSCMsgHeader ; + +/* +* VSCMsgInit Client <-> Host +* Client sends it on connection, with its own capabilities. +* Host replies with VSCMsgInit filling in its capabilities. +* +* It is not meant to be used for negotiation, i.e. sending more then +* once from any side, but could be used for that in the future. +*/ +typedef struct VSCMsgInit { +uint32_t magic; +uint32_t version; +uint32_t capabilities[1 ];/* receiver must check length, +array may grow in the future*/ +}VSCMsgInit ; + +/* +* VSCMsgError Client <-> Host +* This message is a response to any of: +* Reader Add +* Reader Remove +* Card Remove +* If the operation was successful then VSC_SUCCESS +* is returned, other wise a specific error code. +*/ +typedef struct VSCMsgError { +uint32_t code; +}VSCMsgError ; + +/* +* VSCMsgReaderAdd Client -> Host +* Host replies with allocated reader id in VSCMsgError with code==SUCCESS. +* +* name - name of the reader on client side, UTF-8 encoded. Only used +* for client presentation (may be translated to the device presented to the +* guest), protocol wise only reader_id is important. +*/ +typedef struct VSCMsgReaderAdd { +uint8_t name[0 ]; +}VSCMsgReaderAdd ; + +/* +* VSCMsgReaderRemove Client -> Host +* The client's reader has been removed. +*/ +typedef struct VSCMsgReaderRemove { +}VSCMsgReaderRemove ; + +/* +* VSCMsgATR Client -> Host +* Answer to reset. Sent for card insertion or card reset. The reset/insertion +* happens on the client side, they do not require any action from the host. +*/ +typedef struct VSCMsgATR { +uint8_t atr[0 ]; +}VSCMsgATR ; + +/* +* VSCMsgCardRemove Client -> Host +* The client card has been removed. +*/ +typedef struct VSCMsgCardRemove { +}VSCMsgCardRemove ; + +/* +* VSCMsgAPDU Client <-> Host +* Main reason of existance. Transfer a single APDU in either direction. +*/ +typedef struct VSCMsgAPDU { +uint8_t data[0 ]; +}VSCMsgAPDU ; + +/* +* VSCMsgFlush Host -> Client +* Request client to send a FlushComplete message when it is done +* servicing all outstanding APDUs +*/ +typedef struct VSCMsgFlush { +}VSCMsgFlush ; + +/* +* VSCMsgFlush Client -> Host +* Client response to Flush after all APDUs have been processed and +* responses sent. +*/ +typedef struct VSCMsgFlushComplete { +}VSCMsgFlushComplete ; + +#endif /* VSCARD_COMMON_H */
Signature · 1 line
1.7.4.1
PATCH v21 10/11 ccid: add ccid-card-emulated device
In reply to Alon LevyThis devices uses libcacard (internal) to emulate a smartcard conforming to the CAC standard. It attaches to the usb-ccid bus. Usage instructions (example command lines) are in the following patch in docs/ccid.txt. It uses libcacard which uses nss, so it can work with both hw cards and certificates (files).
---
changes from v20->v21: (Jes Sorenson review)
* cosmetics
* use qemu-thread and qemu_malloc/qemu_free
changes from v19->v20:
* checkpatch.pl
changes from v18->v19:
* add qdev.desc
* backend: drop the enumeration property, back to using a string one.
changes from v16->v17:
* use PROP_TYPE_ENUM for backend
changes from v15->v16:
* fix error reporting in initfn
* bump copyright year
* update copyright license
changes from v1:
* remove stale comments, use only c-style comments
* bugfix, forgot to set recv_len
* change reader name to 'Virtual Reader'
--- Makefile.objs | 1 + hw/ccid-card-emulated.c | 595 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 596 insertions(+), 0 deletions(-) create mode 100644 hw/ccid-card-emulated.c
Makefile.objs +1 -0
@@ -200,6 +200,7 @@ hw-obj-$(CONFIG_DMA) += dma.o hw-obj-$(CONFIG_HPET) += hpet.o hw-obj-$(CONFIG_APPLESMC) += applesmc.o hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o +hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o # PPC devices hw-obj-$(CONFIG_OPENPIC) += openpic.o
hw/ccid-card-emulated.c new file +595 -0
595 lines not on this page · raw message
Signature · 1 line
1.7.4.1
PATCH v21 2/11 qemu-thread.h: include inttypes.h
In reply to Alon Levyqemu-thread.h relies on uint64_t being defined, but doesn't include inttypes.h explicitly. This makes it easier to use it from vscclient (part of libcacard).
--- qemu-thread.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
qemu-thread.h +2 -0
@@ -1,6 +1,8 @@#ifndef __QEMU_THREAD_H#define __QEMU_THREAD_H 1 +#include <inttypes.h> +typedef struct QemuMutex QemuMutex ;typedef struct QemuCond QemuCond ;typedef struct QemuThread QemuThread ;
Signature · 1 line
1.7.4.1
PATCH v21 11/11 ccid: add docs
In reply to Alon LevyAdd documentation for the usb-ccid device and accompanying two card devices, ccid-card-emulated and ccid-card-passthru.
--- docs/ccid.txt | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 135 insertions(+), 0 deletions(-) create mode 100644 docs/ccid.txt
docs/ccid.txt new file +135 -0
@@ -0,0 +1,135 @@ +Qemu CCID Device Documentation. + +Contents +1. USB CCID device +2. Building +3. Using ccid-card-emulated with hardware +4. Using ccid-card-emulated with certificates +5. Using ccid-card-passthru with client side hardware +6. Using ccid-card-passthru with client side certificates +7. Passthrough protocol scenario +8. libcacard + +1. USB CCID device + +The USB CCID device is a USB device implementing the CCID specification, which +lets one connect smart card readers that implement the same spec. For more +information see the specification: + + Universal Serial Bus + Device Class: Smart Card + CCID + Specification for + Integrated Circuit(s) Cards Interface Devices + Revision 1.1 + April 22rd, 2005 + +Smartcard are used for authentication, single sign on, decryption in +public/private schemes and digital signatures. A smartcard reader on the client +cannot be used on a guest with simple usb passthrough since it will then not be +available on the client, possibly locking the computer when it is "removed". On +the other hand this device can let you use the smartcard on both the client and +the guest machine. It is also possible to have a completely virtual smart card +reader and smart card (i.e. not backed by a physical device) using this device. + +2. Building + +The cryptographic functions and access to the physical card is done via NSS. + +Installing NSS: + +In redhat/fedora: + yum install nss-devel +In ubuntu/debian: + apt-get install libnss3-dev + (not tested on ubuntu) + +Configuring and building: + ./configure --enable-smartcard && make + +3. Using ccid-card-emulated with hardware + +Assuming you have a working smartcard on the host with the current +user, using NSS, qemu acts as another NSS client using ccid-card-emulated: + + qemu -usb -device usb-ccid -device ccid-card-emualated + +4. Using ccid-card-emulated with certificates + +You must create the certificates. This is a one time process. We use NSS +certificates: + + certutil -d /etc/pki/nssdb -x -t "CT,CT,CT" -S -s "CN=cert1" -n cert1 + +Note: you must have exactly three certificates. + +Assuming the current user can access the certificates (use certutil -L to +verify), you can use the emulated card type with the certificates backend: + + qemu -usb -device usb-ccid -device ccid-card-emulated,backend=certificates,cert1=cert1,cert2=cert2,cert3=cert3 + +5. Using ccid-card-passthru with client side hardware + +on the host specify the ccid-card-passthru device with a suitable chardev: + + qemu -chardev socket,server,host=0.0.0.0,port=2001,id=ccid,nowait -usb -device usb-ccid -device ccid-card-passthru,chardev=ccid + +on the client run vscclient, built when you built the libcacard library: + libcacard/vscclient <qemu-host> 2001 + +6. Using ccid-card-passthru with client side certificates + +Run qemu as per #5, and run vscclient as follows: +(Note: vscclient command line interface is in a state of change) + + libcacard/vscclient -e "db=\"/etc/pki/nssdb\" use_hw=no soft=(,Test,CAC,,cert1,cert2,cert3)" <qemu-host> 2001 + +7. Passthrough protocol scenario + +This is a typical interchange of messages when using the passthru card device. +usb-ccid is a usb device. It defaults to an unattached usb device on startup. +usb-ccid expects a chardev and expects the protocol defined in +cac_card/vscard_common.h to be passed over that. +The usb-ccid device can be in one of three modes: + * detached + * attached with no card + * attached with card + +A typical interchange is: (the arrow shows who started each exchange, it can be client +originated or guest originated) + +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 APDU +client<->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. + + +8. libcacard + +ccid-card-passthru and vscclient use libcacard as the card emulator. +libcacard implements a completely virtual CAC (DoD standard for smart cards) +compliant card and uses NSS to actually retrive certificates and do any +encryption using the backend (real reader + card or file backed certificates). + +For documentation of cac_card see README in libcacard subdirectory. +
Signature · 1 line
1.7.4.1
PATCH v21 8/11 libcacard: add passthru
In reply to Alon LevyFrom: Robert Relyea <[email protected]>
In this mode libcacard doesn't emulate a card, but just passes apdu's straight to the underlying card.
Not to be confused with ccid-card-passthru, which doesn't use libcacard at all. So with this functionality in libcacard you can talk directly to the host accessible card, for instance for provisioning or other functions not available through the CAC interface. This can also be used from a remote client for the same purpose.
--- Makefile.objs | 2 +- libcacard/passthru.c | 609 +++++++++++++++++++++++++++++++++++++++++++ libcacard/passthru.h | 53 ++++ libcacard/vcard_emul_type.c | 6 + libcacard/vscclient.c | 22 ++- 5 files changed, 688 insertions(+), 4 deletions(-) create mode 100644 libcacard/passthru.c create mode 100644 libcacard/passthru.h
Makefile.objs +1 -1
@@ -354,7 +354,7 @@ endif ###################################################################### # smartcard -libcacard-y = cac.o event.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o +libcacard-y = cac.o event.o passthru.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
libcacard/passthru.c new file +609 -0
609 lines not on this page · raw message
libcacard/passthru.h new file +53 -0
53 lines not on this page · raw message
libcacard/vcard_emul_type.c +6 -0
@@ -12,6 +12,7 @@#include "vcardt.h" #include "vcard_emul_type.h" #include "cac.h" +#include "passthru.h" VCardStatus vcard_init(VReader *vreader, VCard *vcard, VCardEmulType type, const char *params,
@@ -24,6 +25,11 @@ VCardStatus vcard_init(VReader *vreader, VCard *vcard,case VCARD_EMUL_CAC :return cac_card_init (vreader, vcard, params, cert, cert_len, key, cert_count); +#ifdef USE_PASSTHRU +case VCARD_EMUL_PASSTHRU : +return passthru_card_init (vreader, vcard, params, + cert, cert_len, key, cert_count); +#endif /* add new ones here */ default :break ;
libcacard/vscclient.c +19 -3
@@ -30,6 +30,7 @@#include "vreader.h" #include "vcard_emul.h" #include "vevent.h" +#include "passthru.h" int verbose;
@@ -500,6 +501,7 @@ main(VReaderStatus reader_status;VReader *reader =NULL ;VCardEmulOptions *command_line_options =NULL ; +int passthru =0 ;char *cert_names[MAX_CERTS ];char *emul_args =NULL ;
@@ -519,8 +521,12 @@ main( emul_args = optarg;break ;case 'p' : +#ifdef USE_PASSTHRU + passthru =1 ; +#else print_usage ();exit (4 ); +#endif break ;case 'd' : verbose =get_id_from_string (optarg,1 );
@@ -533,7 +539,7 @@ main(exit (4 ); } -if (cert_count >0 ) { +if (!passthru && cert_count >0 ) {char *new_args;int len, i;/* if we've given some -c options, we clearly we want do so some
@@ -559,7 +565,12 @@ main( emul_args = new_args; }if (emul_args) { - command_line_options =vcard_emul_options (emul_args); +#ifdef USE_PASSTHRU + command_line_options = passthru ?passthru_emul_options (emul_args) : +#else + command_line_options = +#endif + vcard_emul_options(emul_args); } qemu_host =strdup (argv[argc -2 ]);
@@ -570,7 +581,12 @@ main(qemu_mutex_init (&pending_reader_lock);qemu_cond_init (&pending_reader_condition); -vcard_emul_init (command_line_options); +#ifdef USE_PASSTHRU +if (passthru) { +passthru_emul_init (command_line_options); + } else +#endif +vcard_emul_init (command_line_options);printf ("> " );fflush (stdout);
Signature · 1 line
1.7.4.1
PATCH v21 9/11 libcacard: add docs
In reply to Alon LevyFrom: Robert Relyea <[email protected]>
--- docs/libcacard.txt | 483 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 483 insertions(+), 0 deletions(-) create mode 100644 docs/libcacard.txt
docs/libcacard.txt new file +483 -0
@@ -0,0 +1,483 @@ +This file documents the CAC (Common Access Card) library in the libcacard +subdirectory. + +Virtual Smart Card Emulator + +This emulator is designed to provide emulation of actual smart cards to a +virtual card reader running in a guest virtual machine. The emulated smart +cards can be representations of real smart cards, where the necessary functions +such as signing, card removal/insertion, etc. are mapped to real, physical +cards which are shared with the client machine the emulator is running on, or +the cards could be pure software constructs. + +The emulator is structured to allow multiple replacable or additional pieces, +so it can be easily modified for future requirements. The primary envisioned +modifications are: + +1) The socket connection to the virtual card reader (presumably a CCID reader, +but other ISO-7816 compatible readers could be used). The code that handles +this is in vscclient.c. + +2) The virtual card low level emulation. This is currently supplied by using +NSS. This emulation could be replaced by implementations based on other +security libraries, including but not limitted to openssl+pkcs#11 library, +raw pkcs#11, Microsoft CAPI, direct opensc calls, etc. The code that handles +this is in vcard_emul_nss.c. + +3) Emulation for new types of cards. The current implementation emulates the +original DoD CAC standard with separate pki containers. This emulator lives in +cac.c. More than one card type emulator could be included. Other cards could +be emulated as well, including PIV, newer versions of CAC, PKCS #15, etc. + +-------------------- +Replacing the Socket Based Virtual Reader Interface. + +The current implementation contains a replacable module vscclient.c. The +current vscclient.c implements a sockets interface to the virtual ccid reader +on the guest. CCID commands that are pertinent to emulation are passed +across the socket, and their responses are passed back along that same socket. +The protocol that vscclient uses is defined in vscard_common.h and connects +to a qemu ccid usb device. Since this socket runs as a client, vscclient.c +implements a program with a main entry. It also handles argument parsing for +the emulator. + +An application that wants to use the virtual reader can replace vscclient.c +with it's own implementation that connects to it's own CCID reader. The calls +that the CCID reader can call are: + + VReaderList * vreader_get_reader_list(); + + This function returns a list of virtual readers. These readers may map to + physical devices, or simulated devices depending on vcard the back end. Each + reader in the list should represent a reader to the virtual machine. Virtual + USB address mapping is left to the CCID reader front end. This call can be + made any time to get an updated list. The returned list is a copy of the + internal list that can be referenced by the caller without locking. This copy + must be freed by the caller with vreader_list_delete when it is no longer + needed. + + VReaderListEntry *vreader_list_get_first(VReaderList *); + + This function gets the first entry on the reader list. Along with + vreader_list_get_next(), vreader_list_get_first() can be used to walk the + reader list returned from vreader_get_reader_list(). VReaderListEntries are + part of the list themselves and do not need to be freed separately from the + list. If there are no entries on the list, it will return NULL. + + VReaderListEntry *vreader_list_get_next(VReaderListEntry *); + + This function gets the next entry in the list. If there are no more entries + it will return NULL. + + VReader * vreader_list_get_reader(VReaderListEntry *) + + This function returns the reader stored in the reader List entry. Caller gets + a new reference to a reader. The caller must free it's reference when it is + finished with vreader_free(). + + void vreader_free(VReader *reader); + + This function frees a reference to a reader. Reader's are reference counted + and are automatically deleted when the last reference is freed. + + void vreader_list_delete(VReaderList *list); + + This function frees the list, all the elements on the list, and all the + reader references held by the list. + + VReaderStatus vreader_power_on(VReader *reader, char *atr, int *len); + + This functions simulates a card power on. Virtual cards do not care about + the actual voltage and other physical parameters, but it does care that the + card is actually on or off. Cycling the card causes the card to reset. If + the caller provides enough space, vreader_power_on will return the ATR of + the virtual card. The amount of space provided in atr should be indicated + in *len. The function modifies *len to be the actual length of of the + returned ATR. + + VReaderStatus vreader_power_off(VReader *reader); + + This function simulates a power off of a virtual card. + + VReaderStatus vreader_xfer_bytes(VReader *reader, unsigne char *send_buf, + int send_buf_len, + unsigned char *receive_buf, + int receive_buf_len); + + This functions send a raw apdu to a card and returns the card's response. + The CCID front end should return the response back. Most of the emulation + is driven from these APDUs. + + VReaderStatus vreader_card_is_present(VReader *reader); + + This function returns whether or not the reader has a card inserted. The + vreader_power_on, vreader_power_off, and vreader_xfer_bytes will return + VREADER_NO_CARD. + + const char *vreader_get_name(VReader *reader); + + This function returns the name of the reader. The name comes from the card + emulator level and is usually related to the name of the physical reader. + + VReaderID vreader_get_id(VReader *reader); + + This function returns the id of a reader. All readers start out with an id + of -1. The application can set the id with vreader_set_id. + + VReaderStatus vreader_get_id(VReader *reader, VReaderID id); + + This function sets the reader id. The application is responsible for making + sure that the id is unique for all readers it is actively using. + + VReader *vreader_find_reader_by_id(VReaderID id); + + This function returns the reader which matches the id. If two readers match, + only one is returned. The function returns NULL if the id is -1. + + Event *vevent_wait_next_vevent(); + + This function blocks waiting for reader and card insertion events. There + will be one event for each card insertion, each card removal, each reader + insertion and each reader removal. At start up, events are created for all + the initial readers found, as well as all the cards that are inserted. + + Event *vevent_get_next_vevent(); + + This function returns a pending event if it exists, otherwise it returns + NULL. It does not block. + +---------------- +Card Type Emulator: Adding a New Virtual Card Type + +The ISO 7816 card spec describes 2 types of cards: + 1) File system cards, where the smartcard is managed by reading and writing +data to files in a file system. There is currently only boiler plate +implemented for file system cards. + 2) VM cards, where the card has loadable applets which perform the card +functions. The current implementation supports VM cards. + +In the case of VM cards, the difference between various types of cards is +really what applets have been installed in that card. This structure is +mirrored in card type emulators. The 7816 emulator already handles the basic +ISO 7186 commands. Card type emulators simply need to add the virtual applets +which emulate the real card applets. Card type emulators have exactly one +public entry point: + + VCARDStatus xxx_card_init(VCard *card, const char *flags, + const unsigned char *cert[], + int cert_len[], + VCardKey *key[], + int cert_count); + + The parameters for this are: + card - the virtual card structure which will prepresent this card. + flags - option flags that may be specific to this card type. + cert - array of binary certificates. + cert_len - array of lengths of each of the certificates specified in cert. + key - array of opaque key structures representing the private keys on + the card. + cert_count - number of entries in cert, cert_len, and key arrays. + + Any cert, cert_len, or key with the same index are matching sets. That is + cert[0] is cert_len[0] long and has the corresponsing private key of key[0]. + +The card type emulator is expected to own the VCardKeys, but it should copy +any raw cert data it wants to save. It can create new applets and add them to +the card using the following functions: + + VCardApplet *vcard_new_applet(VCardProcessAPDU apdu_func, + VCardResetApplet reset_func, + const unsigned char *aid, + int aid_len); + + This function creates a new applet. Applet structures store the following + information: + 1) the AID of the applet (set by aid and aid_len). + 2) a function to handle APDUs for this applet. (set by apdu_func, more on + this below). + 3) a function to reset the applet state when the applet is selected. + (set by reset_func, more on this below). + 3) applet private data, a data pointer used by the card type emulator to + store any data or state it needs to complete requests. (set by a + separate call). + 4) applet private data free, a function used to free the applet private + data when the applet itself is destroyed. + The created applet can be added to the card with vcard_add_applet below. + + void vcard_set_applet_private(VCardApplet *applet, + VCardAppletPrivate *private, + VCardAppletPrivateFree private_free); + This function sets the private data and the corresponding free function. + VCardAppletPrivate is an opaque data structure to the rest of the emulator. + The card type emulator can define it any way it wants by defining + struct VCardAppletPrivateStruct {};. If there is already a private data + structure on the applet, the old one is freed before the new one is set up. + passing two NULL clear any existing private data. + + VCardStatus vcard_add_applet(VCard *card, VCardApplet *applet); + + Add an applet onto the list of applets attached to the card. Once an applet + has been added, it can be selected by it's aid, and then commands will be + routed to it VCardProcessAPDU function. This function adopts the applet the + passed int applet. Note: 2 applets with the same AID should not be added to + the same card. It's permissible to add more than one applet. Multiple applets + may have the same VCardPRocessAPDU entry point. + +The certs and keys should be attached to private data associated with one or +more appropriate applets for that card. Control will come to the card type +emulators once one of its applets are selected through the VCardProcessAPDU +function it specified when it created the applet. + +The signature of VCardResetApplet is: + VCardStatus (*VCardResetApplet) (VCard *card, int channel); + This function will reset the any internal applet state that needs to be + cleared after a select applet call. It should return VCARD_DONE; + +The signature of VCardProcessAPDU is: + VCardStatus (*VCardProcessAPDU)(VCard *card, VCardAPDU *apdu, + VCardResponse **response); + This function examines the APDU and determines whether it should process + the apdu directly, reject the apdu as invalid, or pass the apdu on to + the basic 7816 emulator for processing. + If the 7816 emulator should process the apdu, then the VCardProcessAPDU + should return VCARD_NEXT. + If there is an error, then VCardProcessAPDU should return an error + response using vcard_make_response and the appropriate 7816 error code + (see card_7816t.h) or vcard_make_response with a card type specific error + code. It should then return VCARD_DONE. + If the apdu can be processed correctly, VCardProcessAPDU should do so, + set the response value appropriately for that APDU, and return VCARD_DONE. + VCardProcessAPDU should always set the response if it returns VCARD_DONE. + It should always either return VCARD_DONE or VCARD_NEXT. + +Parsing the APDU -- + +Prior to processing calling the card type emulator's VCardProcessAPDU function, the emulator has already decoded the APDU header and set several fields: + + apdu->a_data - The raw apdu data bytes. + apdu->a_len - The len of the raw apdu data. + apdu->a_body - The start of any post header parameter data. + apdu->a_Lc - The parameter length value. + apdu->a_Le - The expected length of any returned data. + apdu->a_cla - The raw apdu class. + apdu->a_channel - The channel (decoded from the class). + apdu->a_secure_messaging_type - The decoded secure messagin type + (from class). + apdu->a_type - The decode class type. + apdu->a_gen_type - the generic class type (7816, PROPRIETARY, RFU, PTS). + apdu->a_ins - The instruction byte. + apdu->a_p1 - Parameter 1. + apdu->a_p2 - Parameter 2. + +Creating a Response -- + +The expected result of any APDU call is a response. The card type emulator must +set *response with an appropriate VCardResponse value if it returns VCARD_DONE. +Reponses could be as simple as returning a 2 byte status word response, to as +complex as returning a block of data along with a 2 byte response. Which is +returned will depend on the semantics of the APDU. The following functions will +create card responses. + + VCardResponse *vcard_make_response(VCard7816Status status); + + This is the most basic function to get a response. This function will + return a response the consists soley one 2 byte status code. If that status + code is defined in card_7816t.h, then this function is guarrenteed to + return a response with that status. If a cart type specific status code + is passed and vcard_make_response fails to allocate the appropriate memory + for that response, then vcard_make_response will return a VCardResponse + of VCARD7816_STATUS_EXC_ERROR_MEMORY. In any case, this function is + guarrenteed to return a valid VCardResponse. + + VCardResponse *vcard_response_new(unsigned char *buf, int len, + VCard7816Status status); + + This function is similar to vcard_make_response except it includes some + returned data with the response. It could also fail to allocate enough + memory, in which case it will return NULL. + + VCardResponse *vcard_response_new_status_bytes(unsigned char sw1, + unsigned char sw2); + + Sometimes in 7816 the response bytes are treated as two separate bytes with + split meanings. This function allows you to create a response based on + two separate bytes. This function could fail, in which case it will return + NULL. + + VCardResponse *vcard_response_new_bytes(unsigned char *buf, int len, + unsigned char sw1, + unsigned char sw2); + + This function is the same as vcard_response_new except you may specify + the status as two separate bytes like vcard_response_new_status_bytes. + + +Implementing functionality --- + +The following helper functions access information about the current card +and applet. + + VCARDAppletPrivate *vcard_get_current_applet_private(VCard *card, + int channel); + + This function returns any private data set by the card type emulator on + the currently selected applet. The card type emulator keeps track of the + current applet state in this data structure. Any certs and keys associated + with a particular applet is also stored here. + + int vcard_emul_get_login_count(VCard *card); + + This function returns the the number of remaing login attempts for this + card. If the card emulator does not know, or the card does not have a + way of giving this information, this function returns -1. + + + VCard7816Status vcard_emul_login(VCard *card, unsigned char *pin, + int pin_len); + + This function logins into the card and return the standard 7816 status + word depending on the success or failure of the call. + + void vcard_emul_delete_key(VCardKey *key); + + This function frees the VCardKey passed in to xxxx_card_init. The card + type emulator is responsible for freeing this key when it no longer needs + it. + + VCard7816Status vcard_emul_rsa_op(VCard *card, VCardKey *key, + unsigned char *buffer, + int buffer_size); + + This function does a raw rsa op on the buffer with the given key. + +The sample card type emulator is found in cac.c. It implements the cac specific +applets. Only those applets needed by the coolkey pkcs#11 driver on the guest +have been implemented. To support the full range CAC middleware, a complete CAC +card according to the CAC specs should be implemented here. + +------------------------------ +Virtual Card Emulator + +This code accesses both real smart cards and simulated smart cards through +services provided on the client. The current implementation uses NSS, which +already knows how to talk to various PKCS #11 modules on the client, and is +portable to most operating systems. A particular emulator can have only one +virtual card implementation at a time. + +The virtual card emulator consists of a series of virtual card services. In +addition to the services describe above (services starting with +vcard_emul_xxxx), the virtual card emulator also provides the following +functions: + + VCardEmulError vcard_emul_init(cont VCardEmulOptions *options); + + The options structure is built by another function in the virtual card + interface where a string of virtual card emulator specific strings are + mapped to the options. The actual structure is defined by the virutal card + emulator and is used to determine the configuration of soft cards, or to + determine which physical cards to present to the guest. + + The vcard_emul_init function will build up sets of readers, create any + threads that are needed to watch for changes in the reader state. If readers + have cards present in them, they are also initialized. + + Readers are created with the function. + + VReader *vreader_new(VReaderEmul *reader_emul, + VReaderEmulFree reader_emul_free); + + The freeFunc is used to free the VReaderEmul * when the reader is + destroyed. The VReaderEmul structure is an opaque structure to the + rest of the code, but defined by the virtual card emulator, which can + use it to store any reader specific state. + + Once the reader has been created, it can be added to the front end with the + call: + + VReaderStatus vreader_add_reader(VReader *reader); + + This function will automatically generate the appropriate new reader + events and add the reader to the list. + + To create a new card, the virtual card emulator will call a similiar + function. + + VCard *vcard_new(VCardEmul *card_emul, + VCardEmulFree card_emul_free); + + Like vreader_new, this function takes a virtual card emulator specific + structure which it uses to keep track of the card state. + + Once the card is created, it is attached to a card type emulator with the + following function: + + VCardStatus vcard_init(VCard *vcard, VCardEmulType type, + const char *flags, + unsigned char *const *certs, + int *cert_len, + VCardKey *key[], + int cert_count); + + The vcard is the value returned from vcard_new. The type is the + card type emulator that this card should presented to the guest as. + The flags are card type emulator specific options. The certs, + cert_len, and keys are all arrays of length cert_count. These are the + the same of the parameters xxxx_card_init() accepts. + + Finally the card is associated with it's reader by the call: + + VReaderStatus vreader_insert_card(VReader *vreader, VCard *vcard); + + This function, like vreader_add_reader, will take care of any event + notification for the card insert. + + + VCardEmulError vcard_emul_force_card_remove(VReader *vreader); + + Force a card that is present to appear to be removed to the guest, even if + that card is a physical card and is present. + + + VCardEmulError vcard_emul_force_card_insert(VReader *reader); + + Force a card that has been removed by vcard_emul_force_card_remove to be + reinserted from the point of view of the guest. This will only work if the + card is physically present (which is always true fro a soft card). + + void vcard_emul_get_atr(Vcard *card, unsigned char *atr, int *atr_len); + + Return the virtual ATR for the card. By convention this should be the value + VCARD_ATR_PREFIX(size) followed by several ascii bytes related to this + particular emulator. For instance the NSS emulator returns + {VCARD_ATR_PREFIX(3), 'N', 'S', 'S' }. Do ot return more data then *atr_len; + + void vcard_emul_reset(VCard *card, VCardPower power) + + Set the state of 'card' to the current power level and reset its internal + state (logout, etc). + +------------------------------------------------------- +List of files and their function: +README - This file +card_7816.c - emulate basic 7816 functionality. Parse APDUs. +card_7816.h - apdu and response services definitions. +card_7816t.h - 7816 specific structures, types and definitions. +event.c - event handling code. +event.h - event handling services definitions. +eventt.h - event handling structures and types +vcard.c - handle common virtual card services like creation, destruction, and + applet management. +vcard.h - common virtual card services function definitions. +vcardt.h - comon virtual card types +vreader.c - common virtual reader services. +vreader.h - common virtual reader services definitions. +vreadert.h - comon virtual reader types. +vcard_emul_type.c - manage the card type emulators. +vcard_emul_type.h - definitions for card type emulators. +cac.c - card type emulator for CAC cards +vcard_emul.h - virtual card emulator service definitions. +vcard_emul_nss.c - virtual card emulator implementation for nss. +vscclient.c - socket connection to guest qemu usb driver. +vscard_common.h - common header with the guest qemu usb driver. +mutex.h - header file for machine independent mutexes. +link_test.c - static test to make sure all the symbols are properly defined.
Signature · 1 line
1.7.4.1
PATCH v21 6/11 libcacard: initial commit
In reply to Alon LevyFrom: Robert Relyea <[email protected]>
libcacard emulates a Common Access Card (CAC) which is a standard for smartcards. It is used by the emulated ccid card introduced in a following patch. Docs are available in docs/libcacard.txt
---
changes from v20->v21: (Jes Sorenson review)
* use qemu infrastructure: qemu-thread, qemu-common (qemu_malloc and qemu_free), error_report
* assert instead of ASSERT
* cosmetic fixes
* use strpbrk and isspace
* add --disable-nss --enable-nss here, instead of in the final patch.
* split vscclient, passthru and docs to following patches.
changes from v19->v20:
* checkpatch.pl
changes from v15->v16:
Build:
* don't erase self with distclean
* fix make clean after make distclean
* Makefile: make vscclient link quiet
Behavioral:
* vcard_emul_nss: load coolkey in more situations
* vscclient:
* use hton,ntoh
* send init on connect, only start vevent thread on response
* read payload after header check, before type switch
* remove Reconnect
* update for vscard_common changes, empty Flush implementation
Style/Whitespace:
* fix wrong variable usage
* remove unused variable
* use only C style comments
* add copyright header
* fix tabulation
--- Makefile | 6 +- Makefile.objs | 5 + Makefile.target | 2 + configure | 49 ++ libcacard/Makefile | 17 + libcacard/cac.c | 406 +++++++++++++++ libcacard/cac.h | 23 + libcacard/card_7816.c | 763 ++++++++++++++++++++++++++++ libcacard/card_7816.h | 62 +++ libcacard/card_7816t.h | 165 ++++++ libcacard/event.c | 108 ++++ libcacard/eventt.h | 29 ++ libcacard/link_test.c | 21 + libcacard/vcard.c | 341 +++++++++++++ libcacard/vcard.h | 86 ++++ libcacard/vcard_emul.h | 65 +++ libcacard/vcard_emul_nss.c | 1159 +++++++++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 57 +++ libcacard/vcard_emul_type.h | 32 ++ libcacard/vcardt.h | 64 +++ libcacard/vevent.h | 27 + libcacard/vreader.c | 519 +++++++++++++++++++ libcacard/vreader.h | 55 ++ libcacard/vreadert.h | 24 + 24 files changed, 4083 insertions(+), 2 deletions(-) create mode 100644 libcacard/Makefile create mode 100644 libcacard/cac.c create mode 100644 libcacard/cac.h create mode 100644 libcacard/card_7816.c create mode 100644 libcacard/card_7816.h create mode 100644 libcacard/card_7816t.h create mode 100644 libcacard/event.c create mode 100644 libcacard/eventt.h create mode 100644 libcacard/link_test.c create mode 100644 libcacard/vcard.c create mode 100644 libcacard/vcard.h create mode 100644 libcacard/vcard_emul.h create mode 100644 libcacard/vcard_emul_nss.c create mode 100644 libcacard/vcard_emul_type.c create mode 100644 libcacard/vcard_emul_type.h create mode 100644 libcacard/vcardt.h create mode 100644 libcacard/vevent.h create mode 100644 libcacard/vreader.c create mode 100644 libcacard/vreader.h create mode 100644 libcacard/vreadert.h
Makefile +4 -2
@@ -141,6 +141,8 @@ check-qlist: check-qlist.o qlist.o qint.o $(CHECK_PROG_DEPS) check-qfloat: check-qfloat.o qfloat.o $(CHECK_PROG_DEPS) check-qjson: check-qjson.o qfloat.o qint.o qdict.o qstring.o qlist.o qbool.o qjson.o json-streamer.o json-lexer.o json-parser.o $(CHECK_PROG_DEPS) +QEMULIBS=libhw32 libhw64 libuser libdis libdis-user + clean: # avoid old build problems by removing potentially incorrect old files rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
@@ -152,7 +154,7 @@ clean: rm -f trace-dtrace.dtrace trace-dtrace.dtrace-timestamp rm -f trace-dtrace.h trace-dtrace.h-timestamp $(MAKE) -C tests clean - for d in $(ALL_SUBDIRS) libhw32 libhw64 libuser libdis libdis-user; do \ + for d in $(ALL_SUBDIRS) $(QEMULIBS) libcacard; do \ if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \ rm -f $$d/qemu-options.def; \ done
@@ -163,7 +165,7 @@ distclean: clean rm -f roms/seabios/config.mak roms/vgabios/config.mak rm -f qemu-doc.info qemu-doc.aux qemu-doc.cp qemu-doc.dvi qemu-doc.fn qemu-doc.info qemu-doc.ky qemu-doc.log qemu-doc.pdf qemu-doc.pg qemu-doc.toc qemu-doc.tp qemu-doc.vr rm -f qemu-tech.info qemu-tech.aux qemu-tech.cp qemu-tech.dvi qemu-tech.fn qemu-tech.info qemu-tech.ky qemu-tech.log qemu-tech.pdf qemu-tech.pg qemu-tech.toc qemu-tech.tp qemu-tech.vr - for d in $(TARGET_DIRS) libhw32 libhw64 libuser libdis libdis-user; do \ + for d in $(TARGET_DIRS) $(QEMULIBS); do \ rm -rf $$d || exit 1 ; \ done
Makefile.objs +5 -0
@@ -351,6 +351,11 @@ user-obj-y += qemu-timer-common.o endif endif +###################################################################### +# smartcard + +libcacard-y = cac.o event.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o + vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
Makefile.target +2 -0
@@ -350,6 +350,8 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +obj-y += $(addprefix ../libcacard/, $(libcacard-$(CONFIG_SMARTCARD))) + obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
configure +49 -0
97 lines not on this page · raw message
libcacard/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +-include ../config-host.mak +-include $(SRC_PATH)/Makefile.objs +-include $(SRC_PATH)/rules.mak + +$(call set-vpath, $(SRC_PATH):$(SRC_PATH)/libcacard) + +ifeq ($(CONFIG_WIN32),y) +QEMU_THREAD=qemu-thread-win32.o +else +QEMU_THREAD=qemu-thread-posix.o +endif + +QEMU_OBJS=$(QEMU_THREAD) $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o + +clean: + rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ +
libcacard/cac.c new file +406 -0
406 lines not on this page · raw message
libcacard/cac.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* defines the entry point for the cac card. Only used by cac.c anc +* vcard_emul_type.c +* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +*/ +#ifndef CAC_H +#define CAC_H 1 +#include "vcard.h" +#include "vreader.h" +/* +* Initialize the cac card. This is the only public function in this file. All +* the rest are connected through function pointers. +*/ +VCardStatus cac_card_init (VReader *reader,VCard *card,const char *params, +unsigned char *const *cert,int cert_len[], +VCardKey *key[]/* adopt the keys*/ , +int cert_count); + +/* not yet implemented */ +VCardStatus cac_is_cac_card (VReader *reader); +#endif
libcacard/card_7816.c new file +763 -0
763 lines not on this page · raw message
libcacard/card_7816.h new file +62 -0
62 lines not on this page · raw message
libcacard/card_7816t.h new file +165 -0
165 lines not on this page · raw message
libcacard/event.c new file +108 -0
108 lines not on this page · raw message
libcacard/eventt.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +*/ + +#ifndef EVENTT_H +#define EVENTT_H 1 +#include "vreadert.h" +#include "vcardt.h" + +typedef struct VEventStruct VEvent ; + +typedef enum { +VEVENT_READER_INSERT , +VEVENT_READER_REMOVE , +VEVENT_CARD_INSERT , +VEVENT_CARD_REMOVE , +VEVENT_LAST , +}VEventType ; + +struct VEventStruct { +VEvent *next; +VEventType type; +VReader *reader; +VCard *card; +}; +#endif + +
libcacard/link_test.c new file +21 -0
@@ -0,0 +1,21 @@ +/* +* This work is licensed under the terms of the GNU LGPL, version 2.1 or later. +* See the COPYING.LIB file in the top-level directory. +*/ +#include <stdio.h> +#include "vcard.h" + +VCardStatus cac_card_init (const char *flags,VCard *card, +const unsigned char *cert[], +int cert_len[],VCardKey *key[]/* adopt the keys*/ , +int cert_count); +/* +* this will crash... just test the linkage right now +*/ + +main(int argc, char **argv) +{ + VCard *card; /* no constructor yet */ +cac_card_init ("" , card,NULL ,0 ,NULL ,0 ); +} +
libcacard/vcard.c new file +341 -0
341 lines not on this page · raw message
libcacard/vcard.h new file +86 -0
86 lines not on this page · raw message
libcacard/vcard_emul.h new file +65 -0
65 lines not on this page · raw message
libcacard/vcard_emul_nss.c new file +1159 -0
774 lines not on this page · raw message
libcacard/vcard_emul_type.c new file +57 -0
57 lines not on this page · raw message
libcacard/vcardt.h new file +64 -0
64 lines not on this page · raw message
libcacard/vreader.c new file +519 -0
519 lines not on this page · raw message
libcacard/vreader.h new file +55 -0
55 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.4.1
Part of the diff is not shown here. View the raw message.
Re: [Qemu-devel] [PATCH v21 01/11] trace: move trace objects from Makefile to Makefile.objs
In reply to Alon LevyQuoted 4 lines · Alon Levy
--- Makefile | 32 -------------------------------- Makefile.objs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-)
The commit message can be a little more verbose :(
It will be:
allow libcacard (later commit) to make use of the rules for building trace objects, to build libcacard/vscclient (and later still libcacard/libcacard.so).
Quoted 91 lines
Makefile +0
-32@@ -112,38 +112,6 @@ ui/vnc.o: QEMU_CFLAGS += $(VNC_TLS_CFLAGS) bt-host.o: QEMU_CFLAGS += $(BLUEZ_CFLAGS) -ifeq ($(TRACE_BACKEND),dtrace) -trace.h: trace.h-timestamp trace-dtrace.h -else -trace.h: trace.h-timestamp -endif -trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h") - @cmp -s $@ trace.h || cp $@ trace.h - -trace.c: trace.c-timestamp -trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c") - @cmp -s $@ trace.c || cp $@ trace.c - -trace.o: trace.c $(GENERATED_HEADERS) - -trace-dtrace.h: trace-dtrace.dtrace - $(call quiet-command,dtrace -o $@ -h -s $<, " GEN trace-dtrace.h") - -# Normal practice is to name DTrace probe file with a '.d' extension -# but that gets picked up by QEMU's Makefile as an external dependancy -# rule file. So we use '.dtrace' instead -trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp -trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@," GEN trace-dtrace.dtrace") - @cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace - -trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS) - $(call quiet-command,dtrace -o $@ -G -s $<, " GEN trace-dtrace.o") - -simpletrace.o: simpletrace.c $(GENERATED_HEADERS) - version.o: $(SRC_PATH)/version.rc config-host.mak $(call quiet-command,$(WINDRES) -I. -o $@ $<," RC $(TARGET_DIR)$@")Makefile.objs +32
-0@@ -309,6 +309,38 @@ libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o # trace ifeq ($(TRACE_BACKEND),dtrace) +trace.h: trace.h-timestamp trace-dtrace.h +else +trace.h: trace.h-timestamp +endif +trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h") + @cmp -s $@ trace.h || cp $@ trace.h + +trace.c: trace.c-timestamp +trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c") + @cmp -s $@ trace.c || cp $@ trace.c + +trace.o: trace.c $(GENERATED_HEADERS) + +trace-dtrace.h: trace-dtrace.dtrace + $(call quiet-command,dtrace -o $@ -h -s $<, " GEN trace-dtrace.h") + +# Normal practice is to name DTrace probe file with a '.d' extension +# but that gets picked up by QEMU's Makefile as an external dependancy +# rule file. So we use '.dtrace' instead +trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp +trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@," GEN trace-dtrace.dtrace") + @cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace + +trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS) + $(call quiet-command,dtrace -o $@ -G -s $<, " GEN trace-dtrace.o") + +simpletrace.o: simpletrace.c $(GENERATED_HEADERS) + +ifeq ($(TRACE_BACKEND),dtrace) trace-obj-y = trace-dtrace.o else trace-obj-y = trace.oSignature · 1 line
1.7.4.1
Re: [Qemu-devel] [PATCH v21 01/11] trace: move trace objects from Makefile to Makefile.objs
Quoted 6 lines · Alon Levy
Quoted 4 lines · Alon Levy
---
Makefile | 32 -------------------------------- Makefile.objs | 32 ++++++++++++++++++++++++++++++++2 files changed, 32 insertions(+), 32 deletions(-)
Quoted 7 lines
The commit message can be a little more verbose :(
It will be:
allow libcacard (later commit) to make use of the rules for building trace objects, to build libcacard/vscclient (and later still libcacard/libcacard.so).
I will test this patch and get back to you within the next two or three days.
Stefan
Re: [Qemu-devel] [PATCH v21 01/11] trace: move trace objects from Makefile to Makefile.objs
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Alon Levy
Quoted 4 lines · Alon Levy
---
Makefile | 32 -------------------------------- Makefile.objs | 32 ++++++++++++++++++++++++++++++++2 files changed, 32 insertions(+), 32 deletions(-)The commit message can be a little more verbose :(
Quoted 7 lines
Quoted 5 lines
It will be:
allow libcacard (later commit) to make use of the rules for building trace objects, to build libcacard/vscclient (and later still libcacard/libcacard.so).
I will test this patch and get back to you within the next two or three days.
Thanks, much appreciated.
Alon
Quoted 3 lines
Stefan
Quoted 6 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
I just build tested this patchset and got:
$ make distclean $ ./configure --prefix=/usr --target-list=x86_64-softmmu --enable-io-thread --disable-strip $ make CC x86_64-softmmu/../libcacard/vcard_emul_nss.o ../libcacard/vcard_emul_nss.c:23:21: fatal error: pk11pub.h: No such file or directory compilation terminated. make[1]: *** [../libcacard/vcard_emul_nss.o] Error 1 make: *** [subdir-x86_64-softmmu] Error 2
It seems the smartcard ./configure check needs to be stricter in checking for the presence of build dependencies.
Stefan
Quoted 20 lines · Stefan Hajnoczi
Quoted 6 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
I just build tested this patchset and got:
$ make distclean $ ./configure --prefix=/usr --target-list=x86_64-softmmu --enable-io-thread --disable-strip $ make CC x86_64-softmmu/../libcacard/vcard_emul_nss.o ../libcacard/vcard_emul_nss.c:23:21: fatal error: pk11pub.h: No such file or directory compilation terminated. make[1]: *** [../libcacard/vcard_emul_nss.o] Error 1 make: *** [subdir-x86_64-softmmu] Error 2
Quoted 4 lines
It seems the smartcard ./configure check needs to be stricter in checking for the presence of build dependencies.
Stefan
Can you give me the output of configure? specifically "nss used yes"? or "nss used no"?
Quoted 20 lines · Stefan Hajnoczi
Quoted 6 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
I just build tested this patchset and got:
$ make distclean $ ./configure --prefix=/usr --target-list=x86_64-softmmu --enable-io-thread --disable-strip $ make CC x86_64-softmmu/../libcacard/vcard_emul_nss.o ../libcacard/vcard_emul_nss.c:23:21: fatal error: pk11pub.h: No such file or directory compilation terminated. make[1]: *** [../libcacard/vcard_emul_nss.o] Error 1 make: *** [subdir-x86_64-softmmu] Error 2
Quoted 5 lines
It seems the smartcard ./configure check needs to be stricter in checking for the presence of build dependencies.
Stefan
Thanks, this should fix it:
Makefile.target +1 -1
@@ -350,7 +350,7 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU -obj-y += $(addprefix ../libcacard/, $(libcacard-$(CONFIG_SMARTCARD))) +obj-y += $(addprefix ../libcacard/, $(libcacard-$(CONFIG_SMARTCARD_NSS))) obj-y += $(addprefix ../, $(trace-obj-y)) obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
Re: [Qemu-devel] [PATCH v21 01/11] trace: move trace objects from Makefile to Makefile.objs
In reply to Alon LevyQuoted 10 lines · Alon Levy
Quoted 9 lines · Stefan Hajnoczi
Quoted 8 lines · Alon Levy
Quoted 4 lines · Alon Levy
---
Makefile | 32 -------------------------------- Makefile.objs | 32 ++++++++++++++++++++++++++++++++2 files changed, 32 insertions(+), 32 deletions(-)The commit message can be a little more verbose :(
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
It will be:
allow libcacard (later commit) to make use of the rules for building trace objects, to build libcacard/vscclient (and later still libcacard/libcacard.so).
I will test this patch and get back to you within the next two or three days.
Thanks, much appreciated.
$ make distclean $ ./configure --prefix=/usr --target-list=x86_64-softmmu --enable-io-thread --disable-strip --enable-trace-backend=simple $ make [...] LINK libcacard/vscclient simpletrace.o: In function `get_clock': /home/stefanha/qemu/qemu-timer.h:92: undefined reference to `use_rt_clock' collect2: ld returned 1 exit status make[1]: *** [vscclient] Error 1 make: *** [subdir-libcacard] Error 2
Stefan
Makefile.target
Quoted 6 lines · Alon Levy
Thanks, this should fix it:
Makefile.target +0
-0
Thanks it fixes it. I didn't have libnss3-dev installed.
Stefan
Ack series
Quoted 273 lines · Alon Levy
This patchset adds three new devices, usb-ccid, ccid-card-passthru and ccid-card-emulated, providing a CCID bus, a simple passthru protocol implementing card requiring a client, and a standalone emulated card.
It also introduces a new directory libcaccard with CAC card emulation, CAC is a type of ISO 7816 smart card.
Tree for pull:
git://anongit.freedesktop.org/~alon/qemuusb_ccid.v20
v20->v21changes:
* all: cosmetics
* libcacard, ccid-card-passthru:
* use qemu-{malloc,free} and qemu-thread,error_report
* libcacard:
* split to multiple patches
v19->v20changes:
* checkpatch.pl. Here are the remaining errors with explanation:
* ignored 5 macro errors of the type
"ERROR: Macros with complex values should be enclosed in parenthesis" because fixing them breaks current code, if it really bothers someone I can fix it.
* four of them are inlibcacard/card_7816t.h:
/* give the subfields a unified look */
..
#definea_claa_header->ah_cla/* class */
#definea_insa_header->ah_ins/* instruction */
#definea_p1a_header->ah_p1/* parameter 1 */
#definea_p2a_header->ah_p2/* parameter 2 */
* and the fifth:
#4946: FILE:libcacard/vcardt.h:31:(quoted diff) +2
-0+#define VCARD_ATR_PREFIX(size) 0x3b, 0x66+(size), 0x00, 0xff, \ + 'V', 'C', 'A', 'R', 'D', '_' * Ignored this warning since I couldn't figure it out, and it's a test file:WARNING: externs should be avoided in .c files #2343: FILE:
libcacard/link_test.c:7:
+VCardStatus cac_card_init(const char *flags, VCard *card,v18-v19 changes:
* more merges, down to a single digit number of patches.
* drop enumeration property, use string.
* rebased (trivial)v17-v18 changes:
* mergevscard_common.hpatches.
* actually provide a tree to pull.v16-v17 changes:
* merged all the "v15->v16" patches
* merged some more wherever it was easy (all same file commits).
* added signed off by to first four patches
*ccid.h: added copyright, removed underscore in defines, and replaced non C89 commentsv15-v16 changes:
* splitvscard_commonintroducing patch for ease of review
* sum of commit logs for the v15-v16 commits: (whitespace fixes
removed for space, see original commit messages in later patches)
* usb-ccid:
* fix abort on client answer after card remove
* enable migration
* remove side affect code from asserts
* return consistent self-powered state
* mask out reserved bits inccid_set_parameters
* add missing abRFU in SetParameters (no affect on linux guest)
*vscard_common.hprotocol change:
* VSCMsgInit capabilities and magic
* removed ReaderResponse, will use Error instead with code==VSC_SUCCESS.
* added Flush and FlushComplete, remove Reconnect.
* defineVSCARD_MAGIC
* added error codeVSC_SUCCESS.
* ccid-card-passthru
* return correct size
* return error instead of assert if client sent too large ATR
* don't assert if client sent too large a size, but add asserts for indices to buffer
* resetvscard_inindices on chardev disconnect
* handle init from client
* error if no chardev supplied
* use ntoh, hton
* eradicatereader_id_t
* remove Reconnect usage (removed from VSCARD protocol)
* sendVSC_SUCCESSon card insert/remove and reader add/remove
* ccid-card-emulated
* fix error reporting in initfnv14-v15 changes:
* add patch with --enable-smartcard and --disable-smartcard and only disable ccid-card-emulated if nss not found.
* add patch with description strings
* s/libcaccard/libcacard/ indocs/ccid.txtv13-v14 changes:
- support device_del/device_add on ccid-card-* and usb-ccid
* usb-ccid:
* lose card reference when card device deleted
* check slot number and deny adding a slot if one is already added.
* ccid-card-*: useqdev_simple_unplug_cbin both emulated and passthru ccid cards, the exitfn already takes care of triggering card removal in the usb dev.
* libcacard:
* remove double include of config-host.mak
* add replay of card events to libcacard to support second and more emulation
* don't initialize more then once (doesn't support it right now, so one thread, NSS thread, is left whendevice_delis done)
* addVCARD_EMUL_INIT_ALREADY_INITED
* ccid-card-emulated:
* take correct mutexes on signaling to fix deadlocks ondevice_del
* allow card insertion/removal event without proper reader insertion eventv12-v13 changes:
* libcacard:
* fixMakefileclean to remove vscclient
* fix double include of config-host inMakefile
* usb-ccid: remove attach/detach logic, usb is always attached. Guest doesn't care if there is a reader attached with no card anyway.
* ccid-card-passthru: don't closechr_devon removal, makes it possible to use device_del/device_add to create remove/insertion for debugging.v11-v12 changes:
* fix out of tree buildv10-v11 changes:
* fix last patch that removed one of the doc files.
* updated flow table indocs/ccid.txtv8-v10 changes:
* usb-ccid:
* add slot for future use (Gerd)
* ifdefENABLE_MIGRATIONfor migration support on account of usb migration not being ready in general. (Gerd)
* verbosified commit messages. (Gerd)
* put libcacard docs in libcacard commit. (Gerd)v8-v9 changes:
* Blue Swirl comments:
* white space fixes
* enabled by default, disabled only if missing nss
* forgotten fix from v8 (don't build libcacard.so)
* added a note about device being little endian
* library renamed from libcaccard to libcacard
* squashed both of libcacard patches, they touched different files anyway.v7-v8 changes:
* Blue Swirl comments:
* usb-ccid: deannonymize some structs
* usb-ccid: coding style change -answer_tandbulk_in_tfixed
* usb-ccid: handle endianess conversion between guest and host
* usb-ccid: s/ccid_bulk_in_copy_out/ccid_bulk_in_copy_to_guest/
* ccid-card-emulated: fix segfault if backend not specified
* ccid-card-emulated: let last reader inserted win
* libcaccard: remove doublevscard_common.h
v6->v7changes:
* external libcaccard became internal directory libcaccard
* statically link object files into qemu
* produce libcaccard.so for usage by external projects
* applied coding style to new code (please check me)
- did not use the qemu options parsing for libcaccard, since it seems to draw large amounts of qemu code (monitor for instance).
v5->v6changes:
* really remove static debug (I apologize for claiming to have done so before)
v4->v5changes:
* rebased to latest
* remove static debug in card devices
* fix --enable-smartcard to link
* stall instead of assert when exceedingBULK_OUT_DATA_SIZE
* makeccid_reserve_recv_buffor too large len discard message, not exit
* makeccid_reserve_recv_bufreturn void*
* fix typo
* remove commented code in VMState
v3->v4:
* remove ccid field in CCIDBus
* remove static debug in bus
* add back docs
v2->v3:
* split into bus (usb-ccid.c, usesccid.h) and card (ccid-card-passthru.c).
* removed documentation (being revised).
v1->v2:
* all QSIMPLEQ turned into fixed sized rings
* all allocated buffers turned into fixed size buffers
* added migration support
* added a message to tell client qemu has migrated to ip:port
* for lack of monitor commands ip:port are 0:0, which causes the updated vscclient to connect to one port higher on the same host. will add monitor commands in a separate patch. tested with current setup.Alon Levy (7):
trace: move trace objects fromMakefileto Makefile.objsqemu-thread.h: includeinttypes.h
usb-ccid: add CCID bus
introducelibcacard/vscard_common.h
ccid: add passthru card device
ccid: add ccid-card-emulated device
ccid: add docsRobert Relyea (4):
libcacard: initial commit
libcacard: add vscclient
libcacard: add passthru
libcacard: add docsMakefile | 38 +- Makefile.objs | 39 ++ Makefile.target | 2 + configure | 60 ++ docs/ccid.txt | 135 ++++ docs/libcacard.txt | 483 +++++++++++++++ hw/ccid-card-emulated.c | 595 ++++++++++++++++++ hw/ccid-card-passthru.c | 341 +++++++++++ hw/ccid.h | 59 ++ hw/usb-ccid.c | 1419 +++++++++++++++++++++++++++++++++++++++++++ libcacard/Makefile | 22 + libcacard/cac.c | 406 ++++++++++++ libcacard/cac.h | 23 + libcacard/card_7816.c | 763 +++++++++++++++++++++++ libcacard/card_7816.h | 62 ++ libcacard/card_7816t.h | 165 +++++ libcacard/event.c | 108 ++++ libcacard/eventt.h | 29 + libcacard/link_test.c | 21 + libcacard/passthru.c | 609 +++++++++++++++++++ libcacard/passthru.h | 53 ++ libcacard/vcard.c | 341 +++++++++++ libcacard/vcard.h | 86 +++ libcacard/vcard_emul.h | 65 ++ libcacard/vcard_emul_nss.c | 1159 +++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 63 ++ libcacard/vcard_emul_type.h | 32 + libcacard/vcardt.h | 64 ++ libcacard/vevent.h | 27 + libcacard/vreader.c | 519 ++++++++++++++++ libcacard/vreader.h | 55 ++ libcacard/vreadert.h | 24 + libcacard/vscard_common.h | 178 ++++++ libcacard/vscclient.c | 746 +++++++++++++++++++++++ qemu-thread.h | 2 + 35 files changed, 8759 insertions(+), 34 deletions(-)create mode 100644
docs/ccid.txt
create mode 100644docs/libcacard.txt
create mode 100644hw/ccid-card-emulated.c
create mode 100644hw/ccid-card-passthru.c
create mode 100644hw/ccid.h
create mode 100644hw/usb-ccid.c
create mode 100644 libcacard/Makefile
create mode 100644libcacard/cac.c
create mode 100644libcacard/cac.h
create mode 100644libcacard/card_7816.c
create mode 100644libcacard/card_7816.h
create mode 100644libcacard/card_7816t.h
create mode 100644libcacard/event.c
create mode 100644libcacard/eventt.h
create mode 100644libcacard/link_test.c
create mode 100644libcacard/passthru.c
create mode 100644libcacard/passthru.h
create mode 100644libcacard/vcard.c
create mode 100644libcacard/vcard.h
create mode 100644libcacard/vcard_emul.h
create mode 100644libcacard/vcard_emul_nss.c
create mode 100644libcacard/vcard_emul_type.c
create mode 100644libcacard/vcard_emul_type.h
create mode 100644libcacard/vcardt.h
create mode 100644libcacard/vevent.h
create mode 100644libcacard/vreader.c
create mode 100644libcacard/vreader.h
create mode 100644libcacard/vreadert.h
create mode 100644libcacard/vscard_common.h
create mode 100644libcacard/vscclient.c