public ProxyConnection(Stream clientStream, TivoEndPoint serverEndPoint) { this.serverEndPoint = serverEndPoint; this.clientStream = clientStream; Task.Factory.StartNew(this.ClientReceiveThreadProc, TaskCreationOptions.LongRunning); }
public async Task <Stream> Initialize(TivoEndPoint endPoint) { if (this.client != null) { throw new InvalidOperationException("Cannot call Initialize on an already connected interface"); } // Create new connection this.client = new TcpClient(); await this.client.ConnectAsync(endPoint.Address, endPoint.Port).ConfigureAwait(false); var tivoTlsClient = new TivoTlsClient(endPoint.Certificate, endPoint.Password); this.tlsProtocolHandler = new TlsProtocolHandler(this.client.GetStream()); this.tlsProtocolHandler.Connect(tivoTlsClient); return(this.tlsProtocolHandler.Stream); }
private void OnAwayClientConnected(TcpClient client) { SslStream sslStream = new SslStream(client.GetStream(), false); // Authenticate the server but don't require the client to authenticate. try { sslStream.AuthenticateAsServer(this.serverCertificate, false, SslProtocols.Default, false); TivoProxyEventSource.Log.ClientConnected( TivoConnectionMode.Away, ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString(), FormatStreamProperties(sslStream)); // Set timeouts for the read and write to 30 seconds. sslStream.ReadTimeout = 30000; sslStream.WriteTimeout = 30000; var serviceProvider = this.IsVirgin ? TivoServiceProvider.VirginMediaUK : TivoServiceProvider.TivoUSA; var serverEndPoint = TivoEndPoint.CreateAway(serviceProvider, TivoCertificateStore.Instance); var proxy = new ProxyConnection(sslStream, serverEndPoint); } //catch (AuthenticationException e) catch (Exception e) { TivoProxyEventSource.Log.ClientConnectionFailure(TivoConnectionMode.Local, e); sslStream.Close(); client.Close(); return; } finally { //// The client stream will be closed with the sslStream //// because we specified this behavior when creating //// the sslStream. //sslStream.Close(); //client.Close(); } }
public async Task <Stream> Initialize(TivoEndPoint endPoint) { if (this.streamSocket != null) { throw new InvalidOperationException("Cannot call Initialize on an open interface"); } this.streamSocket = new StreamSocket(); await this.streamSocket.ConnectAsync(new HostName(endPoint.Address), endPoint.Port.ToString(CultureInfo.InvariantCulture), SocketProtectionLevel.PlainSocket).AsTask().ConfigureAwait(false); var readStream = this.streamSocket.InputStream.AsStreamForRead(); var writeStream = this.streamSocket.OutputStream.AsStreamForWrite(); var tivoTlsClient = new TivoTlsClient(endPoint.Certificate, endPoint.Password); this.tlsProtocolHandler = new TlsProtocolHandler(readStream, writeStream); this.tlsProtocolHandler.Connect(tivoTlsClient); return(this.tlsProtocolHandler.Stream); }