dkimverify 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dkimverify.gemspec +1 -1
- data/dkimverify.rb +9 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac5d9f13f3025786b6a19e4bd8e6147ca6adbcd8
|
4
|
+
data.tar.gz: 461833996fc77a81882190b1011f1355764e5d5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 145a1d41927294da41a5d61ef1e8bdbb631f3fa4ef9e5860e49e1eabf060b66aa3e394c521c55939b79bbb7d2cf3396bbe81a9f88251d7fb3b14d436ecbe3dfa
|
7
|
+
data.tar.gz: a6822d5f82d8fb5e43ec6078db1d6d67ef05a4f83cc2c07dcc834afb7184456f25f2e34e51544d1e35fcc2bfdac65e490d21df20a61df9bfa334721c23c095c3
|
data/dkimverify.gemspec
CHANGED
data/dkimverify.rb
CHANGED
@@ -4,7 +4,7 @@ require 'base64'
|
|
4
4
|
require 'resolv'
|
5
5
|
|
6
6
|
# TODO make this an option somehow
|
7
|
-
$debuglog = STDERR # nil # alternatively, set this to `STDERR` to log to stdout.
|
7
|
+
$debuglog = nil #STDERR # nil # alternatively, set this to `STDERR` to log to stdout.
|
8
8
|
require 'mail'
|
9
9
|
|
10
10
|
module Mail
|
@@ -128,8 +128,9 @@ module Dkim
|
|
128
128
|
# s = dnstxt(sig['s']+"._domainkey."+sig['d']+".")
|
129
129
|
# dkim_record_from_dns = DKIM::Query::Domain.query(@dkim_signature['d'], {:selectors => [@dkim_signature['s']]}).keys[@dkim_signature['s']]
|
130
130
|
txt = Resolv::DNS.open{|dns| dns.getresources("#{@dkim_signature['s']}._domainkey.#{@dkim_signature['d']}", Resolv::DNS::Resource::IN::TXT).map(&:data) }
|
131
|
+
raise DkimTempFail.new("couldn't get public key from DNS system for #{@dkim_signature['s']}/#{@dkim_signature['d']}") if txt.first.nil?
|
131
132
|
parsed_txt = Dkim.parse_header_kv(txt.first)
|
132
|
-
raise DkimTempFail.new("couldn't get public key from DNS system for #{@dkim_signature['s']}/#{@dkim_signature['d']}") if
|
133
|
+
raise DkimTempFail.new("couldn't get public key from DNS system for #{@dkim_signature['s']}/#{@dkim_signature['d']}") if !parsed_txt.keys.include?("p")
|
133
134
|
publickey_asn1 = OpenSSL::ASN1.decode(Base64.decode64(parsed_txt["p"]))
|
134
135
|
publickey = publickey_asn1.value[1].value
|
135
136
|
end
|
@@ -142,7 +143,7 @@ module Dkim
|
|
142
143
|
canonicalized_headers = []
|
143
144
|
header_fields_to_include_with_values = header_fields_to_include.map do |header_name|
|
144
145
|
puts @headers.first_field(header_name).inspect
|
145
|
-
[header_name, @headers.first_field(header_name).instance_variable_get("@raw_value").split(":")[1..-1].join(":") ]
|
146
|
+
[header_name, (hstr = @headers.first_field(header_name).instance_variable_get("@raw_value")).nil? ? '' : hstr.split(":")[1..-1].join(":") ]
|
146
147
|
# .value and .instance_eval { unfold(split(@raw_value)[1]) } return subtly different values
|
147
148
|
# if the value of the Date header is a date with a single-digit day.
|
148
149
|
# see https://github.com/mikel/mail/issues/1075
|
@@ -195,7 +196,11 @@ module Dkim
|
|
195
196
|
end
|
196
197
|
|
197
198
|
def decrypted_header_hash
|
198
|
-
|
199
|
+
begin
|
200
|
+
decrypted_header_hash_bytes = OpenSSL::PKey::RSA.new(public_key).public_decrypt(Base64.decode64(@dkim_signature['b']))
|
201
|
+
rescue OpenSSL::PKey::RSAError
|
202
|
+
raise DkimPermFail.new "couldn't decrypt header hash with public key"
|
203
|
+
end
|
199
204
|
ret = Base64.encode64(decrypted_header_hash_bytes).gsub(/\s+/, '')
|
200
205
|
$debuglog.puts "decrypted_header_hash: #{ret}" unless $debuglog.nil?
|
201
206
|
ret
|