From 70fb6d130ce0f05fe70b597d71d893d2fad4834d Mon Sep 17 00:00:00 2001 From: Philippe Pittoli Date: Mon, 11 Mar 2024 23:39:18 +0100 Subject: [PATCH] WIP: DKIM messages are accepted. --- src/storage/zone.cr | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/storage/zone.cr b/src/storage/zone.cr index d2429ec..e9acdd9 100644 --- a/src/storage/zone.cr +++ b/src/storage/zone.cr @@ -463,12 +463,27 @@ class DNSManager::Storage::Zone 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) + + class DKIMProperties + include JSON::Serializable + property v : Version = Version::DKIM1 + property h : HashAlgorithm = HashAlgorithm::SHA256 + property k : SignatureAlgorithm = SignatureAlgorithm::RSA + property p : String # public key + property n : String = "" # notes + def initialize(@v, @h, @k, @p, @n) + end + def to_s(io : IO) + io << "v=#{v};h=#{h};k=#{k};p=#{p}" + io << ";n=#{n}" unless n == "" + end + end + + property dkim : DKIMProperties + + def initialize(@name, @ttl, @target, v, h, k, p, n) @rrtype = "DKIM" + @dkim = DKIMProperties.new v, h, k, p, n end def get_errors : Array(Error) @@ -488,14 +503,14 @@ class DNSManager::Storage::Zone io << "(#{ "%4d" % @rrid }) " io << "#{ "%30s" % @name} #{ "%6d" % @ttl} DKIM " io << "( " - io << split_line "v=#{v};h=#{h};k=#{k};p=#{p}" + io << split_line dkim.to_s 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 << split_line dkim.to_s io << " )" end end @@ -763,8 +778,9 @@ def split_line(line : String) : String slice = Bytes.new(50) lines = "" while rbytes = iostr.read slice + break if rbytes == 0 lines += '"' - lines += String.new slice[0..rbytes] + lines += String.new slice[0..rbytes -1] lines += '"' lines += "\n\t" end