Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception Value: Invalid input object: Element #19

Closed
nick210 opened this issue Jul 27, 2015 · 7 comments
Closed

Exception Value: Invalid input object: Element #19

nick210 opened this issue Jul 27, 2015 · 7 comments

Comments

@nick210
Copy link

nick210 commented Jul 27, 2015

Dear all,

I am trying to validate an xml signature (saml token) using signxml.
I am using the following code:

cert=open("/path_to_pem_file").read()
root=ElementTree.fromstring(saml_xml_token)
assertion_data=xmldsig(root)verify(x509_cert=cert)

And the last command xmldsig(root)verify(x509_cert=cert) gives me the following error: Invalid input object: Element

The full stack trace is the following:

Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    1.   assertion_data=xmldsig(root).verify()
      
      File "/usr/local/lib/python2.7/dist-packages/signxml/init.py" in verify
  2.         _get_schema().assertValid(signature)
    

Exception Type: TypeError at /model_app/trySaml/
Exception Value: Invalid input object: Element

Do you have any idea what could be wrong with the code?

Thank you,
Nick

@kislyuk
Copy link
Member

kislyuk commented Jul 27, 2015

Can you please paste the actual full stack trace, with line numbers, etc.? You seem to have deleted a whole bunch of text from the stack trace. To format it, surround it with triple backtick quotes each on their own line: ```

@nick210
Copy link
Author

nick210 commented Jul 27, 2015

Dear kislyul,

Thank you very much for your quick response and your help.

Please find below the stack trace with line numbers. Having searched the trace,this is all the information which is related to the signxml library. Anything else is django related, etc.

Traceback:
''' File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response '''
''' 111. response = wrapped_callback(request, _callback_args, *_callback_kwargs) '''
''' File "django related file" in trySaml" '''
''' 225. assertion_data=xmldsig(root).verify() '''
''' File "/usr/local/lib/python2.7/dist-packages/signxml/init.py" in verify '''
''' 579. _get_schema().assertValid(signature) '''

Exception Type: TypeError at /model_app/trySaml/
Exception Value: Invalid input object: Element

I hope this will help :-)

Best regards,
Nikolaos Tousert

@kislyuk
Copy link
Member

kislyuk commented Jul 27, 2015

Please take a closer look at your message. I need the full stack trace down to the specific line where the error occurred, and including line numbers. Take a look at https://guides.github.com/features/mastering-markdown/ for help with how to format your message. You are not formatting it correctly, and as a result, the relevant information including line numbers is not being displayed.

@nick210
Copy link
Author

nick210 commented Jul 27, 2015

Dear kislyuk,

I updated my previous comment with the line numbers.
Please let me know if it is now correct.

Thank you,
Nick

@nickcash
Copy link

nickcash commented Aug 4, 2015

For what it's worth, I also experienced this problem when using the stdlib xml.etree.ElementTree instead of the lxml version thereof, which is what I think @nick210 is experiencing. My use case is signing rather than verifying, but here's the code to recreate it:

import signxml,  xml.etree.ElementTree, lxml.etree

x = "<foo><bar></bar></foo>"
root1=xml.etree.ElementTree.fromstring(x)
root2=lxml.etree.fromstring(x)

>>> signxml.xmldsig(root1).sign(key=key, cert=cert)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/signxml/__init__.py", line 326, in sign
    self._get_payload_c14n(method, c14n_algorithm=c14n_algorithm)
  File "/usr/local/lib/python2.7/dist-packages/signxml/__init__.py", line 219, in _get_payload_c14n
    self.payload_c14n = self._c14n(self.payload, algorithm=c14n_algorithm)
  File "/usr/local/lib/python2.7/dist-packages/signxml/__init__.py", line 260, in _c14n
    inclusive_ns_prefixes=inclusive_ns_prefixes)
  File "lxml.etree.pyx", line 3201, in lxml.etree.tostring (src/lxml/lxml.etree.c:71561)
  File "serializer.pxi", line 164, in lxml.etree._tostringC14N (src/lxml/lxml.etree.c:119021)
  File "apihelpers.pxi", line 46, in lxml.etree._documentOrRaise (src/lxml/lxml.etree.c:14374)
TypeError: Invalid input object: Element
#Oh noes!

>>> signxml.xmldsig(root2).sign(key=key, cert=cert)
<Element foo at 0x7f7b7bbe7cb0>
#Everything went okay!

I think it can probably just be documented to use lxml.

@nickcash
Copy link

nickcash commented Aug 4, 2015

Interestingly in Python3.4, the same thing occurs but with a different (perhaps misleading) error message:

>>> signxml.xmldsig(root1).sign(key=key, cert=cert)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.4/dist-packages/signxml/__init__.py", line 326, in sign
    self._get_payload_c14n(method, c14n_algorithm=c14n_algorithm)
  File "/usr/local/lib/python3.4/dist-packages/signxml/__init__.py", line 200, in _get_payload_c14n
    self.payload.append(self.sig_root)
TypeError: must be xml.etree.ElementTree.Element, not lxml.etree._Element

@kislyuk kislyuk closed this as completed in 0ebdd63 Aug 7, 2015
@kislyuk
Copy link
Member

kislyuk commented Aug 7, 2015

Thank you for tracking this down, @nickcash. Fix released in v0.4.4. Please test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants