|
43 | 43 | )
|
44 | 44 | from pydantic.dataclasses import dataclass
|
45 | 45 | from rekor_types import Dsse, Hashedrekord, ProposedEntry
|
| 46 | +from rfc3161_client import TimeStampResponse, decode_timestamp_response |
46 | 47 | from sigstore_protobuf_specs.dev.sigstore.bundle import v1 as bundle_v1
|
47 | 48 | from sigstore_protobuf_specs.dev.sigstore.bundle.v1 import (
|
48 | 49 | Bundle as _Bundle,
|
49 | 50 | )
|
| 51 | +from sigstore_protobuf_specs.dev.sigstore.bundle.v1 import ( |
| 52 | + TimestampVerificationData as _TimestampVerificationData, |
| 53 | +) |
| 54 | +from sigstore_protobuf_specs.dev.sigstore.bundle.v1 import ( |
| 55 | + VerificationMaterial as _VerificationMaterial, |
| 56 | +) |
50 | 57 | from sigstore_protobuf_specs.dev.sigstore.common import v1 as common_v1
|
51 | 58 | from sigstore_protobuf_specs.dev.sigstore.rekor import v1 as rekor_v1
|
52 | 59 | from sigstore_protobuf_specs.dev.sigstore.rekor.v1 import (
|
@@ -328,6 +335,64 @@ def _verify(self, keyring: RekorKeyring) -> None:
|
328 | 335 | )
|
329 | 336 |
|
330 | 337 |
|
| 338 | +class TimestampVerificationData: |
| 339 | + """ |
| 340 | + Represents a TimestampVerificationData structure. |
| 341 | +
|
| 342 | + @private |
| 343 | + """ |
| 344 | + |
| 345 | + def __init__(self, inner: _TimestampVerificationData) -> None: |
| 346 | + """Init method.""" |
| 347 | + self._inner = inner |
| 348 | + self._verify() |
| 349 | + |
| 350 | + def _verify(self) -> None: |
| 351 | + """ |
| 352 | + Verifies the TimestampVerificationData. |
| 353 | +
|
| 354 | + It verifies that TimeStamp Responses embedded in the bundle are correctly |
| 355 | + formed. |
| 356 | + """ |
| 357 | + try: |
| 358 | + self._signed_ts = [ |
| 359 | + decode_timestamp_response(ts.signed_timestamp) |
| 360 | + for ts in self._inner.rfc3161_timestamps |
| 361 | + ] |
| 362 | + except ValueError: |
| 363 | + raise VerificationError("Invalid Timestamp Response") |
| 364 | + |
| 365 | + @property |
| 366 | + def rfc3161_timestamps(self) -> list[TimeStampResponse]: |
| 367 | + """Returns a list of signed timestamp.""" |
| 368 | + return self._signed_ts |
| 369 | + |
| 370 | + @classmethod |
| 371 | + def from_json(cls, raw: str | bytes) -> TimestampVerificationData: |
| 372 | + """ |
| 373 | + Deserialize the given timestamp verification data. |
| 374 | + """ |
| 375 | + inner = _TimestampVerificationData().from_json(raw) |
| 376 | + return cls(inner)
8000
|
| 377 | + |
| 378 | + |
| 379 | +class VerificationMaterial: |
| 380 | + """ |
| 381 | + Represents a VerificationMaterial structure. |
| 382 | + """ |
| 383 | + |
| 384 | + def __init__(self, inner: _VerificationMaterial) -> None: |
| 385 | + """Init method.""" |
| 386 | + self._inner = inner |
| 387 | + |
| 388 | + @property |
| 389 | + def timestamp_verification_data(self) -> TimestampVerificationData: |
| 390 | + """ |
| 391 | + Returns the Timestamp Verification Data. |
| 392 | + """ |
| 393 | + return TimestampVerificationData(self._inner.timestamp_verification_data) |
| 394 | + |
| 395 | + |
331 | 396 | class InvalidBundle(Error):
|
332 | 397 | """
|
333 | 398 | Raised when the associated `Bundle` is invalid in some way.
|
@@ -503,6 +568,13 @@ def _dsse_envelope(self) -> dsse.Envelope | None:
|
503 | 568 | return dsse.Envelope(self._inner.dsse_envelope)
|
504 | 569 | return None
|
505 | 570 |
|
| 571 | + @property |
| 572 | + def verification_material(self) -> VerificationMaterial: |
| 573 | + """ |
| 574 | + Returns the bundle's verification material. |
| 575 | + """ |
| 576 | + return VerificationMaterial(self._inner.verification_material) |
| 577 | + |
506 | 578 | @classmethod
|
507 | 579 | def from_json(cls, raw: bytes | str) -> Bundle:
|
508 | 580 | """
|
|
0 commit comments