Skip to contentSkip to conversation

usb-ccid (v10)

PATCH In review Alon Levy 2 participants 12 messages Dec 16, 2010 Kbuild

lore
Share & tools
lore

Alon Levy

author
#0 lore raw

cover usb-ccid (v10)

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.

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.

*** BLURB HERE ***

Alon Levy (4):
usb-ccid: add CCID bus
ccid: add passthru card device
ccid: add ccid-card-emulated device (v2)
ccid: add docs

Robert Relyea (1):
libcacard: initial commit after coding style fixes

 Makefile                    |    6 +-
 Makefile.objs               |    6 +
 Makefile.target             |    2 +
 configure                   |   25 +
 docs/ccid.txt               |  125 ++++
 hw/ccid-card-emulated.c     |  501 ++++++++++++++++
 hw/ccid-card-passthru.c     |  277 +++++++++
 hw/ccid.h                   |   35 ++
 hw/usb-ccid.c               | 1362 +++++++++++++++++++++++++++++++++++++++++++
 libcacard/Makefile          |   13 +
 libcacard/cac.c             |  411 +++++++++++++
 libcacard/cac.h             |   20 +
 libcacard/card_7816.c       |  780 +++++++++++++++++++++++++
 libcacard/card_7816.h       |   60 ++
 libcacard/card_7816t.h      |  163 +++++
 libcacard/config.h          |   81 +++
 libcacard/event.c           |  112 ++++
 libcacard/eventt.h          |   28 +
 libcacard/link_test.c       |   20 +
 libcacard/mutex.h           |   59 ++
 libcacard/passthru.c        |  612 +++++++++++++++++++
 libcacard/passthru.h        |   50 ++
 libcacard/vcard.c           |  350 +++++++++++
 libcacard/vcard.h           |   85 +++
 libcacard/vcard_emul.h      |   59 ++
 libcacard/vcard_emul_nss.c  | 1147 ++++++++++++++++++++++++++++++++++++
 libcacard/vcard_emul_type.c |   60 ++
 libcacard/vcard_emul_type.h |   29 +
 libcacard/vcardt.h          |   66 +++
 libcacard/vevent.h          |   26 +
 libcacard/vreader.c         |  515 ++++++++++++++++
 libcacard/vreader.h         |   53 ++
 libcacard/vreadert.h        |   23 +
 libcacard/vscard_common.h   |  130 ++++
 libcacard/vscclient.c       |  710 ++++++++++++++++++++++
 35 files changed, 7999 insertions(+), 2 deletions(-)
 create mode 100644 docs/ccid.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/config.h
 create mode 100644 libcacard/event.c
 create mode 100644 libcacard/eventt.h
 create mode 100644 libcacard/link_test.c
 create mode 100644 libcacard/mutex.h
 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.3.3
author
#1 lore raw

PATCH 1/5 usb-ccid: add CCID bus

A 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.

---
 Makefile.objs |    1 +
 configure     |    6 +
 hw/ccid.h     |   35 ++
 hw/usb-ccid.c | 1362 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1404 insertions(+), 0 deletions(-)
 create mode 100644 hw/ccid.h
 create mode 100644 hw/usb-ccid.c
Makefile.objs +1 -0
index cebb945..1454264 100644
@@ -193,6 +193,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.o
+hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o
 
 # PPC devices
 hw-obj-$(CONFIG_OPENPIC) += openpic.o
configure +6 -0
index 2917874..584cc8e 100755
@@ -332,6 +332,7 @@ zero_malloc=""
 trace_backend="nop"
 trace_file="trace"
 spice=""
+smartcard="yes"
 
 # OS specific
 if check_define __linux__ ; then
@@ -2354,6 +2355,7 @@ echo "vhost-net support $vhost_net"
 echo "Trace backend     $trace_backend"
 echo "Trace output file $trace_file-<pid>"
 echo "spice support     $spice"
