forked from sdgathman/pyspf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
251 lines (187 loc) · 10.2 KB
/
README
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
************
*** NOTE ***
************
This repo was converted from CVS, and the real "master" branch is pyspf-2_0-branch. The CVS conversion doesn't always pick
the right branch to designate "master". I am still too much of a git newbie and haven't figured out how to rename
pyspf-2_0-branch to master. (I had no problem creating a pyspf-2.1 branch duplicating master.) Several hard working devs have
posted patches against this false "master", so I thought I should at least post this note until I get git figured out enough
to do the rename.
SPF
Sender-Policy-Framework queries in Python.
Quick Start
===========
Installation
------------
This package requires PyDNS (or Py3DNS for running with Python 3) and either
the ipaddr or python3.3 and later. PyDNS is available at
http://pydns.sourceforge.net. Binary and source RPMs for PyDNS are also
available from http://pymilter.sourceforge.net. Py3DNS is available on pypi
and at https://launchpad.net/py3dns. The ipaddr module is available from
http://code.google.com/p/ipaddr-py or as part of the Python standard library
starting with python3.3 (as ipaddress). This package requires authres from
either pypi or http://launchpad.net/authentication-results-python to process
and generate RFC 5451 Authentication Results headers.
After unpacking the source distribution, install this in your site-
specific Python extension directory::
% python setup.py build
% su
# python setup.py install
The minimum Python version required is python2.6. The spf module in this
version has been tested with python3.2 and does not require using 2to3. It
will work with all versions of pydns or py3dns. It works either with the
stand alone ipaddr module or the standard library ipaddress module.
Testing
-------
After this package is installed, cd into the test directory and
execute testspf.py::
% cd test
% python testspf.py
WARN: invalid-domain-long in rfc4408-tests.yml, 8.1/2, 5/10: fail preferred to temperror
WARN: txttimeout in rfc4408-tests.yml, 4.4/1: fail preferred to temperror
WARN: spfoverride in rfc4408-tests.yml, 4.5/5: pass preferred to fail
WARN: multitxt1 in rfc4408-tests.yml, 4.5/5: pass preferred to permerror
WARN: multispf2 in rfc4408-tests.yml, 4.5/6: permerror preferred to pass
..
----------------------------------------------------------------------
Ran 2 tests in 3.036s
OK
This runs the SPF council test-suite as of when this package was built.
It does not test the pyDNS installation, but uses an internal driver.
This avoids changing results due to DNS timeouts.
In addition, spf.py runs an internal self-test every time it is used from the
command line.
If you're running on Mac OS X, and it looks like DNS.DiscoverNameServers()
is failing, you'll need to edit your /etc/resolv.conf and specify a
domain name. For some reason, OS X writes out resolv.conf with a single
'domain' line, which isn't good at all. Later versions of py3dns have been
updated to better support Max OS X.
Description
===========
SPF does email sender validation. For more information about SPF,
please see http://www.openspf.org
One incompatible change was introduced in version 1.7. Prior to version 1.7,
connections from a local IP address (127...) would always return a Pass
result. The special case was eliminated. Programs calling pySPF should not
do SPF checks on locally submitted mail.
This SPF client is intended to be installed on the border MTA, checking
if incoming SMTP clients are permitted to forward mail. The SPF check
should be done during the MAIL FROM:<...> command.
There are two ways to use this package. The first is from the command
line::
% python spf.py {ip-addr} {mail-from} {helo}
For instance, during an SMTP exchange from client 69.55.226.139::
S: 220 mail.example.com ESMTP Postfix
C: EHLO mx1.wayforward.net
S: 250-mail.example.com
S: ...
S: 250 8BITMIME
C: MAIL FROM:<[email protected]>
Then the following command line would check if this is a valid sender:
% ./spf.py 69.55.226.139 [email protected] mx1.wayforward.net
('pass', 250, 'sender SPF authorized')
Command line calls return RFC 4408/7208 result codes, i.e. 'pass', 'fail',
'neutral', 'softfail, 'permerror', or 'temperror'.
The second way is via the module's APIs.
The legacy (pySPF 1.6) API:
>>> import spf
>>> spf.check(i='69.55.226.139',
... s='[email protected]',
... h='mx1.wayforward.net')
('pass', 250, 'sender SPF authorized')
The first element in the tuple is one of 'pass', 'fail', 'netural', 'softfail',
'unknown', or 'error'. The second is the SMTP response status code: 550 for
'fail', 450 for 'error' and 250 for all else. The third is an explanation.
Note: SPF results alone are never sufficient to decide that a message should be
accepted. Accept, reject, or defer decisions are a function of local reciever
policy.
The RFC 4408/7208 compliant API:
>>> import spf
>>> spf.check2(i='69.55.226.139',
... s='[email protected]',
... h='mx1.wayforward.net')
('pass', 'sender SPF verified')
The first element in the tuple is one of 'pass', 'fail', 'neutral', 'softfail,
'permerror', or 'temperror'. The second is an explanation.
This package also provides two additional helper scripts; type99.py and
spfquery.py. The type99.py script will convert DNS TXT strings to a binary
equivalent suitable for use in a BIND zone file. The spfquery.py script is a
Python reimplementination of Wayne Schlitt's spfquery command line tool.
The type99.py script is called from the command line as follows:
python type99.py "v=spf1 -all" {Note: Use your desired SPF record instead.}
\# 12 0b763d73706631202d616c6c {This is the correct result for "v=spf1 -all"}
or
python type99 - {File name}
The input file format is a standard BIND Zone file. The type99 script will add
a Type99 record for each TXT record found in the file. Use of DNS type 99
(type SPF) was removed from SPF in RFC 7208, so this script should be of
historical interest only.
The spfquery.py script is called with a number of possible options. Options can
either use standard '-' prefix or be PERL style long options, '--'. Supported
options are:
"--file" or "-file" {filename}: Read the query (or queries) from the designated
file. If {filename} is '0', then query inputs are read from STDIN.
"--ip" or "-ip" {address}: Client IP address to use for SPF check.
"--sender" or "-sender" {Mail From address}: Envelope sender from which mail was
received.
"--helo" or "-helo" {client hostname}: HELO/EHLO name used by SMTP client.
"--local" or "-local" {local policy SPF string}: Additional SPF mechanisms to be
checked on the basis of local policy. Note that local policy matches are
not strictly SPF results. Local policy processing is not defined in RFC
4408 or RFC 7208. Result may vary among SPF implementations.
"--rcpt-to" or "rcpt-to" {rcpt-to address - if available}: Receipt to address is
not used for actual SPF processing, but if available it can be useful for
logging, spf-received header construction, and providing useful rejection
messages when messages are rejected due to SPF.
--default-explanation" or "-default-explanation" {explanation string}: Default
Fail explanation string to be used.
"--sanitize" or "-sanitize" and "--debug" or "-debug": These options are no-op
in the Python implementation, but are valid inputs to provide compatibliity
with input files developed to work with the original PERL and C spfquery
implementations.
Overall per SPF check time limits can be controlled by passing querytime
to the spf.check2 function or when initializing a spf.query object.
It is set to 20 seconds by default based on RFC 7208. If querytime is set to
0, then the overall time limit is disabled and the per DNS lookup limit is used
instead. This defaults to 20 seconds and can be controlled via
spf.MAX_PER_LOOKUP_TIME. RFC 4408 says that the overall limit MAY be used and
recommends no less than 20 seconds if it is. RFC 7208 is stronger, so a
default limit aligned to the RFC requirements is now used.
The type99.py script is called from the command line as follows:
python type99.py "v=spf1 -all" {Note: Use your desired SPF record instead.}
\# 12 0b763d73706631202d616c6c {This is the correct result for "v=spf1 -all"}
or
python type99 - {File name}
The input file format is a standard BIND Zone file. The type99 script will add
a Type99 record for each TXT record found in the file.
The spfquery.py script is called with a number of possible options. Options can
either use standard '-' prefix or be PERL style long options, '--'. Supported
options are:
"--file" or "-file" {filename}: Read the query (or queries) from the designated
file. If {filename} is '0', then query inputs are read from STDIN.
"--ip" or "-ip" {address}: Client IP address to use for SPF check.
"--sender" or "-sender" {Mail From address}: Envelope sender from which mail was
received.
"--helo" or "-helo" {client hostname}: HELO/EHLO name used by SMTP client.
"--local" or "-local" {local policy SPF string}: Additional SPF mechanisms to be
checked on the basis of local policy. Note that local policy matches are
not strictly SPF results. Local policy processing is not defined in RFC
4408. Result may vary among SPF implementations.
"--rcpt-to" or "rcpt-to" {rcpt-to address - if available}: Receipt to address is
not used for actual SPF processing, but if available it can be useful for
logging, spf-received header construction, and providing useful rejection
messages when messages are rejected due to SPF.
--default-explanation" or "-default-explanation" {explanation string}: Default
Fail explanation string to be used.
"--sanitize" or "-sanitize" and "--debug" or "-debug": These options are no-op
in the Python implementation, but are valid inputs to provide compatibliity
with input files developed to work with the original PERL and C spfquery
implementations.
License: Python Software Foundation License
Author:
Terence Way [email protected]
http://www.wayforward.net/spf/
Maintainers:
Stuart Gathman [email protected]
Scott Kitterman [email protected]
http://cheeseshop.python.org/pypi/pyspf
Code is currently hosted at https://github.com/sdgathman/pyspf/