Skip to content

Commit c3ee034

Browse files
committed
don't assume the issuer is at a particular position in the chain
1 parent db88b8e commit c3ee034

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/mongo/socket/ssl.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def verify_ocsp_endpoint!(socket, timeout = nil)
460460
end
461461

462462
cert = socket.peer_cert
463-
ca_cert = socket.peer_cert_chain[1]
463+
ca_cert = find_issuer(cert, socket.peer_cert_chain)
464464

465465
verifier = OcspVerifier.new(@host_name, cert, ca_cert, context.cert_store,
466466
**Utils.shallow_symbolize_keys(options).merge(timeout: timeout))
@@ -503,6 +503,12 @@ def extract_certs(text)
503503
end
504504
end
505505
end
506+
507+
# Find the issuer certificate in the chain.
508+
# If the issuer is not found, raise an error.
509+
def find_issuer(cert, cert_chain)
510+
cert_chain.find { |c| c.subject == cert.issuer }
511+
end
506512
end
507513
end
508514
end

0 commit comments

Comments
 (0)