Skip to content

Commit

Permalink
Merge pull request #3 from gisce/fix_no_md5_compat
Browse files Browse the repository at this point in the history
Multiple Patches to Work with newest distributions like Ubuntu 24.04
  • Loading branch information
polsala authored Jan 31, 2025
2 parents 9926890 + 63cc551 commit e422bf5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/install_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ name: 'Check installable'
on:
push:
branches: [ gisce ]

pull_request:
branches: [ gisce ]

jobs:
check-package-installable:
Expand Down
9 changes: 9 additions & 0 deletions src/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 36 additions & 4 deletions src/exception.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@
PyObject* PyXmlSec_Error;
PyObject* PyXmlSec_InternalError;
PyObject* PyXmlSec_VerificationError;

//#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;
#endif

static int PyXmlSec_PrintErrorMessage = 0;

Expand Down Expand Up @@ -71,16 +75,28 @@ static PyXmlSec_ErrorHolder* PyXmlSec_ExchangeLastError(PyXmlSec_ErrorHolder* e)
PyXmlSec_ErrorHolder* v;
int r;

// #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) {
#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
#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);
#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;
}
Expand Down Expand Up @@ -165,6 +181,17 @@ void PyXmlSecEnableDebugTrace(int v) {
PyXmlSec_PrintErrorMessage = v;
}

void PyXmlSec_InstallErrorCallback() {
// #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) {
#endif
xmlSecErrorsSetCallback(PyXmlSec_ErrorCallback);
}
}

// initializes errors module
int PyXmlSec_ExceptionsModule_Init(PyObject* package) {
PyXmlSec_Error = NULL;
Expand All @@ -184,10 +211,15 @@ 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 PY_MINOR_VERSION >= 7 && PY_MAJOR_VERSION > 2
if (PyThread_tss_create(&PyXmlSec_LastErrorKey) == 0) {
PyXmlSec_InstallErrorCallback();
}
#else
PyXmlSec_LastErrorKey = PyThread_create_key();
PyXmlSec_InstallErrorCallback();
#endif

return 0;

Expand Down
2 changes: 1 addition & 1 deletion src/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit e422bf5

Please sign in to comment.