Class: EchSpec::CLI::Grease
Instance Method Summary
collapse
#evaluate_widths, #field_pairs, #print_ech_configs, #print_field
Instance Method Details
#execute(argv) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/echspec/cli/grease.rb', line 6
def execute(argv)
port, hostname = parse_options(argv)
TTTLS13::Logging.logger.level = Logger::WARN
socket = TCPSocket.new(hostname, port)
recv = TLS13Client.send_ch_with_greased_ech(socket, hostname)
ex = recv.extensions[TTTLS13::Message::ExtensionType::ENCRYPTED_CLIENT_HELLO]
if ex.nil? || ex.retry_configs.nil? || ex.retry_configs.empty?
warn "** #{hostname}:#{port} did not send retry_configs"
exit 1
end
print_ech_configs(ex.retry_configs)
rescue Timeout::Error
warn "** #{hostname}:#{port} connection timeout"
exit 1
rescue Errno::ECONNREFUSED
warn "** #{hostname}:#{port} connection refused"
exit 1
ensure
socket&.close
end
|
#parse_options(argv) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/echspec/cli/grease.rb', line 30
def parse_options(argv)
op = OptionParser.new
port = 443
op.on(
'-p',
'--port VALUE',
"server port number (default #{port})"
) do |v|
port = v
end
op.banner = <<~USAGE
Usage: echspec grease [OPTIONS...] {HOSTNAME}
Send GREASE ECH to a server and display retry_configs.
Examples:
$ echspec grease localhost
$ echspec grease -p 4433 localhost
Options:
USAGE
begin
args = op.parse(argv)
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
warn op
warn "** #{e.message}"
exit 1
end
if args.length != 1
warn op
warn '** {HOSTNAME} argument is not specified'
exit 1
end
[port, args[0]]
end
|