Example #1
0
 public SslStream(Stream innerStream, bool leaveInnerStreamOpen)
     : base(innerStream, leaveInnerStreamOpen)
 {
     provider = GetProvider();
     settings = MonoTlsSettings.CopyDefaultSettings();
     impl     = provider.CreateSslStream(this, innerStream, leaveInnerStreamOpen, settings);
 }
        protected MobileTlsContext(MobileAuthenticatedStream parent, MonoSslAuthenticationOptions options)
        {
            Parent           = parent;
            Options          = options;
            IsServer         = options.ServerMode;
            EnabledProtocols = options.EnabledSslProtocols;

            if (options.ServerMode)
            {
                LocalServerCertificate  = options.ServerCertificate;
                AskForClientCertificate = options.ClientCertificateRequired;
            }
            else
            {
                ClientCertificates = options.ClientCertificates;
                TargetHost         = options.TargetHost;
                ServerName         = options.TargetHost;
                if (!string.IsNullOrEmpty(ServerName))
                {
                    var pos = ServerName.IndexOf(':');
                    if (pos > 0)
                    {
                        ServerName = ServerName.Substring(0, pos);
                    }
                }
            }

            certificateValidator = (ICertificateValidator2)ChainValidationHelper.GetInternalValidator(
                parent.SslStream, parent.Provider, parent.Settings);
        }
Example #3
0
        public MobileTlsContext(
            MobileAuthenticatedStream parent, bool serverMode, string targetHost,
            SslProtocols enabledProtocols, X509Certificate serverCertificate,
            X509CertificateCollection clientCertificates, bool askForClientCert)
        {
            this.parent             = parent;
            this.serverMode         = serverMode;
            this.targetHost         = targetHost;
            this.enabledProtocols   = enabledProtocols;
            this.serverCertificate  = serverCertificate;
            this.clientCertificates = clientCertificates;
            this.askForClientCert   = askForClientCert;

            serverName = targetHost;
            if (!string.IsNullOrEmpty(serverName))
            {
                var pos = serverName.IndexOf(':');
                if (pos > 0)
                {
                    serverName = serverName.Substring(0, pos);
                }
            }

            certificateValidator = CertificateValidationHelper.GetInternalValidator(
                parent.Settings, parent.Provider);
        }
Example #4
0
 internal SslStream(Stream innerStream, bool leaveInnerStreamOpen, MonoTlsProvider provider, MonoTlsSettings settings)
     : base(innerStream, leaveInnerStreamOpen)
 {
     this.provider    = (MNS.MobileTlsProvider)provider;
     this.settings    = settings.Clone();
     explicitSettings = true;
     impl             = this.provider.CreateSslStream(this, innerStream, leaveInnerStreamOpen, settings);
 }
Example #5
0
 public MonoBtlsContext(MNS.MobileAuthenticatedStream parent, MNS.MonoSslAuthenticationOptions options)
     : base(parent, options)
 {
     if (IsServer)
     {
         nativeServerCertificate = GetPrivateCertificate(LocalServerCertificate);
     }
 }
        async Task ProcessOperation(CancellationToken cancellationToken)
        {
            var status = AsyncOperationStatus.Initialize;

            while (status != AsyncOperationStatus.Complete)
            {
                cancellationToken.ThrowIfCancellationRequested();
                Debug("ProcessOperation: {0}", status);

                var ret = await InnerRead(cancellationToken).ConfigureAwait(false);

                if (ret != null)
                {
                    if (ret == 0)
                    {
                        // End-of-stream
                        Debug("END OF STREAM!");
                        status = AsyncOperationStatus.ReadDone;
                    }
                    else if (ret < 0)
                    {
                        // remote prematurely closed connection.
                        throw new IOException("Remote prematurely closed connection.");
                    }
                }

                Debug("ProcessOperation run: {0}", status);

                AsyncOperationStatus newStatus;
                switch (status)
                {
                case AsyncOperationStatus.Initialize:
                case AsyncOperationStatus.Continue:
                case AsyncOperationStatus.ReadDone:
                    try {
                        newStatus = Run(status);
                    } catch (Exception ex) {
                        // We only want to wrap exceptions that are thrown by the TLS code.
                        throw MobileAuthenticatedStream.GetSSPIException(ex);
                    }
                    break;

                default:
                    throw new InvalidOperationException();
                }

                if (Interlocked.Exchange(ref WriteRequested, 0) != 0)
                {
                    // Flush the write queue.
                    Debug("ProcessOperation - flushing write queue");
                    await Parent.InnerWrite(RunSynchronously, cancellationToken).ConfigureAwait(false);
                }

                Debug("ProcessOperation done: {0} -> {1}", status, newStatus);

                status = newStatus;
            }
        }
