ietf-mxcomp
[Top] [All Lists]

SPF to XML converter

2004-05-21 16:20:29


Ok, I have to leave in about 2 minutes and might not be back until
Monday night.  Sorry for the cryptic message.



During some of the, uh, "less interesting" times in the IETF meeting,
I coded up an SPF to XML converter.  This is based on libspf-alt,
which does a very exact and complete parsing of the SPF records into
an internal parse tree.  I already had a routine to print this parse
tree out in SPF format, so all I had to do was copy the routine and
add a whole bunch of extra string literals.

Please note that I've never written a line of XML in my life, so this
code is likely to be wrong in many ways.  However, I understand the
SPF stuff very well, and this is a fathful conversion from the SPF
semantics to something close to XML.

The "SPF header:" line contains a "len=" part.  This is the size of
the byte-compiled SPF record that libspf-alt uses.



Here are some examples:

(wayne(_at_)footbone) $ ./spftest_static spf2xml "v=spf1 a mx -all"

SPF header:  version: 1  mech 3/6  mod 0/0  len=10
SPF record:  v=spf1 a mx -all
SPF record converted to XML: (16 vs 115 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1">
  <out>
    <a/>
    <mx/>
    <all result="fail"/>
  </out>
</ep>

SPF record converted to XML: (16 vs 92 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1"><out><a/><mx/><all 
result="fail"/></out></ep>



(wayne(_at_)footbone) $ ./spftest_static spf2xml "v=spf1 ip4:66.240.66.130/32 
ip4:66.240.66.131/32 ip4:66.240.66.132/32 ip4:66.240.66.133/32 
ip4:66.240.66.134/32 a ptr mx ?all"

SPF record in:  v=spf1 ip4:66.240.66.130/32 ip4:66.240.66.131/32 
ip4:66.240.66.132/32 ip4:66.240.66.133/32 ip4:66.240.66.134/32 a ptr mx ?all
no errors
SPF header:  version: 1  mech 9/38  mod 0/0  len=42
SPF record:  v=spf1 ip4:66.240.66.130 ip4:66.240.66.131 ip4:66.240.66.132 
ip4:66.240.66.133 ip4:66.240.66.134 a ptr mx ?all
SPF record converted to XML: (125 vs 274 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1">
  <out>
    <ip4>66.240.66.130</ip4>
    <ip4>66.240.66.131</ip4>
    <ip4>66.240.66.132</ip4>
    <ip4>66.240.66.133</ip4>
    <ip4>66.240.66.134</ip4>
    <a/>
    <ptr/>
    <mx/>
    <all result="neutral"/>
  </out>
</ep>

SPF record converted to XML: (125 vs 221 bytes)
<ep xmlns='http://spf.pobox.com/1' 
version="1"><out><ip4>66.240.66.130</ip4><ip4>66.240.66.131</ip4><ip4>66.240.66.132</ip4><ip4>66.240.66.133</ip4><ip4>66.240.66.134</ip4><a/><ptr/><mx/><all
 result="neutral"/></out></ep>


(wayne(_at_)footbone) $ ./spftest_static spf2xml "v=spf1 ~ip4:1.2.3.4/8 
a:smtp-out.%{d3} exists:%{ir}.hello.com exists:%{L-=+}.hello.com mx/24//48 -all"

SPF header:  version: 1  mech 6/59  mod 0/0  len=63
SPF record:  v=spf1 ~ip4:1.2.3.4/8 a:smtp-out.%{d3} exists:%{ir}.hello.com 
exists:%{L-+=}.hello.com mx/24//48 -all
SPF record converted to XML: (101 vs 356 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1">
  <out>
    <ip4 cidr4="8" result="softfail">1.2.3.4</ip4>
    <a><str>smtp-out.</str><d num_rhs="3"/>
</a>
    <exists><i rev="y"/>
<str>.hello.com</str></exists>
    <exists><l url="y" delim="-+="/>
<str>.hello.com</str></exists>
    <mx cidr4="24" cidr6="24"></mx>
    <all result="fail"/>
  </out>
</ep>

SPF record converted to XML: (101 vs 315 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1"><out><ip4 cidr4="8" 
result="softfail">1.2.3.4</ip4><a><str>smtp-out.</str><d 
num_rhs="3"/></a><exists><i rev="y"/><str>.hello.com</str></exists><exists><l 
url="y" delim="-+="/><str>.hello.com</str></exists><mx cidr4="24" 
cidr6="24"></mx><all result="fail"/></out></ep>


This is aol.com's SPF record:


(wayne(_at_)footbone) $ ./spftest_static spf2xml "v=spf1 ip4:152.163.225.0/24 
ip4:205.188.139.0/24 ip4:205.188.144.0/24 ip4:205.188.156.0/23 
ip4:205.188.159.0/24 ip4:64.12.136.0/23 ip4:64.12.138.0/24 ptr:mx.aol.com ?all"

SPF header:  version: 1  mech 9/58  mod 0/0  len=62
SPF record:  v=spf1 ip4:152.163.225.0/24 ip4:205.188.139.0/24 
ip4:205.188.144.0/24 ip4:205.188.156.0/23 ip4:205.188.159.0/24 
ip4:64.12.136.0/23 ip4:64.12.138.0/24 ptr:mx.aol.com ?all
SPF record converted to XML: (169 vs 412 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1">
  <out>
    <ip4 cidr4="24">152.163.225.0</ip4>
    <ip4 cidr4="24">205.188.139.0</ip4>
    <ip4 cidr4="24">205.188.144.0</ip4>
    <ip4 cidr4="23">205.188.156.0</ip4>
    <ip4 cidr4="24">205.188.159.0</ip4>
    <ip4 cidr4="23">64.12.136.0</ip4>
    <ip4 cidr4="24">64.12.138.0</ip4>
    <ptr><str>mx.aol.com</str></ptr>
    <all result="neutral"/>
  </out>
</ep>

SPF record converted to XML: (169 vs 359 bytes)
<ep xmlns='http://spf.pobox.com/1' version="1"><out><ip4 
cidr4="24">152.163.225.0</ip4><ip4 cidr4="24">205.188.139.0</ip4><ip4 
cidr4="24">205.188.144.0</ip4><ip4 cidr4="23">205.188.156.0</ip4><ip4 
cidr4="24">205.188.159.0</ip4><ip4 cidr4="23">64.12.136.0</ip4><ip4 
cidr4="24">64.12.138.0</ip4><ptr><str>mx.aol.com</str></ptr><all 
result="neutral"/></out></ep>



-wayne


<Prev in Thread] Current Thread [Next in Thread>
  • SPF to XML converter, wayne <=