Skip to content

Commit

Permalink
Fix SslStream_StreamToStream_Alpn_NonMatchingProtocols (dotnet#33911)
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq authored Dec 8, 2018
1 parent e2e6f10 commit 1baa54e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ internal static bool DoSslHandshake(SafeSslHandle context, byte[] recvBuf, int r
{
sendBuf = null;
sendCount = 0;

if ((recvBuf != null) && (recvCount > 0))
{
if (BioWrite(context.InputBio, recvBuf, recvOffset, recvCount) <= 0)
Expand Down Expand Up @@ -403,7 +403,7 @@ private static unsafe int AlpnServerSelectCallback(IntPtr ssl, out byte* outp, o
GCHandle protocolHandle = GCHandle.FromIntPtr(arg);
if (!(protocolHandle.Target is List<SslApplicationProtocol> protocolList))
{
return Ssl.SSL_TLSEXT_ERR_NOACK;
return Ssl.SSL_TLSEXT_ERR_ALERT_FATAL;
}

try
Expand Down Expand Up @@ -432,14 +432,14 @@ private static unsafe int AlpnServerSelectCallback(IntPtr ssl, out byte* outp, o
// It is ok to clear the handle value here, this results in handshake failure, so the SslStream object is disposed.
protocolHandle.Target = null;

return Ssl.SSL_TLSEXT_ERR_NOACK;
return Ssl.SSL_TLSEXT_ERR_ALERT_FATAL;
}

// No common application protocol was negotiated, set the target on the alpnHandle to null.
// It is ok to clear the handle value here, this results in handshake failure, so the SslStream object is disposed.
protocolHandle.Target = null;

return Ssl.SSL_TLSEXT_ERR_NOACK;
return Ssl.SSL_TLSEXT_ERR_ALERT_FATAL;
}

private static int BioRead(SafeBioHandle bio, byte[] buffer, int count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ internal static partial class Ssl
{
internal const int SSL_TLSEXT_ERR_OK = 0;
internal const int OPENSSL_NPN_NEGOTIATED = 1;
internal const int SSL_TLSEXT_ERR_ALERT_FATAL = 2;
internal const int SSL_TLSEXT_ERR_NOACK = 3;

internal delegate int SslCtxSetVerifyCallback(int preverify_ok, IntPtr x509_ctx);
Expand Down

0 comments on commit 1baa54e

Please sign in to comment.