如何在Python中发布请求时间戳authenticode

ltskdhd1  于 2023-06-25  发布在  Python
关注(0)|答案(1)|浏览(173)

我只是有一个关于这个https://learn.microsoft.com/en-us/windows/win32/seccrypto/time-stamping-authenticode-signatures的问题,我想做一个测试的帖子请求。我不断收到500个错误。我尝试更改OID,但仍然得到相同的错误。我只是想测试如果网址是工作谢谢
这是我的参考https://gist.github.com/etiennebch/a4cb467fb5b1396b1fc1876dd456e5d2到目前为止这是我的代码:

def create_tsq(hash=False,nonce=True,cert=False):
    """Create a TimeStampReq.
    :param file_: the file to hash to create the TimeStampReq.
    :type file_: a python file object.
    :returns: a byte string.
    """

    message_imprint = MessageImprint()

    sha256 = AlgorithmIdentifier()
    # SHA-256 OID is 2.16.840.1.101.3.4.2.1 as per IETF
    sha256['algorithm'] = univ.ObjectIdentifier('1.3.6.1.4.1.311.3.2.1')
    message_imprint['hashAlgorithm'] = sha256
    if hash == False:
        message_imprint['hashedMessage'] = hashlib.sha256(urandom(10000)).digest()
    else:
        message_imprint['hashedMessage'] = hash

    tsq = TimeStampReq()
    tsq['version'] = 'v1'
    tsq['messageImprint'] = message_imprint
    if nonce:
        # generate a cryptographically secure 64 bit integer
        # NB: unpack returns a tuple
        tsq['nonce'] = unpack('<q', urandom(8))[0]

    if cert:
        tsq['certReq'] = True

    return der_encoder.encode(tsq)

t = create_tsq(nonce=True)
headers = {'content-type': 'application/octet-stream'}
signature = "sha2"
url=f'http://timestamp.globalsign.com?signature={signature}'

resp = requests.post(url, data=t, headers=headers)

print(f"Status Code: {resp.status_code}")`
goqiplq2

goqiplq21#

500状态错误由服务器端的错误引起。
要验证URL是否有效,可以使用Python的requests库发送一个简单的GET请求。

import requests

url = 'http://timestamp.globalsign.com'
response = requests.get(url)

print(f"Status Code: {response.status_code}")

如果此代码中的状态代码为200,则URL正在工作。如果返回另一个状态代码,则必须解决问题。
如果URL工作正常,则测试post请求。

相关问题