Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,12 @@ public async Task SslStream_UntrustedCaWithCustomCallback_Throws(bool customCall
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/46837", TestPlatforms.OSX)]
public async Task SslStream_ClientCertificate_SendsChain()
{
List<SslStream> streams = new List<SslStream>();
TestHelper.CleanupCertificates("SslStream_ClinetCertificate_SendsChain");
(X509Certificate2 clientCertificate, X509Certificate2Collection clientChain) = TestHelper.GenerateCertificates("SslStream_ClinetCertificate_SendsChain", serverCertificate: false);
using (X509Store store = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser))
using (X509Store store = new X509Store(PlatformDetection.IsOSXLike ? StoreName.My : StoreName.CertificateAuthority, StoreLocation.CurrentUser))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a comment explaining why OSX is different?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. I will. It is primarily #48207 but there still seems to be another trickery in CI. I'm looking into it and I'll hold this back until clean CI pass.

{
// add chain certificate so we can construct chain since there is no way how to pass intermediates directly.
store.Open(OpenFlags.ReadWrite);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,38 +83,30 @@ internal static (NetworkStream ClientStream, NetworkStream ServerStream) GetConn

internal static void CleanupCertificates(string testName)
{
string caName = $"O={testName}";
try
{
using (X509Store store = new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine))
string name = $"O={testName}";
X509Store[] stores = new X509Store[]
{
store.Open(OpenFlags.ReadWrite);
foreach (X509Certificate2 cert in store.Certificates)
{
if (cert.Subject.Contains(caName))
{
store.Remove(cert);
}
}
}
}
catch { };
new X509Store(StoreName.CertificateAuthority, StoreLocation.LocalMachine),
new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser),
new X509Store(StoreName.My, StoreLocation.CurrentUser)
};

try
foreach (X509Store store in stores)
{
using (X509Store store = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser))
try
{
store.Open(OpenFlags.ReadWrite);
foreach (X509Certificate2 cert in store.Certificates)
{
if (cert.Subject.Contains(caName))
if (cert.Subject.Contains(name))
{
store.Remove(cert);
}
}
}
catch { };
store.Dispose();
}
catch { };
}

internal static (X509Certificate2 certificate, X509Certificate2Collection) GenerateCertificates(string targetName, [CallerMemberName] string? testName = null, bool longChain = false, bool serverCertificate = true)
Expand Down