tba-contracts-public-key-authentication 0.4.0.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: tba-contracts-public-key-authentication
3
+ Version: 0.4.0.dev2
4
+ Summary: Protocol-neutral public-key authentication contracts.
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.10,<3.15
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Classifier: Programming Language :: Python :: 3.13
12
+ Classifier: Programming Language :: Python :: 3.14
13
+ Description-Content-Type: text/markdown
14
+
15
+ # tba-contracts-public-key-authentication
16
+
17
+ Owns public-key credential, ceremony, registration, assertion, attestation, and evidence semantics.
18
+
@@ -0,0 +1,3 @@
1
+ # tba-contracts-public-key-authentication
2
+
3
+ Owns public-key credential, ceremony, registration, assertion, attestation, and evidence semantics.
@@ -0,0 +1,15 @@
1
+ [project]
2
+ name = "tba-contracts-public-key-authentication"
3
+ version = "0.4.0.dev2"
4
+ description = "Protocol-neutral public-key authentication contracts."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10,<3.15"
7
+ license = "Apache-2.0"
8
+ dependencies = []
9
+
10
+ [build-system]
11
+ requires = ["poetry-core>=1.0.0"]
12
+ build-backend = "poetry.core.masonry.api"
13
+
14
+ [tool.poetry]
15
+ packages = [{ include = "tba_contracts_public_key_authentication", from = "src" }]
@@ -0,0 +1,12 @@
1
+ """Canonical protocol-neutral public-key authentication contracts."""
2
+
3
+ from .attestation import *
4
+ from .authentication import *
5
+ from .ceremonies import *
6
+ from .credentials import *
7
+ from .errors import *
8
+ from .evidence import *
9
+ from .ports import *
10
+ from .registration import *
11
+
12
+ __all__ = [name for name in globals() if not name.startswith("_")]
@@ -0,0 +1,58 @@
1
+ """Canonical authenticator attestation contracts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+ from enum import Enum
7
+ from typing import Mapping
8
+
9
+
10
+ class AttestationType(str, Enum):
11
+ NONE = "none"
12
+ SELF = "self"
13
+ BASIC = "basic"
14
+ ATTCA = "attca"
15
+ ANONCA = "anonca"
16
+ ENTERPRISE = "enterprise"
17
+
18
+
19
+ @dataclass(frozen=True, slots=True)
20
+ class AttestationFormat:
21
+ identifier: str
22
+
23
+
24
+ @dataclass(frozen=True, slots=True)
25
+ class AuthenticatorAttestation:
26
+ format: AttestationFormat
27
+ statement: bytes
28
+ authenticator_data: bytes
29
+ client_data_hash: bytes
30
+ aaguid: bytes | None = None
31
+ credential_id: bytes | None = None
32
+ credential_public_key: bytes | None = None
33
+ rp_id_hash: bytes | None = None
34
+
35
+
36
+ @dataclass(frozen=True, slots=True)
37
+ class AttestationTrustResult:
38
+ trusted: bool
39
+ attestation_type: AttestationType
40
+ trust_path: tuple[bytes, ...] = ()
41
+ reason: str | None = None
42
+
43
+
44
+ @dataclass(frozen=True, slots=True)
45
+ class AuthenticatorMetadataResult:
46
+ aaguid: bytes
47
+ found: bool
48
+ status: str | None = None
49
+ attributes: Mapping[str, object] = field(default_factory=dict)
50
+
51
+
52
+ __all__ = [
53
+ "AttestationFormat",
54
+ "AttestationTrustResult",
55
+ "AttestationType",
56
+ "AuthenticatorAttestation",
57
+ "AuthenticatorMetadataResult",
58
+ ]
@@ -0,0 +1,49 @@
1
+ """Canonical public-key assertion authentication contracts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from .ceremonies import CeremonyContext
8
+ from .credentials import CredentialDescriptor
9
+ from .evidence import PublicKeyAuthenticationEvidence
10
+
11
+
12
+ @dataclass(frozen=True, slots=True)
13
+ class PublicKeyAuthenticationIntent:
14
+ tenant_id: str
15
+ rp_id: str
16
+ origin: str
17
+ principal_id: str | None = None
18
+
19
+
20
+ @dataclass(frozen=True, slots=True)
21
+ class PublicKeyAuthenticationOptions:
22
+ ceremony: CeremonyContext
23
+ allowed_credentials: tuple[CredentialDescriptor, ...] = ()
24
+ user_verification: str = "preferred"
25
+
26
+
27
+ @dataclass(frozen=True, slots=True)
28
+ class VerifiedPublicKeyAssertion:
29
+ ceremony_id: str
30
+ credential_id: str
31
+ principal_id: str
32
+ sign_count: int
33
+ evidence: PublicKeyAuthenticationEvidence
34
+
35
+
36
+ @dataclass(frozen=True, slots=True)
37
+ class PublicKeyAuthenticationResult:
38
+ authenticated: bool
39
+ principal_id: str | None = None
40
+ evidence: PublicKeyAuthenticationEvidence | None = None
41
+ reason: str | None = None
42
+
43
+
44
+ __all__ = [
45
+ "PublicKeyAuthenticationIntent",
46
+ "PublicKeyAuthenticationOptions",
47
+ "PublicKeyAuthenticationResult",
48
+ "VerifiedPublicKeyAssertion",
49
+ ]
@@ -0,0 +1,61 @@
1
+ """Canonical public-key ceremony lifecycle contracts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from datetime import datetime
7
+ from enum import Enum
8
+
9
+
10
+ class CeremonyKind(str, Enum):
11
+ REGISTRATION = "registration"
12
+ AUTHENTICATION = "authentication"
13
+
14
+
15
+ class CeremonyState(str, Enum):
16
+ PENDING = "pending"
17
+ VERIFIED = "verified"
18
+ FAILED = "failed"
19
+ EXPIRED = "expired"
20
+ CONSUMED = "consumed"
21
+
22
+
23
+ @dataclass(frozen=True, slots=True)
24
+ class CeremonyBinding:
25
+ tenant_id: str
26
+ rp_id: str
27
+ origin: str
28
+ principal_id: str | None = None
29
+
30
+
31
+ @dataclass(frozen=True, slots=True)
32
+ class CeremonyContext:
33
+ ceremony_id: str
34
+ kind: CeremonyKind
35
+ binding: CeremonyBinding
36
+ challenge: bytes
37
+ issued_at: datetime
38
+ expires_at: datetime
39
+
40
+
41
+ @dataclass(frozen=True, slots=True)
42
+ class CeremonyReservation:
43
+ context: CeremonyContext
44
+ state: CeremonyState = CeremonyState.PENDING
45
+
46
+
47
+ @dataclass(frozen=True, slots=True)
48
+ class CeremonyConsumption:
49
+ ceremony_id: str
50
+ consumed_at: datetime
51
+ bound_credential_id: str | None = None
52
+
53
+
54
+ __all__ = [
55
+ "CeremonyBinding",
56
+ "CeremonyConsumption",
57
+ "CeremonyContext",
58
+ "CeremonyKind",
59
+ "CeremonyReservation",
60
+ "CeremonyState",
61
+ ]
@@ -0,0 +1,52 @@
1
+ """Canonical stable public-key credential contracts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+ from enum import Enum
7
+
8
+
9
+ class CredentialLifecycleStatus(str, Enum):
10
+ ACTIVE = "active"
11
+ REVOKED = "revoked"
12
+ SUSPENDED = "suspended"
13
+
14
+
15
+ @dataclass(frozen=True, slots=True)
16
+ class CredentialDescriptor:
17
+ external_id: bytes
18
+ transports: tuple[str, ...] = ()
19
+
20
+
21
+ @dataclass(frozen=True, slots=True)
22
+ class CredentialBinding:
23
+ tenant_id: str
24
+ rp_id: str
25
+ principal_id: str | None = None
26
+ user_handle: bytes | None = None
27
+
28
+
29
+ @dataclass(frozen=True, slots=True)
30
+ class PublicKeyCredentialSource:
31
+ credential_id: str
32
+ external_id: bytes
33
+ public_key: bytes
34
+ algorithm: int
35
+ binding: CredentialBinding
36
+ sign_count: int = 0
37
+ transports: tuple[str, ...] = ()
38
+ discoverable: bool = False
39
+ backup_eligible: bool = False
40
+ backup_state: bool = False
41
+ status: CredentialLifecycleStatus = CredentialLifecycleStatus.ACTIVE
42
+
43
+
44
+ PublicKeyCredential = PublicKeyCredentialSource
45
+
46
+ __all__ = [
47
+ "CredentialBinding",
48
+ "CredentialDescriptor",
49
+ "CredentialLifecycleStatus",
50
+ "PublicKeyCredential",
51
+ "PublicKeyCredentialSource",
52
+ ]
@@ -0,0 +1,35 @@
1
+ """Canonical public-key ceremony and credential errors."""
2
+
3
+
4
+ class PublicKeyAuthenticationError(RuntimeError):
5
+ """Base failure for public-key registration and authentication."""
6
+
7
+
8
+ class CeremonyStateError(PublicKeyAuthenticationError):
9
+ """Raised when ceremony state is missing, expired, or already consumed."""
10
+
11
+
12
+ class PublicKeyCredentialVerificationError(PublicKeyAuthenticationError):
13
+ """Raised when credential proof verification fails."""
14
+
15
+
16
+ # Compatibility alias; the canonical generic error lives in credentials.errors.
17
+ CredentialVerificationError = PublicKeyCredentialVerificationError
18
+
19
+
20
+ class AttestationVerificationError(PublicKeyAuthenticationError):
21
+ """Raised when authenticator attestation cannot be accepted."""
22
+
23
+
24
+ class RelyingPartyPolicyError(PublicKeyAuthenticationError):
25
+ """Raised when a relying-party policy binding is violated."""
26
+
27
+
28
+ __all__ = [
29
+ "AttestationVerificationError",
30
+ "CeremonyStateError",
31
+ "CredentialVerificationError",
32
+ "PublicKeyCredentialVerificationError",
33
+ "PublicKeyAuthenticationError",
34
+ "RelyingPartyPolicyError",
35
+ ]
@@ -0,0 +1,54 @@
1
+ """Canonical evidence produced by verified public-key ceremonies."""
2
+
3
+ from dataclasses import dataclass
4
+
5
+
6
+ @dataclass(frozen=True, slots=True)
7
+ class UserPresenceEvidence:
8
+ present: bool
9
+
10
+
11
+ @dataclass(frozen=True, slots=True)
12
+ class UserVerificationEvidence:
13
+ verified: bool
14
+ method: str | None = None
15
+
16
+
17
+ @dataclass(frozen=True, slots=True)
18
+ class VerifierBindingEvidence:
19
+ rp_id: str
20
+ origin: str
21
+ valid: bool
22
+
23
+
24
+ @dataclass(frozen=True, slots=True)
25
+ class CredentialBackupEvidence:
26
+ eligible: bool
27
+ backed_up: bool
28
+
29
+
30
+ @dataclass(frozen=True, slots=True)
31
+ class AuthenticatorProvenanceEvidence:
32
+ aaguid: bytes | None = None
33
+ attestation_format: str | None = None
34
+ trusted: bool | None = None
35
+
36
+
37
+ @dataclass(frozen=True, slots=True)
38
+ class PublicKeyAuthenticationEvidence:
39
+ credential_id: str
40
+ user_presence: UserPresenceEvidence
41
+ user_verification: UserVerificationEvidence
42
+ verifier_binding: VerifierBindingEvidence
43
+ backup: CredentialBackupEvidence
44
+ provenance: AuthenticatorProvenanceEvidence | None = None
45
+
46
+
47
+ __all__ = [
48
+ "AuthenticatorProvenanceEvidence",
49
+ "CredentialBackupEvidence",
50
+ "PublicKeyAuthenticationEvidence",
51
+ "UserPresenceEvidence",
52
+ "UserVerificationEvidence",
53
+ "VerifierBindingEvidence",
54
+ ]
@@ -0,0 +1,98 @@
1
+ """Canonical ports for public-key registration and authentication."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from datetime import datetime
6
+ from typing import Protocol, runtime_checkable
7
+
8
+ from .attestation import (
9
+ AttestationTrustResult,
10
+ AuthenticatorAttestation,
11
+ AuthenticatorMetadataResult,
12
+ )
13
+ from .ceremonies import CeremonyConsumption, CeremonyReservation
14
+ from .credentials import PublicKeyCredentialSource
15
+
16
+
17
+ @runtime_checkable
18
+ class CeremonyStatePort(Protocol):
19
+ async def reserve(
20
+ self, reservation: CeremonyReservation, /
21
+ ) -> CeremonyReservation: ...
22
+ async def load(self, ceremony_id: str, /) -> CeremonyReservation | None: ...
23
+ async def consume(
24
+ self, consumption: CeremonyConsumption, /
25
+ ) -> CeremonyConsumption: ...
26
+ async def fail(self, ceremony_id: str, reason: str, /) -> None: ...
27
+
28
+
29
+ @runtime_checkable
30
+ class PublicKeyCredentialStorePort(Protocol):
31
+ async def insert(
32
+ self, credential: PublicKeyCredentialSource, /
33
+ ) -> PublicKeyCredentialSource: ...
34
+ async def update_assertion_state(
35
+ self,
36
+ credential_id: str,
37
+ *,
38
+ sign_count: int,
39
+ backup_state: bool,
40
+ used_at: datetime,
41
+ ) -> PublicKeyCredentialSource: ...
42
+ async def revoke(self, credential_id: str, /) -> None: ...
43
+
44
+
45
+ @runtime_checkable
46
+ class PublicKeyCredentialLookupPort(Protocol):
47
+ async def find_by_external_id(
48
+ self, tenant_id: str, rp_id: str, external_id: bytes, /
49
+ ) -> PublicKeyCredentialSource | None: ...
50
+ async def list_for_principal(
51
+ self, tenant_id: str, principal_id: str, rp_id: str, /
52
+ ) -> tuple[PublicKeyCredentialSource, ...]: ...
53
+
54
+
55
+ @runtime_checkable
56
+ class PublicKeySignatureVerifierPort(Protocol):
57
+ def verify(
58
+ self,
59
+ *,
60
+ public_key: bytes,
61
+ algorithm: int,
62
+ message: bytes,
63
+ signature: bytes,
64
+ ) -> bool: ...
65
+
66
+
67
+ @runtime_checkable
68
+ class AttestationStatementVerifierPort(Protocol):
69
+ def verify(
70
+ self, attestation: AuthenticatorAttestation, /
71
+ ) -> AttestationTrustResult: ...
72
+
73
+
74
+ @runtime_checkable
75
+ class AuthenticatorMetadataProviderPort(Protocol):
76
+ async def resolve(self, aaguid: bytes, /) -> AuthenticatorMetadataResult: ...
77
+
78
+
79
+ @runtime_checkable
80
+ class RelyingPartyConfigurationPort(Protocol):
81
+ async def resolve(self, tenant_id: str, rp_id: str, /) -> object | None: ...
82
+
83
+
84
+ @runtime_checkable
85
+ class OriginPolicyPort(Protocol):
86
+ def allows(self, *, rp_id: str, origin: str) -> bool: ...
87
+
88
+
89
+ __all__ = [
90
+ "AttestationStatementVerifierPort",
91
+ "AuthenticatorMetadataProviderPort",
92
+ "CeremonyStatePort",
93
+ "OriginPolicyPort",
94
+ "PublicKeyCredentialLookupPort",
95
+ "PublicKeyCredentialStorePort",
96
+ "PublicKeySignatureVerifierPort",
97
+ "RelyingPartyConfigurationPort",
98
+ ]
@@ -0,0 +1,51 @@
1
+ """Canonical public-key credential registration contracts."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass
6
+
7
+ from .attestation import AttestationTrustResult
8
+ from .ceremonies import CeremonyContext
9
+ from .credentials import PublicKeyCredentialSource
10
+
11
+
12
+ @dataclass(frozen=True, slots=True)
13
+ class PublicKeyRegistrationIntent:
14
+ tenant_id: str
15
+ principal_id: str
16
+ rp_id: str
17
+ origin: str
18
+ user_handle: bytes
19
+ display_name: str | None = None
20
+
21
+
22
+ @dataclass(frozen=True, slots=True)
23
+ class PublicKeyRegistrationOptions:
24
+ ceremony: CeremonyContext
25
+ algorithms: tuple[int, ...]
26
+ excluded_credential_ids: tuple[bytes, ...] = ()
27
+ user_verification: str = "preferred"
28
+ resident_key: str = "preferred"
29
+ attestation: str = "none"
30
+
31
+
32
+ @dataclass(frozen=True, slots=True)
33
+ class VerifiedCredentialRegistration:
34
+ ceremony_id: str
35
+ credential: PublicKeyCredentialSource
36
+ attestation: AttestationTrustResult | None = None
37
+
38
+
39
+ @dataclass(frozen=True, slots=True)
40
+ class CredentialRegistrationResult:
41
+ registered: bool
42
+ credential: PublicKeyCredentialSource | None = None
43
+ reason: str | None = None
44
+
45
+
46
+ __all__ = [
47
+ "CredentialRegistrationResult",
48
+ "PublicKeyRegistrationIntent",
49
+ "PublicKeyRegistrationOptions",
50
+ "VerifiedCredentialRegistration",
51
+ ]