cardid / WebCard-IE

Smart Card Browser Plugin
http://plugin.cardid.org
MIT License
98 stars 35 forks source link

Build on Ubuntu 14.04 LTS #1

Closed stavros-zavrakas closed 9 years ago

stavros-zavrakas commented 9 years ago

Hi,

I know that officially you don't support ubuntu. I found the following issue that you wrote about this project and below you reply there is a discussion with another guy that he was trying to build it on linux. http://stackoverflow.com/questions/15807038/architectures-to-access-smart-card-from-a-generic-browser-or-how-to-bridge-the

Were you able to build it finally on linux? If yes what distribution and what version of linux did you use? I was able to build the examples of firebreath but when I am trying to build your project I have this error and the compilation breaks:

[  1%] Built target FireBreath_Cmake
[  5%] Built target boost_thread
[  6%] Built target boost_system
[ 23%] Built target ScriptingCore
[ 36%] Built target PluginCore
[ 45%] Built target NpapiCore
[ 53%] Built target WCA_PluginAuto
[ 54%] Building CXX object projects/WebCard/CMakeFiles/WebCard.dir/Reader.cpp.o
In file included from /home/svaba/projects/firebreath-dev/projects/WebCard/Reader.cpp:1:0:
/home/svaba/projects/firebreath-dev/projects/WebCard/Reader.h:9:22: fatal error: winscard.h: No such file or directory
 #include <winscard.h>
                      ^
compilation terminated.
make[2]: *** [projects/WebCard/CMakeFiles/WebCard.dir/Reader.cpp.o] Error 1
make[1]: *** [projects/WebCard/CMakeFiles/WebCard.dir/all] Error 2
make: *** [all] Error 2

Do you have any idea where to look? This is something that I found: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=666661

but I wasn't able to find a solution yet.

adricasti commented 9 years ago

Thanks a lot for helping with this stavros, the problem you see is that the winscard.h file that contains the smart card headers is missing and this is expected since this is platform specific.

In windows, those functions are in the winscard.h file that ships with the Windows SDK and you need to link the project to the winscard.lib that is also part of Windows.

In MacOS, you need to include the Frameworks.PCSC to be able to use the pcsclite version of winscard.h and link to it during compilation. You will see that in the code there are #ifdef directives in places that refer to those headers and for the moment I've only done it for Windows and Mac.

What I would suggest, is you check the code from the author of pcsclite library and also make sure you can compile that sample in Linux. I think that should give you the pointer to what flags to include in the project. I'd be very happy to accept a pull request to build in Linux. http://ludovicrousseau.blogspot.com/2010/04/pcsc-sample-in-c.html

Thanks for your contribution to the project!

stavros-zavrakas commented 9 years ago

Hi cheburashka,

I tried the example of the link that you gave of the author of the pcsclite library. I tried to compile but the makefile had a problem. It is just a simple fix. The errors that I had was the following (I write them just for reference. Maybe someone else has the same problem):

