Skip to content

Commit afaaa01

Browse files
authored
Merge pull request #112 from Snawoot/tlsrpt_zone_prop
TLSRPT follow-up updates
2 parents 097319f + b879e8a commit afaaa01

9 files changed

+19
-14
lines changed

config_examples/mta-sts-daemon.yml.internal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ host: 127.0.0.1
22
port: 8461
33
reuse_port: true
44
shutdown_timeout: 20
5-
# tlsrpt: true
65
cache:
76
type: internal
87
options:
98
cache_size: 10000
109
default_zone:
1110
strict_testing: false
1211
timeout: 4
12+
#tlsrpt: true
1313
zones:
1414
myzone:
1515
strict_testing: false

config_examples/mta-sts-daemon.yml.postgres

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ host: 127.0.0.1
22
port: 8461
33
reuse_port: true
44
shutdown_timeout: 20
5-
# tlsrpt: true
65
cache:
76
type: postgres
87
options:
98
dsn: postgres://user@%2Frun%2Fpostgresql/user
109
default_zone:
1110
strict_testing: false
1211
timeout: 4
12+
#tlsrpt: true
1313
zones:
1414
myzone:
1515
strict_testing: false

config_examples/mta-sts-daemon.yml.redis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ host: 127.0.0.1
22
port: 8461
33
reuse_port: true
44
shutdown_timeout: 20
5-
# tlsrpt: true
65
cache:
76
type: redis
87
options:
@@ -13,6 +12,7 @@ cache:
1312
default_zone:
1413
strict_testing: false
1514
timeout: 4
15+
#tlsrpt: true
1616
zones:
1717
myzone:
1818
strict_testing: false

config_examples/mta-sts-daemon.yml.redis_sentinel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ host: 127.0.0.1
22
port: 8461
33
reuse_port: true
44
shutdown_timeout: 20
5-
# tlsrpt: true
65
cache:
76
type: redis_sentinel
87
options:
@@ -18,6 +17,7 @@ cache:
1817
default_zone:
1918
strict_testing: false
2019
timeout: 4
20+
#tlsrpt: true
2121
zones:
2222
myzone:
2323
strict_testing: false

config_examples/mta-sts-daemon.yml.sqlite

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ host: 127.0.0.1
22
port: 8461
33
reuse_port: true
44
shutdown_timeout: 20
5-
# tlsrpt: true
65
cache:
76
type: sqlite
87
options:
98
filename: "/var/lib/mta-sts/cache.db"
109
default_zone:
1110
strict_testing: false
1211
timeout: 4
12+
#tlsrpt: true
1313
zones:
1414
myzone:
1515
strict_testing: false

config_examples/mta-sts-daemon.yml.sqlite_unixsock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
path: "/var/run/mta-sts.sock"
22
mode: 0666
33
shutdown_timeout: 20
4-
# tlsrpt: true
54
cache:
65
type: sqlite
76
options:
87
filename: "/var/lib/mta-sts/cache.db"
98
default_zone:
109
strict_testing: false
1110
timeout: 4
11+
#tlsrpt: true
1212
zones:
1313
myzone:
1414
strict_testing: false

man/mta-sts-daemon.yml.5.adoc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ The file is in YAML syntax with the following elements:
3030

3131
*shutdown_timeout*: (_float_) time limit granted to existing client sessions for finishing when server stops. Default: 20
3232

33-
*tlsrpt*: (_bool_) include response attributes for TLSRPT support (Postfix 3.10 and later). Default: false
34-
3533
*cache*::
3634

3735
* *type*: (_str_: _internal_|_sqlite_|_redis_|_redis_sentinel_|postgres) cache backend type. Default: internal
@@ -64,6 +62,7 @@ It is unaffected by `cache_grace` and vice versa. Default: 86400
6462
* *strict_testing*: (_bool_) enforce policy for testing domains. Default: false
6563
* *timeout*: (_int_) network operations timeout for resolver in that zone. Default: 4
6664
* *require_sni*: (_bool_) add option `servername=hostname` to policy responses to make Postfix send SNI in TLS handshake as required by RFC 8461. Requires Postfix version 3.4+. Default: true
65+
* *tlsrpt*: (_bool_) include response attributes for TLSRPT support (Postfix 3.10 and later). Default: false
6766

