Repository navigation
SignatureError at /saml2/login/ (failed to load external entity) #863
Copy link
Copy link
Open
Labels
Description
I'm using DjangoSaml2 on windows which use pysaml2, i download xmlsec1 and the needed dlls, below error is received when running
Traceback (most recent call last):
File "C:\Program Files\Python310\lib\site-packages\saml2\sigver.py", line 860, in sign_statement
(stdout, stderr, output) = self._run_xmlsec(com_list, [tmp.name])
File "C:\Program Files\Python310\lib\site-packages\saml2\sigver.py", line 933, in _run_xmlsec
raise XmlsecError(errmsg)
During handling of the above exception (returncode=1
error=I/O error : Permission denied
I/O error : Permission denied
I/O warning : failed to load external entity "C:\Users\u\AppData\Local\Temp\tmpi9vlw7gi.xml"
Error: failed to parse xml file "C:\Users\u\AppData\Local\Temp\tmpi9vlw7gi.xml"
Error: failed to load template "C:\Users\u\AppData\Local\Temp\tmpi9vlw7gi.xml"
Error: failed to sign file "C:\Users\u\AppData\Local\Temp\tmpi9vlw7gi.xml"
output=), another exception occurred:
File "C:\Program Files\Python310\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Program Files\Python310\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Program Files\Python310\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Program Files\Python310\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Program Files\Python310\lib\site-packages\djangosaml2\views.py", line 348, in get
session_id, request_xml = client.create_authn_request(
File "C:\Program Files\Python310\lib\site-packages\saml2\client_base.py", line 481, in create_authn_request
msg = self._message(
File "C:\Program Files\Python310\lib\site-packages\saml2\entity.py", line 606, in _message
signed_req = self.sign(
File "C:\Program Files\Python310\lib\site-packages\saml2\entity.py", line 542, in sign
return signed_instance_factory(msg, self.sec, to_sign)
File "C:\Program Files\Python310\lib\site-packages\saml2\sigver.py", line 344, in signed_instance_factory
signed_xml = seccont.sign_statement(
File "C:\Program Files\Python310\lib\site-packages\saml2\sigver.py", line 1786, in sign_statement
return self.crypto.sign_statement(
File "C:\Program Files\Python310\lib\site-packages\saml2\sigver.py", line 862, in sign_statement
raise SignatureError(com_list)
Exception Type: SignatureError at /saml2/login/
Exception Value: ['xmlsec1.exe', '--sign', '--privkey-pem', 'key.pem', '--id-attr:ID', 'urn:oasis:names:tc:SAML:2.0:protocol:AuthnRequest', '--node-id', 'id-Dihqjb9ADFOjG3mvp', '--output', 'C:\\Users\\u\\AppData\\Local\\Temp\\tmpz91m2e_u.xml', 'C:\\Users\\u\\AppData\\Local\\Temp\\tmpi9vlw7gi.xml']
Reactions are currently unavailable
Activity
c00kiemon5ter commentedon Jul 18, 2022
hello, as with IdentityPython/pyXMLSecurity#71 it looks as if the process is not allowed to read files from temporary storage
Is the process allowed to read/write to the filesystem?
Amr-Es commentedon Jul 18, 2022
@c00kiemon5ter it can write to the temp directory, as I can see the file is created but it can't open it for read, when I copy this file from temp dir to another dir I can open it, i tried to run as admin but still same problem
c00kiemon5ter commentedon Jul 18, 2022
ok, I think this goes back to the generic issue of the
NamedTemporaryFilein Python on Windows.Related MR and discussion: #665
henrikek commentedon Oct 4, 2022
I can confirm that I have the same problem "SignatureError" when running djangosaml2 on Windows server 2016.
I see two problems, a general problem is that installing xmlsec1.exe in windows is a bit complex as there are very few builds.
The second problem is that the NamedTemporaryFile function only works in Windows when the temporary files are used by the current Python program and not when calling external programs such as xmlsec1.exe with Popen. This is due to file locks in Windows.
Has anyone come up with a good solution to get this working under Windows?
c00kiemon5ter commentedon Oct 4, 2022
I am guessing everything should work within WSL2 (Windows Subsystem for Linux)
talebi1 commentedon Feb 14, 2023
WSL is not always an option, specifically for embedded python in windows applications.
Until a solution is found, I have monkey patched the _run_xmlsec method to avoid the current issue:
henrikek commentedon Aug 13, 2025
Is it possible to get PR #931 and #933 merged so it can be included in the next release?
SayeedKhan21 commentedon Sep 30, 2025
Hi , i was trying to integrate sso using djangosaml2 that uses pysaml2 under the hood and getting similar error after authenticating from the idp and getting 403 on the /saml2/acs url
`error=Error: xmlSecCryptoAppKeyLoadEx failed: file=C:\Windows\TEMP\tmp3vs3l6v5.pem
Error: failed to load public key from "C:\Windows\TEMP\tmp3vs3l6v5.pem".
Error: keys manager creation failed
`
is above issue related @henrikek @talebi1 ??