Skip to content

Commit 6c90fe7

Browse files
authored
Merge branch 'master' into 164-pkcs11-support
2 parents 4f5daea + a4e135a commit 6c90fe7

File tree

10 files changed

+33
-246
lines changed

10 files changed

+33
-246
lines changed

Diff for: .pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ repos:
3131
exclude: ^setup.py$
3232
additional_dependencies: [flake8-docstrings, flake8-bugbear, flake8-logging-format, flake8-builtins, flake8-eradicate, flake8-fixme, pep8-naming, flake8-pep3101, flake8-annotations-complexity,flake8-pyi]
3333
- repo: https://github.com/PyCQA/isort
34-
rev: 5.11.5
34+
rev: 5.12.0
3535
hooks:
3636
- id: isort
3737
- repo: https://github.com/pre-commit/mirrors-mypy

Diff for: doc/source/modules/constants.rst

+1-7
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ KeyData
4747

4848
The DSA key klass.
4949

50-
.. data:: xmlsec.constants.KeyDataEcdsa
50+
.. data:: xmlsec.constants.KeyDataEc
5151

5252
The ECDSA key klass.
5353

@@ -166,12 +166,6 @@ Namespaces
166166
.. data:: xmlsec.constants.XPointerNs
167167
:annotation: = 'http://www.w3.org/2001/04/xmldsig-more/xptr'
168168

169-
.. data:: xmlsec.constants.Soap11Ns
170-
:annotation: = 'http://schemas.xmlsoap.org/soap/envelope/'
171-
172-
.. data:: xmlsec.constants.Soap12Ns
173-
:annotation: = 'http://www.w3.org/2002/06/soap-envelope'
174-
175169
.. data:: xmlsec.constants.NsExcC14N
176170
:annotation: = 'http://www.w3.org/2001/10/xml-exc-c14n#'
177171

Diff for: setup.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def run(self):
8686
ext = self.ext_map['xmlsec']
8787
self.debug = os.environ.get('PYXMLSEC_ENABLE_DEBUG', False)
8888
self.static = os.environ.get('PYXMLSEC_STATIC_DEPS', False)
89+
self.size_opt = os.environ.get('PYXMLSEC_OPTIMIZE_SIZE', True)
8990

9091
if self.static or sys.platform == 'win32':
9192
self.info('starting static build on {}'.format(sys.platform))
@@ -153,11 +154,18 @@ def run(self):
153154
)
154155

155156
if self.debug:
156-
ext.extra_compile_args.append('-Wall')
157-
ext.extra_compile_args.append('-O0')
158157
ext.define_macros.append(('PYXMLSEC_ENABLE_DEBUG', '1'))
158+
if sys.platform == 'win32':
159+
ext.extra_compile_args.append('/Od')
160+
else:
161+
ext.extra_compile_args.append('-Wall')
162+
ext.extra_compile_args.append('-O0')
159163
else:
160-
ext.extra_compile_args.append('-Os')
164+
if self.size_opt:
165+
if sys.platform == 'win32':
166+
ext.extra_compile_args.append('/Os')
167+
else:
168+
ext.extra_compile_args.append('-Os')
161169

162170
super(build_ext, self).run()
163171

Diff for: src/common.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "debug.h"
1414

1515
#ifndef MODULE_NAME
16-
#define MODULE_NAME "xmlsec"
16+
#define MODULE_NAME xmlsec
1717
#endif
1818

1919
#define JOIN(X,Y) DO_JOIN1(X,Y)

Diff for: src/constants.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,6 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
316316
PYXMLSEC_ADD_NS_CONSTANT(XPathNs, "XPATH");
317317
PYXMLSEC_ADD_NS_CONSTANT(XPath2Ns, "XPATH2");
318318
PYXMLSEC_ADD_NS_CONSTANT(XPointerNs, "XPOINTER");
319-
PYXMLSEC_ADD_NS_CONSTANT(Soap11Ns, "SOAP11");
320-
PYXMLSEC_ADD_NS_CONSTANT(Soap12Ns, "SOAP12");
321319
PYXMLSEC_ADD_NS_CONSTANT(NsExcC14N, "EXC_C14N");
322320
PYXMLSEC_ADD_NS_CONSTANT(NsExcC14NWithComments, "EXC_C14N_WITH_COMMENT");
323321

@@ -441,13 +439,15 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
441439
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataRetrievalMethod, "RETRIEVALMETHOD")
442440
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEncryptedKey, "ENCRYPTEDKEY")
443441
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataAes, "AES")
442+
#ifndef XMLSEC_NO_DES
444443
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataDes, "DES")
444+
#endif
445445
#ifndef XMLSEC_NO_DSA
446446
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataDsa, "DSA")
447447
#endif
448448
#if XMLSEC_VERSION_HEX > 0x10212
449449
// from version 1.2.19
450-
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEcdsa, "ECDSA")
450+
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataEc, "ECDSA")
451451
#endif
452452
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataHmac, "HMAC")
453453
PYXMLSEC_ADD_KEYDATA_CONSTANT(KeyDataRsa, "RSA")
@@ -489,8 +489,10 @@ int PyXmlSec_ConstantsModule_Init(PyObject* package) {
489489
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformKWAes192, "KW_AES192");
490490
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformKWAes256, "KW_AES256");
491491

