WIP: DKIM.

master
Philippe Pittoli 2024-03-11 21:24:23 +01:00
parent 4cfd068193
commit 1a9666df23
1 changed files with 47 additions and 9 deletions

View File

@ -66,7 +66,7 @@ class DNSManager::Storage::Zone
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) " io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype } #{ "%30s" % @target}\n" io << "#{ "%30s" % @name} #{ "%6d" % @ttl} #{ "%10s" % @rrtype } #{ "%30s" % @target}\n"
end end
def to_bind9(io : IO) def to_bind9(io : IO)
@ -96,7 +96,7 @@ class DNSManager::Storage::Zone
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) " io << "(#{ "%4d" % @rrid }) "
io << "#{name} #{ttl} IN SOA (#{mname} #{rname}\n" io << "#{name} #{ttl} SOA (#{mname} #{rname}\n"
io << "\t\t#{ "%10d" % serial } ; serial\n" io << "\t\t#{ "%10d" % serial } ; serial\n"
io << "\t\t#{ "%10d" % refresh } ; refresh\n" io << "\t\t#{ "%10d" % refresh } ; refresh\n"
io << "\t\t#{ "%10d" % retry } ; retry\n" io << "\t\t#{ "%10d" % retry } ; retry\n"
@ -414,7 +414,7 @@ class DNSManager::Storage::Zone
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) " io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN SPF " io << "#{ "%30s" % @name} #{ "%6d" % @ttl} SPF "
io << '"' io << '"'
@mechanisms.each do |m| @mechanisms.each do |m|
io << m io << m
@ -454,10 +454,19 @@ class DNSManager::Storage::Zone
# TODO # TODO
class DKIM < ResourceRecord class DKIM < ResourceRecord
property v : String = "DKIM1" # DKIM version enum Version
property h : String = "sha256" # encrypting cryptographic algorithm DKIM1
property k : String = "rsa" # signing cryptographic algorithm end
property p : String # public key enum SignatureAlgorithm
RSA
end
enum HashAlgorithm
SHA256
end
property v : Version = Version::DKIM1
property h : HashAlgorithm = HashAlgorithm::SHA256
property k : SignatureAlgorithm = SignatureAlgorithm::RSA
property p : String # public key
def initialize(@name, @ttl, @target, @v, @h, @k, @p) def initialize(@name, @ttl, @target, @v, @h, @k, @p)
@rrtype = "DKIM" @rrtype = "DKIM"
end end
@ -474,6 +483,21 @@ class DNSManager::Storage::Zone
end end
errors errors
end end
def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} DKIM "
io << "( "
io << split_line "v=#{v};h=#{h};k=#{k};p=#{p}"
io << " )"
end
def to_bind9(io : IO)
io << "#{@name} #{@ttl} IN TXT "
io << "( "
io << split_line "v=#{v};h=#{h};k=#{k};p=#{p}"
io << " )"
end
end end
# TODO # TODO
@ -504,7 +528,7 @@ class DNSManager::Storage::Zone
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) " io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN MX #{ "%3d" % @priority} #{ "%30s" % @target}\n" io << "#{ "%30s" % @name} #{ "%6d" % @ttl} MX #{ "%3d" % @priority} #{ "%30s" % @target}\n"
end end
def to_bind9(io : IO) def to_bind9(io : IO)
@ -562,7 +586,7 @@ class DNSManager::Storage::Zone
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) " io << "(#{ "%4d" % @rrid }) "
io << "#{ "%30s" % @name} " io << "#{ "%30s" % @name} "
io << "#{ "%6d" % @ttl} IN SRV " io << "#{ "%6d" % @ttl} SRV "
io << "#{ "%3d" % @priority} " io << "#{ "%3d" % @priority} "
io << "#{ "%3d" % @weight} " io << "#{ "%3d" % @weight} "
io << "#{ "%5d" % @port} " io << "#{ "%5d" % @port} "
@ -733,3 +757,17 @@ end
def qualifier_to_string(qualifier : DNSManager::Storage::Zone::SPF::Qualifier) : String def qualifier_to_string(qualifier : DNSManager::Storage::Zone::SPF::Qualifier) : String
"#{qualifier_to_char qualifier}all" "#{qualifier_to_char qualifier}all"
end end
def split_line(line : String) : String
iostr = IO::Memory.new line
slice = Bytes.new(50)
lines = ""
while rbytes = iostr.read slice
lines += '"'
lines += String.new slice[0..rbytes]
lines += '"'
lines += "\n\t"
end
lines
end