Skip to content

Commit c05e9d1

Browse files
vcsjoneswfurtrzikmbartonjs
authored
Update System.Net.* unit tests to react to SYSLIB0057 obsoletion (#104487)
* Update System.Net.* to react to SYSLIB0057 obsoletion * react to changes in System.Net.WebSockets.Client.Wasm.Tests.csproj --------- Co-authored-by: Tomas Weinfurt <tweinfurt@yahoo.com> Co-authored-by: Radek Zikmund <r.zikmund.rz@gmail.com> Co-authored-by: Jeremy Barton <jbarton@microsoft.com> Co-authored-by: Radek Zikmund <32671551+rzikm@users.noreply.github.com>
1 parent d756692 commit c05e9d1

File tree

22 files changed

+28
-30
lines changed

22 files changed

+28
-30
lines changed

src/libraries/Common/tests/System/Net/Configuration.Certificates.Dynamic.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static (X509Certificate2 certificate, X509Certificate2Collection) Generat
163163
if (!ephemeralKey && PlatformDetection.IsWindows)
164164
{
165165
X509Certificate2 ephemeral = endEntity;
166-
endEntity = new X509Certificate2(endEntity.Export(X509ContentType.Pfx), (string?)null, X509KeyStorageFlags.Exportable);
166+
endEntity = X509CertificateLoader.LoadPkcs12(endEntity.Export(X509ContentType.Pfx), (string?)null, X509KeyStorageFlags.Exportable);
167167
ephemeral.Dispose();
168168
}
169169

src/libraries/Common/tests/System/Net/Configuration.Certificates.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ static Certificates()
4747
Assert.True(mutex?.WaitOne(MutexTimeoutMs) ?? true, "Could not acquire the global certificate mutex.");
4848
try
4949
{
50-
s_serverCertificate = new X509Certificate2(serverCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
51-
s_clientCertificate = new X509Certificate2(clientCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
52-
s_noEKUCertificate = new X509Certificate2(noEKUCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
53-
s_selfSignedServerCertificate = new X509Certificate2(selfSignedServerCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
54-
s_selfSignedClientCertificate = new X509Certificate2(selfSignedClientCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
50+
s_serverCertificate = X509CertificateLoader.LoadPkcs12(serverCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
51+
s_clientCertificate = X509CertificateLoader.LoadPkcs12(clientCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
52+
s_noEKUCertificate = X509CertificateLoader.LoadPkcs12(noEKUCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
53+
s_selfSignedServerCertificate = X509CertificateLoader.LoadPkcs12(selfSignedServerCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
54+
s_selfSignedClientCertificate = X509CertificateLoader.LoadPkcs12(selfSignedClientCertificateBytes, CertificatePassword, X509KeyStorageFlags.Exportable);
5555
}
5656
finally { mutex?.ReleaseMutex(); }
5757
}
@@ -91,7 +91,7 @@ public static X509Certificate2 GetSelfSigned13ServerCertificate()
9191
{
9292
using (innerCert)
9393
{
94-
cert = new X509Certificate2(innerCert.Export(X509ContentType.Pfx));
94+
cert = X509CertificateLoader.LoadPkcs12(innerCert.Export(X509ContentType.Pfx), (string?)null);
9595
}
9696
}
9797
else

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.ClientCertificates.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
115115
{
116116
_output.WriteLine(
117117
"Client cert: {0}",
118-
new X509Certificate2(sslStream.RemoteCertificate.Export(X509ContentType.Cert)).GetNameInfo(X509NameType.SimpleName, false));
118+
X509CertificateLoader.LoadCertificate(sslStream.RemoteCertificate.Export(X509ContentType.Cert)).GetNameInfo(X509NameType.SimpleName, false));
119119
Assert.Equal(cert, sslStream.RemoteCertificate);
120120
}
121121
else
@@ -233,7 +233,7 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
233233

234234
_output.WriteLine(
235235
"Client cert: {0}",
236-
new X509Certificate2(sslStream.RemoteCertificate.Export(X509ContentType.Cert)).GetNameInfo(X509NameType.SimpleName, false));
236+
X509CertificateLoader.LoadCertificate(sslStream.RemoteCertificate.Export(X509ContentType.Cert)).GetNameInfo(X509NameType.SimpleName, false));
237237

238238
Assert.Equal(clientCertificate.GetCertHashString(), sslStream.RemoteCertificate.GetCertHashString());
239239

src/libraries/Common/tests/System/Net/Http/TestHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public static X509Certificate2 CreateServerSelfSignedCertificate(string name = "
142142
X509Certificate2 cert = req.CreateSelfSigned(start, end);
143143
if (PlatformDetection.IsWindows)
144144
{
145-
cert = new X509Certificate2(cert.Export(X509ContentType.Pfx), (string?)null);
145+
cert = X509CertificateLoader.LoadPkcs12(cert.Export(X509ContentType.Pfx), (string?)null);
146146
}
147147

148148
return cert;

src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/CertificateAuthority.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void Dispose()
126126

127127
internal X509Certificate2 CloneIssuerCert()
128128
{
129-
return new X509Certificate2(_cert.RawData);
129+
return X509CertificateLoader.LoadCertificate(_cert.RawData);
130130
}
131131

132132
internal void Revoke(X509Certificate2 certificate, DateTimeOffset revocationTime)

src/libraries/Common/tests/System/Security/Cryptography/X509Certificates/RevocationResponder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ private static byte[] GetCertDataForAiaResponseKind(AiaResponseKind kind, Certif
340340
}
341341
else if (kind == AiaResponseKind.Pkcs12)
342342
{
343-
using X509Certificate2 cert = new X509Certificate2(authority.GetCertData());
343+
using X509Certificate2 cert = X509CertificateLoader.LoadCertificate(authority.GetCertData());
344344
return cert.Export(X509ContentType.Pkcs12);
345345
}
346346
else

src/libraries/System.Net.Http.Json/tests/FunctionalTests/System.Net.Http.Json.Functional.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFrameworks>$(NetCoreAppCurrent);$(NetFrameworkCurrent)</TargetFrameworks>
55
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
6-
<NoWarn>$(NoWarn);SYSLIB0057</NoWarn>
76
</PropertyGroup>
87

98
<ItemGroup>
@@ -33,6 +32,7 @@
3332
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
3433
<Reference Include="System.Net.Http" />
3534
<ProjectReference Include="..\..\src\System.Net.Http.Json.csproj" />
35+
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Bcl.Cryptography\src\Microsoft.Bcl.Cryptography.csproj" />
3636
</ItemGroup>
3737

3838
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">

src/libraries/System.Net.Http.WinHttpHandler/tests/FunctionalTests/System.Net.Http.WinHttpHandler.Functional.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<IncludeRemoteExecutor>true</IncludeRemoteExecutor>
55
<DefineConstants>$(DefineConstants);WINHTTPHANDLER_TEST</DefineConstants>
66
<EnablePreviewFeatures>true</EnablePreviewFeatures>
7-
<NoWarn>$(NoWarn);SYSLIB0057</NoWarn>
87
</PropertyGroup>
98
<ItemGroup>
109
<Compile Include="$(CommonTestPath)System\Net\Configuration.cs"
@@ -155,5 +154,6 @@
155154
<Reference Include="System.DirectoryServices.Protocols" />
156155
<Reference Include="System.Net.Http" />
157156
<ProjectReference Include="$(LibrariesProjectRoot)System.Net.Http.Json\src\System.Net.Http.Json.csproj" />
157+
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Bcl.Cryptography\src\Microsoft.Bcl.Cryptography.csproj" />
158158
</ItemGroup>
159159
</Project>

src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/ClientCertificateHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests
1111
public class ClientCertificateHelper
1212
{
1313
private readonly X509Certificate2 _cert_KeyUsageIncludesDigitalSignature_EKUIncludesClientAuth_PrivateKey =
14-
new X509Certificate2(
14+
X509CertificateLoader.LoadPkcs12(
1515
Convert.FromBase64String(
1616
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Suppression approved. Unit test dummy certificate.")]
1717
@"MIIKTgIBAzCCCgoGCSqGSIb3DQEHAaCCCfsEggn3MIIJ8zCCBgwGCSqGSIb3DQEHAaCCBf0EggX5
@@ -64,7 +64,7 @@ public class ClientCertificateHelper
6464
"password");
6565

6666
private readonly X509Certificate2 _cert_KeyUsageMissingDigitalSignature_EKUIncludesClientAuth_PrivateKey =
67-
new X509Certificate2(
67+
X509CertificateLoader.LoadPkcs12(
6868
Convert.FromBase64String(
6969
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Suppression approved. Unit test dummy certificate.")]
7070
@"MIIKTgIBAzCCCgoGCSqGSIb3DQEHAaCCCfsEggn3MIIJ8zCCBgwGCSqGSIb3DQEHAaCCBf0EggX5
@@ -117,7 +117,7 @@ public class ClientCertificateHelper
117117
"password");
118118

119119
private readonly X509Certificate2 _cert_KeyUsageIncludesDigitalSignature_EKUMissingClientAuth_PrivateKey =
120-
new X509Certificate2(
120+
X509CertificateLoader.LoadPkcs12(
121121
Convert.FromBase64String(
122122
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Suppression approved. Dummy certificate for testing.")]
123123
@"MIIKRgIBAzCCCgIGCSqGSIb3DQEHAaCCCfMEggnvMIIJ6zCCBgQGCSqGSIb3DQEHAaCCBfUEggXx
@@ -170,7 +170,7 @@ public class ClientCertificateHelper
170170
"password");
171171

172172
private readonly X509Certificate2 _cert_KeyUsageIncludesDigitalSignature_NoEKU_PrivateKey =
173-
new X509Certificate2(
173+
X509CertificateLoader.LoadPkcs12(
174174
Convert.FromBase64String(
175175
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Suppression approved. Dummy certificate for testing.")]
176176
@"MIIKPgIBAzCCCfoGCSqGSIb3DQEHAaCCCesEggnnMIIJ4zCCBgwGCSqGSIb3DQEHAaCCBf0EggX5
@@ -223,7 +223,7 @@ public class ClientCertificateHelper
223223
"password");
224224

225225
private readonly X509Certificate2 _cert_KeyUsageIncludesDigitalSignature_EKUIncludesClientAuth_NoPrivateKey =
226-
new X509Certificate2(
226+
X509CertificateLoader.LoadCertificate(
227227
Convert.FromBase64String(
228228
// [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Suppression approved. Dummy certificate for testing.")]
229229
@"MIIDFjCCAf6gAwIBAgIQTm8+EF94L4FJ0nBFl5LICzANBgkqhkiG9w0BAQsFADAb

src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<NoWarn>$(NoWarn);0436;SYSLIB0057</NoWarn>
3+
<NoWarn>$(NoWarn);0436</NoWarn>
44
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
55
<StringResourcesPath>../../src/Resources/Strings.resx</StringResourcesPath>
66
<TargetFramework>$(NetCoreAppCurrent)-windows</TargetFramework>

0 commit comments

Comments
 (0)