viaspf

This library is experimental/in development. The API is not stable yet. Please try out the master branch, feedback on API and implementation is welcome!

The viaspf library is a complete implementation of the Sender Policy Framework (SPF) protocol, version 1, as described in [RFC 7208]. It is written in the Rust programming language.

This library implements the core SPF protocol, but it does not itself do DNS queries and it does not depend on a DNS library. Users of this library must provide an implementation of a DNS lookup trait in order to perform SPF queries. That way, we hope to enable users to choose themselves which DNS resolver they want to use to implement their SPF verifier applications.

This library was first created in a ‘clean room’ setting, that is, it was written from scratch, referring only to the RFC. It can therefore be considered an independent alternative to existing SPF protocol implementations.

The minimum supported Rust version is 1.42.0.

Usage

In order to actually put this library to use, the trait viaspf::Lookup must be implemented.

trait Lookup { fn lookup_a(&self, name: &Name) -> LookupResult<Vec<Ipv4Addr>>; fn lookup_aaaa(&self, name: &Name) -> LookupResult<Vec<Ipv6Addr>>; fn lookup_mx(&self, name: &Name) -> LookupResult<Vec<Name>>; fn lookup_txt(&self, name: &Name) -> LookupResult<Vec<String>>; fn lookup_ptr(&self, ip: IpAddr) -> LookupResult<Vec<Name>>; }

The implementation of this trait serves as a DNS resolver. All DNS queries are performed through that resolver.

The example application included with this library contains an implementation of the Lookup trait.

Examples

A simple SPF verifier is provided as a an executable example: the command-line tool spfquery. This program uses the [Trust-DNS] DNS resolver to perform DNS lookups.

Pass an IP address and a domain as arguments to spfquery. The query is then evaluated and the result and a trace is printed out.

cargo run --example spfquery 83.166.150.145 gluet.ch

IP: 83.166.150.145 Domain: gluet.ch SPF result: pass Trace: executing SPF query for domain "gluet.ch" evaluating SPF record "v=spf1 mx -all" evaluating directive "mx" processing MX name "mail.gluet.ch" processing IP address 83.166.150.145 mechanism "mx" matched evaluated directive to result "pass"

Licence

Copyright © 2020 David Bürgin

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.