Exemplo n.º 1
0
def default_test(tsa_server,
                 certificate,
                 username=None,
                 password=None,
                 data='xx',
                 nonce=None,
                 **kwargs):
    with open(certificate, 'rb') as f:
        certificate_data = f.read()

    kwargs.update({
        'certificate': certificate_data,
    })
    if username and password:
        kwargs.update({
            'username': username,
            'password': password,
        })

    timestamper = rfc3161ng.RemoteTimestamper(tsa_server, **kwargs)
    kwargs = {}
    if nonce:
        kwargs['nonce'] = nonce
    value = timestamper(data=data, **kwargs)
    assert value is not False
    assert isinstance(rfc3161ng.get_timestamp(value), datetime.datetime)
    assert value is not None
Exemplo n.º 2
0
def test_verify_timestamp_response_with_openssl():
    with open(os.path.join(os.path.dirname(__file__), '../data/freetsa.crt'), 'rb') as f:
        certificate_data = f.read()

    timestamper = rfc3161ng.RemoteTimestamper('http://freetsa.org/tsr', certificate=certificate_data)

    with NamedTemporaryFile() as data_f, NamedTemporaryFile() as tsr_f:
        data_f.write(b"Hello World from rfc3161ng\n")
        data_f.flush()
        data_f.seek(0)

        tsr = timestamper(data=data_f.read(), return_tsr=True)
        tsr_f.write(encoder.encode(tsr))
        tsr_f.flush()

        args = ["openssl", "ts", "-verify", "-data", data_f.name, "-in", tsr_f.name, "-CAfile", "data/freetsa_cacert.pem", "-untrusted", "data/freetsa.crt"]
        subprocess.check_call(args)
Exemplo n.º 3
0
def add_tsa(text, hash_data):
    url = 'http://time.certum.pl'
    certificate = open(CERTIFICATE, 'rb').read()
    rt = rfc3161ng.RemoteTimestamper(url,
                                     certificate=certificate,
                                     include_tsa_certificate=True)
    write_file(CERTIFICATE_PATH, 'certificate ' + text + '.crt',
               rt.certificate)
    tst = rt.timestamp(data=hash_data)

    tsq = rfc3161ng.make_timestamp_request(data=hash_data)
    binary_request = rfc3161ng.encode_timestamp_request(tsq)
    headers = {'Content-Type': 'application/timestamp-query'}
    response = requests.post(
        url,
        data=binary_request,
        timeout=10,
        headers=headers,
    )
    tsr = rfc3161ng.decode_timestamp_response(response.content)

    tst1, substrate = decoder.decode(tst, asn1Spec=rfc3161ng.TimeStampToken())

    signed_data = tst1.content
    signer_info = signed_data['signerInfos'][0]
    tsa_signature = bytes(signer_info['encryptedDigest']).hex()

    write_object_file(RESPONSE_PATH, 'response ' + text + '.tsr', tsr)

    # with open("Output.txt", "w") as text_file:
    #     text_file.write("%s" % tsr)

    tst = tsr.time_stamp_token
    tst1 = tst.content
    tst2 = tst.tst_info
    tss = tsr.status

    return tsa_signature