Python 使用OpenSSL撤消CA证书

Python 使用OpenSSL撤消CA证书,python,openssl,certificate,x509certificate,Python,Openssl,Certificate,X509certificate,巨蟒新手在这里!正如标题所暗示的,我正在寻找一种从CA证书序列号中撤销CA证书的方法 我希望通过使用pyopenssl的库(OpenSSL.crypto)来实现这一点。使用此库可以实现加载证书的梦想。但撤销它们完全是另一回事 以下是我尝试过的: import OpenSSL.crypto as crypto def revoke_certificate(self, serial): crl = crypto.CRL() try: if not serial =

巨蟒新手在这里!正如标题所暗示的,我正在寻找一种从CA证书序列号中撤销CA证书的方法

我希望通过使用pyopenssl的库(OpenSSL.crypto)来实现这一点。使用此库可以实现加载证书的梦想。但撤销它们完全是另一回事

以下是我尝试过的:

import OpenSSL.crypto as crypto

def revoke_certificate(self, serial):
    crl = crypto.CRL()

    try:
        if not serial == self.get_ca_certificate().get_serial()
            filename = self.get_certificate_filename(serial)

            with open(filename, "r") as certificate_file:
                certificate_text = certificate_file.read()
                certificate = cr.load_certificate(crypto.FILETYPE_PEM, certificate_text)
                # Note: the certificate is type X509, so it gets properly loaded
                # So... this is not going to work
                crl.set_revoked(certificate)

            # irrelevant lines of code
            # ...
    except CustomError, e:
            # irrelevant logging lines of code
            # ...

    revoked = crl.get_revoked() 
    # obviously, revoked is going to be None
    revoked.set_serial(serial)
    now = self.get_current_time()
    revoked.set_rev_date(now)

    # the rest is also irrelevant
    # ...
    # ...
对于那些想知道的人来说,序列号实际上是一个整数,而不是
None
对象

我删除了不相关的代码行(与撤销无关)。 我很清楚
reversed=crl.get_reversed()
将使
reversed
成为
None
对象

关于如何
set\u reversed
a
OpenSSL.crypto.reversed
对象,有什么想法吗?是否可以从
证书
(从
with
块)执行此操作?由于此
证书
对象是
OpenSSL.crypto.X509
对象,因此不能将其类型转换为
OpenSSL.crypto.reversed
对象

谢谢你的帮助