SslStream.BeginAuthenticateAsServer gives exception



Does anyone know why I get an exception when I calll
SslStream.EndAuthenticateAsServer ?

When I use (the synchronous) AuthenticateAsServer, everything works
fine. When I use BeginAuthenticateAsServer instead, calling
EndAuthenticateAsServer gives an IOException stating "Authentication
failed because the remote party has closed the transport stream."
The inner stream of the SslStream is my own TcpStream capable of
asynchronous tcp transport. The TcpStream itself has been tested
thoroughly and works correctly. I don't close or disconnect anything
myself, so it must be the SslStream that closes the stream, assuming
the error message is correct.

A bit of code:

secureStream = new SslStream (tcpStream, true,
this.ClientAuthenticationCallback);

#if ASYNC_SERVER_AUTHENTICATION
// todo: find out why the asynchronous version won't work.
secureStream.BeginAuthenticateAsServer (this.serverCertificate, true,
System.Security.Authentication.SslProtocols.Tls, true,
this.AuthenticateAsServerCallback, secureStream);
#else
secureStream.AuthenticateAsServer (this.serverCertificate, true,
System.Security.Authentication.SslProtocols.Tls, true);
#endif

private bool ClientAuthenticationCallback (object inSender,
X509Certificate inClientCertificate, X509Chain inChain, SslPolicyErrors
inSslPolicyErrors)
{
if (inSslPolicyErrors == SslPolicyErrors.None)
{
return true;
}
else
{
return false;
}
}

private void AuthenticateAsServerCallback (IAsyncResult inResult)
{
SslStream secureStream = (SslStream) inResult.AsyncState;

try
{
secureStream.EndAuthenticateAsServer (inResult);
}
catch (Exception exception)
{
// ... this is where I get the exception
}
}

.



Relevant Pages

  • .NET 2.0 and SslStream authentication
    ... Could someone point me a tutorial on using SslStream? ... (ClientAuthenticate or ServerAuthenticate), I get an exception ... Invoke one of Authenticate overload ... exception (Win32Exception: ...
    (microsoft.public.dotnet.security)
  • .NET 2.0 and SslStream authentication
    ... Could someone point me a tutorial on using SslStream? ... (ClientAuthenticate or ServerAuthenticate), I get an exception ... Invoke one of Authenticate overload ... exception (Win32Exception: ...
    (microsoft.public.dotnet.security)
  • Re: SSLStream
    ... I have problem with SSLStream. ... I'm using it with p12 certificate and it ... and a got exception: "The server mode SSL must use a certificate with the ... private void ProcessClient{ ...
    (microsoft.public.dotnet.languages.csharp)
  • SSLStream
    ... I have problem with SSLStream. ... I'm using it with p12 certificate and it ... a got exception: "The server mode SSL must use a certificate with the ... private void ProcessClient{ ...
    (microsoft.public.dotnet.languages.csharp)