altsvc: ensuring origin hostname is used during TLS handshake to alternative services

this means that finding a compatible connection got a bit more
expensive, due to options equality needing to account for extra sni
hostname.
This commit is contained in:
HoneyryderChuck 2022-05-23 01:16:52 +01:00
parent 675a2aa547
commit f14016774d
3 changed files with 15 additions and 5 deletions

View File

@ -28,7 +28,7 @@ AllCops:
- 'test/extensions/response_pattern_match.rb'
Metrics/ClassLength:
Max: 400
Enabled: false
Metrics/MethodLength:
Max: 200

View File

@ -102,8 +102,8 @@ module HTTPX
# origin came from an ORIGIN frame, we're going to verify the hostname with the
# SSL certificate
(@origins.size == 1 || @origin == uri.origin || (@io && @io.verify_hostname(uri.host)))
) || match_altsvcs?(uri)
) && @options == options
) && @options == options
) || (match_altsvcs?(uri) && match_altsvc_options?(uri, options))
end
def mergeable?(connection)
@ -162,6 +162,14 @@ module HTTPX
end
end
def match_altsvc_options?(uri, options)
return @options == options unless @options.ssl[:hostname] == uri.host
dup_options = @options.merge(ssl: { hostname: nil })
dup_options.ssl.delete(:hostname)
dup_options == options
end
def connecting?
@state == :idle
end

View File

@ -114,11 +114,13 @@ module HTTPX
# altsvc already exists, somehow it wasn't advertised, probably noop
return unless altsvc
connection = pool.find_connection(alt_origin, options) || build_connection(alt_origin, options)
alt_options = options.merge(ssl: options.ssl.merge(hostname: URI(origin).host))
connection = pool.find_connection(alt_origin, alt_options) || build_connection(alt_origin, alt_options)
# advertised altsvc is the same origin being used, ignore
return if connection == existing_connection
set_connection_callbacks(connection, connections, options)
set_connection_callbacks(connection, connections, alt_options)
log(level: 1) { "#{origin} alt-svc: #{alt_origin}" }