+echo "smartcard support $smartcard"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -2617,6 +2619,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 +35 -0
new file mode 100644
index 0000000..af59070
@@ -0,0 +1,35 @@
+#ifndef __CCID_H__
+#define __CCID_H__
+
+#include "qdev.h"
+
+typedef struct CCIDCardState CCIDCardState;
+typedef struct CCIDCardInfo CCIDCardInfo;
+
+struct CCIDCardState {
+    DeviceState qdev;
+    uint32_t    slot; // For future use with multiple slot reader.
+};
+
+struct CCIDCardInfo {
+    DeviceInfo qdev;
+    void (*print)(Monitor *mon, CCIDCardState *card, int indent);
+    const uint8_t *(*get_atr)(CCIDCardState *card, uint32_t *len);
+    void (*apdu_from_guest)(CCIDCardState *card, const uint8_t *apdu, uint32_t len);
+    int (*exitfn)(CCIDCardState *card);
+    int (*initfn)(CCIDCardState *card);
+};
+
+void ccid_card_send_apdu_to_guest(CCIDCardState *card, uint8_t* apdu, uint32_t len);
+void ccid_card_card_removed(CCIDCardState *card);
+void ccid_card_card_inserted(CCIDCardState *card);
+void ccid_card_card_error(CCIDCardState *card, uint64_t error);
+void ccid_card_qdev_register(CCIDCardInfo *card);
+
+/* support guest visible insertion/removal of ccid devices based on actual
+ * devices connected/removed. Called by card implementation (passthru, local) */
+int ccid_card_ccid_attach(CCIDCardState *card);
+void ccid_card_ccid_detach(CCIDCardState *card);
+
+#endif // __CCID_H__
+
hw/usb-ccid.c new file +1362 -0

1,362 lines not on this page · raw message

Signature · 1 line
1.7.3.3
Acked-by on v1 1/5
#2 lore raw

Re: [Qemu-devel] [PATCH 1/5] usb-ccid: add CCID bus

Quoted 6 lines · Alon Levy

A 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.

cheers,
Gerd

author
#3 lore raw

PATCH 2/5 ccid: add passthru card device

In reply to Alon Levy

The 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

---
 Makefile.objs             |    2 +-
 hw/ccid-card-passthru.c   |  277 +++++++++++++++++++++++++++++++++++++++++++++
 libcacard/vscard_common.h |  130 +++++++++++++++++++++
 3 files changed, 408 insertions(+), 1 deletions(-)
 create mode 100644 hw/ccid-card-passthru.c
 create mode 100644 libcacard/vscard_common.h
Makefile.objs +1 -1
index 1454264..c4a445c 100644
@@ -193,7 +193,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.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 +277 -0

277 lines not on this page · raw message

libcacard/vscard_common.h new file +130 -0

130 lines not on this page · raw message

Signature · 1 line
1.7.3.3
Acked-by on v1 2/5
#4 lore raw

Re: [Qemu-devel] [PATCH 2/5] ccid: add passthru card device

Quoted 6 lines · Alon Levy

The 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

cheers,
Gerd

author
#5 lore raw

PATCH 3/5 libcacard: initial commit after coding style fixes

In reply to Alon Levy

From: 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

---
 Makefile                    |    6 +-
 Makefile.objs               |    5 +
 Makefile.target             |    2 +
 configure                   |   19 +
 docs/libcacard.txt          |  483 ++++++++++++++++++
 libcacard/Makefile          |   13 +
 libcacard/cac.c             |  411 ++++++++++++++++
 libcacard/cac.h             |   20 +
 libcacard/card_7816.c       |  780 +++++++++++++++++++++++++++++
 libcacard/card_7816.h       |   60 +++
 libcacard/card_7816t.h      |  163 ++++++
 libcacard/config.h          |   81 +++
 libcacard/event.c           |  112 +++++
 libcacard/eventt.h          |   28 +
 libcacard/link_test.c       |   20 +
 libcacard/mutex.h           |   59 +++
 libcacard/passthru.c        |  612 +++++++++++++++++++++++
 libcacard/passthru.h        |   50 ++
 libcacard/vcard.c           |  350 +++++++++++++
 libcacard/vcard.h           |   85 ++++
 libcacard/vcard_emul.h      |   59 +++
 libcacard/vcard_emul_nss.c  | 1147 +++++++++++++++++++++++++++++++++++++++++++
 libcacard/vcard_emul_type.c |   60 +++
 libcacard/vcard_emul_type.h |   29 ++
 libcacard/vcardt.h          |   66 +++
 libcacard/vevent.h          |   26 +
 libcacard/vreader.c         |  515 +++++++++++++++++++
 libcacard/vreader.h         |   53 ++
 libcacard/vreadert.h        |   23 +
 libcacard/vscclient.c       |  710 ++++++++++++++++++++++++++
 30 files changed, 6045 insertions(+), 2 deletions(-)
 create mode 100644 docs/libcacard.txt
 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/config.h
 create mode 100644 libcacard/event.c
 create mode 100644 libcacard/eventt.h
 create mode 100644 libcacard/link_test.c
 create mode 100644 libcacard/mutex.h
 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/vscclient.c
