-
Notifications
You must be signed in to change notification settings - Fork 0
/
xml.go
347 lines (306 loc) · 9.81 KB
/
xml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
A direct translation of the XML described in RFC7489 Appendix C, representing an
aggregate DMARC report generated by a receiver.
I am including the XML specification for each type in order to make sure it's
all covered. I am, however, omitting the comments from the RFC. For more
information, see https://tools.ietf.org/html/rfc7489#appendix-C.
*/
package dmarc
import (
"encoding/xml"
)
/*
Represents the range of time which the report covers. Specified in seconds since
epoch (UTC).
<xs:complexType name="DateRangeType">
<xs:all>
<xs:element name="begin" type="xs:integer"/>
<xs:element name="end" type="xs:integer"/>
</xs:all>
</xs:complexType>
*/
type DateRange struct {
Begin int `xml:"begin"`
End int `xml:"end"`
}
/*
Metadata about the receiver generating the report, and the report itself.
<xs:complexType name="ReportMetadataType">
<xs:sequence>
<xs:element name="org_name" type="xs:string"/>
<xs:element name="email" type="xs:string"/>
<xs:element name="extra_contact_info" type="xs:string"
minOccurs="0"/>
<xs:element name="report_id" type="xs:string"/>
<xs:element name="date_range" type="DateRangeType"/>
<xs:element name="error" type="xs:string" minOccurs="0"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
*/
type Metadata struct {
OrgName string `xml:"org_name"`
Email string `xml:"email"`
ExtraContactInfo string `xml:"extra_contact_info,omitempty"`
ReportId string `xml:"report_id"`
DateRange DateRange `xml:"date_range"`
Error []string `xml:"error,omitempty"`
}
/*
Alignment mode. "r" for relaxed, or "s" for strict.
<xs:simpleType name="AlignmentType">
<xs:restriction base="xs:string">
<xs:enumeration value="r"/>
<xs:enumeration value="s"/>
</xs:restriction>
</xs:simpleType>
*/
type Alignment string
/*
The applied DMARC disposition mode.
<xs:simpleType name="DispositionType">
<xs:restriction base="xs:string">
<xs:enumeration value="none"/>
<xs:enumeration value="quarantine"/>
<xs:enumeration value="reject"/>
</xs:restriction>
</xs:simpleType>
*/
type Disposition string
/*
The DMARC policy applied to the messages.
<xs:complexType name="PolicyPublishedType">
<xs:all>
<xs:element name="domain" type="xs:string"/>
<xs:element name="adkim" type="AlignmentType" minOccurs="0"/>
<xs:element name="aspf" type="AlignmentType" minOccurs="0"/>
<xs:element name="p" type="DispositionType"/>
<xs:element name="sp" type="DispositionType"/>
<xs:element name="pct" type="xs:integer"/>
<xs:element name="fo" type="xs:string"/>
</xs:all>
</xs:complexType>
*/
type PolicyPublished struct {
Domain string `xml:"domain"`
Adkim Alignment `xml:"adkim,omitempty"`
Aspf Alignment `xml:"aspf,omitempty"`
P Disposition `xml:"p"`
Sp Disposition `xml:"sp"`
Pct int `xml:"pct"`
Fo string `xml:"fo,omitempty"`
}
/*
The result of the DMARC-aligned authentication. "pass" or "fail".
<xs:simpleType name="DMARCResultType">
<xs:restriction base="xs:string">
<xs:enumeration value="pass"/>
<xs:enumeration value="fail"/>
</xs:restriction>
</xs:simpleType>
*/
type DMARCResult string
/*
Reason for deviating from the Domain Owener's published policy. See RFC7489,
section 6.
<xs:simpleType name="PolicyOverrideType">
<xs:restriction base="xs:string">
<xs:enumeration value="forwarded"/>
<xs:enumeration value="sampled_out"/>
<xs:enumeration value="trusted_forwarder"/>
<xs:enumeration value="mailing_list"/>
<xs:enumeration value="local_policy"/>
<xs:enumeration value="other"/>
</xs:restriction>
</xs:simpleType>
*/
type PolicyOverrideType string
/*
Reason for deviating from the published policy, with optional comment.
<xs:complexType name="PolicyOverrideReason">
<xs:all>
<xs:element name="type" type="PolicyOverrideType"/>
<xs:element name="comment" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
*/
type PolicyOverrideReason struct {
Type PolicyOverrideType `xml:"type"`
Comment string `xml:"comment,omitempty"`
}
/*
The result after applying the DMARC policy.
<xs:complexType name="PolicyEvaluatedType">
<xs:sequence>
<xs:element name="disposition" type="DispositionType"/>
<xs:element name="dkim" type="DMARCResultType"/>
<xs:element name="spf" type="DMARCResultType"/>
<xs:element name="reason" type="PolicyOverrideReason"
minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
*/
type PolicyEvaluated struct {
Disposition Disposition `xml:"disposition"`
Dkim DMARCResult `xml:"dkim"`
Spf DMARCResult `xml:"spf"`
OverrideReasons []PolicyOverrideReason `xml:"reason,omitempty"`
}
/*
A row in the record.
#TODO: Implement the regex for IPAddress as specified in the RFC.
<xs:complexType name="RowType">
<xs:all>
<xs:element name="source_ip" type="IPAddress"/>
<xs:element name="count" type="xs:integer"/>
<xs:element name="policy_evaluated"
type="PolicyEvaluatedType"
minOccurs="1"/>
</xs:all>
</xs:complexType>
*/
type Row struct {
SourceIp string `xml:"source_ip"`
Count int `xml:"count"`
PolicyEvaluated PolicyEvaluated `xml:"policy_evaluated"`
}
/*
The identifying headers from received messages.
Note that while both
envelope_from and header_from are required fields, in practice (from what I've
seen) only header_from is actually used.
<xs:complexType name="IdentifierType">
<xs:all>
<xs:element name="envelope_to" type="xs:string" minOccurs="0"/>
<xs:element name="envelope_from" type="xs:string" minOccurs="1"/>
<xs:element name="header_from" type="xs:string" minOccurs="1"/>
</xs:all>
</xs:complexType>
*/
type Identifier struct {
EnvelopeTo string `xml:"envelope_to,omitempty"`
MailFrom string `xml:"mail_from,omitempty"`
HeaderFrom string `xml:"header_from"`
}
/*
DKIM verification result. See RFC7001, section 2.6.1.
<xs:simpleType name="DKIMResultType">
<xs:restriction base="xs:string">
<xs:enumeration value="none"/>
<xs:enumeration value="pass"/>
<xs:enumeration value="fail"/>
<xs:enumeration value="policy"/>
<xs:enumeration value="neutral"/>
<xs:enumeration value="temperror"/>
<xs:enumeration value="permerror"/>
</xs:restriction>
</xs:simpleType>
*/
type DKIMResult string
/*
The DKIM result, along with information about the "d" and "s" parameters in the
signature.
<xs:complexType name="DKIMAuthResultType">
<xs:all>
<xs:element name="domain" type="xs:string" minOccurs="1"/>
<xs:element name="selector" type="xs:string" minOccurs="0"/>
<xs:element name="result" type="DKIMResultType" minOccurs="1"/>
<xs:element name="human_result" type="xs:string" minOccurs="0"/>
</xs:all>
</xs:complexType>
*/
type DKIMAuthResult struct {
Domain string `xml:"domain"`
Selector string `xml:"selector,omitempty"`
Result DKIMResult `xml:"result"`
HumanResult string `xml:"human_result"`
}
/*
<xs:simpleType name="SPFDomainScope">
<xs:restriction base="xs:string">
<xs:enumeration value="helo"/>
<xs:enumeration value="mfrom"/>
</xs:restriction>
</xs:simpleType>
*/
type SPFDomainScope string
/*
The result of the SPF check.
<xs:simpleType name="SPFResultType">
<xs:restriction base="xs:string">
<xs:enumeration value="none"/>
<xs:enumeration value="neutral"/>
<xs:enumeration value="pass"/>
<xs:enumeration value="fail"/>
<xs:enumeration value="softfail"/>
<xs:enumeration value="temperror"/>
<xs:enumeration value="permerror"/>
</xs:restriction>
</xs:simpleType>
*/
type SPFResult string
/*
The result of the SPF check, with domain and scope information.
<xs:complexType name="SPFAuthResultType">
<xs:all>
<xs:element name="domain" type="xs:string" minOccurs="1"/>
<xs:element name="scope" type="SPFDomainScope" minOccurs="1"/>
<xs:element name="result" type="SPFResultType" minOccurs="1"/>
</xs:all>
</xs:complexType>
*/
type SPFAuthResult struct {
Domain string `xml:"domain"`
Scope SPFDomainScope `xml:"scope,omitempty"`
Result SPFResult `xml:"result"`
}
/*
Combined raw (not influenced by DMARC) DKIM and SPF results.
<xs:complexType name="AuthResultType">
<xs:sequence>
<xs:element name="dkim" type="DKIMAuthResultType" minOccurs="0"
maxOccurs="unbounded"/>
<xs:element name="spf" type="SPFAuthResultType" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
*/
type AuthResult struct {
Dkim []DKIMAuthResult `xml:"dkim,omitempty"`
Spf []SPFAuthResult `xml:"spf"`
}
/*
Authentication results from the receiver regarding a certain set of messages.
<xs:complexType name="RecordType">
<xs:sequence>
<xs:element name="row" type="RowType"/>
<xs:element name="identifiers" type="IdentifierType"/>
<xs:element name="auth_results" type="AuthResultType"/>
</xs:sequence>
</xs:complexType>
*/
type Record struct {
Row Row `xml:"row"`
Identifier Identifier `xml:"identifiers"`
AuthResult AuthResult `xml:"auth_results"`
}
/*
Parent element tying everything together.
<xs:element name="feedback">
<xs:complexType>
<xs:sequence>
<xs:element name="version" type="xs:decimal"/>
<xs:element name="report_metadata" type="ReportMetadataType"/>
<xs:element name="policy_published" type="PolicyPublishedType"/>
<xs:element name="record" type="RecordType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
*/
type Feedback struct {
XMLName xml.Name `xml:"feedback"`
Version float32 `xml:"version,omitempty"`
Metadata Metadata `xml:"report_metadata"`
Policy PolicyPublished `xml:"policy_published"`
Records []Record `xml:"record"`
}