Example #7
0
 public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
     : base(innerStream, leaveInnerStreamOpen)
 {
     provider = GetProvider();
     settings = MonoTlsSettings.CopyDefaultSettings();
     SetAndVerifyValidationCallback(userCertificateValidationCallback);
     SetAndVerifySelectionCallback(userCertificateSelectionCallback);
     impl = provider.CreateSslStream(this, innerStream, leaveInnerStreamOpen, settings);
 }
Example #8
0
 protected override MNS.MobileTlsContext CreateContext(
     MNS.MobileAuthenticatedStream parent, bool serverMode, string targetHost,
     SslProtocols enabledProtocols, X509Certificate serverCertificate,
     X509CertificateCollection clientCertificates, bool askForClientCert)
 {
     return(new MonoBtlsContext(
                parent, serverMode, targetHost,
                enabledProtocols, serverCertificate,
                clientCertificates, askForClientCert));
 }
Example #9
0
 protected override void Dispose(bool disposing)
 {
     try {
         if (impl != null && disposing)
         {
             impl.Dispose();
             impl = null;
         }
     } finally {
         base.Dispose(disposing);
     }
 }
Example #10
0
 public MonoBtlsContext(
     MNS.MobileAuthenticatedStream parent,
     bool serverMode, string targetHost,
     SslProtocols enabledProtocols, X509Certificate serverCertificate,
     X509CertificateCollection clientCertificates, bool askForClientCert)
     : base(parent, serverMode, targetHost, enabledProtocols,
            serverCertificate, clientCertificates, askForClientCert)
 {
     if (serverMode)
     {
         nativeServerCertificate = GetPrivateCertificate(serverCertificate);
     }
 }
Example #11
0
        public SslStream(Stream innerStream, bool leaveInnerStreamOpen)
            : base(innerStream, leaveInnerStreamOpen)
        {
#if WASM
            try {
                provider = GetProvider();
            } catch (Exception ex) {
                throw new PlatformNotSupportedException("System.Net.Security.SslStream is not supported on the current platform.", ex);
            }
#else
            provider = GetProvider();
#endif
            settings = MonoTlsSettings.CopyDefaultSettings();
            impl     = provider.CreateSslStream(this, innerStream, leaveInnerStreamOpen, settings);
        }
Example #12
0
		public MobileTlsContext (
			MobileAuthenticatedStream parent, bool serverMode, string targetHost,
			SslProtocols enabledProtocols, X509Certificate serverCertificate,
			X509CertificateCollection clientCertificates, bool askForClientCert)
		{
			this.parent = parent;
			this.serverMode = serverMode;
			this.targetHost = targetHost;
			this.enabledProtocols = enabledProtocols;
			this.serverCertificate = serverCertificate;
			this.clientCertificates = clientCertificates;
			this.askForClientCert = askForClientCert;

			certificateValidator = CertificateValidationHelper.GetInternalValidator (
				parent.Settings, parent.Provider);
		}
Example #13
0
        public MobileTlsContext(
            MobileAuthenticatedStream parent, bool serverMode, string targetHost,
            SslProtocols enabledProtocols, X509Certificate serverCertificate,
            X509CertificateCollection clientCertificates, bool askForClientCert)
        {
            this.parent             = parent;
            this.serverMode         = serverMode;
            this.targetHost         = targetHost;
            this.enabledProtocols   = enabledProtocols;
            this.serverCertificate  = serverCertificate;
            this.clientCertificates = clientCertificates;
            this.askForClientCert   = askForClientCert;

            certificateValidator = CertificateValidationHelper.GetDefaultValidator(
                parent.Settings, parent.Provider);
        }
