Skip to content

Commit bb7a545

Browse files
committed
[Client] Adds JRuby compatibility to fingerprinting
1 parent 9a21b79 commit bb7a545

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

elasticsearch-transport/lib/elasticsearch/transport/client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def validate_ca_fingerprints
227227
ssl = OpenSSL::SSL::SSLSocket.new(socket, ctx)
228228
ssl.connect
229229
cert_store = ssl.peer_cert_chain
230-
matching_certs = cert_store.chain.select do |cert|
230+
matching_certs = cert_store.select do |cert|
231231
OpenSSL::Digest::SHA256.hexdigest(cert.to_der).upcase == @ca_fingerprint.upcase
232232
end
233233
if matching_certs.empty?

elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,17 +1989,13 @@
19891989

19901990
context 'CA Fingerprinting' do
19911991
context 'when setting a ca_fingerprint' do
1992-
let(:subject) { "/C=BE/O=Test/OU=Test/CN=Test" }
1993-
19941992
let(:certificate) do
1995-
OpenSSL::X509::Certificate.new.tap do |cert|
1996-
cert.subject = cert.issuer = OpenSSL::X509::Name.parse(subject)
1997-
cert.not_before = Time.now
1998-
cert.not_after = Time.now + 365 * 24 * 60 * 60
1999-
cert.public_key = OpenSSL::PKey::RSA.new(1024).public_key
2000-
cert.serial = 0x0
2001-
cert.version = 2
2002-
end
1993+
system(
1994+
'openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -subj "/C=BE/O=Test/CN=Test"' \
1995+
' -keyout certificate.key -out certificate.crt',
1996+
err: File::NULL
1997+
)
1998+
OpenSSL::X509::Certificate.new File.read('./certificate.crt')
20031999
end
20042000

20052001
let(:client) do
@@ -2015,8 +2011,11 @@
20152011

20162012
server = double('server').as_null_object
20172013
allow(TCPSocket).to receive(:new) { server }
2018-
allow_any_instance_of(OpenSSL::SSL::SSLSocket).to receive(:connect) { nil }
2019-
allow_any_instance_of(OpenSSL::SSL::SSLSocket).to receive(:peer_cert_chain) { [certificate] }
2014+
socket = double('socket')
2015+
allow(OpenSSL::SSL::SSLSocket).to receive(:new) { socket }
2016+
allow(socket).to receive(:connect) { nil }
2017+
allow(socket).to receive(:peer_cert_chain) { [certificate] }
2018+
20202019
response = client.perform_request('GET', '/')
20212020
expect(client.transport.connections.connections.map(&:verified).uniq).to eq [true]
20222021
expect(response).to eq 'Hello'

0 commit comments

Comments
 (0)