本文整理汇总了C#中System.Security.Cryptography.X509Certificates.X509CertificateCollection类的典型用法代码示例。如果您正苦于以下问题:C# X509CertificateCollection类的具体用法?C# X509CertificateCollection怎么用?C# X509CertificateCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
X509CertificateCollection类属于System.Security.Cryptography.X509Certificates命名空间,在下文中一共展示了X509CertificateCollection类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: HttpsClientStream
public HttpsClientStream (Stream stream, X509CertificateCollection clientCertificates,
HttpWebRequest request, byte [] buffer)
: base (stream, request.RequestUri.Host, false, (Mono.Security.Protocol.Tls.SecurityProtocolType)
ServicePointManager.SecurityProtocol, clientCertificates)
{
// this constructor permit access to the WebRequest to call
// ICertificatePolicy.CheckValidationResult
_request = request;
_status = 0;
if (buffer != null)
InputBuffer.Write (buffer, 0, buffer.Length);
#if !NET_1_0
// also saved from reflection
base.CheckCertRevocationStatus = ServicePointManager.CheckCertificateRevocationList;
#endif
#if NET_2_0
ClientCertSelection += delegate (X509CertificateCollection clientCerts, X509Certificate serverCertificate,
string targetHost, X509CertificateCollection serverRequestedCertificates) {
return ((clientCerts == null) || (clientCerts.Count == 0)) ? null : clientCerts [0];
};
PrivateKeySelection += delegate (X509Certificate certificate, string targetHost) {
X509Certificate2 cert = (certificate as X509Certificate2);
return (cert == null) ? null : cert.PrivateKey;
};
#endif
}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:26,代码来源:HttpsClientStream.cs
示例2: GcmXmppConnection
public GcmXmppConnection (GcmXmppConfiguration configuration)
{
authCompletion = new TaskCompletionSource<bool> ();
notifications = new Dictionary<string,CompletableNotification> ();
Configuration = configuration;
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);
}
开发者ID:CalebKoch,项目名称:PushSharp,代码行数:28,代码来源:GcmXmppConnection.cs
示例3: 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);
}
开发者ID:romkatv,项目名称:iFix,代码行数:61,代码来源:TcpConnector.cs
示例4: Http2ConnectionSettings
public Http2ConnectionSettings (string host, uint port = 80, bool useTls = false, X509CertificateCollection certificates = null)
{
Host = host;
Port = port;
UseTls = useTls;
Certificates = certificates;
}
开发者ID:gitter-badger,项目名称:HttpTwo,代码行数:7,代码来源:Http2Connection.cs
示例5: InternalSslSocketHttp
static byte[] InternalSslSocketHttp(IPEndPoint endpoint, HttpArgs args, HttpMethod method, X509CertificateCollection certificates)
{
using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
try
{
client.Connect(endpoint);
if (client.Connected)
{
using (SslStream stream = new SslStream(new NetworkStream(client), false, ValidateServerCertificate, null))
{
stream.AuthenticateAsClient("ServerName", certificates, SslProtocols.Tls, false);
if (stream.IsAuthenticated)
{
//生成协议包
byte[] buff = HttpClient.ParseHttpArgs(method, args);
stream.Write(buff, 0, buff.Length);
stream.Flush();
return ParseSslResponse(endpoint, stream, args, certificates);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return null;
}
开发者ID:abel,项目名称:sinan,代码行数:31,代码来源:SslHttpClient.cs
示例6: 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));
}
开发者ID:vniu,项目名称:PushSharp,代码行数:27,代码来源:ApplePushChannel.cs
示例7: SecureChannel
internal SecureChannel(string hostname, bool serverMode, SslProtocols sslProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool remoteCertRequired, bool checkCertName,
bool checkCertRevocationStatus, EncryptionPolicy encryptionPolicy, LocalCertSelectionCallback certSelectionDelegate)
{
GlobalLog.Enter("SecureChannel#" + Logging.HashString(this) + "::.ctor", "hostname:" + hostname + " #clientCertificates=" + ((clientCertificates == null) ? "0" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
if (Logging.On)
{
Logging.PrintInfo(Logging.Web, this, ".ctor", "hostname=" + hostname + ", #clientCertificates=" + ((clientCertificates == null) ? "0" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)) + ", encryptionPolicy=" + encryptionPolicy);
}
SSPIWrapper.VerifyPackageInfo(GlobalSSPI.SSPISecureChannel);
_destination = hostname;
GlobalLog.Assert(hostname != null, "SecureChannel#{0}::.ctor()|hostname == null", Logging.HashString(this));
_hostName = hostname;
_serverMode = serverMode;
_sslProtocols = sslProtocols;
_serverCertificate = serverCertificate;
_clientCertificates = clientCertificates;
_remoteCertRequired = remoteCertRequired;
_securityContext = null;
_checkCertRevocation = checkCertRevocationStatus;
_checkCertName = checkCertName;
_certSelectionDelegate = certSelectionDelegate;
_refreshCredentialNeeded = true;
_encryptionPolicy = encryptionPolicy;
GlobalLog.Leave("SecureChannel#" + Logging.HashString(this) + "::.ctor");
}
开发者ID:andyhebear,项目名称:corefx,代码行数:30,代码来源:_SecureChannel.cs
示例8: SecureChannel
internal SecureChannel(string hostname, bool serverMode, SslProtocols sslProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool remoteCertRequired, bool checkCertName,
bool checkCertRevocationStatus, EncryptionPolicy encryptionPolicy, LocalCertSelectionCallback certSelectionDelegate)
{
if (NetEventSource.IsEnabled)
{
NetEventSource.Enter(this, hostname, clientCertificates);
NetEventSource.Log.SecureChannelCtor(this, hostname, clientCertificates, encryptionPolicy);
}
SslStreamPal.VerifyPackageInfo();
_destination = hostname;
if (hostname == null)
{
NetEventSource.Fail(this, "hostname == null");
}
_hostName = hostname;
_serverMode = serverMode;
_sslProtocols = sslProtocols;
_serverCertificate = serverCertificate;
_clientCertificates = clientCertificates;
_remoteCertRequired = remoteCertRequired;
_securityContext = null;
_checkCertRevocation = checkCertRevocationStatus;
_checkCertName = checkCertName;
_certSelectionDelegate = certSelectionDelegate;
_refreshCredentialNeeded = true;
_encryptionPolicy = encryptionPolicy;
if (NetEventSource.IsEnabled) NetEventSource.Exit(this);
}
开发者ID:dotnet,项目名称:corefx,代码行数:34,代码来源:SecureChannel.cs
示例9: HandshakeSession
protected HandshakeSession(SecurityParameters securityParameters, ILogger logger)
{
this.logger = logger;
_pluginManager = new CipherSuitePluginManager(this.logger);
_state = HandshakeState.Initial;
_minVersion = securityParameters.MinimumVersion;
_maxVersion = securityParameters.MaximumVersion;
_supportedCipherSuites = securityParameters.CipherSuiteIDs.ToArray();
_supportedCompressions = securityParameters.CompressionIDs.ToArray();
_availableCertificates = new List<X509CertificateCollection>(securityParameters.AvailableCertificates);
_availablePrivateKeys = new List<CertificatePrivateKey>(securityParameters.AvailablePrivateKeys);
_clientCertificates = new X509CertificateCollection();
_serverCertificates = new X509CertificateCollection();
// Initialize the default ClientHello version, to
// be as compatible as possible based on maxVersion
_version = _minVersion;
_cipherSuite = new CipherSuite(_version);
}
开发者ID:cwschroeder,项目名称:MeterTestComService,代码行数:25,代码来源:HandshakeSession.cs
示例10: AsyncWebSocketClientConfiguration
public AsyncWebSocketClientConfiguration()
{
InitialBufferAllocationCount = 4;
ReceiveBufferSize = 8192;
SendBufferSize = 8192;
ReceiveTimeout = TimeSpan.Zero;
SendTimeout = TimeSpan.Zero;
NoDelay = true;
LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.
SslTargetHost = null;
SslClientCertificates = new X509CertificateCollection();
SslEncryptionPolicy = EncryptionPolicy.RequireEncryption;
SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
SslCheckCertificateRevocation = false;
SslPolicyErrorsBypassed = false;
ConnectTimeout = TimeSpan.FromSeconds(10);
CloseTimeout = TimeSpan.FromSeconds(5);
KeepAliveInterval = TimeSpan.FromSeconds(30);
KeepAliveTimeout = TimeSpan.FromSeconds(5);
ReasonableFragmentSize = 4096;
EnabledExtensions = new Dictionary<string, IWebSocketExtensionNegotiator>()
{
{ PerMessageCompressionExtension.RegisteredToken, new PerMessageCompressionExtensionNegotiator() },
};
EnabledSubProtocols = new Dictionary<string, IWebSocketSubProtocolNegotiator>();
OfferedExtensions = new List<WebSocketExtensionOfferDescription>()
{
new WebSocketExtensionOfferDescription(PerMessageCompressionExtension.RegisteredToken),
};
RequestedSubProtocols = new List<WebSocketSubProtocolRequestDescription>();
}
开发者ID:xiaomiwk,项目名称:Cowboy,代码行数:35,代码来源:AsyncWebSocketClientConfiguration.cs
示例11: SslFilter
/// <summary>
/// Creates a new SSL filter to a server.
/// </summary>
/// <param name="targetHost">the name of the server that shares this SSL connection</param>
/// <param name="clientCertificates">the <see cref="X509CertificateCollection"/> containing client certificates</param>
public SslFilter(String targetHost, X509CertificateCollection clientCertificates)
{
TargetHost = targetHost;
ClientCertificates = clientCertificates;
UseClientMode = true;
CheckCertificateRevocation = false;
}
开发者ID:zhangf911,项目名称:Mina.NET,代码行数:12,代码来源:SslFilter.cs
示例12: ConnectAsync
public async Task<Stream> ConnectAsync(string host, int port, X509Certificate clientCert, CancellationToken cancel)
{
Stream lowerStream = null;
SslStream sslStream = null;
X509CertificateCollection certCollection = null;;
if (clientCert != null)
{
certCollection = new X509CertificateCollection(new[] { clientCert });
}
try
{
lowerStream = await _connectionResolver.ConnectAsync(host, port, cancel);
sslStream = new SslStream(lowerStream);
await sslStream.AuthenticateAsClientAsync(host, certCollection, _protocols, checkCertificateRevocation: true);
return sslStream;
}
catch (Exception)
{
if (sslStream != null)
{
sslStream.Dispose();
}
if (lowerStream != null)
{
lowerStream.Dispose();
}
throw;
}
}
开发者ID:Tratcher,项目名称:HTTP-SPEED-PLUS-MOBILITY,代码行数:29,代码来源:SslConnectionResolver.cs
示例13: LocalCertificationSelectionInfo
public LocalCertificationSelectionInfo(string targetHost, X509CertificateCollection localCertificates, X509Certificate remoteCertificate, string[] acceptableIssures)
{
this.target = targetHost;
this.localCerts = localCertificates;
this.remoteCert = remoteCertificate;
this.accIssures = acceptableIssures;
}
开发者ID:BGCX261,项目名称:zpoc3-svn-to-git,代码行数:7,代码来源:LocalCertificationSelectionInfo.cs
示例14: BeginAuthenticateAsClient
public virtual IAsyncResult BeginAuthenticateAsClient(string targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, bool checkCertificateRevocation, AsyncCallback asyncCallback, object asyncState)
{
this._SslState.ValidateCreateContext(false, targetHost, enabledSslProtocols, null, clientCertificates, true, checkCertificateRevocation);
LazyAsyncResult lazyResult = new LazyAsyncResult(this._SslState, asyncState, asyncCallback);
this._SslState.ProcessAuthentication(lazyResult);
return lazyResult;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:SslStream.cs
示例15: TlsStream
//
// This version of an Ssl Stream is for internal HttpWebrequest use.
// This Ssl client owns the underlined socket
// The TlsStream will own secured read/write and disposal of the passed "networkStream" stream.
//
public TlsStream(string destinationHost, NetworkStream networkStream, X509CertificateCollection clientCertificates, ServicePoint servicePoint, object initiatingRequest, ExecutionContext executionContext)
:base(networkStream, true) {
// WebRequest manages the execution context manually so we have to ensure we get one for SSL client certificate demand
_ExecutionContext = executionContext;
if (_ExecutionContext == null)
{
_ExecutionContext = ExecutionContext.Capture();
}
//
GlobalLog.Enter("TlsStream::TlsStream", "host="+destinationHost+", #certs="+((clientCertificates == null) ? "none" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
if (Logging.On) Logging.PrintInfo(Logging.Web, this, ".ctor", "host="+destinationHost+", #certs="+((clientCertificates == null) ? "null" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
m_ExceptionStatus = WebExceptionStatus.SecureChannelFailure;
m_Worker = new SslState(networkStream, initiatingRequest is HttpWebRequest, SettingsSectionInternal.Section.EncryptionPolicy);
m_DestinationHost = destinationHost;
m_ClientCertificates = clientCertificates;
RemoteCertValidationCallback certValidationCallback = servicePoint.SetupHandshakeDoneProcedure(this, initiatingRequest);
m_Worker.SetCertValidationDelegate(certValidationCallback);
// The Handshake is NOT done at this point
GlobalLog.Leave("TlsStream::TlsStream (Handshake is not done)");
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:33,代码来源:_TLSstream.cs
示例16: Build
/// <summary>
/// Build a new SSL steam.
/// </summary>
/// <param name="channel">Channel which will use the stream</param>
/// <param name="socket">Socket to wrap</param>
/// <returns>Stream which is ready to be used (must have been validated)</returns>
public SslStream Build(ITcpChannel channel, Socket socket)
{
var ns = new NetworkStream(socket);
var stream = new SslStream(ns, true, OnRemoteCertifiateValidation);
try
{
X509CertificateCollection certificates = null;
if (Certificate != null)
{
certificates = new X509CertificateCollection(new[] { Certificate });
}
stream.AuthenticateAsClient(CommonName, certificates, Protocols, false);
}
catch (IOException err)
{
throw new InvalidOperationException("Failed to authenticate " + socket.RemoteEndPoint, err);
}
catch (ObjectDisposedException err)
{
throw new InvalidOperationException("Failed to create stream, did client disconnect directly?", err);
}
catch (AuthenticationException err)
{
throw new InvalidOperationException("Failed to authenticate " + socket.RemoteEndPoint, err);
}
return stream;
}
开发者ID:krigans,项目名称:Griffin.Framework,代码行数:36,代码来源:ClientSideSslStreamBuilder.cs
示例17: PushNotification
public PushNotification(bool useSandbox, string p12File, string p12FilePassword)
{
if (useSandbox)
{
_host = SandboxHost;
_feedbackHost = SandboxFeedbackHost;
}
else
{
_host = ProductionHost;
_feedbackHost = ProductionFeedbackHost;
}
//Load Certificates in to collection.
_certificate = string.IsNullOrEmpty(p12FilePassword)? new X509Certificate2(File.ReadAllBytes(p12File)): new X509Certificate2(File.ReadAllBytes(p12File), p12FilePassword);
_certificates = new X509CertificateCollection {_certificate};
// Loading Apple error response list.
_errorList.Add(0, "No errors encountered");
_errorList.Add(1, "Processing error");
_errorList.Add(2, "Missing device token");
_errorList.Add(3, "Missing topic");
_errorList.Add(4, "Missing payload");
_errorList.Add(5, "Invalid token size");
_errorList.Add(6, "Invalid topic size");
_errorList.Add(7, "Invalid payload size");
_errorList.Add(8, "Invalid token");
_errorList.Add(255, "None (unknown)");
}
开发者ID:embassem,项目名称:Moon-APNS,代码行数:29,代码来源:PushNotification.cs
示例18: 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);
}
}
}
开发者ID:greg84,项目名称:PushSharp,代码行数:25,代码来源:ApplePushChannel.cs
示例19: X509CertificateEnumerator
public X509CertificateEnumerator(X509CertificateCollection mappings)
{
if (mappings == null)
throw new ArgumentNullException(nameof(mappings));
_enumerator = ((IEnumerable)mappings).GetEnumerator();
}
开发者ID:dotnet,项目名称:corefx,代码行数:7,代码来源:X509CertificateEnumerator.cs
示例20: SecureChannel
internal SecureChannel(string hostname, bool serverMode, SchProtocols protocolFlags, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool remoteCertRequired, bool checkCertName,
bool checkCertRevocationStatus, EncryptionPolicy encryptionPolicy, LocalCertSelectionCallback certSelectionDelegate)
{
GlobalLog.Enter("SecureChannel#" + ValidationHelper.HashString(this) + "::.ctor", "hostname:" + hostname + " #clientCertificates=" + ((clientCertificates == null) ? "0" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)));
if (Logging.On) Logging.PrintInfo(Logging.Web, this, ".ctor", "hostname=" + hostname + ", #clientCertificates=" + ((clientCertificates == null) ? "0" : clientCertificates.Count.ToString(NumberFormatInfo.InvariantInfo)) + ", encryptionPolicy=" + encryptionPolicy);
SSPIWrapper.GetVerifyPackageInfo(GlobalSSPI.SSPISecureChannel, SecurityPackage, true);
m_Destination = hostname;
GlobalLog.Assert(hostname != null, "SecureChannel#{0}::.ctor()|hostname == null", ValidationHelper.HashString(this));
m_HostName = hostname;
m_ServerMode = serverMode;
if (serverMode)
m_ProtocolFlags = (protocolFlags & SchProtocols.ServerMask);
else
m_ProtocolFlags = (protocolFlags & SchProtocols.ClientMask);
m_ServerCertificate = serverCertificate;
m_ClientCertificates = clientCertificates;
m_RemoteCertRequired = remoteCertRequired;
m_SecurityContext = null;
m_CheckCertRevocation = checkCertRevocationStatus;
m_CheckCertName = checkCertName;
m_CertSelectionDelegate = certSelectionDelegate;
m_RefreshCredentialNeeded = true;
m_EncryptionPolicy = encryptionPolicy;
GlobalLog.Leave("SecureChannel#" + ValidationHelper.HashString(this) + "::.ctor");
}
开发者ID:uQr,项目名称:referencesource,代码行数:29,代码来源:_SecureChannel.cs
注:本文中的System.Security.Cryptography.X509Certificates.X509CertificateCollection类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论