Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CNAME delegated DKIM keys #3029

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions app/models/concerns/has_dns_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,27 @@ def check_spf_record!

def check_dkim_record
domain = "#{dkim_record_name}.#{name}"
check_dkim_record_recursive(domain, domain, 0)
end

def check_dkim_record_recursive(originaldomain, domain, level)
records = resolver.txt(domain)
if records.empty?
self.dkim_status = "Missing"
self.dkim_error = "No TXT records were returned for #{domain}"
records = resolver.cname(domain)
if (!records.empty? && records.size == 1 && level < 10)
return check_dkim_record_recursive(originaldomain, records.first, level+1)
else
self.dkim_status = "Missing"
self.dkim_error = "No TXT records were returned for #{originaldomain}"
end
else
sanitised_dkim_record = records.first.strip.ends_with?(";") ? records.first.strip : "#{records.first.strip};"
if records.size > 1
self.dkim_status = "Invalid"
self.dkim_error = "There are #{records.size} records for at #{domain}. There should only be one."
self.dkim_error = "There are #{records.size} records for at #{originaldomain}. There should only be one."
elsif sanitised_dkim_record != dkim_record
self.dkim_status = "Invalid"
self.dkim_error = "The DKIM record at #{domain} does not match the record we have provided. Please check it has been copied correctly."
self.dkim_error = "The DKIM record at #{originaldomain} does not match the record we have provided. Please check it has been copied correctly."
else
self.dkim_status = "OK"
self.dkim_error = nil
Expand Down