Skip to content

Commit 648aad1

Browse files
committed
Merge pull request #591 from estolfo/RUBY-725-ssl-passphrase
RUBY-725 Support providing a SSL keyfile passphrase
2 parents 17244ee + 33d5e6b commit 648aad1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/mongo/socket/ssl.rb

+6-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ def create_context(options)
104104
context.cert = OpenSSL::X509::Certificate.new(File.open(options[:ssl_cert]))
105105
end
106106
if options[:ssl_key]
107-
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]))
107+
if options[:ssl_key_pass_phrase]
108+
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]),
109+
options[:ssl_key_pass_phrase])
110+
else
111+
context.key = OpenSSL::PKey::RSA.new(File.open(options[:ssl_key]))
112+
end
108113
end
109114
if options[:ssl_verify] || options[:ssl_ca_cert]
110115
context.ca_file = options[:ssl_ca_cert]

spec/mongo/server/connection_spec.rb

+6-2
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)