Skip to content

Commit

Permalink
Add compatibility with xmlsec 1.3 (#1)
Browse files Browse the repository at this point in the history
* Add compatibility for xmlsec 1.3
* fix 1.2 compatibility
* update isort to fix poetry error in pre-commit
---------
Co-authored-by: David Adamec <[email protected]>
  • Loading branch information
brennanneoh authored Feb 16, 2024
1 parent 1563947 commit ef0e742
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
exclude: ^setup.py$
additional_dependencies: [flake8-docstrings, flake8-bugbear, flake8-logging-format, flake8-builtins, flake8-eradicate, flake8-fixme, pep8-naming, flake8-pep3101, flake8-annotations-complexity,flake8-pyi]
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
Expand Down
6 changes: 0 additions & 6 deletions doc/source/modules/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,6 @@ Namespaces
.. data:: xmlsec.constants.XPointerNs
:annotation: = 'http://www.w3.org/2001/04/xmldsig-more/xptr'

.. data:: xmlsec.constants.Soap11Ns
:annotation: = 'http://schemas.xmlsoap.org/soap/envelope/'

.. data:: xmlsec.constants.Soap12Ns
:annotation: = 'http://www.w3.org/2002/06/soap-envelope'

.. data:: xmlsec.constants.NsExcC14N
:annotation: = 'http://www.w3.org/2001/10/xml-exc-c14n#'

Expand Down
2 changes: 0 additions & 2 deletions src/constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
PYXMLSEC_ADD_NS_CONSTANT(XPathNs, "XPATH");
PYXMLSEC_ADD_NS_CONSTANT(XPath2Ns, "XPATH2");
PYXMLSEC_ADD_NS_CONSTANT(XPointerNs, "XPOINTER");
PYXMLSEC_ADD_NS_CONSTANT(Soap11Ns, "SOAP11");
PYXMLSEC_ADD_NS_CONSTANT(Soap12Ns, "SOAP12");
PYXMLSEC_ADD_NS_CONSTANT(NsExcC14N, "EXC_C14N");
PYXMLSEC_ADD_NS_CONSTANT(NsExcC14NWithComments, "EXC_C14N_WITH_COMMENT");

Expand Down
12 changes: 12 additions & 0 deletions src/enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
#include <xmlsec/xmlenc.h>
#include <xmlsec/xmltree.h>

// Backwards compatibility with xmlsec 1.2
#ifndef XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH
#define XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH 0x00008000
#endif

typedef struct {
PyObject_HEAD
xmlSecEncCtxPtr handle;
Expand Down Expand Up @@ -50,6 +55,13 @@ static int PyXmlSec_EncryptionContext__init__(PyObject* self, PyObject* args, Py
}
ctx->manager = manager;
PYXMLSEC_DEBUGF("%p: init enc context - ok, manager - %p", self, manager);

// xmlsec 1.3 changed the key search to strict mode, causing various examples
// in the docs to fail. For backwards compatibility, this changes it back to
// lax mode for now.
ctx->handle->keyInfoReadCtx.flags = XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH;
ctx->handle->keyInfoWriteCtx.flags = XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH;

return 0;
ON_FAIL:
PYXMLSEC_DEBUGF("%p: init enc context - failed", self);
Expand Down
2 changes: 0 additions & 2 deletions src/xmlsec/constants.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ NodeX509Data: Final[str]
Ns: Final[str]
NsExcC14N: Final[str]
NsExcC14NWithComments: Final[str]
Soap11Ns: Final[str]
Soap12Ns: Final[str]
TransformAes128Cbc: Final[__Transform]
TransformAes128Gcm: Final[__Transform]
TransformAes192Cbc: Final[__Transform]
Expand Down

0 comments on commit ef0e742

Please sign in to comment.