コード例 #1
0
        public async Task Connect(string host, int port)
        {
            _tcpClient = new TcpClient();

            await _tcpClient.ConnectAsync(host, port).ConfigureAwait(false);

            StartTlsResult sessionInitialized = await TryInitializeSession(_tcpClient.GetStream()).ConfigureAwait(false);

            if (!sessionInitialized.Success)
            {
                throw new Exception("Failed to initialize session.");
            }

            TlsClientProtocol clientProtocol = new TlsClientProtocol(_tcpClient.GetStream(), SecureRandom.GetInstance("SHA256PRNG"));

            clientProtocol.Connect(new BasicTlsClient());
        }
コード例 #2
0
        private async Task <TlsConnectionResult> DoConnect(string host, int port, TlsVersion version, List <CipherSuite> cipherSuites)
        {
            _tcpClient = new TcpClient
            {
                NoDelay        = true,
                SendTimeout    = _timeOut.Milliseconds,
                ReceiveTimeout = _timeOut.Milliseconds,
            };

            _log.Debug($"Starting TCP connection to {host ?? "<null>"}:{port}");
            await _tcpClient.ConnectAsync(host, port).ConfigureAwait(false);

            _log.Debug($"Successfully started TCP connection to {host ?? "<null>"}:{port}");

            _log.Debug("Initializing session");
            StartTlsResult sessionInitialized = await TryInitializeSession(_tcpClient.GetStream()).ConfigureAwait(false);

            _log.Debug("Successfully initialized session");

            if (!sessionInitialized.Success)
            {
                _log.Debug("Failed to initialize session");
                return(new TlsConnectionResult(Error.SESSION_INITIALIZATION_FAILED, sessionInitialized.Error, sessionInitialized.SmtpSession));
            }

            TestTlsClientProtocol clientProtocol = new TestTlsClientProtocol(_tcpClient.GetStream());

            TestTlsClient testSuiteTlsClient = new TestTlsClient(version, cipherSuites);

            _log.Debug("Starting TLS session");
            TlsConnectionResult connectionResult = clientProtocol.ConnectWithResults(testSuiteTlsClient);

            _log.Debug("Successfully started TLS session");

            return(connectionResult);
        }