Skip to content

Commit 92ea99b

Browse files
committed
Use correct certs, add test for ClientCertificateContext
1 parent c5b015d commit 92ea99b

File tree

4 files changed

+73
-12
lines changed

4 files changed

+73
-12
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDWTCCAkGgAwIBAgIBATANBgkqhkiG9w0BAQsFADBLMTowOAYDVQQDDDFUTFNH
3+
ZW5TZWxmU2lnbmVkUm9vdENBIDIwMjUtMTEtMDVUMTE6MDk6MDEuNzUwMzk0MQ0w
4+
CwYDVQQHDAQkJCQkMB4XDTI1MTEwNTE5MDkwMloXDTM1MTEwMzE5MDkwMlowMDES
5+
MBAGA1UEAwwJbG9jYWxob3N0MRowGAYDVQQKDBFJbnRlcm1lZGlhdGUgQ0EgMTCC
6+
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALGTs4Ko9Oki5JxasnIgb8wK
7+
GLm+dIj1ZChIrh1TOu0avkWBHobj7xP7TXN3Vq/R1sIkTud/CU2KFklc8TZGEvhN
8+
Gw93W6pHoxMrb8QA6X+ZDO86V0jJInuY0JLUqvFDxteOdm3ZjCXyQ4IpIukfa64f
9+
gYgrrw8V/OYY7LVEpmYZBVTWQgfs60zXWQGH6mWMveyhyz0cn0s16vVFkGph+WP8
10+
/hn62vV1RWPfC4t5z3wBdFswHk4qI510Mf0T15uHHeXYi76iSy7gXJKNtFzlS/1r
11+
CrXQlt7UbvyF7pKKLKpx4jFKaF/SRQcfAEq+pVxWDPE/YYcQJxqb5RwXvGz6wF0C
12+
AwEAAaNjMGEwEgYDVR0TAQH/BAgwBgEB/wIBADALBgNVHQ8EBAMCAQYwHQYDVR0O
13+
BBYEFK9IWEFnYGJeyCQd177yQJAAzqKXMB8GA1UdIwQYMBaAFLZFdCoYSf57KzPs
14+
DaRWoM/JCmiWMA0GCSqGSIb3DQEBCwUAA4IBAQCbrk/bLbm+2I0wsFDDmXW6MyAJ
15+
8h4yp0JYOcas+rDqQCVKyprHn1ARbWqtKJYxKseV5583y/vHB9lG8wuoMqWlfUAS
16+
aG7v+sw4f35Qf9fl1YboSPYEHuW7ZB481ffj0NBlhKKLkNj7K/uQTgzd67dXcH1W
17+
jmvKXfpISLAvLzh0645JCDYR+yzGrQJ7K7qR0qEia9dGb1f7reaevi8S9dg6YqXs
18+
eFOm0F9c3I3D2yNVy8vrAi/4Qmczs1GC9/9zXKhYjRKDKeRTpe1bSY9jstlgwYbS
19+
oNA029JJBBhz0eX26frVt0YBxm8qPJKrmjcsG/ICCsBsfcm17qZoRWiEr3DN
20+
-----END CERTIFICATE-----

projects/Test/Common/SslEnv.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ namespace Test
3737
public class SslEnv
3838
{
3939
private readonly string _certPassphrase;
40-
private readonly string _certPath;
40+
private readonly string _certDirectPath;
41+
private readonly string _certIntermediatePath;
42+
private readonly string _certIntermediateCaPath;
4143
private const string _hostname = "localhost";
4244
private readonly string _sslDir;
4345
private readonly bool _isSslConfigured;
@@ -52,13 +54,25 @@ public SslEnv()
5254

5355
if (_isSslConfigured)
5456
{
55-
_certPath = Path.Combine(_sslDir, $"client.p12");
57+
_certDirectPath = Path.Combine(_sslDir, $"client_direct.p12");
58+
_certIntermediatePath = Path.Combine(_sslDir, $"client_certificate.p12");
59+
_certIntermediateCaPath = Path.Combine(_sslDir, $"intermediate_ca_certificate.pem");
5660
}
5761
}
5862

59-
public string CertPath
63+
public string CertDirectPath
6064
{
61-
get { return _certPath; }
65+
get { return _certDirectPath; }
66+
}
67+
68+
public string CertIntermediatePath
69+
{
70+
get { return _certIntermediatePath; }
71+
}
72+
73+
public string CertIntermediateCaPath
74+
{
75+
get { return _certIntermediateCaPath; }
6276
}
6377

6478
public string CertPassphrase

projects/Test/Integration/TestSsl.cs

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
using System.IO;
3333
using System.Net.Security;
3434
using System.Security.Authentication;
35+
using System.Security.Cryptography.X509Certificates;
3536
using System.Threading.Tasks;
3637
using RabbitMQ.Client;
3738
using 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);

projects/Test/SequentialIntegration/TestHeartbeats.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task TestThatHeartbeatWriterWithTLSEnabledAsync()
8585
cf.AutomaticRecoveryEnabled = false;
8686

8787
cf.Ssl.ServerName = sslEnv.Hostname;
88-
cf.Ssl.CertPath = sslEnv.CertPath;
88+
cf.Ssl.CertPath = sslEnv.CertDirectPath;
8989
cf.Ssl.CertPassphrase = sslEnv.CertPassphrase;
9090
cf.Ssl.Enabled = true;
9191

0 commit comments

Comments
 (0)