如果证书本身未安装在工作站上但仅用于签署该特定文件,是否可以以某种方式以编程方式导出文件的数字证书主题?
我需要以某种方式从文件中提取该信息并检查它是否正确。最好使用Python/CMD/PowerShell
编辑:
抱歉缺少详细信息。
我目前正在使用这个 python 脚本(我修改为在 Python 3.6 上运行):http://www.zedwood.com/article/python-openssl-x509-parse-certificate来解析我从中提取的 .cer 文件我找到的带有这个小工具的原始可执行文件(我还对其进行了修改以与 Python 3 一起使用): https: //blog.didierstevens.com/programs/disitool/但只有在我将其从 DER 编码的二进制文件转换之后使用 Windows certutil 转换为 base-64。
不过,disitool 脚本的问题在于,它使用 pefile python 模块从可执行文件本身中剪切了一个“签名”字节数组,这使得提取的 .cer 文件无效,正如我在尝试执行操作时不断收到的 python 错误一样使用 OpenSSL.crypto 模块加载证书:
[('asn1 encoding routines', 'asn1_check_tlen', 'wrong tag'), ('asn1 encoding routines', 'asn1_item_embed_d2i', 'nested asn1 error'), ('asn1 encoding routines', 'asn1_template_noexp_d2i', 'nested asn1 error'), ('PEM routines', 'PEM_ASN1_read_bio', 'ASN1 lib')]
Run Code Online (Sandbox Code Playgroud)
但是解析一个好的提取证书(使用我上面发布的第一个脚本)是有效的,正如您在此处看到的:
所以,我想我只需要一种从可执行文件中提取证书的方法。或者,如果您发现我的解决方案太复杂,如果您知道如何从证书的主题字段中获取“Redmond”文本,我非常愿意接受想法:)
powershell python certificate command-line digital-signature