Exemplo n.º 1
0
        public async Task StartServerAsync()
        {
            var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);

            //var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, "f864d23e92894c56df566b7ab7a9c6411d50d14d", false);
            var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, "3fd0b5f28dc32f5f0bb9f44cf1f6816846e44cbe", false);
            
            if (certificates.Count == 0)
            {
                throw new InvalidOperationException("Server certificate not found");
            }

            store.Close();
#if DEBUG
            ITraceWriter traceWriter = new DebugTraceWriter("Server"); 
#else
            ITraceWriter traceWriter = new FileTraceWriter("server.log"); 
#endif

            _listener = new TcpTransportListener(
                _listenerUri,
                certificates[0],
                new EnvelopeSerializer(),
                traceWriter
                );


            await _listener.StartAsync();
        }
Exemplo n.º 2
0
        public async Task StartServerAsync()
        {
            var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

            store.Open(OpenFlags.ReadOnly);

            //var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, "f864d23e92894c56df566b7ab7a9c6411d50d14d", false);
            var certificates = store.Certificates.Find(X509FindType.FindByThumbprint, "3fd0b5f28dc32f5f0bb9f44cf1f6816846e44cbe", false);

            if (certificates.Count == 0)
            {
                throw new InvalidOperationException("Server certificate not found");
            }

            store.Close();
#if DEBUG
            ITraceWriter traceWriter = new DebugTraceWriter("Server");
#else
            ITraceWriter traceWriter = new FileTraceWriter("server.log");
#endif

            _listener = new TcpTransportListener(
                _listenerUri,
                certificates[0],
                new EnvelopeSerializer(),
                traceWriter
                );


            await _listener.StartAsync();
        }
Exemplo n.º 3
0
        public async Task <bool> ConnectAsGuestAsync(string domain, CancellationToken cancellationToken)
        {
            var tcpClient = new TcpClient();

#if DEBUG
            ITraceWriter traceWriter = new DebugTraceWriter("Client");
#else
            ITraceWriter traceWriter = new FileTraceWriter("client.log");
#endif

            var transport = new TcpTransport(
                new TcpClientAdapter(tcpClient),
                new EnvelopeSerializer(),
                hostName: _clientUri.Host,
                traceWriter: traceWriter
                );

            Channel = new ClientChannel(transport, TimeSpan.FromSeconds(60), autoReplyPings: true, autoNotifyReceipt: true);

            await Channel.Transport.OpenAsync(_clientUri, cancellationToken);

            var identity = new Identity()
            {
                Name   = Guid.NewGuid().ToString(),
                Domain = domain
            };

            var resultSession = await Channel.EstablishSessionAsync(
                c => c.First(),
                e => SessionEncryption.TLS,
                identity,
                (s, r) => new GuestAuthentication(),
                Environment.MachineName,
                cancellationToken);

            if (resultSession.State != SessionState.Established)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public async Task<bool> ConnectAsGuestAsync(string domain, CancellationToken cancellationToken)
        {
            var tcpClient = new TcpClient();

#if DEBUG
            ITraceWriter traceWriter = new DebugTraceWriter("Client");
#else
            ITraceWriter traceWriter = new FileTraceWriter("client.log");
#endif

            var transport = new TcpTransport(
                new TcpClientAdapter(tcpClient),
                new EnvelopeSerializer(),
                hostName: _clientUri.Host,
                traceWriter: traceWriter
                );

            Channel = new ClientChannel(transport, TimeSpan.FromSeconds(60), autoReplyPings: true, autoNotifyReceipt: true);

            await Channel.Transport.OpenAsync(_clientUri, cancellationToken);

            var identity = new Identity()
            {
                Name = Guid.NewGuid().ToString(),
                Domain = domain
            };

            var resultSession = await Channel.EstablishSessionAsync(
                c => c.First(),
                e => SessionEncryption.TLS,
                identity,
                (s, r) => new GuestAuthentication(),
                Environment.MachineName,
                cancellationToken);

            if (resultSession.State != SessionState.Established)
            {
                return false;
            }

            return true;
        }
Exemplo n.º 5
0
        public async Task <bool> ConnectWithPasswordAsync(Identity identity, string password, CancellationToken cancellationToken)
        {
            var tcpClient = new TcpClient();

#if DEBUG
            ITraceWriter traceWriter = new DebugTraceWriter("Client");
#else
            ITraceWriter traceWriter = new FileTraceWriter("client.log");
#endif

            var transport = new TcpTransport(
                new TcpClientAdapter(tcpClient),
                new EnvelopeSerializer(),
                hostName: _clientUri.Host,
                traceWriter: traceWriter
                );

            Channel = new ClientChannel(transport, TimeSpan.FromSeconds(60), autoReplyPings: true, autoNotifyReceipt: true);

            await Channel.Transport.OpenAsync(_clientUri, cancellationToken);

            var resultSession = await Channel.EstablishSessionAsync(
                c => c.First(),
                e => SessionEncryption.TLS,
                identity,
                (s, r) => { var auth = new PlainAuthentication(); auth.SetToBase64Password(password); return(auth); },
                Environment.MachineName,
                cancellationToken);

            if (resultSession.State != SessionState.Established)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 6
0
        public async Task<bool> ConnectWithPasswordAsync(Identity identity, string password, CancellationToken cancellationToken)
        {
            var tcpClient = new TcpClient();

#if DEBUG
            ITraceWriter traceWriter = new DebugTraceWriter("Client"); 
#else
            ITraceWriter traceWriter = new FileTraceWriter("client.log");
#endif

            var transport = new TcpTransport(
                new TcpClientAdapter(tcpClient),
                new EnvelopeSerializer(),                
                hostName: _clientUri.Host,
                traceWriter: traceWriter
                );

            Channel = new ClientChannel(transport, TimeSpan.FromSeconds(60), autoReplyPings: true, autoNotifyReceipt: true);
            
            await Channel.Transport.OpenAsync(_clientUri, cancellationToken);

            var resultSession = await Channel.EstablishSessionAsync(
                c => c.First(),
                e => SessionEncryption.TLS,
                identity,
                (s, r) => { var auth = new PlainAuthentication(); auth.SetToBase64Password(password); return auth; },
                Environment.MachineName,
                cancellationToken);

            if (resultSession.State != SessionState.Established)            
            {
                return false;
            }

            return true;
        }