Skip to content

Commit 33d5e6b

Browse files
committed
RUBY-725 Support providing a SSL keyfile passphrase
1 parent 43b45d6 commit 33d5e6b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/mongo/socket/ssl.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ def create_context(options)
8787
context.cert = OpenSSL::X509::Certificate.new(File.open(options[:ssl_cert]))
8888
end
8989
if options[:ssl_key]
90-
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]))
90+
if options[:ssl_key_pass_phrase]
91+
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]),
92+
options[:ssl_key_pass_phrase])
93+
else
94+
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]))
95+
end
9196
end
9297
if options[:ssl_verify] || options[:ssl_ca_cert]
9398
context.ca_file = options[:ssl_ca_cert]

spec/mongo/server/connection_spec.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,16 @@
271271

272272
context 'when ssl options are provided' do
273273

274+
let(:ssl_options) do
275+
{ :ssl => true, :ssl_key => 'file', :ssl_key_pass_phrase => 'iamaphrase' }
276+
end
277+
274278
let(:connection) do
275-
described_class.new(server, :ssl => true)
279+
described_class.new(server, ssl_options)
276280
end
277281

278282
it 'sets the ssl options' do
279-
expect(connection.send(:ssl_options)).to eq(:ssl => true)
283+
expect(connection.send(:ssl_options)).to eq(ssl_options)
280284
end
281285
end
282286

0 commit comments

Comments
 (0)