WIP: DKIM.
This commit is contained in:
		
							parent
							
								
									4cfd068193
								
							
						
					
					
						commit
						1a9666df23
					
				
					 1 changed files with 47 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -66,7 +66,7 @@ class DNSManager::Storage::Zone
 | 
			
		|||
 | 
			
		||||
		def to_s(io : IO)
 | 
			
		||||
			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
 | 
			
		||||
 | 
			
		||||
		def to_bind9(io : IO)
 | 
			
		||||
| 
						 | 
				
			
			@ -96,7 +96,7 @@ class DNSManager::Storage::Zone
 | 
			
		|||
 | 
			
		||||
		def to_s(io : IO)
 | 
			
		||||
			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" % refresh }  ; refresh\n"
 | 
			
		||||
			io << "\t\t#{ "%10d" % retry   }  ; retry\n"
 | 
			
		||||
| 
						 | 
				
			
			@ -414,7 +414,7 @@ class DNSManager::Storage::Zone
 | 
			
		|||
 | 
			
		||||
		def to_s(io : IO)
 | 
			
		||||
			io << "(#{ "%4d" % @rrid }) "
 | 
			
		||||
			io << "#{ "%30s" % @name} #{ "%6d" % @ttl} IN SPF "
 | 
			
		||||
			io << "#{ "%30s" % @name} #{ "%6d" % @ttl} SPF "
 | 
			
		||||
			io << '"'
 | 
			
		||||
			@mechanisms.each do |m|
 | 
			
		||||
				io << m
 | 
			
		||||
| 
						 | 
				
			
			@ -454,10 +454,19 @@ class DNSManager::Storage::Zone
 | 
			
		|||
 | 
			
		||||
	# TODO
 | 
			
		||||
	class DKIM < ResourceRecord
 | 
			
		||||
		property v : String = "DKIM1"  # DKIM version
 | 
			
		||||
		property h : String = "sha256" # encrypting cryptographic algorithm
 | 
			
		||||
		property k : String = "rsa"    # signing cryptographic algorithm
 | 
			
		||||
		property p : String            # public key
 | 
			
		||||
		enum Version
 | 
			
		||||
			DKIM1
 | 
			
		||||
		end
 | 
			
		||||
		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)
 | 
			
		||||
			@rrtype = "DKIM"
 | 
			
		||||
		end
 | 
			
		||||
| 
						 | 
				
			
			@ -474,6 +483,21 @@ class DNSManager::Storage::Zone
 | 
			
		|||
			end
 | 
			
		||||
			errors
 | 
			
		||||
		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
 | 
			
		||||
 | 
			
		||||
	# TODO
 | 
			
		||||
| 
						 | 
				
			
			@ -504,7 +528,7 @@ class DNSManager::Storage::Zone
 | 
			
		|||
 | 
			
		||||
		def to_s(io : IO)
 | 
			
		||||
			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
 | 
			
		||||
 | 
			
		||||
		def to_bind9(io : IO)
 | 
			
		||||
| 
						 | 
				
			
			@ -562,7 +586,7 @@ class DNSManager::Storage::Zone
 | 
			
		|||
		def to_s(io : IO)
 | 
			
		||||
			io << "(#{ "%4d" % @rrid }) "
 | 
			
		||||
			io << "#{ "%30s" % @name} "
 | 
			
		||||
			io << "#{ "%6d" % @ttl} IN SRV "
 | 
			
		||||
			io << "#{ "%6d" % @ttl} SRV "
 | 
			
		||||
			io << "#{ "%3d" % @priority} "
 | 
			
		||||
			io << "#{ "%3d" % @weight} "
 | 
			
		||||
			io << "#{ "%5d" % @port} "
 | 
			
		||||
| 
						 | 
				
			
			@ -733,3 +757,17 @@ end
 | 
			
		|||
def qualifier_to_string(qualifier : DNSManager::Storage::Zone::SPF::Qualifier) : String
 | 
			
		||||
	"#{qualifier_to_char qualifier}all"
 | 
			
		||||
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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue