added code to keep temporary certificate and xml files for xmlsec processing (controlled by setting ENV var PYSAML2_KEEP_XMLSEC_TMP)
This commit is contained in:
@@ -720,7 +720,7 @@ ASSERT_XPATH = ''.join(["/*[local-name()=\"%s\"]" % v for v in [
|
|||||||
|
|
||||||
class CryptoBackendXmlSec1(CryptoBackend):
|
class CryptoBackendXmlSec1(CryptoBackend):
|
||||||
"""
|
"""
|
||||||
CryptoBackend implementation using external binary xmlsec1 to sign
|
CryptoBackend implementation using external binary 1 to sign
|
||||||
and verify XML documents.
|
and verify XML documents.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -730,6 +730,10 @@ class CryptoBackendXmlSec1(CryptoBackend):
|
|||||||
CryptoBackend.__init__(self, **kwargs)
|
CryptoBackend.__init__(self, **kwargs)
|
||||||
assert (isinstance(xmlsec_binary, basestring))
|
assert (isinstance(xmlsec_binary, basestring))
|
||||||
self.xmlsec = xmlsec_binary
|
self.xmlsec = xmlsec_binary
|
||||||
|
if os.environ.get('PYSAML2_KEEP_XMLSEC_TMP', None):
|
||||||
|
self._xmlsec_delete_tmpfiles = False
|
||||||
|
else:
|
||||||
|
self._xmlsec_delete_tmpfiles = True
|
||||||
|
|
||||||
def version(self):
|
def version(self):
|
||||||
com_list = [self.xmlsec, "--version"]
|
com_list = [self.xmlsec, "--version"]
|
||||||
@@ -831,7 +835,8 @@ class CryptoBackendXmlSec1(CryptoBackend):
|
|||||||
:return: The signed statement
|
:return: The signed statement
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_, fil = make_temp("%s" % statement, decode=False)
|
_, fil = make_temp("%s" % statement, suffix=".xml", decode=False,
|
||||||
|
delete=self._xmlsec_delete_tmpfiles)
|
||||||
|
|
||||||
com_list = [self.xmlsec, "--sign",
|
com_list = [self.xmlsec, "--sign",
|
||||||
"--privkey-pem", key_file,
|
"--privkey-pem", key_file,
|
||||||
@@ -866,7 +871,8 @@ class CryptoBackendXmlSec1(CryptoBackend):
|
|||||||
:param id_attr: Should normally be one of "id", "Id" or "ID"
|
:param id_attr: Should normally be one of "id", "Id" or "ID"
|
||||||
:return: Boolean True if the signature was correct otherwise False.
|
:return: Boolean True if the signature was correct otherwise False.
|
||||||
"""
|
"""
|
||||||
_, fil = make_temp(signedtext, decode=False)
|
_, fil = make_temp(signedtext, suffix=".xml",
|
||||||
|
decode=False, delete=self._xmlsec_delete_tmpfiles)
|
||||||
|
|
||||||
com_list = [self.xmlsec, "--verify",
|
com_list = [self.xmlsec, "--verify",
|
||||||
"--pubkey-cert-%s" % cert_type, cert_file,
|
"--pubkey-cert-%s" % cert_type, cert_file,
|
||||||
@@ -905,7 +911,7 @@ class CryptoBackendXmlSec1(CryptoBackend):
|
|||||||
:param exception: The exception class to raise on errors
|
:param exception: The exception class to raise on errors
|
||||||
:result: Whatever xmlsec wrote to an --output temporary file
|
:result: Whatever xmlsec wrote to an --output temporary file
|
||||||
"""
|
"""
|
||||||
ntf = NamedTemporaryFile()
|
ntf = NamedTemporaryFile(suffix=".xml", delete=self._xmlsec_delete_tmpfiles)
|
||||||
com_list.extend(["--output", ntf.name])
|
com_list.extend(["--output", ntf.name])
|
||||||
com_list += extra_args
|
com_list += extra_args
|
||||||
|
|
||||||
@@ -1242,6 +1248,11 @@ class SecurityContext(object):
|
|||||||
self.template = template
|
self.template = template
|
||||||
|
|
||||||
self.encrypt_key_type = encrypt_key_type
|
self.encrypt_key_type = encrypt_key_type
|
||||||
|
# keep certificate files to debug xmlsec invocations
|
||||||
|
if os.environ.get('PYSAML2_KEEP_XMLSEC_TMP', None):
|
||||||
|
self._xmlsec_delete_tmpfiles = False
|
||||||
|
else:
|
||||||
|
self._xmlsec_delete_tmpfiles = True
|
||||||
|
|
||||||
def correctly_signed(self, xml, must=False):
|
def correctly_signed(self, xml, must=False):
|
||||||
logger.debug("verify correct signature")
|
logger.debug("verify correct signature")
|
||||||
@@ -1333,7 +1344,9 @@ class SecurityContext(object):
|
|||||||
certs = []
|
certs = []
|
||||||
for cert in _certs:
|
for cert in _certs:
|
||||||
if isinstance(cert, basestring):
|
if isinstance(cert, basestring):
|
||||||
certs.append(make_temp(pem_format(cert), ".pem", False))
|
certs.append(make_temp(pem_format(cert), suffix=".pem",
|
||||||
|
decode=False,
|
||||||
|
delete=self._xmlsec_delete_tmpfiles))
|
||||||
else:
|
else:
|
||||||
certs.append(cert)
|
certs.append(cert)
|
||||||
else:
|
else:
|
||||||
@@ -1341,8 +1354,9 @@ class SecurityContext(object):
|
|||||||
|
|
||||||
if not certs and not self.only_use_keys_in_metadata:
|
if not certs and not self.only_use_keys_in_metadata:
|
||||||
logger.debug("==== Certs from instance ====")
|
logger.debug("==== Certs from instance ====")
|
||||||
certs = [make_temp(pem_format(cert), ".pem",
|
certs = [make_temp(pem_format(cert), suffix=".pem",
|
||||||
False) for cert in cert_from_instance(item)]
|
decode=False, delete=self._xmlsec_delete_tmpfiles)
|
||||||
|
for cert in cert_from_instance(item)]
|
||||||
else:
|
else:
|
||||||
logger.debug("==== Certs from metadata ==== %s: %s ====" % (issuer,
|
logger.debug("==== Certs from metadata ==== %s: %s ====" % (issuer,
|
||||||
certs))
|
certs))
|
||||||
@@ -1416,8 +1430,8 @@ class SecurityContext(object):
|
|||||||
the entity that sent the info use that, if not use the key that are in
|
the entity that sent the info use that, if not use the key that are in
|
||||||
the message if any.
|
the message if any.
|
||||||
|
|
||||||
:param decoded_xml: The SAML message as a XML string
|
:param decoded_xml: The SAML message as an XML infoset (a string)
|
||||||
:param msgtype:
|
:param msgtype: SAML protocol message type
|
||||||
:param must: Whether there must be a signature
|
:param must: Whether there must be a signature
|
||||||
:param origdoc:
|
:param origdoc:
|
||||||
:return:
|
:return:
|
||||||
@@ -1434,7 +1448,7 @@ class SecurityContext(object):
|
|||||||
|
|
||||||
if not msg.signature:
|
if not msg.signature:
|
||||||
if must:
|
if must:
|
||||||
raise SignatureError("Missing must signature")
|
raise SignatureError("Required signature missing on %s" % msgtype)
|
||||||
else:
|
else:
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user