System.Net.Security.SslSessionsCache.TryCachedCredential C# (CSharp) Method

TryCachedCredential() static private method

static private TryCachedCredential ( byte thumbPrint, SchProtocols allowedProtocols ) : SafeFreeCredentials
thumbPrint byte
allowedProtocols SchProtocols
return SafeFreeCredentials
          internal static SafeFreeCredentials TryCachedCredential(byte[] thumbPrint, SchProtocols allowedProtocols)
          {
              if (s_CachedCreds.Count == 0)
              {
                  GlobalLog.Print("TryCachedCredential() Not Found, Current Cache Count = " + s_CachedCreds.Count);
                  return null;
              }

              object key = new SslCredKey(thumbPrint, allowedProtocols);

              SafeCredentialReference cached = s_CachedCreds[key] as SafeCredentialReference;

              if (cached == null || cached.IsClosed || cached._Target.IsInvalid)
              {
                  GlobalLog.Print("TryCachedCredential() Not Found, Current Cache Count = " + s_CachedCreds.Count);
                  return null;
              }

              GlobalLog.Print("TryCachedCredential() Found a cached Handle = " + cached._Target.ToString());

              return cached._Target;
          }
          //

Usage Example

Beispiel #1
0
        private bool AcquireServerCredentials(ref byte[] thumbPrint)
        {
            X509Certificate serverCertificate = null;

            if (this.m_CertSelectionDelegate != null)
            {
                X509CertificateCollection localCertificates = new X509CertificateCollection();
                localCertificates.Add(this.m_ServerCertificate);
                serverCertificate = this.m_CertSelectionDelegate(string.Empty, localCertificates, null, new string[0]);
            }
            else
            {
                serverCertificate = this.m_ServerCertificate;
            }
            if (serverCertificate == null)
            {
                throw new NotSupportedException(SR.GetString("net_ssl_io_no_server_cert"));
            }
            X509Certificate2 certificate2 = this.EnsurePrivateKey(serverCertificate);

            if (certificate2 == null)
            {
                throw new NotSupportedException(SR.GetString("net_ssl_io_no_server_cert"));
            }
            byte[] certHash = certificate2.GetCertHash();
            try
            {
                SafeFreeCredentials credentials = SslSessionsCache.TryCachedCredential(certHash, this.m_ProtocolFlags, this.m_EncryptionPolicy);
                if (credentials != null)
                {
                    this.m_CredentialsHandle = credentials;
                    this.m_ServerCertificate = serverCertificate;
                    return(true);
                }
                SecureCredential secureCredential = new SecureCredential(4, certificate2, SecureCredential.Flags.Zero, this.m_ProtocolFlags, this.m_EncryptionPolicy);
                this.m_CredentialsHandle = this.AcquireCredentialsHandle(CredentialUse.Inbound, ref secureCredential);
                thumbPrint = certHash;
                this.m_ServerCertificate = serverCertificate;
            }
            finally
            {
                if (serverCertificate != certificate2)
                {
                    certificate2.Reset();
                }
            }
            return(false);
        }
All Usage Examples Of System.Net.Security.SslSessionsCache::TryCachedCredential