Skip to content

Commit 8ee9a9c

Browse files
brennanneohdanvllatdivispre-commit-ci[bot]
authored
PKCS11 Support (#3)
* Added changes to enable 3.11 builds * Fix xmlsec#244 - Fix failing test with libxmlsec-1.2.36, also make libxmlsec version available from Python. * Fix xmlsec#164 - Add support for loading keys from engine (e.g. pkcs11). * Fix xmlsec#164 - Add tests for pkcs11 (softhsm) key. * [pre-commit.ci] auto fixes from pre-commit.com hooks --------- Co-authored-by: Dan Vella <[email protected]> Co-authored-by: Tomas Divis <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ef0e742 commit 8ee9a9c

15 files changed

+547
-11
lines changed

.appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ environment:
1616
python_version: 3.10.6
1717
- python: 310-x64
1818
python_version: 3.10.6
19+
- python: 311
20+
python_version: 3.11.2
21+
- python: 311-x64
22+
python_version: 3.11.2
1923

2024
install:
2125
- ps: |

.github/workflows/macosx.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: macos-latest
66
strategy:
77
matrix:
8-
python: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10"]
8+
python: [3.5, 3.6, 3.7, 3.8, 3.9, "3.10", "3.11"]
99
steps:
1010
- uses: actions/checkout@v3
1111
- name: Setup Python

.github/workflows/manylinux.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
python-abi: [cp36-cp36m, cp37-cp37m, cp38-cp38, cp39-cp39, cp310-cp310]
8+
python-abi: [cp36-cp36m, cp37-cp37m, cp38-cp38, cp39-cp39, cp310-cp310, cp311-cp311]
99
image:
1010
- manylinux2010_x86_64
1111
- manylinux_2_24_x86_64
1212
- musllinux_1_1_x86_64
1313
exclude:
1414
- image: manylinux2010_x86_64
15-
python-abi: cp310-cp310
15+
python-abi: cp311-cp311
1616
- image: manylinux2010_i686
17-
python-abi: cp310-cp310
17+
python-abi: cp311-cp311
1818
container: quay.io/pypa/${{ matrix.image }}
1919
steps:
2020
- uses: actions/checkout@v1

.github/workflows/opensuse-tumbleweed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
container: opensuse/tumbleweed
77
strategy:
88
matrix:
9-
python-version: ["3.8", "3.9", "3.10"]
9+
python-version: ["3.8", "3.9", "3.10", "3.11"]
1010
steps:
1111
- uses: actions/checkout@v1
1212
- name: Install build dependencies

.github/workflows/sdist.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,19 @@ jobs:
55
runs-on: ubuntu-latest
66
steps:
77
- uses: actions/checkout@v3
8-
- name: Set up Python 3.10
8+
- name: Set up Python 3.11
99
uses: actions/setup-python@v4
1010
with:
11-
python-version: "3.10"
11+
python-version: "3.11"
1212
- name: Install build dependencies
1313
run: |
1414
pip install --upgrade pip setuptools wheel
1515
- name: Package source dist
1616
run: |
1717
python setup.py sdist
1818
- name: Install test dependencies
19-
env:
20-
PYXMLSEC_STATIC_DEPS: true
2119
run: |
20+
sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl opensc softhsm2 libengine-pkcs11-openssl
2221
pip install --upgrade -r requirements-test.txt
2322
pip install black # for stub generation tests
2423
pip install dist/xmlsec-$(python setup.py --version).tar.gz

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ matrix:
1616
- python: 3.9
1717
dist: xenial
1818
sudo: required
19+
- python: 3.11
20+
dist: xenial
21+
sudo: required
1922
env:
2023
global:
2124
- CFLAGS=-coverage

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Check the `examples <https://xmlsec.readthedocs.io/en/latest/examples.html>`_ se
3737
Requirements
3838
************
3939
- ``libxml2 >= 2.9.1``
40-
- ``libxmlsec1 >= 1.2.18``
40+
- ``libxmlsec1 >= 1.2.33``
4141

4242
Install
4343
*******

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ def prepare_static_build_linux(self):
533533
'Programming Language :: Python :: 3.7',
534534
'Programming Language :: Python :: 3.8',
535535
'Programming Language :: Python :: 3.9',
536+
'Programming Language :: Python :: 3.11',
536537
'Topic :: Text Processing :: Markup :: XML',
537538
'Typing :: Typed',
538539
],

src/keys.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,47 @@ static PyObject* PyXmlSec_KeyFromFile(PyObject* self, PyObject* args, PyObject*
185185
return NULL;
186186
}
187187

