3232using System . IO ;
3333using System . Net . Security ;
3434using System . Security . Authentication ;
35+ using System . Security . Cryptography . X509Certificates ;
3536using System . Threading . Tasks ;
3637using RabbitMQ . Client ;
3738using Xunit ;
@@ -42,13 +43,11 @@ namespace Test.Integration
4243 public class TestSsl : IntegrationFixture
4344 {
4445 private readonly SslEnv _sslEnv ;
45- private readonly string _certPath ;
4646
4747 public TestSsl ( ITestOutputHelper output ) : base ( output )
4848 {
4949 _sslEnv = new SslEnv ( ) ;
50- _certPath = _sslEnv . CertPath ;
51- Assert . True ( File . Exists ( _certPath ) ) ;
50+ Assert . True ( File . Exists ( _sslEnv . CertDirectPath ) ) ;
5251 }
5352
5453 public override Task InitializeAsync ( )
@@ -67,7 +66,8 @@ public async Task TestServerVerifiedIgnoringNameMismatch()
6766 ConnectionFactory cf = CreateConnectionFactory ( ) ;
6867 cf . Port = 5671 ;
6968 cf . Ssl . ServerName = "*" ;
70- cf . Ssl . CertPath = _certPath ;
69+ cf . Ssl . CertPath = _sslEnv . CertDirectPath ;
70+ cf . Ssl . CertPassphrase = _sslEnv . CertPassphrase ;
7171 cf . Ssl . AcceptablePolicyErrors = SslPolicyErrors . RemoteCertificateNameMismatch ;
7272 cf . Ssl . Enabled = true ;
7373
@@ -82,7 +82,8 @@ public async Task TestServerVerified()
8282 ConnectionFactory cf = CreateConnectionFactory ( ) ;
8383 cf . Port = 5671 ;
8484 cf . Ssl . ServerName = _sslEnv . Hostname ;
85- cf . Ssl . CertPath = _certPath ;
85+ cf . Ssl . CertPath = _sslEnv . CertDirectPath ;
86+ cf . Ssl . CertPassphrase = _sslEnv . CertPassphrase ;
8687 cf . Ssl . Enabled = true ;
8788
8889 await SendReceiveAsync ( cf ) ;
@@ -96,7 +97,7 @@ public async Task TestClientAndServerVerified()
9697 ConnectionFactory cf = CreateConnectionFactory ( ) ;
9798 cf . Port = 5671 ;
9899 cf . Ssl . ServerName = _sslEnv . Hostname ;
99- cf . Ssl . CertPath = _certPath ;
100+ cf . Ssl . CertPath = _sslEnv . CertDirectPath ;
100101 cf . Ssl . CertPassphrase = _sslEnv . CertPassphrase ;
101102 cf . Ssl . Enabled = true ;
102103
@@ -112,7 +113,8 @@ public async Task TestWithClientCertificate()
112113 cf . Port = 5671 ;
113114 cf . Ssl = new SslOption ( )
114115 {
115- CertPath = _certPath ,
116+ CertPath = _sslEnv . CertDirectPath ,
117+ CertPassphrase = _sslEnv . CertPassphrase ,
116118 Enabled = true ,
117119 ServerName = _sslEnv . Hostname ,
118120 Version = SslProtocols . None ,
@@ -124,6 +126,31 @@ public async Task TestWithClientCertificate()
124126 await SendReceiveAsync ( cf ) ;
125127 }
126128
129+ #if NET
130+ [ SkippableFact ]
131+ public async Task TestWithClientCertificateSignedByIntermediate ( )
132+ {
133+ Skip . IfNot ( _sslEnv . IsSslConfigured , "SSL_CERTS_DIR and/or PASSWORD are not configured, skipping test" ) ;
134+
135+ Assert . True ( File . Exists ( _sslEnv . CertIntermediatePath ) ) ;
136+
137+ X509Certificate2 clientCertificate = new ( _sslEnv . CertIntermediatePath , _sslEnv . CertPassphrase ) ;
138+ X509Certificate2 intermediateCaCertificate = new ( _sslEnv . CertIntermediateCaPath ) ;
139+ X509Certificate2Collection intermediateCertificates = new ( intermediateCaCertificate ) ;
140+
141+ ConnectionFactory cf = CreateConnectionFactory ( ) ;
142+ cf . Port = 5671 ;
143+ cf . Ssl . Enabled = true ;
144+ cf . Ssl . ClientCertificateContext = SslStreamCertificateContext . Create ( clientCertificate , intermediateCertificates ) ;
145+ cf . Ssl . ServerName = _sslEnv . Hostname ;
146+ cf . Ssl . AcceptablePolicyErrors =
147+ SslPolicyErrors . RemoteCertificateNotAvailable |
148+ SslPolicyErrors . RemoteCertificateNameMismatch ;
149+
150+ await SendReceiveAsync ( cf ) ;
151+ }
152+ #endif
153+
127154 private async Task SendReceiveAsync ( ConnectionFactory connectionFactory )
128155 {
129156 await using IConnection conn = await CreateConnectionAsyncWithRetries ( connectionFactory ) ;
0 commit comments