svcb_rr_patch 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +28 -2
- data/lib/svcb_rr_patch/https.rb +1 -1
- data/lib/svcb_rr_patch/svc_params/alpn.rb +1 -1
- data/lib/svcb_rr_patch/svc_params/ech.rb +1 -1
- data/lib/svcb_rr_patch/svc_params/ipv4hint.rb +1 -1
- data/lib/svcb_rr_patch/svc_params/ipv6hint.rb +1 -1
- data/lib/svcb_rr_patch/svc_params/mandatory.rb +3 -9
- data/lib/svcb_rr_patch/svc_params/port.rb +1 -1
- data/lib/svcb_rr_patch/svc_params.rb +84 -60
- data/lib/svcb_rr_patch/svcb.rb +3 -3
- data/lib/svcb_rr_patch/version.rb +1 -1
- data/spec/alpn_spec.rb +1 -1
- data/spec/ipv4hint_spec.rb +1 -1
- data/spec/ipv6hint_spec.rb +1 -1
- data/spec/mandatory_spec.rb +8 -8
- data/spec/no_default_alpn_spec.rb +1 -1
- data/spec/port_spec.rb +1 -1
- data/spec/svc_params_spec.rb +5 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3af5857ef38bc6a54ad9abedb5c1227ea008b56e049393d16277103cba4b823
|
4
|
+
data.tar.gz: 8a9152efcf7694b8e6ace3a2fce298854f4020292b3f880c2ec9da4d19b8f25b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 912e4053675275418be0a343010b56e00e912c42ea20f24c89877f6754ee246231a91884e10ae62756185e0e64fc0c030fcdb019203a038088087e27f0d6c3fc
|
7
|
+
data.tar.gz: d56504d2fc39255d4ed9dc805d478b05054251af35b89384db816d340b1c22e400b531b9bee63865776d05fb550f3ec846eb8b0235412fb357776e6fedc284eb
|
data/README.md
CHANGED
@@ -36,10 +36,36 @@ irb(main):004:1* Resolv::DNS::Resource::IN::HTTPS
|
|
36
36
|
irb(main):005:0> )
|
37
37
|
=>
|
38
38
|
[#<Resolv::DNS::Resource::IN::HTTPS:0x0000000000000001
|
39
|
-
@svc_params=
|
39
|
+
@svc_params=
|
40
|
+
#<SvcbRrPatch::SvcParams::Hash:0x0000000000000002
|
41
|
+
@hash=
|
42
|
+
{"alpn"=>#<SvcbRrPatch::SvcParams::Alpn:0x0000000000000003 @protocols=["http/1.1", "h2"]>,
|
43
|
+
"ipv4hint"=>#<SvcbRrPatch::SvcParams::Ipv4hint:0x0000000000000004 @addresses=[#<Resolv::IPv4 162.159.137.85>, #<Resolv::IPv4 162.159.138.85>]>,
|
44
|
+
"ech"=>
|
45
|
+
#<SvcbRrPatch::SvcParams::Ech:0x0000000000000005
|
46
|
+
@echconfiglist=
|
47
|
+
[#<SvcbRrPatch::SvcParams::Ech::ECHConfig:0x0000000000000006
|
48
|
+
@echconfig_contents=
|
49
|
+
#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents:0x0000000000000007
|
50
|
+
@extensions=[],
|
51
|
+
@key_config=
|
52
|
+
#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig:0x0000000000000008
|
53
|
+
@cipher_suites=
|
54
|
+
[#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite:0x0000000000000009
|
55
|
+
@aead_id=#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite::HpkeAeadId:0x0000000000000010 @uint16=1>,
|
56
|
+
@kdf_id=#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeSymmetricCipherSuite::HpkeKdfId:0x0000000000000011 @uint16=1>>],
|
57
|
+
@config_id=238,
|
58
|
+
@kem_id=#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkeKemId:0x0000000000000012 @uint16=32>,
|
59
|
+
@public_key=
|
60
|
+
#<SvcbRrPatch::SvcParams::Ech::ECHConfigContents::HpkeKeyConfig::HpkePublicKey:0x0000000000000013
|
61
|
+
@opaque="I\x19\xD0\xCFP\b>e\xDF\xE1Q\xE8+i\x89\x8AJ\xA2b'\xD0j\xB9+\xDE\xE2\xDE\xF8\xFA\xAD\xBBm">>,
|
62
|
+
@maximum_name_length=0,
|
63
|
+
@public_name="cloudflare-esni.com">,
|
64
|
+
@version="\xFE\r">]>,
|
65
|
+
"ipv6hint"=>#<SvcbRrPatch::SvcParams::Ipv6hint:0x0000000000000014 @addresses=[#<Resolv::IPv6 2606:4700:7::a29f:8955>, #<Resolv::IPv6 2606:4700:7::a29f:8a55>]>}>,
|
40
66
|
@svc_priority=1,
|
41
67
|
@target_name="",
|
42
|
-
@ttl=
|
68
|
+
@ttl=58>]
|
43
69
|
```
|
44
70
|
|
45
71
|
|
data/lib/svcb_rr_patch/https.rb
CHANGED
@@ -21,7 +21,7 @@ class Resolv::DNS::Resource::IN::HTTPS < Resolv::DNS::Resource::IN::SVCB
|
|
21
21
|
return new(svc_priority, target_name, {}) if svc_priority.zero?
|
22
22
|
|
23
23
|
# the SvcParams, consuming the remainder of the record
|
24
|
-
svc_params = ::SvcbRrPatch::SvcParams.decode(msg.get_bytes)
|
24
|
+
svc_params = ::SvcbRrPatch::SvcParams::Hash.decode(msg.get_bytes)
|
25
25
|
new(svc_priority, target_name, svc_params)
|
26
26
|
end
|
27
27
|
end
|
@@ -25,7 +25,7 @@ class SvcbRrPatch::SvcParams::Ech
|
|
25
25
|
# https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06#section-9
|
26
26
|
# In presentation format, the value is a single ECHConfigList encoded in
|
27
27
|
# Base64.
|
28
|
-
def
|
28
|
+
def to_s
|
29
29
|
Base64.strict_encode64(encode)
|
30
30
|
end
|
31
31
|
end
|
@@ -17,18 +17,12 @@ class SvcbRrPatch::SvcParams::Mandatory
|
|
17
17
|
def self.decode(octet)
|
18
18
|
keys = octet.scan(/.{1,2}/)
|
19
19
|
.map { |s| s.unpack1('n') }
|
20
|
-
.filter { |i| i < 7 || i >= 65280 && i < 65535 }
|
21
20
|
new(keys)
|
22
21
|
end
|
23
22
|
|
24
23
|
# :nodoc:
|
25
|
-
def
|
26
|
-
@keys.map
|
27
|
-
|
28
|
-
SvcbRrPatch::SvcParams::PARAMETER_REGISTRY[i]
|
29
|
-
else
|
30
|
-
''
|
31
|
-
end
|
32
|
-
end.join(',')
|
24
|
+
def to_s
|
25
|
+
@keys.map { |i| SvcbRrPatch::SvcParams::PARAMETER_REGISTRY[i] }
|
26
|
+
.join(',')
|
33
27
|
end
|
34
28
|
end
|
@@ -12,85 +12,109 @@ module SvcbRrPatch::SvcParams
|
|
12
12
|
ipv6hint
|
13
13
|
]
|
14
14
|
# rubocop:disable Security/Eval
|
15
|
+
(8...65280).each do |nnnn|
|
16
|
+
eval "registry[nnnn] = \"undefine#{nnnn}\"", binding, __FILE__, __LINE__
|
17
|
+
end
|
15
18
|
(65280...65535).each do |nnnn|
|
16
19
|
eval "registry[nnnn] = \"key#{nnnn}\"", binding, __FILE__, __LINE__
|
17
20
|
end
|
18
21
|
# rubocop:enable Security/Eval
|
19
22
|
registry
|
20
23
|
}.call.freeze
|
24
|
+
|
25
|
+
PARAMETER_REGISTRY_INVERT = lambda {
|
26
|
+
Hash[(0..PARAMETER_REGISTRY.size - 1).zip(PARAMETER_REGISTRY)].invert
|
27
|
+
}.call.freeze
|
21
28
|
end
|
22
29
|
|
23
30
|
Dir[File.dirname(__FILE__) + '/svc_params/*.rb'].sort.each { |f| require f }
|
24
31
|
|
25
32
|
module SvcbRrPatch::SvcParams
|
26
|
-
|
27
|
-
|
28
|
-
|
33
|
+
class Hash
|
34
|
+
def initialize(hash)
|
35
|
+
@hash = hash
|
36
|
+
end
|
29
37
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
# @return [String]
|
39
|
+
def encode
|
40
|
+
@hash
|
41
|
+
.map { |k, v| [PARAMETER_REGISTRY_INVERT[k], v] }
|
42
|
+
.sort { |lh, rh| lh.first <=> rh.first }
|
43
|
+
.map do |k, v|
|
44
|
+
[k].pack('n') + v.encode.then { |s| [s.length].pack('n') + s }
|
45
|
+
end
|
46
|
+
.join
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param octet [String]
|
50
|
+
#
|
51
|
+
# @return [Hash]
|
52
|
+
def self.decode(octet)
|
53
|
+
svc_params = {}
|
54
|
+
i = 0
|
55
|
+
while i < octet.length
|
56
|
+
raise ::Resolv::DNS::DecodeError if i + 4 > octet.length
|
38
57
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
svc_params = {}
|
45
|
-
i = 0
|
46
|
-
h = Hash[(0..PARAMETER_REGISTRY.size - 1).zip(PARAMETER_REGISTRY)].invert
|
47
|
-
while i < octet.length
|
48
|
-
raise ::Resolv::DNS::DecodeError if i + 4 > octet.length
|
58
|
+
k = octet.slice(i, 2).unpack1('n')
|
59
|
+
# SvcParamKeys SHALL appear in increasing numeric order.
|
60
|
+
raise ::Resolv::DNS::DecodeError unless svc_params.keys.find do |key|
|
61
|
+
PARAMETER_REGISTRY_INVERT[key] >= k
|
62
|
+
end.nil?
|
49
63
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
64
|
+
i += 2
|
65
|
+
vlen = octet.slice(i, 2).unpack1('n')
|
66
|
+
i += 2
|
67
|
+
raise ::Resolv::DNS::DecodeError if i + vlen > octet.length
|
54
68
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
69
|
+
v = octet.slice(i, vlen)
|
70
|
+
i += vlen
|
71
|
+
# Values are in a format specific to the SvcParamKey.
|
72
|
+
svc_param_key = PARAMETER_REGISTRY[k]
|
73
|
+
svc_param_values = decode_svc_params(svc_param_key, v)
|
74
|
+
svc_params.store(svc_param_key, svc_param_values)
|
75
|
+
end
|
76
|
+
raise ::Resolv::DNS::DecodeError if i != octet.length
|
59
77
|
|
60
|
-
|
61
|
-
i += vlen
|
62
|
-
# Values are in a format specific to the SvcParamKey.
|
63
|
-
svc_param_key = PARAMETER_REGISTRY[k]
|
64
|
-
svc_param_values = decode_svc_params(svc_param_key, v)
|
65
|
-
svc_params.store(svc_param_key, svc_param_values)
|
78
|
+
new(svc_params)
|
66
79
|
end
|
67
|
-
raise ::Resolv::DNS::DecodeError if i != octet.length
|
68
80
|
|
69
|
-
|
70
|
-
|
71
|
-
|
81
|
+
# :nodoc:
|
82
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
83
|
+
def self.decode_svc_params(key, octet)
|
84
|
+
case key
|
85
|
+
when 'mandatory'
|
86
|
+
Mandatory.decode(octet)
|
87
|
+
when 'alpn'
|
88
|
+
Alpn.decode(octet)
|
89
|
+
when 'no-default-alpn'
|
90
|
+
NoDefaultAlpn.decode(octet)
|
91
|
+
when 'port'
|
92
|
+
Port.decode(octet)
|
93
|
+
when 'ipv4hint'
|
94
|
+
Ipv4hint.decode(octet)
|
95
|
+
when 'ech'
|
96
|
+
Ech.decode(octet)
|
97
|
+
when 'ipv6hint'
|
98
|
+
Ipv6hint.decode(octet)
|
99
|
+
else
|
100
|
+
octet
|
101
|
+
end
|
102
|
+
end
|
103
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
104
|
+
|
105
|
+
# :nodoc:
|
106
|
+
def [](key)
|
107
|
+
@hash[key]
|
108
|
+
end
|
109
|
+
|
110
|
+
# :nodoc:
|
111
|
+
def keys
|
112
|
+
@hash.keys
|
113
|
+
end
|
72
114
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
case key
|
77
|
-
when 'mandatory'
|
78
|
-
Mandatory.decode(octet)
|
79
|
-
when 'alpn'
|
80
|
-
Alpn.decode(octet)
|
81
|
-
when 'no-default-alpn'
|
82
|
-
NoDefaultAlpn.decode(octet)
|
83
|
-
when 'port'
|
84
|
-
Port.decode(octet)
|
85
|
-
when 'ipv4hint'
|
86
|
-
Ipv4hint.decode(octet)
|
87
|
-
when 'ech'
|
88
|
-
Ech.decode(octet)
|
89
|
-
when 'ipv6hint'
|
90
|
-
Ipv6hint.decode(octet)
|
91
|
-
else
|
92
|
-
octet
|
115
|
+
# :nodoc:
|
116
|
+
def to_s
|
117
|
+
@hash.map { |k, v| "#{k}=#{v}" }.join(' ')
|
93
118
|
end
|
94
119
|
end
|
95
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
96
120
|
end
|
data/lib/svcb_rr_patch/svcb.rb
CHANGED
@@ -10,7 +10,7 @@ class Resolv::DNS::Resource::IN::SVCB < Resolv::DNS::Resource
|
|
10
10
|
|
11
11
|
# @param svc_priority [Integer]
|
12
12
|
# @param target_name [String]
|
13
|
-
# @param svc_params [
|
13
|
+
# @param svc_params [Hash]
|
14
14
|
def initialize(svc_priority, target_name, svc_params)
|
15
15
|
# https://datatracker.ietf.org/doc/html/draft-ietf-dnsop-svcb-https-06
|
16
16
|
@svc_priority = svc_priority
|
@@ -37,7 +37,7 @@ class Resolv::DNS::Resource::IN::SVCB < Resolv::DNS::Resource
|
|
37
37
|
def encode_rdata(msg)
|
38
38
|
msg.put_bytes([@svc_priority].pack('n'))
|
39
39
|
msg.put_string(@target_name)
|
40
|
-
msg.put_string(
|
40
|
+
msg.put_string(@svc_params.encode)
|
41
41
|
end
|
42
42
|
|
43
43
|
class << self
|
@@ -48,7 +48,7 @@ class Resolv::DNS::Resource::IN::SVCB < Resolv::DNS::Resource
|
|
48
48
|
return new(svc_priority, target_name, {}) if svc_priority.zero?
|
49
49
|
|
50
50
|
# the SvcParams, consuming the remainder of the record
|
51
|
-
svc_params = ::SvcbRrPatch::SvcParams.decode(msg.get_bytes)
|
51
|
+
svc_params = ::SvcbRrPatch::SvcParams::Hash.decode(msg.get_bytes)
|
52
52
|
new(svc_priority, target_name, svc_params)
|
53
53
|
end
|
54
54
|
end
|
data/spec/alpn_spec.rb
CHANGED
data/spec/ipv4hint_spec.rb
CHANGED
data/spec/ipv6hint_spec.rb
CHANGED
data/spec/mandatory_spec.rb
CHANGED
@@ -5,16 +5,16 @@ require_relative 'spec_helper'
|
|
5
5
|
|
6
6
|
RSpec.describe SvcbRrPatch::SvcParams::Mandatory do
|
7
7
|
let(:octet) do
|
8
|
-
"\x00\x05\x00\x06\xff\xa4"
|
8
|
+
"\x00\x05\x00\x06\x00\x08\xff\xa4"
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:keys) do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
[
|
13
|
+
SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['ech'],
|
14
|
+
SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['ipv6hint'],
|
15
|
+
SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['undefine8'],
|
16
|
+
SvcbRrPatch::SvcParams::PARAMETER_REGISTRY_INVERT['key65444']
|
17
|
+
]
|
18
18
|
end
|
19
19
|
|
20
20
|
context '#decode' do
|
@@ -34,7 +34,7 @@ RSpec.describe SvcbRrPatch::SvcParams::Mandatory do
|
|
34
34
|
|
35
35
|
it 'could encode' do
|
36
36
|
expect(mandatory.encode).to eq octet
|
37
|
-
expect(mandatory.
|
37
|
+
expect(mandatory.to_s).to eq 'ech,ipv6hint,undefine8,key65444'
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -30,7 +30,7 @@ RSpec.describe SvcbRrPatch::SvcParams::NoDefaultAlpn do
|
|
30
30
|
expect(no_default_alpn)
|
31
31
|
.to be_a(SvcbRrPatch::SvcParams::NoDefaultAlpn)
|
32
32
|
expect(no_default_alpn.encode).to eq octet
|
33
|
-
expect(no_default_alpn.
|
33
|
+
expect(no_default_alpn.to_s).to eq 'h3-29,h3-28,h3-27,h2'
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
data/spec/port_spec.rb
CHANGED
data/spec/svc_params_spec.rb
CHANGED
@@ -45,7 +45,7 @@ RSpec.describe SvcbRrPatch::SvcParams do
|
|
45
45
|
|
46
46
|
context '#decode' do
|
47
47
|
let(:svc_params) do
|
48
|
-
SvcbRrPatch::SvcParams.decode(octet)
|
48
|
+
SvcbRrPatch::SvcParams::Hash.decode(octet)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'could decode' do
|
@@ -60,16 +60,18 @@ RSpec.describe SvcbRrPatch::SvcParams do
|
|
60
60
|
|
61
61
|
context '#encode' do
|
62
62
|
let(:svc_params) do
|
63
|
-
{
|
63
|
+
h = {
|
64
64
|
'alpn' => alpn,
|
65
65
|
'ipv4hint' => ipv4hint,
|
66
66
|
'ipv6hint' => ipv6hint,
|
67
67
|
'key65333' => key65333
|
68
68
|
}
|
69
|
+
SvcbRrPatch::SvcParams::Hash.new(h)
|
69
70
|
end
|
70
71
|
|
71
72
|
it 'could encode' do
|
72
|
-
expect(
|
73
|
+
expect(svc_params.encode).to eq octet
|
74
|
+
puts svc_params.inspect
|
73
75
|
end
|
74
76
|
end
|
75
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svcb_rr_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thekuwayama
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|