Esempio n. 1
0
        internal Stream CreateStream(byte[] buffer)
        {
#if SECURITY_DEP
            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 {
                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);
#else
            throw new PlatformNotSupportedException(EXCEPTION_MESSAGE);
#endif
        }
Esempio n. 2
0
        internal Stream CreateStream(byte[] buffer)
        {
            sslStream = provider.CreateSslStream(networkStream, false, settings);

            try {
                sslStream.AuthenticateAsClient(
                    request.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);
        }
Esempio n. 3
0
		internal Stream CreateStream (byte[] buffer)
		{
			sslStream = provider.CreateSslStream (networkStream, false, settings);

			try {
				sslStream.AuthenticateAsClient (
					request.Address.Host, 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;
		}
Esempio n. 4
0
 public void AuthenticateAsClient(string targetHost)
 {
     Impl.AuthenticateAsClient(targetHost);
 }