当前位置: 首页>>代码示例>>C#>>正文


C# X509CertificateCollection类代码示例

本文整理汇总了C#中X509CertificateCollection的典型用法代码示例。如果您正苦于以下问题:C# X509CertificateCollection类的具体用法?C# X509CertificateCollection怎么用?C# X509CertificateCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


X509CertificateCollection类属于命名空间,在下文中一共展示了X509CertificateCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

	static void Main(string[] args)
	{
		string host = "localhost";
		if (args.Length > 0)
			host = args[0];

		SslProtocols protocol = SslProtocols.Tls;
		if (args.Length > 1) {
			switch (args [1].ToUpper ()) {
			case "SSL":
				protocol = SslProtocols.Ssl3;
				break;
			}
		}

		X509CertificateCollection certificates = null;
		if (args.Length > 2) {
			string password = null;
			if (args.Length > 3)
				password = args [3];

			p12 = Mono.Security.X509.PKCS12.LoadFromFile(args [2], password);

			certificates = new X509CertificateCollection ();
			foreach (Mono.Security.X509.X509Certificate cert in p12.Certificates) {
				certificates.Add(new X509Certificate2(args [2], password));
				break;
			}
		}

		TcpClient client = new TcpClient ();
		client.Connect (host, 4433);
 
 		SslStream ssl = new SslStream (client.GetStream(), false, new RemoteCertificateValidationCallback (CertificateValidation), new LocalCertificateSelectionCallback (ClientCertificateSelection));

		ssl.AuthenticateAsClient (host, certificates, protocol, false); 	
		StreamWriter sw = new StreamWriter (ssl, System.Text.Encoding.ASCII);
		sw.WriteLine ("GET /clientcert.aspx{0}", Environment.NewLine);
		sw.Flush ();

		StreamReader sr = new StreamReader (ssl);
		Console.WriteLine (sr.ReadToEnd ());
	}
开发者ID:nlhepler,项目名称:mono,代码行数:43,代码来源:mutual.cs

示例2: BuildX509Chain

		static bool BuildX509Chain (X509CertificateCollection certs, X509Chain chain, ref SslPolicyErrors errors, ref int status11)
		{
#if MOBILE
			return false;
#else
			if (is_macosx)
				return false;

			var leaf = (X509Certificate2)certs [0];

			bool ok;
			try {
				ok = chain.Build (leaf);
				if (!ok)
					errors |= GetErrorsFromChain (chain);
			} catch (Exception e) {
				Console.Error.WriteLine ("ERROR building certificate chain: {0}", e);
				Console.Error.WriteLine ("Please, report this problem to the Mono team");
				errors |= SslPolicyErrors.RemoteCertificateChainErrors;
				ok = false;
			}

			try {
				status11 = GetStatusFromChain (chain);
			} catch {
				status11 = -2146762485; // TRUST_E_FAIL - generic
			}

			return ok;
#endif
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:31,代码来源:SystemCertificateValidator.cs

示例3: TrustEvaluateSsl

		internal static bool TrustEvaluateSsl (X509CertificateCollection collection)
		{
			var certsRawData = new List <byte[]> (collection.Count);
			foreach (var cert in collection)
				certsRawData.Add (cert.GetRawCertData ());
			return trustEvaluateSsl (certsRawData);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:AndroidPlatform.cs

示例4: X509CertificateCollectionEnumerator

        public static void X509CertificateCollectionEnumerator()
        {
            using (X509Certificate2 c1 = new X509Certificate2())
            using (X509Certificate2 c2 = new X509Certificate2())
            using (X509Certificate2 c3 = new X509Certificate2())
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2, c3 });
                X509CertificateCollection.X509CertificateEnumerator e = cc.GetEnumerator();
                object ignored;

                // Not started
                Assert.Throws<InvalidOperationException>(() => ignored = e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(c1, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(c2, e.Current);

                Assert.True(e.MoveNext());
                Assert.Same(c3, e.Current);

                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());
                Assert.False(e.MoveNext());

                // ended.
                Assert.Throws<InvalidOperationException>(() => ignored = e.Current);
            }
        }
开发者ID:jmhardison,项目名称:corefx,代码行数:32,代码来源:CollectionTests.cs

