Beispiel #1
0
        public static void ValidateLocalCertificate(string thumbprint, DateTime?futurePublishDate, bool skipAutomatedDeploymentChecks, Task.TaskErrorLoggingDelegate writeError)
        {
            if (writeError == null)
            {
                throw new ArgumentNullException("writeError");
            }
            if (string.IsNullOrEmpty(thumbprint))
            {
                return;
            }
            X509Store x509Store = null;

            try
            {
                x509Store = new X509Store(StoreLocation.LocalMachine);
                x509Store.Open(OpenFlags.ReadOnly);
                X509Certificate2Collection x509Certificate2Collection = x509Store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
                if (x509Certificate2Collection.Count == 0)
                {
                    writeError(new TaskException(Strings.ErrorThumbprintNotFound(thumbprint)), ErrorCategory.InvalidArgument, null);
                }
                ExchangeCertificate certificate = new ExchangeCertificate(x509Certificate2Collection[0]);
                OAuthTaskHelper.ValidateCertificate(certificate, futurePublishDate, skipAutomatedDeploymentChecks, writeError);
            }
            finally
            {
                if (x509Store != null)
                {
                    x509Store.Close();
                }
            }
        }
Beispiel #2
0
        public static void ValidateRemoteCertificate(string server, string thumbprint, DateTime?futurePublishDate, bool skipAutomatedDeploymentChecks, Task.TaskErrorLoggingDelegate writeError)
        {
            if (writeError == null)
            {
                throw new ArgumentNullException("writeError");
            }
            if (string.IsNullOrEmpty(thumbprint))
            {
                return;
            }
            ExchangeCertificate             certificate = null;
            FederationTrustCertificateState federationTrustCertificateState = FederationCertificate.TestForCertificate(server, thumbprint, out certificate);

            if (federationTrustCertificateState == FederationTrustCertificateState.ServerUnreachable)
            {
                writeError(new TaskException(Strings.ErrorCannotContactServerForCert(server, thumbprint)), ErrorCategory.InvalidArgument, null);
            }
            else if (federationTrustCertificateState != FederationTrustCertificateState.Installed)
            {
                writeError(new TaskException(Strings.ErrorThumbprintNotFound(thumbprint)), ErrorCategory.InvalidArgument, null);
            }
            OAuthTaskHelper.ValidateCertificate(certificate, futurePublishDate, skipAutomatedDeploymentChecks, writeError);
        }