Skip to content

Commit b1ea01d

Browse files
committed
Reflect the encryption_keypairs in the saml client configuration
See also commit 7c82d89 which was reverted for backwards compatibility reasons by commit 5d06014 The original goal was: > Pass proper encryption keys when retrieving the subject NameID > > This requires the latest pysaml2 to work properly, as older versions of > get_subject do not accept the optional keys argument. > > To have this working without this changeset, one should define the > pysaml2 configuration option `encryption_keypairs`. We are now opting the solution without the above changeset (it was reverted) to keep backwards compatibility. Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 5d06014 commit b1ea01d

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/satosa/backends/saml2.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,38 @@ def __init__(self, outgoing, internal_attributes, config, base_url, name):
108108
super().__init__(outgoing, internal_attributes, base_url, name)
109109
self.config = self.init_config(config)
110110

111-
sp_config = SPConfig().load(copy.deepcopy(config[SAMLBackend.KEY_SP_CONFIG]))
112-
self.sp = Saml2Client(sp_config)
113-
114111
self.discosrv = config.get(SAMLBackend.KEY_DISCO_SRV)
115112
self.encryption_keys = []
116113
self.outstanding_queries = {}
117114
self.idp_blacklist_file = config.get('idp_blacklist_file', None)
118115

119-
sp_keypairs = sp_config.getattr('encryption_keypairs', '')
120-
sp_key_file = sp_config.getattr('key_file', '')
121-
if sp_keypairs:
122-
key_file_paths = [pair['key_file'] for pair in sp_keypairs]
123-
elif sp_key_file:
124-
key_file_paths = [sp_key_file]
125-
else:
126-
key_file_paths = []
116+
sp_config = SPConfig().load(copy.deepcopy(config[SAMLBackend.KEY_SP_CONFIG]))
117+
118+
# if encryption_keypairs is defined, use those keys for decryption
119+
# else, if key_file and cert_file are defined, use them for decryption
120+
# otherwise, do not use any decryption key.
121+
# ensure the choice is reflected back in the configuration.
122+
sp_conf_encryption_keypairs = sp_config.getattr('encryption_keypairs', '')
123+
sp_conf_key_file = sp_config.getattr('key_file', '')
124+
sp_conf_cert_file = sp_config.getattr('cert_file', '')
125+
sp_keypairs = (
126+
sp_conf_encryption_keypairs
127+
if sp_conf_encryption_keypairs
128+
else [{'key_file': sp_conf_key_file, 'cert_file': sp_conf_cert_file}]
129+
if sp_conf_key_file and sp_conf_cert_file
130+
else []
131+
)
132+
sp_config.setattr('', 'encryption_keypairs', sp_keypairs)
127133

134+
# load the encryption keys
135+
key_file_paths = [pair['key_file'] for pair in sp_keypairs]
128136
for p in key_file_paths:
129137
with open(p) as key_file:
130138
self.encryption_keys.append(key_file.read())
131139

140+
# finally, initialize the client object
141+
self.sp = Saml2Client(sp_config)
142+
132143
def get_idp_entity_id(self, context):
133144
"""
134145
:type context: satosa.context.Context

0 commit comments

Comments
 (0)