Skip to content

Commit 72cc6f8

Browse files
dheeparajsaibulusu
andauthored
TLS Support to OpenSSL workload - users/vdeepar/tls update (#550)
* basic framework for client-server with openssl * working version of client server model in VC * metric parser code added, tested one hour experiment * metric parser for openssl tls * update server key and cert path locations in the command * additional metrics added for TlsOpenSsl * Copy tlsreource files to openssl binary path * rename OpensslTls classes with TlsPrefix * src/VirtualClient/VirtualClient.Actions.UnitTests/OpenSSL/TlsOpenSslClientExecutorTests.cs * unit tests for TlsClient added * revert build-packages change * update Compete-Openssl-Tls profile --------- Co-authored-by: Sai Bulusu <[email protected]>
1 parent c08853b commit 72cc6f8

File tree

14 files changed

+1653
-73
lines changed

14 files changed

+1653
-73
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Using default temp DH parameters
2+
ACCEPT
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Collecting connection statistics for 5 seconds
2+
*****************
3+
4+
17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
5+
17 connections in 6 real seconds, 536870956 bytes read per connection
6+
7+
8+
Now timing with session id reuse.
9+
starting
10+
rrrrrrrrrrrrrrrrr
11+
12+
17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
13+
17 connections in 6 real seconds, 536870956 bytes read per connection
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace VirtualClient.Actions
5+
{
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Net;
10+
using System.Runtime.InteropServices;
11+
using System.Text;
12+
using System.Threading;
13+
using System.Threading.Tasks;
14+
using Moq;
15+
using NUnit.Framework;
16+
using VirtualClient.Common;
17+
using VirtualClient.Contracts;
18+
19+
[TestFixture]
20+
[Category("Functional")]
21+
public class TlsOpenSslClientProfileTests
22+
{
23+
private DependencyFixture mockFixture;
24+
25+
[SetUp]
26+
public void SetupFixture()
27+
{
28+
this.mockFixture = new DependencyFixture();
29+
this.mockFixture
30+
.Setup(PlatformID.Unix, Architecture.X64, "Client01")
31+
.SetupLayout(
32+
new ClientInstance("Client01", "1.2.3.4", "Client"),
33+
new ClientInstance("Server01", "1.2.3.5", "Server"));
34+
35+
ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
36+
}
37+
38+
[Test]
39+
[TestCase("Compete-OPENSSL-TLS.json")]
40+
public async Task TlsOpenSslClientCreatesExpectedStateAndExecutesWorkload(string profile)
41+
{
42+
List<string> expectedCommands = new List<string>();
43+
44+
// Setup the expectations for the workload
45+
// - Workload package is installed and exists.
46+
// - Workload binaries/executables exist on the file system.
47+
// - Expected processes are executed.
48+
IPAddress.TryParse("1.2.3.4", out IPAddress ipAddress);
49+
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient("1.2.3.4", ipAddress);
50+
51+
State state = new State();
52+
53+
await apiClient.CreateStateAsync(nameof(State), state, CancellationToken.None);
54+
55+
this.mockFixture.ProcessManager.OnCreateProcess = (command, arguments, workingDir) =>
56+
{
57+
IProcessProxy process = this.mockFixture.CreateProcess(command, arguments, workingDir);
58+
if (arguments?.Contains("s_time") == true)
59+
{
60+
return process;
61+
}
62+
63+
return process;
64+
};
65+
66+
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true))
67+
{
68+
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None);
69+
WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "openssl");
70+
WorkloadAssert.CommandsExecuted(this.mockFixture, expectedCommands.ToArray());
71+
}
72+
}
73+
}
74+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace VirtualClient.Actions
5+
{
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Linq;
9+
using System.Net;
10+
using System.Runtime.InteropServices;
11+
using System.Text;
12+
using System.Threading;
13+
using System.Threading.Tasks;
14+
using AutoFixture;
15+
using Moq;
16+
using NUnit.Framework;
17+
using VirtualClient.Common;
18+
using VirtualClient.Contracts;
19+
20+
[TestFixture]
21+
[Category("Functional")]
22+
public class TlsOpenSslServerProfileTests
23+
{
24+
private DependencyFixture mockFixture;
25+
26+
[SetUp]
27+
public void SetupFixture()
28+
{
29+
this.mockFixture = new DependencyFixture();
30+
this.mockFixture
31+
.Setup(PlatformID.Unix, Architecture.X64, "Server01")
32+
.SetupLayout(
33+
new ClientInstance("Client01", "1.2.3.4", "Client"),
34+
new ClientInstance("Server01", "1.2.3.5", "Server"));
35+
36+
ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
37+
}
38+
39+
[Test]
40+
[TestCase("Compete-OPENSSL-TLS.json")]
41+
public async Task TlsOpenSslServerWorkloadProfileInstallsTheExpectedDependenciesOnUnixPlatform(string profile)
42+
{
43+
// Setup the expectations for the workload
44+
// - Workload package is installed and exists.
45+
IPAddress.TryParse("1.2.3.5", out IPAddress ipAddress);
46+
IApiClient apiClient = this.mockFixture.ApiClientManager.GetOrCreateApiClient("1.2.3.5", ipAddress);
47+
48+
State state = new State();
49+
50+
await apiClient.CreateStateAsync(nameof(State), state, CancellationToken.None);
51+
52+
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies, dependenciesOnly: true))
53+
{
54+
await executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None).ConfigureAwait(false);
55+
56+
// Workload dependency package expectations
57+
// The workload dependency package should have been installed at this point.
58+
WorkloadAssert.WorkloadPackageInstalled(this.mockFixture, "openssl");
59+
}
60+
}
61+
62+
[Test]
63+
[TestCase("Compete-OPENSSL-TLS.json")]
64+
public void TlsOpenSslServerWorkloadProfileActionsWillNotBeExecutedIfTheWorkloadPackageDoesNotExist(string profile)
65+
{
66+
// We ensure the workload package does not exist.
67+
this.mockFixture.PackageManager.Clear();
68+
69+
using (ProfileExecutor executor = TestDependencies.CreateProfileExecutor(profile, this.mockFixture.Dependencies))
70+
{
71+
executor.ExecuteDependencies = false;
72+
73+
DependencyException error = Assert.ThrowsAsync<DependencyException>(() => executor.ExecuteAsync(ProfileTiming.OneIteration(), CancellationToken.None));
74+
Assert.AreEqual(ErrorReason.WorkloadDependencyMissing, error.Reason);
75+
Assert.IsFalse(this.mockFixture.ProcessManager.Commands.Contains("openssl s_server"));
76+
}
77+
}
78+
}
79+
}
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace VirtualClient.Actions
5+
{
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Net;
11+
using System.Runtime.InteropServices;
12+
using System.Threading;
13+
using System.Threading.Tasks;
14+
using VirtualClient.Common;
15+
using Moq;
16+
using NUnit.Framework;
17+
using VirtualClient.Actions.Properties;
18+
using VirtualClient.Common.Telemetry;
19+
using VirtualClient.Contracts;
20+
21+
[TestFixture]
22+
[Category("Unit")]
23+
public class TlsOpenSslClientExecutorTests
24+
{
25+
private DependencyFixture fixture;
26+
private DependencyPath mockPackage;
27+
28+
[Test]
29+
[TestCase(PlatformID.Unix, Architecture.X64, "linux-x64/bin/openssl")]
30+
[TestCase(PlatformID.Unix, Architecture.Arm64, "linux-arm64/bin/openssl")]
31+
public async Task Constructor_InitializesDependenciesAndPolicies(PlatformID platform, Architecture architecture, string binaryPath)
32+
{
33+
SetupEnvironment(platform, architecture);
34+
using (TestOpenSslClientExecutor executor = new TestOpenSslClientExecutor(this.fixture, this.fixture.Parameters))
35+
{
36+
37+
Assert.IsNotNull(executor);
38+
Assert.IsNull(executor.ExecutablePath);
39+
40+
await executor.InitializeAsync(EventContext.None, CancellationToken.None)
41+
.ConfigureAwait(false);
42+
43+
DependencyPath expectedWorkloadPackage = this.fixture.PlatformSpecifics.ToPlatformSpecificPath(this.mockPackage, platform, architecture);
44+
Assert.IsTrue(expectedWorkloadPackage.Equals(executor.Package));
45+
46+
47+
string expectedWorkloadExecutablePath = Path.Combine(this.mockPackage.Path, binaryPath);
48+
Assert.IsTrue(PlatformAgnosticPathComparer.Instance.Equals(expectedWorkloadExecutablePath, executor.ExecutablePath));
49+
}
50+
}
51+
52+
[Test]
53+
[TestCase(PlatformID.Unix, Architecture.X64)]
54+
[TestCase(PlatformID.Unix, Architecture.Arm64)]
55+
public void Properties_ReturnExpectedValues(PlatformID platform, Architecture architecture)
56+
{
57+
SetupEnvironment(platform, architecture);
58+
var executor = new TlsOpenSslClientExecutor(this.fixture.Dependencies, this.fixture.Parameters);
59+
60+
Assert.IsNotNull(executor);
61+
Assert.AreEqual(2, executor.ClientInstances);
62+
Assert.AreEqual(443, executor.ServerPort);
63+
Assert.IsTrue(executor.WarmUp);
64+
Assert.IsNotNull(executor.Parameters);
65+
}
66+
67+
68+
[Test]
69+
public void CaptureMetrics_LogsMetricsOnSuccess()
70+
{
71+
SetupEnvironment(PlatformID.Unix, Architecture.X64);
72+
var executor = new TlsOpenSslClientExecutor(this.fixture.Dependencies, this.fixture.Parameters);
73+
Assert.IsNotNull(executor);
74+
var process = this.fixture.CreateProcess("openssl", "s_time ...", "/tmp");
75+
process.ExitCode = 0;
76+
process.StandardOutput.Append(TestResources.Results_OpenSSL_stime);
77+
78+
var method = typeof(TlsOpenSslClientExecutor).GetMethod("CaptureMetrics", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
79+
80+
// Should not throw
81+
Assert.DoesNotThrow(() =>
82+
{
83+
method.Invoke(executor, new object[] { process, "s_time ...", EventContext.None, CancellationToken.None });
84+
});
85+
}
86+
87+
private void SetupEnvironment(PlatformID platform = PlatformID.Unix, Architecture architecture = Architecture.X64)
88+
{
89+
// Setup the default behaviors given all expected dependencies are in place such that the
90+
// workload can be executed successfully.
91+
this.fixture = new DependencyFixture();
92+
this.fixture.Setup(platform, architecture);
93+
this.fixture
94+
.Setup(platform, architecture, "Client01")
95+
.SetupLayout(
96+
new ClientInstance("Client01", "1.2.3.4", "Client"),
97+
new ClientInstance("Server01", "1.2.3.5", "Server"));
98+
99+
// ComponentTypeCache.Instance.LoadComponentTypes(TestDependencies.TestDirectory);
100+
101+
this.fixture.SetupPackage(
102+
"OpenSSL",
103+
expectedFiles: $"{PlatformSpecifics.GetPlatformArchitectureName(platform, architecture)}/bin/openssl");
104+
105+
this.mockPackage = this.fixture.PackageManager.First(pkg => pkg.Name == "OpenSSL");
106+
107+
this.fixture.Parameters = new Dictionary<string, IConvertible>
108+
{
109+
{ "ClientInstances", 2 },
110+
{ "ServerPort", 443 },
111+
{ "WarmUp", true },
112+
{ "CommandArguments", "s_time -connect :443 -www /test_1k.html -time 30 -ciphersuites TLS_AES_256_GCM_SHA384 -tls1_3" },
113+
{ "Scenario", "OpenSSL_TLS_Client_AES_256_GCM_SHA384_1k" },
114+
{ "MetricScenario", "tls_client_aes-256-gcm-sha384-1k" },
115+
{ "PackageName", "OpenSSL" },
116+
{ "Tags", "CPU,OpenSSL,Cryptography" },
117+
{ "Role", "Client" }
118+
};
119+
this.fixture.ProcessManager.OnProcessCreated = (process) =>
120+
{
121+
// When we start the OpenSSL process we want to register a successful
122+
// result.
123+
if (process.IsMatch("openssl s_time"))
124+
{
125+
process.StandardOutput.Append(TestResources.Results_OpenSSL_stime);
126+
}
127+
};
128+
}
129+
private class TestOpenSslClientExecutor : TlsOpenSslClientExecutor
130+
{
131+
public TestOpenSslClientExecutor(DependencyFixture mockFixture, IDictionary<string, IConvertible> parameters)
132+
: base(mockFixture.Dependencies, parameters)
133+
{
134+
}
135+
136+
public new DependencyPath Package
137+
{
138+
get
139+
{
140+
return base.Package;
141+
}
142+
}
143+
144+
public new Task ExecuteAsync(EventContext telemetryContext, CancellationToken cancellationToken)
145+
{
146+
return base.ExecuteAsync(telemetryContext, cancellationToken);
147+
}
148+
149+
public new Task InitializeAsync(EventContext telemetryContext, CancellationToken cancellationToken)
150+
{
151+
return base.InitializeAsync(telemetryContext, cancellationToken);
152+
}
153+
public IApiClient MockApiClient
154+
{
155+
get
156+
{
157+
return base.ApiClient;
158+
}
159+
}
160+
}
161+
}
162+
}

src/VirtualClient/VirtualClient.Actions.UnitTests/Properties/TestResources.Designer.cs

Lines changed: 22 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/VirtualClient/VirtualClient.Actions.UnitTests/Properties/TestResources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120120
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
121+
<data name="Results_OpenSSL_stime" type="System.Resources.ResXFileRef, System.Windows.Forms">
122+
<value>..\Resources\Results-OpenSSL-stime.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
123+
</data>
121124
<data name="Results_DiskSpd_Text" type="System.Resources.ResXFileRef, System.Windows.Forms">
122125
<value>..\Resources\Results_DiskSpd_Text.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252</value>
123126
</data>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Collecting connection statistics for 5 seconds
2+
*****************
3+
4+
17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
5+
17 connections in 6 real seconds, 536870956 bytes read per connection
6+
7+
8+
Now timing with session id reuse.
9+
starting
10+
rrrrrrrrrrrrrrrrr
11+
12+
17 connections in 1.54s; 11.04 connections/user sec, bytes read 9126806252
13+
17 connections in 6 real seconds, 536870956 bytes read per connection

0 commit comments

Comments
 (0)