dkim-query 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +6 -0
- data/README.md +12 -5
- data/bin/dkim-query +1 -1
- data/lib/dkim/query/domain.rb +3 -0
- data/lib/dkim/query/key.rb +27 -0
- data/lib/dkim/query/malformed_key.rb +3 -0
- data/lib/dkim/query/parser.rb +19 -10
- data/lib/dkim/query/query.rb +12 -0
- data/lib/dkim/query/version.rb +2 -1
- data/spec/key_spec.rb +28 -2
- data/spec/parser_spec.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1044c31de0b41b92f7bef616f018efd5214ba8e1
|
4
|
+
data.tar.gz: 6ed8cc2e233929018e7a464457436674f25a1f33
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d0bf4acd647b16c40291120e8f172dfe529cec4dd9e0cd65f607871548684a4b8d737134981e15d001b158d885d8ee795bf9d81dfa4f078e35995309dc5a910
|
7
|
+
data.tar.gz: b3422596b4b3dc22ba95561eb22368bdd7de929db4b9a086679c14f6ea16d38d8a155c556799bc965e3774d454f3d3dce94b45f132f8c6be61530873db6bae96
|
data/ChangeLog.md
CHANGED
data/README.md
CHANGED
@@ -29,10 +29,10 @@ Parse a DKIM record:
|
|
29
29
|
# => :rsa
|
30
30
|
|
31
31
|
key.n
|
32
|
-
# => "A 1024 bit key"
|
32
|
+
# => "A 1024 bit key"
|
33
33
|
|
34
34
|
key.p
|
35
|
-
# => "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB"
|
35
|
+
# => "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB"
|
36
36
|
|
37
37
|
key.s
|
38
38
|
# => nil
|
@@ -42,8 +42,15 @@ Parse a DKIM record:
|
|
42
42
|
|
43
43
|
Query all keys for a domain:
|
44
44
|
|
45
|
-
DKIM::Query::Domain.query('yahoo.com')
|
46
|
-
# => #<DKIM::Query::Domain:0x0000000315c950 @name="yahoo.com", @keys={"s1024"=>#<DKIM::Query::Key:0x0000000315c9f0 @v=nil, @g=nil, @h=nil, @k=:rsa, @n="A 1024 bit key;"
|
45
|
+
domain = DKIM::Query::Domain.query('yahoo.com')
|
46
|
+
# => #<DKIM::Query::Domain:0x0000000315c950 @name="yahoo.com", @keys={"s1024"=>#<DKIM::Query::Key:0x0000000315c9f0 @v=nil, @g=nil, @h=nil, @k=:rsa, @n="A 1024 bit key;", @p="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB", @s=nil, @t=nil>}>
|
47
|
+
|
48
|
+
domain['s1024']
|
49
|
+
# => #<DKIM::Query::Key:0x0000000315c9f0 @v=nil, @g=nil, @h=nil, @k=:rsa, @n="A 1024 bit key;", @p="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB", @s=nil, @t=nil>
|
50
|
+
|
51
|
+
domain.each do |key|
|
52
|
+
# ...
|
53
|
+
end
|
47
54
|
|
48
55
|
## Synopsis
|
49
56
|
|
@@ -87,7 +94,7 @@ Query multiple domains:
|
|
87
94
|
|
88
95
|
## Install
|
89
96
|
|
90
|
-
|
97
|
+
$ gem install dkim-query
|
91
98
|
|
92
99
|
## License
|
93
100
|
|
data/bin/dkim-query
CHANGED
data/lib/dkim/query/domain.rb
CHANGED
data/lib/dkim/query/key.rb
CHANGED
@@ -4,29 +4,56 @@ require 'dkim/query/malformed_key'
|
|
4
4
|
|
5
5
|
module DKIM
|
6
6
|
module Query
|
7
|
+
#
|
8
|
+
# Represents an individual DKIM signing key.
|
9
|
+
#
|
7
10
|
class Key
|
8
11
|
|
12
|
+
# DKIM version.
|
13
|
+
#
|
14
|
+
# @return [:DKIM1]
|
9
15
|
attr_reader :v
|
10
16
|
alias version v
|
11
17
|
|
18
|
+
# `g=` tag.
|
19
|
+
#
|
20
|
+
# @return [String, nil]
|
12
21
|
attr_reader :g
|
13
22
|
alias granularity g
|
14
23
|
|
24
|
+
# `h=` tag.
|
25
|
+
#
|
26
|
+
# @return [:sha1, :sha256, Array<:sha1, :sha256, String>, nil]
|
15
27
|
attr_reader :h
|
16
28
|
alias hash h
|
17
29
|
|
30
|
+
# `k=` tag.
|
31
|
+
#
|
32
|
+
# @return [:rsa, String]
|
18
33
|
attr_reader :k
|
19
34
|
alias key k
|
20
35
|
|
36
|
+
# `n=` tag.
|
37
|
+
#
|
38
|
+
# @return [String, nil]
|
21
39
|
attr_reader :n
|
22
40
|
alias notes n
|
23
41
|
|
42
|
+
# `p=` tag.
|
43
|
+
#
|
44
|
+
# @return [String, nil]
|
24
45
|
attr_reader :p
|
25
46
|
alias public_key p
|
26
47
|
|
48
|
+
# `s=` tag.
|
49
|
+
#
|
50
|
+
# @return [:email, :*, String, Array<:email, :*, String>, nil]
|
27
51
|
attr_reader :s
|
28
52
|
alias service_type s
|
29
53
|
|
54
|
+
# `t=` tag.
|
55
|
+
#
|
56
|
+
# @return [:y, :s, String, nil]
|
30
57
|
attr_reader :t
|
31
58
|
alias flags t
|
32
59
|
|
data/lib/dkim/query/parser.rb
CHANGED
@@ -31,6 +31,8 @@ module DKIM
|
|
31
31
|
).as(:tag)
|
32
32
|
end
|
33
33
|
|
34
|
+
private
|
35
|
+
|
34
36
|
def self.key_tag_rule(name,&block)
|
35
37
|
rule(:"key_#{name}_tag") do
|
36
38
|
str(name).as(:name) >>
|
@@ -43,37 +45,43 @@ module DKIM
|
|
43
45
|
str(name).as(:symbol)
|
44
46
|
end
|
45
47
|
|
48
|
+
public
|
49
|
+
|
46
50
|
key_tag_rule('v') { symbol('DKIM1') }
|
47
51
|
key_tag_rule('g') { key_g_tag_lpart }
|
48
52
|
rule(:key_g_tag_lpart) do
|
49
|
-
|
53
|
+
(
|
54
|
+
dot_atom_text.maybe >>
|
55
|
+
(str('*') >> dot_atom_text.maybe).maybe
|
56
|
+
).as(:string)
|
57
|
+
end
|
58
|
+
rule(:dot_atom_text) do
|
59
|
+
atext.repeat(1) >> (str('.') >> atext.repeat(1)).repeat(0)
|
50
60
|
end
|
51
|
-
rule(:dot_atom_text) { atext.repeat(1) >> (str('.') >> atext.repeat(1)).repeat(0) }
|
52
61
|
|
53
62
|
key_tag_rule('h') do
|
54
|
-
key_h_tag_alg >>
|
55
|
-
(fws? >> str(':') >> fws? >> key_h_tag_alg).repeat(0)
|
63
|
+
key_h_tag_alg >> (fws? >> str(':') >> fws? >> key_h_tag_alg).repeat(0)
|
56
64
|
end
|
57
65
|
rule(:key_h_tag_alg) { symbol('sha1') | symbol('sha256') | x_key_h_tag_alg }
|
58
|
-
rule(:x_key_h_tag_alg) { hyphenated_word }
|
66
|
+
rule(:x_key_h_tag_alg) { hyphenated_word.as(:string) }
|
59
67
|
|
60
68
|
key_tag_rule('k') { key_k_tag_type }
|
61
69
|
rule(:key_k_tag_type) { symbol('rsa') | x_key_k_tag_type }
|
62
|
-
rule(:x_key_k_tag_type) { hyphenated_word }
|
70
|
+
rule(:x_key_k_tag_type) { hyphenated_word.as(:string) }
|
63
71
|
|
64
|
-
key_tag_rule('n') { qp_section }
|
72
|
+
key_tag_rule('n') { qp_section.as(:string) }
|
65
73
|
key_tag_rule('p') { base64string.as(:asn1).maybe }
|
66
74
|
key_tag_rule('s') do
|
67
75
|
key_s_tag_type >> (fws? >> str(':') >> fws? >> key_s_tag_type).repeat(0)
|
68
76
|
end
|
69
77
|
rule(:key_s_tag_type) { symbol('email') | symbol('*') | x_key_s_tag_type }
|
70
|
-
rule(:x_key_s_tag_type) { hyphenated_word }
|
78
|
+
rule(:x_key_s_tag_type) { hyphenated_word.as(:string) }
|
71
79
|
|
72
80
|
key_tag_rule('t') do
|
73
81
|
key_t_tag_flag >> (fws? >> str(':') >> fws? >> key_t_tag_flag).repeat(0)
|
74
82
|
end
|
75
|
-
rule(:key_t_tag_flag) { match['ys'] | x_key_t_tag_flag }
|
76
|
-
rule(:x_key_t_tag_flag) { hyphenated_word }
|
83
|
+
rule(:key_t_tag_flag) { match['ys'].as(:symbol) | x_key_t_tag_flag }
|
84
|
+
rule(:x_key_t_tag_flag) { hyphenated_word.as(:string) }
|
77
85
|
|
78
86
|
#
|
79
87
|
# Section 2.6: DKIM-Quoted-Printable
|
@@ -130,6 +138,7 @@ module DKIM
|
|
130
138
|
class Transform < Parslet::Transform
|
131
139
|
|
132
140
|
rule(:symbol => simple(:name)) { name.to_sym }
|
141
|
+
rule(:string => simple(:text)) { text.to_s }
|
133
142
|
# XXX: temporarily disable ASN1 decoding, due to an OpenSSL bug.
|
134
143
|
# rule(:asn1 => simple(:blob)) { OpenSSL::ASN1.decode(blob) }
|
135
144
|
rule(:asn1 => simple(:blob)) { blob }
|
data/lib/dkim/query/query.rb
CHANGED
@@ -42,6 +42,12 @@ module DKIM
|
|
42
42
|
# Default known selectors
|
43
43
|
SELECTORS = %w[default dkim s1024 c1211]
|
44
44
|
|
45
|
+
#
|
46
|
+
# DKIM query selectors for the host.
|
47
|
+
#
|
48
|
+
# @param [String] host
|
49
|
+
#
|
50
|
+
# @return [Array<String>]
|
45
51
|
#
|
46
52
|
# @api private
|
47
53
|
#
|
@@ -49,6 +55,12 @@ module DKIM
|
|
49
55
|
SELECTORS + [host_without_tld(host)]
|
50
56
|
end
|
51
57
|
|
58
|
+
#
|
59
|
+
# Removes the TLD from the hostname.
|
60
|
+
#
|
61
|
+
# @param [String] host
|
62
|
+
#
|
63
|
+
# @return [String]
|
52
64
|
#
|
53
65
|
# @api private
|
54
66
|
#
|
data/lib/dkim/query/version.rb
CHANGED
data/spec/key_spec.rb
CHANGED
@@ -4,12 +4,14 @@ require 'dkim/query/key'
|
|
4
4
|
describe Key do
|
5
5
|
let(:k) { :rsa }
|
6
6
|
let(:p) { "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDrEee0Ri4Juz+QfiWYui/E9UGSXau/2P8LjnTD8V4Unn+2FAZVGE3kL23bzeoULYv4PeleB3gfmJiDJOKU3Ns5L4KJAUUHjFwDebt0NP+sBK0VKeTATL2Yr/S3bT/xhy+1xtj4RkdV7fVxTn56Lb4udUnwuxK4V5b5PdOKj/+XcwIDAQAB" }
|
7
|
+
let(:t) { :s }
|
7
8
|
let(:n) { "A 1024 bit key;" }
|
8
9
|
|
9
10
|
subject do
|
10
11
|
described_class.new(
|
11
12
|
k: k,
|
12
13
|
p: p,
|
14
|
+
t: t,
|
13
15
|
n: n
|
14
16
|
)
|
15
17
|
end
|
@@ -23,12 +25,16 @@ describe Key do
|
|
23
25
|
expect(subject.p).to be p
|
24
26
|
end
|
25
27
|
|
28
|
+
it "should set @t" do
|
29
|
+
expect(subject.t).to be t
|
30
|
+
end
|
31
|
+
|
26
32
|
it "should set @n" do
|
27
33
|
expect(subject.n).to be n
|
28
34
|
end
|
29
35
|
end
|
30
36
|
|
31
|
-
let(:record) { %{k=#{k}; p=#{p}; n=#{n}} }
|
37
|
+
let(:record) { %{k=#{k}; p=#{p}; t=#{t}; n=#{n}} }
|
32
38
|
let(:invalid_record) { "v=spf1" }
|
33
39
|
|
34
40
|
describe ".parse!" do
|
@@ -38,6 +44,22 @@ describe Key do
|
|
38
44
|
it "should return a Key" do
|
39
45
|
expect(subject).to be_kind_of(described_class)
|
40
46
|
end
|
47
|
+
|
48
|
+
it "should parse k" do
|
49
|
+
expect(subject.k).to be k
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should parse p" do
|
53
|
+
expect(subject.p).to be == p
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should parse t" do
|
57
|
+
expect(subject.t).to be t
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should parse n" do
|
61
|
+
expect(subject.n).to be == n
|
62
|
+
end
|
41
63
|
end
|
42
64
|
|
43
65
|
context "when parsing an invalid DKIM Key record" do
|
@@ -78,6 +100,10 @@ describe Key do
|
|
78
100
|
expect(subject[:p]).to be == p
|
79
101
|
end
|
80
102
|
|
103
|
+
|
104
|
+
it "should include :t" do
|
105
|
+
expect(subject[:t]).to be == t
|
106
|
+
end
|
81
107
|
it "should include :n" do
|
82
108
|
expect(subject[:n]).to be == n
|
83
109
|
end
|
@@ -85,7 +111,7 @@ describe Key do
|
|
85
111
|
|
86
112
|
describe "#to_s" do
|
87
113
|
it "should return a semicolon deliminited string" do
|
88
|
-
expect(subject.to_s).to be == "k=#{k}; p=#{p}; n=#{n}"
|
114
|
+
expect(subject.to_s).to be == "k=#{k}; p=#{p}; t=#{t}; n=#{n}"
|
89
115
|
end
|
90
116
|
end
|
91
117
|
end
|
data/spec/parser_spec.rb
CHANGED
@@ -81,7 +81,7 @@ describe Parser do
|
|
81
81
|
it "should parse n=..." do
|
82
82
|
expect(subject.parse("n=#{notes}")).to be == {
|
83
83
|
name: 'n',
|
84
|
-
value: notes
|
84
|
+
value: {string: notes}
|
85
85
|
}
|
86
86
|
end
|
87
87
|
end
|
@@ -130,14 +130,14 @@ describe Parser do
|
|
130
130
|
it "should parse t=y" do
|
131
131
|
expect(subject.parse('t=y')).to be == {
|
132
132
|
name: 't',
|
133
|
-
value: 'y'
|
133
|
+
value: {symbol: 'y'}
|
134
134
|
}
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should parse t=s" do
|
138
138
|
expect(subject.parse('t=s')).to be == {
|
139
139
|
name: 't',
|
140
|
-
value: 's'
|
140
|
+
value: {symbol: 's'}
|
141
141
|
}
|
142
142
|
end
|
143
143
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dkim-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- nicktitle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|