本文整理汇总了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 ());
}
示例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
}
示例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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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];
}
示例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;
}
示例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);
}
}
示例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 ());
}
示例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);
}
}
示例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 }));
}
}
示例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);
}
}