我遇到了必须签名一些数据并通过TCP套接字将其发送到客户端的情况。
所以在服务器上,我使用xmlsign对其进行签名并以字符串形式发送
#in server
signed_xml_obj = XMLSigner().sign(root, key=PRIVATEKEY)
xml_str = ElementTree.tostring(signed_xml_obj)
#sendtoclient(xml_str)
在客户端中,从字符串创建ElementTree.Element并尝试对其进行验证,但失败
#somewhere in client
signed_xml_obj = ElementTree.fromstring(signiautreString)
XMLVerifier().verify(signed_xml_obj, x509_cert=cer)
追踪
Traceback (most recent call last):
File "/eltioni/.local/lib/python3.7/site-packages/signxml/__init__.py", line 729, in verify
verify(signing_cert, raw_signature, signed_info_c14n, signature_digest_method)
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 2928, in verify
_raise_current_error()
File "/usr/lib/python3/dist-packages/OpenSSL/_util.py", line 54, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.crypto.Error: [('rsa routines', 'int_rsa_verify', 'bad signature')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "sig.py", line 15, in <module>
XMLVerifier().verify(xml2, x509_cert=cert)
File "/eltioni/.local/lib/python3.7/site-packages/signxml/__init__.py", line 735, in verify
raise InvalidSignature("Signature verification failed: {}".format(reason))
signxml.exceptions.InvalidSignature: Signature verification failed: bad signature
我还注意到,当我在服务器上打印signed_xml_obj时,我得到了
print(signed_xml_obj)
#<Element Student at 0x7ff94085f188>
当我在客户端中打印signed_xml_obj时,我得到“学生”(带引号)
print(signed_xml_obj)
#<Element 'Student' at 0x7ff94085f188>