internal static ChainValidationHelper Create(ref MonoTlsSettings settings, MonoTlsStream stream) { var helper = new ChainValidationHelper(settings, true, stream, null); settings = helper.settings; return(helper); }
ChainValidationHelper(MonoTlsProvider provider, MonoTlsSettings settings, bool cloneSettings, MonoTlsStream stream, ServerCertValidationCallbackWrapper callbackWrapper) { if (settings == null) { settings = MonoTlsSettings.CopyDefaultSettings(); } if (cloneSettings) { settings = settings.CloneWithValidator(this); } if (provider == null) { provider = MonoTlsProviderFactory.GetProvider(); } this.provider = provider; this.settings = settings; this.tlsStream = stream; this.callbackWrapper = callbackWrapper; var fallbackToSPM = false; if (settings != null) { if (settings.RemoteCertificateValidationCallback != null) { var callback = Private.CallbackHelpers.MonoToPublic(settings.RemoteCertificateValidationCallback); certValidationCallback = new ServerCertValidationCallback(callback); } certSelectionCallback = Private.CallbackHelpers.MonoToInternal(settings.ClientCertificateSelectionCallback); fallbackToSPM = settings.UseServicePointManagerCallback ?? stream != null; } if (stream != null) { this.request = stream.Request; this.sender = request; if (certValidationCallback == null) { certValidationCallback = request.ServerCertValidationCallback; } if (certSelectionCallback == null) { certSelectionCallback = new LocalCertSelectionCallback(DefaultSelectionCallback); } if (settings == null) { fallbackToSPM = true; } } if (fallbackToSPM && certValidationCallback == null) { certValidationCallback = ServicePointManager.ServerCertValidationCallback; } }
ChainValidationHelper(SslStream owner, MonoTlsProvider provider, MonoTlsSettings settings, bool cloneSettings, MonoTlsStream stream) { if (settings == null) { settings = MonoTlsSettings.CopyDefaultSettings(); } if (cloneSettings) { settings = settings.CloneWithValidator(this); } if (provider == null) { provider = MonoTlsProviderFactory.GetProvider(); } this.provider = provider; this.settings = settings; this.tlsStream = stream; if (owner != null) { this.owner = new WeakReference <SslStream> (owner); } var fallbackToSPM = false; if (settings != null) { certValidationCallback = GetValidationCallback(settings); certSelectionCallback = Private.CallbackHelpers.MonoToInternal(settings.ClientCertificateSelectionCallback); fallbackToSPM = settings.UseServicePointManagerCallback ?? stream != null; } if (stream != null) { this.request = stream.Request; if (certValidationCallback == null) { certValidationCallback = request.ServerCertValidationCallback; } if (certSelectionCallback == null) { certSelectionCallback = new LocalCertSelectionCallback(DefaultSelectionCallback); } if (settings == null) { fallbackToSPM = true; } } if (fallbackToSPM && certValidationCallback == null) { certValidationCallback = ServicePointManager.ServerCertValidationCallback; } }
ChainValidationHelper(ChainValidationHelper other, MonoTlsSettings settings, ServerCertValidationCallbackWrapper callbackWrapper = null) { sender = other.sender; certValidationCallback = other.certValidationCallback; certSelectionCallback = other.certSelectionCallback; tlsStream = other.tlsStream; request = other.request; this.settings = settings = settings.CloneWithValidator(this); this.callbackWrapper = callbackWrapper; }
bool CreateStream (HttpWebRequest request) { try { NetworkStream serverStream = new NetworkStream (socket, false); if (request.Address.Scheme == Uri.UriSchemeHttps) { #if SECURITY_DEP if (!reused || nstream == null || tlsStream == null) { byte [] buffer = null; if (sPoint.UseConnect) { bool ok = CreateTunnel (request, sPoint.Address, serverStream, out buffer); if (!ok) return false; } tlsStream = new MonoTlsStream (request, serverStream); nstream = tlsStream.CreateStream (buffer); } // we also need to set ServicePoint.Certificate // and ServicePoint.ClientCertificate but this can // only be done later (after handshake - which is // done only after a read operation). #else throw new NotSupportedException (); #endif } else { nstream = serverStream; } } catch (Exception ex) { if (tlsStream != null) status = tlsStream.ExceptionStatus; else if (!request.Aborted) status = WebExceptionStatus.ConnectFailure; connect_exception = ex; return false; } return true; }
internal static ChainValidationHelper Create(MonoTlsProvider provider, ref MonoTlsSettings settings, MonoTlsStream stream) { var helper = new ChainValidationHelper(null, provider, settings, true, stream); settings = helper.settings; return(helper); }
ChainValidationHelper (MonoTlsProvider provider, MonoTlsSettings settings, bool cloneSettings, MonoTlsStream stream, ServerCertValidationCallbackWrapper callbackWrapper) { if (settings == null) settings = MonoTlsSettings.CopyDefaultSettings (); if (cloneSettings) settings = settings.CloneWithValidator (this); if (provider == null) provider = MonoTlsProviderFactory.GetProvider (); this.provider = provider; this.settings = settings; this.tlsStream = stream; this.callbackWrapper = callbackWrapper; var fallbackToSPM = false; if (settings != null) { if (settings.RemoteCertificateValidationCallback != null) { var callback = Private.CallbackHelpers.MonoToPublic (settings.RemoteCertificateValidationCallback); certValidationCallback = new ServerCertValidationCallback (callback); } certSelectionCallback = Private.CallbackHelpers.MonoToInternal (settings.ClientCertificateSelectionCallback); fallbackToSPM = settings.UseServicePointManagerCallback ?? stream != null; } if (stream != null) { this.request = stream.Request; this.sender = request; if (certValidationCallback == null) certValidationCallback = request.ServerCertValidationCallback; if (certSelectionCallback == null) certSelectionCallback = new LocalCertSelectionCallback (DefaultSelectionCallback); if (settings == null) fallbackToSPM = true; } if (fallbackToSPM && certValidationCallback == null) certValidationCallback = ServicePointManager.ServerCertValidationCallback; }
internal static ChainValidationHelper Create (MonoTlsProvider provider, ref MonoTlsSettings settings, MonoTlsStream stream) { var helper = new ChainValidationHelper (provider, settings, true, stream, null); settings = helper.settings; return helper; }
ChainValidationHelper (ChainValidationHelper other, MonoTlsProvider provider, MonoTlsSettings settings, ServerCertValidationCallbackWrapper callbackWrapper = null) { sender = other.sender; certValidationCallback = other.certValidationCallback; certSelectionCallback = other.certSelectionCallback; tlsStream = other.tlsStream; request = other.request; if (settings == null) settings = MonoTlsSettings.DefaultSettings; this.provider = provider; this.settings = settings.CloneWithValidator (this); this.callbackWrapper = callbackWrapper; }