Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to change SSL verify mode #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
log_level = info
idle_connection_timeout = 5
upstream = amqp://localhost:5672
ssl_verify_mode = PEER

[listen]
address = 127.0.0.1
Expand Down
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: amqproxy
version: 2.0.3
version: 2.0.3-oleks

authors:
- CloudAMQP <contact@cloudamqp.com>
Expand Down
8 changes: 7 additions & 1 deletion src/amqproxy/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AMQProxy::CLI
@http_port = ENV["HTTP_PORT"]? || 15673
@log_level : ::Log::Severity = ::Log::Severity::Info
@idle_connection_timeout : Int32 = ENV.fetch("IDLE_CONNECTION_TIMEOUT", "5").to_i
@ssl_verify_mode = ENV["SSL_VERIFY_MODE"]? || OpenSSL::SSL::VerifyMode::PEER.to_s
@term_timeout = -1
@term_client_close_timeout = 0
@upstream = ENV["AMQP_URL"]?
Expand All @@ -30,6 +31,7 @@ class AMQProxy::CLI
when "idle_connection_timeout" then @idle_connection_timeout = value.to_i
when "term_timeout" then @term_timeout = value.to_i
when "term_client_close_timeout" then @term_client_close_timeout = value.to_i
when "ssl_verify_mode" then @ssl_verify_mode = value
else raise "Unsupported config #{name}/#{key}"
end
end
Expand Down Expand Up @@ -62,6 +64,9 @@ class AMQProxy::CLI
parser.on("-t IDLE_CONNECTION_TIMEOUT", "--idle-connection-timeout=SECONDS", "Maxiumum time in seconds an unused pooled connection stays open (default 5s)") do |v|
@idle_connection_timeout = v.to_i
end
parser.on("-s SSL_VERIFY_MODE", "--ssl-verify-mode=VALUE", "SSL Verification Mode (default PEER). See OpenSSL::SSL::VerifyMode.") do |v|
@ssl_verify_mode = v
end
parser.on("--term-timeout=SECONDS", "At TERM the server waits SECONDS seconds for clients to gracefully close their sockets after Close has been sent (default: infinite)") do |v|
@term_timeout = v.to_i
end
Expand Down Expand Up @@ -99,7 +104,8 @@ class AMQProxy::CLI
Signal::INT.trap &->self.initiate_shutdown(Signal)
Signal::TERM.trap &->self.initiate_shutdown(Signal)

server = @server = AMQProxy::Server.new(u.hostname || "", port, tls, @idle_connection_timeout)
ssl_verify_mode = OpenSSL::SSL::VerifyMode.parse?(@ssl_verify_mode) || abort("Invalid SSL verify mode #{@ssl_verify_mode}")
server = @server = AMQProxy::Server.new(u.hostname || "", port, tls, @idle_connection_timeout, ssl_verify_mode)

HTTPServer.new(server, @listen_address, @http_port.to_i)
server.listen(@listen_address, @listen_port.to_i)
Expand Down
8 changes: 6 additions & 2 deletions src/amqproxy/server.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ module AMQProxy
new(host, port, tls, idle_connection_timeout)
end

def initialize(upstream_host, upstream_port, upstream_tls, idle_connection_timeout = 5)
tls_ctx = OpenSSL::SSL::Context::Client.new if upstream_tls
def initialize(upstream_host, upstream_port, upstream_tls, idle_connection_timeout = 5, ssl_verify_mode = OpenSSL::SSL::VerifyMode::PEER)
tls_ctx = if upstream_tls
context = OpenSSL::SSL::Context::Client.new
context.verify_mode = ssl_verify_mode
context
end
@channel_pools = Hash(Credentials, ChannelPool).new do |hash, credentials|
hash[credentials] = ChannelPool.new(upstream_host, upstream_port, tls_ctx, credentials, idle_connection_timeout)
end
Expand Down