cc -pthread -I/usr/include/PCSC      pcsc.c   -o pcsc
/tmp/cc40dt7g.o: In function `main':
pcsc.c:(.text+0xba): undefined reference to `SCardEstablishContext'
pcsc.c:(.text+0xda): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x123): undefined reference to `SCardListReaders'
pcsc.c:(.text+0x143): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x1ac): undefined reference to `SCardConnect'
pcsc.c:(.text+0x1cc): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x204): undefined reference to `g_rgSCardT0Pci'
pcsc.c:(.text+0x20b): undefined reference to `g_rgSCardT0Pci'
pcsc.c:(.text+0x222): undefined reference to `g_rgSCardT1Pci'
pcsc.c:(.text+0x229): undefined reference to `g_rgSCardT1Pci'
pcsc.c:(.text+0x280): undefined reference to `SCardTransmit'
pcsc.c:(.text+0x2a0): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x364): undefined reference to `SCardTransmit'
pcsc.c:(.text+0x384): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x414): undefined reference to `SCardDisconnect'
pcsc.c:(.text+0x434): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x469): undefined reference to `SCardFreeMemory'
pcsc.c:(.text+0x489): undefined reference to `pcsc_stringify_error'
pcsc.c:(.text+0x4b1): undefined reference to `SCardReleaseContext'
pcsc.c:(.text+0x4d1): undefined reference to `pcsc_stringify_error'
collect2: error: ld returned 1 exit status

It is just a simple fix on the makefile. Here is a working version of the makefile:

# Linux
PCSC_CFLAGS := $(shell pkg-config --cflags libpcsclite)
LDLIBS := $(shell pkg-config --libs libpcsclite)

# Mac OS X
#PCSC_CFLAGS := -framework PCSC

CFLAGS += $(PCSC_CFLAGS)

pcsc: pcsc.c

clean:
    rm -f pcsc

Because I start reading about firebreath and how to create a plugin few days ago, what should be the next step? Should I fix the makefile (cmake) of your plugin that lives under the WebCard/X11? Is it possible that this is the guide that I have to follow? http://www.firebreath.org/display/documentation/Using+Libraries

I think that somehow I must give the right path of the PCSC library so that it will be able to resolve and link it in the compilation.

Thanks in advance!!

stavros-zavrakas commented 9 years ago

Just an update.

(STEP 1) I think that I resolved the linking of the PCSB library by adding in the X11/projectDef.cmake makefile this line: include_directories(/usr/include/PCSC)

(I put it above the target_link_libraries command).

Then trying to compile I had the following errors:

svaba@svaba:~/projects/firebreath-dev/build$ make
[  0%] Built target FireBreath_Cmake
[  4%] Built target boost_thread
[  5%] Built target boost_system
[ 21%] Built target ScriptingCore
[ 33%] Built target PluginCore
[ 42%] Built target NpapiCore
[ 48%] Built target STA_PluginAuto
[ 51%] Built target svaba
[ 57%] Built target WCA_PluginAuto
Scanning dependencies of target WebCard
[ 58%] Building CXX object projects/WebCard/CMakeFiles/WebCard.dir/WebCardAPI.cpp.o
In file included from /home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp:13:0:
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.h:88:2: error: ‘LPSCARD_READERSTATE_A’ does not name a type
  LPSCARD_READERSTATE_A m_rgReaderStates;
  ^
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp: In member function ‘void WebCardAPI::InitializeReaders()’:
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp:52:2: error: ‘m_rgReaderStates’ was not declared in this scope
  m_rgReaderStates = NULL;
  ^
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp:77:24: error: ‘LPSCARD_READERSTATE_A’ was not declared in this scope
    m_rgReaderStates = (LPSCARD_READERSTATE_A)realloc((LPVOID)m_rgReaderStates, (m_cReaders + 1) * sizeof(SCARD_READERSTATE_A));
                        ^
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp:77:46: error: expected ‘;’ before ‘realloc’
    m_rgReaderStates = (LPSCARD_READERSTATE_A)realloc((LPVOID)m_rgReaderStates, (m_cReaders + 1) * sizeof(SCARD_READERSTATE_A));
                                              ^
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp: In member function ‘void WebCardAPI::ReleaseReaders()’:
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp:115:7: error: ‘m_rgReaderStates’ was not declared in this scope
  free(m_rgReaderStates);
       ^
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp: In member function ‘void WebCardAPI::threadRun()’:
/home/svaba/projects/firebreath-dev/projects/WebCard/WebCardAPI.cpp:132:53: error: ‘m_rgReaderStates’ was not declared in this scope
   lRet = SCardGetStatusChange(m_hContext, INFINITE, m_rgReaderStates, m_cReaders);
                                                     ^
make[2]: *** [projects/WebCard/CMakeFiles/WebCard.dir/WebCardAPI.cpp.o] Error 1
make[1]: *** [projects/WebCard/CMakeFiles/WebCard.dir/all] Error 2
make: *** [all] Error 2

(STEP 2) It seems that in the PCSB ubuntu library is not defined the _LPSCARD_READERSTATEA type and we need the _LPSCARDREADERSTATE type. I did just a simple change just to bypass this errors. In the WebCartAPI.h line 87 I replaced the line: LPSCARD_READERSTATE_A m_rgReaderStates; with
LPSCARD_READERSTATE m_rgReaderStates

I did the same WebCartAPI.cpp in line 76. Replaced the: m_rgReaderStates = (LPSCARD_READERSTATE_A)realloc((LPVOID)m_rgReaderStates, (m_cReaders + 1) * sizeof(SCARD_READERSTATE_A)); with m_rgReaderStates = (LPSCARD_READERSTATE)realloc((LPVOID)m_rgReaderStates, (m_cReaders + 1) * sizeof(SCARD_READERSTATE));

Then trying to compile again I get the following errors:

svaba@svaba:~/projects/firebreath-dev/build$ make
[  0%] Built target FireBreath_Cmake
[  4%] Built target boost_thread
[  5%] Built target boost_system
[ 21%] Built target ScriptingCore
[ 33%] Built target PluginCore
[ 42%] Built target NpapiCore
[ 48%] Built target STA_PluginAuto
[ 51%] Built target svaba
[ 57%] Built target WCA_PluginAuto
Scanning dependencies of target WebCard
[ 58%] Building CXX object projects/WebCard/CMakeFiles/WebCard.dir/WebCardAPI.cpp.o
[ 59%] Building CXX object projects/WebCard/CMakeFiles/WebCard.dir/WebCard.cpp.o
Linking CXX shared library ../../bin/WebCard/npWebCard.so
CMakeFiles/WebCard.dir/Reader.cpp.o: In function `Reader::connect(unsigned int)':
Reader.cpp:(.text+0x67): undefined reference to `SCardConnect'
Reader.cpp:(.text+0x8a): undefined reference to `SCardBeginTransaction'
CMakeFiles/WebCard.dir/Reader.cpp.o: In function `Reader::transcieve(FB::variant const&)':
Reader.cpp:(.text+0x36d): undefined reference to `g_rgSCardT0Pci'
Reader.cpp:(.text+0x376): undefined reference to `g_rgSCardT1Pci'
Reader.cpp:(.text+0x3b5): undefined reference to `SCardTransmit'
Reader.cpp:(.text+0x5be): undefined reference to `g_rgSCardT0Pci'
Reader.cpp:(.text+0x5c7): undefined reference to `g_rgSCardT1Pci'
Reader.cpp:(.text+0x606): undefined reference to `SCardTransmit'
CMakeFiles/WebCard.dir/Reader.cpp.o: In function `Reader::disconnect()':
Reader.cpp:(.text+0x89a): undefined reference to `SCardEndTransaction'
Reader.cpp:(.text+0x8b2): undefined reference to `SCardDisconnect'
CMakeFiles/WebCard.dir/WebCardAPI.cpp.o: In function `WebCardAPI::InitializeReaders()':
WebCardAPI.cpp:(.text+0x2a6): undefined reference to `SCardEstablishContext'
WebCardAPI.cpp:(.text+0x2ee): undefined reference to `SCardListReaders'
CMakeFiles/WebCard.dir/WebCardAPI.cpp.o: In function `WebCardAPI::ReleaseReaders()':
WebCardAPI.cpp:(.text+0x77b): undefined reference to `SCardCancel'
WebCardAPI.cpp:(.text+0x7c1): undefined reference to `SCardFreeMemory'
WebCardAPI.cpp:(.text+0x7d8): undefined reference to `SCardReleaseContext'
CMakeFiles/WebCard.dir/WebCardAPI.cpp.o: In function `WebCardAPI::threadRun()':
WebCardAPI.cpp:(.text+0x85b): undefined reference to `SCardGetStatusChange'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/WebCard/npWebCard.so] Error 1
make[1]: *** [projects/WebCard/CMakeFiles/WebCard.dir/all] Error 2
make: *** [all] Error 2

Do you have any clue if I am on a good way? Is it possible that I didn't link something correct in the STEP1? There is a variable that you are checking #ifdef _WINDOWS. I have no clue who is setting this variable. Is it possible that there is a variable to understand if we are in a _LINUX environment so that I can fix the STEP2 properly?

stavros-zavrakas commented 9 years ago

Done! (Almost)

It was a problem in the linking the final errors that I had. The target_link_libraries in the makefile should be like that:

#/**********************************************************\ 
# Auto-generated X11 project definition file for the
# WebCard project
#\**********************************************************/

# X11 template platform definition CMake file
# Included from ../CMakeLists.txt

# remember that the current source dir is the project root; this file is in X11/
file (GLOB PLATFORM RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
    X11/[^.]*.cpp
    X11/[^.]*.h
    X11/[^.]*.cmake
    )

SOURCE_GROUP(X11 FILES ${PLATFORM})

# use this to add preprocessor definitions
add_definitions(
)

set (SOURCES
    ${SOURCES}
    ${PLATFORM}
    )

add_x11_plugin(${PROJECT_NAME} SOURCES)

include_directories(/usr/include/PCSC)

# add library dependencies here; leave ${PLUGIN_INTERNAL_DEPS} there unless you know what you're doing!
target_link_libraries(${PROJECT_NAME}
    ${PLUGIN_INTERNAL_DEPS}
    ${PCSCLIB_FRAMEWORK}
    )

Now it is able to compile without errors. :)

If you are able to help me with the _WINDOWS variable that I asked above I will be able to fork and to create a proper solution for linux machines. :)

Sorry for the spamming.

adricasti commented 9 years ago

Hi Stavros, I think your pull request was wrong because you were not using find_library to find the pcsclite library before trying to add it. But thanks to your effort I did some testing locally and built the plugin. It did not work in my computer that is an Ubuntu 14.10 virtual machine with an SCM3500 reader, but I hope you have more luck. You can pull or clone the repository again now it includes the changes to build in Linux. Thanks again for your contribution.