mirror of
https://github.com/internetee/registry.git
synced 2025-05-19 10:49:39 +02:00
Add correct DS key tag generation
This commit is contained in:
parent
d39ed1b0e9
commit
11f0b2685e
3 changed files with 25 additions and 3 deletions
|
@ -10,6 +10,12 @@ class Dnskey < ActiveRecord::Base
|
||||||
|
|
||||||
before_save -> { generate_digest if public_key_changed? && !ds_digest_changed? }
|
before_save -> { generate_digest if public_key_changed? && !ds_digest_changed? }
|
||||||
|
|
||||||
|
before_save lambda {
|
||||||
|
if (public_key_changed? || flags_changed? || alg_changed? || protocol_changed?) && !ds_key_tag_changed?
|
||||||
|
generate_ds_key_tag
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
ALGORITHMS = %w(3 5 6 7 8 252 253 254 255)
|
ALGORITHMS = %w(3 5 6 7 8 252 253 254 255)
|
||||||
PROTOCOLS = %w(3)
|
PROTOCOLS = %w(3)
|
||||||
FLAGS = %w(0 256 257)
|
FLAGS = %w(0 256 257)
|
||||||
|
@ -77,6 +83,23 @@ class Dnskey < ActiveRecord::Base
|
||||||
self.class.bin_to_hex(Base64.decode64(public_key))
|
self.class.bin_to_hex(Base64.decode64(public_key))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_ds_key_tag
|
||||||
|
public_key.gsub!(' ', '')
|
||||||
|
wire_format = [flags, protocol, alg].pack('S!>CC')
|
||||||
|
wire_format += Base64.decode64(public_key)
|
||||||
|
|
||||||
|
c = 0
|
||||||
|
wire_format.each_byte.with_index do |b, i|
|
||||||
|
if i.even?
|
||||||
|
c += b << 8
|
||||||
|
else
|
||||||
|
c += b
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self.ds_key_tag = ((c & 0xFFFF) + (c >> 16)) & 0xFFFF
|
||||||
|
end
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def int_to_hex(s)
|
def int_to_hex(s)
|
||||||
s = s.to_s(16)
|
s = s.to_s(16)
|
||||||
|
|
|
@ -258,8 +258,8 @@ class Domain < ActiveRecord::Base
|
||||||
res = ''
|
res = ''
|
||||||
parts = name.split('.')
|
parts = name.split('.')
|
||||||
parts.each do |x|
|
parts.each do |x|
|
||||||
res += sprintf('%02X', x.length)
|
res += sprintf('%02X', x.length) # length of label in hex
|
||||||
res += x.each_byte.map { |b| sprintf('%02X', b) }.join
|
res += x.each_byte.map { |b| sprintf('%02X', b) }.join # label
|
||||||
end
|
end
|
||||||
|
|
||||||
res += '00'
|
res += '00'
|
||||||
|
|
|
@ -198,7 +198,6 @@ class Epp::EppDomain < Domain
|
||||||
|
|
||||||
dnssec_data[:key_data].each do |x|
|
dnssec_data[:key_data].each do |x|
|
||||||
dnskeys.build({
|
dnskeys.build({
|
||||||
ds_key_tag: SecureRandom.hex(5),
|
|
||||||
ds_alg: 3,
|
ds_alg: 3,
|
||||||
ds_digest_type: Setting.ds_algorithm
|
ds_digest_type: Setting.ds_algorithm
|
||||||
}.merge(x))
|
}.merge(x))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue