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); }
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); }
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); }
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; } }
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); }
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)); }
protected override void Dispose(bool disposing) { try { if (impl != null && disposing) { impl.Dispose(); impl = null; } } finally { base.Dispose(disposing); } }
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); } }
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); }
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); }
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); }
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); }
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); }
protected abstract MobileTlsContext CreateContext( MobileAuthenticatedStream parent, bool serverMode, string targetHost, SSA.SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool askForClientCert);
public AsyncRenegotiateRequest(MobileAuthenticatedStream parent) : base(parent, false) { }
public AsyncShutdownRequest(MobileAuthenticatedStream parent) : base(parent, false) { }
public AsyncWriteRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size) : base(parent, sync, buffer, offset, size) { }
public AsyncProtocolRequest (MobileAuthenticatedStream parent, LazyAsyncResult lazyResult, BufferOffsetSize userBuffer = null) { Parent = parent; UserAsyncResult = lazyResult; UserBuffer = userBuffer; }
public AsyncHandshakeRequest(MobileAuthenticatedStream parent, bool sync) : base(parent, sync) { }
public AsyncProtocolRequest(MobileAuthenticatedStream parent, bool sync) { Parent = parent; RunSynchronously = sync; }
protected abstract MobileTlsContext CreateContext ( MobileAuthenticatedStream parent, bool serverMode, string targetHost, SSA.SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool askForClientCert);
public AsyncReadOrWriteRequest(MobileAuthenticatedStream parent, bool sync, byte[] buffer, int offset, int size) : base(parent, sync) { UserBuffer = new BufferOffsetSize(buffer, offset, size); }
public AsyncProtocolRequest(MobileAuthenticatedStream parent, LazyAsyncResult lazyResult, BufferOffsetSize userBuffer = null) { Parent = parent; UserAsyncResult = lazyResult; UserBuffer = userBuffer; }