Example #1
0
        /// <summary>
        /// Returns a selected certificate based on configuration.
        /// </summary>
        /// <param name="certificateSubject">The subject serial number of the certificate</param>
        /// <returns>Returns a selected certificate based on configuration.</returns>
        public X509Certificate2 GetCertificate(CertificateSubject certificateSubject)
        {
            CertificateLoader certificateLoader = new CertificateLoader();

            switch (_config.Action)
            {
            case LdapCertificateLookupTestConfig.LookupAction.FindCertificate:
                // 1. Attempt to load the certificate from store:
                return(certificateLoader.GetCertificateFromStoreWithSSN(
                           certificateSubject.SerialNumberValue,
                           _config.StoreLocation,
                           _config.StoreName
                           ));

            case LdapCertificateLookupTestConfig.LookupAction.ConnectionFailed:
                LdapSettings settings = ConfigurationHandler.GetConfigurationSection <LdapSettings>();
                throw new ConnectingToLdapServerFailedException(settings, new Exception(this.ToString()));

            case LdapCertificateLookupTestConfig.LookupAction.SearchFailed:
                throw new SearchFailedException(new Exception(this.ToString()));

            default:
                throw new NotImplementedException();
            }
        }