예제 #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 <BouncyCastleTlsTestResult> DoConnect(string host, int port, TlsVersion version, List <CipherSuite> cipherSuites)
        {
            _tcpClient = new TcpClient
            {
                NoDelay        = true,
                SendTimeout    = _timeOut.Milliseconds,
                ReceiveTimeout = _timeOut.Milliseconds,
            };

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

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

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

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

            _log.LogDebug("Successfully initialized session");

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

            TestTlsClient testSuiteTlsClient = new TestTlsClient(version, cipherSuites);

            _log.LogDebug("Starting TLS session");
            BouncyCastleTlsTestResult connectionResult = clientProtocol.ConnectWithResults(testSuiteTlsClient);

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

            return(connectionResult);
        }