From 04329c0c6164b585488ae449526e1f1335184e18 Mon Sep 17 00:00:00 2001 From: Roman513 Date: Fri, 23 Apr 2021 23:45:17 +0300 Subject: [PATCH 01/12] Fix xmlsec version comparison macro Use 8 instead of 4 bits for all xmlsec version fields to prevent overflow starting from version number 1.2.32 --- src/constants.c | 9 ++++++--- src/main.c | 2 +- src/platform.h | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/constants.c b/src/constants.c index 68f086e9..b4cdedf4 100644 --- a/src/constants.c +++ b/src/constants.c @@ -452,7 +452,8 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) { #ifndef XMLSEC_NO_DSA PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataDsa, "DSA") #endif -#if XMLSEC_VERSION_HEX > 306 +#if XMLSEC_VERSION_HEX > 0x10212 + // from version 1.2.19 PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEcdsa, "ECDSA") #endif PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataHmac, "HMAC") @@ -502,7 +503,8 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) { PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformDsaSha1, "DSA_SHA1"); #endif -#if XMLSEC_VERSION_HEX > 306 +#if XMLSEC_VERSION_HEX > 0x10212 + // from version 1.2.19 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformEcdsaSha1, "ECDSA_SHA1"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformEcdsaSha224, "ECDSA_SHA224"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformEcdsaSha256, "ECDSA_SHA256"); @@ -543,7 +545,8 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) { PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformSha384, "SHA384"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformSha512, "SHA512"); -#if XMLSEC_VERSION_HEX > 315 +#if XMLSEC_VERSION_HEX > 0x1021B + // from version 1.2.28 PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformAes128Gcm, "AES128_GCM"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformAes192Gcm, "AES192_GCM"); PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformAes256Gcm, "AES256_GCM"); diff --git a/src/main.c b/src/main.c index 59989529..c097d7f5 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,7 @@ static int free_mode = _PYXMLSEC_FREE_NONE; #ifndef XMLSEC_NO_CRYPTO_DYNAMIC_LOADING static const xmlChar* PyXmlSec_GetCryptoLibName() { -#if XMLSEC_VERSION_HEX > 308 +#if XMLSEC_VERSION_HEX > 0x10214 // xmlSecGetDefaultCrypto was introduced in version 1.2.21 const xmlChar* cryptoLib = xmlSecGetDefaultCrypto(); #else diff --git a/src/platform.h b/src/platform.h index 795062f2..01312a11 100644 --- a/src/platform.h +++ b/src/platform.h @@ -19,11 +19,11 @@ #include #endif /* MS_WIN32 */ -#define XMLSEC_VERSION_HEX ((XMLSEC_VERSION_MAJOR << 8) | (XMLSEC_VERSION_MINOR << 4) | (XMLSEC_VERSION_SUBMINOR)) +#define XMLSEC_VERSION_HEX ((XMLSEC_VERSION_MAJOR << 16) | (XMLSEC_VERSION_MINOR << 8) | (XMLSEC_VERSION_SUBMINOR)) // XKMS support was removed in version 1.2.21 // https://mail.gnome.org/archives/commits-list/2015-February/msg10555.html -#if XMLSEC_VERSION_HEX > 0x134 +#if XMLSEC_VERSION_HEX > 0x10214 #define XMLSEC_NO_XKMS 1 #endif From 085bf6a66ba0c917c59f830748e9933d670e786b Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 23 Jul 2024 12:32:03 +0200 Subject: [PATCH 02/12] New workflow intallable check py2/py3 ubuntu 20, 22 and latest --- .github/workflows/install_test.yml | 58 +++++++++++++++++++++++++++++ .github/workflows/macosx.yml | 44 ---------------------- .github/workflows/manylinux2010.yml | 37 ------------------ .github/workflows/sdist.yml | 26 ------------- 4 files changed, 58 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/install_test.yml delete mode 100644 .github/workflows/macosx.yml delete mode 100644 .github/workflows/manylinux2010.yml delete mode 100644 .github/workflows/sdist.yml diff --git a/.github/workflows/install_test.yml b/.github/workflows/install_test.yml new file mode 100644 index 00000000..64ea7551 --- /dev/null +++ b/.github/workflows/install_test.yml @@ -0,0 +1,58 @@ +name: 'Check installable' + +on: + push: + branches: [ gisce ] + + +jobs: + check-package-installable: + strategy: + matrix: + python-version: [ "2.7.18", "3.11"] + os: [ ubuntu-latest, ubuntu-20.04, ubuntu-22.04 ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Set up Python 3 + if: matrix.python-version == '3.11' + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Python 2 on ubuntu 20 + if: matrix.python-version == '2.7.18' && matrix.os == 'ubuntu-20.04' + run: | + sudo apt update + sudo apt install python2 python2-dev + curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py + sudo python2 get-pip.py + sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2 + printf '1\n' | sudo update-alternatives --config python + + - name: Install Python 2 on ubuntu >= 22 + if: matrix.python-version == '2.7.18' && matrix.os != 'ubuntu-20.04' + run: | + sudo add-apt-repository ppa:deadsnakes/ppa -y + sudo apt update + sudo apt install python2 python2-dev python-pip + sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1 + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2 + printf '1\n' | sudo update-alternatives --config python + cd /usr/bin + sudo ln -s /usr/bin/pip2 ./pip + + - name: Set up virtual environment + run: | + python -m pip install --upgrade pip + pip install virtualenv + python -m virtualenv venv + + - name: Install package + run: | + sudo apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl opensc softhsm2 libengine-pkcs11-openssl + source venv/bin/activate + pip install --upgrade pip setuptools wheel build + pip install -e . diff --git a/.github/workflows/macosx.yml b/.github/workflows/macosx.yml deleted file mode 100644 index c8bfee95..00000000 --- a/.github/workflows/macosx.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: MacOS -on: [push, pull_request] -jobs: - macosx: - runs-on: macos-latest - strategy: - matrix: - python: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9] - steps: - - uses: actions/checkout@v1 - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python }} - - name: Install build dependencies - run: | - pip install --upgrade pip setuptools wheel - brew install libxml2 libxmlsec1 pkg-config - - name: Build macosx_x86_64 wheel - run: | - python setup.py bdist_wheel - - name: Set environment variables - shell: bash - run: | - echo ::set-env name=PKGVER::$(python setup.py --version) - echo ::set-env name=LLVM_PROFILE_FILE::"pyxmlsec-%p.profraw" - - name: Install test dependencies - env: - CC: clang - CFLAGS: "-fprofile-instr-generate -fcoverage-mapping" - LDFLAGS: "-fprofile-instr-generate -fcoverage-mapping" - run: | - rm -rf build/ - pip install coverage --upgrade -r requirements-test.txt - pip install --editable . - - name: Run tests - run: | - coverage run -m pytest -v --color=yes - - name: Report coverage to codecov - run: | - LIBFILE=$(python -c "import xmlsec; print(xmlsec.__file__)") - /Library/Developer/CommandLineTools/usr/bin/llvm-profdata merge -sparse pyxmlsec-*.profraw -output pyxmlsec.profdata - /Library/Developer/CommandLineTools/usr/bin/llvm-cov show ${LIBFILE} -instr-profile=pyxmlsec.profdata src > coverage.txt - bash <(curl -s https://codecov.io/bash) -f coverage.txt diff --git a/.github/workflows/manylinux2010.yml b/.github/workflows/manylinux2010.yml deleted file mode 100644 index 637983d4..00000000 --- a/.github/workflows/manylinux2010.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: manylinux2010 -on: [push, pull_request] -jobs: - manylinux2010_x86_64: - runs-on: ubuntu-latest - container: quay.io/pypa/manylinux2010_x86_64 - strategy: - matrix: - python-abi: [cp27-cp27m, cp27-cp27mu, cp35-cp35m, cp36-cp36m, cp37-cp37m, cp38-cp38, cp39-cp39] - steps: - - uses: actions/checkout@v1 - - name: Install build dependencies - run: | - /opt/python/${{ matrix.python-abi }}/bin/pip install --upgrade pip setuptools wheel - - name: Set environment variables - shell: bash - run: | - echo ::set-env name=PKGVER::$(/opt/python/${{ matrix.python-abi }}/bin/python setup.py --version) - - name: Build linux_x86_64 wheel - env: - PYXMLSEC_STATIC_DEPS: true - run: | - /opt/python/${{ matrix.python-abi }}/bin/python setup.py bdist_wheel - - name: Label manylinux2010_x86_64 wheel - run: | - ls -la dist/ - auditwheel show dist/xmlsec-${PKGVER}-${{ matrix.python-abi }}-linux_x86_64.whl - auditwheel repair dist/xmlsec-${PKGVER}-${{ matrix.python-abi }}-linux_x86_64.whl - ls -l wheelhouse/ - auditwheel show wheelhouse/xmlsec-${PKGVER}-${{ matrix.python-abi }}-manylinux2010_x86_64.whl - - name: Install test dependencies - run: | - /opt/python/${{ matrix.python-abi }}/bin/pip install --upgrade -r requirements-test.txt - /opt/python/${{ matrix.python-abi }}/bin/pip install xmlsec --only-binary=xmlsec --no-index --find-links=wheelhouse/ - - name: Run tests - run: | - /opt/python/${{ matrix.python-abi }}/bin/pytest -v --color=yes diff --git a/.github/workflows/sdist.yml b/.github/workflows/sdist.yml deleted file mode 100644 index 5b5dac96..00000000 --- a/.github/workflows/sdist.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: sdist -on: [push, pull_request] -jobs: - sdist: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Set up Python 3.9 - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: Install build dependencies - run: | - pip install --upgrade pip setuptools wheel - - name: Package source dist - run: | - python setup.py sdist - - name: Install test dependencies - env: - PYXMLSEC_STATIC_DEPS: true - run: | - pip install --upgrade -r requirements-test.txt - pip install dist/xmlsec-$(python setup.py --version).tar.gz - - name: Run tests - run: | - pytest -v --color=yes From dc5768527b346ca3f6e097a2f5a78730435c7947 Mon Sep 17 00:00:00 2001 From: PSala Date: Tue, 23 Jul 2024 12:32:16 +0200 Subject: [PATCH 03/12] Custom readme --- README.rst | 207 ++--------------------------------------------------- 1 file changed, 7 insertions(+), 200 deletions(-) diff --git a/README.rst b/README.rst index f01d467d..476f6ee3 100644 --- a/README.rst +++ b/README.rst @@ -1,215 +1,22 @@ python-xmlsec ============= -.. image:: https://img.shields.io/pypi/v/xmlsec.svg?logo=python&logoColor=white - :target: https://pypi.python.org/pypi/xmlsec -.. image:: https://img.shields.io/travis/com/mehcode/python-xmlsec/master.svg?logo=travis&logoColor=white&label=Travis%20CI - :target: https://travis-ci.org/mehcode/python-xmlsec -.. image:: https://img.shields.io/appveyor/ci/hoefling/xmlsec/master.svg?logo=appveyor&logoColor=white&label=AppVeyor - :target: https://ci.appveyor.com/project/hoefling/xmlsec -.. image:: https://github.com/mehcode/python-xmlsec/workflows/manylinux2010/badge.svg - :target: https://github.com/mehcode/python-xmlsec/actions?query=workflow%3A%22manylinux2010%22 -.. image:: https://github.com/mehcode/python-xmlsec/workflows/MacOS/badge.svg - :target: https://github.com/mehcode/python-xmlsec/actions?query=workflow%3A%22MacOS%22 -.. image:: https://codecov.io/gh/mehcode/python-xmlsec/branch/master/graph/badge.svg - :target: https://codecov.io/gh/mehcode/python-xmlsec -.. image:: https://img.shields.io/readthedocs/xmlsec/latest?logo=read-the-docs - :target: https://xmlsec.readthedocs.io/en/latest/?badge=latest - :alt: Documentation Status - -Python bindings for the `XML Security Library `_. - -Documentation -************* - -A documentation for ``xmlsec`` can be found at `xmlsec.readthedocs.io `_. - -Usage -***** - -Check the `examples `_ section in the documentation to see various examples of signing and verifying using the library. - -Requirements -************ -- ``libxml2 >= 2.9.1`` -- ``libxmlsec1 >= 1.2.18`` - -Install -******* - -``xmlsec`` is available on PyPI: - -.. code-block:: bash - - pip install xmlsec - -Depending on your OS, you may need to install the required native -libraries first: - -Linux (Debian) -^^^^^^^^^^^^^^ - -.. code-block:: bash - - apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-openssl - - -Note: There is no required version of LibXML2 for Ubuntu Precise, -so you need to download and install it manually. - -.. code-block:: bash - - wget http://xmlsoft.org/sources/libxml2-2.9.1.tar.gz - tar -xvf libxml2-2.9.1.tar.gz - cd libxml2-2.9.1 - ./configure && make && make install - - -Linux (CentOS) -^^^^^^^^^^^^^^ - -.. code-block:: bash - - yum install libxml2-devel xmlsec1-devel xmlsec1-openssl-devel libtool-ltdl-devel - - -Linux (Fedora) -^^^^^^^^^^^^^^ - -.. code-block:: bash - - dnf install libxml2-devel xmlsec1-devel xmlsec1-openssl-devel libtool-ltdl-devel - - -Mac -^^^ - -.. code-block:: bash - - brew install libxml2 libxmlsec1 pkg-config - - -Alpine -^^^^^^ - -.. code-block:: bash - - apk add build-base libressl libffi-dev libressl-dev libxslt-dev libxml2-dev xmlsec-dev xmlsec - - -Troubleshooting -*************** - -Mac -^^^ - -If you get any fatal errors about missing ``.h`` files, update your -``C_INCLUDE_PATH`` environment variable to include the appropriate -files from the ``libxml2`` and ``libxmlsec1`` libraries. - - -Windows -^^^^^^^ - -Starting with 1.3.7, prebuilt wheels are available for Windows, -so running ``pip install xmlsec`` should suffice. If you want -to build from source: - -#. Configure build environment, see `wiki.python.org `_ for more details. - -#. Install from source dist: - - .. code-block:: bash - - pip install xmlsec --no-binary=xmlsec - - -Building from source -******************** - -#. Clone the ``xmlsec`` source code repository to your local computer. - - .. code-block:: bash - - git clone https://github.com/mehcode/python-xmlsec.git - -#. Change into the ``python-xmlsec`` root directory. - - .. code-block:: bash - - cd /path/to/xmlsec - - -#. Install the project and all its dependencies using ``pip``. - - .. code-block:: bash - - pip install . - - -Contributing -************ - -Setting up your environment +Gisce tests (Ubuntu 20, 22 and latest / python 2.7 and 3.11) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -#. Follow steps 1 and 2 of the `manual installation instructions <#building-from-source>`_. - +.. image:: https://github.com/gisce/python-xmlsec/actions/workflows/install_test.yml/badge.svg?logo=python&logoColor=white + :target: https://github.com/gisce/python-xmlsec/actions/workflows/install_test.yml -#. Initialize a virtual environment to develop in. - This is done so as to ensure every contributor is working with - close-to-identicial versions of packages. - .. code-block:: bash - - mkvirtualenv xmlsec - - The ``mkvirtualenv`` command is available from ``virtualenvwrapper`` package which can be installed by following `link `_. - -#. Activate the created virtual environment: - - .. code-block:: bash - - workon xmlsec - -#. Install ``xmlsec`` in development mode with testing enabled. - This will download all dependencies required for running the unit tests. - - .. code-block:: bash - - pip install -r requirements-test.txt - pip install -e "." - - -Running the test suite -^^^^^^^^^^^^^^^^^^^^^^ - -#. `Set up your environment <#setting-up-your-environment>`_. +Installation +^^^^^^^^^^^^^^^^^^^^^^^^^^^ -#. Run the unit tests. +#. Install ``xmlsec`` patched version. .. code-block:: bash - pytest tests - -#. Tests configuration - - Env variable ``PYXMLSEC_TEST_ITERATIONS`` specifies number of - test iterations to detect memory leaks. - -Reporting an issue -^^^^^^^^^^^^^^^^^^ - -Please attach the output of following information: - -* version of ``xmlsec`` -* version of ``libxmlsec1`` -* version of ``libxml2`` -* output from the command - - .. code-block:: bash + pip install git+https://github.com/gisce/python-xmlsec.git - pkg-config --cflags xmlsec1 License ******* From 8b69ae500d82893d13dd545a58467ed35311f742 Mon Sep 17 00:00:00 2001 From: PSala Date: Thu, 30 Jan 2025 17:28:59 +0100 Subject: [PATCH 04/12] Update ci with ubuntu 24 test check --- .github/workflows/install_test.yml | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/install_test.yml b/.github/workflows/install_test.yml index 64ea7551..7bd88145 100644 --- a/.github/workflows/install_test.yml +++ b/.github/workflows/install_test.yml @@ -33,7 +33,7 @@ jobs: printf '1\n' | sudo update-alternatives --config python - name: Install Python 2 on ubuntu >= 22 - if: matrix.python-version == '2.7.18' && matrix.os != 'ubuntu-20.04' + if: matrix.python-version == '2.7.18' && matrix.os == 'ubuntu-22.04' run: | sudo add-apt-repository ppa:deadsnakes/ppa -y sudo apt update @@ -44,6 +44,27 @@ jobs: cd /usr/bin sudo ln -s /usr/bin/pip2 ./pip + - name: Install Python 2 on ubuntu latest + if: matrix.python-version == '2.7.18' && matrix.os == 'ubuntu-24.04' + run: | + sudo apt update + sudo apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev libbz2-dev libsqlite3-dev wget curl + + wget https://www.python.org/ftp/python/2.7.18/Python-2.7.18.tgz + tar -xzf Python-2.7.18.tgz + cd Python-2.7.18 + ./configure --enable-optimizations + make -j$(nproc) + sudo make altinstall + curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py + sudo python2.7 get-pip.py + + sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python2.7 1 + sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2 + printf '1\n' | sudo update-alternatives --config python + cd .. + rm -rf Python-2.7.18 Python-2.7.18.tgz get-pip.py + - name: Set up virtual environment run: | python -m pip install --upgrade pip From 9926890bdaec8956fa4b2ca656da9036065291fb Mon Sep 17 00:00:00 2001 From: PSala Date: Thu, 30 Jan 2025 17:31:05 +0100 Subject: [PATCH 05/12] Update ci with ubuntu 24 test check --- .github/workflows/install_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/install_test.yml b/.github/workflows/install_test.yml index 7bd88145..59f1f5fc 100644 --- a/.github/workflows/install_test.yml +++ b/.github/workflows/install_test.yml @@ -45,7 +45,7 @@ jobs: sudo ln -s /usr/bin/pip2 ./pip - name: Install Python 2 on ubuntu latest - if: matrix.python-version == '2.7.18' && matrix.os == 'ubuntu-24.04' + if: matrix.python-version == '2.7.18' && matrix.os == 'ubuntu-latest' run: | sudo apt update sudo apt install -y build-essential libssl-dev libreadline-dev zlib1g-dev libbz2-dev libsqlite3-dev wget curl From 6e377f82aab74233810108521c3a78837f02a5d1 Mon Sep 17 00:00:00 2001 From: "oleg.hoefling" Date: Sat, 12 Jun 2021 14:06:51 +0200 Subject: [PATCH 06/12] 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 07/12] 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 08/12] 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 09/12] 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 10/12] 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 11/12] 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 12/12] 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(); }