本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509CertificateCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# X509CertificateCollection.Add方法的具体用法?C# X509CertificateCollection.Add怎么用?C# X509CertificateCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.X509Certificates.X509CertificateCollection
的用法示例。
在下文中一共展示了X509CertificateCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplePushChannel
public ApplePushChannel(ApplePushChannelSettings channelSettings)
{
cancelToken = cancelTokenSrc.Token;
appleSettings = channelSettings;
certificate = this.appleSettings.Certificate;
certificates = new X509CertificateCollection();
if (appleSettings.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
certificates.AddRange(store.Certificates);
}
certificates.Add(certificate);
if (this.appleSettings.AdditionalCertificates != null)
foreach (var addlCert in this.appleSettings.AdditionalCertificates)
certificates.Add(addlCert);
timerCleanup = new Timer(state => Cleanup(), null, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000));
}
示例2: ApplePushChannel
public ApplePushChannel(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
: base(channelSettings, serviceSettings)
{
this.appleSettings = channelSettings;
certificate = this.appleSettings.Certificate;
certificates = new X509CertificateCollection();
if (appleSettings.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
certificates.AddRange(store.Certificates);
}
certificates.Add(certificate);
if (this.appleSettings.AdditionalCertificates != null)
foreach (var addlCert in this.appleSettings.AdditionalCertificates)
certificates.Add(addlCert);
//Start our cleanup task
taskCleanup = new Task(() => Cleanup(), TaskCreationOptions.LongRunning);
taskCleanup.ContinueWith((t) => { var ex = t.Exception; }, TaskContinuationOptions.OnlyOnFaulted);
taskCleanup.Start();
}
示例3: ApnsConnection
public ApnsConnection(ApnsConfiguration configuration)
{
id = ++ID;
if (id >= int.MaxValue)
ID = 0;
Configuration = configuration;
certificate = Configuration.Certificate;
certificates = new X509CertificateCollection();
// Add local/machine certificate stores to our collection if requested
if (Configuration.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
certificates.AddRange(store.Certificates);
}
// Add optionally specified additional certs into our collection
if (Configuration.AdditionalCertificates != null)
{
foreach (var addlCert in Configuration.AdditionalCertificates)
certificates.Add(addlCert);
}
// Finally, add the main private cert for authenticating to our collection
if (certificate != null)
certificates.Add(certificate);
timerBatchWait = new Timer(new TimerCallback(async state =>
{
await batchSendSemaphore.WaitAsync();
try
{
await SendBatch().ConfigureAwait(false);
}
finally
{
batchSendSemaphore.Release();
}
}), null, Timeout.Infinite, Timeout.Infinite);
}
示例4: ConfigureCertificates
private void ConfigureCertificates()
{
_certificate = _appleSettings.Certificate;
_certificates = new X509CertificateCollection();
if (_appleSettings.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
_certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
_certificates.AddRange(store.Certificates);
}
_certificates.Add(_certificate);
if (_appleSettings.AdditionalCertificates != null)
{
foreach (var additionalCertificate in _appleSettings.AdditionalCertificates)
{
_certificates.Add(additionalCertificate);
}
}
}
示例5: TcpConnection
// Establishes SSL connection iff ssl is not null.
public TcpConnection(string host, int port, SslOptions ssl)
{
_log.Info("Connecting to {0}:{1}...", host, port);
_client = new TcpClient(host, port);
if (ssl == null)
{
_strm = _client.GetStream();
}
else
{
try
{
RemoteCertificateValidationCallback cb =
(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors errors) =>
{
if (errors == SslPolicyErrors.None)
return true;
if (errors != SslPolicyErrors.RemoteCertificateChainErrors)
{
_log.Error("SSL handshake error: {0}", errors);
return ssl.AllowAllErrors;
}
foreach (X509ChainStatus ch in chain.ChainStatus)
{
if (ch.Status == X509ChainStatusFlags.NotTimeValid && ssl.AllowExpiredCertificate)
{
_log.Warn("Ignoring NotTimeValid error in SSL handshake.");
continue;
}
if (ch.Status == X509ChainStatusFlags.PartialChain)
{
_log.Warn("Ignoring PartialChain error in SSL handshake.");
continue;
}
_log.Error("SSL handshake error: {0} {1}", ch.Status, ch.StatusInformation);
return ssl.AllowAllErrors;
}
return true;
};
var sslStrm = new SslStream(_client.GetStream(), leaveInnerStreamOpen: false,
userCertificateValidationCallback: cb);
var certs = new X509CertificateCollection();
if (ssl.CertificateFilename != null)
certs.Add(new X509Certificate(ssl.CertificateFilename, ssl.CertificateFilePassword));
sslStrm.AuthenticateAsClient(ssl.CertificateName ?? host, certs,
System.Security.Authentication.SslProtocols.Default,
checkCertificateRevocation: false);
_strm = sslStrm;
}
catch
{
Dispose();
throw;
}
}
var protocols = new Dictionary<string, Mantle.IMessageFactory>() {
{ Mantle.Fix44.Protocol.Value, new Mantle.Fix44.MessageFactory() }
};
_receiver = new Mantle.Receiver(_strm, 1 << 20, protocols);
}
示例6: New
public void New(TcpClient c, bool isOutBound)
{
var stream = new SslStream(c.GetStream());
var remote = ((IPEndPoint)c.Client.RemoteEndPoint).Address.ToString();
var certs = new X509CertificateCollection();
var state = new State { Client = c, Stream = stream };
if (isOutBound)
{
certs.Add(clientCertificate);
stream.BeginAuthenticateAsClient(remote, certs, SslProtocols.Tls, false, EndAuthenticateAsClient, state);
}
else
{
certs.Add(serverCertificate);
stream.BeginAuthenticateAsServer(serverCertificate, true, SslProtocols.Tls, false, EndAuthenticateAsServer, state);
}
}
示例7: GetCertCollection
private X509CertificateCollection GetCertCollection()
{
X509CertificateCollection certCollection = new X509CertificateCollection();
string certLocation = TestContext.GetValue("certLocation");
X509Certificate cert = X509Certificate.CreateFromCertFile(certLocation);
certCollection.Add(cert);
return certCollection;
}
示例8: CertificateValidationClientServer_EndToEnd_Ok
public async Task CertificateValidationClientServer_EndToEnd_Ok()
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.IPv6Loopback, 0);
var server = new TcpListener(endPoint);
server.Start();
using (var clientConnection = new TcpClient(AddressFamily.InterNetworkV6))
{
IPEndPoint serverEndPoint = (IPEndPoint)server.LocalEndpoint;
Task clientConnect = clientConnection.ConnectAsync(serverEndPoint.Address, serverEndPoint.Port);
Task<TcpClient> serverAccept = server.AcceptTcpClientAsync();
Assert.True(
Task.WaitAll(
new Task[] { clientConnect, serverAccept },
TestConfiguration.TestTimeoutSeconds * 1000),
"Client/Server TCP Connect timed out.");
using (TcpClient serverConnection = await serverAccept)
using (SslStream sslClientStream = new SslStream(
clientConnection.GetStream(),
false,
ClientSideRemoteServerCertificateValidation))
using (SslStream sslServerStream = new SslStream(
serverConnection.GetStream(),
false,
ServerSideRemoteClientCertificateValidation))
{
string serverName = _serverCertificate.GetNameInfo(X509NameType.SimpleName, false);
string clientName = _clientCertificate.GetNameInfo(X509NameType.SimpleName, false);
var clientCerts = new X509CertificateCollection();
clientCerts.Add(_clientCertificate);
Task clientAuthentication = sslClientStream.AuthenticateAsClientAsync(
serverName,
clientCerts,
TestConfiguration.DefaultSslProtocols,
false);
Task serverAuthentication = sslServerStream.AuthenticateAsServerAsync(
_serverCertificate,
true,
TestConfiguration.DefaultSslProtocols,
false);
Assert.True(
Task.WaitAll(
new Task[] { clientAuthentication, serverAuthentication },
TestConfiguration.TestTimeoutSeconds * 1000),
"Client/Server Authentication timed out.");
}
}
}
示例9: GetClientCertificates
private static X509CertificateCollection GetClientCertificates(string certName)
{
X509CertificateCollection collection = new X509CertificateCollection();
X509Certificate cer = new X509Certificate(certName, "");
//cer.Import(certName);
//X509Store store = new X509Store(StoreLocation.LocalMachine);
//store.Certificates.Add(cer);
collection.Add(cer);
return collection;
}
示例10: ConnectServer
/// <summary>
/// Establishes the client SSL connection
/// </summary>
protected override Stream ConnectServer(System.Net.Sockets.TcpClient client)
{
Log.Verbose("Connected, SSL Nego...");
// Create an SSL stream that will close the client's stream.
_sslStream = new SslStream(base.ConnectServer(client), false, _certVerify.IsValid, LocalCertificateSelectionCallback);
X509CertificateCollection allCerts = new X509CertificateCollection();
if(_cert != null) allCerts.Add(_cert);
_sslStream.AuthenticateAsClient(base.ServerName, allCerts, SslProtocols.Default, false);
return _sslStream;
}
示例11: ApnsHttp2Connection
public ApnsHttp2Connection (ApnsHttp2Configuration configuration)
{
id = ++ID;
if (id >= int.MaxValue)
ID = 0;
Configuration = configuration;
certificate = Configuration.Certificate;
certificates = new X509CertificateCollection ();
// Add local/machine certificate stores to our collection if requested
if (Configuration.AddLocalAndMachineCertificateStores) {
var store = new X509Store (StoreLocation.LocalMachine);
certificates.AddRange (store.Certificates);
store = new X509Store (StoreLocation.CurrentUser);
certificates.AddRange (store.Certificates);
}
// Add optionally specified additional certs into our collection
if (Configuration.AdditionalCertificates != null) {
foreach (var addlCert in Configuration.AdditionalCertificates)
certificates.Add (addlCert);
}
// Finally, add the main private cert for authenticating to our collection
if (certificate != null)
certificates.Add (certificate);
var http2Settings = new HttpTwo.Http2ConnectionSettings (
Configuration.Host,
(uint)Configuration.Port,
true,
certificates);
http2 = new HttpTwo.Http2Client (http2Settings);
}
示例12: Main
public static void Main(string[] args)
{
Console.WriteLine("SSL Consumer test");
if (args.Length == 0)
{
System.Console.WriteLine(CommandLineArguments.Usage());
return;
}
CommandLineArguments cliArgs = new CommandLineArguments();
Parser parser = new Parser(System.Environment.CommandLine, cliArgs);
parser.Parse();
X509CertificateCollection certCollection = null;
if (cliArgs.CertificatePath != null)
{
X509Certificate cert = X509Certificate.CreateFromCertFile(cliArgs.CertificatePath);
certCollection = new X509CertificateCollection();
certCollection.Add(cert);
}
SslBrokerClient brokerClient = new SslBrokerClient(new HostInfo(cliArgs.Hostname, cliArgs.PortNumber), certCollection);
Subscription subscription = new Subscription(cliArgs.DestinationName, cliArgs.DestinationType);
subscription.OnMessage += delegate(NetNotification notification)
{
System.Console.WriteLine("Message received: {0}",
System.Text.Encoding.UTF8.GetString(notification.Message.Payload));
if (notification.DestinationType != NetAction.DestinationType.TOPIC)
brokerClient.Acknowledge(notification.Subscription, notification.Message.MessageId);
if (notification.DestinationType != NetAction.DestinationType.TOPIC)
{
brokerClient.Acknowledge(notification);
}
};
brokerClient.Subscribe(subscription);
Console.WriteLine("Write X to unsbscribe and exit");
while (!System.Console.Read().Equals('X'))
;
Console.WriteLine();
Console.WriteLine("Unsubscribe...");
// Note Subscription instance could other than the one used for subscription as long as it was equivelent (same destination type and subscription pattern). Since the application is ending and therefor the socket will be closed agent's will discard the previous subscription.
brokerClient.Unsubscribe(subscription);
Console.WriteLine("Good bye");
}
示例13: ApplePushChannel
public ApplePushChannel(ApplePushChannelSettings channelSettings)
{
cancelToken = cancelTokenSrc.Token;
appleSettings = channelSettings;
certificate = this.appleSettings.Certificate;
certificates = new X509CertificateCollection();
if (appleSettings.AddLocalAndMachineCertificateStores)
{
var store = new X509Store(StoreLocation.LocalMachine);
certificates.AddRange(store.Certificates);
store = new X509Store(StoreLocation.CurrentUser);
certificates.AddRange(store.Certificates);
}
certificates.Add(certificate);
if (this.appleSettings.AdditionalCertificates != null)
foreach (var addlCert in this.appleSettings.AdditionalCertificates)
certificates.Add(addlCert);
timerCleanup = new Timer(state => Cleanup(), null, TimeSpan.FromMilliseconds(1000), TimeSpan.FromMilliseconds(1000));
if (channelSettings.IdleConnectionResetTimeout.HasValue)
{
this.IdleConnectionResetTimer.Interval = channelSettings.IdleConnectionResetTimeout.Value.TotalMilliseconds;
this.IdleConnectionResetTimer.AutoReset = false;
this.IdleConnectionResetTimer.Elapsed += (sender, e) =>
{
disconnect();
};
}
}
示例14: ApplePushChannel
public ApplePushChannel(ApplePushChannelSettings channelSettings, PushServiceSettings serviceSettings = null)
: base(channelSettings, serviceSettings)
{
this.appleSettings = channelSettings;
certificate = this.appleSettings.Certificate;
certificates = new X509CertificateCollection();
certificates.Add(certificate);
//Start our cleanup task
taskCleanup = new Task(() => Cleanup(), TaskCreationOptions.LongRunning);
taskCleanup.ContinueWith((t) => { var ex = t.Exception; }, TaskContinuationOptions.OnlyOnFaulted);
taskCleanup.Start();
}
示例15: connect
public void connect()
{
try
{
client.Connect("127.0.0.1", 1288);
// create streams
sslStream = new SslStream(client.GetStream(), false,
new RemoteCertificateValidationCallback(CertificateValidationCallback),
new LocalCertificateSelectionCallback(CertificateSelectionCallback));
bool authenticationPassed = true;
try
{
string serverName = System.Environment.MachineName;
X509Certificate cert = GetServerCert();
X509CertificateCollection certs = new X509CertificateCollection();
certs.Add(cert);
sslStream.AuthenticateAsClient(
serverName,
certs,
SslProtocols.Default,
false); // check cert revokation
}
catch (AuthenticationException)
{
authenticationPassed = false;
}
if (authenticationPassed)
{
receiveThread = new Thread(receive);
receiveThread.Start();
isConnectedFlag = true;
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Thread.Sleep(1000);
isConnectedFlag = false;
}
}