Makefile +4 -2
index c80566c..bceb8ba 100644
@@ -173,6 +173,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 libcacard
+
 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
@@ -184,7 +186,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); do \
 	if test -d $$d; then $(MAKE) -C $$d $@ || exit 1; fi; \
 	rm -f $$d/qemu-options.def; \
         done
@@ -195,7 +197,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
index c4a445c..3f44a91 100644
@@ -310,6 +310,11 @@ user-obj-y += qemu-timer-common.o
 endif
 endif
 
+######################################################################
+# smartcard
+
+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)
 
 vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
Makefile.target +2 -0
index d08f5dd..4c32b11 100644
@@ -334,6 +334,8 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y))
 
 endif # CONFIG_SOFTMMU
 
+obj-y += $(addprefix $(SRC_PATH)/libcacard/, $(libcacard-$(CONFIG_SMARTCARD)))
+
 obj-y += $(addprefix ../, $(trace-obj-y))
 obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
 
configure +19 -0
index 584cc8e..704b7a9 100755
@@ -2124,6 +2124,20 @@ EOF
   fi
 fi
 
+# check for libcacard for smartcard support
+smartcard_cflags="-I\$(SRC_PATH)/libcacard"
+smartcard_libs="-L\$(SRC_PATH)/libcacard -lcaccard"
+libcacard_libs=$($pkgconfig --libs nss 2>/dev/null)
+libcacard_cflags=$($pkgconfig --cflags nss)
+# TODO - what's the minimal nss version we support?
+if $pkgconfig --atleast-version=3.12.8 nss; then
+    smartcard="yes"
+    QEMU_CFLAGS="$QEMU_CFLAGS $smartcard_cflags $libcacard_cflags"
+    LIBS="$libcacard_libs $LIBS"
+else
+    smartcard="no"
+fi
+
 ##########################################
 
 ##########################################
@@ -2950,6 +2964,11 @@ fi
 if test "$target_darwin_user" = "yes" ; then
   echo "CONFIG_DARWIN_USER=y" >> $config_target_mak
 fi
+if test "$smartcard" = "yes" ; then
+  echo "subdir-$target: subdir-libcacard" >> $config_host_mak
+  echo "libcacard_libs=$libcacard_libs" >> $config_host_mak
+  echo "libcacard_cflags=$libcacard_cflags" >> $config_host_mak
+fi
 list=""
 if test ! -z "$gdb_xml_files" ; then
   for x in $gdb_xml_files; do
docs/libcacard.txt new file +483 -0

483 lines not on this page · raw message

libcacard/Makefile new file +13 -0
new file mode 100644
index 0000000..cc20c45
@@ -0,0 +1,13 @@
+include ../Makefile.objs
+include ../config-host.mak
+include ../config-all-devices.mak
+include $(SRC_PATH)/rules.mak
+
+vscclient: $(libcacard-y) vscclient.o
+	gcc $(libcacard_libs) -o $@ $^
+
+all: vscclient
+
+clean:
+	rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~
+
libcacard/cac.c new file +411 -0

411 lines not on this page · raw message

libcacard/cac.h new file +20 -0
new file mode 100644
index 0000000..bb2a9f0
@@ -0,0 +1,20 @@
+/*
+ * defines the entry point for the cac card. Only used by cac.c anc
+ * vcard_emul_type.c
+ */
+#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 +780 -0

780 lines not on this page · raw message

libcacard/card_7816.h new file +60 -0

60 lines not on this page · raw message

libcacard/card_7816t.h new file +163 -0

163 lines not on this page · raw message

libcacard/config.h new file +81 -0

81 lines not on this page · raw message

libcacard/event.c new file +112 -0

112 lines not on this page · raw message

libcacard/eventt.h new file +28 -0
new file mode 100644
index 0000000..4c3df4f
@@ -0,0 +1,28 @@
+/*
+ *
+ */
+
+#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 +20 -0
new file mode 100644
index 0000000..40d2c6d
@@ -0,0 +1,20 @@
+/*
+ *
+ */
+#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/mutex.h new file +59 -0

