Skip to content

Commit 27b5a8b

Browse files
author
Matthias Radestock
committed
better and more robust certificate selection
- don't explode when localCertificates is null or empty - pick a cert based on the acceptableIssuers, if we can
1 parent dfa415d commit 27b5a8b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

projects/client/RabbitMQ.Client/src/client/api/SslHelper.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,19 @@ static X509Certificate CertificateSelectionCallback(object sender,
7777
X509Certificate remoteCertificate,
7878
string[] acceptableIssuers)
7979
{
80-
return localCertificates[0];
80+
if (acceptableIssuers != null && acceptableIssuers.Length > 0 &&
81+
localCertificates != null && localCertificates.Count > 0)
82+
{
83+
foreach (X509Certificate certificate in localCertificates)
84+
{
85+
if (Array.IndexOf(acceptableIssuers, certificate.Issuer) != -1)
86+
return certificate;
87+
}
88+
}
89+
if (localCertificates != null && localCertificates.Count > 0)
90+
return localCertificates[0];
91+
92+
return null;
8193
}
8294

8395
///<summary>Upgrade a Tcp stream to an Ssl stream using the SSL options

0 commit comments

Comments
 (0)