python - Signxml 验证失败
问题描述
我有一个场景,我必须签署一些数据并通过 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>
解决方案
推荐阅读
- javascript - 将 Promise 返回的值压入数组
- python - MacOS 上的 Pipenv 问题“TypeError: 'module' object is not callable”
- php - 在 WordPress 插件激活时创建表(样板文件)
- html - 具有行/列操作的 ng-repeat 中的 Angularjs Contenteditable
- c - 基数排序 C 的分段错误
- java - TestNG:如何从多个类中指定测试方法顺序?
- php - 在 laravel 中验证图像部分工作
- php - jQuery Ajax 调用中的 Foreach 循环
- plot - 如何在交易视图的 PINE 图中使用不同的字符串文字?
- scala - Scala模板如何同时循环两个列表