예제 #1
0
        internal Stream CreateStream(byte[] buffer)
        {
            sslStream = provider.CreateSslStream(networkStream, false, settings);

            try {
                var host = request.Host;
                if (!string.IsNullOrEmpty(host))
                {
                    var pos = host.IndexOf(':');
                    if (pos > 0)
                    {
                        host = host.Substring(0, pos);
                    }
                }

                sslStream.AuthenticateAsClient(
                    host, request.ClientCertificates,
                    (SslProtocols)ServicePointManager.SecurityProtocol,
                    ServicePointManager.CheckCertificateRevocationList);

                status = WebExceptionStatus.Success;
            } catch (Exception) {
                status = WebExceptionStatus.SecureChannelFailure;
                throw;
            } finally {
                if (CertificateValidationFailed)
                {
                    status = WebExceptionStatus.TrustFailure;
                }

                if (status == WebExceptionStatus.Success)
                {
                    request.ServicePoint.UpdateClientCertificate(sslStream.InternalLocalCertificate);
                }
                else
                {
                    request.ServicePoint.UpdateClientCertificate(null);
                    sslStream = null;
                }
            }

            try {
                if (buffer != null)
                {
                    sslStream.Write(buffer, 0, buffer.Length);
                }
            } catch {
                status    = WebExceptionStatus.SendFailure;
                sslStream = null;
                throw;
            }

            return(sslStream.AuthenticatedStream);
        }
예제 #2
0
 internal IMonoSslStream CreateSslStream(Stream innerStream, bool ownsStream, MSI.MonoRemoteCertificateValidationCallback callback)
 {
     lock (registry) {
         if (tlsProvider == null)
         {
             tlsProvider = MonoTlsProviderFactory.GetProviderInternal();
         }
         if (tlsSettings == null)
         {
             tlsSettings = MSI.MonoTlsSettings.CopyDefaultSettings();
         }
         if (tlsSettings.RemoteCertificateValidationCallback == null)
         {
             tlsSettings.RemoteCertificateValidationCallback = callback;
         }
         return(tlsProvider.CreateSslStream(innerStream, ownsStream, tlsSettings));
     }
 }
예제 #3
0
        internal Stream CreateStream(byte[] buffer)
        {
            sslStream = provider.CreateSslStream(networkStream, false, settings);

            try {
                sslStream.AuthenticateAsClient(
                    request.Address.Host, (XX509CertificateCollection)(object)request.ClientCertificates,
                    (SslProtocols)ServicePointManager.SecurityProtocol,
                    ServicePointManager.CheckCertificateRevocationList);

                status = WebExceptionStatus.Success;
            } catch (Exception ex) {
                status = WebExceptionStatus.SecureChannelFailure;
                throw;
            } finally {
                if (CertificateValidationFailed)
                {
                    status = WebExceptionStatus.TrustFailure;
                }

                if (status == WebExceptionStatus.Success)
                {
                    request.ServicePoint.UpdateClientCertificate(sslStream.InternalLocalCertificate);
                }
                else
                {
                    request.ServicePoint.UpdateClientCertificate(null);
                    sslStream = null;
                }
            }

            try {
                if (buffer != null)
                {
                    sslStream.Write(buffer, 0, buffer.Length);
                }
            } catch {
                status    = WebExceptionStatus.SendFailure;
                sslStream = null;
                throw;
            }

            return(sslStream.AuthenticatedStream);
        }