Skip to content

Commit b15b57a

Browse files
authored
Fix h2 connections to use config values (#3214)
1 parent 0096a64 commit b15b57a

File tree

4 files changed

+27
-35
lines changed

4 files changed

+27
-35
lines changed

gems/aws-sdk-core/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Enable ALPN over TLS for H2 Connection by default.
5+
* Issue - Fix HTTP-2 connections to properly use config values configured on the client.
6+
47
3.220.2 (2025-03-20)
58
------------------
69

gems/aws-sdk-core/lib/seahorse/client/async_base.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@
33
module Seahorse
44
module Client
55
class AsyncBase < Seahorse::Client::Base
6-
76
# default H2 plugins
87
# @api private
98
@plugins = PluginList.new([
109
Plugins::Endpoint,
1110
Plugins::H2,
1211
Plugins::ResponseTarget
1312
])
13+
1414
def initialize(plugins, options)
15-
super
16-
@connection = H2::Connection.new(options)
17-
@options = options
15+
super(plugins, options)
16+
@connection = H2::Connection.new(@config)
1817
end
1918

2019
# @return [H2::Connection]
@@ -36,7 +35,7 @@ def close_connection
3635
# @return [Seahorse::Client::H2::Connection]
3736
def new_connection
3837
if @connection.closed?
39-
@connection = H2::Connection.new(@options)
38+
@connection = H2::Connection.new(@config)
4039
else
4140
@connection
4241
end

gems/aws-sdk-core/lib/seahorse/client/h2/connection.rb

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ module Seahorse
1010
module Client
1111
# @api private
1212
module H2
13-
1413
# H2 Connection build on top of `http/2` gem
15-
# (requires Ruby >= 2.1)
16-
# with TLS layer plus ALPN, requires:
17-
# Ruby >= 2.3 and OpenSSL >= 1.0.2
1814
class Connection
19-
2015
OPTIONS = {
2116
max_concurrent_streams: 100,
2217
connection_timeout: 60,
@@ -27,7 +22,7 @@ class Connection
2722
ssl_ca_bundle: nil,
2823
ssl_ca_directory: nil,
2924
ssl_ca_store: nil,
30-
enable_alpn: false
25+
enable_alpn: true
3126
}
3227

3328
# chunk read size at socket
@@ -41,25 +36,23 @@ def initialize(options = {})
4136
instance_variable_set("@#{opt_name}", value)
4237
end
4338
@h2_client = HTTP2::Client.new(
44-
settings_max_concurrent_streams: max_concurrent_streams
39+
settings_max_concurrent_streams: @max_concurrent_streams
4540
)
46-
@logger = if @http_wire_trace
47-
options[:logger] || Logger.new($stdout)
48-
end
41+
@logger ||= Logger.new($stdout) if @http_wire_trace
4942
@chunk_size = options[:read_chunk_size] || CHUNKSIZE
43+
5044
@errors = []
5145
@status = :ready
46+
5247
@mutex = Mutex.new # connection can be shared across requests
5348
@socket = nil
5449
@socket_thread = nil
5550
end
5651

5752
OPTIONS.keys.each do |attr_name|
58-
attr_reader(attr_name)
53+
attr_reader attr_name
5954
end
6055

61-
alias ssl_verify_peer? ssl_verify_peer
62-
6356
attr_reader :errors
6457

6558
attr_accessor :input_signal_thread
@@ -112,7 +105,7 @@ def start(stream)
112105
@h2_client << data
113106
rescue IO::WaitReadable
114107
begin
115-
unless IO.select([@socket], nil, nil, connection_read_timeout)
108+
unless IO.select([@socket], nil, nil, @connection_read_timeout)
116109
self.debug_output('socket connection read time out')
117110
self.close!
118111
else
@@ -154,11 +147,11 @@ def closed?
154147
end
155148

156149
def debug_output(msg, type = nil)
157-
prefix = case type
150+
prefix =
151+
case type
158152
when :send then '-> '
159153
when :receive then '<- '
160-
else
161-
''
154+
else ''
162155
end
163156
return unless @logger
164157
_debug_entry(prefix + msg)
@@ -206,7 +199,7 @@ def _nonblocking_connect(tcp, addr)
206199
begin
207200
tcp.connect_nonblock(addr)
208201
rescue IO::WaitWritable
209-
unless IO.select(nil, [tcp], nil, connection_timeout)
202+
unless IO.select(nil, [tcp], nil, @connection_timeout)
210203
tcp.close
211204
raise
212205
end
@@ -220,31 +213,28 @@ def _nonblocking_connect(tcp, addr)
220213

221214
def _tls_context
222215
ssl_ctx = OpenSSL::SSL::SSLContext.new(:TLSv1_2)
223-
if ssl_verify_peer?
216+
if @ssl_verify_peer
224217
ssl_ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
225-
ssl_ctx.ca_file = ssl_ca_bundle ? ssl_ca_bundle : _default_ca_bundle
226-
ssl_ctx.ca_path = ssl_ca_directory ? ssl_ca_directory : _default_ca_directory
227-
ssl_ctx.cert_store = ssl_ca_store if ssl_ca_store
218+
ssl_ctx.ca_file = @ssl_ca_bundle || _default_ca_bundle
219+
ssl_ctx.ca_path = @ssl_ca_directory || _defalt_ca_directory
220+
ssl_ctx.cert_store = @ssl_ca_store if @ssl_ca_store
228221
else
229222
ssl_ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
230223
end
231-
if enable_alpn
224+
if @enable_alpn
232225
debug_output('enabling ALPN for TLS ...')
233226
ssl_ctx.alpn_protocols = ['h2']
234227
end
235228
ssl_ctx
236229
end
237230

238231
def _default_ca_bundle
239-
File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE) ?
240-
OpenSSL::X509::DEFAULT_CERT_FILE : nil
232+
OpenSSL::X509::DEFAULT_CERT_FILE if File.exist?(OpenSSL::X509::DEFAULT_CERT_FILE)
241233
end
242234

243-
def _default_ca_directory
244-
Dir.exist?(OpenSSL::X509::DEFAULT_CERT_DIR) ?
245-
OpenSSL::X509::DEFAULT_CERT_DIR : nil
235+
def _defalt_ca_directory
236+
OpenSSL::X509::DEFAULT_CERT_DIR if Dir.exist?(OpenSSL::X509::DEFAULT_CERT_DIR)
246237
end
247-
248238
end
249239
end
250240
end

gems/aws-sdk-securityhub/lib/aws-sdk-securityhub/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5278,7 +5278,7 @@ def get_configuration_policy(params = {}, options = {})
52785278
# resp.to_h outputs the following:
52795279
# {
52805280
# association_status: "FAILED",
5281-
# association_status_message: "Configuration Policy a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 couldn\u2019t be applied to account 111122223333 in us-east-1 Region. Retry your request.",
5281+
# association_status_message: "Configuration Policy a1b2c3d4-5678-90ab-cdef-EXAMPLE11111 couldn’t be applied to account 111122223333 in us-east-1 Region. Retry your request.",
52825282
# association_type: "INHERITED",
52835283
# configuration_policy_id: "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
52845284
# target_id: "111122223333",

0 commit comments

Comments
 (0)