Example #14
0
        public SslStream(Stream innerStream, bool leaveInnerStreamOpen, RemoteCertificateValidationCallback userCertificateValidationCallback, LocalCertificateSelectionCallback userCertificateSelectionCallback)
            : base(innerStream, leaveInnerStreamOpen)
        {
#if WASM
            try {
                provider = GetProvider();
            } catch (Exception ex) {
                throw new PlatformNotSupportedException("System.Net.Security.SslStream is not supported on the current platform.", ex);
            }
#else
            provider = GetProvider();
#endif
            settings = MonoTlsSettings.CopyDefaultSettings();
            SetAndVerifyValidationCallback(userCertificateValidationCallback);
            SetAndVerifySelectionCallback(userCertificateSelectionCallback);
            impl = provider.CreateSslStream(this, innerStream, leaveInnerStreamOpen, settings);
        }
Example #15
0
        internal async Task <AsyncProtocolResult> StartOperation(CancellationToken cancellationToken)
        {
            Debug("Start Operation: {0}", this);
            if (Interlocked.CompareExchange(ref Started, 1, 0) != 0)
            {
                throw new InvalidOperationException();
            }

            try {
                await ProcessOperation(cancellationToken).ConfigureAwait(false);

                return(new AsyncProtocolResult(UserResult));
            } catch (Exception ex) {
                var info = Parent.SetException(MobileAuthenticatedStream.GetSSPIException(ex));
                return(new AsyncProtocolResult(info));
            }
        }
		public MobileTlsContext (
			MobileAuthenticatedStream parent, bool serverMode, string targetHost,
			SslProtocols enabledProtocols, X509Certificate serverCertificate,
			X509CertificateCollection clientCertificates, bool askForClientCert)
		{
			this.parent = parent;
			this.serverMode = serverMode;
			this.targetHost = targetHost;
			this.enabledProtocols = enabledProtocols;
			this.serverCertificate = serverCertificate;
			this.clientCertificates = clientCertificates;
			this.askForClientCert = askForClientCert;

			serverName = targetHost;
			if (!string.IsNullOrEmpty (serverName)) {
				var pos = serverName.IndexOf (':');
				if (pos > 0)
					serverName = serverName.Substring (0, pos);
			}

			certificateValidator = CertificateValidationHelper.GetInternalValidator (
				parent.Settings, parent.Provider);
		}
Example #17
0
 protected abstract MobileTlsContext CreateContext(
     MobileAuthenticatedStream parent, bool serverMode, string targetHost,
     SSA.SslProtocols enabledProtocols, X509Certificate serverCertificate,
     X509CertificateCollection clientCertificates, bool askForClientCert);
Example #18
0
 public AsyncRenegotiateRequest(MobileAuthenticatedStream parent)
     : base(parent, false)
 {
 }
Example #19
0
 public AsyncShutdownRequest(MobileAuthenticatedStream parent)
     : base(parent, false)
 {
 }
Example #20
0
 public AsyncWriteRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
     : base(parent, sync, buffer, offset, size)
 {
 }
Example #21
0
		public AsyncProtocolRequest (MobileAuthenticatedStream parent, LazyAsyncResult lazyResult, BufferOffsetSize userBuffer = null)
		{
			Parent = parent;
			UserAsyncResult = lazyResult;
			UserBuffer = userBuffer;
		}
Example #22
0
 public AsyncHandshakeRequest(MobileAuthenticatedStream parent, bool sync)
     : base(parent, sync)
 {
 }
Example #23
0
 public AsyncProtocolRequest(MobileAuthenticatedStream parent, bool sync)
 {
     Parent           = parent;
     RunSynchronously = sync;
 }
Example #24
0
		protected abstract MobileTlsContext CreateContext (
			MobileAuthenticatedStream parent, bool serverMode, string targetHost,
			SSA.SslProtocols enabledProtocols, X509Certificate serverCertificate,
			X509CertificateCollection clientCertificates, bool askForClientCert);
Example #25
0
 public AsyncReadOrWriteRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size)
     : base(parent, sync)
 {
     UserBuffer = new BufferOffsetSize(buffer, offset, size);
 }
Example #26
0
 public AsyncProtocolRequest(MobileAuthenticatedStream parent, LazyAsyncResult lazyResult, BufferOffsetSize userBuffer = null)
 {
     Parent          = parent;
     UserAsyncResult = lazyResult;
     UserBuffer      = userBuffer;
 }