Exemplo n.º 1
0
    async def async_request_tsa_response(self, req: tsp.TimeStampReq) \
            -> tsp.TimeStampResp:
        session = await self.get_session()

        cl_timeout = aiohttp.ClientTimeout(total=self.timeout)
        headers = await self.async_request_headers()
        try:
            async with session.post(url=self.url, headers=headers,
                                    data=req.dump(), auth=self.auth,
                                    raise_for_status=True,
                                    timeout=cl_timeout) as response:
                response_data = await response.read()
                ct = response.headers.get('Content-Type')
                if ct != 'application/timestamp-reply':
                    msg = (
                        f'Bad content type. Expected '
                        f'application/timestamp-reply,but got {ct}.'
                    )
                    raise aiohttp.ContentTypeError(
                        response.request_info, response.history,
                        message=msg, headers=response.headers,
                    )
        except aiohttp.ClientError as e:
            raise TimestampRequestError(
                "Error while contacting timestamp service",
            ) from e
        return tsp.TimeStampResp.load(response_data)
Exemplo n.º 2
0
 def request_tsa_response(self, req: tsp.TimeStampReq) -> tsp.TimeStampResp:
     raw_res = requests.post(
         self.url, req.dump(), headers=self.request_headers(),
         auth=self.auth, timeout=self.timeout
     )
     if raw_res.headers.get('Content-Type') != 'application/timestamp-reply':
         raise TimestampRequestError(
             'Timestamp server response is malformed.', raw_res
         )
     return tsp.TimeStampResp.load(raw_res.content)
Exemplo n.º 3
0
def get_timestamp_token(digest: bytes, hash_type: int):
    # Create a TimestampRequest
    dg_algo = DigestAlgorithm({"algorithm": _get_digest_algo(hash_type)})
    imprint = MessageImprint({
        "hash_algorithm": dg_algo,
        "hashed_message": OctetString(digest)
    })

    tsreq = TimeStampReq({
        "version": Version(1),
        "message_imprint": imprint,
        "cert_req": True,
    })

    # Send tsreq to the server
    headers = {"Content-Type": "application/timestamp-query"}
    resp = requests.post(TIMESTAMP_SERVER, data=tsreq.dump(), headers=headers)
    resp.raise_for_status()
    tsresp = TimeStampResp.load(resp.content)

    return tsresp["time_stamp_token"]