tba-profile-communications-identity-bimi 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.
- tba_profile_communications_identity_bimi-0.4.0.dev2/PKG-INFO +117 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/README.md +94 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/pyproject.toml +24 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/__init__.py +66 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/capability_adapter.py +64 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/certificate.py +126 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/dmarc.py +49 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/logotype.py +3 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/readiness.py +25 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/records.py +35 -0
- tba_profile_communications_identity_bimi-0.4.0.dev2/src/tba_profile_communications_identity_bimi/types.py +70 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tba-profile-communications-identity-bimi
|
|
3
|
+
Version: 0.4.0.dev2
|
|
4
|
+
Summary: Optional BIMI Mark Certificate and DNS readiness profile.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.10,<3.16
|
|
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
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
14
|
+
Provides-Extra: workflow
|
|
15
|
+
Requires-Dist: cryptography (>=46)
|
|
16
|
+
Requires-Dist: tba-capability-communications-identity (==0.4.0.dev2) ; extra == "workflow"
|
|
17
|
+
Requires-Dist: tba-contracts-dns (==0.4.0.dev2)
|
|
18
|
+
Requires-Dist: tba-contracts-security-trust (==0.1.0)
|
|
19
|
+
Requires-Dist: tba-protocol-bimi (==0.4.0.dev2)
|
|
20
|
+
Requires-Dist: tba-protocol-dmarc (==0.4.0.dev2)
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# tba-profile-communications-identity-bimi
|
|
24
|
+
|
|
25
|
+
<!-- BEGIN TBA README HEADER -->
|
|
26
|
+
<p align="center">
|
|
27
|
+
<a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
|
|
28
|
+
</p>
|
|
29
|
+
<p align="center">
|
|
30
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
|
|
31
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/pyproject.toml"><img alt="Python: >=3.10,<3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
|
|
32
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/pyproject.toml"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/License-Apache--2.0-525252"></a>
|
|
33
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/55-profiles"><img alt="Layer: 55 profiles" src="https://img.shields.io/badge/Layer-55%20profiles-0a7f5a"></a>
|
|
34
|
+
<a href="https://pypi.org/project/tba-profile-communications-identity-bimi/"><img alt="PyPI version for tba-profile-communications-identity-bimi" src="https://img.shields.io/pypi/v/tba-profile-communications-identity-bimi?label=tba-profile-communications-identity-bimi%20PyPI"></a>
|
|
35
|
+
</p>
|
|
36
|
+
<p align="center">
|
|
37
|
+
<a href="https://pepy.tech/project/tba-profile-communications-identity-bimi"><img alt="Monthly PyPI downloads for tba-profile-communications-identity-bimi" src="https://static.pepy.tech/badge/tba-profile-communications-identity-bimi/month"></a>
|
|
38
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
|
|
39
|
+
</p>
|
|
40
|
+
<!-- END TBA README HEADER -->
|
|
41
|
+
|
|
42
|
+
Optional BIMI Mark Certificate and DNS readiness profile.
|
|
43
|
+
|
|
44
|
+
Install from the TBA workspace with `uv sync --extra bimi`.
|
|
45
|
+
|
|
46
|
+
- `check_readiness` inspects the selected BIMI TXT record and the sender and
|
|
47
|
+
organizational domains' DMARC enforcement. It returns separate DNS and DMARC
|
|
48
|
+
findings, the assertion owner after any fallback, and the published asset
|
|
49
|
+
URLs. `ready` describes DNS/DMARC preflight for a mark-backed deployment.
|
|
50
|
+
- `verify_certificate` takes a leaf-first PEM bundle and the assertion owner.
|
|
51
|
+
It checks the certificate policy, classifies CMC/VMC from the signed mark
|
|
52
|
+
type, matches the assertion domain or selector-qualified SAN, and checks the
|
|
53
|
+
embedded compressed logotype and its digest. The injected validator checks
|
|
54
|
+
the certificate path, revocation evidence, and CT evidence.
|
|
55
|
+
|
|
56
|
+
The readiness policy uses bounded RFC 9989 discovery by default and accepts a
|
|
57
|
+
known organizational domain for deployments that need to reproduce a specific
|
|
58
|
+
boundary. It checks the legacy `pct` tag and the current `t` testing tag.
|
|
59
|
+
The lookup is domain-level and does not process message-local selectors or
|
|
60
|
+
SPF/DKIM alignment. The embedded-logo check covers format markers and basic
|
|
61
|
+
safety checks. Full SVG schema validation, remote asset retrieval, and mailbox
|
|
62
|
+
display are separate checks.
|
|
63
|
+
|
|
64
|
+
## Run the example
|
|
65
|
+
|
|
66
|
+
`scripts/bimi_check.py` composes the profile with the live TXT resolver or
|
|
67
|
+
with TBA's existing `ProfiledTrustAnchorProvider` and the Mark Certificate
|
|
68
|
+
backend. Use the `assertion.name` returned by the DNS check for the certificate
|
|
69
|
+
check. Pass locally obtained evidence and trust material.
|
|
70
|
+
|
|
71
|
+
```console
|
|
72
|
+
uv run --extra bimi python scripts/bimi_check.py dns news.example.com --selector default
|
|
73
|
+
uv run --extra bimi python scripts/bimi_check.py verify default._bimi.example.com mark-chain.pem --root mva-root.pem --ct-log ct-log.pem --crl http://ca.example/leaf.crl=leaf.crl --crl http://ca.example/issuer.crl=issuer.crl
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
In a TBA tenant-admin application, authorize the caller for the sending domain
|
|
77
|
+
first. The workspace `bimi` extra includes the optional `workflow` adapter.
|
|
78
|
+
It composes the profile with the shared communications identity assessment
|
|
79
|
+
and TBA's existing durable audit writer. The evidence callback can look up a
|
|
80
|
+
local bundle keyed by the discovered assertion owner.
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
from tba_capability_communications_identity import assess_domain_onboarding, recheck_domain
|
|
84
|
+
from tba_durability_audit.operations.audit import append_audit_event_async
|
|
85
|
+
from tba_profile_communications_identity_bimi import BimiProfile
|
|
86
|
+
from tba_profile_communications_identity_bimi.capability_adapter import BimiDomainChecker
|
|
87
|
+
from tba_provider_dns_txt import DnsTxtResolver
|
|
88
|
+
|
|
89
|
+
bimi = BimiProfile(dns=DnsTxtResolver(), validator=validator)
|
|
90
|
+
checker = BimiDomainChecker(bimi, evidence=lambda assertion: bundles.get(assertion.name))
|
|
91
|
+
initial = await assess_domain_onboarding(
|
|
92
|
+
sending_domain, checker=checker, audit=append_audit_event_async,
|
|
93
|
+
db=db, tenant_id=tenant_id,
|
|
94
|
+
)
|
|
95
|
+
latest = await recheck_domain(
|
|
96
|
+
sending_domain, checker=checker, audit=append_audit_event_async,
|
|
97
|
+
db=db, tenant_id=tenant_id,
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
References include the [BIMI draft](https://datatracker.ietf.org/doc/html/draft-brand-indicators-for-message-identification-15),
|
|
102
|
+
the [Mark Certificate verification draft](https://datatracker.ietf.org/doc/html/draft-fetch-validation-vmc-wchuang-12),
|
|
103
|
+
the [v1.8 Mark Certificate requirements](https://bimigroup.org/resources/VMC_Requirements_latest.pdf),
|
|
104
|
+
and [DMARC RFC 9989](https://www.rfc-editor.org/rfc/rfc9989.html).
|
|
105
|
+
|
|
106
|
+
## Quick start
|
|
107
|
+
|
|
108
|
+
Build the package from the repository root.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
uv build --wheel pkgs/55-profiles/tba-profile-communications-identity-bimi
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Verification
|
|
115
|
+
|
|
116
|
+
Check that the build produces a wheel with the package version declared in `pyproject.toml`.
|
|
117
|
+
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# tba-profile-communications-identity-bimi
|
|
2
|
+
|
|
3
|
+
<!-- BEGIN TBA README HEADER -->
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://github.com/tigrbl/tigrbl_auth#readme"><img src="https://raw.githubusercontent.com/tigrbl/tigrbl_auth/master/docs/assets/tba-brand.png" alt="TBA · Tigrbl Auth" width="240"></a>
|
|
6
|
+
</p>
|
|
7
|
+
<p align="center">
|
|
8
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/pyproject.toml"><img alt="Checkout: 0.4.0.dev2" src="https://img.shields.io/badge/Checkout-0.4.0.dev2-1f6feb"></a>
|
|
9
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/pyproject.toml"><img alt="Python: >=3.10,<3.16" src="https://img.shields.io/badge/Python-%3E%3D3.10%2C%3C3.16-3776ab"></a>
|
|
10
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/pyproject.toml"><img alt="License: Apache-2.0" src="https://img.shields.io/badge/License-Apache--2.0-525252"></a>
|
|
11
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/tree/master/pkgs/55-profiles"><img alt="Layer: 55 profiles" src="https://img.shields.io/badge/Layer-55%20profiles-0a7f5a"></a>
|
|
12
|
+
<a href="https://pypi.org/project/tba-profile-communications-identity-bimi/"><img alt="PyPI version for tba-profile-communications-identity-bimi" src="https://img.shields.io/pypi/v/tba-profile-communications-identity-bimi?label=tba-profile-communications-identity-bimi%20PyPI"></a>
|
|
13
|
+
</p>
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="https://pepy.tech/project/tba-profile-communications-identity-bimi"><img alt="Monthly PyPI downloads for tba-profile-communications-identity-bimi" src="https://static.pepy.tech/badge/tba-profile-communications-identity-bimi/month"></a>
|
|
16
|
+
<a href="https://github.com/tigrbl/tigrbl_auth/blob/master/pkgs/55-profiles/tba-profile-communications-identity-bimi/README.md#verification"><img alt="Evidence: verification" src="https://img.shields.io/badge/Evidence-verification-8250df"></a>
|
|
17
|
+
</p>
|
|
18
|
+
<!-- END TBA README HEADER -->
|
|
19
|
+
|
|
20
|
+
Optional BIMI Mark Certificate and DNS readiness profile.
|
|
21
|
+
|
|
22
|
+
Install from the TBA workspace with `uv sync --extra bimi`.
|
|
23
|
+
|
|
24
|
+
- `check_readiness` inspects the selected BIMI TXT record and the sender and
|
|
25
|
+
organizational domains' DMARC enforcement. It returns separate DNS and DMARC
|
|
26
|
+
findings, the assertion owner after any fallback, and the published asset
|
|
27
|
+
URLs. `ready` describes DNS/DMARC preflight for a mark-backed deployment.
|
|
28
|
+
- `verify_certificate` takes a leaf-first PEM bundle and the assertion owner.
|
|
29
|
+
It checks the certificate policy, classifies CMC/VMC from the signed mark
|
|
30
|
+
type, matches the assertion domain or selector-qualified SAN, and checks the
|
|
31
|
+
embedded compressed logotype and its digest. The injected validator checks
|
|
32
|
+
the certificate path, revocation evidence, and CT evidence.
|
|
33
|
+
|
|
34
|
+
The readiness policy uses bounded RFC 9989 discovery by default and accepts a
|
|
35
|
+
known organizational domain for deployments that need to reproduce a specific
|
|
36
|
+
boundary. It checks the legacy `pct` tag and the current `t` testing tag.
|
|
37
|
+
The lookup is domain-level and does not process message-local selectors or
|
|
38
|
+
SPF/DKIM alignment. The embedded-logo check covers format markers and basic
|
|
39
|
+
safety checks. Full SVG schema validation, remote asset retrieval, and mailbox
|
|
40
|
+
display are separate checks.
|
|
41
|
+
|
|
42
|
+
## Run the example
|
|
43
|
+
|
|
44
|
+
`scripts/bimi_check.py` composes the profile with the live TXT resolver or
|
|
45
|
+
with TBA's existing `ProfiledTrustAnchorProvider` and the Mark Certificate
|
|
46
|
+
backend. Use the `assertion.name` returned by the DNS check for the certificate
|
|
47
|
+
check. Pass locally obtained evidence and trust material.
|
|
48
|
+
|
|
49
|
+
```console
|
|
50
|
+
uv run --extra bimi python scripts/bimi_check.py dns news.example.com --selector default
|
|
51
|
+
uv run --extra bimi python scripts/bimi_check.py verify default._bimi.example.com mark-chain.pem --root mva-root.pem --ct-log ct-log.pem --crl http://ca.example/leaf.crl=leaf.crl --crl http://ca.example/issuer.crl=issuer.crl
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
In a TBA tenant-admin application, authorize the caller for the sending domain
|
|
55
|
+
first. The workspace `bimi` extra includes the optional `workflow` adapter.
|
|
56
|
+
It composes the profile with the shared communications identity assessment
|
|
57
|
+
and TBA's existing durable audit writer. The evidence callback can look up a
|
|
58
|
+
local bundle keyed by the discovered assertion owner.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from tba_capability_communications_identity import assess_domain_onboarding, recheck_domain
|
|
62
|
+
from tba_durability_audit.operations.audit import append_audit_event_async
|
|
63
|
+
from tba_profile_communications_identity_bimi import BimiProfile
|
|
64
|
+
from tba_profile_communications_identity_bimi.capability_adapter import BimiDomainChecker
|
|
65
|
+
from tba_provider_dns_txt import DnsTxtResolver
|
|
66
|
+
|
|
67
|
+
bimi = BimiProfile(dns=DnsTxtResolver(), validator=validator)
|
|
68
|
+
checker = BimiDomainChecker(bimi, evidence=lambda assertion: bundles.get(assertion.name))
|
|
69
|
+
initial = await assess_domain_onboarding(
|
|
70
|
+
sending_domain, checker=checker, audit=append_audit_event_async,
|
|
71
|
+
db=db, tenant_id=tenant_id,
|
|
72
|
+
)
|
|
73
|
+
latest = await recheck_domain(
|
|
74
|
+
sending_domain, checker=checker, audit=append_audit_event_async,
|
|
75
|
+
db=db, tenant_id=tenant_id,
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
References include the [BIMI draft](https://datatracker.ietf.org/doc/html/draft-brand-indicators-for-message-identification-15),
|
|
80
|
+
the [Mark Certificate verification draft](https://datatracker.ietf.org/doc/html/draft-fetch-validation-vmc-wchuang-12),
|
|
81
|
+
the [v1.8 Mark Certificate requirements](https://bimigroup.org/resources/VMC_Requirements_latest.pdf),
|
|
82
|
+
and [DMARC RFC 9989](https://www.rfc-editor.org/rfc/rfc9989.html).
|
|
83
|
+
|
|
84
|
+
## Quick start
|
|
85
|
+
|
|
86
|
+
Build the package from the repository root.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
uv build --wheel pkgs/55-profiles/tba-profile-communications-identity-bimi
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Verification
|
|
93
|
+
|
|
94
|
+
Check that the build produces a wheel with the package version declared in `pyproject.toml`.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "tba-profile-communications-identity-bimi"
|
|
3
|
+
version = "0.4.0.dev2"
|
|
4
|
+
description = "Optional BIMI Mark Certificate and DNS readiness profile."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10,<3.16"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"cryptography>=46",
|
|
10
|
+
"tba-contracts-security-trust==0.1.0",
|
|
11
|
+
"tba-contracts-dns==0.4.0.dev2",
|
|
12
|
+
"tba-protocol-bimi==0.4.0.dev2",
|
|
13
|
+
"tba-protocol-dmarc==0.4.0.dev2",
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
[project.optional-dependencies]
|
|
17
|
+
workflow = ["tba-capability-communications-identity==0.4.0.dev2"]
|
|
18
|
+
|
|
19
|
+
[build-system]
|
|
20
|
+
requires = ["poetry-core>=1.0.0"]
|
|
21
|
+
build-backend = "poetry.core.masonry.api"
|
|
22
|
+
|
|
23
|
+
[tool.poetry]
|
|
24
|
+
packages = [{ include = "tba_profile_communications_identity_bimi", from = "src" }]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
|
|
3
|
+
from tba_contracts_security_trust import CertificatePathValidatorPort
|
|
4
|
+
from tba_contracts_dns import TxtResolver
|
|
5
|
+
|
|
6
|
+
from .certificate import verify_certificate
|
|
7
|
+
from .readiness import check_readiness
|
|
8
|
+
from .types import (
|
|
9
|
+
AssertionCheck,
|
|
10
|
+
BimiAssertion,
|
|
11
|
+
CertificateOutcome,
|
|
12
|
+
CheckOutcome,
|
|
13
|
+
DmarcCheck,
|
|
14
|
+
MarkType,
|
|
15
|
+
MarkVerification,
|
|
16
|
+
ReadinessResult,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class BimiProfile:
|
|
21
|
+
def __init__(self, *, dns: TxtResolver, validator: CertificatePathValidatorPort):
|
|
22
|
+
self._dns = dns
|
|
23
|
+
self._validator = validator
|
|
24
|
+
|
|
25
|
+
def check_readiness(
|
|
26
|
+
self,
|
|
27
|
+
domain: str,
|
|
28
|
+
*,
|
|
29
|
+
selector: str = "default",
|
|
30
|
+
organizational_domain: str | None = None,
|
|
31
|
+
) -> ReadinessResult:
|
|
32
|
+
return check_readiness(
|
|
33
|
+
domain,
|
|
34
|
+
dns=self._dns,
|
|
35
|
+
selector=selector,
|
|
36
|
+
organizational_domain=organizational_domain,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def verify_certificate(
|
|
40
|
+
self,
|
|
41
|
+
pem: bytes,
|
|
42
|
+
*,
|
|
43
|
+
assertion_name: str,
|
|
44
|
+
validation_time: datetime | None = None,
|
|
45
|
+
) -> MarkVerification:
|
|
46
|
+
return verify_certificate(
|
|
47
|
+
pem,
|
|
48
|
+
assertion_name=assertion_name,
|
|
49
|
+
validator=self._validator,
|
|
50
|
+
validation_time=validation_time,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
__all__ = [
|
|
55
|
+
"AssertionCheck",
|
|
56
|
+
"BimiAssertion",
|
|
57
|
+
"BimiProfile",
|
|
58
|
+
"CertificateOutcome",
|
|
59
|
+
"CheckOutcome",
|
|
60
|
+
"DmarcCheck",
|
|
61
|
+
"MarkType",
|
|
62
|
+
"MarkVerification",
|
|
63
|
+
"ReadinessResult",
|
|
64
|
+
"check_readiness",
|
|
65
|
+
"verify_certificate",
|
|
66
|
+
]
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
2
|
+
|
|
3
|
+
from tba_capability_communications_identity import DomainCheck, DomainOutcome
|
|
4
|
+
|
|
5
|
+
from . import BimiProfile
|
|
6
|
+
from .types import BimiAssertion, CertificateOutcome, CheckOutcome
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class BimiDomainChecker:
|
|
10
|
+
"""Adapt BIMI to the shared domain assessment workflow."""
|
|
11
|
+
|
|
12
|
+
profile = "bimi"
|
|
13
|
+
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
bimi: BimiProfile,
|
|
17
|
+
*,
|
|
18
|
+
evidence: Callable[[BimiAssertion], bytes | None],
|
|
19
|
+
selector: str = "default",
|
|
20
|
+
organizational_domain: str | None = None,
|
|
21
|
+
) -> None:
|
|
22
|
+
self._bimi = bimi
|
|
23
|
+
self._evidence = evidence
|
|
24
|
+
self._selector = selector
|
|
25
|
+
self._organizational_domain = organizational_domain
|
|
26
|
+
|
|
27
|
+
def check(self, domain: str, /) -> DomainCheck:
|
|
28
|
+
readiness = self._bimi.check_readiness(
|
|
29
|
+
domain,
|
|
30
|
+
selector=self._selector,
|
|
31
|
+
organizational_domain=self._organizational_domain,
|
|
32
|
+
)
|
|
33
|
+
assertion = readiness.bimi.assertion
|
|
34
|
+
details = {
|
|
35
|
+
"assertion": readiness.assertion_name,
|
|
36
|
+
"bimi": readiness.bimi.outcome.value,
|
|
37
|
+
"dmarc": readiness.dmarc.outcome.value,
|
|
38
|
+
}
|
|
39
|
+
if CheckOutcome.INDETERMINATE in (
|
|
40
|
+
readiness.bimi.outcome,
|
|
41
|
+
readiness.dmarc.outcome,
|
|
42
|
+
):
|
|
43
|
+
return DomainCheck(readiness.domain, DomainOutcome.INDETERMINATE, details)
|
|
44
|
+
if not readiness.ready or assertion is None:
|
|
45
|
+
return DomainCheck(readiness.domain, DomainOutcome.NOT_READY, details)
|
|
46
|
+
try:
|
|
47
|
+
pem = self._evidence(assertion)
|
|
48
|
+
except OSError:
|
|
49
|
+
pem = None
|
|
50
|
+
if pem is None:
|
|
51
|
+
details["certificate"] = "unavailable"
|
|
52
|
+
return DomainCheck(readiness.domain, DomainOutcome.INDETERMINATE, details)
|
|
53
|
+
result = self._bimi.verify_certificate(pem, assertion_name=assertion.name)
|
|
54
|
+
details.update(
|
|
55
|
+
certificate=result.outcome.value,
|
|
56
|
+
certificate_sha256=result.sha256,
|
|
57
|
+
mark_type=result.mark_type.value if result.mark_type else None,
|
|
58
|
+
)
|
|
59
|
+
outcome = {
|
|
60
|
+
CertificateOutcome.VALID: DomainOutcome.READY,
|
|
61
|
+
CertificateOutcome.INVALID: DomainOutcome.NOT_READY,
|
|
62
|
+
CertificateOutcome.INDETERMINATE: DomainOutcome.INDETERMINATE,
|
|
63
|
+
}[result.outcome]
|
|
64
|
+
return DomainCheck(readiness.domain, outcome, details)
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from hashlib import sha256
|
|
3
|
+
|
|
4
|
+
from cryptography import x509
|
|
5
|
+
from cryptography.hazmat.primitives import serialization
|
|
6
|
+
from tba_contracts_security_trust import (
|
|
7
|
+
CertificateArtifact,
|
|
8
|
+
CertificatePathValidationRequest,
|
|
9
|
+
CertificatePathValidatorPort,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
from .logotype import verify_subject_logo
|
|
13
|
+
from .records import assertion_owner, normalize_domain, normalize_selector
|
|
14
|
+
from .types import CertificateOutcome, MarkType, MarkVerification
|
|
15
|
+
|
|
16
|
+
_MARK_TYPE = x509.ObjectIdentifier("1.3.6.1.4.1.53087.1.13")
|
|
17
|
+
_MARK_POLICY = x509.ObjectIdentifier("1.3.6.1.4.1.53087.1.1")
|
|
18
|
+
_BIMI_EKU = x509.ObjectIdentifier("1.3.6.1.5.5.7.3.31")
|
|
19
|
+
_LOGOTYPE = x509.ObjectIdentifier("1.3.6.1.5.5.7.1.12")
|
|
20
|
+
_TYPES = {
|
|
21
|
+
"Registered Mark": MarkType.VMC,
|
|
22
|
+
"Government Mark": MarkType.VMC,
|
|
23
|
+
"Prior Use Mark": MarkType.CMC,
|
|
24
|
+
"Modified Registered Mark": MarkType.CMC,
|
|
25
|
+
"Provisional Mark": MarkType.CMC,
|
|
26
|
+
}
|
|
27
|
+
_MAX_PEM_BYTES = 512 * 1024
|
|
28
|
+
_MAX_CHAIN = 10
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _normalize_assertion(name: str) -> tuple[str, str]:
|
|
32
|
+
selector, separator, domain = name.lower().partition("._bimi.")
|
|
33
|
+
if not separator:
|
|
34
|
+
raise ValueError("assertion name must be <selector>._bimi.<domain>")
|
|
35
|
+
domain = normalize_domain(domain)
|
|
36
|
+
return assertion_owner(normalize_selector(selector), domain), domain
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _matches_name(name: str, owner: str, domain: str) -> bool:
|
|
40
|
+
try:
|
|
41
|
+
if "._bimi." in name.lower():
|
|
42
|
+
return _normalize_assertion(name)[0] == owner
|
|
43
|
+
return normalize_domain(name) == domain
|
|
44
|
+
except ValueError:
|
|
45
|
+
return False
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _validate_leaf(leaf: x509.Certificate, owner: str, domain: str) -> MarkType:
|
|
49
|
+
marks = leaf.subject.get_attributes_for_oid(_MARK_TYPE)
|
|
50
|
+
if len(marks) != 1 or marks[0].value not in _TYPES:
|
|
51
|
+
raise ValueError("unknown or ambiguous BIMI mark type")
|
|
52
|
+
policies = leaf.extensions.get_extension_for_class(x509.CertificatePolicies).value
|
|
53
|
+
if not any(policy.policy_identifier == _MARK_POLICY for policy in policies):
|
|
54
|
+
raise ValueError("certificate is missing the Mark Certificate policy")
|
|
55
|
+
eku = leaf.extensions.get_extension_for_class(x509.ExtendedKeyUsage).value
|
|
56
|
+
if _BIMI_EKU not in eku:
|
|
57
|
+
raise ValueError("certificate is missing the BIMI EKU")
|
|
58
|
+
sans = leaf.extensions.get_extension_for_class(x509.SubjectAlternativeName).value
|
|
59
|
+
if not any(
|
|
60
|
+
_matches_name(name, owner, domain)
|
|
61
|
+
for name in sans.get_values_for_type(x509.DNSName)
|
|
62
|
+
):
|
|
63
|
+
raise ValueError("certificate SAN does not match the BIMI assertion name")
|
|
64
|
+
logo = leaf.extensions.get_extension_for_oid(_LOGOTYPE).value
|
|
65
|
+
if not isinstance(logo, x509.UnrecognizedExtension):
|
|
66
|
+
raise ValueError("unsupported BIMI logotype representation")
|
|
67
|
+
verify_subject_logo(logo.value)
|
|
68
|
+
return _TYPES[marks[0].value]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def verify_certificate(
|
|
72
|
+
pem: bytes,
|
|
73
|
+
*,
|
|
74
|
+
assertion_name: str,
|
|
75
|
+
validator: CertificatePathValidatorPort,
|
|
76
|
+
validation_time: datetime | None = None,
|
|
77
|
+
) -> MarkVerification:
|
|
78
|
+
owner, domain = _normalize_assertion(assertion_name)
|
|
79
|
+
if len(pem) > _MAX_PEM_BYTES:
|
|
80
|
+
return MarkVerification(
|
|
81
|
+
CertificateOutcome.INVALID, errors=("certificate bundle is too large",)
|
|
82
|
+
)
|
|
83
|
+
try:
|
|
84
|
+
leaf, *chain = x509.load_pem_x509_certificates(pem)
|
|
85
|
+
if len(chain) >= _MAX_CHAIN:
|
|
86
|
+
raise ValueError("certificate bundle has too many certificates")
|
|
87
|
+
der = leaf.public_bytes(serialization.Encoding.DER)
|
|
88
|
+
except ValueError:
|
|
89
|
+
return MarkVerification(
|
|
90
|
+
CertificateOutcome.INVALID, errors=("invalid PEM certificate bundle",)
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
fingerprint = sha256(der).hexdigest()
|
|
94
|
+
try:
|
|
95
|
+
mark_type = _validate_leaf(leaf, owner, domain)
|
|
96
|
+
except (ValueError, x509.ExtensionNotFound, x509.DuplicateExtension) as exc:
|
|
97
|
+
return MarkVerification(
|
|
98
|
+
CertificateOutcome.INVALID, sha256=fingerprint, errors=(str(exc),)
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
profile = "bimi-mark"
|
|
102
|
+
result = validator.validate(
|
|
103
|
+
CertificatePathValidationRequest(
|
|
104
|
+
leaf=CertificateArtifact(der, profile),
|
|
105
|
+
intermediates=tuple(
|
|
106
|
+
cert.public_bytes(serialization.Encoding.DER) for cert in chain
|
|
107
|
+
),
|
|
108
|
+
validation_time=validation_time,
|
|
109
|
+
)
|
|
110
|
+
)
|
|
111
|
+
if result.profile != profile:
|
|
112
|
+
return MarkVerification(
|
|
113
|
+
CertificateOutcome.INVALID,
|
|
114
|
+
mark_type,
|
|
115
|
+
fingerprint,
|
|
116
|
+
errors=("validator returned the wrong certificate profile",),
|
|
117
|
+
)
|
|
118
|
+
if getattr(result, "indeterminate", False):
|
|
119
|
+
outcome = CertificateOutcome.INDETERMINATE
|
|
120
|
+
else:
|
|
121
|
+
outcome = (
|
|
122
|
+
CertificateOutcome.VALID if result.valid else CertificateOutcome.INVALID
|
|
123
|
+
)
|
|
124
|
+
return MarkVerification(
|
|
125
|
+
outcome, mark_type, fingerprint, result.trust_anchor_id, tuple(result.errors)
|
|
126
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from tba_contracts_dns import TxtResolver
|
|
2
|
+
from tba_protocol_dmarc import PolicyStatus, discover_policy
|
|
3
|
+
|
|
4
|
+
from .types import CheckOutcome, DmarcCheck
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def check_dmarc(
|
|
8
|
+
dns: TxtResolver, domain: str, organizational_domain: str | None
|
|
9
|
+
) -> DmarcCheck:
|
|
10
|
+
result = discover_policy(dns, domain, organizational_domain)
|
|
11
|
+
if result.status is PolicyStatus.TEMPORARY_FAILURE:
|
|
12
|
+
return DmarcCheck(
|
|
13
|
+
CheckOutcome.INDETERMINATE,
|
|
14
|
+
result.organizational_domain,
|
|
15
|
+
result.policy_source,
|
|
16
|
+
reason=result.reason,
|
|
17
|
+
)
|
|
18
|
+
if result.status is PolicyStatus.INVALID:
|
|
19
|
+
return DmarcCheck(
|
|
20
|
+
CheckOutcome.FAIL,
|
|
21
|
+
result.organizational_domain,
|
|
22
|
+
result.policy_source,
|
|
23
|
+
reason=result.reason,
|
|
24
|
+
)
|
|
25
|
+
if result.organizational_record is None or result.record is None:
|
|
26
|
+
return DmarcCheck(
|
|
27
|
+
CheckOutcome.MISSING,
|
|
28
|
+
result.organizational_domain,
|
|
29
|
+
reason="an organizational DMARC policy is required",
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
outcome = CheckOutcome.PASS
|
|
33
|
+
reason = None
|
|
34
|
+
if any(
|
|
35
|
+
record.policy == "none"
|
|
36
|
+
or record.subdomain_policy == "none"
|
|
37
|
+
or record.testing
|
|
38
|
+
or record.legacy_percentage < 100
|
|
39
|
+
for record in (result.organizational_record, result.record)
|
|
40
|
+
):
|
|
41
|
+
outcome = CheckOutcome.FAIL
|
|
42
|
+
reason = "BIMI requires full DMARC enforcement at the author and organizational domains"
|
|
43
|
+
return DmarcCheck(
|
|
44
|
+
outcome,
|
|
45
|
+
result.organizational_domain,
|
|
46
|
+
result.policy_source,
|
|
47
|
+
result.effective_policy,
|
|
48
|
+
reason,
|
|
49
|
+
)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from tba_contracts_dns import TxtResolver
|
|
2
|
+
|
|
3
|
+
from .dmarc import check_dmarc
|
|
4
|
+
from .records import (
|
|
5
|
+
assertion_owner,
|
|
6
|
+
discover_assertion,
|
|
7
|
+
normalize_domain,
|
|
8
|
+
normalize_selector,
|
|
9
|
+
)
|
|
10
|
+
from .types import ReadinessResult
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def check_readiness(
|
|
14
|
+
domain: str,
|
|
15
|
+
*,
|
|
16
|
+
dns: TxtResolver,
|
|
17
|
+
selector: str = "default",
|
|
18
|
+
organizational_domain: str | None = None,
|
|
19
|
+
) -> ReadinessResult:
|
|
20
|
+
domain = normalize_domain(domain)
|
|
21
|
+
selector = normalize_selector(selector)
|
|
22
|
+
assertion_owner(selector, domain)
|
|
23
|
+
dmarc = check_dmarc(dns, domain, organizational_domain)
|
|
24
|
+
bimi = discover_assertion(dns, domain, selector, dmarc.organizational_domain)
|
|
25
|
+
return ReadinessResult(domain, selector, bimi, dmarc)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from tba_contracts_dns import (
|
|
2
|
+
TxtResolver,
|
|
3
|
+
normalize_domain,
|
|
4
|
+
parse_tags,
|
|
5
|
+
versioned_records,
|
|
6
|
+
)
|
|
7
|
+
from tba_protocol_bimi import AssertionStatus, assertion_owner, normalize_selector
|
|
8
|
+
from tba_protocol_bimi import discover_assertion as discover_bimi_assertion
|
|
9
|
+
|
|
10
|
+
from .types import AssertionCheck, CheckOutcome
|
|
11
|
+
|
|
12
|
+
_OUTCOMES = {
|
|
13
|
+
AssertionStatus.FOUND: CheckOutcome.PASS,
|
|
14
|
+
AssertionStatus.INVALID: CheckOutcome.FAIL,
|
|
15
|
+
AssertionStatus.MISSING: CheckOutcome.MISSING,
|
|
16
|
+
AssertionStatus.DECLINED: CheckOutcome.DECLINED,
|
|
17
|
+
AssertionStatus.TEMPORARY_FAILURE: CheckOutcome.INDETERMINATE,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def discover_assertion(
|
|
22
|
+
dns: TxtResolver, domain: str, selector: str, organizational_domain: str | None
|
|
23
|
+
) -> AssertionCheck:
|
|
24
|
+
result = discover_bimi_assertion(dns, domain, selector, organizational_domain)
|
|
25
|
+
return AssertionCheck(_OUTCOMES[result.status], result.assertion, result.reason)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
__all__ = [
|
|
29
|
+
"assertion_owner",
|
|
30
|
+
"discover_assertion",
|
|
31
|
+
"normalize_domain",
|
|
32
|
+
"normalize_selector",
|
|
33
|
+
"parse_tags",
|
|
34
|
+
"versioned_records",
|
|
35
|
+
]
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from enum import Enum
|
|
3
|
+
|
|
4
|
+
from tba_protocol_bimi import BimiAssertion
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class CheckOutcome(str, Enum):
|
|
8
|
+
PASS = "pass"
|
|
9
|
+
FAIL = "fail"
|
|
10
|
+
MISSING = "missing"
|
|
11
|
+
DECLINED = "declined"
|
|
12
|
+
INDETERMINATE = "indeterminate"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class CertificateOutcome(str, Enum):
|
|
16
|
+
VALID = "valid"
|
|
17
|
+
INVALID = "invalid"
|
|
18
|
+
INDETERMINATE = "indeterminate"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class MarkType(str, Enum):
|
|
22
|
+
CMC = "cmc"
|
|
23
|
+
VMC = "vmc"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass(frozen=True, slots=True)
|
|
27
|
+
class AssertionCheck:
|
|
28
|
+
outcome: CheckOutcome
|
|
29
|
+
assertion: BimiAssertion | None = None
|
|
30
|
+
reason: str | None = None
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@dataclass(frozen=True, slots=True)
|
|
34
|
+
class DmarcCheck:
|
|
35
|
+
outcome: CheckOutcome
|
|
36
|
+
organizational_domain: str | None = None
|
|
37
|
+
policy_source: str | None = None
|
|
38
|
+
effective_policy: str | None = None
|
|
39
|
+
reason: str | None = None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True, slots=True)
|
|
43
|
+
class ReadinessResult:
|
|
44
|
+
domain: str
|
|
45
|
+
selector: str
|
|
46
|
+
bimi: AssertionCheck
|
|
47
|
+
dmarc: DmarcCheck
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def assertion_name(self) -> str | None:
|
|
51
|
+
return self.bimi.assertion.name if self.bimi.assertion else None
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def ready(self) -> bool:
|
|
55
|
+
assertion = self.bimi.assertion
|
|
56
|
+
return (
|
|
57
|
+
self.dmarc.outcome is CheckOutcome.PASS
|
|
58
|
+
and self.bimi.outcome is CheckOutcome.PASS
|
|
59
|
+
and assertion is not None
|
|
60
|
+
and assertion.evidence_url is not None
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
@dataclass(frozen=True, slots=True)
|
|
65
|
+
class MarkVerification:
|
|
66
|
+
outcome: CertificateOutcome
|
|
67
|
+
mark_type: MarkType | None = None
|
|
68
|
+
sha256: str | None = None
|
|
69
|
+
trust_anchor_id: str | None = None
|
|
70
|
+
errors: tuple[str, ...] = ()
|