diff --git a/src/gcns/.gitignore b/src/gcns/.gitignore new file mode 100644 index 00000000..84c048a7 --- /dev/null +++ b/src/gcns/.gitignore @@ -0,0 +1 @@ +/build/ diff --git a/src/gcns/CMakeLists.txt b/src/gcns/CMakeLists.txt new file mode 100644 index 00000000..ae74f16e --- /dev/null +++ b/src/gcns/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.18) + +project(gcns VERSION 1.0 DESCRIPTION "Italian healthcare smart card parsing utility") + +add_library(gcns SHARED gcns.c) +set_target_properties(gcns PROPERTIES PUBLIC_HEADER gcns.h) +target_include_directories(gcns PUBLIC ../.. .. .) + +add_executable(main main.c ../tools/util.c) +target_link_libraries(main gcns opensc bsd) + diff --git a/src/tools/gcns.c b/src/gcns/gcns.c similarity index 69% rename from src/tools/gcns.c rename to src/gcns/gcns.c index 7f05a20e..37738260 100644 --- a/src/tools/gcns.c +++ b/src/gcns/gcns.c @@ -20,33 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include -#include -#include -#include -#include - -#include "config.h" -#ifdef ENABLE_READLINE -#include -#include -#endif -#if !defined(_WIN32) -#include /* for htons() */ -#endif - -#include - -#include "common/compat_strlcpy.h" #include "gcns.h" -#include "libopensc/asn1.h" -#include "libopensc/cardctl.h" -#include "libopensc/cards.h" -#include "libopensc/internal.h" -#include "libopensc/iso7816.h" -#include "libopensc/log.h" -#include "libopensc/opensc.h" -#include "util.h" static int opt_wait = 0; static const char *opt_reader = NULL; @@ -112,32 +86,3 @@ int gcns_read_personal_data(u8 *buffer, size_t len) { return r; } - -int main(int argc, char *argv[]) { - int r; - - printf("OpenSC version: %s\n", sc_get_version()); - - r = gcns_init(); - if (r != GCNS_SUCCESS) { - fprintf(stderr, "Init Error\n"); - return GCNS_INIT; - } - - u8 buffer[2048]; - r = gcns_read_personal_data(buffer, 2048); - - if (r < 0) { - fprintf(stderr, "Read personal data error\n"); - return GCNS_READ_PERSONAL_DATA; - } - - util_hex_dump_asc(stdout, buffer, r, 0); - - r = gcns_close(); - if (r != GCNS_SUCCESS) { - return GCNS_CLOSE; - } - - return GCNS_SUCCESS; -} diff --git a/src/gcns/gcns.h b/src/gcns/gcns.h new file mode 100644 index 00000000..1a8291cf --- /dev/null +++ b/src/gcns/gcns.h @@ -0,0 +1,16 @@ +#ifndef GCNS_H +#define GCNS_H + +#include "libopensc/asn1.h" +#include "tools/util.h" + +#define GCNS_SUCCESS 0 +#define GCNS_INIT -1001 +#define GCNS_READ_PERSONAL_DATA -1002 +#define GCNS_CLOSE -1003 + +int gcns_init(); +int gcns_read_personal_data(u8 *buffer, size_t len); +int gcns_close(); + +#endif diff --git a/src/gcns/main.c b/src/gcns/main.c new file mode 100644 index 00000000..d8bd6bb2 --- /dev/null +++ b/src/gcns/main.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +#include "config.h" +#ifdef ENABLE_READLINE +#include +#include +#endif +#if !defined(_WIN32) +#include /* for htons() */ +#endif + +#include + +#include "common/compat_strlcpy.h" +#include "gcns.h" +#include "libopensc/asn1.h" +#include "libopensc/cardctl.h" +#include "libopensc/cards.h" +#include "libopensc/internal.h" +#include "libopensc/iso7816.h" +#include "libopensc/log.h" +#include "libopensc/opensc.h" +#include "tools/util.h" + +int main(int argc, char *argv[]) { + int r; + + printf("OpenSC version: %s\n", sc_get_version()); + + r = gcns_init(); + if (r != GCNS_SUCCESS) { + fprintf(stderr, "Init Error\n"); + return GCNS_INIT; + } + + u8 buffer[2048]; + r = gcns_read_personal_data(buffer, 2048); + + if (r < 0) { + fprintf(stderr, "Read personal data error\n"); + return GCNS_READ_PERSONAL_DATA; + } + + util_hex_dump_asc(stdout, buffer, r, 0); + + r = gcns_close(); + if (r != GCNS_SUCCESS) { + return GCNS_CLOSE; + } + + return GCNS_SUCCESS; +} diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am index 87969352..fe67ad01 100644 --- a/src/tools/Makefile.am +++ b/src/tools/Makefile.am @@ -29,8 +29,7 @@ noinst_HEADERS = util.h fread_to_eof.h \ noinst_PROGRAMS = sceac-example bin_PROGRAMS = opensc-tool opensc-explorer opensc-notify \ pkcs15-tool pkcs15-crypt pkcs11-tool pkcs11-register \ - cardos-tool eidenv openpgp-tool iasecc-tool egk-tool opensc-asn1 goid-tool \ - gcns + cardos-tool eidenv openpgp-tool iasecc-tool egk-tool opensc-asn1 goid-tool if ENABLE_OPENSSL bin_PROGRAMS += cryptoflex-tool pkcs15-init netkey-tool piv-tool \ westcos-tool sc-hsm-tool dnie-tool gids-tool npa-tool @@ -53,8 +52,6 @@ piv_tool_SOURCES = piv-tool.c util.c piv_tool_LDADD = $(OPTIONAL_OPENSSL_LIBS) opensc_explorer_SOURCES = opensc-explorer.c util.c opensc_explorer_LDADD = $(OPTIONAL_READLINE_LIBS) -gcns_SOURCES = gcns.c util.c -gcns_LDADD = $(OPTIONAL_READLINE_LIBS) pkcs15_tool_SOURCES = pkcs15-tool.c util.c ../pkcs11/pkcs11-display.c ../pkcs11/pkcs11-display.h pkcs15_tool_LDADD = $(OPTIONAL_OPENSSL_LIBS) pkcs11_tool_SOURCES = pkcs11-tool.c util.c diff --git a/src/tools/gcns.h b/src/tools/gcns.h deleted file mode 100644 index 854a8e58..00000000 --- a/src/tools/gcns.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef GCNS_H -#define GCNS_h - -#define GCNS_SUCCESS 0 -#define GCNS_INIT -1001 -#define GCNS_READ_PERSONAL_DATA -1002 -#define GCNS_CLOSE -1003 - -#endif