Provides secure client connections for TCP network services.
Пример #1
0
        public void Connect(string hostname, int port, bool ssl)
        {
            try {
            Host = hostname;
            Port = port;
            Ssl = ssl;

            var protocol = ssl ? SecureProtocol.Tls1 | SecureProtocol.Ssl3 : SecureProtocol.None;
            SecurityOptions options = new SecurityOptions(protocol);
            options.Certificate = null;
            options.Entity = ConnectionEnd.Client;
            options.CommonName = hostname;
            options.VerificationType = CredentialVerification.Auto;
            options.Flags = SecurityFlags.Default;
            options.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS;

            //_Connection = new TcpClient(hostname, port);
            _Connection = new SecureTcpClient(hostname, port, options);
            _Stream = _Connection.GetStream();

            _Reader = new StreamReader(_Stream, System.Text.Encoding.Default);
            string info = _Reader.ReadLine();
            OnConnected(info);

            IsConnected = true;
            Host = hostname;
              } catch (Exception) {
            IsConnected = false;
            throw;
              }
        }
 /// <summary>
 /// Create a new SecureTcpClient based on an existing one.
 /// </summary>
 /// <param name="client">The SecureTcpClient to copy from.</param>
 public SecureTcpClient(SecureTcpClient client) : base()
 {
     m_Client     = client.Client;
     m_Active     = client.Active;
     m_CleanedUp  = client.CleanedUp;
     m_DataStream = client.DataStream;
 }
Пример #3
0
		/// <summary>
		/// Opens the stream
		/// </summary>
		public override void Open()
		{
			SecurityOptions opts = null;
			if(secured)
			{
				opts = new SecurityOptions(SecureProtocol.Tls1);
				opts.Protocol = SecureProtocol.Tls1;
				opts.Certificate = null;
				opts.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS;
				opts.VerificationType = CredentialVerification.Manual;
				opts.Verifier = new CertVerifyEventHandler(stream_OnCertVerify);
				opts.Flags = SecurityFlags.Default;
			}
			else 
			{
				opts = new SecurityOptions(SecureProtocol.None);
			}
			SecureTcpClient cli = new SecureTcpClient(hostname, port, opts);
			stream = cli.GetStream();
		}
Пример #4
0
        public void Dispose()
        {
            try {
            OnDispose();
              } catch (Exception) { }

              Disconnect();

              IsDisposed = true;
              _Stream = null;
              _Reader = null;
              _Connection = null;
        }
Пример #5
0
 /// <summary> 
 /// Create a new SecureTcpClient based on an existing one.
 /// </summary>
 /// <param name="client">The SecureTcpClient to copy from.</param>
 public SecureTcpClient(SecureTcpClient client)
     : base()
 {
     m_Client = client.Client;
     m_Active = client.Active;
     m_CleanedUp = client.CleanedUp;
     m_DataStream = client.DataStream;
 }
Пример #6
0
 /// <summary><see cref="Ch.Elca.Iiop.ITranport.CloseConnection/></summary>
 public void CloseConnection() {
     try {
         if (m_socket != null) {
             m_socket.Close();
         }
     } catch {
         // ignore
     }
     m_socket = null;
     try {
         if(m_stream != null) {
             m_stream.Close(); // close the stream and the socket.
         }
     } catch {
         // ignore
     }
     m_stream = null;
 }
Пример #7
0
 public SslServerTransport(SecureTcpClient theClient) {
     m_socket = theClient;
     m_stream = m_socket.GetStream();
 }
Пример #8
0
 /// <summary><see cref="Ch.Elca.Iiop.IClientTranport.OpenConnection/></summary>
 public void OpenConnection() {
     if (IsConnectionOpen()) {
         return; // already open
     }
     m_socket = new SecureTcpClient(m_options);
     if (m_targetHostIp != null) {
         m_socket.Connect(m_targetHostIp, m_port);
     } else if (m_targetHost != null) {
         m_socket.Connect(m_targetHost, m_port);
     } else {
         throw new INTERNAL(547, CompletionStatus.Completed_No);
     }
     m_socket.NoDelay = true; // send immediately; (TODO: what is better here?)
     m_socket.ReceiveTimeout = m_receiveTimeOut;
     m_socket.SendTimeout = m_sendTimeOut;
     m_stream = m_socket.GetStream();
 }
Пример #9
0
        private void ConnectClient( SecureProtocol protocol )
        {
            lock ( this )
            {
                if( connected )
                {
                    throw new Exception("Connection with IRC server already opened.");
                }
                Debug.WriteLineIf( Rfc2812Util.IrcTrace.TraceInfo,"[" + Thread.CurrentThread.Name +"] Connection::Connect()");

                    SecurityOptions options = new SecurityOptions( protocol );
                    options.Certificate = null;
                    options.Entity = ConnectionEnd.Client;
                    options.VerificationType = CredentialVerification.None;
                    options.Flags = SecurityFlags.Default;
                    options.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS;
                    client = new SecureTcpClient( options );
                    client.Connect( connectionArgs.Hostname, connectionArgs.Port );

                connected = true;
                writer = new StreamWriter( client.GetStream(), TextEncoding );
                writer.AutoFlush = true;
                reader = new StreamReader(  client.GetStream(), TextEncoding );
                socketListenThread = new Thread(new ThreadStart( ReceiveIRCMessages ) );
                socketListenThread.Name = Name;
                socketListenThread.Start();
                sender.RegisterConnection( connectionArgs );
            }
        }