59 lines not on this page · raw message

libcacard/passthru.c new file +612 -0

612 lines not on this page · raw message

libcacard/passthru.h new file +50 -0

50 lines not on this page · raw message

libcacard/vcard.c new file +350 -0

34 lines not on this page · raw message

libcacard/vcard.h new file +85 -0

85 lines not on this page · raw message

libcacard/vcard_emul.h new file +59 -0

59 lines not on this page · raw message

libcacard/vcard_emul_nss.c new file +1147 -0

1,147 lines not on this page · raw message

libcacard/vcard_emul_type.c new file +60 -0

60 lines not on this page · raw message

libcacard/vcard_emul_type.h new file +29 -0
new file mode 100644
index 0000000..da15528

Lines of this file are not shown. View the raw message.

libcacard/vcardt.h new file +66 -0

66 lines not on this page · raw message

libcacard/vevent.h new file +26 -0
new file mode 100644
index 0000000..f202ea8

Lines of this file are not shown. View the raw message.

libcacard/vreader.c new file +515 -0

515 lines not on this page · raw message

libcacard/vreader.h new file +53 -0

53 lines not on this page · raw message

libcacard/vreadert.h new file +23 -0
new file mode 100644
index 0000000..4c01259

Lines of this file are not shown. View the raw message.

libcacard/vscclient.c new file +710 -0

710 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.3.3

Part of the diff is not shown here. View the raw message.

Acked-by on v1 3/5
#6 lore raw

Re: [Qemu-devel] [PATCH 3/5] libcacard: initial commit after coding style fixes

Quoted 3 lines · Alon Levy

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

Looks good to me, although I'm not a crypto expert. Most of the critical crypto stuff is in nss anyway though, so:

cheers,
Gerd

author
#7 lore raw

PATCH 4/5 ccid: add ccid-card-emulated device (v2)

In reply to Alon Levy

This 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 v1:
remove stale comments, use only c-style comments bugfix, forgot to set recv_len
change reader name to 'Virtual Reader'

---
 Makefile.objs           |    2 +-
 hw/ccid-card-emulated.c |  501 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 502 insertions(+), 1 deletions(-)
 create mode 100644 hw/ccid-card-emulated.c
Makefile.objs +1 -1
index 3f44a91..54b22ca 100644
@@ -193,7 +193,7 @@ hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 hw-obj-$(CONFIG_DMA) += dma.o
-hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
+hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o ccid-card-emulated.o
 
 # PPC devices
 hw-obj-$(CONFIG_OPENPIC) += openpic.o
hw/ccid-card-emulated.c new file +501 -0

501 lines not on this page · raw message

Signature · 1 line
1.7.3.3
Acked-by on v1 4/5
#8 lore raw

Re: [Qemu-devel] [PATCH 4/5] ccid: add ccid-card-emulated device (v2)

Quoted 5 lines · Alon Levy

This 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).

cheers,
Gerd

author
#9 lore raw

PATCH 5/5 ccid: add docs

In reply to Alon Levy

Add documentation for the usb-ccid device and accompanying two card devices, ccid-card-emulated and ccid-card-passthru.

---
 docs/ccid.txt      |  125 ++++++++++++++
 docs/libcacard.txt |  483 ----------------------------------------------------
 2 files changed, 125 insertions(+), 483 deletions(-)
 create mode 100644 docs/ccid.txt
 delete mode 100644 docs/libcacard.txt
docs/ccid.txt new file +125 -0
new file mode 100644
index 0000000..791c28c
@@ -0,0 +1,125 @@
+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. libcaccard
+
+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 libcaccard library:
+    libcaccard/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)
+
+    libcaccard/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.
+
+A typical interchange is:
+
+client event      |      vscclient           |    passthru    |     usb-ccid  |  guest event
+----------------------------------------------------------------------------------------------
+                  |      VSC_Init            |                |               |
+                  |      VSC_ReaderAdd       |                |     attach    |
+                  |                          |                |               |  sees new usb device.
+card inserted     |                          |                |               |
+                  |      VSC_ATR             |                |               |
+                  |                          |                |               |  guest operation, APDU transfer via CCID
+                  |                          |   VSC_APDU     |               |
+                  |      VSC_APDU            |                |               |
+client<->physical |                          |                |               |
+card APDU exchange|                          |                |               |
+                            [APDU<->APDU repeats several times]
+card removed      |                          |                |               |
+                  |      VSC_CardRemove      |                |               |
+kill/quit         |                          |                |               |
+  vscclient       |                          |                |               |
+                  |      VSC_ReaderRemove    |                |    detach     |
+                  |                          |                |               |   usb device removed.
+
+
+8. libcaccard
+
+ccid-card-passthru and vscclient use libcaccard as the card emulator.
+libcaccard 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 libcaccard subdirectory.
+
docs/libcacard.txt deleted +0 -483

