From 6e377f82aab74233810108521c3a78837f02a5d1 Mon Sep 17 00:00:00 2001 From: "oleg.hoefling" Date: Sat, 12 Jun 2021 14:06:51 +0200 Subject: [PATCH 1/7] add XMLSEC_NO_MD5 check Signed-off-by: oleg.hoefling --- src/constants.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/constants.c b/src/constants.c index b4cdedf4..451858fd 100644 --- a/src/constants.c +++ b/src/constants.c @@ -512,7 +512,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) { PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformEcdsaSha512, "ECDSA_SHA512"); #endif +#ifndef XMLSEC_NO_MD5 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacMd5, "HMAC_MD5"); +#endif + #ifndef XMLSEC_NO_RIPEMD160 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacRipemd160, "HMAC_RIPEMD160"); #endif @@ -522,7 +525,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) { PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacSha384, "HMAC_SHA384"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformHmacSha512, "HMAC_SHA512"); +#ifndef XMLSEC_NO_MD5 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaMd5, "RSA_MD5"); +#endif + #ifndef XMLSEC_NO_RIPEMD160 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaRipemd160, "RSA_RIPEMD160"); #endif @@ -534,7 +540,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) { PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaPkcs1, "RSA_PKCS1"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRsaOaep, "RSA_OAEP"); +#ifndef XMLSEC_NO_MD5 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformMd5, "MD5"); +#endif + #ifndef XMLSEC_NO_RIPEMD160 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformRipemd160, "RIPEMD160"); #endif From b384b26f64e4a1f5c6cc323b5ee7f6f0f9b98dd6 Mon Sep 17 00:00:00 2001 From: "oleg.hoefling" Date: Fri, 28 May 2021 18:09:25 +0200 Subject: [PATCH 2/7] support PEP 539 for Python>=3.7 Signed-off-by: oleg.hoefling --- src/exception.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/src/exception.c b/src/exception.c index 2ca5ab57..06cbc61a 100644 --- a/src/exception.c +++ b/src/exception.c @@ -23,7 +23,11 @@ PyObject* PyXmlSec_Error; PyObject* PyXmlSec_InternalError; PyObject* PyXmlSec_VerificationError; +#if PY_MINOR_VERSION >= 7 +static Py_tss_t PyXmlSec_LastErrorKey; +#else static int PyXmlSec_LastErrorKey = 0; +#endif static int PyXmlSec_PrintErrorMessage = 0; @@ -71,16 +75,26 @@ static PyXmlSec_ErrorHolder* PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolder* e) PyXmlSec_ErrorHolder* v; int r; - if (PyXmlSec_LastErrorKey == 0) { + #if PY_MINOR_VERSION >= 7 + if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) != 0) { + #else + if (PyXmlSec_LastErrorKey != 0) { + #endif PYXMLSEC_DEBUG("WARNING: There is no error key."); PyXmlSec_ErrorHolderFree(e); return NULL; } // get_key_value and set_key_value are gil free + #if PY_MINOR_VERSION >= 7 + v = (PyXmlSec_ErrorHolder*)PyThread_tss_get(&PyXmlSec_LastErrorKey); + //PyThread_tss_delete(&PyXmlSec_LastErrorKey); + r = PyThread_tss_set(&PyXmlSec_LastErrorKey, (void*)e); + #else v = (PyXmlSec_ErrorHolder*)PyThread_get_key_value(PyXmlSec_LastErrorKey); PyThread_delete_key_value(PyXmlSec_LastErrorKey); r = PyThread_set_key_value(PyXmlSec_LastErrorKey, (void*)e); + #endif PYXMLSEC_DEBUGF("set_key_value returns %d", r); return v; } @@ -165,6 +179,16 @@ void PyXmlSecEnableDebugTrace(int v) { PyXmlSec_PrintErrorMessage = v; } +void PyXmlSec_InstallErrorCallback() { + #if PY_MINOR_VERSION >= 7 + if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) != 0) { + #else + if (PyXmlSec_LastErrorKey != 0) { + #endif + xmlSecErrorsSetCallback(PyXmlSec_ErrorCallback); + } +} + // initializes errors module int PyXmlSec_ExceptionsModule_Init(PyObject* package) { PyXmlSec_Error = NULL; @@ -184,10 +208,14 @@ int PyXmlSec_ExceptionsModule_Init(PyObject* package) { if (PyModule_AddObject(package, "InternalError", PyXmlSec_InternalError) < 0) goto ON_FAIL; if (PyModule_AddObject(package, "VerificationError", PyXmlSec_VerificationError) < 0) goto ON_FAIL; - PyXmlSec_LastErrorKey = PyThread_create_key(); - if (PyXmlSec_LastErrorKey != 0) { - xmlSecErrorsSetCallback(&PyXmlSec_ErrorCallback); + #if PY_MINOR_VERSION >= 7 + if (PyThread_tss_create(&PyXmlSec_LastErrorKey)) { + PyXmlSec_InstallErrorCallback(); } + #else + PyXmlSec_LastErrorKey = PyThread_create_key(); + PyXmlSec_InstallErrorCallback(); + #endif return 0; From 6ff917e089633ec22f401d2e5dc3d33bae228825 Mon Sep 17 00:00:00 2001 From: "oleg.hoefling" Date: Sat, 29 May 2021 13:45:06 +0200 Subject: [PATCH 3/7] avoid incompatible pointer type warning Signed-off-by: oleg.hoefling --- src/keys.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keys.c b/src/keys.c index 357cc9c7..8859e596 100644 --- a/src/keys.c +++ b/src/keys.c @@ -453,7 +453,7 @@ static int PyXmlSec_KeyNameSet(PyObject* self, PyObject* value, void* closure) { } if (value == NULL) { - if (xmlSecKeySetName(key->handle, value) < 0) { + if (xmlSecKeySetName(key->handle, NULL) < 0) { PyXmlSec_SetLastError("cannot delete name"); return -1; } From 29da1ad4cebfedf71aad8b5c4c48586023220491 Mon Sep 17 00:00:00 2001 From: "oleg.hoefling" Date: Sat, 5 Jun 2021 00:29:56 +0200 Subject: [PATCH 4/7] fix error key presence check Signed-off-by: oleg.hoefling --- src/exception.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exception.c b/src/exception.c index 06cbc61a..ac0e44ee 100644 --- a/src/exception.c +++ b/src/exception.c @@ -76,9 +76,9 @@ static PyXmlSec_ErrorHolder* PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolder* e) int r; #if PY_MINOR_VERSION >= 7 - if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) != 0) { + if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) == 0) { #else - if (PyXmlSec_LastErrorKey != 0) { + if (PyXmlSec_LastErrorKey == 0) { #endif PYXMLSEC_DEBUG("WARNING: There is no error key."); PyXmlSec_ErrorHolderFree(e); @@ -209,7 +209,7 @@ int PyXmlSec_ExceptionsModule_Init(PyObject* package) { if (PyModule_AddObject(package, "VerificationError", PyXmlSec_VerificationError) < 0) goto ON_FAIL; #if PY_MINOR_VERSION >= 7 - if (PyThread_tss_create(&PyXmlSec_LastErrorKey)) { + if (PyThread_tss_create(&PyXmlSec_LastErrorKey) == 0) { PyXmlSec_InstallErrorCallback(); } #else From 91ab05a682f65798aa6280d8556b4bd7cbbb5d83 Mon Sep 17 00:00:00 2001 From: PSala Date: Fri, 31 Jan 2025 09:47:53 +0100 Subject: [PATCH 5/7] Explicitly cast the pointer type in PyXmlSec_ClearReplacedNodes --- src/enc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/enc.c b/src/enc.c index aaf35ae5..b994f982 100644 --- a/src/enc.c +++ b/src/enc.c @@ -192,7 +192,7 @@ static void PyXmlSec_ClearReplacedNodes(xmlSecEncCtxPtr ctx, PyXmlSec_LxmlDocume PYXMLSEC_DEBUGF("clear replaced node %p", n); nn = n->next; // if n has references, it will not be deleted - elem = PyXmlSec_elementFactory(doc, n); + elem = (PyXmlSec_LxmlElementPtr*)PyXmlSec_elementFactory(doc, n); if (NULL == elem) xmlFreeNode(n); else From 8f1084ee34a264d1eda2bb563647ab77d079d158 Mon Sep 17 00:00:00 2001 From: PSala Date: Fri, 31 Jan 2025 09:52:38 +0100 Subject: [PATCH 6/7] Update .github/workflows/install_test.yml trigger on Pull Request --- .github/workflows/install_test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/install_test.yml b/.github/workflows/install_test.yml index 59f1f5fc..1ca42ed5 100644 --- a/.github/workflows/install_test.yml +++ b/.github/workflows/install_test.yml @@ -3,7 +3,8 @@ name: 'Check installable' on: push: branches: [ gisce ] - + pull_request: + branches: [ gisce ] jobs: check-package-installable: From 63cc55115755a3f4fba0cb1ddc18650eaf0cb131 Mon Sep 17 00:00:00 2001 From: PSala Date: Fri, 31 Jan 2025 10:18:32 +0100 Subject: [PATCH 7/7] Pol's Black Magic: Make patches python 2 compatible --- src/exception.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/exception.c b/src/exception.c index ac0e44ee..821570f3 100644 --- a/src/exception.c +++ b/src/exception.c @@ -22,8 +22,8 @@ PyObject* PyXmlSec_Error; PyObject* PyXmlSec_InternalError; PyObject* PyXmlSec_VerificationError; - -#if PY_MINOR_VERSION >= 7 +//#if PY_MINOR_VERSION >= 7 +#if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2 static Py_tss_t PyXmlSec_LastErrorKey; #else static int PyXmlSec_LastErrorKey = 0; @@ -75,7 +75,8 @@ static PyXmlSec_ErrorHolder* PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolder* e) PyXmlSec_ErrorHolder* v; int r; - #if PY_MINOR_VERSION >= 7 +// #if PY_MINOR_VERSION >= 7 + #if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2 if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) == 0) { #else if (PyXmlSec_LastErrorKey == 0) { @@ -86,7 +87,8 @@ static PyXmlSec_ErrorHolder* PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolder* e) } // get_key_value and set_key_value are gil free - #if PY_MINOR_VERSION >= 7 +// #if PY_MINOR_VERSION >= 7 + #if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2 v = (PyXmlSec_ErrorHolder*)PyThread_tss_get(&PyXmlSec_LastErrorKey); //PyThread_tss_delete(&PyXmlSec_LastErrorKey); r = PyThread_tss_set(&PyXmlSec_LastErrorKey, (void*)e); @@ -180,7 +182,8 @@ void PyXmlSecEnableDebugTrace(int v) { } void PyXmlSec_InstallErrorCallback() { - #if PY_MINOR_VERSION >= 7 +// #if PY_MINOR_VERSION >= 7 + #if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2 if (PyThread_tss_is_created(&PyXmlSec_LastErrorKey) != 0) { #else if (PyXmlSec_LastErrorKey != 0) { @@ -208,7 +211,8 @@ int PyXmlSec_ExceptionsModule_Init(PyObject* package) { if (PyModule_AddObject(package, "InternalError", PyXmlSec_InternalError) < 0) goto ON_FAIL; if (PyModule_AddObject(package, "VerificationError", PyXmlSec_VerificationError) < 0) goto ON_FAIL; - #if PY_MINOR_VERSION >= 7 +// #if PY_MINOR_VERSION >= 7 + #if PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2 if (PyThread_tss_create(&PyXmlSec_LastErrorKey) == 0) { PyXmlSec_InstallErrorCallback(); }