Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement - working implementation on Windows10 with Visual Studio (...and Cygwin also) #33

Merged
merged 8 commits into from
Feb 15, 2019

Conversation

keldonin
Copy link
Contributor

@keldonin keldonin commented Feb 8, 2019

Hi danni, it's me again 😉

I my previous PR, I claimed that it was working on the Windows platform. I had to revise this assertion; it indeed compiles (on Cygwin), but it does not work properly.

After digging, it is possible to make it work with Cygwin 32 bits, by adding a #pragma pack(1) before including the PKCS#11 header files; the situation is different with Cygwin 64 bits, as GCC sizeof(CK_ULONG) on this platform is different than on the 32 bits version, resulting in discrepancy for every structure. Since most of the PKCS#11 DLLs are built from MSVC, the interest is limited.

Actually, the #pragma pack() directive is mandatory on Windows platform, according to the PKCS#11 documentation.

I decided therefore to add the code needed to compile with MSVC. It uses the native Windows calls. It took me several changes:

  • I had to remove the defines you set in setup.py and create a new header file that contains the pragmas
  • there is also a new _mswin.pxd file that contains the definitions for Windows.
  • I also had to use a couple of IF Cython precompiler directives.

I have tested on the Windows platform against SoftHSMv2 for Windows, and it passes most of the tests (see result - two tests have failed because of an issue with subprocess.Popen() on Windows).

I hope you'll enjoy it. This PR together with the previous should solve issues #12 and #27, IMO.

Eric

