Skip to content

Commit d038e06

Browse files
committed
Do not embed the cert in the EncryptedData element
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent fc6e532 commit d038e06

File tree

3 files changed

+21
-27
lines changed

3 files changed

+21
-27
lines changed

src/saml2/entity.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -657,21 +657,14 @@ def _encrypt_assertion(self, encrypt_cert, sp_entity_id, response, node_xpath=No
657657
for _cert in _certs:
658658
wrapped_cert, unwrapped_cert = get_pem_wrapped_unwrapped(_cert)
659659
try:
660-
tmp = make_temp(wrapped_cert.encode('ascii'),
661-
decode=False,
662-
delete_tmpfiles=self.config.delete_tmpfiles)
663-
664-
# it would be possibile to handle many other args here ...
665-
pre_enc_part_dict = dict()
666-
if encrypt_cert:
667-
pre_enc_part_dict['encrypt_cert'] = unwrapped_cert
668-
pre_enc_part = pre_encryption_part(**pre_enc_part_dict)
669-
# end pre_enc_part
670-
671-
672-
response = self.sec.encrypt_assertion(response, tmp.name,
673-
pre_enc_part,
674-
node_xpath=node_xpath)
660+
tmp = make_temp(
661+
wrapped_cert.encode('ascii'),
662+
decode=False,
663+
delete_tmpfiles=self.config.delete_tmpfiles,
664+
)
665+
response = self.sec.encrypt_assertion(
666+
response, tmp.name, pre_encryption_part(), node_xpath=node_xpath
667+
)
675668
return response
676669
except Exception as ex:
677670
exception = ex

src/saml2/sigver.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,7 @@ def pre_signature_part(
18441844
if identifier:
18451845
signature.id = 'Signature{n}'.format(n=identifier)
18461846

1847+
# XXX remove - do not embed the cert
18471848
if public_key:
18481849
x509_data = ds.X509Data(
18491850
x509_certificate=[ds.X509Certificate(text=public_key)])
@@ -1881,10 +1882,13 @@ def pre_signature_part(
18811882
# </EncryptedData>
18821883

18831884

1884-
def pre_encryption_part(msg_enc=TRIPLE_DES_CBC, key_enc=RSA_OAEP_MGF1P,
1885-
key_name='my-rsa-key',
1886-
encrypted_key_id=None, encrypted_data_id=None,
1887-
encrypt_cert=None):
1885+
def pre_encryption_part(
1886+
msg_enc=TRIPLE_DES_CBC,
1887+
key_enc=RSA_OAEP_MGF1P,
1888+
key_name='my-rsa-key',
1889+
encrypted_key_id=None,
1890+
encrypted_data_id=None,
1891+
):
18881892
"""
18891893
18901894
:param msg_enc:
@@ -1896,12 +1900,8 @@ def pre_encryption_part(msg_enc=TRIPLE_DES_CBC, key_enc=RSA_OAEP_MGF1P,
18961900
ed_id = encrypted_data_id or "ED_{id}".format(id=gen_random_key())
18971901
msg_encryption_method = EncryptionMethod(algorithm=msg_enc)
18981902
key_encryption_method = EncryptionMethod(algorithm=key_enc)
1899-
1900-
enc_key_dict= dict(key_name=ds.KeyName(text=key_name))
1901-
enc_key_dict['x509_data'] = ds.X509Data(
1902-
x509_certificate=ds.X509Certificate(text=encrypt_cert))
1903-
key_info = ds.KeyInfo(**enc_key_dict)
1904-
1903+
key_info = ds.KeyInfo(key_name=ds.KeyName(text=key_name))
1904+
19051905
encrypted_key = EncryptedKey(
19061906
id=ek_id,
19071907
encryption_method=key_encryption_method,
@@ -1914,7 +1914,8 @@ def pre_encryption_part(msg_enc=TRIPLE_DES_CBC, key_enc=RSA_OAEP_MGF1P,
19141914
type='http://www.w3.org/2001/04/xmlenc#Element',
19151915
encryption_method=msg_encryption_method,
19161916
key_info=key_info,
1917-
cipher_data=CipherData(cipher_value=CipherValue(text='')))
1917+
cipher_data=CipherData(cipher_value=CipherValue(text='')),
1918+
)
19181919
return encrypted_data
19191920

19201921

tests/test_42_enc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
__author__ = 'roland'
1414

15-
TMPL_NO_HEADER = """<ns0:EncryptedData xmlns:ns0="http://www.w3.org/2001/04/xmlenc#" xmlns:ns1="http://www.w3.org/2000/09/xmldsig#" Id="{ed_id}" Type="http://www.w3.org/2001/04/xmlenc#Element"><ns0:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /><ns1:KeyInfo><ns0:EncryptedKey Id="{ek_id}"><ns0:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" /><ns1:KeyInfo><ns1:KeyName>my-rsa-key</ns1:KeyName><ns1:X509Data><ns1:X509Certificate /></ns1:X509Data></ns1:KeyInfo><ns0:CipherData><ns0:CipherValue /></ns0:CipherData></ns0:EncryptedKey></ns1:KeyInfo><ns0:CipherData><ns0:CipherValue /></ns0:CipherData></ns0:EncryptedData>"""
15+
TMPL_NO_HEADER = """<ns0:EncryptedData xmlns:ns0="http://www.w3.org/2001/04/xmlenc#" xmlns:ns1="http://www.w3.org/2000/09/xmldsig#" Id="{ed_id}" Type="http://www.w3.org/2001/04/xmlenc#Element"><ns0:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" /><ns1:KeyInfo><ns0:EncryptedKey Id="{ek_id}"><ns0:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" /><ns1:KeyInfo><ns1:KeyName>my-rsa-key</ns1:KeyName></ns1:KeyInfo><ns0:CipherData><ns0:CipherValue /></ns0:CipherData></ns0:EncryptedKey></ns1:KeyInfo><ns0:CipherData><ns0:CipherValue /></ns0:CipherData></ns0:EncryptedData>"""
1616
TMPL = f"<?xml version='1.0' encoding='UTF-8'?>\n{TMPL_NO_HEADER}"
1717

1818
IDENTITY = {"eduPersonAffiliation": ["staff", "member"],

0 commit comments

Comments
 (0)