dmarcator 1.6.0 → 1.7.0
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.
- checksums.yaml +4 -4
- data/ChangeLog.md +23 -0
- data/README.md +16 -11
- data/lib/dmarcator/internal/parser.rb +37 -11
- data/lib/dmarcator/query.rb +9 -7
- data/lib/dmarcator/record.rb +6 -2
- data/lib/dmarcator/report.rb +0 -2
- data/lib/dmarcator/resolver/doh.rb +34 -19
- data/lib/dmarcator/resolver/dot.rb +13 -11
- data/lib/dmarcator/resolver/encrypted.rb +9 -3
- data/lib/dmarcator/uri.rb +15 -0
- data/lib/dmarcator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 558d54a036ce3eb0d8664fc284cd62e0333b7204c07f6ed825b4cdb1d0a2d20f
|
|
4
|
+
data.tar.gz: 28c8d4ac1d67cc23412261a3e8efba82dc5fb72f94aaa3b02a8f866a25999c3c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 240ed6386e53a130689da6f5b34e710524f390d89c7cbb511907804ed41b47cb6294a532b3c50db5c82eb3929e24e552eddd275d4516c31a9446703593c12899
|
|
7
|
+
data.tar.gz: 8cc32742b0db5c2f77389634de14acc93350315786d208f4d45a46fcc67793621a69a38d657e13fdeb9b2d6e782d28ab7f1994eb5d2a43cc320675ce16696931
|
data/ChangeLog.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
### 1.7.0 / 2026-11-21
|
|
2
|
+
|
|
3
|
+
Behaviour changes, for RFC 7489 compliance:
|
|
4
|
+
|
|
5
|
+
* DMARC tag names and keyword values are now matched case-insensitively, as RFC 7489's ABNF (RFC 5234) requires. `P=REJECT`, `SP=Quarantine`, `ADKIM=S`, `RF=AFRF`, `FO=1:D` and `rua=mailto:d@example.com!10M` all parse, and the values are normalized to lower-case atoms (`record.p == :reject`). The version string remains exact: `v=dmarc1` is still rejected, while `V=DMARC1` is accepted because the tag name is case-insensitive. `DMARCator.dmarc` selects records that begin with the version tag under the same rules.
|
|
6
|
+
* A duplicate `v=` tag is now malformed and raises `InvalidRecord` in both modes. It was previously ignored in lenient mode.
|
|
7
|
+
* A known tag with an empty value is reported as `empty DMARC tag value` in strict mode instead of `unknown DMARC tag`.
|
|
8
|
+
* A `rua`/`ruf` size limit may now use up to 20 digits, provided it fits an unsigned 64-bit integer as RFC 7489 requires. The previous cap was ten digits.
|
|
9
|
+
* `DMARCator.validate_domain` caps a domain at 246 octets rather than 248, reserving the seven octets of the `_dmarc.` prefix within the 253-octet DNS name limit. Domains of 247 or 248 octets are now rejected.
|
|
10
|
+
|
|
11
|
+
The record-parser corpus has been regenerated to record these outcomes, and new cases cover mixed-case tags, mixed-case values and units, uint64 size limits, duplicate version tags and empty tag values.
|
|
12
|
+
|
|
13
|
+
### 1.6.1 / 2026-11-21
|
|
14
|
+
|
|
15
|
+
* `Uri#to_str` is now defined on `DMARCator::Uri` and returns the same String as `Uri#to_s`, including the optional `!size` and unit. It was previously delegated to the wrapped `URI::MailTo`, so implicit String conversion (`Array#join`, `String#+`) silently dropped the size; `record.rua.join(',')` is now lossless. The contract spec gains `Uri#to_str`; no methods are removed.
|
|
16
|
+
* Freeze the `fo` entries of a parsed `Record`, and the default `fo` value, so the parsed record matches the immutability guarantee documented for 1.0.0.
|
|
17
|
+
* Stop retaining the raw report XML on `DMARCator::Report` after parsing. The input string (up to `max_report_bytes`) was held for the object's lifetime although it is never read again.
|
|
18
|
+
* Close the DoT TCP and SSL sockets when the TLS handshake fails; the sockets were only closed after a successful handshake, leaking a descriptor per failed connection.
|
|
19
|
+
* Only use records in a DNS answer whose owner name matches the queried name, and only follow a CNAME owned by it. A response could otherwise supply a record for a different name.
|
|
20
|
+
* Bound the DoH response body while streaming it, and reject an oversized declared `Content-Length` before reading. The size limit was previously checked only after the whole body had been buffered.
|
|
21
|
+
* Documentation: correct the `nokogiri` minimum (`>= 1.19.5`, not `1.10`), the record parse cost (~0.03 ms, not 0.4 ms), the per-series Ruby support wording, and the stale reference to a memoized parser and transform.
|
|
22
|
+
* CI: smoke-test the built gem so a packaging regression is caught before release.
|
|
23
|
+
|
|
1
24
|
### 1.6.0 / 2026-11-21
|
|
2
25
|
|
|
3
26
|
* Reject an injected `Resolv::DNS` that was not constructed with `raise_timeout_errors: true`. By default `Resolv` treats a complete timeout as an empty answer, so a failed lookup was indistinguishable from a name with no records, contradicting the documented fail-closed guarantee. Construct the resolver with `Resolv::DNS.new(raise_timeout_errors: true)`, or use `DMARCator::Resolver::Plain`. This is a behaviour change for callers that inject a bare `Resolv::DNS`.
|
data/README.md
CHANGED
|
@@ -107,7 +107,7 @@ The lookup methods are named after what they return:
|
|
|
107
107
|
| `DMARCator.txt_records(name)` | `Array<Resolv::DNS::Resource::IN::TXT>` — the records themselves | one lookup |
|
|
108
108
|
| `DMARCator.txt(name)` | `Array<String>` — every TXT record at `name` | one lookup |
|
|
109
109
|
| `DMARCator.dmarc(domain)` | `String` — the DMARC record text, or `nil` | one lookup |
|
|
110
|
-
| `DMARCator::Record.lookup(domain)` | `Record` — parsed | one lookup + parse (~0.
|
|
110
|
+
| `DMARCator::Record.lookup(domain)` | `Record` — parsed | one lookup + parse (~0.03 ms) |
|
|
111
111
|
| `DMARCator::Record.parse(text)` | `Record` — parsed from a string | parse only |
|
|
112
112
|
|
|
113
113
|
`DMARCator.txt` is the primitive: unfiltered, in response order, multi-chunk
|
|
@@ -176,8 +176,8 @@ domains.each do |domain|
|
|
|
176
176
|
end
|
|
177
177
|
```
|
|
178
178
|
|
|
179
|
-
Notes for large scans: `Record.lookup` adds a parse per domain (~0.
|
|
180
|
-
|
|
179
|
+
Notes for large scans: `Record.lookup` adds a parse per domain (~0.03 ms,
|
|
180
|
+
negligible next to the lookup); each lookup opens its own TCP
|
|
181
181
|
connection, so keep one resolver per thread when parallelising; and DoT/DoH add
|
|
182
182
|
a TLS handshake per lookup, so plaintext is the better choice for bulk work.
|
|
183
183
|
|
|
@@ -241,6 +241,10 @@ DMARCator::Record.parse("v=DMARC1; p=none; pct=abc", strict: true)
|
|
|
241
241
|
# => DMARCator::InvalidRecord: invalid DMARC tag value: "pct=abc"
|
|
242
242
|
```
|
|
243
243
|
|
|
244
|
+
Tag names and keyword values are matched case-insensitively, as RFC 7489's
|
|
245
|
+
ABNF requires, and parsed values are normalized to lowercase atoms. The
|
|
246
|
+
version string is the exception: `DMARC1` is exact, so `v=dmarc1` is rejected.
|
|
247
|
+
|
|
244
248
|
## Parsing XML reports
|
|
245
249
|
|
|
246
250
|
Parse a DMARC aggregate/forensic report:
|
|
@@ -322,7 +326,8 @@ XML helper, the internal resolver plumbing — may change in a minor release.
|
|
|
322
326
|
|
|
323
327
|
* `DMARCator::Record`, `DMARCator::Report` and the parsed value objects are
|
|
324
328
|
read-only after construction and safe to share between threads.
|
|
325
|
-
*
|
|
329
|
+
* Record parsing and XML report parsing keep no shared mutable state, so both
|
|
330
|
+
are safe for concurrent use.
|
|
326
331
|
* Resolvers are not necessarily safe for concurrent lookups: each lookup opens
|
|
327
332
|
its own connection, but `Resolv::DNS` (if you inject one) does not serialise
|
|
328
333
|
queries. Use one resolver per thread, or configure a factory with
|
|
@@ -338,11 +343,11 @@ removed in the next major release.
|
|
|
338
343
|
|
|
339
344
|
### Ruby support
|
|
340
345
|
|
|
341
|
-
The
|
|
342
|
-
library
|
|
343
|
-
4.0.10. Dropping support for a Ruby series is
|
|
344
|
-
|
|
345
|
-
|
|
346
|
+
The gemspec requires Ruby >= 3.3.14, which includes the regular expression
|
|
347
|
+
fixes the library uses. CI tests the oldest supported patch of each series:
|
|
348
|
+
3.3.14, 3.4.13, and 4.0.10. Dropping support for a Ruby series is the one
|
|
349
|
+
documented exception to the no-breaking-changes promise: it is announced in a
|
|
350
|
+
minor release and removed in the next major.
|
|
346
351
|
|
|
347
352
|
## Security
|
|
348
353
|
|
|
@@ -386,7 +391,7 @@ for the reporting policy and scope.
|
|
|
386
391
|
* A warning is emitted at load time if the bundled `resolv` gem is affected by
|
|
387
392
|
CVE-2026-80212/CVE-2026-80213.
|
|
388
393
|
* Domain names are validated before resolution (labels ≤ 63 octets, total ≤
|
|
389
|
-
|
|
394
|
+
246 octets, no leading/trailing hyphens).
|
|
390
395
|
* Optional [DNS over HTTPS and DNS over TLS](#dns-transport) transports verify
|
|
391
396
|
TLS certificates and fail closed: a transport failure raises
|
|
392
397
|
`DMARCator::ResolutionError` rather than being reported as a domain without a
|
|
@@ -397,7 +402,7 @@ for the reporting policy and scope.
|
|
|
397
402
|
## Requirements
|
|
398
403
|
|
|
399
404
|
* [Ruby] >= 3.3.14
|
|
400
|
-
* [nokogiri] >= 1.
|
|
405
|
+
* [nokogiri] >= 1.19.5
|
|
401
406
|
|
|
402
407
|
## Testing
|
|
403
408
|
|
|
@@ -48,8 +48,15 @@ module DMARCator
|
|
|
48
48
|
# Tags whose value is a list of mailto URIs.
|
|
49
49
|
URI_TAGS = %w[rua ruf].freeze
|
|
50
50
|
|
|
51
|
+
# Every tag the parser understands.
|
|
52
|
+
KNOWN_TAGS = (KEYWORD_TAGS.keys + DIGIT_TAGS.keys + %w[fo] + URI_TAGS).freeze
|
|
53
|
+
|
|
51
54
|
# The `v=` tag, which may only appear first.
|
|
52
|
-
|
|
55
|
+
#
|
|
56
|
+
# RFC 7489 spells the version with ABNF quoted strings and numeric
|
|
57
|
+
# terminals, so the tag name `v` is case-insensitive (RFC 5234) while the
|
|
58
|
+
# version string `DMARC1` is exact.
|
|
59
|
+
VERSION = /\A[vV][ \t]*=[ \t]*DMARC1\z/
|
|
53
60
|
|
|
54
61
|
# Characters allowed in a mailto local part and domain.
|
|
55
62
|
ADDRESS = /[A-Za-z0-9._%+-]+@[A-Za-z0-9._%+-]+/
|
|
@@ -105,10 +112,16 @@ module DMARCator
|
|
|
105
112
|
raise InvalidRecord, "duplicate DMARC tag: #{key}" if tags.key?(key)
|
|
106
113
|
|
|
107
114
|
tags[key] = value
|
|
115
|
+
when :version
|
|
116
|
+
raise InvalidRecord, 'duplicate DMARC version tag'
|
|
108
117
|
when :unknown
|
|
109
118
|
if strict
|
|
110
119
|
raise InvalidRecord, "unknown DMARC tag: #{truncate(segment).inspect}"
|
|
111
120
|
end
|
|
121
|
+
when :empty
|
|
122
|
+
if strict
|
|
123
|
+
raise InvalidRecord, "empty DMARC tag value: #{truncate(segment).inspect}"
|
|
124
|
+
end
|
|
112
125
|
when :invalid
|
|
113
126
|
if strict
|
|
114
127
|
raise InvalidRecord, "invalid DMARC tag value: #{truncate(segment).inspect}"
|
|
@@ -159,11 +172,17 @@ module DMARCator
|
|
|
159
172
|
|
|
160
173
|
return [:unknown] if value.nil?
|
|
161
174
|
|
|
162
|
-
name = name.sub(/[ \t]+\z/, '').sub(/\A[ \t]+/, '')
|
|
175
|
+
name = name.sub(/[ \t]+\z/, '').sub(/\A[ \t]+/, '').downcase(:ascii)
|
|
163
176
|
value = value.sub(/\A[ \t]+/, '').sub(/[ \t]+\z/, '')
|
|
164
177
|
|
|
165
|
-
#
|
|
166
|
-
|
|
178
|
+
# The version tag may only appear first, so a second one is a
|
|
179
|
+
# duplicate whatever its value.
|
|
180
|
+
return [:version] if name == 'v'
|
|
181
|
+
|
|
182
|
+
# An empty value is an error only for a tag the parser understands;
|
|
183
|
+
# an unknown tag is ignored either way.
|
|
184
|
+
return [:unknown] if value.empty? && !KNOWN_TAGS.include?(name)
|
|
185
|
+
return [:empty] if value.empty?
|
|
167
186
|
|
|
168
187
|
if (keywords = KEYWORD_TAGS[name])
|
|
169
188
|
keyword(name, keywords, value)
|
|
@@ -179,11 +198,13 @@ module DMARCator
|
|
|
179
198
|
end
|
|
180
199
|
|
|
181
200
|
def keyword(name, keywords, value)
|
|
182
|
-
|
|
201
|
+
folded = value.downcase(:ascii)
|
|
202
|
+
|
|
203
|
+
return [:ok, name.to_sym, folded.to_sym] if keywords.include?(folded)
|
|
183
204
|
|
|
184
205
|
# A known keyword followed by junk is a malformed record, not an
|
|
185
206
|
# invalid value: the value grammar matched and the remainder did not.
|
|
186
|
-
malformed!(value) if keywords.any? { |keyword|
|
|
207
|
+
malformed!(value) if keywords.any? { |keyword| folded.start_with?(keyword) }
|
|
187
208
|
|
|
188
209
|
[:invalid]
|
|
189
210
|
end
|
|
@@ -201,9 +222,10 @@ module DMARCator
|
|
|
201
222
|
end
|
|
202
223
|
|
|
203
224
|
def fo(value)
|
|
204
|
-
|
|
225
|
+
folded = value.downcase(:ascii)
|
|
226
|
+
return [:ok, :fo, folded.split(':')] if folded.match?(/\A[01ds](?::[01ds])*\z/)
|
|
205
227
|
|
|
206
|
-
malformed!(value) if
|
|
228
|
+
malformed!(value) if folded.match?(/\A[01ds](?::[01ds])*/)
|
|
207
229
|
|
|
208
230
|
[:invalid]
|
|
209
231
|
end
|
|
@@ -251,13 +273,17 @@ module DMARCator
|
|
|
251
273
|
size = unit = nil
|
|
252
274
|
|
|
253
275
|
if scanner.scan(/!/)
|
|
254
|
-
digits = scanner.scan(/\d{1,
|
|
276
|
+
digits = scanner.scan(/\d{1,20}/)
|
|
255
277
|
|
|
256
|
-
# A bare `!` or more than
|
|
278
|
+
# A bare `!` or more than twenty digits is an invalid value.
|
|
257
279
|
return nil if digits.nil? || scanner.match?(/\d/)
|
|
258
280
|
|
|
259
281
|
size = digits.to_i
|
|
260
|
-
|
|
282
|
+
|
|
283
|
+
# RFC 7489 requires the numeric portion to fit a uint64.
|
|
284
|
+
return nil if size > (2**64) - 1
|
|
285
|
+
|
|
286
|
+
unit = scanner.scan(/[kmgt]/i)&.downcase(:ascii)&.to_sym
|
|
261
287
|
|
|
262
288
|
# A second `!` is an invalid value.
|
|
263
289
|
return nil if scanner.match?(/!/)
|
data/lib/dmarcator/query.rb
CHANGED
|
@@ -69,9 +69,10 @@ module DMARCator
|
|
|
69
69
|
#
|
|
70
70
|
# Validates a domain before using it in a DNS query.
|
|
71
71
|
#
|
|
72
|
-
# Rejects underscores and
|
|
73
|
-
# the
|
|
74
|
-
#
|
|
72
|
+
# Rejects underscores and enforces the DNS length and label limits, reserving
|
|
73
|
+
# the seven octets of the `_dmarc.` prefix that {dmarc} adds. This is the
|
|
74
|
+
# validator for registrable domains rather than arbitrary DNS names; use
|
|
75
|
+
# {validate_txt_name} for service labels.
|
|
75
76
|
#
|
|
76
77
|
# @param [String] domain
|
|
77
78
|
# The domain to validate.
|
|
@@ -84,7 +85,7 @@ module DMARCator
|
|
|
84
85
|
#
|
|
85
86
|
def self.validate_domain(domain)
|
|
86
87
|
unless domain.is_a?(String) && !domain.empty? &&
|
|
87
|
-
domain.length <=
|
|
88
|
+
domain.length <= 246 &&
|
|
88
89
|
!domain.start_with?('.') &&
|
|
89
90
|
!domain.include?('..') &&
|
|
90
91
|
!domain.match?(/[^A-Za-z0-9.-]/) &&
|
|
@@ -248,12 +249,13 @@ module DMARCator
|
|
|
248
249
|
def self.dmarc(domain, resolver: default_resolver)
|
|
249
250
|
name = "_dmarc.#{validate_domain(domain)}"
|
|
250
251
|
|
|
251
|
-
# Per RFC 7489 §6.6.3, use the TXT record
|
|
252
|
-
#
|
|
252
|
+
# Per RFC 7489 §6.6.3, use the TXT record that starts with the `v=` tag for
|
|
253
|
+
# DMARC1. Tag names are case-insensitive (RFC 5234), so `V=` matches; the
|
|
254
|
+
# version string `DMARC1` is exact.
|
|
253
255
|
dmarc_records = lookup_txt(name, resolver: resolver).map do |record|
|
|
254
256
|
record.strings.join
|
|
255
257
|
end.select do |text|
|
|
256
|
-
text.
|
|
258
|
+
text.b.match?(/\A[vV][ \t]*=[ \t]*DMARC1[ \t]*(?:;|\z)/)
|
|
257
259
|
end
|
|
258
260
|
|
|
259
261
|
dmarc_records.first if dmarc_records.one?
|
data/lib/dmarcator/record.rb
CHANGED
|
@@ -34,6 +34,10 @@ module DMARCator
|
|
|
34
34
|
# @return [:DMARC1]
|
|
35
35
|
attr_reader :v
|
|
36
36
|
|
|
37
|
+
# Default value of the `fo=` field.
|
|
38
|
+
DEFAULT_FO = %w[0].freeze
|
|
39
|
+
private_constant :DEFAULT_FO
|
|
40
|
+
|
|
37
41
|
#
|
|
38
42
|
# Initializes the record.
|
|
39
43
|
#
|
|
@@ -66,7 +70,7 @@ module DMARCator
|
|
|
66
70
|
@v = attributes.fetch(:v)
|
|
67
71
|
@adkim = attributes[:adkim]
|
|
68
72
|
@aspf = attributes[:aspf]
|
|
69
|
-
@fo = attributes[:fo]&.freeze
|
|
73
|
+
@fo = attributes[:fo]&.map(&:freeze)&.freeze
|
|
70
74
|
@p = attributes[:p]
|
|
71
75
|
@pct = attributes[:pct]
|
|
72
76
|
@rf = attributes[:rf]
|
|
@@ -157,7 +161,7 @@ module DMARCator
|
|
|
157
161
|
# The value of the `fo=` field, or `["0"]` if the field was omitted.
|
|
158
162
|
#
|
|
159
163
|
def fo
|
|
160
|
-
@fo ||
|
|
164
|
+
@fo || DEFAULT_FO
|
|
161
165
|
end
|
|
162
166
|
|
|
163
167
|
#
|
data/lib/dmarcator/report.rb
CHANGED
|
@@ -102,25 +102,40 @@ module DMARCator
|
|
|
102
102
|
request['accept'] = CONTENT_TYPE
|
|
103
103
|
request.body = query.encode
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
105
|
+
body = +''.b
|
|
106
|
+
|
|
107
|
+
http.start do |connection|
|
|
108
|
+
connection.request(request) do |response|
|
|
109
|
+
status = response.code.to_i
|
|
110
|
+
|
|
111
|
+
unless status.between?(200, 299)
|
|
112
|
+
raise ResolutionError, "DoH endpoint returned HTTP #{status}"
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
content_type = response['content-type'].to_s
|
|
116
|
+
|
|
117
|
+
unless content_type.start_with?(CONTENT_TYPE)
|
|
118
|
+
raise ResolutionError,
|
|
119
|
+
"DoH endpoint returned unexpected content-type: #{content_type.inspect}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Reject a declared oversize before reading anything, then enforce
|
|
123
|
+
# the same bound while streaming, so a chunked or lying response
|
|
124
|
+
# cannot allocate more than the limit.
|
|
125
|
+
if response['content-length'].to_i > MAX_RESPONSE_BYTES
|
|
126
|
+
raise ResolutionError,
|
|
127
|
+
"DoH response exceeds maximum size of #{MAX_RESPONSE_BYTES} bytes"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
response.read_body do |chunk|
|
|
131
|
+
body << chunk.b
|
|
132
|
+
|
|
133
|
+
if body.bytesize > MAX_RESPONSE_BYTES
|
|
134
|
+
raise ResolutionError,
|
|
135
|
+
"DoH response exceeds maximum size of #{MAX_RESPONSE_BYTES} bytes"
|
|
136
|
+
end
|
|
137
|
+
end
|
|
138
|
+
end
|
|
124
139
|
end
|
|
125
140
|
|
|
126
141
|
body
|
|
@@ -125,22 +125,24 @@ module DMARCator
|
|
|
125
125
|
|
|
126
126
|
def with_tls
|
|
127
127
|
tcp = Socket.tcp(@host, @port, connect_timeout: @timeout)
|
|
128
|
-
|
|
128
|
+
socket = nil
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
context.set_params
|
|
130
|
+
begin
|
|
131
|
+
tcp.timeout = @timeout if tcp.respond_to?(:timeout=)
|
|
133
132
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
context = OpenSSL::SSL::SSLContext.new
|
|
134
|
+
context.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
135
|
+
context.set_params
|
|
136
|
+
|
|
137
|
+
socket = OpenSSL::SSL::SSLSocket.new(tcp, context)
|
|
138
|
+
socket.hostname = @sni unless ip_literal?(@sni)
|
|
139
|
+
socket.sync_close = true
|
|
140
|
+
socket.connect
|
|
141
|
+
socket.post_connection_check(@sni)
|
|
139
142
|
|
|
140
|
-
begin
|
|
141
143
|
yield socket
|
|
142
144
|
ensure
|
|
143
|
-
close_quietly(socket)
|
|
145
|
+
close_quietly(socket) if socket
|
|
144
146
|
close_quietly(tcp)
|
|
145
147
|
end
|
|
146
148
|
end
|
|
@@ -69,11 +69,17 @@ module DMARCator
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def collect(message, name, type, depth)
|
|
72
|
-
|
|
72
|
+
# Only answers owned by the queried name are usable: a response may
|
|
73
|
+
# carry records for other owners (an injected CNAME chain, or a
|
|
74
|
+
# malicious answer), and accepting them would let the transport return
|
|
75
|
+
# a record for a different name.
|
|
76
|
+
matching = message.answer.select do |owner, _ttl, record|
|
|
77
|
+
record.is_a?(type) && same_name?(owner, name)
|
|
78
|
+
end
|
|
73
79
|
return matching.map { |_name, _ttl, record| record } unless matching.empty?
|
|
74
80
|
|
|
75
|
-
cname = message.answer.find do |
|
|
76
|
-
record.is_a?(Resolv::DNS::Resource::IN::CNAME)
|
|
81
|
+
cname = message.answer.find do |owner, _ttl, record|
|
|
82
|
+
record.is_a?(Resolv::DNS::Resource::IN::CNAME) && same_name?(owner, name)
|
|
77
83
|
end
|
|
78
84
|
|
|
79
85
|
return fetch(cname[2].name, type, depth - 1) if cname && depth.positive?
|
data/lib/dmarcator/uri.rb
CHANGED
|
@@ -115,6 +115,21 @@ module DMARCator
|
|
|
115
115
|
return str
|
|
116
116
|
end
|
|
117
117
|
|
|
118
|
+
#
|
|
119
|
+
# Converts the DMARC URI into a String.
|
|
120
|
+
#
|
|
121
|
+
# Same as {#to_s}. It is defined so implicit String conversion, such as
|
|
122
|
+
# `Array#join` or `String#+`, keeps the optional size and unit instead of
|
|
123
|
+
# falling through to the wrapped URI.
|
|
124
|
+
#
|
|
125
|
+
# @return [String]
|
|
126
|
+
#
|
|
127
|
+
# @since 1.6.1
|
|
128
|
+
#
|
|
129
|
+
def to_str
|
|
130
|
+
to_s
|
|
131
|
+
end
|
|
132
|
+
|
|
118
133
|
private
|
|
119
134
|
|
|
120
135
|
#
|
data/lib/dmarcator/version.rb
CHANGED