483 lines not on this page · raw message

Signature · 1 line
1.7.3.3
#10 lore raw

Re: [Qemu-devel] [PATCH 5/5] ccid: add docs

Quoted 5 lines · Alon Levy

Add documentation for the usb-ccid device and accompanying two card devices, ccid-card-emulated and ccid-card-passthru.

---
  docs/ccid.txt      |  125 ++++++++++++++
  docs/libcacard.txt |  483 ----------------------------------------------------

Guess that isn't intentional, right?

Quoted 11 lines
docs/ccid.txt new file +11 -0
+A typical interchange is:
+
+client event      |      vscclient           |    passthru    |     usb-ccid  |  guest event
+----------------------------------------------------------------------------------------------
+                  |      VSC_Init            |                |               |
+                  |      VSC_ReaderAdd       |                |     attach    |
+                  |                          |                |               |  sees new usb device.
+card inserted     |                          |                |               |
+                  |      VSC_ATR             |                |               |
+                  |                          |                |               |  guest operation, APDU transfer via CCID
+                  |                          |   VSC_APDU     |               |

docs/ccid.txt line 114

Quoted 10 lines
docs/ccid.txt new file +10 -0
+                  |      VSC_APDU            |                |               |
+client<->physical |                          |                |               |
+card APDU exchange|                          |                |               |
+                            [APDU<->APDU repeats several times]
+card removed      |                          |                |               |
+                  |      VSC_CardRemove      |                |               |
+kill/quit         |                          |                |               |
+  vscclient       |                          |                |               |
+                  |      VSC_ReaderRemove    |                |    detach     |
+                  |                          |                |               |   usb device removed.

This needs updating, doesn't it? I think you plugin and -out just the cards on the ccid bus instead of the whole usb device, right?

cheers,
Gerd

author
#11 lore raw

Re: [Qemu-devel] [PATCH 5/5] ccid: add docs

Quoted 9 lines · Gerd Hoffmann
Quoted 5 lines · Alon Levy

Add documentation for the usb-ccid device and accompanying two card devices, ccid-card-emulated and ccid-card-passthru.

---
 docs/ccid.txt      |  125 ++++++++++++++
 docs/libcacard.txt |  483 ----------------------------------------------------

Guess that isn't intentional, right?

doh!

Quoted 16 lines
Quoted 16 lines
docs/ccid.txt new file +16 -0
+A typical interchange is:
+
+client event      |      vscclient           |    passthru    |     usb-ccid  |  guest event
+----------------------------------------------------------------------------------------------
+                  |      VSC_Init            |                |               |
+                  |      VSC_ReaderAdd       |                |     attach    |
+                  |                          |                |               |  sees new usb device.
+card inserted     |                          |                |               |
+                  |      VSC_ATR             |                |               |
+                  |                          |                |               |  guest operation, APDU transfer via CCID
+                  |                          |   VSC_APDU     |               |
+                  |      VSC_APDU            |                |               |
+client<->physical |                          |                |               |
+card APDU exchange|                          |                |               |
+                            [APDU<->APDU repeats several times]
+card removed      |                          |                |               |
Quoted 9 lines

docs/ccid.txt line 114

Quoted 5 lines
docs/ccid.txt new file +5 -0
+                  |      VSC_CardRemove      |                |               |
+kill/quit         |                          |                |               |
+  vscclient       |                          |                |               |
+                  |      VSC_ReaderRemove    |                |    detach     |
+                  |                          |                |               |   usb device removed.

This needs updating, doesn't it? I think you plugin and -out just the cards on the ccid bus instead of the whole usb device, right?

actually I'm not sure.. I'll check and update.

Quoted 4 lines

cheers,
Gerd