示例5: ProcessAsTls1

		protected override void ProcessAsTls1()
		{
			this.certificates = new X509CertificateCollection();
			
			int readed	= 0;
			int length	= this.ReadInt24();

			while (readed < length)
			{
				// Read certificate length
				int certLength = ReadInt24();

				// Increment readed
				readed += 3;

				if (certLength > 0)
				{
					// Read certificate data
					byte[] buffer = this.ReadBytes(certLength);

					// Create a new X509 Certificate
					X509Certificate certificate = new X509Certificate(buffer);
					certificates.Add(certificate);

					readed += certLength;

					DebugHelper.WriteLine(
						String.Format("Server Certificate {0}", certificates.Count),
						buffer);
				}
			}

			this.validateCertificates(certificates);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:34,代码来源:TlsServerCertificate.cs

示例6: CreateX509Chain

		public static X509Chain CreateX509Chain (X509CertificateCollection certs)
		{
			var chain = new X509Chain ();
			chain.ChainPolicy = new X509ChainPolicy ((X509CertificateCollection)(object)certs);

#if !MOBILE
			chain.ChainPolicy.RevocationMode = revocation_mode;
#endif

			return chain;
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:11,代码来源:SystemCertificateValidator.cs

示例7: Create

		internal static SSPIInterface Create (string hostname, bool serverMode, SchProtocols protocolFlags, X509Certificate serverCertificate, X509CertificateCollection clientCertificates,
		                                           bool remoteCertRequired, bool checkCertName, bool checkCertRevocationStatus, EncryptionPolicy encryptionPolicy,
		                                           LocalCertSelectionCallback certSelectionDelegate, RemoteCertValidationCallback remoteValidationCallback, SSPIConfiguration userConfig)
		{
			if (userConfig.Settings != null && remoteValidationCallback != null)
				throw new InvalidOperationException ();
			var context = userConfig.Provider.CreateTlsContext (
				hostname, serverMode, (TlsProtocols)protocolFlags, serverCertificate, clientCertificates,
				remoteCertRequired, checkCertName, checkCertRevocationStatus,
				(MonoEncryptionPolicy)encryptionPolicy, userConfig.Settings);
			return new SSPIInterface (context, userConfig.EventSink);
		}
开发者ID:razzfazz,项目名称:mono,代码行数:12,代码来源:SSPIWrapper.cs

示例8: X509CertificateCollectionsProperties

        public static void X509CertificateCollectionsProperties()
        {
            IList ilist = new X509CertificateCollection();
            Assert.False(ilist.IsSynchronized);
            Assert.False(ilist.IsFixedSize);
            Assert.False(ilist.IsReadOnly);

            ilist = new X509Certificate2Collection();
            Assert.False(ilist.IsSynchronized);
            Assert.False(ilist.IsFixedSize);
            Assert.False(ilist.IsReadOnly);
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:12,代码来源:CollectionTests.cs

示例9: ClientCertificateSelection

	static X509Certificate ClientCertificateSelection (X509CertificateCollection clientCertificates,
		X509Certificate serverCertificate, string targetHost, X509CertificateCollection serverRequestedCertificates)
	{
		Console.WriteLine ("ClientCertificateSelection");
		Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
		int i = 1;
		foreach (X509Certificate client in clientCertificates)
			Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.Write ("SERVER {0}", serverCertificate.ToString (true));
		Console.WriteLine ();
		return clientCertificates [0];
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:13,代码来源:mutual.cs

示例10: ClientCertificateSelection

	static X509Certificate ClientCertificateSelection (object sender, string targetHost, X509CertificateCollection clientCertificates,
		X509Certificate serverCertificate, string [] acceptableIssuers)
	{
		Console.WriteLine ("ClientCertificateSelection");
		Console.WriteLine ("\tClient Certificates ({0})", clientCertificates.Count);
		int i = 1;
		foreach (X509Certificate client in clientCertificates)
			Console.WriteLine ("#{0} - {1}", i++, client.ToString (true));
		Console.WriteLine ("\tHost: {0}", targetHost);
		Console.Write ("SERVER {0}", serverCertificate != null ? serverCertificate.ToString (true) : null);
		Console.WriteLine ();
		if (i == 1)
			return null;
		X509Certificate2 cc = new X509Certificate2 (clientCertificates [0]);
		cc.PrivateKey = PrivateKeySelection (cc, targetHost);
		return cc;
	}
开发者ID:nlhepler,项目名称:mono,代码行数:17,代码来源:mutual.cs

示例11: Connect

        /// <summary>
        /// Connect to the registry end point
        /// </summary>
        public void Connect()
        {
            var client = new TcpClient(EPP_REGISTRY_COM, PORT);

            stream = new SslStream(client.GetStream(), false, ValidateServerCertificate);

            if (clientCertificate != null)
            {
                var clientCertificates = new X509CertificateCollection {clientCertificate};

                stream.AuthenticateAsClient(EPP_REGISTRY_COM, clientCertificates, SslProtocols.Ssl3, false);
            }
            else
            {
                stream.AuthenticateAsClient(EPP_REGISTRY_COM);
            }

        }
开发者ID:softwareengr,项目名称:EppLib.NET,代码行数:21,代码来源:TcpTransport.cs

示例12: Main

	static void Main(string[] args)
	{
		string host = "localhost";
		if (args.Length > 0)
			host = args[0];

		SecurityProtocolType protocol = SecurityProtocolType.Tls;
		if (args.Length > 1) {
			switch (args [1].ToUpper ()) {
			case "SSL":
				protocol = SecurityProtocolType.Ssl3;
				break;
			}
		}

		X509CertificateCollection certificates = null;
		if (args.Length > 2) {
			string password = null;
			if (args.Length > 3)
				password = args [3];

			p12 = Mono.Security.X509.PKCS12.LoadFromFile(args [2], password);

			certificates = new X509CertificateCollection ();
			foreach (Mono.Security.X509.X509Certificate cert in p12.Certificates) {
				certificates.Add(new X509Certificate(cert.RawData));
			}
		}

		TcpClient client = new TcpClient ();
		client.Connect (host, 4433);
 
 		SslClientStream ssl = new SslClientStream (client.GetStream(), host, false, protocol, certificates);
 		ssl.ServerCertValidationDelegate += new CertificateValidationCallback (CertificateValidation);
 		ssl.ClientCertSelectionDelegate += new CertificateSelectionCallback (ClientCertificateSelection);
 		ssl.PrivateKeyCertSelectionDelegate += new PrivateKeySelectionCallback (PrivateKeySelection);
	
		StreamWriter sw = new StreamWriter (ssl, System.Text.Encoding.ASCII);
		sw.WriteLine ("GET /clientcert.aspx{0}", Environment.NewLine);
		sw.Flush ();

		StreamReader sr = new StreamReader (ssl);
		Console.WriteLine (sr.ReadToEnd ());
	}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:44,代码来源:mutual.cs

示例13: ProcessAsTls1

		protected override void ProcessAsTls1()
		{
			int bytesRead = 0;
			int length = this.ReadInt24 ();
			this.clientCertificates = new X509CertificateCollection ();
			while (length > bytesRead) {
				int certLength = this.ReadInt24 ();
				bytesRead += certLength + 3;
				byte[] cert = this.ReadBytes (certLength);
				this.clientCertificates.Add (new X509Certificate (cert));
			}

			if (this.clientCertificates.Count > 0) 
			{
				this.validateCertificates (this.clientCertificates);
			} 
			else if ((this.Context as ServerContext).ClientCertificateRequired) 
			{
				throw new TlsException (AlertDescription.NoCertificate);
			}
		}
开发者ID:Jakosa,项目名称:MonoLibraries,代码行数:21,代码来源:TlsClientCertificate.cs

示例14: X509CertificateCollectionConstructors

        public static void X509CertificateCollectionConstructors()
        {
            using (X509Certificate c1 = new X509Certificate())
            using (X509Certificate c2 = new X509Certificate())
            using (X509Certificate c3 = new X509Certificate())
            {
                X509CertificateCollection cc = new X509CertificateCollection(new X509Certificate[] { c1, c2, c3 });
                Assert.Equal(3, cc.Count);
                Assert.Same(c1, cc[0]);
                Assert.Same(c2, cc[1]);
                Assert.Same(c3, cc[2]);

                X509CertificateCollection cc2 = new X509CertificateCollection(cc);
                Assert.Equal(3, cc2.Count);
                Assert.Same(c1, cc2[0]);
                Assert.Same(c2, cc2[1]);
                Assert.Same(c3, cc2[2]);

                Assert.Throws<ArgumentNullException>(() => new X509CertificateCollection(new X509Certificate[] { c1, c2, null, c3 }));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:21,代码来源:CollectionTests.cs

示例15: Connect

        /// <summary>
        /// Connect to the registry end point
        /// </summary>
        public void Connect(SslProtocols sslProtocols)
        {
            var client = new TcpClient(EPP_REGISTRY_COM, PORT);

            stream = new SslStream(client.GetStream(), false, ValidateServerCertificate)
                     {
                         ReadTimeout = READ_TIMEOUT,
                         WriteTimeout = WRITE_TIMEOUT
                     };

            if (clientCertificate != null)
            {
                var clientCertificates = new X509CertificateCollection {clientCertificate};

                stream.AuthenticateAsClient(EPP_REGISTRY_COM, clientCertificates, sslProtocols, false);
            }
            else
            {
                stream.AuthenticateAsClient(EPP_REGISTRY_COM);
            }

        }
开发者ID:CodeMakerInc,项目名称:EppLib.NET,代码行数:25,代码来源:TcpTransport.cs


注:本文中的X509CertificateCollection类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。