492+
#ifndef XMLSEC_NO_DES
492493
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformDes3Cbc, "DES3");
493494
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformKWDes3, "KW_DES3");
495+
#endif
494496
#ifndef XMLSEC_NO_DSA
495497
PYXMLSEC_ADD_TRANSFORM_CONSTANT(TransformDsaSha1, "DSA_SHA1");
496498
#endif

Diff for: src/enc.c

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
#include <xmlsec/xmlenc.h>
1818
#include <xmlsec/xmltree.h>
1919

20+
// Backwards compatibility with xmlsec 1.2
21+
#ifndef XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH
22+
#define XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH 0x00008000
23+
#endif
24+
2025
typedef struct {
2126
PyObject_HEAD
2227
xmlSecEncCtxPtr handle;
@@ -50,6 +55,13 @@ static int PyXmlSec_EncryptionContext__init__(PyObject* self, PyObject* args, Py
5055
}
5156
ctx->manager = manager;
5257
PYXMLSEC_DEBUGF("%p: init enc context - ok, manager - %p", self, manager);
58+
59+
// xmlsec 1.3 changed the key search to strict mode, causing various examples
60+
// in the docs to fail. For backwards compatibility, this changes it back to
61+
// lax mode for now.
62+
ctx->handle->keyInfoReadCtx.flags = XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH;
63+
ctx->handle->keyInfoWriteCtx.flags = XMLSEC_KEYINFO_FLAGS_LAX_KEY_SEARCH;
64+
5365
return 0;
5466
ON_FAIL:
5567
PYXMLSEC_DEBUGF("%p: init enc context - failed", self);

Diff for: src/keys.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static PyObject* PyXmlSec_KeyFromFile(PyObject* self, PyObject* args, PyObject*
163163
if (is_content) {
164164
key->handle = xmlSecCryptoAppKeyLoadMemory((const xmlSecByte*)data, (xmlSecSize)data_size, format, password, NULL, NULL);
165165
} else {
166-
key->handle = xmlSecCryptoAppKeyLoad(data, format, password, NULL, NULL);
166+
key->handle = xmlSecCryptoAppKeyLoadEx(data, xmlSecKeyDataTypePrivate, format, password, NULL, NULL);
167167
}
168168
Py_END_ALLOW_THREADS;
169169

Diff for: src/xmlsec/constants.pyi

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ EncNs: Final[str]
2929
KeyDataAes: Final[__KeyData]
3030
KeyDataDes: Final[__KeyData]
3131
KeyDataDsa: Final[__KeyData]
32-
KeyDataEcdsa: Final[__KeyData]
32+
KeyDataEc: Final[__KeyData]
3333
KeyDataEncryptedKey: Final[__KeyData]
3434
KeyDataFormatBinary: Final[int]
3535
KeyDataFormatCertDer: Final[int]
@@ -85,8 +85,6 @@ NodeX509Data: Final[str]
8585
Ns: Final[str]
8686
NsExcC14N: Final[str]
8787
NsExcC14NWithComments: Final[str]
88-
Soap11Ns: Final[str]
89-
Soap12Ns: Final[str]
9088
TransformAes128Cbc: Final[__Transform]
9189
TransformAes128Gcm: Final[__Transform]
9290
TransformAes192Cbc: Final[__Transform]

Diff for: tests/data/enc-bad-in.xml

-208
This file was deleted.

Diff for: tests/test_enc.py

-19
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,3 @@ def test_decrypt_bad_args(self):
233233
ctx = xmlsec.EncryptionContext()
234234
with self.assertRaises(TypeError):
235235
ctx.decrypt('')
236-
237-
def check_no_segfault(self):
238-
namespaces = {'soap': 'http://schemas.xmlsoap.org/soap/envelope/'}
239-
240-
manager = xmlsec.KeysManager()
241-
key = xmlsec.Key.from_file(self.path("rsacert.pem"), format=consts.KeyDataFormatCertPem)
242-
manager.add_key(key)
243-
template = self.load_xml('enc-bad-in.xml')
244-
enc_data = xmlsec.template.encrypted_data_create(
245-
template, xmlsec.Transform.AES128, type=xmlsec.EncryptionType.CONTENT, ns='xenc'
246-
)
247-
xmlsec.template.encrypted_data_ensure_cipher_value(enc_data)
248-
key_info = xmlsec.template.encrypted_data_ensure_key_info(enc_data, ns='dsig')
249-
enc_key = xmlsec.template.add_encrypted_key(key_info, xmlsec.Transform.RSA_PKCS1)
250-
xmlsec.template.encrypted_data_ensure_cipher_value(enc_key)
251-
data = template.find('soap:Body', namespaces=namespaces)
252-
enc_ctx = xmlsec.EncryptionContext(manager)
253-
enc_ctx.key = xmlsec.Key.generate(xmlsec.KeyData.AES, 192, xmlsec.KeyDataType.SESSION)
254-
self.assertRaises(Exception, enc_ctx.encrypt_xml(enc_data, data))

0 commit comments

Comments
 (0)