Exemplo n.º 1
0
        /// <summary>
        /// Starts SSL/TLS on a connection. This can be used for old Jabber style SSL.
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task DoSslAsync(CancellationToken cancellationToken)
        {
            await Task.Run(async() =>
            {
                var tlsSettingsProvider = await TlsSettingsProvider.ProvideAsync(this);
                XmppSessionState.Value  = SessionState.Securing;
                var tlsHandler          =
                    new TlsHandler(stream
                                   => new SslStream(stream,
                                                    true,
                                                    (sender, certificate, chain, errors) => CertificateValidator.RemoteCertificateValidationCallback(sender, certificate, chain, errors)),
                                   tlsSettingsProvider);

                Pipeline.AddFirst(tlsHandler);
                XmppSessionState.Value = SessionState.Secure;
            }, cancellationToken);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle StartTls asynchronous
        /// </summary>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        private async Task <StreamFeatures> DoStartTlsAsync(CancellationToken cancellationToken)
        {
            XmppSessionState.Value = SessionState.Securing;

            var tlsSettingsProvider = await TlsSettingsProvider.ProvideAsync(this);

            var tlsHandler =
                new TlsHandler(stream
                               => new SslStream(stream,
                                                true,
                                                (sender, certificate, chain, errors) => CertificateValidator.RemoteCertificateValidationCallback(sender, certificate, chain, errors)),
                               tlsSettingsProvider);

            await SendAsync <Proceed>(new StartTls(), cancellationToken);

            Pipeline.AddFirst(tlsHandler);
            var streamFeatures = await ResetStreamAsync(cancellationToken);

            XmppSessionState.Value = SessionState.Secure;

            return(streamFeatures);
        }