-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #94 from thekuwayama/ech_outer_extensions
feat: support ech_outer_extensions
- Loading branch information
Showing
18 changed files
with
288 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,57 @@ | ||
# encoding: ascii-8bit | ||
# frozen_string_literal: true | ||
|
||
require_relative 'helper' | ||
|
||
uri = URI.parse(ARGV[0] || 'https://localhost:4433') | ||
ca_file = __dir__ '/../tmp/ca.crt' | ||
req = simple_http_request(uri.host, uri.path) | ||
ech_config = if ARGV.length > 1 | ||
parse_echconfigs_pem(File.open(ARGV[1]).read).first | ||
else | ||
resolve_echconfig(uri.host) | ||
end | ||
|
||
settings_2nd = { | ||
ca_file: File.exist?(ca_file) ? ca_file : nil, | ||
alpn: ['http/1.1'], | ||
ech_config: ech_config, | ||
ech_hpke_cipher_suites: | ||
TTTLS13::STANDARD_CLIENT_ECH_HPKE_SYMMETRIC_CIPHER_SUITES, | ||
sslkeylogfile: '/tmp/sslkeylogfile.log' | ||
} | ||
process_new_session_ticket = lambda do |nst, rms, cs| | ||
return if Time.now.to_i - nst.timestamp > nst.ticket_lifetime | ||
|
||
settings_2nd[:ticket] = nst.ticket | ||
settings_2nd[:resumption_main_secret] = rms | ||
settings_2nd[:psk_cipher_suite] = cs | ||
settings_2nd[:ticket_nonce] = nst.ticket_nonce | ||
settings_2nd[:ticket_age_add] = nst.ticket_age_add | ||
settings_2nd[:ticket_timestamp] = nst.timestamp | ||
end | ||
settings_1st = { | ||
ca_file: File.exist?(ca_file) ? ca_file : nil, | ||
alpn: ['http/1.1'], | ||
ech_config: ech_config, | ||
ech_hpke_cipher_suites: | ||
TTTLS13::STANDARD_CLIENT_ECH_HPKE_SYMMETRIC_CIPHER_SUITES, | ||
process_new_session_ticket: process_new_session_ticket, | ||
sslkeylogfile: '/tmp/sslkeylogfile.log' | ||
} | ||
|
||
[ | ||
# Initial Handshake: | ||
settings_1st, | ||
# Subsequent Handshake: | ||
settings_2nd | ||
].each do |settings| | ||
socket = TCPSocket.new(uri.host, uri.port) | ||
client = TTTLS13::Client.new(socket, uri.host, **settings) | ||
client.connect | ||
client.write(req) | ||
|
||
print recv_http_response(client) | ||
client.close unless client.eof? | ||
socket.close | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,52 @@ | ||
# encoding: ascii-8bit | ||
# frozen_string_literal: true | ||
|
||
module TTTLS13 | ||
using Refinements | ||
module Message | ||
module Extension | ||
# NOTE: | ||
# ExtensionType OuterExtensions<2..254>; | ||
class ECHOuterExtensions | ||
attr_reader :extension_type | ||
attr_reader :outer_extensions | ||
|
||
# @param outer_extensions [Array of TTTLS13::Message::ExtensionType] | ||
def initialize(outer_extensions) | ||
@extension_type = ExtensionType::ECH_OUTER_EXTENSIONS | ||
@outer_extensions = outer_extensions | ||
end | ||
|
||
# @raise [TTTLS13::Error::ErrorAlerts] | ||
# | ||
# @return [String] | ||
def serialize | ||
binary = @outer_extensions.join.prefix_uint8_length | ||
@extension_type binary.prefix_uint16_length | ||
end | ||
|
||
# @param binary [String] | ||
# | ||
# @raise [TTTLS13::Error::ErrorAlerts] | ||
# | ||
# @return [TTTLS13::Message::Extensions::ECHOuterExtensions] | ||
def self.deserialize(binary) | ||
raise Error::ErrorAlerts, :internal_error if binary.nil? | ||
|
||
return nil if binary.length < 2 | ||
|
||
exlist_len = Convert.bin2i(binary.slice(0, 1)) | ||
i = 1 | ||
outer_extensions = [] | ||
while i < exlist_len 1 | ||
outer_extensions << binary.slice(i, 2) | ||
i = 2 | ||
end | ||
return nil unless outer_extensions.length * 2 == exlist_len | ||
|
||
ECHOuterExtensions.new(outer_extensions) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.