Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix credential caching on macOS #73577

Merged
merged 1 commit into from
Aug 9, 2022
Merged
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 @@ -34,7 +34,7 @@ public SafeDeleteSslContext(SafeFreeSslCredentials credential, SslAuthentication
{
int osStatus;

_sslContext = CreateSslContext(credential, sslAuthenticationOptions.IsServer);
_sslContext = CreateSslContext(credential, sslAuthenticationOptions);

// Make sure the class instance is associated to the session and is provided
// in the Read/Write callback connection parameter
Expand Down Expand Up @@ -129,7 +129,7 @@ public SafeDeleteSslContext(SafeFreeSslCredentials credential, SslAuthentication
}
}

private static SafeSslHandle CreateSslContext(SafeFreeSslCredentials credential, bool isServer)
private static SafeSslHandle CreateSslContext(SafeFreeSslCredentials credential, SslAuthenticationOptions sslAuthenticationOptions)
{
switch (credential.Policy)
{
Expand All @@ -145,7 +145,7 @@ private static SafeSslHandle CreateSslContext(SafeFreeSslCredentials credential,
throw new PlatformNotSupportedException(SR.Format(SR.net_encryptionpolicy_notsupported, credential.Policy));
}

SafeSslHandle sslContext = Interop.AppleCrypto.SslCreateContext(isServer ? 1 : 0);
SafeSslHandle sslContext = Interop.AppleCrypto.SslCreateContext(sslAuthenticationOptions.IsServer ? 1 : 0);

try
{
Expand All @@ -157,14 +157,14 @@ private static SafeSslHandle CreateSslContext(SafeFreeSslCredentials credential,
}

// Let None mean "system default"
if (credential.Protocols != SslProtocols.None)
if (sslAuthenticationOptions.EnabledSslProtocols != SslProtocols.None)
{
SetProtocols(sslContext, credential.Protocols);
SetProtocols(sslContext, sslAuthenticationOptions.EnabledSslProtocols);
}

if (credential.CertificateContext != null)
if (sslAuthenticationOptions.CertificateContext != null)
{
SetCertificate(sslContext, credential.CertificateContext);
SetCertificate(sslContext, sslAuthenticationOptions.CertificateContext);
}

Interop.AppleCrypto.SslBreakOnCertRequested(sslContext, true);
Expand Down Expand Up @@ -360,7 +360,6 @@ internal static void SetCertificate(SafeSslHandle sslContext, SslStreamCertifica
{
Debug.Assert(sslContext != null, "sslContext != null");


IntPtr[] ptrs = new IntPtr[context!.IntermediateCertificates!.Length + 1];

for (int i = 0; i < context.IntermediateCertificates.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,10 +791,7 @@ public async Task SslStream_UntrustedCaWithCustomTrust_OK(bool usePartialChain)
serverChain = _certificates.serverChain;
}

// TODO: line below is wrong, but it breaks on Mac, it should be
// serverOptions.ServerCertificateContext = SslStreamCertificateContext.Create(_certificates.serverCert, serverChain);
// [ActiveIssue("https://github.com/dotnet/runtime/issues/73295")]
serverOptions.ServerCertificateContext = SslStreamCertificateContext.Create(_certificates.serverCert, _certificates.serverChain);
serverOptions.ServerCertificateContext = SslStreamCertificateContext.Create(_certificates.serverCert, serverChain);

(Stream clientStream, Stream serverStream) = TestHelper.GetConnectedStreams();
using (clientStream)
Expand Down