dkimverify 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/dkimverify.gemspec +1 -1
  3. data/dkimverify.rb +9 -4
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8e478a5441b933c84c1880587bca90d3433f5d1
4
- data.tar.gz: c6ff69ed30db9e8d03fb21f5fcec8277f9c51bc4
3
+ metadata.gz: ac5d9f13f3025786b6a19e4bd8e6147ca6adbcd8
4
+ data.tar.gz: 461833996fc77a81882190b1011f1355764e5d5c
5
5
  SHA512:
6
- metadata.gz: 8d239d98049d9868040fed1e6267c6568a30499df36eb48663ca7968123f0de021be46bb0ca7fed8c67430f999e085cd9af23e43532943c41b6a465d148fe6e7
7
- data.tar.gz: 8f38905a1d21db655e524469eb37fe6726383aeebe68375fb3257648cb85996ef599ba8c067dac878317ae7b5905e8c9033a7ae16f352206d732e3275eb0a5a6
6
+ metadata.gz: 145a1d41927294da41a5d61ef1e8bdbb631f3fa4ef9e5860e49e1eabf060b66aa3e394c521c55939b79bbb7d2cf3396bbe81a9f88251d7fb3b14d436ecbe3dfa
7
+ data.tar.gz: a6822d5f82d8fb5e43ec6078db1d6d67ef05a4f83cc2c07dcc834afb7184456f25f2e34e51544d1e35fcc2bfdac65e490d21df20a61df9bfa334721c23c095c3
data/dkimverify.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "dkimverify"
5
- gem.version = '0.0.3'
5
+ gem.version = '0.0.4'
6
6
  gem.authors = ["Jeremy B. Merrill"]
7
7
  gem.license = "MIT"
8
8
  gem.email = ["jeremybmerrill@gmail.com"]
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 txt.first.nil? || !parsed_txt.keys.include?("p")
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
- decrypted_header_hash_bytes = OpenSSL::PKey::RSA.new(public_key).public_decrypt(Base64.decode64(@dkim_signature['b']))
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dkimverify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy B. Merrill