Skip to content

Commit 4e5782c

Browse files
authored
Merge pull request #33 from keldonin/enh_implement_on_win10_msvc
enhancement - working implementation on Windows10 with Visual Studio (...and Cygwin also)
2 parents 82cf556 + e84eb6f commit 4e5782c

10 files changed

+244
-61
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ env:
1111
- PKCS11_MODULE=/home/travis/lib/softhsm/libsofthsm2.so
1212
- PKCS11_TOKEN_LABEL=TEST
1313
- PKCS11_TOKEN_PIN=1234
14+
- PKCS11_TOKEN_SO_PIN=5678
1415

1516
cache:
1617
- pip

extern/cryptoki.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#ifndef _CRYPTOKI_H_
2+
#define _CRYPTOKI_H_ 1
3+
4+
/* MIT License */
5+
6+
/* Copyright (c) 2019 Eric Devolder */
7+
8+
/* Permission is hereby granted, free of charge, to any person obtaining */
9+
/* a copy of this software and associated documentation files (the */
10+
/* "Software"), to deal in the Software without restriction, including */
11+
/* without limitation the rights to use, copy, modify, merge, publish, */
12+
/* distribute, sublicense, and/or sell copies of the Software, and to */
13+
/* permit persons to whom the Software is furnished to do so, subject to */
14+
/* the following conditions: */
15+
16+
/* The above copyright notice and this permission notice shall be */
17+
/* included in all copies or substantial portions of the Software. */
18+
19+
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
20+
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
21+
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
22+
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE */
23+
/* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION */
24+
/* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION */
25+
/* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
26+
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
#if defined(__CYGWIN64__)
33+
#pragma warning "Cygwin 64 bits build will only work with Cygwin64-compiled PKCS#11 modules"
34+
#endif
35+
36+
#define CK_PTR *
37+
#define CK_DEFINE_FUNCTION(returnType, name) returnType name
38+
#define CK_DECLARE_FUNCTION(returnType, name) returnType name
39+
#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
40+
#define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
41+
42+
#ifndef NULL_PTR
43+
#define NULL_PTR 0
44+
#endif
45+
46+
#if defined(_MSC_VER) && defined(_WIN32) /* we are compiling using Visual C */
47+
#pragma pack(push, cryptoki, 1)
48+
#elif defined(__CYGWIN__)
49+
#pragma pack(push, 1)
50+
#endif
51+
52+
#include "pkcs11.h"
53+
54+
#if defined(_MSC_VER) && defined(_WIN32) /* we are compiling using Visual C */
55+
#pragma pack(pop, cryptoki)
56+
#elif defined(__CYGWIN__)
57+
#pragma pack(pop)
58+
#endif
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
64+
#endif /* _CRYPTOKI_H_ */
65+

pkcs11/_mswin.pxd

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!python
2+
#cython: language_level=3
3+
#
4+
# MIT License
5+
#
6+
# Copyright 2019 Eric Devolder
7+
#
8+
# Permission is hereby granted, free of charge, to any person obtaining
9+
# a copy of this software and associated documentation files (the
10+
# "Software"), to deal in the Software without restriction, including
11+
# without limitation the rights to use, copy, modify, merge, publish,
12+
# distribute, sublicense, and/or sell copies of the Software, and to
13+
# permit persons to whom the Software is furnished to do so, subject to
14+
# the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be
17+
# included in all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
27+
"""
28+
Definitions to support compilation on Windows platform
29+
"""
30+
31+
cdef extern from "Windows.h":
32+
ctypedef unsigned long DWORD
33+
ctypedef Py_UNICODE wchar_t
34+
ctypedef const wchar_t *LPCWSTR
35+
ctypedef const char *LPCSTR
36+
ctypedef void *PVOID
37+
ctypedef PVOID HANDLE
38+
ctypedef HANDLE HINSTANCE
39+
ctypedef HINSTANCE HMODULE
40+
ctypedef bint BOOL
41+
42+
HMODULE LoadLibraryW(LPCWSTR lpLibFileName)
43+
BOOL FreeLibrary(HMODULE hLinModule)
44+
PVOID GetProcAddress(HMODULE hModule, LPCSTR lpProcName)
45+
DWORD GetLastError()
46+
47+
cdef inline _winerrormsg(self):
48+
dw = GetLastError()
49+
# TODO: return error message from Windows, using FormatError()
50+
return dw

0 commit comments

Comments
 (0)