frankmorgner / vsmartcard

umbrella project for emulation of smart card readers or smart cards
http://frankmorgner.github.io/vsmartcard/
704 stars 201 forks source link

Compiling for exe #88

Closed joaoguariglia closed 6 years ago

joaoguariglia commented 7 years ago

Hello good afternoon! I'm doing the compile for windows from vicc.py, follow the steps:

C: > pip install pyinstaller C: > pyinstaller --onefile vicc.py

It generates this log:

671 INFO: PyInstaller: 3.2 671 INFO: Python: 2.7.12 671 INFO: Platform: Windows-10-10.0.14393 687 INFO: wrote C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc\vicc.spec 687 INFO: UPX is not available. 687 INFO: Extending PYTHONPATH with paths ['C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc', 'C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc'] 687 INFO: checking Analysis 687 INFO: Building Analysis because out00-Analysis.toc is non existent 687 INFO: Initializing module dependency graph... 703 INFO: Initializing module graph hooks... 766 INFO: running Analysis out00-Analysis.toc 937 INFO: Adding Microsoft.VC90.CRT to dependent assemblies of final executable required by c:\python27\python.exe 8265 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest 8296 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9247_none_acd10521e1dac77d.manifest 8422 INFO: Searching for assembly amd64_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.9247_none ... 8422 INFO: Found manifest C:\Windows\WinSxS\Manifests\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9247_none_08e394a1a83e212f.manifest 8422 INFO: Searching for file msvcr90.dll 8422 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9247_none_08e394a1a83e212f\msvcr90.dll 8422 INFO: Searching for file msvcp90.dll 8437 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9247_none_08e394a1a83e212f\msvcp90.dll 8437 INFO: Searching for file msvcm90.dll 8437 INFO: Found file C:\Windows\WinSxS\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9247_none_08e394a1a83e212f\msvcm90.dll 8546 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.1_none_3da38fdebd0e6822.manifest 8546 INFO: Found C:\Windows\WinSxS\Manifests\amd64_policy.9.0.microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9247_none_acd10521e1dac77d.manifest 8546 INFO: Adding redirect Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 13891 INFO: Caching module hooks... 13906 INFO: Analyzing C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc\vicc.py 18453 INFO: Processing pre-find module path hook distutils 18765 INFO: Processing pre-safe import module hook _xmlplus 22687 INFO: Loading module hooks... 22687 INFO: Loading module hook "hook-distutils.py"... 22687 INFO: Loading module hook "hook-sysconfig.py"... 22687 INFO: Loading module hook "hook-xml.py"... 22796 INFO: Loading module hook "hook-httplib.py"... 22796 INFO: Loading module hook "hook-_tkinter.py"... 23765 INFO: checking Tree 23765 INFO: Building Tree because out00-Tree.toc is non existent 23765 INFO: Building Tree out00-Tree.toc 23983 INFO: checking Tree 23983 INFO: Building Tree because out01-Tree.toc is non existent 23983 INFO: Building Tree out01-Tree.toc 24016 INFO: Loading module hook "hook-pkg_resources.py"... 24109 INFO: Processing pre-safe import module hook win32com 24484 INFO: Loading module hook "hook-pywintypes.py"... 24765 INFO: Loading module hook "hook-encodings.py"... 25938 INFO: Loading module hook "hook-win32com.py"... 26359 INFO: Loading module hook "hook-pythoncom.py"... 29110 INFO: checking Tree 29110 INFO: Building Tree because out02-Tree.toc is non existent 29124 INFO: Building Tree out02-Tree.toc 29124 INFO: Looking for ctypes DLLs 29187 INFO: Analyzing run-time hooks ... 29187 INFO: Including run-time hook 'pyi_rth__tkinter.py' 29187 INFO: Including run-time hook 'pyi_rth_pkgres.py' 29203 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py' 29219 INFO: Looking for dynamic libraries 39265 INFO: Searching for assembly amd64_Microsoft.VC90.MFC_1fc8b3b9a1e18e3b_9.0.21022.8_none ... 39281 INFO: Found manifest c:\python27\lib\site-packages\Pythonwin\Microsoft.VC90.MFC.manifest 39281 INFO: Searching for file mfc90.dll 39281 INFO: Found file c:\python27\lib\site-packages\Pythonwin\mfc90.dll 39296 INFO: Searching for file mfc90u.dll 39296 INFO: Found file c:\python27\lib\site-packages\Pythonwin\mfc90u.dll 39296 INFO: Searching for file mfcm90.dll 39296 INFO: Found file c:\python27\lib\site-packages\Pythonwin\mfcm90.dll 39296 INFO: Searching for file mfcm90u.dll 39296 INFO: Found file c:\python27\lib\site-packages\Pythonwin\mfcm90u.dll 39374 INFO: Adding redirect Microsoft.VC90.MFC version (9, 0, 21022, 8) -> (9, 0, 21022, 8) 50000 WARNING: lib not found: MSVCR120.dll dependency of C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc_eac.pyd 55265 INFO: Looking for eggs 55265 INFO: Using Python library C:\Windows\system32\python27.dll 55281 INFO: Found binding redirects: [BindingRedirect(name=u'Microsoft.VC90.MFC', language=None, arch=u'amd64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 21022, 8), publicKeyToken=u'1fc8b3b9a1e18e3b'), BindingRedirect(name=u'Microsoft.VC90.CRT', language=None, arch=u'amd64', oldVersion=(9, 0, 21022, 8), newVersion=(9, 0, 30729, 9247), publicKeyToken=u'1fc8b3b9a1e18e3b')] 55296 INFO: Warnings written to C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc\build\vicc\warnvicc.txt 55578 INFO: checking PYZ 55578 INFO: Building PYZ because out00-PYZ.toc is non existent 55578 INFO: Building PYZ (ZlibArchive) C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc\build\vicc\out00-PYZ.pyz 56672 INFO: checking PKG 56672 INFO: Building PKG because out00-PKG.toc is non existent 56672 INFO: Building PKG (CArchive) out00-PKG.pkg 56906 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 56922 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\python27.dll 56937 INFO: Updating resource type 24 name 2 language 1033 57078 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57078 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_hashlib.pyd 57078 INFO: Updating resource type 24 name 2 language 1033 57140 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57140 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_ctypes.pyd 57140 INFO: Updating resource type 24 name 2 language 1033 57218 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57218 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_ssl.pyd 57218 INFO: Updating resource type 24 name 2 language 1033 57297 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57297 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_socket.pyd 57297 INFO: Updating resource type 24 name 2 language 1033 57343 INFO: Redirecting Microsoft.VC90.MFC version (9, 0, 21022, 8) -> (9, 0, 21022, 8) 57343 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57343 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\win32ui.pyd 57343 INFO: Updating resource type 24 name 2 language 1033 57468 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57468 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\bz2.pyd 57468 INFO: Updating resource type 24 name 2 language 1033 57500 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57500 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\select.pyd 57500 INFO: Updating resource type 24 name 2 language 1033 57593 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57593 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\pyexpat.pyd 57610 INFO: Updating resource type 24 name 2 language 1033 57688 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57703 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\unicodedata.pyd 57703 INFO: Updating resource type 24 name 2 language 1033 57750 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57750 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_bsddb.pyd 57750 INFO: Updating resource type 24 name 2 language 1033 57797 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57812 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_testcapi.pyd 57812 INFO: Updating resource type 24 name 2 language 1033 57844 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 57844 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_tkinter.pyd 57860 INFO: Updating resource type 24 name 2 language 1033 57922 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit_eac.pyd 57922 INFO: Updating resource type 24 name 2 language 1033 58047 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\mfc90.dll 58062 INFO: Updating resource type 24 name 1000 language 1033 62344 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\mfc90u.dll 62344 INFO: Updating resource type 24 name 1000 language 1033 63015 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 63015 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\tcl85.dll 63015 INFO: Updating resource type 24 name 2 language 1033 63109 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\tk85.dll 63109 INFO: Updating resource type 24 name 1 language 1033 63140 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 63157 INFO: Updating manifest in C:\Users\suporte\AppData\Roaming\pyinstaller\bincache00_py27_64bit\tk85.dll 63157 INFO: Updating resource type 24 name 2 language 1033 63296 INFO: Redirecting Microsoft.VC90.CRT version (9, 0, 21022, 8) -> (9, 0, 30729, 9247) 74671 INFO: Bootloader c:\python27\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe 74671 INFO: checking EXE 74687 INFO: Building EXE because out00-EXE.toc is non existent 74687 INFO: Building EXE from out00-EXE.toc 74687 INFO: Appending archive to EXE C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc\dist\vicc.exe

