Reject non-http(s) TSA URLs !5
2 files changed, +12 −0
Layout: unified · split
evidence_seal/timestamp.py +4
| @@ -19,6 +19,7 @@ from __future__ import annotations | ||
| 19 | 19 | |
| 20 | 20 | import base64 |
| 21 | 21 | import secrets |
| 22 | import urllib.parse | |
| 22 | 23 | import urllib.request |
| 23 | 24 | from datetime import timezone |
| 24 | 25 | from pathlib import Path |
| @@ -76,6 +77,9 @@ def submit(request_der: bytes, tsa_url: str, timeout: float = 30.0) -> bytes: | ||
| 76 | 77 | |
| 77 | 78 | Network call — the caller is responsible for choosing a trusted TSA URL. |
| 78 | 79 | """ |
| 80 | scheme = urllib.parse.urlsplit(tsa_url).scheme.lower() | |
| 81 | if scheme not in ("http", "https"): | |
| 82 | raise ValueError(f"TSA URL must use http or https: {tsa_url}") | |
| 79 | 83 | req = urllib.request.Request( |
| 80 | 84 | tsa_url, |
| 81 | 85 | data=request_der, |
tests/test_timestamp.py +8
| @@ -17,6 +17,7 @@ from evidence_seal.timestamp import ( | ||
| 17 | 17 | apply_timestamp, |
| 18 | 18 | build_request, |
| 19 | 19 | parse_token, |
| 20 | submit, | |
| 20 | 21 | verify_timestamp, |
| 21 | 22 | ) |
| 22 | 23 | |
| @@ -223,6 +224,13 @@ def test_verify_unstamped_manifest(manifest): | ||
| 223 | 224 | assert "not timestamped" in message |
| 224 | 225 | |
| 225 | 226 | |
| 227 | def test_submit_rejects_non_http_url(manifest, tmp_path): | |
| 228 | target = tmp_path / "tsa.tsr" | |
| 229 | target.write_bytes(b"") | |
| 230 | with pytest.raises(ValueError, match="http or https"): | |
| 231 | submit(build_request(manifest["id"]), target.as_uri()) | |
| 232 | ||
| 233 | ||
| 226 | 234 | # --- full CMS signature verification (needs cryptography) --- |
| 227 | 235 | |
| 228 | 236 | |