Esempio n. 1
0
 public BinaryConnection(IChannel channel, TransportClient client)
 {
     _connectionId = Interlocked.Increment(ref _connectionCounter);
     _channel = channel;
     _transport = client.Transport;
     _bufferedStream = new BufferedStreamEx(client.GetStream());
     _reader = new BinaryReader(_bufferedStream, Encoding.UTF8);
     _writer = new BinaryWriter(_bufferedStream, Encoding.UTF8);
 }
Esempio n. 2
0
        static void Main()
        {
            Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
            Console.WriteLine("Starting client...");

            try
            {
                // initialize network transport
                TransportClient transport = new TransportClient(@"\\.\pipe\TestServer", typeof(PipeTransport));
                //TransportClient transport = new TransportClient("tcp://localhost:100", typeof(TcpTransport));
                TransportStream stream = transport.GetStream();

                Console.WriteLine("Client started, generate some requests...");

                byte[] clientRequest = Encoding.ASCII.GetBytes("Hello, world!");
                byte[] serverResponse = Encoding.ASCII.GetBytes("DocsVision ruleZZZ!");

                for (int size = 1; size <= 100; ++size)
                {
                    DateTime testStarted = DateTime.Now;
                    byte[] clientData = new byte[1024 * size];
                    clientRequest.CopyTo(clientData, 0);

                    for (int i = 0; i < 1000; ++i)
                    {
                        // send client data
                        SendBuffer(stream, clientData);

                        // receive server data
                        byte[] serverData = ReceiveBuffer(stream);
                        Debug.Assert(IsEqualArray(serverData, serverResponse, serverResponse.Length));
                    }

                    TimeSpan testTime = DateTime.Now - testStarted;
                    Console.WriteLine("Buffer size: " + size + "kb, time: " + testTime.TotalMilliseconds/1000 + "ms");
                }

                // signal for completion
                SendBuffer(stream, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine("Hit <enter> to exit...");
            Console.ReadLine();
        }
Esempio n. 3
0
        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;
        }
Esempio n. 4
0
        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);
            }
        }