Skip to content

Commit 6787ce4

Browse files
author
Roland Hedberg
committed
Looks at the Popen returncode.
1 parent b3a7db9 commit 6787ce4

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/saml2/entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ def _response(self, in_response_to, consumer_url=None, status=None,
543543
if to_sign:
544544
signed_instance_factory(response, self.sec, to_sign)
545545
else:
546+
# default is to sign the whole response if anything
546547
sign_class = [(class_name(response), response.id)]
547548
return signed_instance_factory(response, self.sec,
548549
sign_class)

src/saml2/sigver.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,8 @@ def sign_statement(self, statement, node_name, key_file, node_id,
847847
com_list.extend(["--node-id", node_id])
848848

849849
try:
850-
(stdout, stderr, signed_statement) = \
851-
self._run_xmlsec(com_list, [fil], validate_output=False)
850+
(stdout, stderr, signed_statement) = self._run_xmlsec(
851+
com_list, [fil], validate_output=False)
852852
# this doesn't work if --store-signatures are used
853853
if stdout == "":
854854
if signed_statement:
@@ -924,12 +924,17 @@ def _run_xmlsec(self, com_list, extra_args, validate_output=True,
924924

925925
p_out = pof.stdout.read()
926926
p_err = pof.stderr.read()
927+
928+
if pof.returncode is not None and pof.returncode < 0:
929+
logger.error(LOG_LINE % (p_out, p_err))
930+
raise XmlsecError("%d:%s" % (pof.returncode, p_err))
931+
927932
try:
928933
if validate_output:
929934
parse_xmlsec_output(p_err)
930935
except XmlsecError, exc:
931936
logger.error(LOG_LINE_2 % (p_out, p_err, exc))
932-
raise exception("%s" % (exc,))
937+
raise
933938

934939
ntf.seek(0)
935940
return p_out, p_err, ntf.read()

tests/test_40_sigver.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22

33
import base64
4-
from saml2.sigver import pre_encryption_part, make_temp
4+
from saml2.sigver import pre_encryption_part, make_temp, XmlsecError
55
from saml2.mdstore import MetadataStore
66
from saml2.saml import assertion_from_string, EncryptedAssertion
77
from saml2.samlp import response_from_string
@@ -438,7 +438,8 @@ def test_xbox():
438438
)
439439

440440
sigass = sec.sign_statement(assertion, class_name(assertion),
441-
key_file=full_path("test.key"), node_id=assertion.id)
441+
key_file=full_path("test.key"),
442+
node_id=assertion.id)
442443

443444
_ass0 = saml.assertion_from_string(sigass)
444445

@@ -471,7 +472,38 @@ def test_xbox():
471472
print assertions
472473

473474

475+
def test_xmlsec_err():
476+
conf = config.SPConfig()
477+
conf.load_file("server_conf")
478+
md = MetadataStore([saml, samlp], None, conf)
479+
md.load("local", full_path("idp_example.xml"))
480+
481+
conf.metadata = md
482+
conf.only_use_keys_in_metadata = False
483+
sec = sigver.security_context(conf)
484+
485+
assertion = factory(
486+
saml.Assertion, version="2.0", id="11111",
487+
issue_instant="2009-10-30T13:20:28Z",
488+
signature=sigver.pre_signature_part("11111", sec.my_cert, 1),
489+
attribute_statement=do_attribute_statement(
490+
{("", "", "surName"): ("Foo", ""),
491+
("", "", "givenName"): ("Bar", ""), })
492+
)
493+
494+
try:
495+
sec.sign_statement(assertion, class_name(assertion),
496+
key_file=full_path("tes.key"),
497+
node_id=assertion.id)
498+
except XmlsecError as err: # should throw an exception
499+
pass
500+
else:
501+
assert False
502+
503+
474504
if __name__ == "__main__":
475-
t = TestSecurity()
476-
t.setup_class()
477-
t.test_non_verify_2()
505+
# t = TestSecurity()
506+
# t.setup_class()
507+
# t.test_non_verify_2()
508+
509+
test_xbox()

0 commit comments

Comments
 (0)