Class: Ddig::Ddr::DesignatedResolver
- Inherits:
-
Object
- Object
- Ddig::Ddr::DesignatedResolver
- Defined in:
- lib/ddig/ddr/designated_resolver.rb
Constant Summary collapse
- PROTOCOLS =
['http/1.1', 'h2', 'h3', 'dot', 'doq']
- IGNORE_PROTOCOLS =
[ "\u001A\u001A", "\u002A\u002A", "\u003A\u003A", "\u004A\u004A", "\u005A\u005A", "\u006A\u006A", "\u007A\u007A", "\u008A\u008A", "\u009A\u009A", "\u00AA\u00AA", "\u00BA\u00BA", "\u00CA\u00CA", "\u00DA\u00DA", "\u00EA\u00EA", "\u00FA\u00FA" ]
Instance Attribute Summary collapse
-
#a ⇒ Object
readonly
Returns the value of attribute a.
-
#aaaa ⇒ Object
readonly
Returns the value of attribute aaaa.
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#dohpath ⇒ Object
readonly
Returns the value of attribute dohpath.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#hostname ⇒ Object
readonly
Returns the value of attribute hostname.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#protocol ⇒ Object
readonly
Returns the value of attribute protocol.
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
-
#unencrypted_resolver ⇒ Object
readonly
Returns the value of attribute unencrypted_resolver.
-
#verify_cert ⇒ Object
readonly
Returns the value of attribute verify_cert.
Instance Method Summary collapse
- #as_json ⇒ Object
-
#initialize(unencrypted_resolver:, target:, protocol: nil, port: nil, dohpath: nil, address: nil, ip: nil) ⇒ DesignatedResolver
constructor
‘**’, ‘::’, ‘JJ’, ‘ZZ’, ‘jj’, ‘zz’.
- #lookup(hostname) ⇒ Object
-
#set_default_port ⇒ Object
Set default port by protocol ref: www.rfc-editor.org/rfc/rfc9461.html#section-4.2.
- #to_cli ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s ⇒ Object
- #uniq_key ⇒ Object
- #verify ⇒ Object
Constructor Details
#initialize(unencrypted_resolver:, target:, protocol: nil, port: nil, dohpath: nil, address: nil, ip: nil) ⇒ DesignatedResolver
‘**’, ‘::’, ‘JJ’, ‘ZZ’, ‘jj’, ‘zz’
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 19 def initialize(unencrypted_resolver:, target:, protocol: nil, port: nil, dohpath: nil, address: nil, ip: nil) @target = target @unencrypted_resolver = unencrypted_resolver @protocol = protocol @port = port @dohpath = dohpath @address = address @ip = ip @errors = [] # check protocol unless PROTOCOLS.include?(@protocol) if IGNORE_PROTOCOLS.include?(@protocol) @errors << "Skip the protocol (protocol: #{@protocol}), as it is a reserved value in ALPN." else @errors << "Not Supportted Protocol (protocol: #{@protocol}). Suported protocol is #{PROTOCOLS.join(' / ')}" puts "#{@errors.join('\n')}" end end if @port.nil? set_default_port end end |
Instance Attribute Details
#a ⇒ Object (readonly)
Returns the value of attribute a.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def a @a end |
#aaaa ⇒ Object (readonly)
Returns the value of attribute aaaa.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def aaaa @aaaa end |
#address ⇒ Object (readonly)
Returns the value of attribute address.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def address @address end |
#dohpath ⇒ Object (readonly)
Returns the value of attribute dohpath.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def dohpath @dohpath end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def errors @errors end |
#hostname ⇒ Object (readonly)
Returns the value of attribute hostname.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def hostname @hostname end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def ip @ip end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def port @port end |
#protocol ⇒ Object (readonly)
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def protocol @protocol end |
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
8 9 10 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 8 def resolver @resolver end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def target @target end |
#unencrypted_resolver ⇒ Object (readonly)
Returns the value of attribute unencrypted_resolver.
6 7 8 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 6 def unencrypted_resolver @unencrypted_resolver end |
#verify_cert ⇒ Object (readonly)
Returns the value of attribute verify_cert.
7 8 9 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 7 def verify_cert @verify_cert end |
Instance Method Details
#as_json ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 78 def as_json(*) { unencrypted_resolver: @unencrypted_resolver, target: @target, protocol: @protocol, port: @port, dohpath: @dohpath, address: @address, ip: @ip, verify: @verify_cert&.verify, hostname: @hostname, a: @a, aaaa: @aaaa, errors: @errors, } end |
#lookup(hostname) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 49 def lookup(hostname) @hostname = hostname case @protocol when 'dot' @resolver = Ddig::Resolver::Dot.new(hostname: @hostname, server: @address, server_name: @target, port: @port).lookup unless @resolver.nil? @a = @resolver.a @aaaa = @resolver.aaaa return self end when 'http/1.1', 'h2', 'h3' @resolver = Ddig::Resolver::DohH1.new(hostname: @hostname, server: @address, address: @address, dohpath: @dohpath, port: @port).lookup unless @resolver.nil? @a = @resolver.a @aaaa = @resolver.aaaa return self end when 'doq' @errors << "#{@protocol} is not supportted protocol" end end |
#set_default_port ⇒ Object
Set default port by protocol ref: www.rfc-editor.org/rfc/rfc9461.html#section-4.2
118 119 120 121 122 123 124 125 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 118 def set_default_port case @protocol when 'http/1.1', 'h2', 'h3' @port = 443 when 'dot', 'doq' @port = 853 end end |
#to_cli ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 99 def to_cli if @resolver.nil? puts "# #{@errors.join('\n# ')}" return end @resolver.to_cli end |
#to_json(*args) ⇒ Object
95 96 97 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 95 def to_json(*args) as_json.to_json end |
#to_s ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 108 def to_s if ['http/1.1', 'h2', 'h3'].include?(@protocol) "#{@protocol}: #{@target}:#{@port} (#{@address}),\tpath: #{@dohpath},\tunencrypted_resolver: #{@unencrypted_resolver}, \tverify cert: #{@verify_cert.verify}" else "#{@protocol}: #{@target}:#{@port} (#{@address}),\tunencrypted_resolver: #{@unencrypted_resolver}, \tverify cert: #{@verify_cert.verify}" end end |
#uniq_key ⇒ Object
127 128 129 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 127 def uniq_key "#{@unencrypted_resolver}-#{@target}-#{@protocol}-#{@port}-#{@dohpath}-#{@address}-#{@ip}" end |
#verify ⇒ Object
44 45 46 47 |
# File 'lib/ddig/ddr/designated_resolver.rb', line 44 def verify @verify_cert = VerifyCert.new(hostname: @target, address: @address, port: @port, unencrypted_resolver: @unencrypted_resolver) @verify_cert.verify end |