locked
A call to SSPI failed, see inner exception - The Local Security Authority cannot be contacted RRS feed

  • 问题

  • Hi Gurus,
    I am having some serious troubles understanding and finding a way around this problem I am having. I will post the exception a bit later, first I want to explain what I am trying to do.
    I am trying to understand SSL communication using C#.
    I created a certificate using makecert.exe tool, here is the code

    makecert -r -pe -n "CN=SslTestCert" -ss my serverCert.cer -sr localMachine

    Then I got some sample code from internet and am trying to work. Code has 2 components a Server and a client.
    I used the following code to load the certificate on server

      
    string certPath = System.Reflection.Assembly.GetEntryAssembly().Location;<br>&nbsp; Console.WriteLine("Location:" + certPath);<br>&nbsp; certPath = Path.GetDirectoryName(certPath); 
    <br>&nbsp; certPath = Path.Combine(certPath, "serverCert.cer"); 
    <br>&nbsp;  
    Console.WriteLine("Loading Server Cert From: " + certPath);<br>&nbsp;  
    X509Certificate serverCert = X509Certificate.CreateFromCertFile(certPath);<br>&nbsp; Console.WriteLine("Loaded SERVER Cert From: " + certPath); 

    Now when I run server code, it starts up correctly, next step is I run the client, however as soon as that starts, I get the following exception

    System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The Local Security Authority cannot be contacted
       --- End of inner exception stack trace ---
       at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
       at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)
       at System.Net.Security.SslStream.EndAuthenticateAsServer(IAsyncResult asyncResult)
       at TestSSLStream.SecureTcpServer.OnAuthenticateAsServer(IAsyncResult result)
    in D:\development\c#\TestSSLStream\TestSSLStream\SecureTcpServer.cs:line 176
    System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets
    .SocketException: An existing connection was forcibly closed by the remote host
       at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult)
       at System.Net.Sockets.NetworkStream.EndRead(IAsyncResult asyncResult)
       --- End of inner exception stack trace ---
       at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
       at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result)

       at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
       at TestSSLStream.SecureTcpClient.OnAuthenticateAsClient(IAsyncResult result)
    in D:\development\c#\TestSSLStream\TestSSLStream\SecureTcpClient.cs:line 120


    This is code part where it triggers the exception (bold font above)

    try{
                sslStream = result.AsyncState as SslStream;
                Console.WriteLine("OnAuthenticateAsServer: is result = null:" + (result == null));
                sslStream.EndAuthenticateAsServer(result);
              //sslStream.AuthenticateAsServer(serverCert);
                this.connectionCallback(this, new SecureConnectionResults(sslStream));
            }catch (Exception ex){
                if (sslStream != null){
                    sslStream.Dispose();
                    sslStream = null;
                }
                this.connectionCallback(this, new SecureConnectionResults(ex));
            }

    I am not well verserd at all with security stuff, and will be immensely gratefull if some one could guide me through
    Thanks
    2008年9月8日 21:51

答案

全部回复