1# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
4
5from __future__ import annotations
6
7import abc
8import datetime
9
10from cryptography import utils
11from cryptography.hazmat.bindings._rust import x509 as rust_x509
12from cryptography.hazmat.primitives.hashes import HashAlgorithm
13
14
15class LogEntryType(utils.Enum):
16 X509_CERTIFICATE = 0
17 PRE_CERTIFICATE = 1
18
19
20class Version(utils.Enum):
21 v1 = 0
22
23
24class SignatureAlgorithm(utils.Enum):
25 """
26 Signature algorithms that are valid for SCTs.
27
28 These are exactly the same as SignatureAlgorithm in RFC 5246 (TLS 1.2).
29
30 See: <https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.1.4.1>
31 """
32
33 ANONYMOUS = 0
34 RSA = 1
35 DSA = 2
36 ECDSA = 3
37
38
39class SignedCertificateTimestamp(metaclass=abc.ABCMeta):
40 @property
41 @abc.abstractmethod
42 def version(self) -> Version:
43 """
44 Returns the SCT version.
45 """
46
47 @property
48 @abc.abstractmethod
49 def log_id(self) -> bytes:
50 """
51 Returns an identifier indicating which log this SCT is for.
52 """
53
54 @property
55 @abc.abstractmethod
56 def timestamp(self) -> datetime.datetime:
57 """
58 Returns the timestamp for this SCT.
59 """
60
61 @property
62 @abc.abstractmethod
63 def entry_type(self) -> LogEntryType:
64 """
65 Returns whether this is an SCT for a certificate or pre-certificate.
66 """
67
68 @property
69 @abc.abstractmethod
70 def signature_hash_algorithm(self) -> HashAlgorithm:
71 """
72 Returns the hash algorithm used for the SCT's signature.
73 """
74
75 @property
76 @abc.abstractmethod
77 def signature_algorithm(self) -> SignatureAlgorithm:
78 """
79 Returns the signing algorithm used for the SCT's signature.
80 """
81
82 @property
83 @abc.abstractmethod
84 def signature(self) -> bytes:
85 """
86 Returns the signature for this SCT.
87 """
88
89 @property
90 @abc.abstractmethod
91 def extension_bytes(self) -> bytes:
92 """
93 Returns the raw bytes of any extensions for this SCT.
94 """
95
96
97SignedCertificateTimestamp.register(rust_x509.Sct)