188+
static const char PyXmlSec_KeyFromEngine__doc__[] = \
189+
"from_engine(engine_and_key_id) -> xmlsec.Key\n"
190+
"Loads PKI key from an engine.\n\n"
191+
":param engine_and_key_id: engine and key id, i.e. 'pkcs11;pkcs11:token=XmlsecToken;object=XmlsecKey;pin-value=password'\n"
192+
":type engine_and_key_id: :class:`str`, "
193+
":return: pointer to newly created key\n"
194+
":rtype: :class:`~xmlsec.Key`";
195+
static PyObject* PyXmlSec_KeyFromEngine(PyObject* self, PyObject* args, PyObject* kwargs) {
196+
static char *kwlist[] = {"engine_and_key_id", NULL};
197+
198+
const char* engine_and_key_id = NULL;
199+
PyXmlSec_Key* key = NULL;
200+
201+
PYXMLSEC_DEBUG("load key from engine - start");
202+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s:from_engine", kwlist, &engine_and_key_id)) {
203+
goto ON_FAIL;
204+
}
205+
206+
if ((key = PyXmlSec_NewKey1((PyTypeObject*)self)) == NULL) goto ON_FAIL;
207+
208+
Py_BEGIN_ALLOW_THREADS;
209+
key->handle = xmlSecCryptoAppKeyLoad(engine_and_key_id, xmlSecKeyDataFormatEngine, NULL, xmlSecCryptoAppGetDefaultPwdCallback(),
210+
(void*)engine_and_key_id);
211+
Py_END_ALLOW_THREADS;
212+
213+
if (key->handle == NULL) {
214+
PyXmlSec_SetLastError("cannot read key");
215+
goto ON_FAIL;
216+
}
217+
218+
key->is_own = 1;
219+
220+
PYXMLSEC_DEBUG("load key from engine - ok");
221+
return (PyObject*)key;
222+
223+
ON_FAIL:
224+
PYXMLSEC_DEBUG("load key from engine - fail");
225+
Py_XDECREF(key);
226+
return NULL;
227+
}
228+
188229
static const char PyXmlSec_KeyGenerate__doc__[] = \
189230
"generate(klass, size, type) -> xmlsec.Key\n"
190231
"Generates key of kind ``klass`` with ``size`` and ``type``.\n\n"
@@ -494,6 +535,12 @@ static PyMethodDef PyXmlSec_KeyMethods[] = {
494535
METH_CLASS|METH_VARARGS|METH_KEYWORDS,
495536
PyXmlSec_KeyFromFile__doc__
496537
},
538+
{
539+
"from_engine",
540+
(PyCFunction)PyXmlSec_KeyFromEngine,
541+
METH_CLASS|METH_VARARGS|METH_KEYWORDS,
542+
PyXmlSec_KeyFromEngine__doc__
543+
},
497544
{
498545
"generate",
499546
(PyCFunction)PyXmlSec_KeyGenerate,

src/main.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ static PyObject* PyXmlSec_PyShutdown(PyObject* self) {
119119
Py_RETURN_NONE;
120120
}
121121

122+
static char PyXmlSec_GetLibXmlSecVersion__doc__[] = \
123+
"get_libxmlsec_version() -> tuple\n"
124+
"Returns Version tuple of wrapped libxml library.";
125+
static PyObject* PyXmlSec_GetLibXmlSecVersion() {
126+
return Py_BuildValue("(iii)", XMLSEC_VERSION_MAJOR, XMLSEC_VERSION_MINOR, XMLSEC_VERSION_SUBMINOR);
127+
}
128+
122129
static char PyXmlSec_PyEnableDebugOutput__doc__[] = \
123130
"enable_debug_trace(enabled) -> None\n"
124131
"Enables or disables calling LibXML2 callback from the default errors callback.\n\n"
@@ -386,6 +393,12 @@ static PyMethodDef PyXmlSec_MainMethods[] = {
386393
METH_NOARGS,
387394
PyXmlSec_PyShutdown__doc__
388395
},
396+
{
397+
"get_libxmlsec_version",
398+
(PyCFunction)PyXmlSec_GetLibXmlSecVersion,
399+
METH_NOARGS,
400+
PyXmlSec_GetLibXmlSecVersion__doc__
401+
},
389402
{
390403
"enable_debug_trace",
391404
(PyCFunction)PyXmlSec_PyEnableDebugOutput,

0 commit comments

Comments
 (0)