libcacard: initial commit
PATCH v25 6/10 libcacard: initial commit
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
---
changes from v24->v25:
* Fix out of tree builds.
* Fix build with linux-user targets.
changes from v23->v24: (Jes Sorensen review 2)
* Makefile.target: use obj-$(CONFIG_*) +=
* remove unrequired includes, include qemu-common before qemu-thread
* required adding #define NO_NSPR_10_SUPPORT (harmless)
changes from v22->v23:
* configure fixes: (reported by Stefan Hajnoczi)
* test a = b, not a == b (second isn't portable)
* quote $source_path in case it contains spaces
- this doesn't really help since there are many other places that need similar fixes, not introduced by this patch.
changes from v21->v22:
* fix configure to not link libcacard if nss not found (reported by Stefan Hajnoczi)
* fix vscclient linkage with simpletrace backend (reported by Stefan Hajnoczi)
* card_7816.c: add missing break in ERROR_DATA_NOT_FOUND (reported by William van de Velde)
changes from v20->v21: (Jes Sorensen 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
libcacard: fix out of tree builds
--- Makefile | 6 +- Makefile.objs | 5 + Makefile.target | 6 + configure | 49 ++ libcacard/Makefile | 20 + libcacard/cac.c | 403 +++++++++++++++ libcacard/cac.h | 23 + libcacard/card_7816.c | 763 ++++++++++++++++++++++++++++ libcacard/card_7816.h | 62 +++ libcacard/card_7816t.h | 165 ++++++ libcacard/event.c | 106 ++++ libcacard/eventt.h | 29 ++ libcacard/link_test.c | 22 + libcacard/vcard.c | 339 +++++++++++++ libcacard/vcard.h | 86 ++++ libcacard/vcard_emul.h | 65 +++ libcacard/vcard_emul_nss.c | 1157 +++++++++++++++++++++++++++++++++++++++++++ libcacard/vcard_emul_type.c | 57 +++ libcacard/vcard_emul_type.h | 32 ++ libcacard/vcardt.h | 64 +++ libcacard/vevent.h | 27 + libcacard/vreader.c | 513 +++++++++++++++++++ libcacard/vreader.h | 55 ++ libcacard/vreadert.h | 24 + 24 files changed, 4076 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
@@ -352,6 +352,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 +6 -0
@@ -353,6 +353,12 @@ obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y)) endif # CONFIG_SOFTMMU +ifndef CONFIG_LINUX_USER +# libcacard needs qemu-thread support, and besides is only needed by devices +# so not requires with linux-user targets +obj-$(CONFIG_SMARTCARD_NSS) += $(addprefix ../libcacard/, $(libcacard-y)) +endif # CONFIG_LINUX_USER + 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 +20 -0
@@ -0,0 +1,20 @@ +-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=$(addprefix ../, $(QEMU_THREAD) $(oslib-obj-y) $(trace-obj-y) qemu-malloc.o qemu-timer-common.o) + +QEMU_CFLAGS+=-I../ + +clean: + rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~ +
libcacard/cac.c new file +403 -0
403 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 +106 -0
106 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 +22 -0
@@ -0,0 +1,22 @@ +/* +* 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 +339 -0
339 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 +1157 -0
773 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 +513 -0
513 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.2
Part of the diff is not shown here. View the raw message.