6867
*zones*::
6968

postfix_mta_sts_resolver/responder.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
REQUEST_ENCODING = 'utf-8'
1717

18-
ZoneEntry = collections.namedtuple('ZoneEntry', ('strict', 'resolver', 'require_sni'))
18+
ZoneEntry = collections.namedtuple('ZoneEntry', ('strict', 'resolver', 'require_sni', 'tlsrpt'))
1919

2020

2121
# pylint: disable=too-many-instance-attributes
@@ -33,19 +33,20 @@ def __init__(self, cfg, loop, cache):
3333
self._port = cfg['port']
3434
self._reuse_port = cfg['reuse_port']
3535
self._shutdown_timeout = cfg['shutdown_timeout']
36-
self._tlsrpt = cfg['tlsrpt']
3736
self._grace = cfg['cache_grace']
3837

3938
# Construct configurations and resolvers for every socketmap name
4039
self._default_zone = ZoneEntry(cfg["default_zone"]["strict_testing"],
4140
STSResolver(loop=loop,
4241
timeout=cfg["default_zone"]["timeout"]),
43-
cfg["default_zone"]["require_sni"])
42+
cfg["default_zone"]["require_sni"],
43+
cfg["default_zone"]["tlsrpt"])
4444

4545
self._zones = dict((k, ZoneEntry(zone["strict_testing"],
4646
STSResolver(loop=loop,
4747
timeout=zone["timeout"]),
48-
zone["require_sni"]))
48+
zone["require_sni"],
49+
zone["tlsrpt"]))
4950
for k, zone in cfg["zones"].items())
5051

5152
self._cache = cache
@@ -226,8 +227,13 @@ async def process_request(self, raw_req):
226227
resp = "OK secure match=" + ":".join(mxlist)
227228
if zone_cfg.require_sni:
228229
resp += " servername=hostname"
229-
if self._tlsrpt:
230+
if zone_cfg.tlsrpt:
230231
resp += " policy_type=sts policy_domain=" + domain
232+
resp += " " + " ".join("mx_host_pattern=" + mx for mx in cached.pol_body['mx'])
233+
resp += " " + " ".join(
234+
"{ policy_string = %s: %s }" % (k, v) if k != "mx" else
235+
" ".join("{ policy_string = mx: %s }" % (mx,) for mx in v)
236+
for k, v in cached.pol_body.items())
231237
return netstring.encode(resp.encode('utf-8'))
232238
else:
233239
return netstring.encode(b'NOTFOUND ')

postfix_mta_sts_resolver/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ def populate_cfg_defaults(cfg):
8787
cfg['reuse_port'] = cfg.get('reuse_port', defaults.REUSE_PORT)
8888
cfg['shutdown_timeout'] = cfg.get('shutdown_timeout',
8989
defaults.SHUTDOWN_TIMEOUT)
90-
cfg['tlsrpt'] = cfg.get('tlsrpt', defaults.TLSRPT)
9190
cfg['cache_grace'] = cfg.get('cache_grace', defaults.CACHE_GRACE)
9291

9392
if 'proactive_policy_fetching' not in cfg:
@@ -117,6 +116,7 @@ def populate_zone(zone):
117116
zone['timeout'] = zone.get('timeout', defaults.TIMEOUT)
118117
zone['strict_testing'] = zone.get('strict_testing', defaults.STRICT_TESTING)
119118
zone['require_sni'] = zone.get('require_sni', defaults.REQUIRE_SNI)
119+
zone['tlsrpt'] = zone.get('tlsrpt', defaults.TLSRPT)
120120
return zone
121121

122122
if 'default_zone' not in cfg:

0 commit comments

Comments
 (0)