spf_parse 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +57 -0
- data/.rspec +1 -0
- data/.travis.yml +16 -0
- data/Gemfile +14 -0
- data/LICENSE +22 -0
- data/LICENSE.txt +22 -0
- data/README.md +57 -0
- data/Rakefile +23 -0
- data/bin/spf +30 -0
- data/lib/spf_parse/version.rb +3 -0
- data/lib/spf_parse.rb +25 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/spf_parse_spec.rb +36 -0
- data/spf_parse.gemspec +24 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 747139ef2f19abff4a5678df8442085b6c4887c9
|
4
|
+
data.tar.gz: c7287ea92191bc32566118862f5446b385023dbc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b7f5d54159e5f133d6ca00b1a8944a1f3b5372b67cd32a6216e2f7f720e880c13e0c02b15c68938de182c6d9d6989e0280470f2954c223893721b9f849800ba
|
7
|
+
data.tar.gz: f57ea5e6d432ef69b83fb4497a2d7498a4d675ab02fbfe0e2f7bebf2f9e41e0ff607fc07a009ee3479b4b7ca1aaf35387dc5edd2b08ed075b673405ba1bea0d3
|
data/.gitignore
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
<<<<<<< HEAD
|
2
|
+
<<<<<<< HEAD
|
3
|
+
/.bundle/
|
4
|
+
/.yardoc
|
5
|
+
/Gemfile.lock
|
6
|
+
/_yardoc/
|
7
|
+
/coverage/
|
8
|
+
/doc/
|
9
|
+
/pkg/
|
10
|
+
/spec/reports/
|
11
|
+
/tmp/
|
12
|
+
*.bundle
|
13
|
+
*.so
|
14
|
+
*.o
|
15
|
+
*.a
|
16
|
+
mkmf.log
|
17
|
+
=======
|
18
|
+
=======
|
19
|
+
>>>>>>> fed1141939dbe709d44dedb0247d31908300c31f
|
20
|
+
*.gem
|
21
|
+
*.rbc
|
22
|
+
/.config
|
23
|
+
/coverage/
|
24
|
+
/InstalledFiles
|
25
|
+
/pkg/
|
26
|
+
/spec/reports/
|
27
|
+
/test/tmp/
|
28
|
+
/test/version_tmp/
|
29
|
+
/tmp/
|
30
|
+
|
31
|
+
## Specific to RubyMotion:
|
32
|
+
.dat*
|
33
|
+
.repl_history
|
34
|
+
build/
|
35
|
+
|
36
|
+
## Documentation cache and generated files:
|
37
|
+
/.yardoc/
|
38
|
+
/_yardoc/
|
39
|
+
/doc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalisation:
|
43
|
+
/.bundle/
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
<<<<<<< HEAD
|
55
|
+
>>>>>>> 62c17ee30b1a7d25ef12fab39fd6c2de0bcbadbc
|
56
|
+
=======
|
57
|
+
>>>>>>> fed1141939dbe709d44dedb0247d31908300c31f
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.3
|
4
|
+
- 2.0.0
|
5
|
+
- 2.1.1
|
6
|
+
- 2.1.2
|
7
|
+
- ruby-head
|
8
|
+
- jruby-19mode
|
9
|
+
- jruby-head
|
10
|
+
- rbx-2
|
11
|
+
matrix:
|
12
|
+
allow_failures:
|
13
|
+
- rvm: rbx-2
|
14
|
+
addons:
|
15
|
+
code_climate:
|
16
|
+
repo_token: e649f3a8e0e9e03d26febcff08fce5d76d831ab9ee5d02a06b83bab7180c0587
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Trail of Bits
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 nickespo
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# spf_parse
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/trailofbits/spf_parse.png)](https://codeclimate.com/github/trailofbits/spf_parse) [![Build Status](https://travis-ci.org/trailofbits/spf_parse.svg)](https://travis-ci.org/trailofbits/spf_parse)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/trailofbits/spf_parse/badges/coverage.svg)](https://codeclimate.com/github/trailofbits/spf_parse)
|
5
|
+
|
6
|
+
The `spf_parse` library searches the spf records for a host. We assume the host uses standard spf 'selectors', and also check if they use their own 'selector'.
|
7
|
+
|
8
|
+
## Examples
|
9
|
+
|
10
|
+
###CLI
|
11
|
+
___
|
12
|
+
-use a single domain
|
13
|
+
|
14
|
+
spf google.com
|
15
|
+
____________________________
|
16
|
+
SPF record search for google.com
|
17
|
+
- found SPF record for google.com at google.com:
|
18
|
+
v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all
|
19
|
+
____________________________
|
20
|
+
|
21
|
+
|
22
|
+
-or a bunch in a row
|
23
|
+
|
24
|
+
spf trailofbits.com facebook.com yahoo.com
|
25
|
+
____________________________
|
26
|
+
SPF record search for trailofbits.com
|
27
|
+
- found SPF record for trailofbits.com at trailofbits.com:
|
28
|
+
v=spf1 include:_spf.google.com ~all
|
29
|
+
____________________________
|
30
|
+
|
31
|
+
____________________________
|
32
|
+
SPF record search for facebook.com
|
33
|
+
- found SPF record for facebook.com at facebook.com:
|
34
|
+
v=spf1 redirect=_spf.facebook.com
|
35
|
+
____________________________
|
36
|
+
|
37
|
+
____________________________
|
38
|
+
SPF record search for yahoo.com
|
39
|
+
- found SPF record for yahoo.com at yahoo.com:
|
40
|
+
v=spf1 redirect=_spf.mail.yahoo.com
|
41
|
+
____________________________
|
42
|
+
|
43
|
+
###In a project
|
44
|
+
___
|
45
|
+
require 'spf_parse'
|
46
|
+
|
47
|
+
SpfParse.check_host('twitter.com')
|
48
|
+
=> {:record=>"v=spf1 ip4:199.16.156.0/22 ip4:199.59.148.0/22 ip4:8.25.194.0/23 ip4:8.25.196.0/23 ip4:204.92.114.203 ip4:204.92.114.204/31 ip4:107.20.52.15 ip4:23.21.83.90 include:_spf.google.com include:_thirdparty.twitter.com -all", :record_path=>"twitter.com"}
|
49
|
+
|
50
|
+
|
51
|
+
## Install
|
52
|
+
|
53
|
+
rake install
|
54
|
+
|
55
|
+
## License
|
56
|
+
|
57
|
+
See the {file:LICENSE.txt} file.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'bundler/setup'
|
6
|
+
rescue LoadError => e
|
7
|
+
warn e.message
|
8
|
+
warn "Run `gem install bundler` to install Bundler."
|
9
|
+
exit -1
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'rake'
|
13
|
+
require 'bundler/gem_tasks'
|
14
|
+
|
15
|
+
require 'rspec/core/rake_task'
|
16
|
+
RSpec::Core::RakeTask.new
|
17
|
+
|
18
|
+
task :test => :spec
|
19
|
+
task :default => :spec
|
20
|
+
|
21
|
+
require 'yard'
|
22
|
+
YARD::Rake::YardocTask.new
|
23
|
+
task :doc => :yard
|
data/bin/spf
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'spf_parse'
|
4
|
+
require 'resolv'
|
5
|
+
|
6
|
+
unless ARGV[0]
|
7
|
+
puts "Please supply at least one host name"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
resolver = Resolv::DNS.new
|
12
|
+
ARGV.each do |arg|
|
13
|
+
|
14
|
+
puts "____________________________\n"
|
15
|
+
puts "SPF record search for #{arg}"
|
16
|
+
begin
|
17
|
+
spf = SpfParse.check_host(arg, resolver)
|
18
|
+
rescue
|
19
|
+
puts " -error: could not process input :#{arg}"
|
20
|
+
puts "____________________________\n\n"
|
21
|
+
next
|
22
|
+
end
|
23
|
+
|
24
|
+
if spf
|
25
|
+
puts " - found SPF record for #{arg} at #{spf[:record_path]}:\n #{spf[:record]}"
|
26
|
+
else
|
27
|
+
puts " - no SPF record found for #{arg}"
|
28
|
+
end
|
29
|
+
puts "____________________________\n\n"
|
30
|
+
end
|
data/lib/spf_parse.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spf_parse/version"
|
2
|
+
require 'resolv'
|
3
|
+
|
4
|
+
module SpfParse
|
5
|
+
def self.check_host(host, resolver=Resolv::DNS.new)
|
6
|
+
begin
|
7
|
+
host_without_tld = host[0...host.rindex('.')]
|
8
|
+
rescue
|
9
|
+
raise StandardError.new('host'), "invalid hostname"
|
10
|
+
end
|
11
|
+
paths = [host, "_spf.#{host}"]
|
12
|
+
spf = nil
|
13
|
+
paths.each do |path|
|
14
|
+
begin
|
15
|
+
spf = resolver.getresource(path, Resolv::DNS::Resource::IN::TXT).strings.join
|
16
|
+
if spf.index('v=spf1')
|
17
|
+
spf = {:record =>spf, :record_path=>path}
|
18
|
+
break
|
19
|
+
end
|
20
|
+
rescue Resolv::ResolvError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
spf
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'spf_parse'
|
3
|
+
|
4
|
+
describe SpfParse do
|
5
|
+
describe "spf" do
|
6
|
+
context "when given a domain which we know to have a SPF record" do
|
7
|
+
let(:domain) { 'trailofbits.com' }
|
8
|
+
|
9
|
+
it "should return a hash containing the SPF record and path where it was found" do
|
10
|
+
spf = SpfParse.check_host(domain)
|
11
|
+
|
12
|
+
expect(spf).to be_kind_of(Hash)
|
13
|
+
expect(spf[:record_path]).to ( eq("#{domain}") || eq("_spf.#{domain}") )
|
14
|
+
puts " - record path: #{spf[:record_path]}"
|
15
|
+
puts " - record: #{spf[:record]}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "when given a domain which does not have a SPF record" do
|
20
|
+
let(:domain) { 'fsho.trailofbits.com' }
|
21
|
+
|
22
|
+
it "should return nil" do
|
23
|
+
spf = SpfParse.check_host(domain)
|
24
|
+
expect(spf).to eq(nil)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "when given a bad domain" do
|
29
|
+
it "should raise an error explaining that the domain was malformed" do
|
30
|
+
expect {
|
31
|
+
SpfParse.check_host('qwerty')
|
32
|
+
}.to raise_error
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spf_parse.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'spf_parse/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "spf_parse"
|
8
|
+
gem.version = SpfParse::VERSION
|
9
|
+
gem.authors = ["nicktitle"]
|
10
|
+
gem.email = ["nick.esposito@trailofbits.com"]
|
11
|
+
gem.summary = %q{SPF Retriever and Parser}
|
12
|
+
gem.description = %q{Search and retrieve SPF records for any number of hosts}
|
13
|
+
gem.homepage = "https://github.com/trailofbits/spf_parse#readme"
|
14
|
+
gem.license = "MIT"
|
15
|
+
|
16
|
+
gem.files = `git ls-files -z`.split("\x0")
|
17
|
+
gem.executables = ['spf']
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ["lib"]
|
20
|
+
gem.required_ruby_version = '>= 1.9.1'
|
21
|
+
|
22
|
+
gem.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
gem.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spf_parse
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nicktitle
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Search and retrieve SPF records for any number of hosts
|
42
|
+
email:
|
43
|
+
- nick.esposito@trailofbits.com
|
44
|
+
executables:
|
45
|
+
- spf
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- .rspec
|
51
|
+
- .travis.yml
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- bin/spf
|
58
|
+
- lib/spf_parse.rb
|
59
|
+
- lib/spf_parse/version.rb
|
60
|
+
- spec/spec_helper.rb
|
61
|
+
- spec/spf_parse_spec.rb
|
62
|
+
- spf_parse.gemspec
|
63
|
+
homepage: https://github.com/trailofbits/spf_parse#readme
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.9.1
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: SPF Retriever and Parser
|
87
|
+
test_files:
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
- spec/spf_parse_spec.rb
|
90
|
+
has_rdoc:
|