Skip to content

Commit d1c71d7

Browse files
committed
Merge in IdentityPython#634 into our branch and
fix conflicts and the like
1 parent 78e71b3 commit d1c71d7

File tree

7 files changed

+120
-116
lines changed

7 files changed

+120
-116
lines changed

docs/howto/config.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The basic structure of the configuration file is therefore like this::
3434
"key_file" : "my.key",
3535
"cert_file" : "ca.pem",
3636
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
37+
"delete_tmpfiles": True,
3738
"metadata": {
3839
"local": ["edugain.xml"],
3940
},
@@ -283,6 +284,17 @@ Example::
283284

284285
"xmlsec_binary": "/usr/local/bin/xmlsec1",
285286

287+
delete_tmpfiles
288+
^^^^^^^^^^^^^^^
289+
290+
In many cases temporary files will have to be created during the
291+
encryption/decryption/signing/validation process.
292+
This option defines whether these temporary files will be automatically deleted when
293+
they are no longer needed. Setting this to False, will keep these files until they are
294+
manually deleted or automatically deleted by the OS (i.e Linux rules for /tmp).
295+
Absence of this option, defaults to True.
296+
297+
286298
valid_for
287299
^^^^^^^^^
288300

@@ -756,6 +768,7 @@ We start with a simple but fairly complete Service provider configuration::
756768
"key_file" : "./mykey.pem",
757769
"cert_file" : "./mycert.pem",
758770
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
771+
"delete_tmpfiles": True,
759772
"attribute_map_dir": "./attributemaps",
760773
"metadata": {
761774
"local": ["idp.xml"]
@@ -804,6 +817,7 @@ A slightly more complex configuration::
804817
"key_file" : "./mykey.pem",
805818
"cert_file" : "./mycert.pem",
806819
"xmlsec_binary" : "/usr/local/bin/xmlsec1",
820+
"delete_tmpfiles": True,
807821
"metadata" : {
808822
"local": ["example.xml"],
809823
"remote": [{

src/saml2/config.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"allow_unknown_attributes",
6868
"crypto_backend",
6969
"id_attr_name",
70+
"delete_tmpfiles",
7071
]
7172

7273
SP_ARGS = [
@@ -238,6 +239,7 @@ def __init__(self, homedir="."):
238239
self.attribute = []
239240
self.attribute_profile = []
240241
self.requested_attribute_name_format = NAME_FORMAT_URI
242+
self.delete_tmpfiles = True
241243

242244
def setattr(self, context, attr, val):
243245
if context == "":
@@ -353,6 +355,12 @@ def load(self, cnf, metadata_construction=False):
353355
except TypeError: # Something that can't be a string
354356
setattr(self, arg, cnf[arg])
355357

358+
if not self.delete_tmpfiles:
359+
logger.warning(
360+
"delete_tmpfiles is set to False; "
361+
"temporary files will not be deleted."
362+
)
363+
356364
if "service" in cnf:
357365
for typ in ["aa", "idp", "sp", "pdp", "aq"]:
358366
try:

src/saml2/entity.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ def __init__(self, entity_type, config=None, config_file="",
143143
if _val.startswith("http"):
144144
r = requests.request("GET", _val)
145145
if r.status_code == 200:
146-
_, filename = make_temp(r.text, ".pem", False)
147-
setattr(self.config, item, filename)
146+
tmp = make_temp(r.text, ".pem", False, self.config.delete_tmpfiles)
147+
setattr(self.config, item, tmp.name)
148148
else:
149149
raise Exception(
150150
"Could not fetch certificate from %s" % _val)
@@ -567,8 +567,10 @@ def _encrypt_assertion(self, encrypt_cert, sp_entity_id, response,
567567
_cert = "%s%s" % (begin_cert, _cert)
568568
if end_cert not in _cert:
569569
_cert = "%s%s" % (_cert, end_cert)
570-
_, cert_file = make_temp(_cert.encode('ascii'), decode=False)
571-
response = self.sec.encrypt_assertion(response, cert_file,
570+
tmp = make_temp(_cert.encode('ascii'),
571+
decode=False,
572+
delete_tmpfiles=self.config.delete_tmpfiles)
573+
response = self.sec.encrypt_assertion(response, tmp.name,
572574
pre_encryption_part(),
573575
node_xpath=node_xpath)
574576
return response

0 commit comments

Comments
 (0)