我想打印证书中的所有x509信息。以下是我们所做的工作:
context.load_verify_locations('path/to/cabundle.pem')“添加到示例中。因此,证书是正确的和有效的。import asn1tools; foo = asn1tools.compile_files("x509.asn"); output = foo.decode("Certificate", cert)“。这需要一个asn文件。AlgorithmObjectIdentifiers.asn、AuthenticationFramework.asn、CertificateExtensions.asn。因为第一个文件在其他文件中导入元素,所以我想它是顶级文件,所以我将它交给代码。
foo = asn1tools.compile_files("AlgorithmObjectIdentifiers.asn") output =foo.decode(“证书",证书)打印(”证书输出:“,输出)它说出一个错误:
File ".../test-print-ssl.py", line 47, in cert_print_asn1
output = foo.decode("Certificate", cert)
File "...\lib\site-packages\asn1tools\compiler.py", line 161, in decode
"Type '{}' not found in types dictionary.".format(name))
asn1tools.errors.DecodeError: Type 'Certificate' not found in types dictionary.几个问题:
请注意,我已经使用命令openssl x509 -in website.com.pem -text从文件中打印了相同的证书。这是可行的。我想我可以使用os.system()来实现同样的目标。我想有一个在python中解码和打印的解决方案。
我见过质疑编译失败,但在我的例子中,它正在解码失败,这是不同的。
发布于 2022-06-02 09:38:20
你应该分享你的文件以便有更具体的答案.
您只需创建一个文件,将文件中的类型连接起来。
与其一蹴而就,不如将所需的类型放入其中,并添加所缺少的内容。
您的asn1规范的内容应该类似于
X509 DEFINITIONS ::=
BEGIN
Type1
Type2
END您可以在https://asn1.io/asn1playground/上验证您的文件
https://stackoverflow.com/questions/72465075
复制相似问题