static SecurityContext AuthenticateClient(TransportClient client) { TransportStream stream = client.GetStream(); byte[] clientToken; byte[] serverToken; // create client context SecurityContext clientContext = authModule.CreateSecurityContext(clientCredentials, SecurityContextAttributes.Identify, null, out clientToken); while (true) { if (clientToken != null) { // send client token to server SendBuffer(stream, clientToken); } if (clientContext.State == SecurityContextState.Completed) { // authentication completed break; } // receive server token serverToken = ReceiveBuffer(stream); // update security context authModule.UpdateSecurityContext(clientContext, SecurityContextAttributes.Identify, serverToken, out clientToken); } return(clientContext); }
private string SendSspiAuthentication() { try { // initialize network transport TransportClient client = new TransportClient(this.Repository.CvsRoot.ToString(), typeof(CvsTransport)); this.SetInputStream(new CvsStream(client.GetStream())); this.SetOutputStream(this.InputStream); this.OutputStream.SendString("BEGIN SSPI\n"); string[] names = System.Enum.GetNames(typeof(EncryptionType)); string protocols = string.Empty; for (int i = 0; i < names.Length; i++) { protocols += names[i]; if (i + 1 < names.Length) { protocols += ","; } } this.OutputStream.SendString(string.Format("{0}\n", protocols)); string authTypeResponse = this.InputStream.ReadLine(); CurrentEncryptionType = (EncryptionType) System.Enum.Parse(typeof(EncryptionType), authTypeResponse); // initialize authorization module authModule = new NTAuthModule(new SecurityPackage(CurrentEncryptionType.ToString())); // acquire client credentials clientCredentials = authModule.AcquireSecurityCredentials(SecurityCredentialsType.OutBound, null); byte[] clientToken; byte[] serverToken; // create client context SecurityContext clientContext = authModule.CreateSecurityContext(clientCredentials, SecurityContextAttributes.Identify, null, out clientToken); while (true) { if (clientToken != null) { // send client token to server string clientTokenString = Encoding.ASCII.GetString(clientToken, 54, 57); this.OutputStream.SendString( clientTokenString); } if (clientContext.State == SecurityContextState.Completed) { // authentication completed break; } // receive server token serverToken = Encoding.ASCII.GetBytes(this.InputStream.ReadToFirstWS()); // update security context authModule.UpdateSecurityContext(clientContext, SecurityContextAttributes.Identify, serverToken, out clientToken); } // AuthenticateClient(client); return(InputStream.ReadLine()); } catch (IOException e) { String msg = "Failed to read line from server. " + "It is possible that the remote server was down."; LOGGER.Error(msg, e); throw new AuthenticationException(msg); } }
private string SendSspiAuthentication () { try { // initialize network transport TransportClient client = new TransportClient(this.Repository.CvsRoot.ToString(), typeof(CvsTransport)); this.SetInputStream(new CvsStream(client.GetStream())); this.SetOutputStream(this.InputStream); this.OutputStream.SendString("BEGIN SSPI\n"); string[] names = System.Enum.GetNames(typeof(EncryptionType)); string protocols = string.Empty; for (int i = 0; i < names.Length; i++) { protocols += names[i]; if (i + 1 < names.Length) { protocols += ","; } } this.OutputStream.SendString(string.Format("{0}\n", protocols)); string authTypeResponse = this.InputStream.ReadLine(); CurrentEncryptionType = (EncryptionType) System.Enum.Parse(typeof(EncryptionType), authTypeResponse); // initialize authorization module authModule = new NTAuthModule(new SecurityPackage(CurrentEncryptionType.ToString())); // acquire client credentials clientCredentials = authModule.AcquireSecurityCredentials(SecurityCredentialsType.OutBound, null); byte[] clientToken; byte[] serverToken; // create client context SecurityContext clientContext = authModule.CreateSecurityContext(clientCredentials, SecurityContextAttributes.Identify, null, out clientToken); while (true) { if (clientToken != null) { // send client token to server string clientTokenString = Encoding.ASCII.GetString(clientToken, 54, 57); this.OutputStream.SendString( clientTokenString); } if (clientContext.State == SecurityContextState.Completed) { // authentication completed break; } // receive server token serverToken = Encoding.ASCII.GetBytes(this.InputStream.ReadToFirstWS()); // update security context authModule.UpdateSecurityContext(clientContext, SecurityContextAttributes.Identify, serverToken, out clientToken); } // AuthenticateClient(client); return InputStream.ReadLine(); } catch (IOException e) { String msg = "Failed to read line from server. " + "It is possible that the remote server was down."; LOGGER.Error (msg, e); throw new AuthenticationException (msg); } }