Esempio n. 1
0
		bool CreateStream (HttpWebRequest request)
		{
			try {
				NetworkStream serverStream = new NetworkStream (socket, false);

				if (request.Address.Scheme == Uri.UriSchemeHttps) {
					ssl = true;
					EnsureSSLStreamAvailable ();
					if (!reused || nstream == null || nstream.GetType () != sslStream) {
						byte [] buffer = null;
						if (sPoint.UseConnect) {
							bool ok = CreateTunnel (request, sPoint.Address, serverStream, out buffer);
							if (!ok)
								return false;
						}
#if SECURITY_DEP
#if MONOTOUCH || MONODROID
						nstream = new HttpsClientStream (serverStream, request.ClientCertificates, request, buffer);
#else
						object[] args = new object [4] { serverStream,
							request.ClientCertificates,
							request, buffer};
						nstream = (Stream) Activator.CreateInstance (sslStream, args);
#endif
						SslClientStream scs = (SslClientStream) nstream;
						var helper = new ServicePointManager.ChainValidationHelper (request, request.Address.Host);
						scs.ServerCertValidation2 += new CertificateValidationCallback2 (helper.ValidateChain);
#endif
						certsAvailable = false;
					}
					// 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 {
					ssl = false;
					nstream = serverStream;
				}
			} catch (Exception) {
				if (!request.Aborted)
					status = WebExceptionStatus.ConnectFailure;
				return false;
			}

			return true;
		}
Esempio n. 2
0
 public TlsStream(NetworkStream stream, Socket socket, string host, X509CertificateCollection clientCertificates) : base(socket)
 {
     _sslStream          = new SslStream(stream, false, ServicePointManager.ServerCertificateValidationCallback);
     _host               = host;
     _clientCertificates = clientCertificates;
 }