C:\Users\User\python-pkcs11>python setup.py test
running test
running egg_info
writing python_pkcs11.egg-info\PKG-INFO
writing dependency_links to python_pkcs11.egg-info\dependency_links.txt
writing requirements to python_pkcs11.egg-info\requires.txt
writing top-level names to python_pkcs11.egg-info\top_level.txt
writing manifest file 'python_pkcs11.egg-info\SOURCES.txt'
running build_ext
skipping 'pkcs11\_pkcs11.c' Cython extension (up-to-date)
copying build\lib.win-amd64-3.7\pkcs11\_pkcs11.cp37-win_amd64.pyd -> pkcs11
test_encrypt (tests.test_aes.AESTests) ... ok
test_encrypt_big_string (tests.test_aes.AESTests) ... ok
test_encrypt_stream (tests.test_aes.AESTests) ... ok
test_encrypt_whacky_sizes (tests.test_aes.AESTests) ... ok
test_sign (tests.test_aes.AESTests) ... skipped 'Requires Mechanism.AES_MAC'
test_sign_stream (tests.test_aes.AESTests) ... skipped 'Requires Mechanism.AES_MAC'
test_wrap (tests.test_aes.AESTests) ... ok
test_encrypt_des2 (tests.test_des.DESTests) ... ok
test_encrypt_des3 (tests.test_des.DESTests) ... ok
test_generate_des2_key (tests.test_des.DESTests) ... ok
test_generate_des3_key (tests.test_des.DESTests) ... ok
test_derive_key (tests.test_dh.DHTests) ... ok
test_generate_params (tests.test_dh.DHTests) ... ok
test_load_params (tests.test_dh.DHTests) ... ok
test_digest (tests.test_digest.DigestTests) ... ok
test_digest_generator (tests.test_digest.DigestTests) ... ok
test_digest_key (tests.test_digest.DigestTests) ... ok
test_digest_key_data (tests.test_digest.DigestTests) ... ok
test_generate_keypair_and_sign (tests.test_dsa.DSATests) ... ok
test_generate_keypair_directly (tests.test_dsa.DSATests) ... ok
test_generate_params (tests.test_dsa.DSATests) ... ok
test_derive_key (tests.test_ecc.ECCTests) ... ok
test_import_key_named_curve (tests.test_ecc.ECCTests) ... skipped 'Requires Mechanism.ECDSA_SHA1'
test_import_key_pair (tests.test_ecc.ECCTests) ... ok
test_import_key_params (tests.test_ecc.ECCTests) ... ok
test_sign_ecdsa (tests.test_ecc.ECCTests) ... ok
test_close_iterators (tests.test_iterators.IteratorTests) ... expected failure
test_partial_decrypt (tests.test_iterators.IteratorTests) ... ok
test_ecdh (tests.test_public_key_external.ExternalPublicKeyTests) ... ok
test_ecdsa (tests.test_public_key_external.ExternalPublicKeyTests) ... skipped 'Requires Mechanism.ECDSA_SHA1'
test_rsa (tests.test_public_key_external.ExternalPublicKeyTests) ... ok
test_terrible_hybrid_file_encryption_app (tests.test_public_key_external.ExternalPublicKeyTests) ... ok
test_encrypt_oaep (tests.test_rsa.RSATests) ... ok
test_encrypt_too_much_data (tests.test_rsa.RSATests) ... ok
test_key_wrap (tests.test_rsa.RSATests) ... ok
test_sign_default (tests.test_rsa.RSATests) ... ok
test_sign_pkcs_v15 (tests.test_rsa.RSATests) ... ok
test_sign_pss (tests.test_rsa.RSATests) ... ok
test_sign_stream (tests.test_rsa.RSATests) ... ok
test_copy_object (tests.test_sessions.SessionTests) ... skipped 'SoftHSMv2 only'
test_create_object (tests.test_sessions.SessionTests) ... ok
test_destroy_object (tests.test_sessions.SessionTests) ... ok
test_generate_key (tests.test_sessions.SessionTests) ... ok
test_generate_keypair (tests.test_sessions.SessionTests) ... ok
test_generate_random (tests.test_sessions.SessionTests) ... ok
test_get_key (tests.test_sessions.SessionTests) ... ok
test_get_key_not_found (tests.test_sessions.SessionTests) ... ok
test_get_key_vague (tests.test_sessions.SessionTests) ... ok
test_get_objects (tests.test_sessions.SessionTests) ... ok
test_open_session (tests.test_sessions.SessionTests) ... ok
test_open_session_and_login_so (tests.test_sessions.SessionTests) ... skipped 'SoftHSMv2 only'
test_open_session_and_login_user (tests.test_sessions.SessionTests) ... ok
test_seed_random (tests.test_sessions.SessionTests) ... ok
test_double_initialise (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_double_initialise_different_libs (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_mechanism_info (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_mechanism_info_ec (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_mechanisms (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_slots (tests.test_slots_and_tokens.SlotsAndTokensTests) ... skipped 'SoftHSMv2 only'
test_get_token (tests.test_slots_and_tokens.SlotsAndTokensTests) ... skipped 'SoftHSMv2 only'
test_get_tokens (tests.test_slots_and_tokens.SlotsAndTokensTests) ... skipped 'SoftHSMv2 only'
test_concurrency (tests.test_threading.ThreadingTests) ... ok
test_import_ca_certificate (tests.test_x509.X509Tests) ... ok
test_import_ca_certificate_easy (tests.test_x509.X509Tests) ... ok
test_self_sign_certificate (tests.test_x509.X509Tests) ... C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py:664: ResourceWarning: unclosed file <_io.BufferedReader name=5>
  _cleanup()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
ERROR
test_sign_csr (tests.test_x509.X509Tests) ... ERROR
test_verify_certificate_dsa (tests.test_x509.X509Tests) ... ok
test_verify_certificate_ecdsa (tests.test_x509.X509Tests) ... skipped 'Requires Mechanism.ECDSA_SHA1'
test_verify_certificate_rsa (tests.test_x509.X509Tests) ... ok

======================================================================
ERROR: test_self_sign_certificate (tests.test_x509.X509Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\user\python-pkcs11\tests\__init__.py", line 73, in wrapper
    return func(self, *args, **kwargs)
  File "c:\users\user\python-pkcs11\tests\test_x509.py", line 217, in test_self_sign_certificate
    stdout=subprocess.DEVNULL) as proc:
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

======================================================================
ERROR: test_sign_csr (tests.test_x509.X509Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "c:\users\user\python-pkcs11\tests\__init__.py", line 73, in wrapper
    return func(self, *args, **kwargs)
  File "c:\users\user\python-pkcs11\tests\test_x509.py", line 262, in test_sign_csr
    stdout=subprocess.DEVNULL) as proc:
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable

----------------------------------------------------------------------
Ran 69 tests in 1.625s

FAILED (errors=2, skipped=10, expected failures=1)
Test failed: <unittest.runner.TextTestResult run=69 errors=2 failures=0>
error: Test failed: <unittest.runner.TextTestResult run=69 errors=2 failures=0>

Copy link
Collaborator

@danni danni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, really exciting stuff. Couple of questions and minor comments and we can get this merged.

IF UNAME_SYSNAME == "Windows":
from . cimport _mswin as mswin
ELSE:
from posix cimport dlfcn
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised no one has wrapped this actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure to get your point here (sorry, I'm not a native speaker). Could you clarify please?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised there's not a cross-platform library open for Cython.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh OK. That would be great indeed! I must admit I didn't look for it. If not existing, this is perhaps opportunity for a new project...

dlfcn.dlclose(self._handle)


IF UNAME_SYSNAME == "Windows":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this go in your mswin.pxd?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming you mean the cdef _winerrormsg() code section surrounded with the IF statement.
I have a personal preference to put only headers declaration into .pxd files; Cython however allows code sections into these files. Fair enough, I'll move this as per request.

setup.py Outdated
from platform import system

# if compiling using MSVC, we need to add user32 library
libraries = ('user32',) if system() == 'Windows' else ()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid ternary operators.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough.

#pragma warning "Cygwin 64 bits build will only work with Cygwin64-compiled PKCS#11 modules"
#endif

#define CK_PTR *
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I understood these defines were different on the different platforms. Is that not the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short answer: not really...

Long one - take a deep breath:
PKCS#11 was originally designed with Windows platform in mind. ( and, by the time, when 16 bits binaries was still the norm, presumably). You had the ability to define many kinds of pointers ( e.g. far pointers vs short pointers). Hence the assumption these defines could change.
If we consider Today's platforms share, you mainly have Windows and unix ish ones. Incidentally, the same defines apply to all platform, for all the defines.

As an evidence, feel free to checkout this code on Github: https://github.com/Mastercard/pkcs11-tools/blob/master/include/cryptoki/cryptoki.h , from my project (making free advertisement, I recognize 😉 ) that compile nicely on Windows(cross-compiled), Linux, Freebsd, AIX, Solaris, MacOS,... All sharing the same header file.

Actually, PKCS#11 screwed up with one thing: defining CK_ULONG as unsigned int long, which yields a 64 bits wide integer on unix ish patforms. This is not an issue when the PKCS#11 drivers are all compiled through the same compiler that we use; it leads to discrepancies when e.g. you start using Cygwin64 - which implements gcc 64 bits like on a unix platform, and try to interface that code with MSVC-compiled PKCS#11 DLLs, where sizeof(unsigned long int) is always 32 bits, irrespective of the processor bit width.

Hope this answers your question.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that detailed answer.

@danni
Copy link
Collaborator

danni commented Feb 10, 2019

Are the tests failing because it can't find openssl? We can probably add a decorator to @skip if openssl is not found.

It looks like the the Is class used for decorating some tests is broken on Windows. There's a few tests being skipped with skipped 'SoftHSMv2 only'. I'm guessing this is because it hard-codes the library name, which is different on Windows.

@keldonin
Copy link
Contributor Author

I am currently abroad, and don't have the ability to progress on this, this week. Thanks for the questions/comments, I'll work this out when I'm back and push an update to the PR.

@keldonin
Copy link
Contributor Author

keldonin commented Feb 14, 2019

There you go. For testing, I took the freedom to enhance a few side items:

  • environment variables for SO PIN (instead of hard-coded value), and defaulting to user PIN
  • detection of a library is now multi-platform (Windows, MacOS, linux)
  • detection for openssl binary, and skipping these tests if not found
  • path to openssl can be specified as an environment variable, if not in the path

Here is the result: (using softHSM2)

C:\Users\User\python-pkcs11>set
...
OPENSSL_PATH=C:\OpenSSL-Win64\bin
...
PKCS11_MODULE=C:\SoftHSM2\lib\softhsm2-x64.dll
PKCS11_TOKEN_LABEL=token-1
PKCS11_TOKEN_PIN=changeit
PKCS11_TOKEN_SO_PIN=changeit
...

C:\Users\User\python-pkcs11>python setup.py test
running test
running egg_info
writing python_pkcs11.egg-info\PKG-INFO
writing dependency_links to python_pkcs11.egg-info\dependency_links.txt
writing requirements to python_pkcs11.egg-info\requires.txt
writing top-level names to python_pkcs11.egg-info\top_level.txt
writing manifest file 'python_pkcs11.egg-info\SOURCES.txt'
running build_ext
cythoning pkcs11/_pkcs11.pyx to pkcs11\_pkcs11.c
building 'pkcs11._pkcs11' extension
creating build
creating build\temp.win-amd64-3.7
creating build\temp.win-amd64-3.7\Release
creating build\temp.win-amd64-3.7\Release\pkcs11
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -IC:\Users\User\AppData\Local\Programs\Python\Python37\include -IC:\Users\User\AppData\Local\Programs\Python\Python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tcpkcs11\_pkcs11.c /Fobuild\temp.win-amd64-3.7\Release\pkcs11\_pkcs11.obj
_pkcs11.c
creating C:\Users\User\python-pkcs11\build\lib.win-amd64-3.7
creating C:\Users\User\python-pkcs11\build\lib.win-amd64-3.7\pkcs11
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\User\AppData\Local\Programs\Python\Python37\libs /LIBPATH:C:\Users\User\AppData\Local\Programs\Python\Python37\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" user32.lib /EXPORT:PyInit__pkcs11 build\temp.win-amd64-3.7\Release\pkcs11\_pkcs11.obj /OUT:build\lib.win-amd64-3.7\pkcs11\_pkcs11.cp37-win_amd64.pyd /IMPLIB:build\temp.win-amd64-3.7\Release\pkcs11\_pkcs11.cp37-win_amd64.lib
   Creating library build\temp.win-amd64-3.7\Release\pkcs11\_pkcs11.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\pkcs11\_pkcs11.cp37-win_amd64.exp
Generating code
Finished generating code
copying build\lib.win-amd64-3.7\pkcs11\_pkcs11.cp37-win_amd64.pyd -> pkcs11
test_encrypt (tests.test_aes.AESTests) ... ok
test_encrypt_big_string (tests.test_aes.AESTests) ... ok
test_encrypt_stream (tests.test_aes.AESTests) ... ok
test_encrypt_whacky_sizes (tests.test_aes.AESTests) ... ok
test_sign (tests.test_aes.AESTests) ... skipped 'Requires Mechanism.AES_MAC'
test_sign_stream (tests.test_aes.AESTests) ... skipped 'Requires Mechanism.AES_MAC'
test_wrap (tests.test_aes.AESTests) ... ok
test_encrypt_des2 (tests.test_des.DESTests) ... ok
test_encrypt_des3 (tests.test_des.DESTests) ... ok
test_generate_des2_key (tests.test_des.DESTests) ... ok
test_generate_des3_key (tests.test_des.DESTests) ... ok
test_derive_key (tests.test_dh.DHTests) ... ok
test_generate_params (tests.test_dh.DHTests) ... ok
test_load_params (tests.test_dh.DHTests) ... ok
test_digest (tests.test_digest.DigestTests) ... ok
test_digest_generator (tests.test_digest.DigestTests) ... ok
test_digest_key (tests.test_digest.DigestTests) ... ok
test_digest_key_data (tests.test_digest.DigestTests) ... ok
test_generate_keypair_and_sign (tests.test_dsa.DSATests) ... ok
test_generate_keypair_directly (tests.test_dsa.DSATests) ... ok
test_generate_params (tests.test_dsa.DSATests) ... ok
test_derive_key (tests.test_ecc.ECCTests) ... ok
test_import_key_named_curve (tests.test_ecc.ECCTests) ... skipped 'Requires Mechanism.ECDSA_SHA1'
test_import_key_pair (tests.test_ecc.ECCTests) ... ok
test_import_key_params (tests.test_ecc.ECCTests) ... ok
test_sign_ecdsa (tests.test_ecc.ECCTests) ... ok
test_close_iterators (tests.test_iterators.IteratorTests) ... expected failure
test_partial_decrypt (tests.test_iterators.IteratorTests) ... ok
test_ecdh (tests.test_public_key_external.ExternalPublicKeyTests) ... ok
test_ecdsa (tests.test_public_key_external.ExternalPublicKeyTests) ... skipped 'Requires Mechanism.ECDSA_SHA1'
test_rsa (tests.test_public_key_external.ExternalPublicKeyTests) ... ok
test_terrible_hybrid_file_encryption_app (tests.test_public_key_external.ExternalPublicKeyTests) ... ok
test_encrypt_oaep (tests.test_rsa.RSATests) ... ok
test_encrypt_too_much_data (tests.test_rsa.RSATests) ... ok
test_key_wrap (tests.test_rsa.RSATests) ... ok
test_sign_default (tests.test_rsa.RSATests) ... ok
test_sign_pkcs_v15 (tests.test_rsa.RSATests) ... ok
test_sign_pss (tests.test_rsa.RSATests) ... ok
test_sign_stream (tests.test_rsa.RSATests) ... ok
test_copy_object (tests.test_sessions.SessionTests) ... ok
test_create_object (tests.test_sessions.SessionTests) ... ok
test_destroy_object (tests.test_sessions.SessionTests) ... ok
test_generate_key (tests.test_sessions.SessionTests) ... ok
test_generate_keypair (tests.test_sessions.SessionTests) ... ok
test_generate_random (tests.test_sessions.SessionTests) ... ok
test_get_key (tests.test_sessions.SessionTests) ... ok
test_get_key_not_found (tests.test_sessions.SessionTests) ... ok
test_get_key_vague (tests.test_sessions.SessionTests) ... ok
test_get_objects (tests.test_sessions.SessionTests) ... ok
test_open_session (tests.test_sessions.SessionTests) ... ok
test_open_session_and_login_so (tests.test_sessions.SessionTests) ... ok
test_open_session_and_login_user (tests.test_sessions.SessionTests) ... ok
test_seed_random (tests.test_sessions.SessionTests) ... ok
test_double_initialise (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_double_initialise_different_libs (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_mechanism_info (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_mechanism_info_ec (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_mechanisms (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_slots (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_token (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_get_tokens (tests.test_slots_and_tokens.SlotsAndTokensTests) ... ok
test_concurrency (tests.test_threading.ThreadingTests) ... ok
test_import_ca_certificate (tests.test_x509.X509Tests) ... ok
test_import_ca_certificate_easy (tests.test_x509.X509Tests) ... ok
test_self_sign_certificate (tests.test_x509.X509Tests) ... C:\Users\User\AppData\Local\Programs\Python\Python37\lib\subprocess.py:664: ResourceWarning: unclosed file <_io.BufferedReader name=5>
  _cleanup()
ResourceWarning: Enable tracemalloc to get the object allocation traceback
ok
test_sign_csr (tests.test_x509.X509Tests) ... verify OK
ok
test_verify_certificate_dsa (tests.test_x509.X509Tests) ... ok
test_verify_certificate_ecdsa (tests.test_x509.X509Tests) ... skipped 'Requires Mechanism.ECDSA_SHA1'
test_verify_certificate_rsa (tests.test_x509.X509Tests) ... ok

----------------------------------------------------------------------
Ran 69 tests in 1.891s

OK (skipped=5, expected failures=1)

As you can see, there remains an issue with a file descriptor left open. This is caused by subprocess.Popen, which I suspect not to behave properly on this platform. This error happens sometimes, and is likely not related to the library code.

Copy link
Collaborator

@danni danni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

@danni
Copy link
Collaborator

danni commented Feb 14, 2019

Wait a moment. I'm not sure why Travis has stopped reporting, but there's something to fix up: https://travis-ci.org/danni/python-pkcs11/jobs/493412106

@keldonin
Copy link
Contributor Author

😅 Here is the reason:
you hard-coded the SO PIN to '5678', in the current implementation, see https://github.com/danni/python-pkcs11/blob/82cf55683bedc7a662de7351d5db9ff07bb6248d/tests/test_sessions.py#L26
The PR no longer assumes this value and either expects that you set it through a new environment variable PKCS11_TOKEN_SO_PIN, or assumes it be the same as for PKCS11_TOKEN_PIN; see tests/__init__.py from PR, it's documented in the module docstring.

Hence Travis legitimately complaining:

Too bad that Travis triggers only upon changes approval and not upon PR submission - I would have spotted it. (Can Github be configured that way?)

I have adapted Travis config file to fix the issue, in my last commit. Travis seems happy now.

@danni
Copy link
Collaborator

danni commented Feb 15, 2019

I'm sure it used to, maybe it stopped because people were executing random denials of service.

@danni danni merged commit 4e5782c into pyauth:master Feb 15, 2019
@danni
Copy link
Collaborator

danni commented Feb 15, 2019

Thanks again for this. I'll try and do a release on the weekend.

@danni danni mentioned this pull request Feb 15, 2019
@keldonin keldonin deleted the enh_implement_on_win10_msvc branch February 18, 2019 12:38
@avoidik
Copy link

avoidik commented Feb 25, 2019

@danni kindly reminder ;) I was able to test compilation on Windows, the only prerequisite is VS Build Tools

@danni
Copy link
Collaborator

danni commented Mar 2, 2019

Thanks @avoidik. Just trying to figure out Windows CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants