Skip to content
Merged
Prev Previous commit
Next Next commit
dispose innerContext if we don't cache
  • Loading branch information
wfurt committed Aug 16, 2021
commit 55a17700b24bbf492d7331eb02672717d9e35283
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ internal static SafeSslHandle AllocateSslHandle(SafeFreeSslCredentials credentia
}
finally
{
if (innerContext != null && cacheSslContext)
if (innerContext != null)
{
// We allocated new context
if (sslAuthenticationOptions.CertificateContext?.SslContexts == null ||
// We allocated new context and we want to cache
if (!cacheSslContext || sslAuthenticationOptions.CertificateContext?.SslContexts == null ||
!sslAuthenticationOptions.CertificateContext.SslContexts.TryAdd(sslAuthenticationOptions.EnabledSslProtocols, innerContext))
{
innerContext.Dispose();
Copy link
Member

Choose a reason for hiding this comment

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

In the event that we're not caching, what happens here? Seems like we'll have created an SSL_CTX, from that we created an SSL, then without doing anything yet we call dispose on the SSL_CTX handle, which might call SSL_shutdown.

I feel like I must be missing something.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think disposing the context would call SSL_shutdown. It does not have data to do so and it would only call Interop.Ssl.SslCtxDestroy().

We already do that 100% in existing code:

internal static SafeSslHandle AllocateSslContext(SslProtocols protocols, SafeX509Handle? certHandle, SafeEvpPKeyHandle? certKeyHandle, EncryptionPolicy policy, SslAuthenticationOptions sslAuthenticationOptions)
{
SafeSslHandle? context = null;
// Always use SSLv23_method, regardless of protocols. It supports negotiating to the highest
// mutually supported version and can thus handle any of the set protocols, and we then use
// SetProtocolOptions to ensure we only allow the ones requested.
using (SafeSslContextHandle innerContext = Ssl.SslCtxCreate(Ssl.SslMethods.SSLv23_method))

This logic is there to skip it if we put the context to cache.

Expand Down