Then I enter the folder where the exe is, when I run the following error:

C:\Users\suporte\Desktop\virtualsmartcard-0.7_win32\vpicc\dist>vicc.exe -vvvvv --type relay

Traceback (most recent call last): File "vicc.py", line 104, in File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "virtualsmartcard\VirtualSmartcard.py", line 24, in File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "virtualsmartcard\CardGenerator.py", line 26, in File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "virtualsmartcard\CryptoUtils.py", line 20, in File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "build\bdist.win-amd64\egg\Crypto\Cipher\DES3.py", line 67, in File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module exec(bytecode, module.dict) File "build\bdist.win-amd64\egg\Crypto\Cipher_DES3.py", line 7, in File "build\bdist.win-amd64\egg\Crypto\Cipher_DES3.py", line 6, in bootstrap ImportError: DLL load failed: Could not find the specified module. Failed to execute script vicc

Just for the right information, follow the step-by-step instructions as I promised to set up this scenario:

1-) Download Python 2.7.12 (be careful to always choose by 64bit)     - Set the PATH option in Windows     https://www.python.org/downloads/windows/     [ Execute as administrator ]     Reboot - PC

2-) [Run as Administrator]     C: > python -m pip install --upgrade pip     C: > pip install virtualenv

3-) Microsoft Visual C ++ Compiler for Python 2.7     https://www.microsoft.com/en-us/download/details.aspx?id=44266     Reboot - PC

