/// <summary> /// Starts a new session /// </summary> /// <returns>The session.</returns> /// <param name="operationTimeout">The operation timeout.</param> /// <param name="readwriteTimeout">The readwrite timeout.</param> /// <param name="bufferRequests">If set to <c>true</c> http requests are buffered.</param> public static IDisposable StartSession(TimeSpan operationTimeout = default(TimeSpan), TimeSpan readwriteTimeout = default(TimeSpan), bool bufferRequests = false, bool acceptAnyCertificate = false, string[] allowedCertificates = null) { return(CallContextSettings <HttpSettings> .StartContext(new HttpSettings() { OperationTimeout = operationTimeout, ReadWriteTimeout = readwriteTimeout, BufferRequests = bufferRequests, CertificateValidator = acceptAnyCertificate || (allowedCertificates != null) ? new SslCertificateValidator(acceptAnyCertificate, allowedCertificates) : null })); }
/// <summary> /// Starts a new session /// </summary> /// <returns>The session.</returns> /// <param name="operationTimeout">The operation timeout.</param> /// <param name="readwriteTimeout">The readwrite timeout.</param> /// <param name="bufferRequests">If set to <c>true</c> http requests are buffered.</param> public static IDisposable StartSession(TimeSpan operationTimeout = default(TimeSpan), TimeSpan readwriteTimeout = default(TimeSpan), bool bufferRequests = false, bool acceptAnyCertificate = false, string[] allowedCertificates = null) { // Make sure we always use our own version of the callback System.Net.ServicePointManager.ServerCertificateValidationCallback = ServicePointManagerCertificateCallback; return(CallContextSettings <HttpSettings> .StartContext(new HttpSettings() { OperationTimeout = operationTimeout, ReadWriteTimeout = readwriteTimeout, BufferRequests = bufferRequests, CertificateValidator = acceptAnyCertificate || (allowedCertificates != null) ? new SslCertificateValidator(acceptAnyCertificate, allowedCertificates) : null })); }
public static IDisposable StartSession(string tempdir = null, long buffersize = 0) { if (buffersize < 1024) { buffersize = 64 * 1024; } var systemSettings = new SystemSettings { Tempdir = string.IsNullOrWhiteSpace(tempdir) ? DefaultTempPath : tempdir, Buffersize = buffersize }; return(CallContextSettings <SystemSettings> .StartContext(systemSettings)); }
public static IDisposable StartSession(string tempdir = null, long buffersize = 0) { if (string.IsNullOrWhiteSpace(tempdir)) { tempdir = System.IO.Path.GetTempPath(); } if (buffersize < 1024) { buffersize = 64 * 1024; } return(CallContextSettings <SystemSettings> .StartContext(new SystemSettings() { Tempdir = tempdir, Buffersize = buffersize })); }
/// <summary> /// The callback used to defer the call context, such that each scope can have its own callback /// </summary> /// <returns><c>true</c>, if point manager certificate callback was serviced, <c>false</c> otherwise.</returns> /// <param name="sender">The sender of the validation.</param> /// <param name="certificate">The certificate to validate.</param> /// <param name="chain">The certificate chain.</param> /// <param name="sslPolicyErrors">Errors discovered.</param> private static bool ServicePointManagerCertificateCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { // If we have a custom SSL validator, invoke it if (HttpContextSettings.CertificateValidator != null) { return(CertificateValidator.ValidateServerCertficate(sender, certificate, chain, sslPolicyErrors)); } // Default is to only approve certificates without errors var result = sslPolicyErrors == SslPolicyErrors.None; // Hack: If we have no validator, see if the context is all messed up // This is not the right way, but ServicePointManager is not designed right for this var any = false; foreach (var v in CallContextSettings <HttpSettings> .GetAllInstances()) { if (v.CertificateValidator != null) { var t = v.CertificateValidator.ValidateServerCertficate(sender, certificate, chain, sslPolicyErrors); // First instance overrides framework result if (!any) { result = t; } // If there are more, we see if anyone will accept it else { result |= t; } any = true; } } return(result); }