Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
.depend
*.o
*.so
hexStringTest
*.dylib
hexStringTest*
socketTest
Testing*
50 changes: 0 additions & 50 deletions de.persosim.driver.linux/Makefile

This file was deleted.

19 changes: 0 additions & 19 deletions de.persosim.driver.linux/README

This file was deleted.

14 changes: 0 additions & 14 deletions de.persosim.driver.linux/reader.conf

This file was deleted.

File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions de.persosim.driver.unix/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
cmake_minimum_required(VERSION 3.0)
project("de.persosim.driver.unix" VERSION 0.8.0)

if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
set(IS_LINUX TRUE)
endif()

if(!APPLE AND !IS_LINUX)
message(FATAL_ERROR "Currently only OS X and Linux platforms are supported")
endif()


if(IS_LINUX)
file(GLOB SRC_FILES *.c)
elseif(APPLE)
file(GLOB SRC_FILES *.c MacOSX/*.c)
endif()
list(REMOVE_ITEM SRC_FILES ${PROJECT_SOURCE_DIR}/hexStringTest.c)


# Build the library
set(LIB_NAME ifdhPersoSim)
set(CMAKE_C_FLAGS "-g -std=gnu99 -fpic")
add_definitions(-DPCSC_DEBUG=1)
#add_definitions(-DATR_DEBUG=1)
if(IS_LINUX)
include_directories(${PROJECT_SOURCE_DIR} /usr/include/PCSC)
elseif(APPLE)
include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/MacOSX)
add_definitions(-DUSE_SYSLOG -DRESPONSECODE_DEFINED_IN_WINTYPES_H)
endif()
add_library(${LIB_NAME} SHARED ${SRC_FILES})


# Create the installation files
if(IS_LINUX)
set(LIBPATH "/usr/lib/pcsc/drivers/serial/${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
elseif(APPLE)
set(BUNDLEPATH "/usr/local/libexec/SmartCardServices/drivers/${LIB_NAME}.bundle")
set(LIBPATH ${BUNDLEPATH})
set(CFBUNDLEEXECUTABLE ${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
configure_file("${PROJECT_SOURCE_DIR}/MacOSX/Info.plist.in" "${PROJECT_BINARY_DIR}/Info.plist")
endif()
configure_file("${PROJECT_SOURCE_DIR}/reader.conf.in" "${PROJECT_BINARY_DIR}/reader.conf")


# Specify installations files and locations
if(IS_LINUX)
install(TARGETS ${LIB_NAME} DESTINATION "/usr/lib/pcsc/drivers/serial/")
install(FILES ${PROJECT_BINARY_DIR}/reader.conf DESTINATION "/etc/reader.conf.d/" RENAME "${LIB_NAME}.conf")
elseif(APPLE)
install(FILES ${PROJECT_BINARY_DIR}/Info.plist DESTINATION "${BUNDLEPATH}/Contents")
install(TARGETS ${LIB_NAME} DESTINATION "${BUNDLEPATH}/Contents/MacOS")
install(FILES ${PROJECT_BINARY_DIR}/reader.conf DESTINATION "/etc/")
endif()


# Build the test (you may run the test by invoking make test)
enable_testing()
include(CTest)
add_executable(hexStringTest hexStringTest.c hexString.c)
add_test(NAME hexStringTest COMMAND ${CMAKE_BINARY_DIR}/hexStringTest)
Binary file added de.persosim.driver.unix/MacOSX/.DS_Store
Binary file not shown.
35 changes: 35 additions & 0 deletions de.persosim.driver.unix/MacOSX/Info.plist.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>@PROJECT_VERSION@</string>
<key>ifdCapabilities</key>
<string>0x00000000</string>
<key>ifdProtocolSupport</key>
<string>0x00000001</string>
<key>ifdVersionNumber</key>
<string>0x00000001</string>

<key>CFBundleExecutable</key>
<string>@CFBUNDLEEXECUTABLE@</string>

<key>ifdManufacturerString</key>
<string>Federal Office for Information Security, Germany</string>

<key>ifdProductString</key>
<string>Driver for virtual smart card reader PersoSim</string>

<key>ifdFriendlyName</key>
<string>PersoSim smart card reader</string>
</dict>
</plist>
181 changes: 181 additions & 0 deletions de.persosim.driver.unix/MacOSX/debug.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
/*
debug.c: log (or not) messages
Copyright (C) 2003-2011 Ludovic Rousseau

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include "misc.h"
#include "debug.h"

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/time.h>
#include <stdlib.h>

#ifdef USE_SYSLOG
#include <syslog.h>
#endif


#undef LOG_TO_STDERR

#ifdef LOG_TO_STDERR
#define LOG_STREAM stderr
#else
#define LOG_STREAM stdout
#endif

void log_msg(const int priority, const char *fmt, ...)
{
char debug_buffer[160]; /* up to 2 lines of 80 characters */
va_list argptr;
static struct timeval last_time = { 0, 0 };
struct timeval new_time = { 0, 0 };
struct timeval tmp;
int delta;
#ifdef USE_SYSLOG
int syslog_level;

switch(priority)
{
case PCSC_LOG_CRITICAL:
syslog_level = LOG_CRIT;
break;
case PCSC_LOG_ERROR:
syslog_level = LOG_ERR;
break;
case PCSC_LOG_INFO:
syslog_level = LOG_INFO;
break;
default:
syslog_level = LOG_DEBUG;
}
#else
const char *color_pfx = "", *color_sfx = "";
const char *time_pfx = "", *time_sfx = "";
static int initialized = 0;
static int LogDoColor = 0;

if (!initialized)
{
char *term;

initialized = 1;
term = getenv("TERM");
if (term)
{
const char *terms[] = { "linux", "xterm", "xterm-color", "Eterm", "rxvt", "rxvt-unicode", "xterm-256color" };
unsigned int i;

/* for each known color terminal */
for (i = 0; i < COUNT_OF(terms); i++)
{
/* we found a supported term? */
if (0 == strcmp(terms[i], term))
{
LogDoColor = 1;
break;
}
}
}
}

if (LogDoColor)
{
color_sfx = "\33[0m";
time_sfx = color_sfx;
time_pfx = "\33[36m"; /* Cyan */

switch (priority)
{
case PCSC_LOG_CRITICAL:
color_pfx = "\33[01;31m"; /* bright + Red */
break;

case PCSC_LOG_ERROR:
color_pfx = "\33[35m"; /* Magenta */
break;

case PCSC_LOG_INFO:
color_pfx = "\33[34m"; /* Blue */
break;

case PCSC_LOG_DEBUG:
color_pfx = ""; /* normal (black) */
color_sfx = "";
break;
}
}
#endif

gettimeofday(&new_time, NULL);
if (0 == last_time.tv_sec)
last_time = new_time;

tmp.tv_sec = new_time.tv_sec - last_time.tv_sec;
tmp.tv_usec = new_time.tv_usec - last_time.tv_usec;
if (tmp.tv_usec < 0)
{
tmp.tv_sec--;
tmp.tv_usec += 1000000;
}
if (tmp.tv_sec < 100)
delta = tmp.tv_sec * 1000000 + tmp.tv_usec;
else
delta = 99999999;

last_time = new_time;

va_start(argptr, fmt);
(void)vsnprintf(debug_buffer, sizeof debug_buffer, fmt, argptr);
va_end(argptr);

#ifdef USE_SYSLOG
syslog(syslog_level, "%.8d %s", delta, debug_buffer);
#else
(void)fprintf(LOG_STREAM, "%s%.8d%s %s%s%s\n", time_pfx, delta, time_sfx,
color_pfx, debug_buffer, color_sfx);
fflush(LOG_STREAM);
#endif
} /* log_msg */

void log_xxd(const int priority, const char *msg, const unsigned char *buffer,
const int len)
{
int i;
char *c, debug_buffer[len*3 + strlen(msg) +1];
size_t l;

(void)priority;

l = strlcpy(debug_buffer, msg, sizeof debug_buffer);
c = debug_buffer + l;

for (i = 0; i < len; ++i)
{
/* 2 hex characters, 1 space, 1 NUL : total 4 characters */
(void)snprintf(c, 4, "%02X ", buffer[i]);
c += 3;
}

#ifdef USE_SYSLOG
syslog(LOG_DEBUG, "%s", debug_buffer);
#else
(void)fprintf(LOG_STREAM, "%s\n", debug_buffer);
fflush(LOG_STREAM);
#endif
} /* log_xxd */
Loading