import os
import requests
import subprocess
import tempfile
def timestamp(file_path: str) -> bytes:
with tempfile.NamedTemporaryFile(suffix=".tsq", delete=False) as f:
tsq = f.name
try:
subprocess.run([
"openssl", "ts", "-query", "-data", file_path,
"-cert", "-sha256", "-no_nonce", "-out", tsq
], check=True, capture_output=True)
with open(tsq, "rb") as f:
data = f.read()
r = requests.post(
"https://tsr.open-tsa.eu",
data=data,
headers={"Content-Type": "application/timestamp-query"},
timeout=15
)
r.raise_for_status()
return r.content
finally:
os.unlink(tsq)