Class: MailAuth::Dkim::Verification

Inherits:
Object
  • Object
show all
Defined in:
lib/mailauth/dkim.rb

Overview

One DKIM-Signature header, taken from its tags to a verdict.

Instance Method Summary collapse

Constructor Details

#initialize(message, field, resolver:, now:) ⇒ Verification

Returns a new instance of Verification.



88
89
90
91
92
93
# File 'lib/mailauth/dkim.rb', line 88

def initialize(message, field, resolver:, now:)
  @message, @field, @resolver, @now = message, field, resolver, now
  tags = Dkim.parse_tags(field.split(":", 2).last.to_s)
  @well_formed = !tags.nil?
  @tags = tags || {}
end

Instance Method Details

#resultObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/mailauth/dkim.rb', line 95

def result
  validate

  if expired?
    failed("signature expired")
  elsif 
    failed("signature timestamp in the future")
  elsif body_hash_matches?
    verified? ? signature(Status::PASS) : failed("bad signature")
  else
    # Some verifiers call this neutral. We call it failure: the signer
    # said what the body would hash to, and it hashes to something else.
    failed("body hash did not verify")
  end
rescue Malformed => error
  signature(Status::PERMERROR, comment: error.message)
rescue Resolver::NotFound
  signature(Status::PERMERROR, comment: "no key for #{key_name}")
rescue Resolver::Timeout, Resolver::ServerFailure
  signature(Status::TEMPERROR, comment: "DNS failure resolving #{key_name}")
end