4-) [Run as Administrator]     C: > pip install -U setuptools     C: > easy_install PyCrypto     C: > pip install pyreadline

5-) Downloading Swig in http://www.swig.org/     -> Create a folder called [swig] C: \ Python27 \ Lib \ site-packages \ swig \ -> Unzip the files the -> You have to set this variable in Windows pointed to this folder C: \ Python27 \ Lib \ site-packages \ swig \     -> In the Environment Variables section -> [PATH] -> [Edit] -> [New] -> Windows reboot

6-) C: > pip install pyscard      C: > pip install --egg M2CryptoWin64      C: > python.exe vicc.py -vvvvv --type relay

Compilation Test

7-) C: > pip install pyinstaller

S.O Windows 10 64

frankmorgner commented 7 years ago

Interesting, I never tested this. Thanks for the great step-by-step guide. I hope, I'll find time to try this soon.

Your stacktrace shows an error that's within a dependent python module, not within one of the virtual smart card modules. Thus, I conclude that your setup is missing some bits.

Have you tried the commandline options suggested in http://stackoverflow.com/questions/32457341/pyinstaller-and-onefile-build-causes-error-loading-python-dll-error-code-14001? There is also some information about debugging this kind of problems here https://github.com/pyinstaller/pyinstaller/issues/1291. You could also try the dependency walker to check which dll is missing http://www.dependencywalker.com/.

joaoguariglia commented 7 years ago

Cool, I'll try and tell you

joaoguariglia commented 7 years ago

Hello good Morning! I tried in several ways to compile for exe, even with the mentioned tips but nothing worked, I said I do not understand anything about python, programming alias, just curious, my area is infrastructure, if you have a little time to reproduce those steps And help me with this error I'd be grateful, I'm putting together a vpicc client which we can then insert into your site for the new ones if you have interest.

joaoguariglia commented 7 years ago

screenshot Hello .. Good evening, To not stay still I made a client in Batch in Windows, because I know a little bit about Batch, it tests on your Windows to see if it works, the source code is inside too. Test done in Windows 10 64bit

https://1drv.ms/u/s!AnFFaoMvX5FCkGh8mYA8yr-Mb404

If you pass me or implement errorlevel that windows can interpret I think I can mount a service on windows to run in the background and stay monitored when the connection drops and so reconnect again.

frankmorgner commented 7 years ago

I hope to get my hands on a Windows machine next week for trying out...

The Windows service is a nice idea! If I'm not mistaken this would even allow windows logon with the virtual card. Maybe you should also look into Windows' builtin virtual smart card that's based on using a key in a TPM. There are several guides available on how to set this up.

The debug level can be chosen by adding -v (multiple times) to the command line. It will be written to stdout.

joaoguariglia commented 7 years ago

1-) Windows logon, ummm I do not understand, the service runs with the SYSTEM account, right? 2-) I work with desktop virtualization if you want I can leave a new windows 10 VM in the cloud for you to do some tests, the access would be via RDP then I will pass the credentials and you do whatever you want. 3-) I have another question, does the VPCD run on windows doing the reverse? SmartCard - >> Ubuntu (vicc) - >>> Windows - >> VPCD I mounted the BixVReader driver in Windows what would be the next step?

frankmorgner commented 7 years ago
  1. If you run vicc as system service connecting to localhost, this will make the card available even when you're logging out. So the card will be present in the local reader for windows logon. However, thinking about this, this only replaces your password with a PIN, which isn't a big difference.
  2. I have a machine ready with python and dependencies, so I hope I can check your build recipe quickly next week.
  3. Yes, vpcd is available on Windows, Linux and Mac. You can run the virtual smartcard (vicc) on either platform and connect to the virtual driver (vpcd) on either platform. Your next step would be to run vicc --hostname IP_OF_WINDOWS_VPCD. If you want to relay a real card you need to add --type=relay, which would be equivalent of using pcsc-relay --emulator=vpcd --vpcd-hostname=IP_OF_WINDOWS_VPCD --connector=pcsc.
frankmorgner commented 7 years ago

Isn't the third point what you did in https://github.com/frankmorgner/vsmartcard/issues/86?

frankmorgner commented 6 years ago

@joaoguariglia thanks for your detailed description for compiling to an executable. I finally had the chance to verify the procedure on a 32 bit Windows. Note that although I didn't use swig or M2Crypto, I successfully tested vicc.exe --type relay (The problem may still be present, but due to bca53f92f18a5e41fdfcf86281b37f60d90b8c5a it's limited to the ePassport/Cyberflex emulation, where it's actually needed). Anyway, I think, for Windows users this is still a gain to quickly get started and I'll include the executable in the next relese.

joaoguariglia commented 6 years ago

Hello Frank, thanks for the feedback, after this Beta I have already developed a GUI and several options, what I did was create a windows tunnel for Linux, I bought an OrangePi Zero and the cards are remote, then with more time I show you , the product is ready for use, I tested it in several companies.

frankmorgner commented 6 years ago

sounds nice, I'm excited to have a look!

Note that if you're only using the PC/SC relaying, you should consider using pcsc-relay.exe, which has a much lower footprint...